PHPUnit proof of concept

This commit is contained in:
Shish 2015-08-09 12:14:28 +01:00
parent e3959e5ec8
commit 9af5995dcc
64 changed files with 366 additions and 416 deletions

View file

@ -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 '<?php define("DATABASE_DSN", "pgsql:user=postgres;password=;host=;dbname=shimmie");' > 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 '<?php define("DATABASE_DSN", "mysql:user=root;password=;host=localhost;dbname=shimmie");' > data/config/auto_install.conf.php ; fi
- if [[ "$DB" == "sqlite" ]]; then echo '<?php define("DATABASE_DSN", "sqlite:shimmie.sqlite");' > 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:

View file

@ -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

View file

@ -1,5 +1,5 @@
<?php
class AdminPageTest extends ShimmieWebTestCase {
class AdminPageTest extends ShimmiePHPUnitTestCase {
function testAuth() {
$this->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();
}
}

View file

@ -1,16 +1,20 @@
<?php
class AliasEditorTest extends ShimmieWebTestCase {
function testAliasEditor() {
class AliasEditorTest extends ShimmiePHPUnitTestCase {
function testAliasList() {
$this->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");

View file

@ -1,8 +1,9 @@
<?php
class ArtistTest extends ShimmieWebTestCase {
class ArtistTest extends ShimmiePHPUnitTestCase {
function testSearch() {
# FIXME: check that the results are there
$this->get_page("post/list/author=bob/1");
#$this->assert_response(200);
}
}

View file

@ -1,45 +1,33 @@
<?php
class BanWordsTest extends ShimmieWebTestCase {
class BanWordsTest extends ShimmiePHPUnitTestCase {
function check_blocked($image_id, $words) {
global $user;
try {
send_event(new CommentPostingEvent($image_id, $user, $words));
$this->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();
}
}

View file

@ -1,78 +1,73 @@
<?php
# FIXME: web test
class BBCodeTest extends ShimmieWebTestCase {}
if(!defined(VERSION)) return;
class BBCodeUnitTest extends UnitTestCase {
class BBCodeTest extends ShimmiePHPUnitTestCase {
public function testBasics() {
$this->assertEqual(
$this->assertEquals(
$this->filter("[b]bold[/b][i]italic[/i]"),
"<b>bold</b><i>italic</i>");
}
public function testStacking() {
$this->assertEqual(
$this->assertEquals(
$this->filter("[b]B[/b][i]I[/i][b]B[/b]"),
"<b>B</b><i>I</i><b>B</b>");
$this->assertEqual(
$this->assertEquals(
$this->filter("[b]bold[i]bolditalic[/i]bold[/b]"),
"<b>bold<i>bolditalic</i>bold</b>");
}
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]"),
"<pre>[b]bold[/b]</pre>");
}
public function testNestedList() {
$this->assertEqual(
$this->assertEquals(
$this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"),
"<ul><li>a<ul><li>a<li>b</ul><li>b</ul>");
$this->assertEqual(
$this->assertEquals(
$this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]"),
"<ul><li>a<ol><li>a<li>b</ol><li>b</ul>");
}
public function testSpoiler() {
$this->assertEqual(
$this->assertEquals(
$this->filter("[spoiler]ShishNet[/spoiler]"),
"<span style=\"background-color:#000; color:#000;\">ShishNet</span>");
$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]"),
"<a href=\"http://shishnet.org\">http://shishnet.org</a>");
$this->assertEqual(
$this->assertEquals(
$this->filter("[url=http://shishnet.org]ShishNet[/url]"),
"<a href=\"http://shishnet.org\">ShishNet</a>");
$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]"),
"<a href=\"mailto:spam@shishnet.org\">spam@shishnet.org</a>");
}
public function testAnchor() {
$this->assertEqual(
$this->assertEquals(
$this->filter("[anchor=rules]Rules[/anchor]"),
'<span class="anchor">Rules <a class="alink" href="#bb-rules" name="bb-rules" title="link to this anchor"> ¶ </a></span>');
}

View file

@ -1,11 +1,10 @@
<?php
class BlocksTest extends SCoreWebTestCase {
class BlocksTest extends ShimmiePHPUnitTestCase {
function testBlocks() {
$this->log_in_as_admin();
$this->get_page("blocks/list");
$this->log_out();
$this->assert_response(200);
$this->assert_title("Blocks");
}
}

View file

@ -1,10 +1,10 @@
<?php
class BlotterTest extends SCoreWebTestCase {
class BlotterTest extends ShimmiePHPUnitTestCase {
function testLogin() {
$this->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");
}
}

View file

@ -1,5 +1,5 @@
<?php
class BookmarksTest extends ShimmieWebTestCase {
class BookmarksTest extends ShimmiePHPUnitTestCase {
function testBookmarks() {
$this->get_page("bookmark/add");
$this->get_page("bookmark/remove");

View file

@ -1,5 +1,5 @@
<?php
class BrowserSearchTest extends SCoreWebTestCase {
class BrowserSearchTest extends ShimmiePHPUnitTestCase {
function testBasic() {
$this->get_page("browser_search/please_dont_use_this_tag_as_it_would_break_stuff__search.xml");
$this->get_page("browser_search/test");

View file

@ -1,5 +1,5 @@
<?php
class BulkAddTest extends ShimmieWebTestCase {
class BulkAddTest {
function testBulkAdd() {
$this->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"

View file

@ -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;
}
}

View file

@ -1,5 +1,5 @@
<?php
class CommentListTest extends ShimmieWebTestCase {
class CommentListTest {
function setUp() {
$this->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");

View file

@ -1,9 +1,9 @@
<?php
class DanbooruApiTest extends ShimmieWebTestCase {
class DanbooruApiTest { // extends ShimmiePHPUnitTestCase {
function testSearch() {
$this->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");
}
}

View file

@ -1,5 +1,5 @@
<?php
class DowntimeTest extends SCoreWebTestCase {
class DowntimeTest {
function testDowntime() {
$this->log_in_as_admin();
$this->get_page("setup");

View file

@ -1,8 +1,8 @@
<?php
class EmoticonTest extends ShimmieWebTestCase {
class EmoticonTest {
function testEmoticons() {
$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', ":cool: :beans:");

View file

@ -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');

View file

@ -1,10 +1,8 @@
<?php
class ETTest extends ShimmieWebTestCase {
class ETTest extends ShimmiePHPUnitTestCase {
function testET() {
$this->log_in_as_admin();
$this->get_page("system_info");
$this->assert_title("System Info");
$this->log_out();
}
}

View file

@ -1,5 +1,5 @@
<?php
class ExtManagerTest extends SCoreWebTestCase {
class ExtManagerTest extends ShimmiePHPUnitTestCase {
function testAuth() {
$this->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
}
}

View file

@ -1,8 +1,8 @@
<?php
class FavoritesTest extends ShimmieWebTestCase {
class FavoritesTest {
function testFavorites() {
$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->get_page("post/view/$image_id");
$this->assert_title("Image $image_id: test");

View file

@ -1,8 +1,8 @@
<?php
class FeaturedTest extends ShimmieWebTestCase {
class FeaturedTest {
function testFeatured() {
$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->log_out();
# FIXME: test that regular users can't feature things

View file

@ -1,5 +1,5 @@
<?php
class Handle404Test extends SCoreWebTestCase {
class Handle404Test extends ShimmiePHPUnitTestCase {
function test404Handler() {
$this->get_page('not/a/page');
$this->assert_response(404);

View file

@ -1,20 +1,14 @@
<?php
class IcoHandlerTest extends ShimmieWebTestCase {
function testPixelHander() {
class IcoHandlerTest { // extends ShimmiePHPUnitTestCase {
function testIcoHander() {
$this->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
}
}

View file

@ -1,14 +1,9 @@
<?php
class PixelHandlerTest extends ShimmieWebTestCase {
class PixelHandlerTest extends ShimmiePHPUnitTestCase {
function testPixelHander() {
$this->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

View file

@ -1,7 +1,7 @@
<?php
class SVGHandlerTest extends ShimmieWebTestCase {
class SVGHandlerTest { // extends ShimmiePHPUnitTestCase {
function testSVGHander() {
file_put_contents("test.svg", '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
file_put_contents("tests/test.svg", '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg"
width="128"
@ -17,18 +17,13 @@ class SVGHandlerTest extends ShimmieWebTestCase {
</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

View file

@ -1,11 +1,12 @@
<?php
class HomeTest extends ShimmieWebTestCase {
class HomeTest extends ShimmiePHPUnitTestCase {
function testHomePage() {
$this->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
}
}

View file

@ -1,26 +1,20 @@
<?php
class ImageTest extends ShimmieWebTestCase {
class ImageTest { // extends ShimmiePHPUnitTestCase {
public function testUserStats() {
$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");
# 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();
}
}

View file

@ -1,8 +1,8 @@
<?php
class HashBanTest extends ShimmieWebTestCase {
class HashBanTest {
function testBan() {
$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->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();

View file

@ -1,12 +1,12 @@
<?php
class IndexTest extends ShimmieWebTestCase {
class IndexTest {
function testIndexPage() {
$this->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

View file

@ -1,5 +1,5 @@
<?php
class IPBanTest extends SCoreWebTestCase {
class IPBanTest {
function testIPBan() {
$this->get_page('ip_ban/list');
$this->assert_response(403);

View file

@ -1,8 +1,8 @@
<?php
class LinkImageTest extends ShimmieWebTestCase {
class LinkImageTest {
function testLinkImage() {
$this->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

View file

@ -1,5 +1,5 @@
<?php
class LogDatabaseTest extends SCoreWebTestCase {
class LogDatabaseTest extends ShimmiePHPUnitTestCase {
function testLog() {
$this->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();
}
}

View file

@ -1,8 +1,8 @@
<?php
class NumericScoreTest extends ShimmieWebTestCase {
class NumericScoreTest {
function testNumericScore() {
$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_text("Current Score: 0");
$this->click("Vote Down");

View file

@ -1,9 +1,7 @@
<?php
class OekakiTest extends SCoreWebTestCase {
class OekakiTest extends ShimmiePHPUnitTestCase {
function testLog() {
$this->log_in_as_user();
$this->get_page("oekaki/create");
$this->log_out();
}
}

View file

@ -1,5 +1,5 @@
<?php
class PrivMsgTest extends SCoreWebTestCase {
class PrivMsgTest {
function testPM() {
$this->log_in_as_admin();
$this->get_page("user/test");

View file

@ -1,5 +1,5 @@
<?php
class PoolsTest extends ShimmieWebTestCase {
class PoolsTest {
function testPools() {
$this->get_page('pool/list');
$this->assert_title("Pools");

View file

@ -1,8 +1,8 @@
<?php
class RandomTest extends ShimmieWebTestCase {
class RandomTest {
function testRandom() {
$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();
$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

View file

@ -1,8 +1,8 @@
<?php
class RatingTest extends ShimmieWebTestCase {
class RatingTest {
function testRating() {
$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");
# test for bug #735: user forced to set rating, can't
# set tags and leave unrated

View file

@ -1,8 +1,8 @@
<?php
class RegenThumbTest extends ShimmieWebTestCase {
class RegenThumbTest {
function testRegenThumb() {
$this->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");

View file

@ -1,8 +1,8 @@
<?php
class ReportImageTest extends ShimmieWebTestCase {
class ReportImageTest {
function testReportImage() {
$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('reason', "report details");
$this->click("Report");

View file

@ -1,5 +1,5 @@
<?php
class ResLimitTest extends ShimmieWebTestCase {
class ResLimitTest {
function testResLimitOK() {
$this->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");

View file

@ -1,8 +1,8 @@
<?php
class RSSCommentsTest extends ShimmieWebTestCase {
class RSSCommentsTest {
function testImageFeed() {
$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->set_field('comment', "Test Comment ASDFASDF");
$this->click("Post Comment");

View file

@ -1,8 +1,8 @@
<?php
class RSSImagesTest extends ShimmieWebTestCase {
class RSSImagesTest {
function testImageFeed() {
$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('rss/images');

View file

@ -1,5 +1,5 @@
<?php
class SetupTest extends SCoreWebTestCase {
class SetupTest {
function testAuth() {
$this->get_page('setup');
$this->assert_response(403);

View file

@ -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)){

View file

@ -1,29 +1,23 @@
<?php
class ShimmieApiTest extends ShimmieWebTestCase {
class ShimmieApiTest extends ShimmiePHPUnitTestCase {
function testAPI() {
$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");
// 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();
}
}

View file

@ -1,5 +1,5 @@
<?php
class SiteDescriptionTest extends SCoreWebTestCase {
class SiteDescriptionTest {
function testSiteDescription() {
$this->log_in_as_admin();
$this->get_page('setup');

View file

@ -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);

View file

@ -1,9 +1,8 @@
<?php
class XMLSitemapTest extends ShimmieWebTestCase {
class XMLSitemapTest extends ShimmiePHPUnitTestCase {
function testBasic() {
# this will implicitly check that there are no
# PHP-level error messages
$this->get_page('sitemap.xml');
}
}

View file

@ -1,8 +1,8 @@
<?php
class TagEditTest extends ShimmieWebTestCase {
class TagEditTest {
function testTagEdit() {
$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");
$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");

View file

@ -1,8 +1,8 @@
<?php
class TagHistoryTest extends ShimmieWebTestCase {
class TagHistoryTest {
function testTagHistory() {
$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");
$this->set_field("tag_edit__tags", "new");

View file

@ -1,5 +1,5 @@
<?php
class TagListTest extends ShimmieWebTestCase {
class TagListTest extends ShimmiePHPUnitTestCase {
var $pages = array("map", "alphabetic", "popularity", "categories");
function testTagList() {
@ -34,4 +34,3 @@ class TagListTest extends ShimmieWebTestCase {
}
}
}

View file

@ -1,5 +1,5 @@
<?php
class TipsTest extends SCoreWebTestCase {
class TipsTest {
function setUp() {
$this->log_in_as_admin();
$raw = $this->get_page("tips/list");

View file

@ -1,15 +1,15 @@
<?php
class UploadTest extends ShimmieWebTestCase {
class UploadTest {
function testUpload() {
$this->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");

View file

@ -1,5 +1,5 @@
<?php
class UserPageTest extends SCoreWebTestCase {
class UserPageTest extends ShimmiePHPUnitTestCase {
function testUserPage() {
$this->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");
}
}

View file

@ -1,10 +1,10 @@
<?php
class ViewTest extends ShimmieWebTestCase {
class ViewTest {
function testViewPage() {
$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");
$idp1 = $image_id_3 + 1;
$this->log_out();

View file

@ -1,5 +1,5 @@
<?php
class WikiTest extends SCoreWebTestCase {
class WikiTest {
function testIndex() {
$this->get_page("wiki");
$this->assert_title("Index");

View file

@ -1,5 +1,5 @@
<?php
class WordFilterTest extends ShimmieWebTestCase {
class WordFilterTest {
function testWordFilter() {
$this->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

View file

@ -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 <webmaster at shishnet.org>, jgen <jeffgenovy at gmail.com>
* @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');
?>
<!DOCTYPE html>
<html>
<!-- Shimmie (c) Shish et all. 2007-2013 -->
<head>
<title>Shimmie Installation</title>
<link rel="shortcut icon" href="favicon.ico" />
@ -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 <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Things are OK \o/</h3>
<p>If you aren't redirected, <a href="index.php">click here to Continue</a>.
</div>
EOD;
}
else {
$h_file_content = htmlentities($file_content);
print <<<EOD
<div id="installer">
@ -448,12 +459,12 @@ function write_config() { // {{{
<p><textarea cols="80" rows="2">$h_file_content</textarea>
<p>Once done, <a href="index.php">Click here to Continue</a>.
<p>Once done, <a href="index.php">click here to Continue</a>.
<br/><br/>
</div>
EOD;
exit;
}
echo "\n";
} // }}}
?>
</body>

View file

@ -1,58 +0,0 @@
<?php
/**
* SimpleTest integration with Travis CI for Shimmie
*
* @package Shimmie
* @author jgen <jeffgenovy@gmail.com>
* @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);

115
tests/bootstrap.php Normal file
View file

@ -0,0 +1,115 @@
<?php
define("TIMEZONE", 'UTC');
define("EXTRA_EXTS", str_replace("ext/", "", implode(',', glob('ext/*'))));
define("BASE_HREF", "/");
define("CLI_LOG_LEVEL", 50);
$_SERVER['QUERY_STRING'] = '/';
require_once "core/_bootstrap.inc.php";
if(is_null(User::by_name("demo"))) {
$userPage = new UserPage();
$userPage->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);
}
}
}

View file

@ -1,78 +0,0 @@
<?php
/**
* SimpleTest integration with Travis CI for Shimmie
*
* @package Shimmie
* @author jgen <jeffgenovy@gmail.com>
* @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);

7
tests/phpunit.xml Normal file
View file

@ -0,0 +1,7 @@
<phpunit bootstrap="../tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="shimmie">
<directory suffix="test.php">../ext/</directory>
</testsuite>
</testsuites>
</phpunit>