Source
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
require_once dirname(__FILE__).'/../../include/CWebTest.php';
require_once dirname(__FILE__).'/../behaviors/CMessageBehavior.php';
require_once dirname(__FILE__).'/../behaviors/CTableBehavior.php';
/**
* Base class for API tokens page function tests.
*/
class testPageApiTokens extends CWebTest {
/**
* Attach MessageBehavior and TableBehavior to the test.
*
* @return array
*/
public function getBehaviors() {
return [
CMessageBehavior::class,
CTableBehavior::class
];
}
/**
* Function that checks the layout of the API token list in Administration or User settings section.
*
* @param array $token_data Reference array with expected content of the API tokens list table.
* @param string $source Section from which the scenario is executed.
*/
public function checkLayout($token_data, $source) {
if ($source === 'user settings') {
$url = 'zabbix.php?action=user.token.list';
$filter_fields = ['Name', 'Expires in less than', 'Status'];
$tokens_count = CDBHelper::getCount('SELECT tokenid FROM token WHERE userid=1');
$reference_headers = ['Name', 'Expires at', 'Created at', 'Last accessed at', 'Status'];
}
else {
$url = 'zabbix.php?action=token.list';
$filter_fields = ['Name', 'Users', 'Expires in less than', 'Created by users', 'Status'];
$tokens_count = CDBHelper::getCount('SELECT tokenid FROM token');
$reference_headers = ['Name', 'User', 'Expires at', 'Created at', 'Created by user', 'Last accessed at', 'Status'];
}
// Open API tokens page and check header.
$this->page->login()->open($url);
$this->page->assertHeader('API tokens');
// Check status of buttons on the API tokens page.
$form_buttons = [
'Create API token' => true,