createDatabaseInterface(); $GLOBALS['db'] = ''; $GLOBALS['table'] = ''; $this->configurableMenusFeature = new ConfigurableMenusFeature( DatabaseName::fromValue('pmadb'), TableName::fromValue('usergroups'), TableName::fromValue('users'), ); } /** * Tests UserGroups::getHtmlForUserGroupsTable() function when there are no user groups * * @group medium */ public function testGetHtmlForUserGroupsTableWithNoUserGroups(): void { $expectedQuery = 'SELECT * FROM `pmadb`.`usergroups` ORDER BY `usergroup` ASC'; $resultStub = $this->createMock(DummyResult::class); $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->once()) ->method('tryQueryAsControlUser') ->with($expectedQuery) ->will($this->returnValue($resultStub)); $resultStub->expects($this->once()) ->method('numRows') ->will($this->returnValue(0)); $GLOBALS['dbi'] = $dbi; $html = UserGroups::getHtmlForUserGroupsTable($this->configurableMenusFeature); $this->assertStringNotContainsString('', $html); $urlTag = '', $html, ); } /** * Tests UserGroups::delete() function */ public function testDeleteUserGroup(): void { $userDelQuery = 'DELETE FROM `pmadb`.`users` WHERE `usergroup`=\'ug\''; $userGrpDelQuery = 'DELETE FROM `pmadb`.`usergroups` WHERE `usergroup`=\'ug\''; $result = $this->createStub(ResultInterface::class); $dbi = $this->createMock(DatabaseInterface::class); $dbi->expects($this->exactly(2))->method('queryAsControlUser')->willReturnMap([ [$userDelQuery, $result], [$userGrpDelQuery, $result], ]); $dbi->expects($this->any())->method('quoteString') ->will($this->returnCallback(static fn (string $string): string => "'" . $string . "'")); UserGroups::delete($dbi, $this->configurableMenusFeature, 'ug'); } /** * Tests UserGroups::getHtmlToEditUserGroup() function */ public function testGetHtmlToEditUserGroup(): void { // adding a user group $html = UserGroups::getHtmlToEditUserGroup($this->configurableMenusFeature); $this->assertStringContainsString('assertStringContainsString('createMock(DummyResult::class); $expectedQuery = 'SELECT * FROM `pmadb`.`usergroups` WHERE `usergroup`=\'ug\''; $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->once()) ->method('tryQueryAsControlUser') ->with($expectedQuery) ->will($this->returnValue($resultStub)); $resultStub->expects($this->exactly(1)) ->method('getIterator') ->will($this->returnCallback(static function (): Generator { yield from [['usergroup' => 'ug', 'tab' => 'server_sql', 'allowed' => 'Y']]; })); $dbi->expects($this->any())->method('quoteString') ->will($this->returnCallback(static fn (string $string): string => "'" . $string . "'")); $GLOBALS['dbi'] = $dbi; // editing a user group $html = UserGroups::getHtmlToEditUserGroup($this->configurableMenusFeature, 'ug'); $this->assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString( '', $html, ); $this->assertStringContainsString( '', $html, ); } }