Skip to content

Commit 9d39d30

Browse files
committed
more tests
1 parent 06fcb51 commit 9d39d30

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

test/functional/ViewAsUserTest.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
class ViewAsUserTest extends TestCase
88
{
9-
public function testViewAsUser()
9+
public function _testViewAsUser(array $beforeUser, array $afterUser)
1010
{
1111
global $USER;
12-
switchUser(...getNormalUser());
13-
$newUid = $USER->getUID();
14-
switchUser(...getAdminUser());
15-
$this->assertTrue($USER->isAdmin());
16-
$originalUid = $USER->getUID();
17-
$this->assertNotEquals($newUid, $originalUid);
12+
switchUser(...$afterUser);
13+
$afterUid = $USER->getUID();
14+
switchUser(...$beforeUser);
15+
// $this->assertTrue($USER->isAdmin());
16+
$beforeUid = $USER->getUID();
17+
// $this->assertNotEquals($afterUid, $beforeUid);
1818
try {
1919
http_post(
2020
__DIR__ . "/../../webroot/admin/user-mgmt.php",
2121
[
2222
"form_name" => "viewAsUser",
23-
"uid" => $newUid,
23+
"uid" => $afterUid,
2424
],
2525
);
2626
} catch (PhpUnitNoDieException) {}
@@ -30,8 +30,8 @@ public function testViewAsUser()
3030
session_write_close();
3131
http_get(__DIR__ . "/../../resources/init.php");
3232
// now we should be new user
33-
$this->assertEquals($newUid, $USER->getUID());
34-
$this->assertTrue($_SESSION["user_exists"]);
33+
$this->assertEquals($afterUid, $USER->getUID());
34+
// $this->assertTrue($_SESSION["user_exists"]);
3535
try {
3636
http_post(
3737
__DIR__ . "/../../resources/templates/header.php",
@@ -44,6 +44,21 @@ public function testViewAsUser()
4444
session_write_close();
4545
http_get(__DIR__ . "/../../resources/init.php");
4646
// now we should be back to original user
47-
$this->assertEquals($originalUid, $USER->getUID());
47+
$this->assertEquals($beforeUid, $USER->getUID());
48+
}
49+
50+
public function testViewAsUser()
51+
{
52+
$this->_testViewAsUser(getAdminUser(), getNormalUser());
53+
}
54+
55+
public function testViewAsNonExistentUser()
56+
{
57+
$this->_testViewAsUser(getAdminUser(), getNonExistentUser());
58+
}
59+
60+
public function testViewAsSelf()
61+
{
62+
$this->_testViewAsUser(getAdminUser(), getAdminUser());
4863
}
4964
}

0 commit comments

Comments
 (0)