This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/ipban/test.php

61 lines
1.5 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
class IPBanTest extends ShimmiePHPUnitTestCase
{
# FIXME: test that the IP is actually banned
2020-01-29 00:49:21 +00:00
public function testAccess()
{
$page = $this->get_page('ip_ban/list');
$this->assertEquals(403, $page->code);
$this->assertEquals("Permission Denied", $page->title);
}
2020-01-29 00:49:21 +00:00
public function testIPBan()
{
global $database;
$this->log_in_as_admin();
// Check initial state
$this->get_page('ip_ban/list');
$this->assert_no_text("42.42.42.42");
// Add ban
send_event(new AddIPBanEvent(
'42.42.42.42',
'block',
'unit testing',
2020-01-30 09:01:19 +00:00
'2030-01-01'
));
// Check added
$page = $this->get_page('ip_ban/list');
$this->assertStringContainsString(
"42.42.42.42",
$page->find_block("Edit IP Bans")->body
);
2009-01-04 19:18:37 +00:00
// Delete ban
$ban_id = (int)$database->get_one("SELECT id FROM bans");
send_event(new RemoveIPBanEvent($ban_id));
// Check delete
$page = $this->get_page('ip_ban/list');
$this->assertStringNotContainsString(
"42.42.42.42",
$page->find_block("Edit IP Bans")->body
);
}
2009-09-27 14:48:38 +00:00
2020-01-29 00:49:21 +00:00
public function test_all()
{
2020-01-29 20:22:50 +00:00
// just test it doesn't crash for now
$this->log_in_as_admin();
2020-01-29 20:22:50 +00:00
$page = $this->get_page('ip_ban/list', ['r_all'=>'on']);
$this->assertEquals(200, $page->code);
}
}