3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
7 use PhpMyAdmin\CheckUserPrivileges
;
9 use PhpMyAdmin\DatabaseInterface
;
10 use PhpMyAdmin\ShowGrants
;
11 use PhpMyAdmin\UserPrivileges
;
12 use PHPUnit\Framework\Attributes\CoversClass
;
14 #[CoversClass(CheckUserPrivileges::class)]
15 class CheckUserPrivilegesTest
extends AbstractTestCase
17 private CheckUserPrivileges
$checkUserPrivileges;
20 * prepares environment for tests
22 protected function setUp(): void
26 DatabaseInterface
::$instance = $this->createDatabaseInterface();
27 Config
::getInstance()->selectedServer
['DisableIS'] = false;
28 UserPrivileges
::$column = false;
29 UserPrivileges
::$database = false;
30 UserPrivileges
::$routines = false;
31 UserPrivileges
::$table = false;
32 UserPrivileges
::$isReload = false;
34 $this->checkUserPrivileges
= new CheckUserPrivileges(DatabaseInterface
::getInstance());
38 * Test for checkRequiredPrivilegesForAdjust
40 public function testCheckRequiredPrivilegesForAdjust(): void
43 $showGrants = new ShowGrants('GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'localhost\' WITH GRANT OPTION');
45 // call the to-be-tested function
46 $this->checkUserPrivileges
->checkRequiredPrivilegesForAdjust($showGrants);
48 $this->assertTrue(UserPrivileges
::$column);
49 $this->assertTrue(UserPrivileges
::$database);
50 $this->assertTrue(UserPrivileges
::$routines);
51 $this->assertTrue(UserPrivileges
::$table);
53 // re-initialise the privileges
57 $showGrants = new ShowGrants('GRANT ALL PRIVILEGES ON `mysql`.* TO \'root\'@\'localhost\' WITH GRANT OPTION');
59 // call the to-be-tested function
60 $this->checkUserPrivileges
->checkRequiredPrivilegesForAdjust($showGrants);
62 $this->assertTrue(UserPrivileges
::$column);
63 $this->assertTrue(UserPrivileges
::$database);
64 $this->assertTrue(UserPrivileges
::$routines);
65 $this->assertTrue(UserPrivileges
::$table);
67 // re-initialise the privileges
71 $showGrants = new ShowGrants('GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.* TO \'root\'@\'localhost\'');
73 // call the to-be-tested function
74 $this->checkUserPrivileges
->checkRequiredPrivilegesForAdjust($showGrants);
76 $this->assertTrue(UserPrivileges
::$column);
77 $this->assertTrue(UserPrivileges
::$database);
78 $this->assertTrue(UserPrivileges
::$routines);
79 $this->assertTrue(UserPrivileges
::$table);
81 // re-initialise the privileges
85 $showGrants = new ShowGrants('GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.`db` TO \'root\'@\'localhost\'');
87 // call the to-be-tested function
88 $this->checkUserPrivileges
->checkRequiredPrivilegesForAdjust($showGrants);
90 $this->assertFalse(UserPrivileges
::$column);
91 $this->assertTrue(UserPrivileges
::$database);
92 $this->assertFalse(UserPrivileges
::$routines);
93 $this->assertFalse(UserPrivileges
::$table);