diff options
author | Anna Kucenko <git-no-reply@zabbix.com> | 2018-07-16 11:20:51 +0300 |
---|---|---|
committer | Anna Kucenko <git-no-reply@zabbix.com> | 2018-07-16 11:20:51 +0300 |
commit | 335a17f6822090733db5cd9fd4eba0b4f2082279 (patch) | |
tree | fb04e47db33894a8131d05a1ab52c7119fe68b47 /frontends | |
parent | e6e8dd300c45fa61c3b22b5512a1beccf484c348 (diff) |
.......... [DEV-850] added new Selenium tests - Inheritance Host prototype
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/php/tests/selenium/data/data_test.sql | 37 | ||||
-rw-r--r-- | frontends/php/tests/selenium/testInheritanceHostPrototype.php | 423 |
2 files changed, 460 insertions, 0 deletions
diff --git a/frontends/php/tests/selenium/data/data_test.sql b/frontends/php/tests/selenium/data/data_test.sql index ba848accd9f..c41f91dcbde 100644 --- a/frontends/php/tests/selenium/data/data_test.sql +++ b/frontends/php/tests/selenium/data/data_test.sql @@ -1621,3 +1621,40 @@ INSERT INTO alerts (alertid, actionid, eventid, userid, clock, mediatypeid, send INSERT INTO alerts (alertid, actionid, eventid, userid, clock, mediatypeid, sendto, subject, message, status, retries, error, esc_step, alerttype) VALUES (125, 12, 1, 7, 1478201613, 3, 'notificatio.report@zabbix.com', 'PROBLEM: problem', 'Event at 2016.11.03 21:33:33', 1, 0, '', 1, 1); INSERT INTO alerts (alertid, actionid, eventid, userid, clock, mediatypeid, sendto, subject, message, status, retries, error, esc_step, alerttype) VALUES (126, 12, 1, 7, 1478032474, 3, 'notificatio.report@zabbix.com', 'PROBLEM: problem', 'Event at 2016.11.01 22:34:34', 1, 0, '', 1, 1); INSERT INTO alerts (alertid, actionid, eventid, userid, clock, mediatypeid, sendto, subject, message, status, retries, error, esc_step, alerttype) VALUES (127, 12, 1, 7, 1478122535, 3, 'notificatio.report@zabbix.com', 'PROBLEM: problem', 'Event at 2016.11.02 23:35:35', 1, 0, '', 1, 1); + +-- testInheritanceHostPrototype +INSERT INTO groups (groupid, name, internal) VALUES (15, 'Inheritance test', 0); +INSERT INTO hosts (hostid, host, name, flags, templateid, description) VALUES (15, 'Inheritance test', 'Inheritance test', 0, NULL, 'Inheritance test'); +INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES (15, 15, 1); +INSERT INTO hosts (hostid, host, name, flags, templateid, description) VALUES (99000, 'testInheritanceHostPrototype {#TEST}', 'testInheritanceHostPrototype {#TEST}', 2, NULL, 'testInheritanceHostPrototype {#TEST}'); +INSERT INTO hosts (hostid, host, name, flags, templateid, description) VALUES (99001, 'testInheritanceHostPrototype {#TEST}', 'testInheritanceHostPrototype {#TEST}', 2, 99000, 'testInheritanceHostPrototype {#TEST}'); +INSERT INTO host_discovery (hostid, parent_hostid, parent_itemid, host, lastcheck, ts_delete) VALUES (99000, NULL, 15011, '', 0, 0); +INSERT INTO host_discovery (hostid, parent_hostid, parent_itemid, host, lastcheck, ts_delete) VALUES (99001, NULL, 15016, '', 0, 0); +INSERT INTO group_prototype (group_prototypeid, hostid, name, groupid, templateid) VALUES (1000, 99000, '', 15, NULL); +INSERT INTO group_prototype (group_prototypeid, hostid, name, groupid, templateid) VALUES (1001, 99001, '', 15, 1000); +INSERT INTO host_inventory (hostid, inventory_mode, hardware_full, software_full, contact, location, notes, host_networks, site_notes, poc_1_notes, poc_2_notes) VALUES (99000, -1, '', '', '', '', '', '', '', '', ''); +INSERT INTO host_inventory (hostid, inventory_mode, hardware_full, software_full, contact, location, notes, host_networks, site_notes, poc_1_notes, poc_2_notes) VALUES (99001, -1, '', '', '', '', '', '', '', '', ''); +INSERT INTO hosts (hostid, host, name, status, description) VALUES (99006, 'Inheritance test template with host prototype', 'Inheritance test template with host prototype', 3, ''); +INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES (99006, 99006, 15); +INSERT INTO items (itemid, hostid, type, name, key_, delay, value_type, formula, params, description, posts, headers, flags) VALUES (99083, 99006, 2, 'Discovery rule for host prototype test', 'key_test', '30s', 4, '', '', '', '', '', 1); +INSERT INTO hosts (hostid, host, name, status, description, flags) VALUES (99007, 'Host prototype for update {#TEST}', 'Host prototype for update {#TEST}', 0, '', 2); +INSERT INTO group_prototype (group_prototypeid, hostid, name, groupid, templateid) VALUES (1002, 99007, '', 15, NULL); +INSERT INTO host_discovery (hostid, parent_hostid, parent_itemid, host, lastcheck, ts_delete) VALUES (99007, NULL, 99083, '', 0, 0); +INSERT INTO host_inventory (hostid, inventory_mode, hardware_full, software_full, contact, location, notes, host_networks, site_notes, poc_1_notes, poc_2_notes) VALUES (99007, -1, '', '', '', '', '', '', '', '', ''); +INSERT INTO hosts (hostid, host, name, status, description, flags) VALUES (99009, 'Host prototype for delete {#TEST}', 'Host prototype for delete {#TEST}', 0, '', 2); +INSERT INTO group_prototype (group_prototypeid, hostid, name, groupid, templateid) VALUES (1004, 99009, '', 15, NULL); +INSERT INTO host_discovery (hostid, parent_hostid, parent_itemid, host, lastcheck, ts_delete) VALUES (99009, NULL, 99083, '', 0, 0); +INSERT INTO host_inventory (hostid, inventory_mode, hardware_full, software_full, contact, location, notes, host_networks, site_notes, poc_1_notes, poc_2_notes) VALUES (99009, -1, '', '', '', '', '', '', '', '', ''); +INSERT INTO hosts (hostid, host, name, status, description) VALUES (99004, 'Host for inheritance host prototype tests', 'Host for inheritance host prototype tests', 0, ''); +INSERT INTO interface (interfaceid, hostid, main, type, useip, ip, dns, port) VALUES (10026,99004,1,1,1,'127.0.0.1','','10050'); +INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES (99004, 99004, 15); +INSERT INTO hosts_templates (hosttemplateid, hostid, templateid) VALUES (15004, 99004, 99006); +INSERT INTO items (itemid, hostid, type, name, key_, delay, value_type, formula, params, description, posts, headers, templateid, flags) VALUES (99084, 99004, 2, 'Discovery rule for host prototype test', 'key_test', '30s', 4, '', '', '', '', '', 99083, 1); +INSERT INTO hosts (hostid, host, name, status, description, templateid, flags) VALUES (99008, 'Host prototype for update {#TEST}', 'Host prototype for update {#TEST}', 0, '', 99007, 2); +INSERT INTO group_prototype (group_prototypeid, hostid, name, groupid, templateid) VALUES (1003, 99008, '', 15, 1002); +INSERT INTO host_discovery (hostid, parent_hostid, parent_itemid, host, lastcheck, ts_delete) VALUES (99008, NULL, 99084, '', 0, 0); +INSERT INTO host_inventory (hostid, inventory_mode, hardware_full, software_full, contact, location, notes, host_networks, site_notes, poc_1_notes, poc_2_notes) VALUES (99008, -1, '', '', '', '', '', '', '', '', ''); +INSERT INTO hosts (hostid, host, name, status, description, templateid, flags) VALUES (99010, 'Host prototype for delete {#TEST}', 'Host prototype for delete {#TEST}', 0, '', 99009, 2); +INSERT INTO group_prototype (group_prototypeid, hostid, name, groupid, templateid) VALUES (1005, 99010, '', 15, 1004); +INSERT INTO host_discovery (hostid, parent_hostid, parent_itemid, host, lastcheck, ts_delete) VALUES (99010, NULL, 99084, '', 0, 0); +INSERT INTO host_inventory (hostid, inventory_mode, hardware_full, software_full, contact, location, notes, host_networks, site_notes, poc_1_notes, poc_2_notes) VALUES (99010, -1, '', '', '', '', '', '', '', '', ''); diff --git a/frontends/php/tests/selenium/testInheritanceHostPrototype.php b/frontends/php/tests/selenium/testInheritanceHostPrototype.php new file mode 100644 index 00000000000..28ee50b7bf6 --- /dev/null +++ b/frontends/php/tests/selenium/testInheritanceHostPrototype.php @@ -0,0 +1,423 @@ +<?php +/* +** Zabbix +** Copyright (C) 2001-2018 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/class.cwebtest.php'; + +/** + * Test the creation of inheritance of new objects on a previously linked template. + * + * @backup hosts + */ +class testInheritanceHostPrototype extends CWebTest { + + public static function getLayoutData() { + return [ + [ + [ + 'host_prototype' => 'Host prototype for update {#TEST}', + 'discovery_id' => 'Discovery rule for host prototype test' + ] + ] + ]; + } + + /** + * @dataProvider getLayoutData + */ + public function testInheritanceHostPrototype_CheckLayout($data) { + $this->selectHostPrototypeForUpdate('host', $data); + + // Get hostid and discoveryid to check href to template. + $host_prototype = DBfetch(DBSelect('SELECT hostid FROM hosts WHERE templateid IS NULL AND host='.zbx_dbstr($data['host_prototype']))); + $discovery_id = DBfetch(DBSelect('SELECT itemid FROM items WHERE templateid IS NULL AND name='.zbx_dbstr($data['discovery_id']))); + $host_prototype = $host_prototype['hostid']; + $discovery_id = $discovery_id['itemid']; + + // Check layout at Host tab. + $this->zbxTestAssertElementPresentXpath('//a[contains(@href, \'?form=update&hostid='.$host_prototype.'&parent_discoveryid='.$discovery_id.'\')]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="name"][@readonly]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="host"][@readonly]'); + $this->zbxTestAssertElementPresentXpath('//td[@class="interface-ip"]/input[@type="text"][@readonly]'); + $this->zbxTestAssertElementPresentXpath('//td[@class="interface-dns"]/input[@type="text"][@readonly]'); + $interface = DBfetch(DBSelect('SELECT interfaceid'. + ' FROM interface'. + ' WHERE hostid IN ('. + 'SELECT hostid'. + ' FROM items'. + ' WHERE templateid IS NOT NULL'. + ' AND name='.zbx_dbstr($data['discovery_id']). + ')' + )); + $interface=$interface['interfaceid']; + $this->zbxTestAssertElementPresentXpath('//td/ul[@id="interfaces_'.$interface.'_useip"]/li/input[@value="0"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//td/ul[@id="interfaces_'.$interface.'_useip"]/li/input[@value="1"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//td[@class="interface-port"]/input[@type="text"][@readonly]'); + $this->zbxTestAssertElementText('//tr[@id="SNMPInterfacesFooter"]/td[2]','No SNMP interfaces found.'); + $this->zbxTestAssertElementText('//tr[@id="JMXInterfacesFooter"]/td[2]', 'No JMX interfaces found.'); + $this->zbxTestAssertElementText('//tr[@id="IPMIInterfacesFooter"]/td[2]', 'No IPMI interfaces found.'); + $this->zbxTestAssertElementPresentXpath('//input[@id="proxy_hostid"][@readonly]'); + + // Check layout at Groups tab. + $this->zbxTestClick('tab_groupTab'); + $this->zbxTestAssertElementPresentXpath('//div[@id="group_links_"]/div/ul[@class="multiselect-list disabled"]'); + $this->zbxTestAssertElementPresentXpath('//button[@class="btn-grey"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@name="group_prototypes[0][name]"][@disabled]'); + + // Check layout at IPMI tab. + $this->zbxTestClick('tab_ipmiTab'); + $this->zbxTestAssertElementPresentXpath('//input[@id=\'ipmi_authtype\'][@readonly]'); + $this->zbxTestAssertElementPresentXpath('//input[@id=\'ipmi_privilege\'][@readonly]'); + $this->zbxTestAssertElementPresentXpath('//input[@id=\'ipmi_username\'][@readonly]'); + $this->zbxTestAssertElementPresentXpath('//input[@id=\'ipmi_password\'][@readonly]'); + + //Check layout at HostInventory. + $this->zbxTestClick('tab_inventoryTab'); + $this->zbxTestAssertElementPresentXpath('//input[@id="inventory_mode_0"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="inventory_mode_1"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="inventory_mode_2"][@disabled]'); + + //Check layout at Encryption tab. + $this->zbxTestClick('tab_encryptionTab'); + $this->zbxTestAssertElementPresentXpath('//input[@id="tls_connect_0"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="tls_connect_1"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="tls_connect_2"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="tls_in_none"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="tls_in_cert"][@disabled]'); + $this->zbxTestAssertElementPresentXpath('//input[@id="tls_in_psk"][@disabled]'); + + $this->zbxTestAssertAttribute('//button[@id=\'delete\']', 'disabled'); + + // Macro tab check must be after IPMI tab (this must be changed when ZBX-14609 will CLOSED). + // Check layout at Macros tab. + $this->zbxTestClick('tab_macroTab'); + $this->zbxTestAssertElementPresentXpath('//input[@id="show_inherited_macros_0"]'); + $this->zbxTestClickXpath('//label[@for="show_inherited_macros_1"]'); + + $macros = DBdata('SELECT * FROM globalmacro', false); + foreach ($macros as $macro) { + $macro = $macro[0]; + // Macro check and row selection. + $element = $this->webDriver->findElement(WebDriverBy::xpath('//input[@class="macro"][@readonly][@value="'.$macro['macro'].'"]/../..')); + // Effective value. + $this->assertEquals($macro['value'], $element->findElement(WebDriverBy::xpath('./td[3]/input[@type="text"][@readonly]'))->getAttribute('value')); + // Template value. + $this->assertEquals('', $element->findElement(WebDriverBy::xpath('./td[5]/div'))->getText()); + // Global value. + $this->assertEquals('"'.$macro['value'].'"', $element->findElement(WebDriverBy::xpath('./td[7]/div'))->getText()); + } + + // Total macro count. + $this->assertEquals(count($macros), count($this->webDriver->findElements(WebDriverBy::xpath('//input[@class="macro"]')))); + } + + public static function getCreateData() { + return [ + [ + [ + 'host' => 'test Inheritance host prototype', + 'templates' => [ + ['template' => 'Inheritance test template'] + ] + ] + ] + ]; + } + + /** + * @dataProvider getCreateData + */ + public function testInheritanceHostPrototype_Create_OnHost($data) { + $this->zbxTestLogin('hosts.php?form=create'); + $this->zbxTestInputTypeWait('host', $data['host']); + $this->zbxTestClickButtonMultiselect('groups_'); + $this->zbxTestLaunchOverlayDialog('Host groups'); + $this->zbxTestClickLinkTextWait('Zabbix servers'); + $this->zbxTestClick('tab_templateTab'); + $this->zbxTestClickButtonMultiselect('add_templates_'); + $this->zbxTestLaunchOverlayDialog('Templates'); + + foreach ($data['templates'] as $template) { + $templ = $template['template']; + $this->zbxTestDropdownSelectWait('groupid', 'Templates'); + $this->zbxTestClickLinkTextWait($templ); + $this->zbxTestClickXpath('(//button[@type=\'button\'])[8]'); + } + + $this->zbxTestClickXpathWait("//button[@id='add' and @type='submit']"); + $this->zbxTestCheckTitle('Configuration of hosts'); + $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Host added'); + + // DB check. + foreach ($data['templates'] as $template) { + $templ = $template['template']; + + // Table hosts_templates check. + $hosts_templates='SELECT NULL'. + ' FROM hosts_templates'. + ' WHERE hostid IN ('. + 'SELECT hostid'. + ' FROM hosts'. + ' WHERE host='.zbx_dbstr($data['host']). + ')'. + ' AND templateid IN ('. + 'SELECT hostid'. + ' FROM hosts'. + ' WHERE host='.zbx_dbstr($templ). + ')'; + + $this->assertEquals(1, DBcount($hosts_templates)); + + $host_host = ($this->sqlForHostCompare($data['host'])); + $host_templ = ($this->sqlForHostCompare($templ)); + + $this->assertEquals($host_host,$host_templ); + } + } + + /** + * SQL request from table hosts to check data stay without changes + * + * @param array $data test case data from data provider + */ + private function sqlForHostCompare($data) { + $sql = 'SELECT host, status, name, disable_until, error, available,'. + ' errors_from, lastaccess, ipmi_authtype, ipmi_privilege,'. + ' ipmi_username, ipmi_password, ipmi_disable_until,'. + ' snmp_disable_until, snmp_available, ipmi_errors_from,'. + ' ipmi_error, snmp_error, jmx_disable_until, jmx_available,'. + ' jmx_errors_from, jmx_error,description, tls_connect,'. + ' tls_accept, tls_issuer, tls_subject, tls_psk_identity,'. + ' tls_psk, auto_compres s, flags'. + ' FROM hosts'. + ' WHERE flags=2 AND hostid IN ('. + 'SELECT hostid'. + ' FROM host_discovery'. + ' WHERE parent_itemid IN ('. + 'SELECT itemid'. + ' FROM items'. + ' WHERE hostid in ('. + 'SELECT hostid'. + ' FROM hosts'. + ' WHERE host='.zbx_dbstr($data). + ')'. + ')'. + ')'. + ' ORDER BY host, name'; + + return DBhash($sql); + } + + public static function getSimpleUpdateData() { + return [ + [ + [ + 'host_prototype' => 'Host prototype for update {#TEST}', + 'discovery_id' => 'Discovery rule for host prototype test', + 'update' => 'host' + ] + ], + [ + [ + 'host_prototype' => 'Host prototype for update {#TEST}', + 'discovery_id' => 'Discovery rule for host prototype test', + 'update' => 'template' + ] + ] + ]; + } + + /** + * @dataProvider getSimpleUpdateData + */ + public function testInheritanceHost_SimpleUpdate($data) { + if ($data['update'] === 'host') { + $sql = 'SELECT hostid FROM hosts WHERE templateid IS NOT NULL AND host='.zbx_dbstr($data['host_prototype']); + } + elseif ($data['update'] === 'template') { + $sql = 'SELECT hostid FROM hosts WHERE templateid IS NULL AND host='.zbx_dbstr($data['host_prototype']); + } + $old_host = DBhash($sql); + $this->selectHostPrototypeForUpdate($data['update'], $data); + $this->zbxTestClick('update'); + $this->zbxTestCheckTitle('Configuration of host prototypes'); + $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Host prototype updated'); + $this->assertEquals($old_host, DBhash($sql)); + } + + public static function getUpdateTemplateData() { + return [ + [ + [ + 'host_prototype' => 'Host prototype for update {#TEST}', + 'discovery_id' => 'Discovery rule for host prototype test', + 'update_name' => 'New host prototype name {#TEST}', + 'visible_name' => 'New visible name', + 'status_change' => HOST_STATUS_NOT_MONITORED, + 'groups' => [ + ['group_name' => 'Templates'] + ], + 'macro' => '{#MACRO_NEW}', + 'templates' => [ + ['template' => 'Inheritance test template', 'group' => 'Templates'] + ], + 'host_inventory' => '2' + ] + ] + ]; + } + /** + * @dataProvider getUpdateTemplateData + */ + public function testInheritanceHost_Update($data) { + $this->selectHostPrototypeForUpdate('template', $data); + + // Host tab. + if (array_key_exists('update_name', $data)) { + $this->zbxTestInputTypeOverwrite('host', $data['update_name']); + } + if (array_key_exists('visible_name', $data)) { + $this->zbxTestInputTypeOverwrite('name', $data['visible_name']); + } + + if (array_key_exists('status_change', $data)) { + if ($data['status_change'] === HOST_STATUS_MONITORED) { + $this->zbxTestCheckboxSelect('status'); + } + else { + $this->zbxTestCheckboxSelect('status', false); + } + } + + // Groups tab. + $this->zbxTestClick('tab_groupTab'); + if (array_key_exists('groups', $data)) { + foreach ($data['groups'] as $i => $group_row) { + $this->zbxTestClickButtonText('Select'); + $this->zbxTestLaunchOverlayDialog('Host groups'); + $this->zbxTestClickXpath('//div[@id=\'overlay_dialogue\']//a[text()="'.$group_row['group_name'].'"]'); + } + } + + if (array_key_exists('macro', $data)) { + $this->zbxTestInputTypeByXpath('//*[@name="group_prototypes[0][name]"]', $data['macro']); + } + + // Templates tab. + $this->zbxTestClick('tab_templateTab'); + if (array_key_exists('templates', $data)) { + foreach ($data['templates'] as $template) { + $templ = $template['template']; + $this->zbxTestClickButtonMultiselect('add_templates_'); + $this->zbxTestLaunchOverlayDialog('Templates'); + $this->zbxTestDropdownSelectWait('groupid', 'Templates'); + $this->zbxTestClickLinkTextWait($templ); + } + } + + // Host inventory tab. + $this->zbxTestClickWait('tab_inventoryTab'); + if (array_key_exists('host_inventory', $data)) { + $this->zbxTestClickXpathWait('//label[@for="inventory_mode_'.$data['host_inventory'].'"]'); + } + + $this->zbxTestClick('update'); + // Check the results in frontend. + $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Host prototype updated'); + $this->zbxTestCheckTitle('Configuration of host prototypes'); + $this->zbxTestCheckHeader('Host prototypes'); + $this->zbxTestCheckFatalErrors(); + + $host_host = ($this->sqlForHostCompare($data['update_name'])); + + foreach ($data['templates'] as $template) { + $templ = $template['template']; + $host_templ = ($this->sqlForHostCompare($templ)); + } + + $this->assertEquals($host_host,$host_templ); + } + + + public static function getDeleteData() { + return [ + [ + [ + 'host_prototype' => 'Host prototype for delete {#TEST}', + 'discovery_id' => 'Discovery rule for host prototype test', + 'error' => 'Cannot delete host prototypes' + ] + ], + [ + [ + 'host_prototype' => 'Host prototype for delete {#TEST}', + 'discovery_id' => 'Discovery rule for host prototype test' + ] + ] + ]; + } + + /** + * @dataProvider getDeleteData + */ + public function testInheritanceHost_Delete($data) { + if (array_key_exists('error', $data)) { + $discovery_id = DBfetch(DBSelect('SELECT itemid FROM items WHERE templateid IS NOT NULL AND name='.zbx_dbstr($data['discovery_id']))); + } + else { + $discovery_id = DBfetch(DBSelect('SELECT itemid FROM items WHERE templateid IS NULL AND name='.zbx_dbstr($data['discovery_id']))); + } + $discovery_id = $discovery_id['itemid']; + $this->zbxTestLogin('host_prototypes.php?parent_discoveryid='.$discovery_id); + $this->zbxTestCheckboxSelect('all_hosts'); + $this->zbxTestClickButtonText('Delete'); + $this->zbxTestAcceptAlert(); + $this->zbxTestCheckTitle('Configuration of host prototypes'); + if (array_key_exists('error', $data)) { + $this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Cannot delete host prototypes'); + $sql = 'SELECT hostid FROM hosts WHERE templateid IS NOT NULL AND host='.zbx_dbstr($data['host_prototype']); + $this->assertEquals(1, DBcount($sql)); + } + else { + $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Host prototypes deleted'); + $sql = 'SELECT hostid FROM hosts WHERE templateid IS NULL AND host='.zbx_dbstr($data['host_prototype']); + $this->assertEquals(0, DBcount($sql)); + } + } + + /** + * Select specified hosts prototype for update from host prototype page. + * + * @param array $data test case data from data provider + */ + private function selectHostPrototypeForUpdate($action, $data) { + if ($action === 'host') { + $host_prototype = DBfetch(DBSelect('SELECT hostid FROM hosts WHERE templateid IS NOT NULL AND host='.zbx_dbstr($data['host_prototype']))); + $discovery_id = DBfetch(DBSelect('SELECT itemid FROM items WHERE templateid IS NOT NULL AND name='.zbx_dbstr($data['discovery_id']))); + } + elseif ($action === 'template') { + $host_prototype = DBfetch(DBSelect('SELECT hostid FROM hosts WHERE templateid IS NULL AND host='.zbx_dbstr($data['host_prototype']))); + $discovery_id = DBfetch(DBSelect('SELECT itemid FROM items WHERE templateid IS NULL AND name='.zbx_dbstr($data['discovery_id']))); + } + + $host_prototype = $host_prototype['hostid']; + $discovery_id = $discovery_id['itemid']; + $this->zbxTestLogin('host_prototypes.php?form=update&parent_discoveryid='.$discovery_id.'&hostid='.$host_prototype); + } +} |