public function SavedSearchCrudTest::testPostSave in Search API Saved Searches 8
Tests the post-save hook for new saved searches.
@covers ::preCreate @covers ::postSave
@dataProvider postSaveDataProvider
Parameters
bool $set_date_field: Whether to set a date field to use for the saved search.
bool $set_query: Whether to set a query on the saved search.
bool $expect_check: Whether a call to \Drupal\search_api_saved_searches\NewResultsCheck::getNewResults() is expected.
File
- tests/
src/ Kernel/ SavedSearchCrudTest.php, line 252
Class
- SavedSearchCrudTest
- Tests CRUD functionality for saved searches.
Namespace
Drupal\Tests\search_api_saved_searches\KernelCode
public function testPostSave($set_date_field, $set_query, $expect_check) {
$index_id = 'test';
if ($set_date_field) {
$options['date_field'][$index_id] = 'created';
SavedSearchType::load('default')
->set('options', $options)
->save();
}
$values = [
'type' => 'default',
];
if ($set_query) {
$query = Index::create([
'id' => $index_id,
])
->query();
$values['query'] = $query;
}
$search = SavedSearch::create($values);
$search
->save();
$method_log = $this->newResultsCheckMethodCalls;
if ($expect_check) {
$this
->assertEquals([
[
$search
->id(),
],
], $method_log->saveKnownResults);
$this
->assertObjectNotHasAttribute('getNewResults', $method_log);
}
else {
$this
->assertObjectNotHasAttribute('saveKnownResults', $method_log);
$this
->assertObjectNotHasAttribute('getNewResults', $method_log);
}
// Re-saving should never trigger a "new results" check.
unset($method_log->getNewResults);
$search
->save();
$this
->assertObjectNotHasAttribute('getNewResults', $method_log);
}