2017-07-06 18:20:55 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-09-29 10:52:32 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Installer\Config\Plugin;
|
2017-07-06 18:20:55 +03:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
2018-09-29 10:52:32 +03:00
|
|
|
use Shlinkio\Shlink\Installer\Config\Plugin\LanguageConfigCustomizer;
|
|
|
|
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
|
2017-12-31 19:14:01 +03:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-07-06 18:20:55 +03:00
|
|
|
|
2017-12-31 19:22:25 +03:00
|
|
|
class LanguageConfigCustomizerTest extends TestCase
|
2017-07-06 18:20:55 +03:00
|
|
|
{
|
|
|
|
/**
|
2017-12-31 19:18:54 +03:00
|
|
|
* @var LanguageConfigCustomizer
|
2017-07-06 18:20:55 +03:00
|
|
|
*/
|
|
|
|
protected $plugin;
|
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
2017-12-31 19:45:27 +03:00
|
|
|
protected $io;
|
2017-07-06 18:20:55 +03:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->io = $this->prophesize(SymfonyStyle::class);
|
|
|
|
$this->io->title(Argument::any())->willReturn(null);
|
|
|
|
$this->plugin = new LanguageConfigCustomizer();
|
2017-07-06 18:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function configIsRequestedToTheUser()
|
|
|
|
{
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('en');
|
2017-07-06 18:20:55 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:20:55 +03:00
|
|
|
|
|
|
|
$this->assertTrue($config->hasLanguage());
|
|
|
|
$this->assertEquals([
|
|
|
|
'DEFAULT' => 'en',
|
|
|
|
'CLI' => 'en',
|
|
|
|
], $config->getLanguage());
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice->shouldHaveBeenCalledTimes(2);
|
2017-07-06 18:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2018-10-06 11:05:25 +03:00
|
|
|
public function onlyMissingOptionsAreAsked()
|
2017-07-06 18:20:55 +03:00
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('es');
|
2017-07-06 18:20:55 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setLanguage([
|
|
|
|
'DEFAULT' => 'en',
|
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:20:55 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
2018-10-06 11:05:25 +03:00
|
|
|
'DEFAULT' => 'en',
|
2017-07-06 18:20:55 +03:00
|
|
|
'CLI' => 'es',
|
|
|
|
], $config->getLanguage());
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice->shouldHaveBeenCalledTimes(1);
|
2017-07-06 18:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2018-10-06 11:05:25 +03:00
|
|
|
public function noQuestionsAskedIfImportedConfigContainsEverything()
|
2017-07-06 18:20:55 +03:00
|
|
|
{
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('en');
|
2017-07-06 18:20:55 +03:00
|
|
|
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setLanguage([
|
|
|
|
'DEFAULT' => 'es',
|
|
|
|
'CLI' => 'es',
|
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:20:55 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'DEFAULT' => 'es',
|
|
|
|
'CLI' => 'es',
|
|
|
|
], $config->getLanguage());
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice->shouldNotHaveBeenCalled();
|
2017-07-06 18:20:55 +03:00
|
|
|
}
|
|
|
|
}
|