search tests
This commit is contained in:
parent
43eed32958
commit
c41c9d680f
2 changed files with 142 additions and 60 deletions
|
@ -1,5 +1,18 @@
|
|||
<?php
|
||||
class IndexTest extends ShimmiePHPUnitTestCase {
|
||||
private function upload() {
|
||||
$this->log_in_as_user();
|
||||
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "thing computer screenshot pbx phone");
|
||||
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "thing computer computing bedroom workshop");
|
||||
$this->log_out();
|
||||
|
||||
# make sure both uploads were ok
|
||||
$this->assertTrue($image_id_1 > 0);
|
||||
$this->assertTrue($image_id_2 > 0);
|
||||
|
||||
return array($image_id_1, $image_id_2);
|
||||
}
|
||||
|
||||
public function testIndexPage() {
|
||||
$this->get_page('post/list');
|
||||
$this->assert_title("Welcome to Shimmie ".VERSION);
|
||||
|
@ -24,85 +37,146 @@ class IndexTest extends ShimmiePHPUnitTestCase {
|
|||
$this->assert_title("Shimmie");
|
||||
|
||||
$this->get_page('post/list/99999');
|
||||
$this->assert_title("No Images Found");
|
||||
|
||||
# FIXME: test search box
|
||||
$this->assert_response(404);
|
||||
}
|
||||
|
||||
public function testSearches() {
|
||||
$this->log_in_as_user();
|
||||
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
||||
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "computer bedroom workshop");
|
||||
$this->log_out();
|
||||
/* * * * * * * * * * *
|
||||
* Tag Search *
|
||||
* * * * * * * * * * */
|
||||
public function testTagSearchNoResults() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
# make sure both uploads were ok
|
||||
$this->assertTrue($image_id_1 > 0);
|
||||
$this->assertTrue($image_id_2 > 0);
|
||||
|
||||
# regular tag, no results
|
||||
$this->get_page('post/list/maumaumau/1');
|
||||
$this->assert_title("No Images Found");
|
||||
$this->assert_response(404);
|
||||
}
|
||||
|
||||
public function testTagSearchOneResult() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
$this->get_page("post/list/pbx/1");
|
||||
$this->assert_response(302);
|
||||
}
|
||||
|
||||
public function testTagSearchManyResults() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
# regular tag, many results
|
||||
$this->get_page('post/list/computer/1');
|
||||
$this->assert_response(200);
|
||||
$this->assert_title("computer");
|
||||
$this->assert_no_text("No Images Found");
|
||||
}
|
||||
|
||||
# meta tag, many results
|
||||
$this->get_page('post/list/size=640x480/1');
|
||||
$this->assert_title("size=640x480");
|
||||
$this->assert_no_text("No Images Found");
|
||||
|
||||
# meta tag, one result
|
||||
$this->get_page("post/list/hash=feb01bab5698a11dd87416724c7a89e3/1");
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_1: /"));
|
||||
$this->assert_no_text("No Images Found");
|
||||
|
||||
# meta tag, one result
|
||||
$this->get_page("post/list/md5=feb01bab5698a11dd87416724c7a89e3/1");
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_1: /"));
|
||||
$this->assert_no_text("No Images Found");
|
||||
|
||||
$this->markTestIncomplete();
|
||||
|
||||
# multiple tags, many results
|
||||
$this->get_page('post/list/computer%20size=640x480/1');
|
||||
$this->assert_title("computer size=640x480");
|
||||
$this->assert_no_text("No Images Found");
|
||||
/* * * * * * * * * * *
|
||||
* Multi-Tag Search *
|
||||
* * * * * * * * * * */
|
||||
public function testMultiTagSearchNoResults() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
# multiple tags, one of which doesn't exist
|
||||
# (test the "one tag doesn't exist = no hits" path)
|
||||
$this->get_page('post/list/computer%20asdfasdfwaffle/1');
|
||||
$this->assert_text("No Images Found");
|
||||
$this->get_page('post/list/computer asdfasdfwaffle/1');
|
||||
$this->assert_response(404);
|
||||
}
|
||||
|
||||
# multiple tags, single result; search with one result = direct to image
|
||||
$this->get_page('post/list/screenshot%20computer/1');
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_1: /"));
|
||||
public function testMultiTagSearchOneResult() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
$this->get_page('post/list/computer screenshot/1');
|
||||
$this->assert_response(302);
|
||||
}
|
||||
|
||||
public function testMultiTagSearchManyResults() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
$this->get_page('post/list/computer thing/1');
|
||||
$this->assert_response(200);
|
||||
}
|
||||
|
||||
/* * * * * * * * * * *
|
||||
* Meta Search *
|
||||
* * * * * * * * * * */
|
||||
public function testMetaSearchNoResults() {
|
||||
$this->get_page('post/list/hash=1234567890/1');
|
||||
$this->assert_response(404);
|
||||
}
|
||||
|
||||
public function testMetaSearchOneResult() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
$this->get_page("post/list/hash=feb01bab5698a11dd87416724c7a89e3/1");
|
||||
$this->assert_response(302);
|
||||
|
||||
$this->get_page("post/list/md5=feb01bab5698a11dd87416724c7a89e3/1");
|
||||
$this->assert_response(302);
|
||||
|
||||
$this->get_page("post/list/id={$image_ids[1]}/1");
|
||||
$this->assert_response(302);
|
||||
|
||||
$this->get_page("post/list/filename=screenshot/1");
|
||||
$this->assert_response(302);
|
||||
|
||||
}
|
||||
|
||||
public function testMetaSearchManyResults() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
$this->get_page('post/list/size=640x480/1');
|
||||
$this->assert_response(200);
|
||||
|
||||
$this->get_page("post/list/tags=5/1");
|
||||
$this->assert_response(200);
|
||||
|
||||
$this->get_page("post/list/ext=jpg/1");
|
||||
$this->assert_response(200);
|
||||
}
|
||||
|
||||
/* * * * * * * * * * *
|
||||
* Wildcards *
|
||||
* * * * * * * * * * */
|
||||
public function testWildSearch() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
// Only the first image matches both the wildcard and the tag.
|
||||
// This checks for https://github.com/shish/shimmie2/issues/547
|
||||
// (comp* is expanded to "computer computing", then we searched
|
||||
// for images which match two or more of the tags in
|
||||
// "computer computing screenshot")
|
||||
$this->get_page("post/list/comp* screenshot/1");
|
||||
$this->assert_response(302);
|
||||
}
|
||||
|
||||
/* * * * * * * * * * *
|
||||
* Mixed *
|
||||
* * * * * * * * * * */
|
||||
public function testMixedSearchTagMeta() {
|
||||
$image_ids = $this->upload();
|
||||
|
||||
# multiple tags, many results
|
||||
$this->get_page('post/list/computer size=640x480/1');
|
||||
$this->assert_response(200);
|
||||
}
|
||||
// tag + negative
|
||||
// wildcards + ???
|
||||
|
||||
/* * * * * * * * * * *
|
||||
* Other *
|
||||
* - negative tags *
|
||||
* - wildcards *
|
||||
* * * * * * * * * * */
|
||||
public function testOther() {
|
||||
$this->markTestIncomplete();
|
||||
|
||||
# negative tag, should have one result
|
||||
$this->get_page('post/list/computer%20-pbx/1');
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_2: /"));
|
||||
$this->get_page('post/list/computer -pbx/1');
|
||||
$this->assert_response(302);
|
||||
|
||||
# negative tag alone, should work
|
||||
# FIXME: known broken in mysql
|
||||
//$this->get_page('post/list/-pbx/1');
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_2: /"));
|
||||
//$this->assert_response(302);
|
||||
|
||||
# test various search methods
|
||||
$this->get_page("post/list/bedroo*/1");
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_2: /"));
|
||||
$this->get_page("post/list/id=$image_id_1/1");
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_1: /"));
|
||||
$this->assert_no_text("No Images Found");
|
||||
$this->get_page("post/list/filename=screenshot/1");
|
||||
//$this->assert_title(new PatternExpectation("/^Image $image_id_1: /"));
|
||||
$this->assert_no_text("No Images Found");
|
||||
$this->get_page("post/list/tags=3/1");
|
||||
$this->assert_title("tags=3");
|
||||
$this->assert_no_text("No Images Found");
|
||||
$this->get_page("post/list/ext=jpg/1");
|
||||
$this->assert_title("ext=jpg");
|
||||
$this->assert_no_text("No Images Found");
|
||||
$this->assert_response(302);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,20 @@ abstract class ShimmiePHPUnitTestCase extends PHPUnit_Framework_TestCase {
|
|||
$_GET = $args;
|
||||
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
||||
send_event(new PageRequestEvent($page_name));
|
||||
if($page->mode == "redirect") {
|
||||
$page->code = 302;
|
||||
}
|
||||
}
|
||||
|
||||
// page things
|
||||
protected function assert_title($title) {
|
||||
global $page;
|
||||
$this->assertEquals($title, $page->title);
|
||||
$this->assertContains($title, $page->title);
|
||||
}
|
||||
|
||||
protected function assert_no_title($title) {
|
||||
global $page;
|
||||
$this->assertNotContains($title, $page->title);
|
||||
}
|
||||
|
||||
protected function assert_response($code) {
|
||||
|
@ -59,7 +67,7 @@ abstract class ShimmiePHPUnitTestCase extends PHPUnit_Framework_TestCase {
|
|||
|
||||
protected function page_to_text($section=null) {
|
||||
global $page;
|
||||
$text = "";
|
||||
$text = $page->title . "\n";
|
||||
foreach($page->blocks as $block) {
|
||||
if(is_null($section) || $section == $block->section) {
|
||||
$text .= $block->header . "\n";
|
||||
|
|
Reference in a new issue