2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2023-01-10 22:44:09 +00:00
|
|
|
|
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class WikiTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testIndex(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-02-11 11:34:09 +00:00
|
|
|
$page = $this->get_page("wiki");
|
|
|
|
$this->assertEquals(PageMode::REDIRECT, $page->mode);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 16:40:38 +00:00
|
|
|
// By default users are read-only
|
|
|
|
public function testAccessUser(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-02-10 16:40:38 +00:00
|
|
|
$this->log_in_as_user();
|
|
|
|
|
|
|
|
$this->get_page("wiki/test");
|
|
|
|
$this->assert_title("test");
|
|
|
|
$this->assert_text("This is a default page");
|
|
|
|
|
2024-02-11 15:47:40 +00:00
|
|
|
$this->assertException(PermissionDenied::class, function () {
|
2024-02-10 23:03:14 +00:00
|
|
|
$this->get_page("wiki/test/edit");
|
|
|
|
});
|
2024-02-10 16:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Admins can edit
|
|
|
|
public function testAccessAdmin(): void
|
|
|
|
{
|
|
|
|
$this->log_in_as_admin();
|
|
|
|
|
|
|
|
$this->get_page("wiki/test");
|
|
|
|
$this->assert_title("test");
|
|
|
|
$this->assert_text("This is a default page");
|
|
|
|
|
|
|
|
$this->get_page("wiki/test/edit");
|
|
|
|
$this->assert_text("Editor");
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testDefault(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testRevisions(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
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
|
|
|
|
2024-02-10 16:40:38 +00:00
|
|
|
$this->get_page("wiki/test/history");
|
|
|
|
$this->assert_title("test");
|
|
|
|
$this->assert_text("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
|
|
|
}
|