$response->setContent('<html><head><title>foobar</title></head><body>keyword</body></html>'); $highlight->execute($chain); $t->like($response->getContent(), '#<link .*?href=".*?search\\.css".*?/>\\n</head>#', 'highlighter adds search stylesheet'); $response->setContent('<html><head><title>foobar</title></head><body>~notice~ google search test</body></html>'); $request->getParameterHolder()->remove('h'); $_SERVER['HTTP_REFERER'] = 'http://www.google.com/search?num=50&hl=en&safe=off&q=google&btnG=Search'; $highlight->execute($chain); $t->like($response->getContent(), '#<highlighted>google</highlighted> search test#', 'highlighter highlights results from Google'); $t->like($response->getContent(), '#<from>Google</from><keywords><highlighted>google</highlighted></keywords><remove>~remove~</remove>#', 'highlighter adds correct notice for results from Google'); $t->like($response->getContent(), '#<link .*?href=".*?search\\.css".*?/>\\n</head>#', 'highlighter adds search stylesheet for results from Google'); $t->diag('testing conditions when no highlighting occurs'); $request->getParameterHolder()->remove('h'); $_SERVER['HTTP_REFERER'] = null; $response->setContent('<head></head><body>~notice~ keywords</body>'); $highlight->execute($chain); $t->unlike($response->getContent(), '#~notice~#', 'highlighter removes notice replacement if there is nothing to do'); $t->unlike($response->getContent(), '#<link .*?href=".*?search\\.css".*?/>\\n</head>#', 'highlighter does not add the search stylesheet if there is nothing to do'); $t->is($response->getContent(), '<head></head><body> keywords</body>', 'highlighter leaves result untouched except for notice bang if there is nothing to do'); $_SERVER['HTTP_REFERER'] = 'http://www.slashdot.org/'; $response->setContent('<head></head><body>~notice~ google search test</body>'); $request->getParameterHolder()->remove('h'); $highlight->execute($chain); $t->is($response->getContent(), '<head></head><body> google search test</body>', 'highlighter removes notice if there is a possible but invalid refer and does not touch rest of response'); $t->diag('testing different content types'); $content = '<head></head><body>~notice~ keyword</body>'; $response->setContent($content); $request->setParameter('h', 'keyword'); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $highlight->execute($chain); $t->is($response->getContent(), $content, 'highlighter skips highlighting on ajax requests'); $_SERVER['HTTP_X_REQUESTED_WITH'] = null;