protected function SearchApiWebTest::indexItems in Search API 7
Tests indexing via the UI "Index now" functionality.
Asserts that errors during indexing are handled properly and that the status readings work.
1 call to SearchApiWebTest::indexItems()
- SearchApiWebTest::testFramework in ./
search_api.test - Tests correct admin UI, indexing and search behavior.
File
- ./
search_api.test, line 391 - Contains the SearchApiWebTest and the SearchApiUnitTest classes.
Class
- SearchApiWebTest
- Class for testing Search API functionality via the UI.
Code
protected function indexItems() {
$this
->checkIndexStatus();
// Here we test the indexing + the warning message when some items
// cannot be indexed.
// The server refuses (for test purpose) to index the item that has the same
// ID as the "search_api_test_indexing_break" variable (default: 8).
// Therefore, if we try to index 8 items, only the first seven will be
// successfully indexed and a warning should be displayed.
$values = array(
'limit' => 8,
);
$this
->drupalPost(NULL, $values, t('Index now'));
$this
->assertText(t('Successfully indexed @count items.', array(
'@count' => 7,
)));
$this
->assertText(t('1 item could not be indexed. Check the logs for details.'), 'Index errors warning is displayed.');
$this
->assertNoText(t("Couldn't index items. Check the logs for details."), "Index error isn't displayed.");
$this
->checkIndexStatus(7);
// Here we're testing the error message when no item could be indexed.
// The item with ID 8 is still not indexed, but it will be the first to be
// indexed now. Therefore, if we try to index a single items, only item 8
// will be passed to the server, which will reject it and no items will be
// indexed. Since normally this signifies a more serious error than when
// only some items couldn't be indexed, this is handled differently.
$values = array(
'limit' => 1,
);
$this
->drupalPost(NULL, $values, t('Index now'));
$this
->assertNoPattern('/' . str_replace('144', '-?\\d*', t('Successfully indexed @count items.', array(
'@count' => 144,
))) . '/', 'No items could be indexed.');
$this
->assertNoText(t('1 item could not be indexed. Check the logs for details.'), "Index errors warning isn't displayed.");
$this
->assertText(t("Couldn't index items. Check the logs for details."), 'Index error is displayed.');
// No we set the "search_api_test_indexing_break" variable to 0, so all
// items will be indexed. The remaining items (8, 9, 10) should therefore
// be successfully indexed and no warning should show.
variable_set('search_api_test_indexing_break', 0);
$values = array(
'limit' => -1,
);
$this
->drupalPost(NULL, $values, t('Index now'));
$this
->assertText(t('Successfully indexed @count items.', array(
'@count' => 3,
)));
$this
->assertNoText(t("Some items couldn't be indexed. Check the logs for details."), "Index errors warning isn't displayed.");
$this
->assertNoText(t("Couldn't index items. Check the logs for details."), "Index error isn't displayed.");
$this
->checkIndexStatus(10);
// Reset the static cache for the server.
$this
->server();
}