You are here

protected function AddURLTest::setUp in Search API 8

Creates a new processor object for use in the tests.

Overrides UnitTestCase::setUp

File

tests/src/Unit/Processor/AddURLTest.php, line 41

Class

AddURLTest
Tests the "URL field" processor.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

protected function setUp() {
  parent::setUp();
  $this
    ->setUpMockContainer();

  // Mock the datasource of the indexer to return the mocked url object.
  $datasource = $this
    ->createMock(DatasourceInterface::class);
  $datasource
    ->expects($this
    ->any())
    ->method('getItemUrl')
    ->withAnyParameters()
    ->will($this
    ->returnValue(new TestUrl('/node/example')));

  // Create a mock for the index to return the datasource mock.

  /** @var \Drupal\search_api\IndexInterface $index */
  $index = $this->index = $this
    ->createMock(IndexInterface::class);
  $this->index
    ->expects($this
    ->any())
    ->method('getDatasource')
    ->with('entity:node')
    ->will($this
    ->returnValue($datasource));

  // Create the tested processor and set the mocked indexer.
  $this->processor = new AddURL([], 'add_url', []);
  $this->processor
    ->setIndex($index);

  /** @var \Drupal\Core\StringTranslation\TranslationInterface $translation */
  $translation = $this
    ->getStringTranslationStub();
  $this->processor
    ->setStringTranslation($translation);
}