class HelpTopicTwigTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/help_topics/tests/src/Unit/HelpTopicTwigTest.php \Drupal\Tests\help_topics\Unit\HelpTopicTwigTest
- 10 core/modules/help_topics/tests/src/Unit/HelpTopicTwigTest.php \Drupal\Tests\help_topics\Unit\HelpTopicTwigTest
Unit test for the HelpTopicTwig class.
Note that the toUrl() and toLink() methods are not covered, because they have calls to new Url() and new Link() in them, so they cannot be unit tested.
@coversDefaultClass \Drupal\help_topics\HelpTopicTwig @group help_topics
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\help_topics\Unit\HelpTopicTwigTest
Expanded class hierarchy of HelpTopicTwigTest
File
- core/
modules/ help_topics/ tests/ src/ Unit/ HelpTopicTwigTest.php, line 19
Namespace
Drupal\Tests\help_topics\UnitView source
class HelpTopicTwigTest extends UnitTestCase {
/**
* The help topic instance to test.
*
* @var \Drupal\help_topics\HelpTopicTwig
*/
protected $helpTopic;
/**
* The plugin information to use for setting up a test topic.
*
* @var array
*/
const PLUGIN_INFORMATION = [
'id' => 'test.topic',
'provider' => 'test',
'label' => 'This is the topic label',
'top_level' => TRUE,
'related' => [
'something',
],
'body' => '<p>This is the topic body</p>',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->helpTopic = new HelpTopicTwig([], self::PLUGIN_INFORMATION['id'], self::PLUGIN_INFORMATION, $this
->getTwigMock());
}
/**
* @covers ::getBody
* @covers ::getLabel
*/
public function testText() {
$this
->assertEquals($this->helpTopic
->getBody(), [
'#markup' => self::PLUGIN_INFORMATION['body'],
]);
$this
->assertEquals($this->helpTopic
->getLabel(), self::PLUGIN_INFORMATION['label']);
}
/**
* @covers ::getProvider
* @covers ::isTopLevel
* @covers ::getRelated
*/
public function testDefinition() {
$this
->assertEquals($this->helpTopic
->getProvider(), self::PLUGIN_INFORMATION['provider']);
$this
->assertEquals($this->helpTopic
->isTopLevel(), self::PLUGIN_INFORMATION['top_level']);
$this
->assertEquals($this->helpTopic
->getRelated(), self::PLUGIN_INFORMATION['related']);
}
/**
* @covers ::getCacheContexts
* @covers ::getCacheTags
* @covers ::getCacheMaxAge
*/
public function testCacheInfo() {
$this
->assertEquals($this->helpTopic
->getCacheContexts(), []);
$this
->assertEquals($this->helpTopic
->getCacheTags(), [
'core.extension',
]);
$this
->assertEquals($this->helpTopic
->getCacheMaxAge(), Cache::PERMANENT);
}
/**
* Creates a mock Twig loader class for the test.
*/
protected function getTwigMock() {
$twig = $this
->getMockBuilder('Drupal\\Core\\Template\\TwigEnvironment')
->disableOriginalConstructor()
->getMock();
$twig
->method('load')
->willReturn(new FakeTemplateWrapper(self::PLUGIN_INFORMATION['body']));
return $twig;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HelpTopicTwigTest:: |
protected | property | The help topic instance to test. | |
HelpTopicTwigTest:: |
protected | function | Creates a mock Twig loader class for the test. | |
HelpTopicTwigTest:: |
constant | The plugin information to use for setting up a test topic. | ||
HelpTopicTwigTest:: |
protected | function |
Overrides UnitTestCase:: |
|
HelpTopicTwigTest:: |
public | function | @covers ::getCacheContexts @covers ::getCacheTags @covers ::getCacheMaxAge | |
HelpTopicTwigTest:: |
public | function | @covers ::getProvider @covers ::isTopLevel @covers ::getRelated | |
HelpTopicTwigTest:: |
public | function | @covers ::getBody @covers ::getLabel | |
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. |