class AjaxBasePageNegotiatorTest in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Theme/AjaxBasePageNegotiatorTest.php \Drupal\Tests\Core\Theme\AjaxBasePageNegotiatorTest
- 10 core/tests/Drupal/Tests/Core/Theme/AjaxBasePageNegotiatorTest.php \Drupal\Tests\Core\Theme\AjaxBasePageNegotiatorTest
@coversDefaultClass \Drupal\Core\Theme\AjaxBasePageNegotiator @group Theme
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Theme\AjaxBasePageNegotiatorTest
Expanded class hierarchy of AjaxBasePageNegotiatorTest
File
- core/
tests/ Drupal/ Tests/ Core/ Theme/ AjaxBasePageNegotiatorTest.php, line 17
Namespace
Drupal\Tests\Core\ThemeView source
class AjaxBasePageNegotiatorTest extends UnitTestCase {
/**
* @var \Drupal\Core\Theme\AjaxBasePageNegotiator
*
* The AJAX base page negotiator.
*/
protected $negotiator;
/**
* @var \Drupal\Core\Access\CsrfTokenGenerator|\Prophecy\Prophecy\ProphecyInterface
*
* The CSRF token generator.
*/
protected $tokenGenerator;
/**
* @var \Symfony\Component\HttpFoundation\RequestStack
*
* The request stack.
*/
protected $requestStack;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->tokenGenerator = $this
->prophesize(CsrfTokenGenerator::class);
$config_factory = $this
->getConfigFactoryStub([
'system.theme' => [
'default' => 'bartik',
],
]);
$this->requestStack = new RequestStack();
$this->negotiator = new AjaxBasePageNegotiator($this->tokenGenerator
->reveal(), $config_factory, $this->requestStack);
}
/**
* @covers ::applies
* @dataProvider providerTestApplies
*/
public function testApplies($request_data, $expected) {
$request = new Request([], $request_data);
$route_match = RouteMatch::createFromRequest($request);
$this->requestStack
->push($request);
$result = $this->negotiator
->applies($route_match);
$this
->assertSame($expected, $result);
}
public function providerTestApplies() {
$data = [];
$data['empty'] = [
[],
FALSE,
];
$data['no_theme'] = [
[
'ajax_page_state' => [
'theme' => '',
'theme_token' => '',
],
],
FALSE,
];
$data['valid_theme_empty_theme_token'] = [
[
'ajax_page_state' => [
'theme' => 'seven',
'theme_token' => '',
],
],
TRUE,
];
$data['valid_theme_valid_theme_token'] = [
[
'ajax_page_state' => [
'theme' => 'seven',
'theme_token' => 'valid_theme_token',
],
],
TRUE,
];
return $data;
}
/**
* @covers ::determineActiveTheme
*/
public function testDetermineActiveThemeValidToken() {
$theme = 'seven';
$theme_token = 'valid_theme_token';
$request = new Request([], [
'ajax_page_state' => [
'theme' => $theme,
'theme_token' => $theme_token,
],
]);
$this->requestStack
->push($request);
$route_match = RouteMatch::createFromRequest($request);
$this->tokenGenerator
->validate($theme_token, $theme)
->willReturn(TRUE);
$result = $this->negotiator
->determineActiveTheme($route_match);
$this
->assertSame($theme, $result);
}
/**
* @covers ::determineActiveTheme
*/
public function testDetermineActiveThemeInvalidToken() {
$theme = 'seven';
$theme_token = 'invalid_theme_token';
$request = new Request([], [
'ajax_page_state' => [
'theme' => $theme,
'theme_token' => $theme_token,
],
]);
$this->requestStack
->push($request);
$route_match = RouteMatch::createFromRequest($request);
$this->tokenGenerator
->validate($theme_token, $theme)
->willReturn(FALSE);
$result = $this->negotiator
->determineActiveTheme($route_match);
$this
->assertSame(NULL, $result);
}
/**
* @covers ::determineActiveTheme
*/
public function testDetermineActiveThemeDefaultTheme() {
$theme = 'bartik';
// When the theme is the system default, an empty string is provided as the
// theme token. See system_js_settings_alter().
$theme_token = '';
$request = new Request([], [
'ajax_page_state' => [
'theme' => $theme,
'theme_token' => $theme_token,
],
]);
$this->requestStack
->push($request);
$route_match = RouteMatch::createFromRequest($request);
$this->tokenGenerator
->validate(Argument::cetera())
->shouldNotBeCalled();
$result = $this->negotiator
->determineActiveTheme($route_match);
$this
->assertSame($theme, $result);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxBasePageNegotiatorTest:: |
protected | property | The AJAX base page negotiator. | |
AjaxBasePageNegotiatorTest:: |
protected | property | The request stack. | |
AjaxBasePageNegotiatorTest:: |
protected | property | The CSRF token generator. | |
AjaxBasePageNegotiatorTest:: |
public | function | ||
AjaxBasePageNegotiatorTest:: |
public | function |
Overrides UnitTestCase:: |
|
AjaxBasePageNegotiatorTest:: |
public | function | @covers ::applies @dataProvider providerTestApplies | |
AjaxBasePageNegotiatorTest:: |
public | function | @covers ::determineActiveTheme | |
AjaxBasePageNegotiatorTest:: |
public | function | @covers ::determineActiveTheme | |
AjaxBasePageNegotiatorTest:: |
public | function | @covers ::determineActiveTheme | |
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. |