class LocalActionDefaultTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php \Drupal\Tests\Core\Menu\LocalActionDefaultTest
- 8.9.x core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php \Drupal\Tests\Core\Menu\LocalActionDefaultTest
- 11.x core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php \Drupal\Tests\Core\Menu\LocalActionDefaultTest
@coversDefaultClass \Drupal\Core\Menu\LocalActionDefault @group Menu
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Menu\LocalActionDefaultTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of LocalActionDefaultTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Menu/ LocalActionDefaultTest.php, line 16
Namespace
Drupal\Tests\Core\MenuView source
class LocalActionDefaultTest extends UnitTestCase {
/**
* The tested local action default plugin.
*
* @var \Drupal\Core\Menu\LocalActionDefault
*/
protected $localActionDefault;
/**
* The used plugin configuration.
*
* @var array
*/
protected $config = [];
/**
* The used plugin ID.
*
* @var string
*/
protected $pluginId = 'local_action_default';
/**
* The used plugin definition.
*
* @var array
*/
protected $pluginDefinition = [
'id' => 'local_action_default',
];
/**
* The mocked translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* The mocked route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $routeProvider;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->stringTranslation = $this->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
$this->routeProvider = $this->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
}
/**
* Setups the local action default.
*/
protected function setupLocalActionDefault() {
$this->localActionDefault = new LocalActionDefault($this->config, $this->pluginId, $this->pluginDefinition, $this->routeProvider);
}
/**
* Tests the getTitle method without a translation context.
*
* @see \Drupal\Core\Menu\LocalTaskDefault::getTitle()
*/
public function testGetTitle() : void {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example', [], [], $this->stringTranslation);
$this->stringTranslation
->expects($this->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->willReturn('Example translated');
$this->setupLocalActionDefault();
$this->assertEquals('Example translated', $this->localActionDefault
->getTitle());
}
/**
* Tests the getTitle method with a translation context.
*
* @see \Drupal\Core\Menu\LocalTaskDefault::getTitle()
*/
public function testGetTitleWithContext() : void {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example', [], [
'context' => 'context',
], $this->stringTranslation);
$this->stringTranslation
->expects($this->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->willReturn('Example translated with context');
$this->setupLocalActionDefault();
$this->assertEquals('Example translated with context', $this->localActionDefault
->getTitle());
}
/**
* Tests the getTitle method with title arguments.
*/
public function testGetTitleWithTitleArguments() : void {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example @test', [
'@test' => 'value',
], [], $this->stringTranslation);
$this->stringTranslation
->expects($this->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->willReturn('Example value');
$this->setupLocalActionDefault();
$request = new Request();
$this->assertEquals('Example value', $this->localActionDefault
->getTitle($request));
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
LocalActionDefaultTest::$config | protected | property | The used plugin configuration. | |||
LocalActionDefaultTest::$localActionDefault | protected | property | The tested local action default plugin. | |||
LocalActionDefaultTest::$pluginDefinition | protected | property | The used plugin definition. | |||
LocalActionDefaultTest::$pluginId | protected | property | The used plugin ID. | |||
LocalActionDefaultTest::$routeProvider | protected | property | The mocked route provider. | |||
LocalActionDefaultTest::$stringTranslation | protected | property | The mocked translator. | |||
LocalActionDefaultTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
LocalActionDefaultTest::setupLocalActionDefault | protected | function | Setups the local action default. | |||
LocalActionDefaultTest::testGetTitle | public | function | Tests the getTitle method without a translation context. | |||
LocalActionDefaultTest::testGetTitleWithContext | public | function | Tests the getTitle method with a translation context. | |||
LocalActionDefaultTest::testGetTitleWithTitleArguments | public | function | Tests the getTitle method with title arguments. | |||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
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. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
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 | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.