SortsFunctionalBase.php in Search API sorts 8
File
tests/src/Functional/SortsFunctionalBase.php
View source
<?php
namespace Drupal\Tests\search_api_sorts\Functional;
use Drupal\search_api\Entity\Index;
use Drupal\Tests\search_api\Functional\ExampleContentTrait;
use Drupal\Tests\search_api\Functional\SearchApiBrowserTestBase;
abstract class SortsFunctionalBase extends SearchApiBrowserTestBase {
use ExampleContentTrait;
protected $displayId;
protected $escapedDisplayId;
public static $modules = [
'block',
'search_api_sorts',
'search_api_test_db',
'search_api_sorts_test_views',
];
public function setUp() : void {
parent::setUp();
$this
->getTestServer();
$this
->getTestIndex();
$this->indexId = 'database_search_index';
$index = Index::load($this->indexId);
\Drupal::state()
->set('search_api_use_tracking_batch', FALSE);
$this
->setUpExampleStructure();
$this
->insertExampleContent();
$this->escapedDisplayId = 'views_page---search_api_sorts_test_view__page_1';
$this->displayId = 'views_page:search_api_sorts_test_view__page_1';
$this
->drupalLogin($this->adminUser);
\Drupal::getContainer()
->get('search_api.index_task_manager')
->addItemsAll($index);
$this
->assertEquals(5, $this
->indexItems($this->indexId));
}
protected function assertPositions(array $params) {
$webAssert = $this
->assertSession();
$pageContent = $this
->getSession()
->getPage()
->getContent();
foreach ($params as $k => $string) {
$webAssert
->responseContains($string);
if ($k > 0) {
$x_position = strpos($pageContent, $params[$k - 1]);
$y_position = strpos($pageContent, $params[$k]);
$this
->assertTrue($x_position < $y_position, 'Position of ' . $params[$k - 1] . ' is before ' . $params[$k]);
}
}
}
}