Skip to content

Commit d8c2651

Browse files
authored
Merge branch 'main' into testing5
2 parents 817efbd + 44394c4 commit d8c2651

File tree

6 files changed

+78
-26
lines changed

6 files changed

+78
-26
lines changed

resources/lib/UnitySQL.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ public function accDeletionRequestExists($uid)
283283
return count($stmt->fetchAll()) > 0;
284284
}
285285

286+
public function deleteAccountDeletionRequest($uid)
287+
{
288+
if (!$this->accDeletionRequestExists($uid)) {
289+
return;
290+
}
291+
$stmt = $this->conn->prepare(
292+
"DELETE FROM " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " WHERE uid=:uid"
293+
);
294+
$stmt->bindParam(":uid", $uid);
295+
$stmt->execute();
296+
}
297+
286298
public function getSiteVar($name)
287299
{
288300
$stmt = $this->conn->prepare(

test/functional/AccountDeletionRequestTest.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@ public function testRequestAccountDeletionUserHasNoGroups()
3737
switchUser(...getUserHasNotRequestedAccountDeletionHasNoGroups());
3838
$this->assertEmpty($USER->getGroups());
3939
$this->assertNumberAccountDeletionRequests(0);
40-
post(
41-
__DIR__ . "/../../webroot/panel/account.php",
42-
["form_type" => "account_deletion_request"]
43-
);
44-
$this->assertNumberAccountDeletionRequests(1);
45-
post(
46-
__DIR__ . "/../../webroot/panel/account.php",
47-
["form_type" => "account_deletion_request"]
48-
);
49-
$this->assertNumberAccountDeletionRequests(1);
40+
try {
41+
post(
42+
__DIR__ . "/../../webroot/panel/account.php",
43+
["form_type" => "account_deletion_request"]
44+
);
45+
$this->assertNumberAccountDeletionRequests(1);
46+
post(
47+
__DIR__ . "/../../webroot/panel/account.php",
48+
["form_type" => "account_deletion_request"]
49+
);
50+
$this->assertNumberAccountDeletionRequests(1);
51+
} finally {
52+
$SQL->deleteAccountDeletionRequest($USER->getUID());
53+
$this->assertNumberAccountDeletionRequests(0);
54+
}
5055
}
5156

5257
public function testRequestAccountDeletionUserHasGroup()
@@ -56,10 +61,15 @@ public function testRequestAccountDeletionUserHasGroup()
5661
switchUser(...getUserHasNotRequestedAccountDeletionHasGroup());
5762
$this->assertNotEmpty($USER->getGroups());
5863
$this->assertNumberAccountDeletionRequests(0);
59-
post(
60-
__DIR__ . "/../../webroot/panel/account.php",
61-
["form_type" => "account_deletion_request"]
62-
);
63-
$this->assertNumberAccountDeletionRequests(0);
64+
try {
65+
post(
66+
__DIR__ . "/../../webroot/panel/account.php",
67+
["form_type" => "account_deletion_request"]
68+
);
69+
$this->assertNumberAccountDeletionRequests(0);
70+
} finally {
71+
$SQL->deleteAccountDeletionRequest($USER->getUID());
72+
$this->assertNumberAccountDeletionRequests(0);
73+
}
6474
}
6575
}

test/functional/PiBecomeRequestTest.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,37 @@ public function testRequestBecomePi()
3737
switchUser(...getUserNotPiNotRequestedBecomePi());
3838
$this->assertFalse($USER->isPI());
3939
$this->assertNumberPiBecomeRequests(0);
40-
post(
41-
__DIR__ . "/../../webroot/panel/account.php",
42-
["form_type" => "pi_request"]
43-
);
44-
$this->assertNumberPiBecomeRequests(1);
45-
post(
46-
__DIR__ . "/../../webroot/panel/account.php",
47-
["form_type" => "pi_request"]
48-
);
49-
$this->assertNumberPiBecomeRequests(1);
40+
try {
41+
post(
42+
__DIR__ . "/../../webroot/panel/account.php",
43+
["form_type" => "pi_request"]
44+
);
45+
$this->assertNumberPiBecomeRequests(1);
46+
post(
47+
__DIR__ . "/../../webroot/panel/account.php",
48+
["form_type" => "pi_request"]
49+
);
50+
$this->assertNumberPiBecomeRequests(1);
51+
} finally {
52+
$SQL->removeRequest($USER->getUID());
53+
}
54+
}
55+
56+
public function testRequestBecomePiUserRequestedAccountDeletion()
57+
{
58+
global $USER, $SQL;
59+
switchUser(...getUserNotPiNotRequestedBecomePiRequestedAccountDeletion());
60+
$this->assertFalse($USER->isPI());
61+
$this->assertNumberPiBecomeRequests(0);
62+
$this->assertTrue($SQL->accDeletionRequestExists($USER->getUID()));
63+
try {
64+
post(
65+
__DIR__ . "/../../webroot/panel/account.php",
66+
["form_type" => "pi_request"]
67+
);
68+
$this->assertNumberPiBecomeRequests(0);
69+
} finally {
70+
$SQL->removeRequest($USER->getUID());
71+
}
5072
}
5173
}

test/phpunit-bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ function getUserNotPiNotRequestedBecomePi()
100100
return ["[email protected]", "foo", "bar", "[email protected]"];
101101
}
102102

103+
function getUserNotPiNotRequestedBecomePiRequestedAccountDeletion()
104+
{
105+
return ["[email protected]", "foo", "bar", "[email protected]"];
106+
}
107+
103108
function getUserWithOneKey()
104109
{
105110
return ["[email protected]", "foo", "bar", "[email protected]"];

tools/docker-dev/sql/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ RUN apt-get update && apt-get install -y \
1010
netcat-openbsd
1111
RUN sed -i '/bind-address/c\bind-address = 0.0.0.0' /etc/mysql/mariadb.conf.d/50-server.cnf
1212
COPY bootstrap.sql /tmp/bootstrap.sql
13+
COPY bootstrap-users.sql /tmp/bootstrap-users.sql
1314

1415
RUN service mariadb start; \
1516
mariadb -e "CREATE DATABASE unity"; \
1617
mariadb -e "CREATE USER 'unity'@'%' IDENTIFIED BY 'password'"; \
1718
mariadb -e "GRANT ALL PRIVILEGES ON unity.* TO 'unity'@'%'"; \
1819
mariadb -e "FLUSH PRIVILEGES"; \
19-
mariadb unity < /tmp/bootstrap.sql
20+
mariadb unity < /tmp/bootstrap.sql; \
21+
mariadb unity < /tmp/bootstrap-users.sql
2022

2123
RUN rm -rf /tmp/bootstrap.sql
2224

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSERT INTO `account_deletion_requests` (`id`, `timestamp`, `uid`) VALUES (1, '1970-01-01 00:00:01', 'user4_org1_test');

0 commit comments

Comments
 (0)