3 namespace Drupal\Tests\diff\Unit;
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Config\ImmutableConfig;
7 use Drupal\Core\Routing\RouteMatchInterface;
8 use Drupal\diff\VisualDiffThemeNegotiator;
9 use Drupal\Tests\UnitTestCase;
12 * Tests theme negotiator.
14 * @coversDefaultClass \Drupal\diff\VisualDiffThemeNegotiator
17 class VisualDiffThemeNegotiatorTest extends UnitTestCase {
22 * @var \Drupal\Core\Config\ConfigFactoryInterface|\Prophecy\Prophecy\ProphecyInterface
24 protected $configFactory;
27 * The class under test.
29 * @var \Drupal\diff\VisualDiffThemeNegotiator
31 protected $themeNegotiator;
36 protected function setUp() {
39 $this->configFactory = $this->prophesize(ConfigFactoryInterface::class);
40 $this->themeNegotiator = new VisualDiffThemeNegotiator($this->configFactory->reveal());
44 * @covers ::determineActiveTheme
46 public function testDetermineActiveTheme() {
47 $config = $this->prophesize(ImmutableConfig::class);
48 $config->get('default')->willReturn('the_default_theme');
49 $this->configFactory->get('system.theme')->willReturn($config->reveal());
51 $route_match = $this->prophesize(RouteMatchInterface::class);
52 $result = $this->themeNegotiator->determineActiveTheme($route_match->reveal());
53 $this->assertSame('the_default_theme', $result);
57 * Tests if the theme negotiator applies under correct conditions.
59 * @param string $filter_parameter
60 * The filter parameter.
61 * @param string $route_name
63 * @param string $config_value
64 * The configuration value of the element taken from the form values.
65 * @param bool $expected
66 * The expected result.
69 * @covers ::isDiffRoute
71 * @dataProvider providerTestApplies
73 public function testApplies($filter_parameter, $route_name, $config_value, $expected) {
74 $route_match = $this->prophesize(RouteMatchInterface::class);
75 $route_match->getParameter('filter')->willReturn($filter_parameter);
78 $route_match->getRouteName()->willReturn($route_name);
81 $route_match->getRouteName()->shouldNotBeCalled();
85 $diff_config = $this->prophesize(ImmutableConfig::class);
86 $diff_config->get('general_settings.visual_inline_theme')->willReturn($config_value);
87 $this->configFactory->get('diff.settings')->willReturn($diff_config->reveal());
90 $this->configFactory->get('diff.settings')->shouldNotBeCalled();
93 $this->assertSame($expected, $this->themeNegotiator->applies($route_match->reveal()));
97 * Provides test data to ::testApplies().
99 public function providerTestApplies() {
102 'unexpected_filter_parameter',
109 'unexpected_route_name',
115 'diff.revisions_diff',
116 'unexpected_config_value',
121 'diff.revisions_diff',
127 'entity.foo.revisions_diff',