You are here

private function NodeExcludeTest::createNode in Search API exclude 8

Creates a node for testing.

Parameters

mixed $exclude: The value of the sae_exclude-field.

Return value

\PHPUnit\Framework\MockObject\MockObject The mocked node.

1 call to NodeExcludeTest::createNode()
NodeExcludeTest::testAlterItems in tests/src/Unit/Plugin/Processor/NodeExcludeTest.php
Tests if nodes, which are configured to be excluded, are removed.

File

tests/src/Unit/Plugin/Processor/NodeExcludeTest.php, line 143

Class

NodeExcludeTest
Tests the "Node exclude" processor.

Namespace

Drupal\Tests\search_api_exclude\Unit\Plugin\Processor

Code

private function createNode($exclude) {
  $nodeType = $this
    ->getMockBuilder(NodeType::class)
    ->disableOriginalConstructor()
    ->getMock();
  $nodeType
    ->method('getThirdPartySetting')
    ->with('search_api_exclude', 'enabled', FALSE)
    ->will($this
    ->returnValue(TRUE));
  $entityReferenceList = $this
    ->getMockBuilder(EntityReferenceFieldItemList::class)
    ->disableOriginalConstructor()
    ->getMock();
  $entityReferenceList
    ->method('__get')
    ->with('entity')
    ->will($this
    ->returnValue($nodeType));
  $field_item_list = $this
    ->getMockBuilder(FieldItemList::class)
    ->disableOriginalConstructor()
    ->getMock();
  $field_item_list
    ->method('getString')
    ->will($this
    ->returnValue($exclude));
  $node = $this
    ->getMockBuilder(Node::class)
    ->disableOriginalConstructor()
    ->getMock();
  $node
    ->method('__get')
    ->with('type')
    ->will($this
    ->returnValue($entityReferenceList));
  $node
    ->method('get')
    ->with('sae_exclude')
    ->will($this
    ->returnValue($field_item_list));
  return $node;
}