class ContextualLinkDefaultTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php \Drupal\Tests\Core\Menu\ContextualLinkDefaultTest
- 8.9.x core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php \Drupal\Tests\Core\Menu\ContextualLinkDefaultTest
- 10 core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php \Drupal\Tests\Core\Menu\ContextualLinkDefaultTest
@group Menu @coversDefaultClass \Drupal\Core\Menu\ContextualLinkDefault
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Menu\ContextualLinkDefaultTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ContextualLinkDefaultTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Menu/ ContextualLinkDefaultTest.php, line 16
Namespace
Drupal\Tests\Core\MenuView source
class ContextualLinkDefaultTest extends UnitTestCase {
/**
* The tested contextual link default plugin.
*
* @var \Drupal\Core\Menu\ContextualLinkDefault
*/
protected $contextualLinkDefault;
/**
* The used plugin configuration.
*
* @var array
*/
protected $config = [];
/**
* The used plugin ID.
*
* @var string
*/
protected $pluginId = 'contextual_link_default';
/**
* The used plugin definition.
*
* @var array
*/
protected $pluginDefinition = [
'id' => 'contextual_link_default',
];
/**
* The mocked translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->stringTranslation = $this->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
}
protected function setupContextualLinkDefault() : void {
$this->contextualLinkDefault = new ContextualLinkDefault($this->config, $this->pluginId, $this->pluginDefinition);
}
/**
* @covers ::getTitle
*/
public function testGetTitle() : void {
$title = 'Example';
$this->pluginDefinition['title'] = new TranslatableMarkup($title, [], [], $this->stringTranslation);
$this->stringTranslation
->expects($this->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->willReturn('Example translated');
$this->setupContextualLinkDefault();
$this->assertEquals('Example translated', $this->contextualLinkDefault
->getTitle());
}
/**
* @covers ::getTitle
*/
public function testGetTitleWithContext() : void {
$title = 'Example';
$this->pluginDefinition['title'] = new TranslatableMarkup($title, [], [
'context' => 'context',
], $this->stringTranslation);
$this->stringTranslation
->expects($this->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->willReturn('Example translated with context');
$this->setupContextualLinkDefault();
$this->assertEquals('Example translated with context', $this->contextualLinkDefault
->getTitle());
}
/**
* @covers ::getTitle
*/
public function testGetTitleWithTitleArguments() : void {
$title = 'Example @test';
$this->pluginDefinition['title'] = new TranslatableMarkup($title, [
'@test' => 'value',
], [], $this->stringTranslation);
$this->stringTranslation
->expects($this->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->willReturn('Example value');
$this->setupContextualLinkDefault();
$request = new Request();
$this->assertEquals('Example value', $this->contextualLinkDefault
->getTitle($request));
}
/**
* @covers ::getRouteName
*/
public function testGetRouteName($route_name = 'test_route_name') : void {
$this->pluginDefinition['route_name'] = $route_name;
$this->setupContextualLinkDefault();
$this->assertEquals($route_name, $this->contextualLinkDefault
->getRouteName());
}
/**
* @covers ::getGroup
*/
public function testGetGroup($group_name = 'test_group') : void {
$this->pluginDefinition['group'] = $group_name;
$this->setupContextualLinkDefault();
$this->assertEquals($group_name, $this->contextualLinkDefault
->getGroup());
}
/**
* @covers ::getOptions
*/
public function testGetOptions($options = [
'key' => 'value',
]) : void {
$this->pluginDefinition['options'] = $options;
$this->setupContextualLinkDefault();
$this->assertEquals($options, $this->contextualLinkDefault
->getOptions());
}
/**
* @covers ::getWeight
*/
public function testGetWeight($weight = 5) : void {
$this->pluginDefinition['weight'] = $weight;
$this->setupContextualLinkDefault();
$this->assertEquals($weight, $this->contextualLinkDefault
->getWeight());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ContextualLinkDefaultTest::$config | protected | property | The used plugin configuration. | |
ContextualLinkDefaultTest::$contextualLinkDefault | protected | property | The tested contextual link default plugin. | |
ContextualLinkDefaultTest::$pluginDefinition | protected | property | The used plugin definition. | |
ContextualLinkDefaultTest::$pluginId | protected | property | The used plugin ID. | |
ContextualLinkDefaultTest::$stringTranslation | protected | property | The mocked translator. | |
ContextualLinkDefaultTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
ContextualLinkDefaultTest::setupContextualLinkDefault | protected | function | ||
ContextualLinkDefaultTest::testGetGroup | public | function | @covers ::getGroup | |
ContextualLinkDefaultTest::testGetOptions | public | function | @covers ::getOptions | |
ContextualLinkDefaultTest::testGetRouteName | public | function | @covers ::getRouteName | |
ContextualLinkDefaultTest::testGetTitle | public | function | @covers ::getTitle | |
ContextualLinkDefaultTest::testGetTitleWithContext | public | function | @covers ::getTitle | |
ContextualLinkDefaultTest::testGetTitleWithTitleArguments | public | function | @covers ::getTitle | |
ContextualLinkDefaultTest::testGetWeight | public | function | @covers ::getWeight | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.