View source
<?php
namespace Drupal\Tests\search_api\Functional;
use Drupal\search_api\Entity\Index;
use Drupal\search_api_test\PluginTestTrait;
class EventsTest extends SearchApiBrowserTestBase {
use PluginTestTrait;
public static $modules = [
'node',
'rest',
'search_api',
'search_api_test',
'search_api_test_views',
'search_api_test_events',
];
protected $server;
public function setUp() {
parent::setUp();
$this
->drupalCreateNode([
'type' => 'page',
'title' => 'node - 1',
]);
$this
->drupalCreateNode([
'type' => 'page',
'title' => 'node - 2',
]);
$this
->drupalCreateNode([
'type' => 'page',
'title' => 'node - 3',
]);
$this
->drupalCreateNode([
'type' => 'page',
'title' => 'node - 4',
]);
$this->server = $this
->getTestServer();
$index = $this
->getTestIndex();
$processor = \Drupal::getContainer()
->get('search_api.plugin_helper')
->createProcessorPlugin($index, 'search_api_test');
$index
->addProcessor($processor)
->save();
$index = Index::load('database_search_index');
$processor = \Drupal::getContainer()
->get('search_api.plugin_helper')
->createProcessorPlugin($index, 'search_api_test');
$index
->addProcessor($processor)
->save();
$this
->getCalledMethods('processor');
$this
->drupalLogin($this->adminUser);
}
public function testEvents() {
$this
->drupalGet('admin/config/search/search-api/add-server');
$this
->assertSession()
->pageTextContains('Slims return');
$this
->drupalGet('admin/config/search/search-api/add-index');
$this
->assertSession()
->pageTextContains('Distant land');
$this
->assertSession()
->pageTextContains('Good luck');
$this
->drupalGet($this
->getIndexPath('processors'));
$this
->assertSession()
->pageTextContains('Mystic bounce');
$definition = \Drupal::getContainer()
->get('plugin.manager.search_api.parse_mode')
->getDefinition('direct');
$this
->assertEquals('Song for My Father', $definition['label']);
$this
->submitForm([], 'Save');
$processor_methods = $this
->getCalledMethods('processor');
$this
->assertEquals([
'preIndexSave',
], $processor_methods);
$this
->drupalGet($this
->getIndexPath());
$this
->submitForm([], 'Index now');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('Successfully indexed 4 items.');
$processor_methods = $this
->getCalledMethods('processor');
$expected = [
'alterIndexedItems',
'preprocessIndexItems',
];
$this
->assertEquals($expected, $processor_methods);
$this
->assertSession()
->pageTextContains('There are 2 items indexed on the server for this index.');
$this
->assertSession()
->pageTextContains('Stormy');
$this
->assertSession()
->pageTextContains('Please set me at ease');
$this
->drupalGet($this
->getIndexPath('reindex'));
$this
->submitForm([], 'Confirm');
$this
->assertSession()
->pageTextContains('Montara');
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->assertSession()
->pageTextContains('Peace/Dolphin dance');
$url_options['query']['datasource'] = 'entity:node';
$this
->drupalGet($this
->getIndexPath('fields/add/nojs'), $url_options);
$this
->assertSession()
->pageTextContains('Add fields to index');
$this
->assertSession()
->pageTextNotContains('timestamp');
$this
->drupalGet('search-api-test');
$this
->assertSession()
->pageTextContains('Search id: views_page:search_api_test_view__page_1');
$this
->assertSession()
->pageTextContains('Funky blue note');
$this
->assertSession()
->pageTextContains('Freeland');
$this
->assertSession()
->pageTextContains('Stepping into tomorrow');
$this
->assertSession()
->pageTextContains('Llama');
$processor_methods = $this
->getCalledMethods('processor');
$expected = [
'preprocessSearchQuery',
'postprocessSearchResults',
];
$this
->assertEquals($expected, $processor_methods);
$this
->assertTrue($this->server
->supportsFeature('welcome_to_the_jungle'));
$displays = \Drupal::getContainer()
->get('plugin.manager.search_api.display')
->getInstances();
$display_label = $displays['views_page:search_api_test_view__page_1']
->label();
$this
->assertEquals('Some funny label for testing', $display_label);
}
}