Source
$hintbox_text = $this->query('xpath://div[@class="overlay-dialogue wordbreak"]')->one()->waitUntilVisible()->getText();
<?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';
/**
* Base class for API tokens form function tests.
*/
class testFormApiTokens extends CWebTest {
/**
* Attach MessageBehavior to the test.
*
* @return array
*/
public function getBehaviors() {
return [
'class' => CMessageBehavior::class
];
}
const UPDATE_TOKEN = 'Admin reference token'; // Token for update.
const DELETE_TOKEN = 'Token to be deleted'; // Token for deletion.
const USER_ZABBIX_TOKEN = 'user-zabbix token'; // Token to be updated that belongs to user-zabbix.
public static $tokenid;
/**
* Function retrieves the tokenid based on token name.
*
* @param string $token_name The name of the token for which the ID is obtained.
* @param boolean $return Flag that specifies whether token id should be returned by this method.
*
* @return string
*/
public function getTokenId($token_name = self::UPDATE_TOKEN) {
self::$tokenid = CDBHelper::getValue('SELECT tokenid FROM token WHERE name='.zbx_dbstr($token_name));
return self::$tokenid;
}
/**
* Function that checks the layout of the API token configuration form in Administration or User settings section.
*
* @param string $source Section from which the scenario is executed.
*/
public function checkTokensFormLayout($source) {
$this->page->login()->open('zabbix.php?action='.(($source === 'user settings') ? 'user.token.edit' : 'token.edit'));
$this->page->assertTitle('API tokens');
$this->page->assertHeader('API tokens');
$form = $this->query('id:token_form')->asForm()->one();
foreach (['Name' => '64', 'Description' => '65535'] as $field_name => $maxlength) {
$field = $form->getField($field_name);
$this->assertEquals('', $field->getValue());
$this->assertEquals($maxlength, $field->getAttribute('maxlength'));
}
// Check the presence of User field and that it is empty by default if it exists.
if ($source === 'administration') {
$this->assertEquals('', $form->getField('User')->getValue());
}
else {
$this->assertFalse($form->query('xpath://label[text()="User"]')->one(false)->isDisplayed());
}
// Check that "Set expiration date and time" checkbox is set by default.
$expiration_checkbox = $form->getField('Set expiration date and time');
$this->assertTrue($expiration_checkbox->getValue());
$expires_at = $form->getField('Expires at')->query('id:expires_at')->one();
$this->assertEquals('',$field->getValue());