class VisualDiffThemeNegotiatorTest in Diff 8
Tests theme negotiator.
@coversDefaultClass \Drupal\diff\VisualDiffThemeNegotiator @group diff
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\diff\Unit\VisualDiffThemeNegotiatorTest
Expanded class hierarchy of VisualDiffThemeNegotiatorTest
File
- tests/
src/ Unit/ VisualDiffThemeNegotiatorTest.php, line 17
Namespace
Drupal\Tests\diff\UnitView source
class VisualDiffThemeNegotiatorTest extends UnitTestCase {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $configFactory;
/**
* The class under test.
*
* @var \Drupal\diff\VisualDiffThemeNegotiator
*/
protected $themeNegotiator;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
VisualDiffThemeNegotiatorTest:: |
protected | property | The config factory. | |
VisualDiffThemeNegotiatorTest:: |
protected | property | The class under test. | |
VisualDiffThemeNegotiatorTest:: |
public | function | Provides test data to ::testApplies(). | |
VisualDiffThemeNegotiatorTest:: |
protected | function |
Overrides UnitTestCase:: |
|
VisualDiffThemeNegotiatorTest:: |
public | function | Tests if the theme negotiator applies under correct conditions. | |
VisualDiffThemeNegotiatorTest:: |
public | function | @covers ::determineActiveTheme |