You are here

protected function NodeTest::setUp in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Plugin/freelinking/NodeTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\NodeTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/Plugin/freelinking/NodeTest.php, line 42

Class

NodeTest
Tests the nid plugin.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

protected function setUp() {

  // Mock string translation interface.
  $tProphet = $this
    ->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
  $tProphet
    ->translateString(Argument::any())
    ->willReturn('Click to view a local node.');
  $this->translationInterfaceMock = $tProphet
    ->reveal();

  // Mock node entity.
  $nodeProphet = $this
    ->prophesize('\\Drupal\\node\\Entity\\Node');
  $nodeProphet
    ->id()
    ->willReturn(1);
  $nodeProphet
    ->label()
    ->willReturn('Test Node');
  $nodeProphet
    ->language()
    ->willReturn(self::getDefaultLanguage());

  // Mock node storage interface.
  $nodeStorageProphet = $this
    ->prophesize('\\Drupal\\node\\NodeStorageInterface');
  $nodeStorageProphet
    ->load(1)
    ->willReturn($nodeProphet
    ->reveal());
  $nodeStorageProphet
    ->load(2)
    ->willReturn(NULL);

  // Mock entity type manager.
  $entityManagerProphet = $this
    ->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
  $entityManagerProphet
    ->getStorage('node')
    ->willReturn($nodeStorageProphet
    ->reveal());
  $container = new ContainerBuilder();
  $container
    ->set('entity_type.manager', $entityManagerProphet
    ->reveal());
  $container
    ->set('string_translation', $this->translationInterfaceMock);
  \Drupal::setContainer($container);
  $this->container = $container;
  $plugin_definition = [
    'id' => 'nid',
    'title' => 'Node ID',
    'hidden' => FALSE,
    'weight' => 0,
    'settings' => [],
  ];
  $this->plugin = Node::create($container, [], 'nid', $plugin_definition);
}