protected function NodeTitleFailoverTest::setUp in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/Plugin/freelinking/NodeTitleFailoverTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\NodeTitleFailoverTest::setUp()
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Plugin/ freelinking/ NodeTitleFailoverTest.php, line 34
Class
- NodeTitleFailoverTest
- Tests the failover options for nodetitle plugin.
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');
$this->translationInterfaceMock = $tProphet
->reveal();
// 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([]);
// 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');
$moduleHandlerProphet
->moduleExists('search')
->willReturn(TRUE);
$moduleHandlerProphet
->moduleExists('freelinking_prepopulate')
->willReturn(TRUE);
// Mock Path Validator.
$pathValidatorProphet = $this
->prophesize('\\Drupal\\Core\\Path\\PathValidatorInterface');
$container = new ContainerBuilder();
$container
->set('string_translation', $this->translationInterfaceMock);
$container
->set('entity_type.manager', $entityManagerProphet
->reveal());
$container
->set('path.validator', $pathValidatorProphet
->reveal());
$container
->set('module_handler', $moduleHandlerProphet
->reveal());
\Drupal::setContainer($container);
$this->container = $container;
}