Source
$this->assertEquals($result['result']['tokenids'], $tokenids, 'Response tokenids should match the request.');
<?php declare(strict_types = 0);
/*
** 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/CAPITest.php';
/**
* @backup token
*/
class testToken extends CAPITest {
protected static $unique_counter = 1;
protected static function uniqueName(): string {
return 'name'.static::$unique_counter ++;
}
public static function token_create(): array {
return [
// Name field validation.
[
'tokens' => [
[
'name' => str_repeat('a', DB::getFieldLength('token', 'name'))
]
],
'expected_error' => null
],
[
'tokens' => [
[
'name' => str_repeat('a', DB::getFieldLength('token', 'name') + 1)
]
],
'expected_error' => 'Invalid parameter "/1/name": value is too long.'
],
[
'tokens' => [
[
'name' => ''
]
],
'expected_error' => 'Invalid parameter "/1/name": cannot be empty.'
],
// Description field validation.
[
'tokens' => [
[
'name' => static::uniqueName(),
'description' => str_repeat('a', DB::getFieldLength('token', 'description'))
]