2017-07-06 18:28:32 +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:28:32 +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\UrlShortenerConfigCustomizer;
|
|
|
|
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
|
2017-12-31 19:14:01 +03:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-07-06 18:28:32 +03:00
|
|
|
|
2017-12-31 19:22:25 +03:00
|
|
|
class UrlShortenerConfigCustomizerTest extends TestCase
|
2017-07-06 18:28:32 +03:00
|
|
|
{
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var UrlShortenerConfigCustomizer */
|
2017-07-06 18:28:32 +03:00
|
|
|
private $plugin;
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var ObjectProphecy */
|
2017-12-31 19:45:27 +03:00
|
|
|
private $io;
|
2017-07-06 18:28:32 +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 UrlShortenerConfigCustomizer();
|
2017-07-06 18:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function configIsRequestedToTheUser()
|
|
|
|
{
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('chosen');
|
|
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('asked');
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(true);
|
2017-07-06 18:28:32 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:28:32 +03:00
|
|
|
|
|
|
|
$this->assertTrue($config->hasUrlShortener());
|
|
|
|
$this->assertEquals([
|
2018-10-06 11:05:25 +03:00
|
|
|
'SCHEMA' => 'chosen',
|
|
|
|
'HOSTNAME' => 'asked',
|
|
|
|
'CHARS' => 'asked',
|
2017-12-31 19:45:27 +03:00
|
|
|
'VALIDATE_URL' => true,
|
2018-11-04 14:05:22 +03:00
|
|
|
'ENABLE_NOT_FOUND_REDIRECTION' => true,
|
|
|
|
'NOT_FOUND_REDIRECT_TO' => 'asked',
|
2017-07-06 18:28:32 +03:00
|
|
|
], $config->getUrlShortener());
|
2018-11-04 14:05:22 +03:00
|
|
|
$ask->shouldHaveBeenCalledTimes(3);
|
2018-11-11 15:18:21 +03:00
|
|
|
$choice->shouldHaveBeenCalledOnce();
|
2018-11-04 14:05:22 +03:00
|
|
|
$confirm->shouldHaveBeenCalledTimes(2);
|
2017-07-06 18:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2018-10-06 11:05:25 +03:00
|
|
|
public function onlyMissingOptionsAreAsked()
|
2017-07-06 18:28:32 +03:00
|
|
|
{
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('chosen');
|
|
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('asked');
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
|
2017-07-06 18:28:32 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setUrlShortener([
|
2018-10-06 11:05:25 +03:00
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
2018-11-04 14:05:22 +03:00
|
|
|
'ENABLE_NOT_FOUND_REDIRECTION' => true,
|
|
|
|
'NOT_FOUND_REDIRECT_TO' => 'foo',
|
2017-07-06 18:28:32 +03:00
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:28:32 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
2018-10-06 11:05:25 +03:00
|
|
|
'CHARS' => 'asked',
|
2017-10-17 12:03:12 +03:00
|
|
|
'VALIDATE_URL' => false,
|
2018-11-04 14:05:22 +03:00
|
|
|
'ENABLE_NOT_FOUND_REDIRECTION' => true,
|
|
|
|
'NOT_FOUND_REDIRECT_TO' => 'foo',
|
2017-07-06 18:28:32 +03:00
|
|
|
], $config->getUrlShortener());
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice->shouldNotHaveBeenCalled();
|
2018-11-11 15:18:21 +03:00
|
|
|
$ask->shouldHaveBeenCalledOnce();
|
|
|
|
$confirm->shouldHaveBeenCalledOnce();
|
2017-07-06 18:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2018-10-06 11:05:25 +03:00
|
|
|
public function noQuestionsAskedIfImportedConfigContainsEverything()
|
2017-07-06 18:28:32 +03:00
|
|
|
{
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('chosen');
|
|
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('asked');
|
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
|
2017-07-06 18:28:32 +03:00
|
|
|
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setUrlShortener([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
|
|
|
'CHARS' => 'foo',
|
2018-10-06 11:05:25 +03:00
|
|
|
'VALIDATE_URL' => true,
|
2018-11-04 14:05:22 +03:00
|
|
|
'ENABLE_NOT_FOUND_REDIRECTION' => true,
|
|
|
|
'NOT_FOUND_REDIRECT_TO' => 'foo',
|
2017-07-06 18:28:32 +03:00
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:28:32 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
|
|
|
'CHARS' => 'foo',
|
2018-10-06 11:05:25 +03:00
|
|
|
'VALIDATE_URL' => true,
|
2018-11-04 14:05:22 +03:00
|
|
|
'ENABLE_NOT_FOUND_REDIRECTION' => true,
|
|
|
|
'NOT_FOUND_REDIRECT_TO' => 'foo',
|
2017-07-06 18:28:32 +03:00
|
|
|
], $config->getUrlShortener());
|
2018-10-06 11:05:25 +03:00
|
|
|
$choice->shouldNotHaveBeenCalled();
|
|
|
|
$ask->shouldNotHaveBeenCalled();
|
|
|
|
$confirm->shouldNotHaveBeenCalled();
|
2017-07-06 18:28:32 +03:00
|
|
|
}
|
2018-11-04 14:05:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function redirectUrlOptionIsNotAskedIfAnswerToPreviousQuestionIsNo()
|
|
|
|
{
|
|
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('asked');
|
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
|
|
|
|
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setUrlShortener([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
|
|
|
'CHARS' => 'foo',
|
|
|
|
'VALIDATE_URL' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
|
|
|
|
|
|
|
$this->assertTrue($config->hasUrlShortener());
|
|
|
|
$this->assertEquals([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
|
|
|
'CHARS' => 'foo',
|
|
|
|
'VALIDATE_URL' => true,
|
|
|
|
'ENABLE_NOT_FOUND_REDIRECTION' => false,
|
|
|
|
], $config->getUrlShortener());
|
|
|
|
$ask->shouldNotHaveBeenCalled();
|
2018-11-11 15:18:21 +03:00
|
|
|
$confirm->shouldHaveBeenCalledOnce();
|
2018-11-04 14:05:22 +03:00
|
|
|
}
|
2017-07-06 18:28:32 +03:00
|
|
|
}
|