1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8require_once(__DIR__ . '/../../language/MergeFiles.php');
9
10use org\bovigo\vfs\vfsStream;
11use org\bovigo\vfs\vfsStreamFile;
12
13class Language_MergeFilesTest extends TikiTestCase
14{
15	protected $obj;
16
17	protected function setUp()
18	{
19		$root = vfsStream::setup('root');
20		$this->sourceFile = new vfsStreamFile('language_source.php');
21		$this->targetFile = new vfsStreamFile('language_target.php');
22		$this->targetFile->setContent(file_get_contents(__DIR__ . '/fixtures/language_merge_files_original.php'));
23		$root->addChild($this->sourceFile);
24		$root->addChild($this->targetFile);
25
26		$sourceFilePath = vfsStream::url('root/language_source.php');
27		$targetFilePath = vfsStream::url('root/language_target.php');
28		$this->sourceFileObj = $this->getMockBuilder('Language_File')
29									->setMethods(['parse'])
30									->setConstructorArgs([$sourceFilePath])
31									->getMock();
32
33		$this->targetFileObj = $this->getMockBuilder('Language_File')
34									->setMethods(['parse'])
35									->setConstructorArgs([$targetFilePath])
36									->getMock();
37
38		$this->obj = new Language_MergeFiles($this->sourceFileObj, $this->targetFileObj);
39	}
40
41	public function testMerge_shouldUpdateTargetFileWithTranslationsFromSourceFile()
42	{
43		$sourceFileData = [
44			'Bytecode Cache' => ['key' => 'Bytecode Cache', 'translated' => false],
45			'Used' => ['key' => 'Used', 'translation' => "Usado", 'translated' => true],
46			 'Available' => ['key' => 'Available', 'translation' => 'Disponível', 'translated' => true],
47			'Memory' => ['key' => 'Memory', 'translation' => 'Memória', 'translated' => true],
48			'%0 enabled' => ['key' => '%0 enabled', 'translation' => '%0 habilitado', 'translated' => true],
49			'Features' => ['key' => 'Features', 'translation' => 'Recursos', 'translated' => true],
50			'Wiki Config' => ['key' => 'Wiki Config', 'translations' => 'Configuração Wiki', 'translated' => true],
51		];
52
53		$targetFileData = [
54			'Bytecode Cache' => ['key' => 'Bytecode Cache', 'translated' => false],
55			'Used' => ['key' => 'Used', 'translation' => "Usado", 'translated' => true],
56			 'Available' => ['key' => 'Available', 'translated' => false],
57			'Memory' => ['key' => 'Memory', 'translated' => false],
58			'%0 enabled' => ['key' => '%0 enabled', 'translation' => '%0 habilitado', 'translated' => true],
59			'Features' => ['key' => 'Features', 'translation' => 'Recursos antigos', 'translated' => true],
60			'Tiki Admin' => ['key' => 'Tiki Admin', 'translation' => 'Administração do Tiki', 'translated' => true],
61		];
62
63		$this->sourceFileObj->expects($this->once())->method('parse')->will($this->returnValue($sourceFileData));
64		$this->targetFileObj->expects($this->once())->method('parse')->will($this->returnValue($targetFileData));
65
66		$this->obj->merge();
67
68		$this->assertEquals(file_get_contents(__DIR__ . '/fixtures/language_merge_files_result.php'), file_get_contents(vfsStream::url('root/language_target.php')));
69	}
70}
71