Improved UrlShortenerConfigCustomizerTest covering new config options

This commit is contained in:
Alejandro Celaya 2018-11-04 12:05:22 +01:00
parent 057f88a36a
commit a71245b883

View File

@ -46,10 +46,12 @@ class UrlShortenerConfigCustomizerTest extends TestCase
'HOSTNAME' => 'asked', 'HOSTNAME' => 'asked',
'CHARS' => 'asked', 'CHARS' => 'asked',
'VALIDATE_URL' => true, 'VALIDATE_URL' => true,
'ENABLE_NOT_FOUND_REDIRECTION' => true,
'NOT_FOUND_REDIRECT_TO' => 'asked',
], $config->getUrlShortener()); ], $config->getUrlShortener());
$ask->shouldHaveBeenCalledTimes(2); $ask->shouldHaveBeenCalledTimes(3);
$choice->shouldHaveBeenCalledTimes(1); $choice->shouldHaveBeenCalledTimes(1);
$confirm->shouldHaveBeenCalledTimes(1); $confirm->shouldHaveBeenCalledTimes(2);
} }
/** /**
@ -64,6 +66,8 @@ class UrlShortenerConfigCustomizerTest extends TestCase
$config->setUrlShortener([ $config->setUrlShortener([
'SCHEMA' => 'foo', 'SCHEMA' => 'foo',
'HOSTNAME' => 'foo', 'HOSTNAME' => 'foo',
'ENABLE_NOT_FOUND_REDIRECTION' => true,
'NOT_FOUND_REDIRECT_TO' => 'foo',
]); ]);
$this->plugin->process($this->io->reveal(), $config); $this->plugin->process($this->io->reveal(), $config);
@ -73,6 +77,8 @@ class UrlShortenerConfigCustomizerTest extends TestCase
'HOSTNAME' => 'foo', 'HOSTNAME' => 'foo',
'CHARS' => 'asked', 'CHARS' => 'asked',
'VALIDATE_URL' => false, 'VALIDATE_URL' => false,
'ENABLE_NOT_FOUND_REDIRECTION' => true,
'NOT_FOUND_REDIRECT_TO' => 'foo',
], $config->getUrlShortener()); ], $config->getUrlShortener());
$choice->shouldNotHaveBeenCalled(); $choice->shouldNotHaveBeenCalled();
$ask->shouldHaveBeenCalledTimes(1); $ask->shouldHaveBeenCalledTimes(1);
@ -94,6 +100,8 @@ class UrlShortenerConfigCustomizerTest extends TestCase
'HOSTNAME' => 'foo', 'HOSTNAME' => 'foo',
'CHARS' => 'foo', 'CHARS' => 'foo',
'VALIDATE_URL' => true, 'VALIDATE_URL' => true,
'ENABLE_NOT_FOUND_REDIRECTION' => true,
'NOT_FOUND_REDIRECT_TO' => 'foo',
]); ]);
$this->plugin->process($this->io->reveal(), $config); $this->plugin->process($this->io->reveal(), $config);
@ -103,9 +111,41 @@ class UrlShortenerConfigCustomizerTest extends TestCase
'HOSTNAME' => 'foo', 'HOSTNAME' => 'foo',
'CHARS' => 'foo', 'CHARS' => 'foo',
'VALIDATE_URL' => true, 'VALIDATE_URL' => true,
'ENABLE_NOT_FOUND_REDIRECTION' => true,
'NOT_FOUND_REDIRECT_TO' => 'foo',
], $config->getUrlShortener()); ], $config->getUrlShortener());
$choice->shouldNotHaveBeenCalled(); $choice->shouldNotHaveBeenCalled();
$ask->shouldNotHaveBeenCalled(); $ask->shouldNotHaveBeenCalled();
$confirm->shouldNotHaveBeenCalled(); $confirm->shouldNotHaveBeenCalled();
} }
/**
* @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();
$confirm->shouldHaveBeenCalledTimes(1);
}
} }