protected function NodeTitleTest::setUp in Freelinking 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Unit/Plugin/freelinking/NodeTitleTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\NodeTitleTest::setUp()
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Plugin/ freelinking/ NodeTitleTest.php, line 27
Class
- NodeTitleTest
- Tests the nodetitle plugin behavior.
Namespace
Drupal\Tests\freelinking\Unit\Plugin\freelinkingCode
protected function setUp() {
// Mock the translation service.
$tProphet = $this
->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
$tProphet
->translateString(Argument::any())
->willReturn('Click to view a local node');
// Mock Entity Type Manager.
$entityManagerProphet = $this
->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
// Mock Entity Query via Mock Builder to support chaining.
$entityQuery = $this
->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')
->disableOriginalConstructor()
->getMock();
$entityQuery
->expects($this
->any())
->method('condition')
->willReturnSelf();
$entityQuery
->expects($this
->any())
->method('accessCheck')
->willReturnSelf();
$entityQuery
->expects($this
->any())
->method('execute')
->willReturn([
1 => 1,
2 => 2,
]);
// Mock Node Storage.
$nodeStorageProphet = $this
->prophesize('\\Drupal\\node\\NodeStorageInterface');
$nodeStorageProphet
->getQuery('AND')
->willReturn($entityQuery);
// Mock Entity Type Manager getStorage.
$entityManagerProphet
->getStorage('node')
->wilLReturn($nodeStorageProphet
->reveal());
// Mock Module Handler.
$moduleHandlerProphet = $this
->prophesize('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
$container = new ContainerBuilder();
$container
->set('string_translation', $tProphet
->reveal());
$container
->set('entity_type.manager', $entityManagerProphet
->reveal());
$container
->set('module_handler', $moduleHandlerProphet
->reveal());
\Drupal::setContainer($container);
$this->plugin = NodeTitle::create($container, [
'settings' => [
'nodetypes' => [],
'failover' => '',
],
], 'nodetitle', []);
}