From 9af5995dcca608d3d36b595f1318452ebe89b790 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 9 Aug 2015 12:14:28 +0100 Subject: [PATCH] PHPUnit proof of concept --- .travis.yml | 34 +++++----- core/extension.class.php | 2 +- ext/admin/test.php | 45 ++++++------- ext/alias_editor/test.php | 16 +++-- ext/artists/test.php | 3 +- ext/ban_words/test.php | 50 ++++++--------- ext/bbcode/test.php | 37 +++++------ ext/blocks/test.php | 7 +-- ext/blotter/test.php | 23 +++---- ext/bookmarks/test.php | 2 +- ext/browser_search/test.php | 2 +- ext/bulk_add/test.php | 4 +- ext/comment/main.php | 2 + ext/comment/test.php | 6 +- ext/danbooru_api/test.php | 11 ++-- ext/downtime/test.php | 2 +- ext/emoticons/test.php | 4 +- ext/et/main.php | 2 +- ext/et/test.php | 4 +- ext/ext_manager/test.php | 5 +- ext/favorites/test.php | 4 +- ext/featured/test.php | 4 +- ext/handle_404/test.php | 2 +- ext/handle_ico/test.php | 10 +-- ext/handle_pixel/test.php | 11 +--- ext/handle_svg/test.php | 13 ++-- ext/home/test.php | 9 +-- ext/image/test.php | 16 ++--- ext/image_hash_ban/test.php | 8 +-- ext/index/test.php | 8 +-- ext/ipban/test.php | 2 +- ext/link_image/test.php | 4 +- ext/log_db/test.php | 4 +- ext/numeric_score/test.php | 4 +- ext/oekaki/test.php | 4 +- ext/pm/test.php | 2 +- ext/pools/test.php | 2 +- ext/random_image/test.php | 6 +- ext/rating/test.php | 4 +- ext/regen_thumb/test.php | 4 +- ext/report_image/test.php | 4 +- ext/res_limit/test.php | 10 +-- ext/rss_comments/test.php | 4 +- ext/rss_images/test.php | 4 +- ext/setup/test.php | 2 +- ext/shimmie_api/main.php | 3 +- ext/shimmie_api/test.php | 20 +++--- ext/site_description/test.php | 2 +- ext/sitemap/main.php | 7 ++- ext/sitemap/test.php | 3 +- ext/tag_edit/test.php | 8 +-- ext/tag_history/test.php | 4 +- ext/tag_list/test.php | 3 +- ext/tips/test.php | 2 +- ext/upload/test.php | 8 +-- ext/user/test.php | 9 +-- ext/view/test.php | 8 +-- ext/wiki/test.php | 2 +- ext/word_filter/test.php | 4 +- install.php | 35 +++++++---- tests/all.php | 58 ----------------- tests/bootstrap.php | 115 ++++++++++++++++++++++++++++++++++ tests/install.php | 78 ----------------------- tests/phpunit.xml | 7 +++ 64 files changed, 366 insertions(+), 416 deletions(-) delete mode 100644 tests/all.php create mode 100644 tests/bootstrap.php delete mode 100644 tests/install.php create mode 100644 tests/phpunit.xml diff --git a/.travis.yml b/.travis.yml index c6dfdc66..62ce49c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: php +sudo: false php: # Here is where we can list the versions of PHP you want to test against @@ -14,34 +15,31 @@ env: - DB=pgsql install: - - mkdir -p data - - php -S 127.0.0.1:8080 tests/router.php >>data/php.log 2>>data/php.log & sleep 3 - # Enable logging of all queries (for debugging) and create the database schema for shimmie. + - mkdir -p data/config - if [[ "$DB" == "pgsql" ]]; then psql -c "SELECT set_config('log_statement', 'all', false);" -U postgres; fi - if [[ "$DB" == "pgsql" ]]; then psql -c "CREATE DATABASE shimmie;" -U postgres; fi + - if [[ "$DB" == "pgsql" ]]; then echo ' data/config/auto_install.conf.php ; fi - if [[ "$DB" == "mysql" ]]; then mysql -e "SET GLOBAL general_log = 'ON';" -uroot; fi - if [[ "$DB" == "mysql" ]]; then mysql -e "CREATE DATABASE shimmie;" -uroot; fi + - if [[ "$DB" == "mysql" ]]; then echo ' data/config/auto_install.conf.php ; fi + - if [[ "$DB" == "sqlite" ]]; then echo ' data/config/auto_install.conf.php ; fi script: - - php tests/install.php -d $DB -h "http://127.0.0.1:8080/" - - php tests/all.php -h "http://127.0.0.1:8080/" + - php install.php + - phpunit --configuration tests/phpunit.xml # If a failure occured then dump out a bunch of logs for debugging purposes. after_failure: - - sudo ls -al - - sudo ls -al data/config/ - - sudo cat data/config/shimmie.conf.php - - sudo cat data/config/extensions.conf.php - - sudo cat data/php.log - - sudo ls /var/run/mysql* - - sudo ls /var/log/*mysql* - - sudo cat /var/log/mysql.err - - sudo cat /var/log/mysql.log - - sudo cat /var/log/mysql/error.log - - sudo cat /var/log/mysql/slow.log - - sudo ls /var/log/postgresql - - sudo cat /var/log/postgresql/postgresql* + - head -n 100 data/config/* + - ls /var/run/mysql* + - ls /var/log/*mysql* + - cat /var/log/mysql.err + - cat /var/log/mysql.log + - cat /var/log/mysql/error.log + - cat /var/log/mysql/slow.log + - ls /var/log/postgresql + - cat /var/log/postgresql/postgresql* # configure notifications (email, IRC, campfire etc) #notifications: diff --git a/core/extension.class.php b/core/extension.class.php index a872801c..e7561450 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -47,7 +47,7 @@ * } * * // ext/hello/test.php - * public class HelloTest extends SCoreWebTestCase { + * public class HelloTest extends SCorePHPUnitTestCase { * public function testHello() { * $this->get_page("post/list"); // View a page, any page * $this->assert_text("Hello there"); // Check that the specified text is in that page diff --git a/ext/admin/test.php b/ext/admin/test.php index 3aad3d93..271ef104 100644 --- a/ext/admin/test.php +++ b/ext/admin/test.php @@ -1,5 +1,5 @@ get_page('admin'); $this->assert_response(403); @@ -9,27 +9,31 @@ class AdminPageTest extends ShimmieWebTestCase { $this->get_page('admin'); $this->assert_response(403); $this->assert_title("Permission Denied"); - $this->log_out(); + + $this->log_in_as_admin(); + $this->get_page('admin'); + $this->assert_response(200); + $this->assert_title("Admin Tools"); } function testLowercase() { $ts = time(); // we need a tag that hasn't been used before $this->log_in_as_admin(); - $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "TeStCase$ts"); + $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "TeStCase$ts"); $this->get_page("post/view/$image_id_1"); $this->assert_title("Image $image_id_1: TeStCase$ts"); $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->click("All tags to lowercase"); + //$this->click("All tags to lowercase"); + send_event(new AdminActionEvent('lowercase_all_tags')); $this->get_page("post/view/$image_id_1"); $this->assert_title("Image $image_id_1: testcase$ts"); $this->delete_image($image_id_1); - $this->log_out(); } # FIXME: make sure the admin tools actually work @@ -37,35 +41,33 @@ class AdminPageTest extends ShimmieWebTestCase { $this->log_in_as_admin(); $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->click("Recount tag use"); - $this->log_out(); - } - function testPurge() { - $this->log_in_as_admin(); - $this->get_page('admin'); - $this->assert_title("Admin Tools"); - $this->click("Purge unused tags"); - $this->log_out(); + //$this->click("Recount tag use"); + send_event(new AdminActionEvent('recount_tag_use')); } function testDump() { $this->log_in_as_admin(); $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->click("Download database contents"); - $this->assert_response(200); - $this->log_out(); + + // this calls mysqldump which jams up travis prompting for a password + //$this->click("Download database contents"); + //send_event(new AdminActionEvent('database_dump')); + //$this->assert_response(200); } function testDBQ() { $this->log_in_as_user(); - $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); - $image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "test2"); - $image_id_3 = $this->post_image("ext/simpletest/data/favicon.png", "test"); + $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test"); + $image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "test2"); + $image_id_3 = $this->post_image("tests/favicon.png", "test"); $this->get_page("post/list/test/1"); - $this->click("Delete All These Images"); + //$this->click("Delete All These Images"); + $_POST['query'] = 'test'; + //$_POST['reason'] = 'reason'; // non-null-reason = add a hash ban + send_event(new AdminActionEvent('delete_by_query')); $this->get_page("post/view/$image_id_1"); $this->assert_response(404); @@ -77,7 +79,6 @@ class AdminPageTest extends ShimmieWebTestCase { $this->delete_image($image_id_1); $this->delete_image($image_id_2); $this->delete_image($image_id_3); - $this->log_out(); } } diff --git a/ext/alias_editor/test.php b/ext/alias_editor/test.php index 2aa3ab78..f714a904 100644 --- a/ext/alias_editor/test.php +++ b/ext/alias_editor/test.php @@ -1,16 +1,20 @@ get_page('alias/list'); + $this->assert_response(200); $this->assert_title("Alias List"); + } + function testAliasListReadOnly() { // Check that normal users can't add aliases. $this->log_in_as_user(); $this->get_page('alias/list'); $this->assert_title("Alias List"); $this->assert_no_text("Add"); - $this->log_out(); + } + function testAliasEditor() { /* ********************************************************************** * FIXME: TODO: @@ -39,7 +43,7 @@ class AliasEditorTest extends ShimmieWebTestCase { $this->get_page("alias/export/aliases.csv"); $this->assert_text("test1,test2"); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test1"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "test1"); $this->get_page("post/view/$image_id"); # check that the tag has been replaced $this->assert_title("Image $image_id: test2"); $this->get_page("post/list/test1/1"); # searching for an alias should find the master tag @@ -67,8 +71,8 @@ class AliasEditorTest extends ShimmieWebTestCase { $this->get_page("alias/export/aliases.csv"); $this->assert_text("onetag,multi tag"); - $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "onetag"); - $image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "onetag"); + $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "onetag"); + $image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "onetag"); // FIXME: known broken //$this->get_page("post/list/onetag/1"); # searching for an aliased tag should find its aliases //$this->assert_title("onetag"); diff --git a/ext/artists/test.php b/ext/artists/test.php index 767d764b..6f17ee9c 100644 --- a/ext/artists/test.php +++ b/ext/artists/test.php @@ -1,8 +1,9 @@ get_page("post/list/author=bob/1"); + #$this->assert_response(200); } } diff --git a/ext/ban_words/test.php b/ext/ban_words/test.php index 37c0cfda..80fb4bae 100644 --- a/ext/ban_words/test.php +++ b/ext/ban_words/test.php @@ -1,45 +1,33 @@ fail("Exception not thrown"); + } + catch(CommentPostingException $e) { + $this->assertEquals($e->getMessage(), "Comment contains banned terms"); + } + } + function testWordBan() { - $this->log_in_as_admin(); - $this->get_page("setup"); - $this->set_field("_config_banned_words", "viagra\nporn\n\n/http:.*\.cn\//"); - $this->click("Save Settings"); - $this->log_out(); + global $config; + $config->set_string("banned_words", "viagra\nporn\n\n/http:.*\.cn\//"); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); - $this->get_page("post/view/$image_id"); - $this->set_field('comment', "kittens and viagra"); - $this->click("Post Comment"); - $this->assert_title("Comment Blocked"); - - $this->get_page("post/view/$image_id"); - $this->set_field('comment', "kittens and ViagrA"); - $this->click("Post Comment"); - $this->assert_title("Comment Blocked"); - - $this->get_page("post/view/$image_id"); - $this->set_field('comment', "kittens and viagra!"); - $this->click("Post Comment"); - $this->assert_title("Comment Blocked"); - - $this->get_page("post/view/$image_id"); - $this->set_field('comment', "some link to http://something.cn/"); - $this->click("Post Comment"); - $this->assert_title("Comment Blocked"); + $this->check_blocked($image_id, "kittens and viagra"); + $this->check_blocked($image_id, "kittens and ViagrA"); + $this->check_blocked($image_id, "kittens and viagra!"); + $this->check_blocked($image_id, "some link to http://something.cn/"); $this->get_page('comment/list'); $this->assert_title('Comments'); $this->assert_no_text('viagra'); $this->assert_no_text('ViagrA'); $this->assert_no_text('http://something.cn/'); - $this->log_out(); - - $this->log_in_as_admin(); - $this->delete_image($image_id); - $this->log_out(); } } diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php index a1832653..9df81c0f 100644 --- a/ext/bbcode/test.php +++ b/ext/bbcode/test.php @@ -1,78 +1,73 @@ assertEqual( + $this->assertEquals( $this->filter("[b]bold[/b][i]italic[/i]"), "bolditalic"); } public function testStacking() { - $this->assertEqual( + $this->assertEquals( $this->filter("[b]B[/b][i]I[/i][b]B[/b]"), "BIB"); - $this->assertEqual( + $this->assertEquals( $this->filter("[b]bold[i]bolditalic[/i]bold[/b]"), "boldbolditalicbold"); } public function testFailure() { - $this->assertEqual( + $this->assertEquals( $this->filter("[b]bold[i]italic"), "[b]bold[i]italic"); } public function testCode() { - $this->assertEqual( + $this->assertEquals( $this->filter("[code][b]bold[/b][/code]"), "
[b]bold[/b]
"); } public function testNestedList() { - $this->assertEqual( + $this->assertEquals( $this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"), ""); - $this->assertEqual( + $this->assertEquals( $this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]"), ""); } public function testSpoiler() { - $this->assertEqual( + $this->assertEquals( $this->filter("[spoiler]ShishNet[/spoiler]"), "ShishNet"); - $this->assertEqual( + $this->assertEquals( $this->strip("[spoiler]ShishNet[/spoiler]"), "FuvfuArg"); - #$this->assertEqual( + #$this->assertEquals( # $this->filter("[spoiler]ShishNet"), # "[spoiler]ShishNet"); } public function testURL() { - $this->assertEqual( + $this->assertEquals( $this->filter("[url]http://shishnet.org[/url]"), "http://shishnet.org"); - $this->assertEqual( + $this->assertEquals( $this->filter("[url=http://shishnet.org]ShishNet[/url]"), "ShishNet"); - $this->assertEqual( + $this->assertEquals( $this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]"), "[url=javascript:alert(\"owned\")]click to fail[/url]"); } public function testEmailURL() { - $this->assertEqual( + $this->assertEquals( $this->filter("[email]spam@shishnet.org[/email]"), "spam@shishnet.org"); } public function testAnchor() { - $this->assertEqual( + $this->assertEquals( $this->filter("[anchor=rules]Rules[/anchor]"), 'Rules ΒΆ '); } diff --git a/ext/blocks/test.php b/ext/blocks/test.php index d6f91a38..397418b5 100644 --- a/ext/blocks/test.php +++ b/ext/blocks/test.php @@ -1,11 +1,10 @@ log_in_as_admin(); - $this->get_page("blocks/list"); - - $this->log_out(); + $this->assert_response(200); + $this->assert_title("Blocks"); } } diff --git a/ext/blotter/test.php b/ext/blotter/test.php index 20c321b0..aba22105 100644 --- a/ext/blotter/test.php +++ b/ext/blotter/test.php @@ -1,10 +1,10 @@ log_in_as_admin(); - $this->assert_text("Blotter Editor"); - $this->click("Blotter Editor"); - $this->log_out(); + //$this->assert_text("Blotter Editor"); + //$this->click("Blotter Editor"); + //$this->log_out(); } function testDenial() { @@ -20,18 +20,15 @@ class BlotterTest extends SCoreWebTestCase { $this->log_in_as_admin(); $this->get_page("blotter/editor"); - $this->set_field("entry_text", "blotter testing"); - $this->click("Add"); - $this->assert_text("blotter testing"); + //$this->set_field("entry_text", "blotter testing"); + //$this->click("Add"); + //$this->assert_text("blotter testing"); $this->get_page("blotter"); - $this->assert_text("blotter testing"); + //$this->assert_text("blotter testing"); $this->get_page("blotter/editor"); - $this->click("Remove"); - $this->assert_no_text("blotter testing"); - - $this->log_out(); + //$this->click("Remove"); + //$this->assert_no_text("blotter testing"); } } - diff --git a/ext/bookmarks/test.php b/ext/bookmarks/test.php index 66d41a96..baac6697 100644 --- a/ext/bookmarks/test.php +++ b/ext/bookmarks/test.php @@ -1,5 +1,5 @@ get_page("bookmark/add"); $this->get_page("bookmark/remove"); diff --git a/ext/browser_search/test.php b/ext/browser_search/test.php index e0df2f92..129d2308 100644 --- a/ext/browser_search/test.php +++ b/ext/browser_search/test.php @@ -1,5 +1,5 @@ get_page("browser_search/please_dont_use_this_tag_as_it_would_break_stuff__search.xml"); $this->get_page("browser_search/test"); diff --git a/ext/bulk_add/test.php b/ext/bulk_add/test.php index 3f57fe99..84d639ee 100644 --- a/ext/bulk_add/test.php +++ b/ext/bulk_add/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); @@ -11,7 +11,7 @@ class BulkAddTest extends ShimmieWebTestCase { $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->set_field('dir', "contrib/simpletest"); + $this->set_field('dir', "tests"); $this->click("Add"); # FIXME: test that the output here makes sense, no "adding foo.php ... ok" diff --git a/ext/comment/main.php b/ext/comment/main.php index 9432468f..3bb4ca08 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -25,6 +25,7 @@ class CommentPostingEvent extends Event { * @param string $comment */ public function __construct($image_id, $user, $comment) { + assert('is_numeric($image_id)'); $this->image_id = $image_id; $this->user = $user; $this->comment = $comment; @@ -44,6 +45,7 @@ class CommentDeletionEvent extends Event { * @param int $comment_id */ public function __construct($comment_id) { + assert('is_numeric($comment_id)'); $this->comment_id = $comment_id; } } diff --git a/ext/comment/test.php b/ext/comment/test.php index 1cae2054..d52ce896 100644 --- a/ext/comment/test.php +++ b/ext/comment/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $this->get_page("setup"); @@ -18,7 +18,7 @@ class CommentListTest extends ShimmieWebTestCase { function testCommentsPage() { $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); # a good comment $this->get_page("post/view/$image_id"); @@ -82,7 +82,7 @@ class CommentListTest extends ShimmieWebTestCase { function testSingleDel() { $this->log_in_as_admin(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); # make a comment $this->get_page("post/view/$image_id"); diff --git a/ext/danbooru_api/test.php b/ext/danbooru_api/test.php index 3717ed80..fb837fbd 100644 --- a/ext/danbooru_api/test.php +++ b/ext/danbooru_api/test.php @@ -1,9 +1,9 @@ log_in_as_admin(); - $image_id = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "data"); + $image_id = $this->post_image("tests/bedroom_workshop.jpg", "data"); $this->get_page("api/danbooru/find_posts"); $this->get_page("api/danbooru/find_posts?id=$image_id"); @@ -17,10 +17,7 @@ class DanbooruApiTest extends ShimmieWebTestCase { $this->assert_response(302); $this->get_page("post/list/md5:17fc89f372ed3636e28bd25cc7f3bac1/1"); - $this->assert_title(new PatternExpectation("/^Image \d+: data/")); - $this->click("Delete"); - - $this->log_out(); + //$this->assert_title(new PatternExpectation("/^Image \d+: data/")); + //$this->click("Delete"); } } - diff --git a/ext/downtime/test.php b/ext/downtime/test.php index 77657dff..37850ef2 100644 --- a/ext/downtime/test.php +++ b/ext/downtime/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $this->get_page("setup"); diff --git a/ext/emoticons/test.php b/ext/emoticons/test.php index 7f9237c7..8f7a1279 100644 --- a/ext/emoticons/test.php +++ b/ext/emoticons/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->get_page("post/view/$image_id"); $this->set_field('comment', ":cool: :beans:"); diff --git a/ext/et/main.php b/ext/et/main.php index b77bdd57..21f1f77a 100644 --- a/ext/et/main.php +++ b/ext/et/main.php @@ -47,7 +47,7 @@ class ET extends Extension { $info['sys_os'] = php_uname(); $info['sys_disk'] = to_shorthand_int(disk_total_space("./") - disk_free_space("./")) . " / " . to_shorthand_int(disk_total_space("./")); - $info['sys_server'] = $_SERVER["SERVER_SOFTWARE"]; + $info['sys_server'] = isset($_SERVER["SERVER_SOFTWARE"]) ? $_SERVER["SERVER_SOFTWARE"] : 'unknown'; $info['thumb_engine'] = $config->get_string("thumb_engine"); $info['thumb_quality'] = $config->get_int('thumb_quality'); diff --git a/ext/et/test.php b/ext/et/test.php index d6df53b9..4e53a8bb 100644 --- a/ext/et/test.php +++ b/ext/et/test.php @@ -1,10 +1,8 @@ log_in_as_admin(); $this->get_page("system_info"); $this->assert_title("System Info"); - $this->log_out(); } } - diff --git a/ext/ext_manager/test.php b/ext/ext_manager/test.php index 4a4b0601..330df3cc 100644 --- a/ext/ext_manager/test.php +++ b/ext/ext_manager/test.php @@ -1,5 +1,5 @@ get_page('ext_manager'); $this->assert_title("Extensions"); @@ -17,10 +17,9 @@ class ExtManagerTest extends SCoreWebTestCase { $this->log_in_as_admin(); $this->get_page('ext_manager'); $this->assert_title("Extensions"); - $this->assert_text("SimpleTest integration"); + //$this->assert_text("SimpleTest integration"); // FIXME: something which still exists $this->log_out(); # FIXME: test that some extensions can be added and removed? :S } } - diff --git a/ext/favorites/test.php b/ext/favorites/test.php index c3c4b8d1..51cfbb13 100644 --- a/ext/favorites/test.php +++ b/ext/favorites/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "test"); $this->get_page("post/view/$image_id"); $this->assert_title("Image $image_id: test"); diff --git a/ext/featured/test.php b/ext/featured/test.php index 2308238e..4b82b650 100644 --- a/ext/featured/test.php +++ b/ext/featured/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->log_out(); # FIXME: test that regular users can't feature things diff --git a/ext/handle_404/test.php b/ext/handle_404/test.php index ad6d3943..961eeff6 100644 --- a/ext/handle_404/test.php +++ b/ext/handle_404/test.php @@ -1,5 +1,5 @@ get_page('not/a/page'); $this->assert_response(404); diff --git a/ext/handle_ico/test.php b/ext/handle_ico/test.php index 9292a4a5..0ae08ff0 100644 --- a/ext/handle_ico/test.php +++ b/ext/handle_ico/test.php @@ -1,20 +1,14 @@ log_in_as_user(); $image_id = $this->post_image("lib/static/favicon.ico", "shimmie favicon"); $this->assert_response(302); - $this->log_out(); $this->get_page("post/view/$image_id"); // test for no crash $this->get_page("get_ico/$image_id"); // test for no crash - $this->log_in_as_admin(); - $this->delete_image($image_id); - $this->log_out(); - # FIXME: test that the thumb works # FIXME: test that it gets displayed properly } } - diff --git a/ext/handle_pixel/test.php b/ext/handle_pixel/test.php index c8096114..db2f524f 100644 --- a/ext/handle_pixel/test.php +++ b/ext/handle_pixel/test.php @@ -1,14 +1,9 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); - $this->assert_response(302); - $this->log_out(); - - $this->log_in_as_admin(); - $this->delete_image($image_id); - $this->log_out(); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + //$this->assert_response(302); # FIXME: test that the thumb works # FIXME: test that it gets displayed properly diff --git a/ext/handle_svg/test.php b/ext/handle_svg/test.php index f6420684..55576053 100644 --- a/ext/handle_svg/test.php +++ b/ext/handle_svg/test.php @@ -1,7 +1,7 @@ + file_put_contents("tests/test.svg", ' '); $this->log_in_as_user(); - $image_id = $this->post_image("test.svg", "something"); + $image_id = $this->post_image("tests/test.svg", "something"); $this->assert_response(302); - $this->log_out(); $raw = $this->get_page("get_svg/$image_id"); $this->assertTrue(strpos($raw, "www.w3.org") > 0); - $this->log_in_as_admin(); - $this->delete_image($image_id); - $this->log_out(); - - unlink("test.svg"); + unlink("tests/test.svg"); # FIXME: test that the thumb works # FIXME: test that it gets displayed properly diff --git a/ext/home/test.php b/ext/home/test.php index 3a142074..d6793e9d 100644 --- a/ext/home/test.php +++ b/ext/home/test.php @@ -1,11 +1,12 @@ get_page('home'); - $this->assert_title('Shimmie'); - $this->assert_text('Shimmie'); + + // FIXME: this page doesn't use blocks; need assert_data_contains + //$this->assert_title('Shimmie'); + //$this->assert_text('Shimmie'); # FIXME: test search box } } - diff --git a/ext/image/test.php b/ext/image/test.php index 3e5a94b3..b0907962 100644 --- a/ext/image/test.php +++ b/ext/image/test.php @@ -1,26 +1,20 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "test"); # test collision - $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); + $this->post_image("tests/pbx_screenshot.jpg", "test"); $this->assert_text("already has hash"); $this->get_page("user/test"); $this->assert_text("Images uploaded: 1"); - $this->click("Images uploaded"); - $this->assert_title("Image $image_id: test"); - $this->log_out(); + //$this->click("Images uploaded"); + //$this->assert_title("Image $image_id: test"); # test that serving manually doesn't cause errors $this->get_page("image/$image_id/moo.jpg"); $this->get_page("thumb/$image_id/moo.jpg"); - - $this->log_in_as_admin(); - $this->delete_image($image_id); - $this->log_out(); } } - diff --git a/ext/image_hash_ban/test.php b/ext/image_hash_ban/test.php index d84889fd..778b2b4e 100644 --- a/ext/image_hash_ban/test.php +++ b/ext/image_hash_ban/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->log_out(); $this->log_in_as_admin(); @@ -13,7 +13,7 @@ class HashBanTest extends ShimmieWebTestCase { $this->log_in_as_user(); $this->get_page("post/view/$image_id"); $this->assert_response(404); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->assert_response(404); $this->log_out(); @@ -24,7 +24,7 @@ class HashBanTest extends ShimmieWebTestCase { $this->log_out(); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->assert_response(200); $this->log_out(); diff --git a/ext/index/test.php b/ext/index/test.php index 6496882b..3bc60399 100644 --- a/ext/index/test.php +++ b/ext/index/test.php @@ -1,12 +1,12 @@ get_page('post/list'); $this->assert_title("Welcome to Shimmie ".VERSION); $this->assert_no_text("Prev | Index | Next"); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->log_out(); $this->get_page('post/list'); @@ -34,8 +34,8 @@ class IndexTest extends ShimmieWebTestCase { function testSearches() { $this->log_in_as_user(); - $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); - $image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "computer bedroom workshop"); + $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(); # make sure both uploads were ok diff --git a/ext/ipban/test.php b/ext/ipban/test.php index 4e4226b6..952f142a 100644 --- a/ext/ipban/test.php +++ b/ext/ipban/test.php @@ -1,5 +1,5 @@ get_page('ip_ban/list'); $this->assert_response(403); diff --git a/ext/link_image/test.php b/ext/link_image/test.php index 1e70a4d2..a2fafcdd 100644 --- a/ext/link_image/test.php +++ b/ext/link_image/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pie"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pie"); # look in the "plain text link to post" box, follow the link # in there, see if it takes us to the right page diff --git a/ext/log_db/test.php b/ext/log_db/test.php index 2314d41f..3ab326fe 100644 --- a/ext/log_db/test.php +++ b/ext/log_db/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $this->get_page("log/view"); @@ -7,7 +7,5 @@ class LogDatabaseTest extends SCoreWebTestCase { $this->get_page("log/view?time=2012-03-01"); $this->get_page("log/view?user=demo"); $this->get_page("log/view?priority=10"); - $this->log_out(); } } - diff --git a/ext/numeric_score/test.php b/ext/numeric_score/test.php index ed230272..8501b821 100644 --- a/ext/numeric_score/test.php +++ b/ext/numeric_score/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->assert_text("Current Score: 0"); $this->click("Vote Down"); diff --git a/ext/oekaki/test.php b/ext/oekaki/test.php index 07ca4ec3..8c59d263 100644 --- a/ext/oekaki/test.php +++ b/ext/oekaki/test.php @@ -1,9 +1,7 @@ log_in_as_user(); $this->get_page("oekaki/create"); - $this->log_out(); } } - diff --git a/ext/pm/test.php b/ext/pm/test.php index f08a0274..d50942eb 100644 --- a/ext/pm/test.php +++ b/ext/pm/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $this->get_page("user/test"); diff --git a/ext/pools/test.php b/ext/pools/test.php index 8a59dce9..fe0bae36 100644 --- a/ext/pools/test.php +++ b/ext/pools/test.php @@ -1,5 +1,5 @@ get_page('pool/list'); $this->assert_title("Pools"); diff --git a/ext/random_image/test.php b/ext/random_image/test.php index f11c83ef..ad905a50 100644 --- a/ext/random_image/test.php +++ b/ext/random_image/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "test"); $this->log_out(); $this->get_page("random_image/view"); @@ -31,7 +31,7 @@ class RandomTest extends ShimmieWebTestCase { $this->assert_no_text("Random Image"); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "test"); $this->log_out(); # enabled, image = text diff --git a/ext/rating/test.php b/ext/rating/test.php index 81d02dfc..2a1fca96 100644 --- a/ext/rating/test.php +++ b/ext/rating/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); # test for bug #735: user forced to set rating, can't # set tags and leave unrated diff --git a/ext/regen_thumb/test.php b/ext/regen_thumb/test.php index e2b5dc63..4191fcd5 100644 --- a/ext/regen_thumb/test.php +++ b/ext/regen_thumb/test.php @@ -1,8 +1,8 @@ log_in_as_admin(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->get_page("post/view/$image_id"); $this->click("Regenerate"); $this->assert_title("Thumbnail Regenerated"); diff --git a/ext/report_image/test.php b/ext/report_image/test.php index 65b89aef..a1520dca 100644 --- a/ext/report_image/test.php +++ b/ext/report_image/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->get_page("post/view/$image_id"); $this->set_field('reason', "report details"); $this->click("Report"); diff --git a/ext/res_limit/test.php b/ext/res_limit/test.php index 9d66d3ce..4300f3df 100644 --- a/ext/res_limit/test.php +++ b/ext/res_limit/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $this->get_page("setup"); @@ -12,7 +12,7 @@ class ResLimitTest extends ShimmieWebTestCase { $this->log_out(); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->assert_response(302); $this->assert_no_text("Image too large"); $this->assert_no_text("Image too small"); @@ -36,7 +36,7 @@ class ResLimitTest extends ShimmieWebTestCase { $this->log_out(); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->assert_response(200); $this->assert_title("Upload Status"); $this->assert_text("Image too small"); @@ -60,7 +60,7 @@ class ResLimitTest extends ShimmieWebTestCase { $this->log_out(); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->assert_response(200); $this->assert_title("Upload Status"); $this->assert_text("Image too large"); @@ -84,7 +84,7 @@ class ResLimitTest extends ShimmieWebTestCase { $this->log_out(); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->assert_response(200); $this->assert_title("Upload Status"); $this->assert_text("Image needs to be in one of these ratios"); diff --git a/ext/rss_comments/test.php b/ext/rss_comments/test.php index 1036c177..4ebbe8fe 100644 --- a/ext/rss_comments/test.php +++ b/ext/rss_comments/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->set_field('comment', "Test Comment ASDFASDF"); $this->click("Post Comment"); diff --git a/ext/rss_images/test.php b/ext/rss_images/test.php index 4322b308..e1766200 100644 --- a/ext/rss_images/test.php +++ b/ext/rss_images/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->log_out(); $this->get_page('rss/images'); diff --git a/ext/setup/test.php b/ext/setup/test.php index 6114b030..2507c504 100644 --- a/ext/setup/test.php +++ b/ext/setup/test.php @@ -1,5 +1,5 @@ get_page('setup'); $this->assert_response(403); diff --git a/ext/shimmie_api/main.php b/ext/shimmie_api/main.php index 7e426288..17a77c7d 100644 --- a/ext/shimmie_api/main.php +++ b/ext/shimmie_api/main.php @@ -111,6 +111,7 @@ class ShimmieApi extends Extension { $type = "id"; if($event->count_args() == 1) { $query = $event->get_arg(0); + $type = "name"; } elseif(isset($_GET['id'])) { $query = $_GET['id']; @@ -121,7 +122,7 @@ class ShimmieApi extends Extension { } $all = $database->get_row( - "SELECT id,name,joindate,class FROM users WHERE ".$type."=?", + "SELECT id,name,joindate,class FROM users WHERE $type=?", array($query)); if(!empty($all)){ diff --git a/ext/shimmie_api/test.php b/ext/shimmie_api/test.php index c8dfa91c..4d4e210b 100644 --- a/ext/shimmie_api/test.php +++ b/ext/shimmie_api/test.php @@ -1,29 +1,23 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); + // FIXME: get_page should support GET params $this->get_page("api/shimmie/get_tags"); $this->get_page("api/shimmie/get_tags/pb"); - $this->get_page("api/shimmie/get_tags?tag=pb"); + //$this->get_page("api/shimmie/get_tags?tag=pb"); $this->get_page("api/shimmie/get_image/$image_id"); - $this->get_page("api/shimmie/get_image?id=$image_id"); + //$this->get_page("api/shimmie/get_image?id=$image_id"); $this->get_page("api/shimmie/find_images"); $this->get_page("api/shimmie/find_images/pbx"); $this->get_page("api/shimmie/find_images/pbx/1"); $this->get_page("api/shimmie/get_user/demo"); - $this->get_page("api/shimmie/get_user?name=demo"); - $this->get_page("api/shimmie/get_user?id=2"); + //$this->get_page("api/shimmie/get_user?name=demo"); + //$this->get_page("api/shimmie/get_user?id=2"); // FIXME: test unspecified / bad values // FIXME: test that json is encoded properly - - $this->log_out(); - - $this->log_in_as_admin(); - $this->delete_image($image_id); - $this->log_out(); } } - diff --git a/ext/site_description/test.php b/ext/site_description/test.php index 293c6a1a..0679fc53 100644 --- a/ext/site_description/test.php +++ b/ext/site_description/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $this->get_page('setup'); diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index c427b44a..904c36fc 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -20,7 +20,7 @@ class XMLSitemap extends Extension if ($event->page_matches("sitemap.xml")) { global $config; - $this->sitemap_filepath = $_SERVER['DOCUMENT_ROOT'] . "/data/cache/sitemap.xml"; + $this->sitemap_filepath = data_path("cache/sitemap.xml"); // determine if new sitemap needs to be generated if ($this->new_sitemap_needed()) { // determine which type of sitemap to generate @@ -49,6 +49,7 @@ class XMLSitemap extends Extension { /* --- Add latest images to sitemap with higher priority --- */ $latestimages = Image::find_images(0, 50, array()); + if(empty($latestimages)) return; $latestimages_urllist = array(); foreach ($latestimages as $arrayid => $image) { // create url from image id's @@ -160,6 +161,10 @@ class XMLSitemap extends Extension */ private function new_sitemap_needed() { + if(!file_exists($this->sitemap_filepath)) { + return true; + } + $sitemap_generation_interval = 86400; // allow new site map every day $last_generated_time = filemtime($this->sitemap_filepath); diff --git a/ext/sitemap/test.php b/ext/sitemap/test.php index fa459d9b..f98ec4ae 100644 --- a/ext/sitemap/test.php +++ b/ext/sitemap/test.php @@ -1,9 +1,8 @@ get_page('sitemap.xml'); } } - diff --git a/ext/tag_edit/test.php b/ext/tag_edit/test.php index 89541830..23545291 100644 --- a/ext/tag_edit/test.php +++ b/ext/tag_edit/test.php @@ -1,8 +1,8 @@ log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->assert_title("Image $image_id: pbx"); $this->set_field("tag_edit__tags", "new"); @@ -20,7 +20,7 @@ class TagEditTest extends ShimmieWebTestCase { function testSourceEdit() { $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->assert_title("Image $image_id: pbx"); @@ -49,7 +49,7 @@ class TagEditTest extends ShimmieWebTestCase { function testMassEdit() { $this->log_in_as_admin(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->assert_title("Image $image_id: pbx"); diff --git a/ext/tag_history/test.php b/ext/tag_history/test.php index ae8f2bdf..415a07db 100644 --- a/ext/tag_history/test.php +++ b/ext/tag_history/test.php @@ -1,8 +1,8 @@ log_in_as_admin(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $this->get_page("post/view/$image_id"); $this->assert_title("Image $image_id: pbx"); $this->set_field("tag_edit__tags", "new"); diff --git a/ext/tag_list/test.php b/ext/tag_list/test.php index 6b50fc87..4910f304 100644 --- a/ext/tag_list/test.php +++ b/ext/tag_list/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $raw = $this->get_page("tips/list"); diff --git a/ext/upload/test.php b/ext/upload/test.php index 7eb0b08d..af7756f5 100644 --- a/ext/upload/test.php +++ b/ext/upload/test.php @@ -1,15 +1,15 @@ log_in_as_user(); $this->get_page("upload"); $this->assert_title("Upload"); - $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->assert_response(302); - $image_id_2 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id_2 = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->assert_response(200); $this->assert_title("Upload Status"); $this->assert_text("already has hash"); @@ -21,7 +21,7 @@ class UploadTest extends ShimmieWebTestCase { /* // FIXME: huge.dat is rejected for other reasons; manual testing shows that this works - file_put_contents("huge.dat", file_get_contents("ext/simpletest/data/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3)); + file_put_contents("huge.dat", file_get_contents("tests/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3)); $image_id_4 = $this->post_image("index.php", "test"); $this->assert_response(200); $this->assert_title("Upload Status"); diff --git a/ext/user/test.php b/ext/user/test.php index cd55086b..8c777c67 100644 --- a/ext/user/test.php +++ b/ext/user/test.php @@ -1,5 +1,5 @@ get_page('user'); $this->assert_title("Not Logged In"); @@ -15,7 +15,8 @@ class UserPageTest extends SCoreWebTestCase { $this->log_in_as_user(); // should be on the user page - $this->assert_title(USER_NAME+"'s Page"); + $this->get_page('user/test'); + $this->assert_title("test's Page"); $this->assert_text("Options"); // FIXME: check class //$this->assert_no_text("Admin:"); @@ -23,7 +24,8 @@ class UserPageTest extends SCoreWebTestCase { $this->log_in_as_admin(); // should be on the user page - $this->assert_title(ADMIN_NAME+"'s Page"); + $this->get_page('user/demo'); + $this->assert_title("demo's Page"); $this->assert_text("Options"); // FIXME: check class //$this->assert_text("Admin:"); @@ -37,4 +39,3 @@ class UserPageTest extends SCoreWebTestCase { $this->assert_text("demo"); } } - diff --git a/ext/view/test.php b/ext/view/test.php index 2398e356..eeab6f47 100644 --- a/ext/view/test.php +++ b/ext/view/test.php @@ -1,10 +1,10 @@ log_in_as_user(); - $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); - $image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "test2"); - $image_id_3 = $this->post_image("ext/simpletest/data/favicon.png", "test"); + $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test"); + $image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "test2"); + $image_id_3 = $this->post_image("tests/favicon.png", "test"); $idp1 = $image_id_3 + 1; $this->log_out(); diff --git a/ext/wiki/test.php b/ext/wiki/test.php index 3cbbd44c..4f1fffbb 100644 --- a/ext/wiki/test.php +++ b/ext/wiki/test.php @@ -1,5 +1,5 @@ get_page("wiki"); $this->assert_title("Index"); diff --git a/ext/word_filter/test.php b/ext/word_filter/test.php index 6b3df0b2..0f0d7f10 100644 --- a/ext/word_filter/test.php +++ b/ext/word_filter/test.php @@ -1,5 +1,5 @@ log_in_as_admin(); $this->get_page("setup"); @@ -8,7 +8,7 @@ class WordFilterTest extends ShimmieWebTestCase { $this->log_out(); $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $this->get_page("post/view/$image_id"); # regular diff --git a/install.php b/install.php index 1c2ca6dd..3c6d2b19 100644 --- a/install.php +++ b/install.php @@ -3,11 +3,16 @@ * Shimmie Installer * * @package Shimmie - * @copyright Copyright (c) 2007-2014, Shish et al. + * @copyright Copyright (c) 2007-2015, Shish et al. * @author Shish , jgen * @link http://code.shishnet.org/shimmie2/ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * + * Initialise the database, check that folder + * permissions are set properly. + * + * This file should be independant of the database + * and other such things that aren't ready yet */ // TODO: Rewrite the entire installer and make it more readable. @@ -18,7 +23,6 @@ date_default_timezone_set('UTC'); ?> - Shimmie Installation @@ -113,21 +117,20 @@ function eok($name, $value) { function do_install() { // {{{ if(file_exists("data/config/auto_install.conf.php")) { require_once "data/config/auto_install.conf.php"; - install_process(); } else if(@$_POST["database_type"] == "sqlite" && isset($_POST["database_name"])) { define('DATABASE_DSN', "sqlite:{$_POST["database_name"]}"); - define("DATABASE_KA", true); // Keep database connection alive - install_process(); } else if(isset($_POST['database_type']) && isset($_POST['database_host']) && isset($_POST['database_user']) && isset($_POST['database_name'])) { define('DATABASE_DSN', "{$_POST['database_type']}:user={$_POST['database_user']};password={$_POST['database_password']};host={$_POST['database_host']};dbname={$_POST['database_name']}"); - define("DATABASE_KA", true); // Keep database connection alive - install_process(); } else { ask_questions(); + return; } + + define("DATABASE_KA", true); + install_process(); } // }}} function ask_questions() { // {{{ @@ -245,8 +248,6 @@ function install_process() { // {{{ create_tables(); insert_defaults(); write_config(); - - header("Location: index.php"); } // }}} function create_tables() { // {{{ @@ -435,7 +436,17 @@ function write_config() { // {{{ mkdir("data/config", 0755, true); } - if(!file_put_contents("data/config/shimmie.conf.php", $file_content, LOCK_EX)) { + if(file_put_contents("data/config/shimmie.conf.php", $file_content, LOCK_EX)) { + header("Location: index.php"); + print << +

Shimmie Installer

+

Things are OK \o/

+

If you aren't redirected, click here to Continue. + +EOD; + } + else { $h_file_content = htmlentities($file_content); print << @@ -448,12 +459,12 @@ function write_config() { // {{{

-

Once done, Click here to Continue. +

Once done, click here to Continue.

EOD; - exit; } + echo "\n"; } // }}} ?> diff --git a/tests/all.php b/tests/all.php deleted file mode 100644 index 2d82e8e9..00000000 --- a/tests/all.php +++ /dev/null @@ -1,58 +0,0 @@ - - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 - * @copyright Copyright (c) 2014, jgen - */ - -if(PHP_SAPI !== 'cli') die('cli only'); - -require_once('lib/simpletest/unit_tester.php'); -require_once('lib/simpletest/web_tester.php'); -require_once('lib/simpletest/reporter.php'); - -// Enable all errors. -error_reporting(E_ALL); -define("CLI_LOG_LEVEL", -100); // output everything. - -// Get the command line option telling us where the webserver is. -$options = getopt("h:"); -$host = rtrim(trim(trim($options["h"], '"')), "/"); - -if (empty($host)){ $host = "http://127.0.0.1"; } - -define("_TRAVIS_WEBHOST", $host); - -// The code below is based on the code in index.php -//-------------------------------------------------- - -require_once('core/_bootstrap.inc.php'); -require_once('ext/simpletest/main.php'); - -// Fire off the InitExtEvent() -$page = class_exists("CustomPage") ? new CustomPage() : new Page(); -$user = _get_user(); -send_event(new InitExtEvent()); - -// Create the necessary users for the tests. -$userPage = new UserPage(); -$userPage->onUserCreation(new UserCreationEvent("demo", "demo", "")); -$userPage->onUserCreation(new UserCreationEvent("test", "test", "")); - -// Commit the users. -$database->commit(); - -// Fire off the InitExtEvent() again after we have made the users. -$page = class_exists("CustomPage") ? new CustomPage() : new Page(); -$user = _get_user(); -send_event(new InitExtEvent()); - -// Now we can actually run all the tests. -$all = new TestFinder(""); -$results = $all->run(new TextReporter()); - -// Travis-CI needs to know the results of the tests. -exit ($results ? 0 : 1); diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..35384597 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,115 @@ +onUserCreation(new UserCreationEvent("demo", "demo", "")); + $userPage->onUserCreation(new UserCreationEvent("test", "test", "")); +} + +abstract class ShimmiePHPUnitTestCase extends PHPUnit_Framework_TestCase { + protected $backupGlobalsBlacklist = array('database', 'config'); + private $images = array(); + + public function setUp() { + // things to do after bootstrap and before request + // log in as anon + $this->log_out(); + } + + public function tearDown() { + foreach($this->images as $image_id) { + $this->delete_image($image_id); + } + } + + protected function get_page($page_name) { + // use a fresh page + global $page; + $page = class_exists("CustomPage") ? new CustomPage() : new Page(); + send_event(new PageRequestEvent($page_name)); + } + + // page things + protected function assert_title($title) { + global $page; + $this->assertEquals($title, $page->title); + } + + protected function assert_response($code) { + global $page; + $this->assertEquals($code, $page->code); + } + + protected function has_text($text) { + global $page; + foreach($page->blocks as $block) { + if(strpos($block->header, $text) !== false) return true; + if(strpos($block->body, $text) !== false) return true; + } + return false; + } + + protected function assert_text($text) { + $this->assertTrue($this->has_text($text)); + } + + protected function assert_no_text($text) { + $this->assertFalse($this->has_text($text)); + } + + // user things + protected function log_in_as_admin() { + global $user; + $user = User::by_name('demo'); + $this->assertNotNull($user); + } + + protected function log_in_as_user() { + global $user; + $user = User::by_name('test'); + $this->assertNotNull($user); + } + + protected function log_out() { + global $user, $config; + $user = User::by_id($config->get_int("anon_id", 0)); + $this->assertNotNull($user); + } + + // post things + /** + * @param string $filename + * @param string|string[] $tags + * @return int + */ + protected function post_image($filename, $tags) { + $dae = new DataUploadEvent($filename, array( + "filename"=>$filename, + "extension"=>'jpg', // fixme + "tags"=>$tags, + "source"=>null, + )); + send_event($dae); + $this->images[] = $dae->image_id; + return $dae->image_id; + } + + /** + * @param int $image_id + */ + protected function delete_image($image_id) { + $img = Image::by_id($image_id); + if($img) { + $ide = new ImageDeletionEvent($img); + send_event($ide); + } + } +} diff --git a/tests/install.php b/tests/install.php deleted file mode 100644 index 86dddf1d..00000000 --- a/tests/install.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 - * @copyright Copyright (c) 2014, jgen - */ - -if(PHP_SAPI !== 'cli') die('cli only'); - -require_once('lib/simpletest/unit_tester.php'); -require_once('lib/simpletest/web_tester.php'); -require_once('lib/simpletest/reporter.php'); - -// Enable all errors. -error_reporting(E_ALL); - -// Get the command line option telling us what database and host to use. -$options = getopt("d:h:"); -$db = $options["d"]; -$host = rtrim(trim(trim($options["h"], '"')), "/"); - -// Check if they are empty. -if (empty($db)){ die("Error: need to specify a database for the test environment."); } -if (empty($host)){ $host = "http://127.0.0.1"; } - -define("_TRAVIS_DATABASE", $db); -define("_TRAVIS_WEBHOST", $host); - -// Currently the tests only support MySQL and PostgreSQL. -if ($db === "mysql") { - define("_TRAVIS_DATABASE_USERNAME", "root"); - define("_TRAVIS_DATABASE_PASSWORD", ""); -} elseif ($db === "pgsql") { - define("_TRAVIS_DATABASE_USERNAME", "postgres"); - define("_TRAVIS_DATABASE_PASSWORD", ""); -} else { - die("Unsupported Database Option"); -} - -class ShimmieInstallerTest extends WebTestCase { - function testInstallShimmie() - { - // Get the settings from the global constants. - $db = constant("_TRAVIS_DATABASE"); - $host = constant("_TRAVIS_WEBHOST"); - $username = constant("_TRAVIS_DATABASE_USERNAME"); - $password = constant("_TRAVIS_DATABASE_PASSWORD"); - - // Make sure that we know where the host is. - $this->assertFalse(empty($host)); - // Make sure that we know what database to use. - $this->assertFalse(empty($db)); - - $this->get($host); - $this->assertResponse(200); - $this->assertTitle("Shimmie Installation"); - $this->assertText("Database Install"); - - $this->setField("database_type", $db); - $this->assertField("database_type", $db); - $this->assertField("database_host", "localhost"); - $this->setField("database_user", $username); - $this->setField("database_password", $password); - $this->assertField("database_name", "shimmie"); - $this->clickSubmit("Go!"); - - if (!$this->assertText("Installation Succeeded!")) { - $this->showSource(); - } - } -} - -$test = new TestSuite('Install Shimmie'); -$test->add(new ShimmieInstallerTest()); -exit ($test->run(new TextReporter()) ? 0 : 1); diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 00000000..1fdaf756 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,7 @@ + + + + ../ext/ + + +