|
| 1 | +<?php |
| 2 | + |
| 3 | +use PHPUnit\Framework\TestCase; |
| 4 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 5 | +use UnityWebPortal\lib\UnityUser; |
| 6 | +use UnityWebPortal\lib\UnityLDAP; |
| 7 | +use UnityWebPortal\lib\RedirectException; |
| 8 | + |
| 9 | +class PiDisbandTest extends TestCase { |
| 10 | + static $requestUid; |
| 11 | + |
| 12 | + public static function setUpBeforeClass(): void{ |
| 13 | + global $USER; |
| 14 | + switchUser(...getNormalUser()); |
| 15 | + self::$requestUid = $USER->getUID(); |
| 16 | + } |
| 17 | + |
| 18 | + private function disband() |
| 19 | + { |
| 20 | + // PI disband leads to redirect, redirect doesn't work during testing |
| 21 | + try { |
| 22 | + post( |
| 23 | + __DIR__ . "/../../webroot/panel/pi.php", |
| 24 | + ["form_name" => "disband"] |
| 25 | + ); |
| 26 | + } catch (RedirectException $e) {} |
| 27 | + } |
| 28 | + |
| 29 | + public function testDisband() |
| 30 | + { |
| 31 | + global $USER, $SQL; |
| 32 | + switchUser(...getUserIsPIHasNoMembersNoMemberRequests()); |
| 33 | + $pi = $USER; |
| 34 | + $piGroup = $USER->getPIGroup(); |
| 35 | + $piGroup->requestGroup(true); |
| 36 | + $piGroup->approveGroup(); |
| 37 | + $piGroupEntry = $piGroup->getLDAPPiGroup(); |
| 38 | + $piGroupAttributesBefore = $piGroupEntry->getAttributes(); |
| 39 | + error_log(json_encode($piGroupAttributesBefore, JSON_PRETTY_PRINT)); |
| 40 | + $piGroupName = $piGroup->getPIUID(); |
| 41 | + $this->assertTrue($piGroup->exists()); |
| 42 | + $this->assertEquals([$pi->getUID()], $piGroup->getGroupMemberUIDs()); |
| 43 | + $this->assertEmpty($piGroup->getRequests()); |
| 44 | + try { |
| 45 | + $SQL->addRequest(self::$requestUid, $piGroupName); |
| 46 | + $this->disband(); |
| 47 | + $this->assertFalse($piGroup->exists()); |
| 48 | + $this->assertEmpty($SQL->getRequests($piGroup->getPIUID())); |
| 49 | + } finally { |
| 50 | + $piGroupEntry->setAttributes($piGroupAttributesBefore); |
| 51 | + if (!$piGroupEntry->write()) { |
| 52 | + throw new Exception("Failed to recreate POSIX group $piGroupName"); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments