Source
<?php
/*
** Zabbix
** 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 General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
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);