123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091 |
- <?php
- define('SEARCH_TYPE', '_test_');
- define('SEARCH_TYPE_2', '_test2_');
- define('SEARCH_TYPE_JPN', '_test3_');
- class SearchMatchTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search engine queries',
- 'description' => 'Indexes content and queries it.',
- 'group' => 'Search',
- );
- }
-
- function setUp() {
- parent::setUp('search');
- }
-
- function testMatching() {
- $this->_setup();
- $this->_testQueries();
- }
-
- function _setup() {
- variable_set('minimum_word_size', 3);
- for ($i = 1; $i <= 7; ++$i) {
- search_index($i, SEARCH_TYPE, $this->getText($i));
- }
- for ($i = 1; $i <= 5; ++$i) {
- search_index($i + 7, SEARCH_TYPE_2, $this->getText2($i));
- }
-
- foreach (array(
- 13 => '以呂波耳・ほへとち。リヌルヲ。',
- 14 => 'ドルーパルが大好きよ!',
- 15 => 'コーヒーとケーキ',
- ) as $i => $jpn) {
- search_index($i, SEARCH_TYPE_JPN, $jpn);
- }
- search_update_totals();
- }
-
- function getText($n) {
- $words = explode(' ', "Ipsum dolore sit am. Ut enim am minim veniam. Es cillum dolore eu.");
- return implode(' ', array_slice($words, $n - 1, $n));
- }
-
- function getText2($n) {
- $words = explode(' ', "Dear King Philip came over from Germany swimming.");
- return implode(' ', array_slice($words, $n - 1, $n));
- }
-
- function _testQueries() {
-
- $queries = array(
-
- 'ipsum' => array(1),
- 'enim' => array(4, 5, 6),
- 'xxxxx' => array(),
- 'enim minim' => array(5, 6),
- 'enim xxxxx' => array(),
- 'dolore eu' => array(7),
- 'dolore xx' => array(),
- 'ut minim' => array(5),
- 'xx minim' => array(),
- 'enim veniam am minim ut' => array(5),
-
- 'dolore OR ipsum' => array(1, 2, 7),
- 'dolore OR xxxxx' => array(2, 7),
- 'dolore OR ipsum OR enim' => array(1, 2, 4, 5, 6, 7),
- 'ipsum OR dolore sit OR cillum' => array(2, 7),
- 'minim dolore OR ipsum' => array(7),
- 'dolore OR ipsum veniam' => array(7),
- 'minim dolore OR ipsum OR enim' => array(5, 6, 7),
- 'dolore xx OR yy' => array(),
- 'xxxxx dolore OR ipsum' => array(),
-
- 'dolore -sit' => array(7),
- 'dolore -eu' => array(2),
- 'dolore -xxxxx' => array(2, 7),
- 'dolore -xx' => array(2, 7),
-
- '"dolore sit"' => array(2),
- '"sit dolore"' => array(),
- '"am minim veniam es"' => array(6, 7),
- '"minim am veniam es"' => array(),
-
- '"am minim veniam es" OR dolore' => array(2, 6, 7),
- '"minim am veniam es" OR "dolore sit"' => array(2),
- '"minim am veniam es" OR "sit dolore"' => array(),
- '"am minim veniam es" -eu' => array(6),
- '"am minim veniam" -"cillum dolore"' => array(5, 6),
- '"am minim veniam" -"dolore cillum"' => array(5, 6, 7),
- 'xxxxx "minim am veniam es" OR dolore' => array(),
- 'xx "minim am veniam es" OR dolore' => array()
- );
- foreach ($queries as $query => $results) {
- $result = db_select('search_index', 'i')
- ->extend('SearchQuery')
- ->searchExpression($query, SEARCH_TYPE)
- ->execute();
- $set = $result ? $result->fetchAll() : array();
- $this->_testQueryMatching($query, $set, $results);
- $this->_testQueryScores($query, $set, $results);
- }
-
- $queries = array(
-
- 'ipsum' => array(),
- 'enim' => array(),
- 'enim minim' => array(),
- 'dear' => array(8),
- 'germany' => array(11, 12),
- );
- foreach ($queries as $query => $results) {
- $result = db_select('search_index', 'i')
- ->extend('SearchQuery')
- ->searchExpression($query, SEARCH_TYPE_2)
- ->execute();
- $set = $result ? $result->fetchAll() : array();
- $this->_testQueryMatching($query, $set, $results);
- $this->_testQueryScores($query, $set, $results);
- }
-
- $queries = array(
-
- '呂波耳' => array(13),
- '以呂波耳' => array(13),
- 'ほへと ヌルヲ' => array(13),
- 'とちリ' => array(),
- 'ドルーパル' => array(14),
- 'パルが大' => array(14),
- 'コーヒー' => array(15),
- 'ヒーキ' => array(),
- );
- foreach ($queries as $query => $results) {
- $result = db_select('search_index', 'i')
- ->extend('SearchQuery')
- ->searchExpression($query, SEARCH_TYPE_JPN)
- ->execute();
- $set = $result ? $result->fetchAll() : array();
- $this->_testQueryMatching($query, $set, $results);
- $this->_testQueryScores($query, $set, $results);
- }
- }
-
- function _testQueryMatching($query, $set, $results) {
-
- $found = array();
- foreach ($set as $item) {
- $found[] = $item->sid;
- }
-
- sort($found);
- sort($results);
- $this->assertEqual($found, $results, "Query matching '$query'");
- }
-
- function _testQueryScores($query, $set, $results) {
-
- $scores = array();
- foreach ($set as $item) {
- $scores[] = $item->calculated_score;
- }
-
- $sorted = $scores;
- sort($sorted);
- $this->assertEqual($scores, array_reverse($sorted), "Query order '$query'");
-
- $this->assertEqual(!count($scores) || (min($scores) > 0.0 && max($scores) <= 1.0001), TRUE, "Query scoring '$query'");
- }
- }
- class SearchPageText extends DrupalWebTestCase {
- protected $searching_user;
- public static function getInfo() {
- return array(
- 'name' => 'Search page text',
- 'description' => 'Tests the bike shed text on the no results page, and various other text on search pages.',
- 'group' => 'Search'
- );
- }
- function setUp() {
- parent::setUp('search');
-
- $this->searching_user = $this->drupalCreateUser(array('search content', 'access user profiles'));
- }
-
- function testSearchText() {
- $this->drupalLogin($this->searching_user);
- $this->drupalGet('search/node');
- $this->assertText(t('Enter your keywords'));
- $this->assertText(t('Search'));
- $title = t('Search') . ' | Drupal';
- $this->assertTitle($title, 'Search page title is correct');
- $edit = array();
- $edit['keys'] = 'bike shed ' . $this->randomName();
- $this->drupalPost('search/node', $edit, t('Search'));
- $this->assertText(t('Consider loosening your query with OR. bike OR shed will often show more results than bike shed.'), 'Help text is displayed when search returns no results.');
- $this->assertText(t('Search'));
- $this->assertTitle($title, 'Search page title is correct');
- $edit['keys'] = $this->searching_user->name;
- $this->drupalPost('search/user', $edit, t('Search'));
- $this->assertText(t('Search'));
- $this->assertTitle($title, 'Search page title is correct');
-
-
- $arg = $this->randomName() . '/' . $this->randomName();
- $this->drupalGet('search/node/' . $arg);
- $input = $this->xpath("//input[@id='edit-keys' and @value='{$arg}']");
- $this->assertFalse(empty($input), 'Search keys with a / are correctly set as the default value in the search box.');
-
-
- $limit = variable_get('search_and_or_limit', 7);
- $keys = array();
- for ($i = 0; $i < $limit + 1; $i++) {
- $keys[] = $this->randomName(3);
- if ($i % 2 == 0) {
- $keys[] = 'OR';
- }
- }
- $edit['keys'] = implode(' ', $keys);
- $this->drupalPost('search/node', $edit, t('Search'));
- $this->assertRaw(t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => $limit)));
- }
- }
- class SearchAdvancedSearchForm extends DrupalWebTestCase {
- protected $node;
- public static function getInfo() {
- return array(
- 'name' => 'Advanced search form',
- 'description' => 'Indexes content and tests the advanced search form.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
-
- $test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes'));
- $this->drupalLogin($test_user);
-
- $node = $this->drupalCreateNode();
- $this->node = $this->drupalCreateNode();
-
- node_update_index();
-
-
-
- search_update_totals();
- }
-
- function testNodeType() {
- $this->assertTrue($this->node->type == 'page', 'Node type is Basic page.');
-
- $dummy_title = 'Lorem ipsum';
- $this->assertNotEqual($dummy_title, $this->node->title, "Dummy title doesn't equal node title");
-
- $this->drupalGet('search/node/' . $dummy_title);
- $this->assertNoText($this->node->title, 'Basic page node is not found with dummy title.');
-
- $this->drupalGet('search/node/' . $this->node->title);
- $this->assertText($this->node->title, 'Basic page node is found with GET query.');
-
- $edit = array('or' => $this->node->title);
- $this->drupalPost('search/node', $edit, t('Advanced search'));
- $this->assertText($this->node->title, 'Basic page node is found with POST query.');
-
- $this->drupalPost('search/node', array_merge($edit, array('type[page]' => 'page')), t('Advanced search'));
- $this->assertText($this->node->title, 'Basic page node is found with POST query and type:page.');
- $this->drupalPost('search/node', array_merge($edit, array('type[article]' => 'article')), t('Advanced search'));
- $this->assertText('bike shed', 'Article node is not found with POST query and type:article.');
- }
- }
- class SearchRankingTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search engine ranking',
- 'description' => 'Indexes content and tests ranking factors.',
- 'group' => 'Search',
- );
- }
-
- function setUp() {
- parent::setUp('search', 'statistics', 'comment');
- }
- function testRankings() {
-
- $this->drupalLogin($this->drupalCreateUser(array('skip comment approval', 'create page content')));
-
- $node_ranks = array('sticky', 'promote', 'relevance', 'recent', 'comments', 'views');
-
- foreach ($node_ranks as $node_rank) {
- $settings = array(
- 'type' => 'page',
- 'title' => 'Drupal rocks',
- 'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))),
- );
- foreach (array(0, 1) as $num) {
- if ($num == 1) {
- switch ($node_rank) {
- case 'sticky':
- case 'promote':
- $settings[$node_rank] = 1;
- break;
- case 'relevance':
- $settings['body'][LANGUAGE_NONE][0]['value'] .= " really rocks";
- break;
- case 'recent':
- $settings['created'] = REQUEST_TIME + 3600;
- break;
- case 'comments':
- $settings['comment'] = 2;
- break;
- }
- }
- $nodes[$node_rank][$num] = $this->drupalCreateNode($settings);
- }
- }
-
- module_invoke_all('update_index');
- search_update_totals();
-
- $this->refreshVariables();
-
- $edit = array();
- $edit['subject'] = 'my comment title';
- $edit['comment_body[' . LANGUAGE_NONE . '][0][value]'] = 'some random comment';
- $this->drupalGet('comment/reply/' . $nodes['comments'][1]->nid);
- $this->drupalPost(NULL, $edit, t('Preview'));
- $this->drupalPost(NULL, $edit, t('Save'));
-
- variable_set('statistics_count_content_views', 1);
-
- for ($i = 0; $i < 5; $i ++) {
- $this->drupalGet('node/' . $nodes['views'][1]->nid);
- }
-
- foreach ($node_ranks as $node_rank) {
-
- foreach ($node_ranks as $var) {
- variable_set('node_rank_' . $var, $var == $node_rank ? 10 : 0);
- }
-
- $set = node_search_execute('rocks');
- $this->assertEqual($set[0]['node']->nid, $nodes[$node_rank][1]->nid, 'Search ranking "' . $node_rank . '" order.');
- }
- }
-
- function testHTMLRankings() {
-
- $this->drupalLogin($this->drupalCreateUser(array('create page content')));
-
- $sorted_tags = array('h1', 'h2', 'h3', 'h4', 'a', 'h5', 'h6', 'notag');
- $shuffled_tags = $sorted_tags;
-
- shuffle($shuffled_tags);
- $settings = array(
- 'type' => 'page',
- 'title' => 'Simple node',
- );
- foreach ($shuffled_tags as $tag) {
- switch ($tag) {
- case 'a':
- $settings['body'] = array(LANGUAGE_NONE => array(array('value' => l('Drupal Rocks', 'node'), 'format' => 'full_html')));
- break;
- case 'notag':
- $settings['body'] = array(LANGUAGE_NONE => array(array('value' => 'Drupal Rocks')));
- break;
- default:
- $settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html')));
- break;
- }
- $nodes[$tag] = $this->drupalCreateNode($settings);
- }
-
- module_invoke_all('update_index');
- search_update_totals();
-
- $this->refreshVariables();
-
- $node_ranks = array('sticky', 'promote', 'recent', 'comments', 'views');
- foreach ($node_ranks as $node_rank) {
- variable_set('node_rank_' . $node_rank, 0);
- }
- $set = node_search_execute('rocks');
-
- foreach ($sorted_tags as $tag_rank => $tag) {
-
- if ($tag == 'notag') {
- $this->assertEqual($set[$tag_rank]['node']->nid, $nodes[$tag]->nid, 'Search tag ranking for plain text order.');
- } else {
- $this->assertEqual($set[$tag_rank]['node']->nid, $nodes[$tag]->nid, 'Search tag ranking for "<' . $sorted_tags[$tag_rank] . '>" order.');
- }
- }
-
- $unsorted_tags = array('u', 'b', 'i', 'strong', 'em');
- foreach ($unsorted_tags as $tag) {
- $settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html')));
- $node = $this->drupalCreateNode($settings);
-
- module_invoke_all('update_index');
- search_update_totals();
-
- $this->refreshVariables();
- $set = node_search_execute('rocks');
-
- $set = array_slice($set, -2, 1);
-
- $this->assertEqual($set[0]['node']->nid, $node->nid, 'Search tag ranking for "<' . $tag . '>" order.');
-
- node_delete($node->nid);
- }
- }
-
- function testDoubleRankings() {
-
- $this->drupalLogin($this->drupalCreateUser(array('skip comment approval', 'create page content')));
-
- $settings = array(
- 'type' => 'page',
- 'title' => 'Drupal rocks',
- 'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))),
- 'sticky' => 1,
- );
- $node = $this->drupalCreateNode($settings);
-
- module_invoke_all('update_index');
- search_update_totals();
-
- $this->refreshVariables();
-
-
- $node_ranks = array('sticky', 'promote', 'relevance', 'recent', 'comments', 'views');
- foreach ($node_ranks as $var) {
- $value = ($var == 'sticky' || $var == 'comments') ? 10 : 0;
- variable_set('node_rank_' . $var, $value);
- }
-
- $set = node_search_execute('rocks');
- $this->assertEqual($set[0]['node']->nid, $node->nid, 'Search double ranking order.');
- }
- }
- class SearchBlockTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Block availability',
- 'description' => 'Check if the search form block is available.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
-
- $admin_user = $this->drupalCreateUser(array('administer blocks', 'search content'));
- $this->drupalLogin($admin_user);
- }
- function testSearchFormBlock() {
-
- $this->drupalPost('admin/structure/block/manage/search/form/configure', array('title' => $this->randomName(8)), t('Save block'));
- $this->assertText(t('The block configuration has been saved.'), 'Block configuration set.');
-
- $edit = array();
- $edit['blocks[search_form][region]'] = 'footer';
- $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
- $this->assertText(t('The block settings have been updated.'), 'Block successfully move to footer region.');
- }
-
- function testBlock() {
-
-
- $edit = array('blocks[search_form][region]' => 'content');
- $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
-
- $terms = array('search_block_form' => 'test');
- $this->drupalPost('node', $terms, t('Search'));
- $this->assertText('Your search yielded no results');
-
- $this->drupalGet('foo');
- $this->assertResponse(404);
- $this->drupalPost(NULL, $terms, t('Search'));
- $this->assertResponse(200);
- $this->assertText('Your search yielded no results');
-
- $edit = array('pages' => 'search');
- $this->drupalPost('admin/structure/block/manage/search/form/configure', $edit, t('Save block'));
- $this->drupalPost('node', $terms, t('Search'));
- $this->assertText('Your search yielded no results');
-
- $this->assertEqual(
- $this->getUrl(),
- url('search/node/' . $terms['search_block_form'], array('absolute' => TRUE)),
- 'Redirected to correct url.'
- );
-
- $terms = array('search_block_form' => '');
- $this->drupalPost('node', $terms, t('Search'));
- $this->assertText('Please enter some keywords');
-
- $this->assertEqual(
- $this->getUrl(),
- url('search/node/', array('absolute' => TRUE)),
- 'Redirected to correct url.'
- );
- }
- }
- class SearchExactTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search engine phrase queries',
- 'description' => 'Tests that searching for a phrase gets the correct page count.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
- }
-
- function testExactQuery() {
-
- $this->drupalLogin($this->drupalCreateUser(array('create page content', 'search content')));
- $settings = array(
- 'type' => 'page',
- 'title' => 'Simple Node',
- );
-
- for ($i = 0; $i <= 17; $i++) {
- $settings['body'] = array(LANGUAGE_NONE => array(array('value' => 'love pizza')));
- $this->drupalCreateNode($settings);
- }
-
- for ($i = 0; $i <= 17; $i++) {
- $settings['body'] = array(LANGUAGE_NONE => array(array('value' => 'love cheesy pizza')));
- $this->drupalCreateNode($settings);
- }
-
- module_invoke_all('update_index');
- search_update_totals();
-
- $this->refreshVariables();
-
- $edit = array('keys' => 'love pizza');
- $this->drupalPost('search/node', $edit, t('Search'));
- $this->assertLinkByHref('page=1', 0, '2nd page link is found for keyword search.');
- $this->assertLinkByHref('page=2', 0, '3rd page link is found for keyword search.');
- $this->assertLinkByHref('page=3', 0, '4th page link is found for keyword search.');
- $this->assertNoLinkByHref('page=4', '5th page link is not found for keyword search.');
-
- $edit = array('keys' => '"love pizza"');
- $this->drupalPost('search/node', $edit, t('Search'));
- $this->assertLinkByHref('page=1', 0, '2nd page link is found for exact phrase search.');
- $this->assertNoLinkByHref('page=2', '3rd page link is not found for exact phrase search.');
- }
- }
- class SearchCommentTestCase extends DrupalWebTestCase {
- protected $admin_user;
- public static function getInfo() {
- return array(
- 'name' => 'Comment Search tests',
- 'description' => 'Test integration searching comments.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('comment', 'search');
-
-
- $full_html_format = filter_format_load('full_html');
- $permissions = array(
- 'administer filters',
- filter_permission_name($full_html_format),
- 'administer permissions',
- 'create page content',
- 'skip comment approval',
- 'access comments',
- );
- $this->admin_user = $this->drupalCreateUser($permissions);
- $this->drupalLogin($this->admin_user);
- }
-
- function testSearchResultsComment() {
- $comment_body = 'Test comment body';
- variable_set('comment_preview_article', DRUPAL_OPTIONAL);
-
- $filtered_html_format_id = 'filtered_html';
- $edit = array(
- 'filters[filter_html_escape][status]' => TRUE,
- );
- $this->drupalPost('admin/config/content/formats/' . $filtered_html_format_id, $edit, t('Save configuration'));
-
- $edit = array(
- DRUPAL_ANONYMOUS_RID . '[search content]' => 1,
- DRUPAL_ANONYMOUS_RID . '[access comments]' => 1,
- DRUPAL_ANONYMOUS_RID . '[post comments]' => 1,
- );
- $this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
-
- $node = $this->drupalCreateNode(array('type' => 'article'));
-
- $edit_comment = array();
- $edit_comment['subject'] = 'Test comment subject';
- $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]'] = '<h1>' . $comment_body . '</h1>';
- $full_html_format_id = 'full_html';
- $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][format]'] = $full_html_format_id;
- $this->drupalPost('comment/reply/' . $node->nid, $edit_comment, t('Save'));
-
- $this->drupalLogout();
- $this->cronRun();
-
- $edit = array(
- 'search_block_form' => "'" . $edit_comment['subject'] . "'",
- );
- $this->drupalPost('', $edit, t('Search'));
- $this->assertText($node->title, 'Node found in search results.');
- $this->assertText($edit_comment['subject'], 'Comment subject found in search results.');
-
- $edit = array(
- 'search_block_form' => "'" . $comment_body . "'",
- );
- $this->drupalPost('', $edit, t('Search'));
- $this->assertText($node->title, 'Node found in search results.');
-
- $this->assertText($comment_body, 'Comment body text found in search results.');
- $this->assertNoRaw(t('n/a'), 'HTML in comment body is not hidden.');
- $this->assertNoRaw(check_plain($edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]']), 'HTML in comment body is not escaped.');
-
- $this->drupalLogin($this->admin_user);
- $node->comment = 0;
- node_save($node);
-
- $this->drupalLogout();
- $this->cronRun();
-
- $this->drupalPost('', $edit, t('Search'));
- $this->assertNoText($comment_body, 'Comment body text not found in search results.');
- }
-
- function testSearchResultsCommentAccess() {
- $comment_body = 'Test comment body';
- $this->comment_subject = 'Test comment subject';
- $this->admin_role = $this->admin_user->roles;
- unset($this->admin_role[DRUPAL_AUTHENTICATED_RID]);
- $this->admin_role = key($this->admin_role);
-
- variable_set('comment_preview_article', DRUPAL_OPTIONAL);
- $this->node = $this->drupalCreateNode(array('type' => 'article'));
-
- $edit_comment = array();
- $edit_comment['subject'] = $this->comment_subject;
- $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]'] = '<h1>' . $comment_body . '</h1>';
- $this->drupalPost('comment/reply/' . $this->node->nid, $edit_comment, t('Save'));
- $this->drupalLogout();
- $this->setRolePermissions(DRUPAL_ANONYMOUS_RID);
- $this->checkCommentAccess('Anon user has search permission but no access comments permission, comments should not be indexed');
- $this->setRolePermissions(DRUPAL_ANONYMOUS_RID, TRUE);
- $this->checkCommentAccess('Anon user has search permission and access comments permission, comments should be indexed', TRUE);
- $this->drupalLogin($this->admin_user);
- $this->drupalGet('admin/people/permissions');
-
- $this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, FALSE, FALSE);
- $this->setRolePermissions($this->admin_role);
- $this->checkCommentAccess('Admin user has search permission but no access comments permission, comments should not be indexed');
- $this->setRolePermissions($this->admin_role, TRUE);
- $this->checkCommentAccess('Admin user has search permission and access comments permission, comments should be indexed', TRUE);
- $this->setRolePermissions(DRUPAL_AUTHENTICATED_RID);
- $this->checkCommentAccess('Authenticated user has search permission but no access comments permission, comments should not be indexed');
- $this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE);
- $this->checkCommentAccess('Authenticated user has search permission and access comments permission, comments should be indexed', TRUE);
-
-
- $this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE, FALSE);
- $this->setRolePermissions($this->admin_role);
- $this->checkCommentAccess('Admin user has search permission and no access comments permission, but comments should be indexed because admin user inherits authenticated user\'s permission to access comments', TRUE);
-
-
- $this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE, TRUE);
- $this->setRolePermissions($this->admin_role, TRUE, FALSE);
- $this->checkCommentAccess('Admin user has access comments permission and no search permission, but comments should be indexed because admin user inherits authenticated user\'s permission to search', TRUE);
- }
-
- function setRolePermissions($rid, $access_comments = FALSE, $search_content = TRUE) {
- $permissions = array(
- 'access comments' => $access_comments,
- 'search content' => $search_content,
- );
- user_role_change_permissions($rid, $permissions);
- }
-
- function checkCommentAccess($message, $assume_access = FALSE) {
-
- search_touch_node($this->node->nid);
- $this->cronRun();
-
- $edit = array(
- 'search_block_form' => "'" . $this->comment_subject . "'",
- );
- $this->drupalPost('', $edit, t('Search'));
- $method = $assume_access ? 'assertText' : 'assertNoText';
- $verb = $assume_access ? 'found' : 'not found';
- $this->{$method}($this->node->title, "Node $verb in search results: " . $message);
- $this->{$method}($this->comment_subject, "Comment subject $verb in search results: " . $message);
- }
-
- function testAddNewComment() {
-
- $settings = array(
- 'type' => 'article',
- 'title' => 'short title',
- 'body' => array(LANGUAGE_NONE => array(array('value' => 'short body text'))),
- );
- $user = $this->drupalCreateUser(array('search content', 'create article content', 'access content'));
- $this->drupalLogin($user);
- $node = $this->drupalCreateNode($settings);
-
-
- $this->drupalGet('node/' . $node->nid);
- $this->assertText(t('Add new comment'), 'Add new comment appears on node page');
-
- $this->drupalLogout();
- $this->cronRun();
-
- $this->drupalLogin($user);
- $this->drupalPost('search/node', array('keys' => 'comment'), t('Search'));
- $this->assertText(t('Your search yielded no results'), 'No results searching for the word comment');
-
-
- $this->drupalPost('search/node', array('keys' => 'short'), t('Search'));
- $this->assertText($node->title, 'Search for keyword worked');
- $this->assertNoText(t('Add new comment'), 'Add new comment does not appear on search results page');
- }
- }
- class SearchExpressionInsertExtractTestCase extends DrupalUnitTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search expression insert/extract',
- 'description' => 'Tests the functions search_expression_insert() and search_expression_extract()',
- 'group' => 'Search',
- );
- }
- function setUp() {
- drupal_load('module', 'search');
- parent::setUp();
- }
-
- function testInsertExtract() {
- $base_expression = "mykeyword";
-
-
- $cases = array(
- array('foo', 'bar', 'foo:bar', 'bar'),
- array('foo', NULL, '', NULL),
- array('foo', ' ', 'foo:', ''),
- array('foo', '', 'foo:', ''),
- array('foo', '0', 'foo:0', '0'),
- array('foo', 0, 'foo:0', '0'),
- );
- foreach ($cases as $index => $case) {
- $after_insert = search_expression_insert($base_expression, $case[0], $case[1]);
- if (empty($case[2])) {
- $this->assertEqual($after_insert, $base_expression, "Empty insert does not change expression in case $index");
- }
- else {
- $this->assertEqual($after_insert, $base_expression . ' ' . $case[2], "Insert added correct expression for case $index");
- }
- $retrieved = search_expression_extract($after_insert, $case[0]);
- if (!isset($case[3])) {
- $this->assertFalse(isset($retrieved), "Empty retrieval results in unset value in case $index");
- }
- else {
- $this->assertEqual($retrieved, $case[3], "Value is retrieved for case $index");
- }
- $after_clear = search_expression_insert($after_insert, $case[0]);
- $this->assertEqual(trim($after_clear), $base_expression, "After clearing, base expression is restored for case $index");
- $cleared = search_expression_extract($after_clear, $case[0]);
- $this->assertFalse(isset($cleared), "After clearing, value could not be retrieved for case $index");
- }
- }
- }
- class SearchCommentCountToggleTestCase extends DrupalWebTestCase {
- protected $searching_user;
- protected $searchable_nodes;
- public static function getInfo() {
- return array(
- 'name' => 'Comment count toggle',
- 'description' => 'Verify that comment count display toggles properly on comment status of node.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
-
- $this->searching_user = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'skip comment approval'));
-
- $node_params = array('type' => 'article', 'body' => array(LANGUAGE_NONE => array(array('value' => 'SearchCommentToggleTestCase'))));
- $this->searchable_nodes['1 comment'] = $this->drupalCreateNode($node_params);
- $this->searchable_nodes['0 comments'] = $this->drupalCreateNode($node_params);
-
- $this->drupalLogin($this->searching_user);
-
- $edit_comment = array();
- $edit_comment['subject'] = $this->randomName();
- $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName();
- $filtered_html_format_id = 'filtered_html';
- $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][format]'] = $filtered_html_format_id;
-
- $this->drupalPost('comment/reply/' . $this->searchable_nodes['1 comment']->nid, $edit_comment, t('Save'));
-
- node_update_index();
-
-
-
- search_update_totals();
- }
-
- function testSearchCommentCountToggle() {
-
- $edit = array(
- 'search_block_form' => "'SearchCommentToggleTestCase'",
- );
-
- $this->drupalPost('', $edit, t('Search'));
- $this->assertText(t('0 comments'), 'Empty comment count displays for nodes with comment status set to Open');
- $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open');
-
- $this->searchable_nodes['0 comments']->comment = COMMENT_NODE_CLOSED;
- node_save($this->searchable_nodes['0 comments']);
- $this->searchable_nodes['1 comment']->comment = COMMENT_NODE_CLOSED;
- node_save($this->searchable_nodes['1 comment']);
- $this->drupalPost('', $edit, t('Search'));
- $this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Closed');
- $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed');
-
- $this->searchable_nodes['0 comments']->comment = COMMENT_NODE_HIDDEN;
- node_save($this->searchable_nodes['0 comments']);
- $this->searchable_nodes['1 comment']->comment = COMMENT_NODE_HIDDEN;
- node_save($this->searchable_nodes['1 comment']);
- $this->drupalPost('', $edit, t('Search'));
- $this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Hidden');
- $this->assertNoText(t('1 comment'), 'Non-empty comment count does not display for nodes with comment status set to Hidden');
- }
- }
- class SearchSimplifyTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search simplify',
- 'description' => 'Check that the search_simply() function works as intended.',
- 'group' => 'Search',
- );
- }
-
- function testSearchSimplifyUnicode() {
-
-
-
-
-
-
-
- $input = file_get_contents(DRUPAL_ROOT . '/modules/search/tests/UnicodeTest.txt');
- $basestrings = explode(chr(10), $input);
- $strings = array();
- foreach ($basestrings as $key => $string) {
- if ($key %2) {
-
- $simplified = search_simplify($string);
- $this->assertIdentical($simplified, ' ', "Line $key is excluded from the index");
- }
- else {
-
-
-
- $start = 0;
- while ($start < drupal_strlen($string)) {
- $newstr = drupal_substr($string, $start, 30);
-
-
-
- if (preg_match('/^[0-9]+$/', $newstr)) {
- $newstr = '1' . $newstr;
- }
- $strings[] = $newstr;
- $start += 30;
- }
- }
- }
- foreach ($strings as $key => $string) {
- $simplified = search_simplify($string);
- $this->assertTrue(drupal_strlen($simplified) >= drupal_strlen($string), "Nothing is removed from string $key.");
- }
-
-
- $string = '';
- for ($i = 0; $i < 32; $i++) {
- $string .= chr($i);
- }
- $this->assertIdentical(' ', search_simplify($string), 'Search simplify works for ASCII control characters.');
- }
-
- function testSearchSimplifyPunctuation() {
- $cases = array(
- array('20.03/94-28,876', '20039428876', 'Punctuation removed from numbers'),
- array('great...drupal--module', 'great drupal module', 'Multiple dot and dashes are word boundaries'),
- array('very_great-drupal.module', 'verygreatdrupalmodule', 'Single dot, dash, underscore are removed'),
- array('regular,punctuation;word', 'regular punctuation word', 'Punctuation is a word boundary'),
- );
- foreach ($cases as $case) {
- $out = trim(search_simplify($case[0]));
- $this->assertEqual($out, $case[1], $case[2]);
- }
- }
- }
- class SearchKeywordsConditions extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Keywords and conditions',
- 'description' => 'Verify the search pulls in keywords and extra conditions.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search', 'search_extra_type');
-
- $this->searching_user = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'skip comment approval'));
-
- $this->drupalLogin($this->searching_user);
-
- variable_set('search_active_modules', array('node' => 'node', 'user' => 'user', 'search_extra_type' => 'search_extra_type'));
- menu_rebuild();
- }
-
- function testSearchKeyswordsConditions() {
-
- $this->drupalGet('search/dummy_path');
- $this->assertNoText('Dummy search snippet to display');
-
- $keys = 'bike shed ' . $this->randomName();
- $this->drupalGet("search/dummy_path/{$keys}");
- $this->assertText("Dummy search snippet to display. Keywords: {$keys}");
- $keys = 'blue drop ' . $this->randomName();
- $this->drupalGet("search/dummy_path", array('query' => array('keys' => $keys)));
- $this->assertText("Dummy search snippet to display. Keywords: {$keys}");
-
- $keys = 'moving drop ' . $this->randomName();
- $this->drupalGet("search/dummy_path/bike", array('query' => array('search_conditions' => $keys)));
- $this->assertText("Dummy search snippet to display.");
- $this->assertRaw(print_r(array('search_conditions' => $keys), TRUE));
-
- $keys = 'drop kick ' . $this->randomName();
- $this->drupalGet("search/dummy_path", array('query' => array('search_conditions' => $keys)));
- $this->assertText("Dummy search snippet to display.");
- $this->assertRaw(print_r(array('search_conditions' => $keys), TRUE));
- }
- }
- class SearchNumbersTestCase extends DrupalWebTestCase {
- protected $test_user;
- protected $numbers;
- protected $nodes;
- public static function getInfo() {
- return array(
- 'name' => 'Search numbers',
- 'description' => 'Check that numbers can be searched',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
- $this->test_user = $this->drupalCreateUser(array('search content', 'access content', 'administer nodes', 'access site reports'));
- $this->drupalLogin($this->test_user);
-
-
-
- $this->numbers = array(
- 'ISBN' => '978-0446365383',
- 'UPC' => '036000 291452',
- 'EAN bar code' => '5901234123457',
- 'negative' => '-123456.7890',
- 'quoted negative' => '"-123456.7890"',
- 'leading zero' => '0777777777',
- 'tiny' => '111',
- 'small' => '22222222222222',
- 'medium' => '333333333333333333333333333',
- 'large' => '444444444444444444444444444444444444444',
- 'gigantic' => '5555555555555555555555555555555555555555555555555',
- 'over fifty characters' => '666666666666666666666666666666666666666666666666666666666666',
- 'date', '01/02/2009',
- 'commas', '987,654,321',
- );
- foreach ($this->numbers as $doc => $num) {
- $info = array(
- 'body' => array(LANGUAGE_NONE => array(array('value' => $num))),
- 'type' => 'page',
- 'language' => LANGUAGE_NONE,
- 'title' => $doc . ' number',
- );
- $this->nodes[$doc] = $this->drupalCreateNode($info);
- }
-
- $this->cronRun();
- $this->drupalGet('admin/reports/dblog');
- $this->assertText(t('Cron run completed'), 'Log shows cron run completed');
- }
-
- function testNumberSearching() {
- $types = array_keys($this->numbers);
- foreach ($types as $type) {
- $number = $this->numbers[$type];
-
-
- $number = ltrim($number, '-');
- $node = $this->nodes[$type];
-
-
- $this->drupalPost('search/node',
- array('keys' => 'foo'),
- t('Search'));
- $this->assertNoText($node->title, $type . ': node title not shown in dummy search');
-
-
- $this->drupalPost('search/node',
- array('keys' => $number),
- t('Search'));
- $this->assertText($node->title, format_string('%type: node title shown (search found the node) in search for number %number.', array('%type' => $type, '%number' => $number)));
- }
- }
- }
- class SearchNumberMatchingTestCase extends DrupalWebTestCase {
- protected $test_user;
- protected $numbers;
- protected $nodes;
- public static function getInfo() {
- return array(
- 'name' => 'Search number matching',
- 'description' => 'Check that numbers can be searched with more complex matching',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
- $this->test_user = $this->drupalCreateUser(array('search content', 'access content', 'administer nodes', 'access site reports'));
- $this->drupalLogin($this->test_user);
-
-
-
-
- $this->numbers = array(
- '123456789',
- '12/34/56789',
- '12.3456789',
- '12-34-56789',
- '123,456,789',
- '-123456789',
- '0123456789',
- );
- foreach ($this->numbers as $num) {
- $info = array(
- 'body' => array(LANGUAGE_NONE => array(array('value' => $num))),
- 'type' => 'page',
- 'language' => LANGUAGE_NONE,
- );
- $this->nodes[] = $this->drupalCreateNode($info);
- }
-
- $this->cronRun();
- $this->drupalGet('admin/reports/dblog');
- $this->assertText(t('Cron run completed'), 'Log shows cron run completed');
- }
-
- function testNumberSearching() {
- for ($i = 0; $i < count($this->numbers); $i++) {
- $node = $this->nodes[$i];
-
-
- $this->drupalPost('search/node',
- array('keys' => 'foo'),
- t('Search'));
- $this->assertNoText($node->title, format_string('%number: node title not shown in dummy search', array('%number' => $i)));
-
-
- for ($j = 0; $j < count($this->numbers); $j++) {
- $number = $this->numbers[$j];
-
-
- $number = ltrim($number, '-');
- $this->drupalPost('search/node',
- array('keys' => $number),
- t('Search'));
- $this->assertText($node->title, format_string('%i: node title shown (search found the node) in search for number %number', array('%i' => $i, '%number' => $number)));
- }
- }
- }
- }
- class SearchConfigSettingsForm extends DrupalWebTestCase {
- public $search_user;
- public $search_node;
- public static function getInfo() {
- return array(
- 'name' => 'Config settings form',
- 'description' => 'Verify the search config settings form.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search', 'search_extra_type');
-
- $this->search_user = $this->drupalCreateUser(array('search content', 'administer search', 'administer nodes', 'bypass node access', 'access user profiles', 'administer users', 'administer blocks'));
- $this->drupalLogin($this->search_user);
-
- $node = $this->drupalCreateNode();
- $this->search_node = $node;
-
-
- $langcode = LANGUAGE_NONE;
- $body_key = "body[$langcode][0][value]";
- $edit[$body_key] = l($node->title, 'node/' . $node->nid) . ' pizza sandwich';
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- node_update_index();
- search_update_totals();
-
- $edit = array();
- $edit['blocks[search_form][region]'] = 'content';
- $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
- }
-
- function testSearchSettingsPage() {
-
- $this->drupalGet('admin/config/search/settings');
- $this->assertText(t('There are @count items left to index.', array('@count' => 0)));
-
- $this->drupalPost('admin/config/search/settings', array(), t('Re-index site'));
- $this->assertText(t('Are you sure you want to re-index the site'));
- $this->drupalPost('admin/config/search/settings/reindex', array(), t('Re-index site'));
- $this->assertText(t('The index will be rebuilt'));
- $this->drupalGet('admin/config/search/settings');
- $this->assertText(t('There is 1 item left to index.'));
-
- $this->drupalPost('admin/config/search/settings', array(), t('Save configuration'));
- $this->assertText(t('The configuration options have been saved.'), 'Form saves with the default values.');
-
- $edit = array(
- 'minimum_word_size' => $this->randomName(3),
- );
- $this->drupalPost('admin/config/search/settings', $edit, t('Save configuration'));
- $this->assertNoText(t('The configuration options have been saved.'), 'Form does not save with an invalid word length.');
- }
-
- function testSearchModuleDisabling() {
-
-
-
- $module_info = array(
- 'node' => array(
- 'path' => 'node',
- 'title' => 'Content',
- 'keys' => 'pizza',
- 'text' => $this->search_node->title,
- ),
- 'user' => array(
- 'path' => 'user',
- 'title' => 'User',
- 'keys' => $this->search_user->name,
- 'text' => $this->search_user->mail,
- ),
- 'search_extra_type' => array(
- 'path' => 'dummy_path',
- 'title' => 'Dummy search type',
- 'keys' => 'foo',
- 'text' => 'Dummy search snippet to display',
- ),
- );
- $modules = array_keys($module_info);
-
- foreach ($modules as $module) {
-
- $info = $module_info[$module];
- $edit = array();
- foreach ($modules as $other) {
- $edit['search_active_modules[' . $other . ']'] = (($other == $module) ? $module : FALSE);
- }
- $edit['search_default_module'] = $module;
- $this->drupalPost('admin/config/search/settings', $edit, t('Save configuration'));
-
- $this->drupalGet('search/' . $info['path'] . '/' . $info['keys']);
- $this->assertNoText('no results', $info['title'] . ' search found results');
- $this->assertText($info['text'], 'Correct search text found');
-
- foreach ($modules as $other) {
- if ($other != $module) {
- $title = $module_info[$other]['title'];
- $this->assertNoText($title, $title . ' search tab is not shown');
- }
- }
-
-
- $terms = array('search_block_form' => $info['keys']);
- $this->drupalPost('node', $terms, t('Search'));
- $this->assertEqual(
- $this->getURL(),
- url('search/' . $info['path'] . '/' . $info['keys'], array('absolute' => TRUE)),
- 'Block redirected to right search page');
-
- $this->drupalGet('search/not_a_module_path');
- $this->assertEqual(
- $this->getURL(),
- url('search/' . $info['path'], array('absolute' => TRUE)),
- 'Invalid search path redirected to default search page');
- }
-
-
- $edit = array();
- foreach ($modules as $module) {
- $edit['search_active_modules[' . $module . ']'] = $module;
- }
- $edit['search_default_module'] = 'node';
- $this->drupalPost('admin/config/search/settings', $edit, t('Save configuration'));
- foreach (array('search/node/pizza', 'search/node') as $path) {
- $this->drupalGet($path);
- foreach ($modules as $module) {
- $title = $module_info[$module]['title'];
- $this->assertText($title, format_string('%title search tab is shown', array('%title' => $title)));
- }
- }
- }
- }
- class SearchExcerptTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search excerpt extraction',
- 'description' => 'Tests that the search_excerpt() function works.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
- }
-
- function testSearchExcerpt() {
-
- $text = 'The <strong>quick</strong> <a href="#">brown</a> fox & jumps <h2>over</h2> the lazy dog';
-
-
- $expected = 'The quick brown fox & jumps over the lazy dog';
- $result = preg_replace('| +|', ' ', search_excerpt('nothing', $text));
- $this->assertEqual(preg_replace('| +|', ' ', $result), $expected, 'Entire string is returned when keyword is not found in short string');
- $result = preg_replace('| +|', ' ', search_excerpt('fox', $text));
- $this->assertEqual($result, 'The quick brown <strong>fox</strong> & jumps over the lazy dog ...', 'Found keyword is highlighted');
- $longtext = str_repeat($text . ' ', 10);
- $result = preg_replace('| +|', ' ', search_excerpt('nothing', $longtext));
- $this->assertTrue(strpos($result, $expected) === 0, 'When keyword is not found in long string, return value starts as expected');
- $entities = str_repeat('készítése ', 20);
- $result = preg_replace('| +|', ' ', search_excerpt('nothing', $entities));
- $this->assertFalse(strpos($result, '&'), 'Entities are not present in excerpt');
- $this->assertTrue(strpos($result, 'í') > 0, 'Entities are converted in excerpt');
-
-
- $text = "<div class=\"field field-name-body field-type-text-with-summary field-label-hidden\"><div class=\"field-items\"><div class=\"field-item even\" property=\"content:encoded\"><p>123456789 HTMLTest +123456789+‘ +‘ +‘ +‘ +12345678 +‘ +‘ +‘ ‘</p>\n</div></div></div> ";
- $result = search_excerpt('HTMLTest', $text);
- $this->assertFalse(empty($result), 'Rendered Multi-byte HTML encodings are not corrupted in search excerpts');
- }
-
- function testSearchExcerptSimplified() {
- $lorem1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero.';
- $lorem2 = 'Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci.';
-
- $text = $lorem1 . ' Number: 123456.7890 Hyphenated: one-two abc,def ' . $lorem2;
-
-
- $result = preg_replace('| +|', ' ', search_excerpt('123456.7890', $text));
- $this->assertTrue(strpos($result, 'Number: <strong>123456.7890</strong>') !== FALSE, 'Numeric keyword is highlighted with exact match');
- $result = preg_replace('| +|', ' ', search_excerpt('1234567890', $text));
- $this->assertTrue(strpos($result, 'Number: <strong>123456.7890</strong>') !== FALSE, 'Numeric keyword is highlighted with simplified match');
- $result = preg_replace('| +|', ' ', search_excerpt('Number 1234567890', $text));
- $this->assertTrue(strpos($result, '<strong>Number</strong>: <strong>123456.7890</strong>') !== FALSE, 'Punctuated and numeric keyword is highlighted with simplified match');
- $result = preg_replace('| +|', ' ', search_excerpt('"Number 1234567890"', $text));
- $this->assertTrue(strpos($result, '<strong>Number: 123456.7890</strong>') !== FALSE, 'Phrase with punctuated and numeric keyword is highlighted with simplified match');
- $result = preg_replace('| +|', ' ', search_excerpt('"Hyphenated onetwo"', $text));
- $this->assertTrue(strpos($result, '<strong>Hyphenated: one-two</strong>') !== FALSE, 'Phrase with punctuated and hyphenated keyword is highlighted with simplified match');
- $result = preg_replace('| +|', ' ', search_excerpt('"abc def"', $text));
- $this->assertTrue(strpos($result, '<strong>abc,def</strong>') !== FALSE, 'Phrase with keyword simplified into two separate words is highlighted with simplified match');
-
- $result = preg_replace('| +|', ' ', search_excerpt('"ipsum _"', $text));
- $this->assertTrue(strpos($result, '<strong>ipsum </strong>') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part containing "_" is ignored.');
- $result = preg_replace('| +|', ' ', search_excerpt('"ipsum 0000"', $text));
- $this->assertTrue(strpos($result, '<strong>ipsum </strong>') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part "0000" is ignored.');
-
-
- $result = preg_replace('| +|', ' ', search_excerpt('ipsum _', $text));
- $this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "_" is ignored.');
- $result = preg_replace('| +|', ' ', search_excerpt('ipsum 0000', $text));
- $this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "0000" is ignored.');
- }
- }
- class SearchTokenizerTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'CJK tokenizer',
- 'description' => 'Check that CJK tokenizer works as intended.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
- }
-
- function testTokenizer() {
-
-
- variable_set('minimum_word_size', 1);
- variable_set('overlap_cjk', TRUE);
- $this->refreshVariables();
-
-
-
- $starts = array(
- 'CJK unified' => 0x4e00,
- 'CJK Ext A' => 0x3400,
- 'CJK Compat' => 0xf900,
- 'Hangul Jamo' => 0x1100,
- 'Hangul Ext A' => 0xa960,
- 'Hangul Ext B' => 0xd7b0,
- 'Hangul Compat' => 0x3131,
- 'Half non-punct 1' => 0xff21,
- 'Half non-punct 2' => 0xff41,
- 'Half non-punct 3' => 0xff66,
- 'Hangul Syllables' => 0xac00,
- 'Hiragana' => 0x3040,
- 'Katakana' => 0x30a1,
- 'Katakana Ext' => 0x31f0,
- 'CJK Reserve 1' => 0x20000,
- 'CJK Reserve 2' => 0x30000,
- 'Bomofo' => 0x3100,
- 'Bomofo Ext' => 0x31a0,
- 'Lisu' => 0xa4d0,
- 'Yi' => 0xa000,
- );
-
- $ends = array(
- 'CJK unified' => 0x9fcf,
- 'CJK Ext A' => 0x4dbf,
- 'CJK Compat' => 0xfaff,
- 'Hangul Jamo' => 0x11ff,
- 'Hangul Ext A' => 0xa97f,
- 'Hangul Ext B' => 0xd7ff,
- 'Hangul Compat' => 0x318e,
- 'Half non-punct 1' => 0xff3a,
- 'Half non-punct 2' => 0xff5a,
- 'Half non-punct 3' => 0xffdc,
- 'Hangul Syllables' => 0xd7af,
- 'Hiragana' => 0x309f,
- 'Katakana' => 0x30ff,
- 'Katakana Ext' => 0x31ff,
- 'CJK Reserve 1' => 0x2fffd,
- 'CJK Reserve 2' => 0x3fffd,
- 'Bomofo' => 0x312f,
- 'Bomofo Ext' => 0x31b7,
- 'Lisu' => 0xa4fd,
- 'Yi' => 0xa48f,
- );
-
- $chars = array();
- $charcodes = array();
- foreach ($starts as $key => $value) {
- $charcodes[] = $starts[$key];
- $chars[] = $this->code2utf($starts[$key]);
- $mid = round(0.5 * ($starts[$key] + $ends[$key]));
- $charcodes[] = $mid;
- $chars[] = $this->code2utf($mid);
- $charcodes[] = $ends[$key];
- $chars[] = $this->code2utf($ends[$key]);
- }
-
- $string = implode('', $chars);
- $out = trim(search_simplify($string));
- $expected = drupal_strtolower(implode(' ', $chars));
-
- $this->assertEqual($out, $expected, 'CJK tokenizer worked on all supplied CJK characters');
- }
-
- function testNoTokenizer() {
-
-
- variable_set('minimum_word_size', 1);
- variable_set('overlap_cjk', TRUE);
- $this->refreshVariables();
- $letters = 'abcdefghijklmnopqrstuvwxyz';
- $out = trim(search_simplify($letters));
- $this->assertEqual($letters, $out, 'Letters are not CJK tokenized');
- }
-
- function code2utf($num) {
- if ($num < 128) {
- return chr($num);
- }
- if ($num < 2048) {
- return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
- }
- if ($num < 65536) {
- return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
- }
- if ($num < 2097152) {
- return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
- }
- return '';
- }
- }
- class SearchEmbedForm extends DrupalWebTestCase {
-
- public $node;
-
- public $submit_count = 0;
- public static function getInfo() {
- return array(
- 'name' => 'Embedded forms',
- 'description' => 'Verifies that a form embedded in search results works',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search', 'search_embedded_form');
-
- $test_user = $this->drupalCreateUser(array('access content', 'search content', 'administer nodes'));
- $this->drupalLogin($test_user);
- $this->node = $this->drupalCreateNode();
- node_update_index();
- search_update_totals();
-
- $this->submit_count = 12;
- variable_set('search_embedded_form_submitted', $this->submit_count);
- $this->refreshVariables();
- }
-
- function testEmbeddedForm() {
-
- $this->drupalPost('search_embedded_form',
- array('name' => 'John'),
- t('Send away'));
- $this->assertText(t('Test form was submitted'), 'Form message appears');
- $count = variable_get('search_embedded_form_submitted', 0);
- $this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct');
- $this->submit_count = $count;
-
- $this->drupalGet('search/node/' . $this->node->title);
- $this->assertText(t('Your name'), 'Form is visible');
- $this->drupalPost('search/node/' . $this->node->title,
- array('name' => 'John'),
- t('Send away'));
- $this->assertText(t('Test form was submitted'), 'Form message appears');
- $count = variable_get('search_embedded_form_submitted', 0);
- $this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct');
- $this->submit_count = $count;
-
-
- $this->drupalPost('search',
- array('keys' => 'foo'),
- t('Search'));
- $this->assertNoText(t('Test form was submitted'), 'Form message does not appear');
- $count = variable_get('search_embedded_form_submitted', 0);
- $this->assertEqual($this->submit_count, $count, 'Form submission count is correct');
- $this->submit_count = $count;
- }
- }
- class SearchPageOverride extends DrupalWebTestCase {
- public $search_user;
- public static function getInfo() {
- return array(
- 'name' => 'Search page override',
- 'description' => 'Verify that hook_search_page can override search page display.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search', 'search_extra_type');
-
- $this->search_user = $this->drupalCreateUser(array('search content', 'administer search'));
- $this->drupalLogin($this->search_user);
-
- variable_set('search_active_modules', array('node' => 'node', 'user' => 'user', 'search_extra_type' => 'search_extra_type'));
- menu_rebuild();
- }
- function testSearchPageHook() {
- $keys = 'bike shed ' . $this->randomName();
- $this->drupalGet("search/dummy_path/{$keys}");
- $this->assertText('Dummy search snippet', 'Dummy search snippet is shown');
- $this->assertText('Test page text is here', 'Page override is working');
- }
- }
- class SearchLanguageTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search language selection',
- 'description' => 'Tests advanced search with different languages enabled.',
- 'group' => 'Search',
- );
- }
-
- function setUp() {
- parent::setUp('search', 'locale');
-
- $test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages'));
- $this->drupalLogin($test_user);
- }
- function testLanguages() {
-
- $this->drupalGet('search/node');
- $this->assertNoText(t('Languages'), 'No languages to choose from.');
-
- $edit = array('langcode' => 'fr');
- $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
- $this->assertText('fr', 'Language added successfully.');
-
- $this->drupalGet('search/node');
- $this->assertText(t('Languages'), 'Languages displayed to choose from.');
- $this->assertText(t('English'), 'English is a possible choice.');
- $this->assertText(t('French'), 'French is a possible choice.');
-
- $this->drupalPost('search/node', array(), t('Advanced search'));
- $this->assertEqual($this->getUrl(), url('search/node/', array('absolute' => TRUE)), 'Correct page redirection, no language filtering.');
-
- $edit = array('language[fr]' => TRUE);
- $this->drupalPost('search/node', $edit, t('Advanced search'));
- $this->assertFieldByXPath('//input[@name="keys"]', 'language:fr', 'Language filter added to query.');
-
- $path = 'admin/config/regional/language';
- $this->drupalGet($path);
- $this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
- $edit = array('site_default' => 'fr');
- $this->drupalPost(NULL, $edit, t('Save configuration'));
- $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
- $edit = array('enabled[en]' => FALSE);
- $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
- $this->assertNoFieldChecked('edit-enabled-en', 'Language disabled.');
-
- $this->drupalGet('search/node');
- $this->assertNoText(t('Languages'), 'No languages to choose from.');
- }
- }
- class SearchNodeAccessTest extends DrupalWebTestCase {
- public $test_user;
- public static function getInfo() {
- return array(
- 'name' => 'Search and node access',
- 'description' => 'Tests search functionality with node access control.',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search', 'node_access_test');
- node_access_rebuild();
-
- $this->test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search'));
- $this->drupalLogin($this->test_user);
- }
-
- function testPhraseSearchPunctuation() {
- $node = $this->drupalCreateNode(array('body' => array(LANGUAGE_NONE => array(array('value' => "The bunny's ears were fuzzy.")))));
-
- module_invoke_all('update_index');
- search_update_totals();
-
- $this->refreshVariables();
-
- $edit = array('keys' => '"bunny\'s"');
- $this->drupalPost('search/node', $edit, t('Search'));
- $this->assertText($node->title);
- }
- }
- class SearchSetLocaleTest extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Search with numeric locale set',
- 'description' => 'Check that search works with numeric locale settings',
- 'group' => 'Search',
- );
- }
- function setUp() {
- parent::setUp('search');
-
- $info = array(
- 'body' => array(LANGUAGE_NONE => array(array('value' => 'Tapir'))),
- );
- $this->drupalCreateNode($info);
-
- $this->cronRun();
- }
-
- public function testSearchWithNumericLocale() {
-
- setlocale(LC_NUMERIC, 'fr_FR');
-
-
- db_select('search_index', 'i')
- ->extend('searchquery')
- ->searchexpression('tapir', 'node')
- ->execute();
- }
- }
|