public function SmartReadMoreLinkUnitTest::testWhenTeaserMatchesFull in Smart read more link 8
Test no link is generated when teaser and full views match.
File
- tests/
src/ Unit/ SmartReadMoreLinkUnitTest.php, line 71
Class
- SmartReadMoreLinkUnitTest
- Unit tests of smart_read_more_link module.
Namespace
Drupal\Tests\smart_read_more_link\UnitCode
public function testWhenTeaserMatchesFull() {
$field_definition = $this
->getMockBuilder(FieldDefinitionInterface::class)
->getMock();
$base_formatter = $this
->getMockBuilder(FormatterBase::class)
->disableOriginalConstructor()
->getMock();
$random_string1 = $this
->getRandomGenerator()
->string(20);
$default_formatter = $this
->getMockBuilder(FormatterBase::class)
->disableOriginalConstructor()
->getMock();
$formatter_manager = $this
->getMockBuilder(PluginManagerInterface::class)
->getMock();
$formatter_manager
->method('createInstance')
->willReturnCallback(static function ($plugin_id) use ($default_formatter, $base_formatter) {
if ($plugin_id === 'text_summary_or_trimmed') {
return $base_formatter;
}
else {
return $default_formatter;
}
});
$renderer = $this
->getMockBuilder(RendererInterface::class)
->getMock();
// Rendered view is constant.
$renderer
->method('render')
->willReturn($random_string1);
$formatter = new SmartReadMoreLinkFormatter('smart_read_more_link', [], $field_definition, [], 'Field label', 'view_mode', [], $formatter_manager, $renderer);
$items = $this
->getMockBuilder(FieldItemListInterface::class)
->getMock();
$result = $formatter
->viewElements($items, 'und');
// @todo be more thorough about this
$this
->assertEmpty($result[0]['links'], 'no link in output');
}