Source
xxxxxxxxxx
<?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';
class testTriggerDependencies extends CWebTest {
/**
* SQL to check trigger dependencies hash.
*/
const SQL = 'SELECT * FROM trigger_depends ORDER by triggerdepid';
/**
* Attach Behaviors to the test.
*
* @return array
*/
public function getBehaviors() {
return [
CMessageBehavior::class,
CTableBehavior::class
];
}
/**
* Create or update trigger with dependencies.
*
* @param array $data data provider.
* @param string $success_title success message title.
* @param string $expression trigger expression used in create scenarios.
* @param string $error_title error message title.
* @param string $name_check trigger name that should be checked in update scenarios.
*/
public function triggerCreateUpdate($data, $success_title, $expression = null, $error_title = null, $name_check = null) {
// If scenarios is TEST_BAD, hash should be checked.
if (CTestArrayHelper::get($data, 'expected', TEST_GOOD) === TEST_BAD) {
$old_hash = CDBHelper::getHash(self::SQL);
}
$form = $this->query('name:triggersForm')->asForm(['normalized' => true])->waitUntilPresent()->one();
if ($expression) {
$form->fill(['Name' => $data['name'], 'Expression' => $expression]);
}
// Add trigger/host trigger dependency.
$form->selectTab('Dependencies');
// If expressions doesn't exist, then it is update scenario.
if (is_null($expression) && CTestArrayHelper::get($data, 'expected', TEST_GOOD) === TEST_GOOD) {
foreach ($form->getField('Dependencies')->asTable()->getRows() as $row) {
$row->query('button:Remove')->one()->click();
}
}
// Dependencies buttons.
$trigger_dependencies = [
'dependencies' => 'Add',
'prototype_dependencies' => 'Add prototype'
];
// Add dependencies.
foreach ($trigger_dependencies as $dependency_type => $selector) {
if (array_key_exists($dependency_type, $data)) {
$this->addDependence($data[$dependency_type], $selector);
}
}
$form->submit();
$this->page->waitUntilReady();