protected function SortsFunctionalBase::assertPositions in Search API sorts 8
Asserts to position of an array of string in the page result.
An array of positions is passed in here, we check for each of them what their position is in the resulting html of the page.
Parameters
array $params: An array of strings to assert positions for.
2 calls to SortsFunctionalBase::assertPositions()
- HooksTest::testHookDefaultSortsAlter in tests/
src/ Functional/ HooksTest.php - Tests sorting.
- IntegrationTest::testFramework in tests/
src/ Functional/ IntegrationTest.php - Tests sorting.
File
- tests/
src/ Functional/ SortsFunctionalBase.php, line 83
Class
- SortsFunctionalBase
- Base class for sorts web tests.
Namespace
Drupal\Tests\search_api_sorts\FunctionalCode
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]);
}
}
}