public function ScannerWithLinkTestCase::testSearch in Search and Replace Scanner 7
Make sure the basic search functionality works.
Overrides ScannerBasicsTestCase::testSearch
File
- tests/
ScannerWithLinkTestCase.test, line 70 - Test integration with Link.
Class
- ScannerWithLinkTestCase
- Test integration with Link.
Code
public function testSearch() {
$search_or = db_or()
->condition('field_links_title', '%' . db_like($this->searchWord) . '%', 'LIKE')
->condition('field_links_url', '%' . db_like($this->searchWord) . '%', 'LIKE');
$replace_or = db_or()
->condition('field_links_title', '%' . db_like($this->replaceWord) . '%', 'LIKE')
->condition('field_links_url', '%' . db_like($this->replaceWord) . '%', 'LIKE');
// Look for 'link' data that contains the search word.
$pre_search_count = db_select('field_data_field_links', 'l')
->fields('l', array(
'entity_type',
'entity_id',
'delta',
))
->condition($search_or)
->execute()
->rowCount();
// Look for 'link' data that contains the replacement word.
$pre_replace_count = db_select('field_data_field_links', 'l')
->fields('l', array(
'entity_type',
'entity_id',
'delta',
))
->condition($replace_or)
->execute()
->rowCount();
$this
->assertNotEqual($pre_search_count, $pre_replace_count, 'Search word count and Replace word count not the same');
$this
->assertNotEqual($pre_search_count, 0, 'Search word count is not zero');
$this
->assertEqual($pre_replace_count, 0, 'Replace word count is zero');
// Run the parent tests.
parent::testSearch();
// Look for 'link' data that contains the search word.
$post_search_count = db_select('field_data_field_links', 'l')
->fields('l')
->condition($search_or)
->execute()
->rowCount();
// Look for 'link' data that contains the replacement word.
$post_replace_count = db_select('field_data_field_links', 'l')
->fields('l')
->condition($replace_or)
->execute()
->rowCount();
$this
->assertNotEqual($pre_search_count, $post_search_count, 'Pre and post Search word count are not the same');
$this
->assertNotEqual($pre_replace_count, $post_replace_count, 'Pre and post Replace word count are not the same');
$this
->assertNotEqual($post_search_count, $post_replace_count, 'Search word count and Replace word count not the same');
$this
->assertEqual($post_search_count, 0, 'Search word count is zero');
$this
->assertNotEqual($post_replace_count, 0, 'Replace word count is not zero');
}