X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdiff%2Ftests%2Fsrc%2FUnit%2FVisualDiffThemeNegotiatorTest.php;fp=web%2Fmodules%2Fcontrib%2Fdiff%2Ftests%2Fsrc%2FUnit%2FVisualDiffThemeNegotiatorTest.php;h=f7a6de896e801d7da2de728e395f0352491f0345;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/diff/tests/src/Unit/VisualDiffThemeNegotiatorTest.php b/web/modules/contrib/diff/tests/src/Unit/VisualDiffThemeNegotiatorTest.php new file mode 100644 index 000000000..f7a6de896 --- /dev/null +++ b/web/modules/contrib/diff/tests/src/Unit/VisualDiffThemeNegotiatorTest.php @@ -0,0 +1,134 @@ +configFactory = $this->prophesize(ConfigFactoryInterface::class); + $this->themeNegotiator = new VisualDiffThemeNegotiator($this->configFactory->reveal()); + } + + /** + * @covers ::determineActiveTheme + */ + public function testDetermineActiveTheme() { + $config = $this->prophesize(ImmutableConfig::class); + $config->get('default')->willReturn('the_default_theme'); + $this->configFactory->get('system.theme')->willReturn($config->reveal()); + + $route_match = $this->prophesize(RouteMatchInterface::class); + $result = $this->themeNegotiator->determineActiveTheme($route_match->reveal()); + $this->assertSame('the_default_theme', $result); + } + + /** + * Tests if the theme negotiator applies under correct conditions. + * + * @param string $filter_parameter + * The filter parameter. + * @param string $route_name + * The route name. + * @param string $config_value + * The configuration value of the element taken from the form values. + * @param bool $expected + * The expected result. + * + * @covers ::applies + * @covers ::isDiffRoute + * + * @dataProvider providerTestApplies + */ + public function testApplies($filter_parameter, $route_name, $config_value, $expected) { + $route_match = $this->prophesize(RouteMatchInterface::class); + $route_match->getParameter('filter')->willReturn($filter_parameter); + + if ($route_name) { + $route_match->getRouteName()->willReturn($route_name); + } + else { + $route_match->getRouteName()->shouldNotBeCalled(); + } + + if ($config_value) { + $diff_config = $this->prophesize(ImmutableConfig::class); + $diff_config->get('general_settings.visual_inline_theme')->willReturn($config_value); + $this->configFactory->get('diff.settings')->willReturn($diff_config->reveal()); + } + else { + $this->configFactory->get('diff.settings')->shouldNotBeCalled(); + } + + $this->assertSame($expected, $this->themeNegotiator->applies($route_match->reveal())); + } + + /** + * Provides test data to ::testApplies(). + */ + public function providerTestApplies() { + $data = []; + $data[] = [ + 'unexpected_filter_parameter', + NULL, + NULL, + FALSE, + ]; + $data[] = [ + 'visual_inline', + 'unexpected_route_name', + NULL, + FALSE, + ]; + $data[] = [ + 'visual_inline', + 'diff.revisions_diff', + 'unexpected_config_value', + FALSE, + ]; + $data[] = [ + 'visual_inline', + 'diff.revisions_diff', + 'default', + TRUE, + ]; + $data[] = [ + 'visual_inline', + 'entity.foo.revisions_diff', + 'default', + TRUE, + ]; + return $data; + } + +}