2017-02-05 19:00:57 -05:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
2017-03-28 00:12:12 -04:00
|
|
|
namespace JKingWeb\Arsse\Test\Lang;
|
2017-03-28 18:50:00 -04:00
|
|
|
use JKingWeb\Arsse\Lang;
|
|
|
|
use JKingWeb\Arsse\Data;
|
2017-03-28 20:30:40 -04:00
|
|
|
use org\bovigo\vfs\vfsStream;
|
|
|
|
use Phake;
|
2017-02-05 19:00:57 -05:00
|
|
|
|
2017-02-09 16:56:30 -05:00
|
|
|
|
|
|
|
|
2017-02-14 22:34:08 -05:00
|
|
|
trait Setup {
|
2017-03-28 18:50:00 -04:00
|
|
|
function setUp() {
|
2017-02-16 15:29:42 -05:00
|
|
|
// test files
|
2017-03-28 18:50:00 -04:00
|
|
|
$this->files = [
|
2017-02-16 15:29:42 -05:00
|
|
|
'en.php' => '<?php return ["Test.presentText" => "and the Philosopher\'s Stone"];',
|
|
|
|
'en_ca.php' => '<?php return ["Test.presentText" => "{0} and {1}"];',
|
|
|
|
'en_us.php' => '<?php return ["Test.presentText" => "and the Sorcerer\'s Stone"];',
|
|
|
|
'fr.php' => '<?php return ["Test.presentText" => "à l\'école des sorciers"];',
|
|
|
|
'ja.php' => '<?php return ["Test.absentText" => "賢者の石"];',
|
|
|
|
'de.php' => '<?php return ["Test.presentText" => "und der Stein der Weisen"];',
|
|
|
|
'pt_br.php' => '<?php return ["Test.presentText" => "e a Pedra Filosofal"];',
|
2017-02-16 17:50:34 -05:00
|
|
|
// corrupted message in valid file
|
|
|
|
'vi.php' => '<?php return ["Test.presentText" => "{0} and {1"];',
|
2017-02-16 15:29:42 -05:00
|
|
|
// corrupt files
|
|
|
|
'it.php' => '<?php return 0;',
|
|
|
|
'zh.php' => '<?php return 0',
|
|
|
|
'ko.php' => 'DEAD BEEF',
|
|
|
|
'fr_ca.php' => '',
|
|
|
|
// unreadable file
|
|
|
|
'ru.php' => '',
|
|
|
|
];
|
2017-03-28 18:50:00 -04:00
|
|
|
$vfs = vfsStream::setup("langtest", 0777, $this->files);
|
|
|
|
$this->path = $vfs->url()."/";
|
2017-02-16 15:29:42 -05:00
|
|
|
// set up a file without read access
|
2017-03-28 18:50:00 -04:00
|
|
|
chmod($this->path."ru.php", 0000);
|
|
|
|
// make the test Lang class use the vfs files
|
2017-06-01 13:50:46 -04:00
|
|
|
$this->l = new TestLang($this->path);
|
2017-03-28 20:30:40 -04:00
|
|
|
// create a mock Lang object so as not to create a dependency loop
|
2017-03-28 18:50:00 -04:00
|
|
|
$this->clearData(false);
|
2017-07-11 20:27:37 -04:00
|
|
|
Data::$lang = Phake::mock(Lang::class);
|
|
|
|
Phake::when(Data::$lang)->msg->thenReturn("");
|
2017-03-28 18:50:00 -04:00
|
|
|
// call the additional setup method if it exists
|
|
|
|
if(method_exists($this, "setUpSeries")) $this->setUpSeries();
|
2017-02-16 15:29:42 -05:00
|
|
|
}
|
2017-02-09 16:56:30 -05:00
|
|
|
|
2017-03-28 18:50:00 -04:00
|
|
|
function tearDown() {
|
2017-03-28 20:30:40 -04:00
|
|
|
// verify calls to the mock Lang object
|
2017-07-11 20:27:37 -04:00
|
|
|
Phake::verify(Data::$lang, Phake::atLeast(0))->msg($this->isType("string"), $this->anything());
|
|
|
|
Phake::verifyNoOtherInteractions(Data::$lang);
|
2017-03-28 20:30:40 -04:00
|
|
|
// clean up
|
2017-03-28 18:50:00 -04:00
|
|
|
$this->clearData(true);
|
|
|
|
// call the additional teardiwn method if it exists
|
|
|
|
if(method_exists($this, "tearDownSeries")) $this->tearDownSeries();
|
2017-02-16 15:29:42 -05:00
|
|
|
}
|
2017-02-09 16:39:13 -05:00
|
|
|
}
|