2017-02-06 00:00:57 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-02-06 00:00:57 +00:00
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse\Test\Lang;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-03-28 22:50:00 +00:00
|
|
|
use JKingWeb\Arsse\Lang;
|
2017-07-17 11:47:57 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
2017-03-29 00:30:40 +00:00
|
|
|
use org\bovigo\vfs\vfsStream;
|
2019-10-17 17:00:56 +00:00
|
|
|
use Webmozart\Glob\Glob;
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-02-15 03:34:08 +00:00
|
|
|
trait Setup {
|
2019-10-16 18:42:43 +00:00
|
|
|
public function setUp(): void {
|
2017-02-16 20:29:42 +00:00
|
|
|
// test files
|
2017-03-28 22:50:00 +00:00
|
|
|
$this->files = [
|
2017-02-16 20:29:42 +00: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 22:50:34 +00:00
|
|
|
// corrupted message in valid file
|
|
|
|
'vi.php' => '<?php return ["Test.presentText" => "{0} and {1"];',
|
2017-02-16 20:29:42 +00: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 22:50:00 +00:00
|
|
|
$vfs = vfsStream::setup("langtest", 0777, $this->files);
|
|
|
|
$this->path = $vfs->url()."/";
|
2017-02-16 20:29:42 +00:00
|
|
|
// set up a file without read access
|
2017-03-28 22:50:00 +00:00
|
|
|
chmod($this->path."ru.php", 0000);
|
|
|
|
// make the test Lang class use the vfs files
|
2021-03-01 23:01:25 +00:00
|
|
|
$this->l = $this->partialMock(Lang::class, $this->path);
|
|
|
|
$this->l->globFiles->does(function(string $path): array {
|
2019-10-17 17:00:56 +00:00
|
|
|
return Glob::glob($this->path."*.php");
|
|
|
|
});
|
2021-03-01 23:01:25 +00:00
|
|
|
$this->l = $this->l->get();
|
2018-11-23 15:01:17 +00:00
|
|
|
self::clearData(false);
|
2024-07-06 15:01:00 +00:00
|
|
|
Arsse::$lang = $this->l;
|
2017-03-28 22:50:00 +00:00
|
|
|
// call the additional setup method if it exists
|
2017-08-29 14:50:31 +00:00
|
|
|
if (method_exists($this, "setUpSeries")) {
|
|
|
|
$this->setUpSeries();
|
|
|
|
}
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-02-09 21:56:30 +00:00
|
|
|
|
2019-10-16 18:42:43 +00:00
|
|
|
public function tearDown(): void {
|
2017-03-29 00:30:40 +00:00
|
|
|
// clean up
|
2018-11-23 15:01:17 +00:00
|
|
|
self::clearData(true);
|
2017-03-28 22:50:00 +00:00
|
|
|
// call the additional teardiwn method if it exists
|
2017-08-29 14:50:31 +00:00
|
|
|
if (method_exists($this, "tearDownSeries")) {
|
|
|
|
$this->tearDownSeries();
|
|
|
|
}
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|