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'; $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->once()) ->method('tryQuery') ->with($expectedQuery) ->will($this->returnValue(true)); $dbi->expects($this->once()) ->method('numRows') ->withAnyParameters() ->will($this->returnValue(0)); $dbi->expects($this->once()) ->method('freeResult'); $GLOBALS['dbi'] = $dbi; $html = UserGroups::getHtmlForUserGroupsTable($this->configurableMenusFeature); $this->assertStringNotContainsString('', $html); $url_tag = '', $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\''; $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->exactly(2)) ->method('query') ->withConsecutive([$this->equalTo($userDelQuery)], [$this->equalTo($userGrpDelQuery)]); $dbi->expects($this->any()) ->method('escapeString') ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; UserGroups::delete($this->configurableMenusFeature, 'ug'); } /** * Tests UserGroups::getHtmlToEditUserGroup() function */ public function testGetHtmlToEditUserGroup(): void { // adding a user group $html = UserGroups::getHtmlToEditUserGroup($this->configurableMenusFeature); $this->assertStringContainsString('assertStringContainsString('getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->once()) ->method('tryQuery') ->with($expectedQuery) ->will($this->returnValue(true)); $dbi->expects($this->exactly(2)) ->method('fetchAssoc') ->willReturnOnConsecutiveCalls( [ 'usergroup' => 'ug', 'tab' => 'server_sql', 'allowed' => 'Y', ], null ); $dbi->expects($this->once()) ->method('freeResult'); $dbi->expects($this->any()) ->method('escapeString') ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; // editing a user group $html = UserGroups::getHtmlToEditUserGroup($this->configurableMenusFeature, 'ug'); $this->assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString( '', $html ); $this->assertStringContainsString( '', $html ); } }