2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-05-28 16:59:38 +00:00
|
|
|
class WikiTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
|
|
|
public function testIndex()
|
|
|
|
{
|
|
|
|
$this->get_page("wiki");
|
|
|
|
$this->assert_title("Index");
|
|
|
|
$this->assert_text("This is a default page");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAccess()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
foreach (["anon", "user", "admin"] as $user) {
|
|
|
|
foreach ([false, true] as $allowed) {
|
|
|
|
// admin has no settings to set
|
|
|
|
if ($user != "admin") {
|
|
|
|
$config->set_bool("wiki_edit_$user", $allowed);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user == "user") {
|
|
|
|
$this->log_in_as_user();
|
|
|
|
}
|
|
|
|
if ($user == "admin") {
|
|
|
|
$this->log_in_as_admin();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->get_page("wiki/test");
|
|
|
|
$this->assert_title("test");
|
|
|
|
$this->assert_text("This is a default page");
|
|
|
|
|
|
|
|
if ($allowed || $user == "admin") {
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->post_page("wiki_admin/edit", ["title"=>"test"]);
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_text("Editor");
|
2020-01-28 21:19:59 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
// Everyone can see the editor
|
|
|
|
else {
|
|
|
|
$this->post_page("wiki_admin/edit", ["title"=>"test"]);
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_no_text("Editor");
|
|
|
|
}
|
2020-01-28 21:19:59 +00:00
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
if ($user == "user" || $user == "admin") {
|
|
|
|
$this->log_out();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefault()
|
|
|
|
{
|
2020-01-28 21:19:59 +00:00
|
|
|
global $user;
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->log_in_as_admin();
|
2020-01-28 21:19:59 +00:00
|
|
|
|
|
|
|
// Check default page is default
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page("wiki/wiki:default");
|
|
|
|
$this->assert_title("wiki:default");
|
|
|
|
$this->assert_text("This is a default page");
|
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
// Customise default page
|
|
|
|
$wikipage = Wiki::get_page("wiki:default");
|
|
|
|
$wikipage->revision = 1;
|
|
|
|
$wikipage->body = "New Default Template";
|
|
|
|
send_event(new WikiUpdateEvent($user, $wikipage));
|
|
|
|
|
|
|
|
// Check that some random page is using the new default
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page("wiki/something");
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->assert_text("New Default Template");
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
// Delete the custom default
|
|
|
|
send_event(new WikiDeletePageEvent("wiki:default"));
|
|
|
|
|
|
|
|
// Check that the default page is back to normal
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page("wiki/wiki:default");
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->assert_title("wiki:default");
|
|
|
|
$this->assert_text("This is a default page");
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRevisions()
|
|
|
|
{
|
2020-01-28 21:19:59 +00:00
|
|
|
global $user;
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->log_in_as_admin();
|
2020-01-28 21:19:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page("wiki/test");
|
|
|
|
$this->assert_title("test");
|
|
|
|
$this->assert_text("This is a default page");
|
2020-01-28 21:19:59 +00:00
|
|
|
|
|
|
|
$wikipage = Wiki::get_page("test");
|
|
|
|
$wikipage->revision = $wikipage->revision + 1;
|
|
|
|
$wikipage->body = "Mooooo 1";
|
|
|
|
send_event(new WikiUpdateEvent($user, $wikipage));
|
|
|
|
$this->get_page("wiki/test");
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_text("Mooooo 1");
|
|
|
|
$this->assert_text("Revision 1");
|
2020-01-28 21:19:59 +00:00
|
|
|
|
|
|
|
$wikipage = Wiki::get_page("test");
|
|
|
|
$wikipage->revision = $wikipage->revision + 1;
|
|
|
|
$wikipage->body = "Mooooo 2";
|
|
|
|
send_event(new WikiUpdateEvent($user, $wikipage));
|
|
|
|
$this->get_page("wiki/test");
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_text("Mooooo 2");
|
|
|
|
$this->assert_text("Revision 2");
|
2020-01-28 21:19:59 +00:00
|
|
|
|
|
|
|
send_event(new WikiDeleteRevisionEvent("test", 2));
|
|
|
|
$this->get_page("wiki/test");
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_text("Mooooo 1");
|
|
|
|
$this->assert_text("Revision 1");
|
2020-01-28 21:19:59 +00:00
|
|
|
|
|
|
|
send_event(new WikiDeletePageEvent("test"));
|
|
|
|
$this->get_page("wiki/test");
|
|
|
|
$this->assert_title("test");
|
|
|
|
$this->assert_text("This is a default page");
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-07-19 03:48:25 +00:00
|
|
|
}
|