'Dashboard with favorite graphs widget', 'private' => 1, 'pages' => [ [ 'widgets' => [ [ 'type' => 'favgraphs', 'x' => 0, 'y' => 0, 'width' => 12, 'height' => 4 ] ] ] ] ] ]); self::$dashboardid = $response['dashboardids'][0]; } public function testDashboardFavoriteGraphsWidget_AddFavoriteGraphs() { $cpu_itemid = CDBHelper::getValue('SELECT itemid FROM items WHERE hostid=10084 AND name='.zbx_dbstr($this->graph_cpu)); $memory_itemid = CDBHelper::getValue('SELECT itemid FROM items WHERE hostid=10084 AND name='.zbx_dbstr($this->graph_memory)); $this->page->login()->open('zabbix.php?action=latest.view&filter_selected=0&filter_reset=1')->waitUntilReady(); $this->page->assertHeader('Latest data'); $filter = $this->query('name:zbx_filter')->asForm()->one(); $table = $this->query('xpath://table['.CXPathHelper::fromClass('overflow-ellipsis').']')->asTable()->one(); foreach ([$this->graph_cpu, $this->graph_memory] as $graph) { $filter->fill(['Hosts' => $this->host_name, 'Name' => $graph]); $filter->submit(); $table->waitUntilReloaded()->invalidate(); $table->findRow('Host', $this->host_name)->query('link:Graph')->waitUntilClickable()->one()->click(); // Add graph to favorite. $this->page->waitUntilReady(); $button = $this->query('xpath://button[@id="addrm_fav"]')->waitUntilVisible()->one(); $this->assertEquals('Add to favorites', $button->getAttribute('title')); $button->waitUntilClickable()->click(); $button->waitUntilAttributesPresent(['title' => 'Remove from favorites']); $this->page->open('zabbix.php?action=latest.view')->waitUntilReady(); $this->query('button:Reset')->waitUntilClickable()->one()->click(); $table->waitUntilReloaded(); } $this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid)->waitUntilReady(); $widget = CDashboardElement::find()->one()->getWidget('Favorite graphs')->waitUntilReady()->getContent(); // Check favorite graphs in widget. foreach ([$this->graph_cpu => $cpu_itemid, $this->graph_memory => $memory_itemid] as $graph => $itemid) { $this->assertEquals('history.php?action=showgraph&itemids%5B0%5D='.$itemid, $widget->query('link', $this->host_name.': '.$graph)->one()->getAttribute('href') ); $this->assertEquals(1, CDBHelper::getCount('SELECT profileid FROM profiles WHERE idx='. zbx_dbstr('web.favorite.graphids').' AND value_id='.zbx_dbstr($itemid)) ); } } public function testDashboardFavoriteGraphsWidget_RemoveFavoriteGraphs() { $favorite_graphs = CDBHelper::getAll('SELECT value_id FROM profiles WHERE idx='.zbx_dbstr('web.favorite.graphids')); $this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid)->waitUntilReady(); $widget = CDashboardElement::find()->one()->getWidget('Favorite graphs')->waitUntilReady()->getContent(); foreach ($favorite_graphs as $graph) { // Added variable due to External Hook. $xpath = './/button[@data-itemid='.CXPathHelper::escapeQuotes($graph['value_id']); $remove_item = $widget->query('xpath', $xpath.' and contains(@onclick, "rm4favorites")]')->waituntilClickable()->one(); $remove_item->click(); $remove_item->waitUntilNotVisible(); } $this->assertEquals('No graphs added.', $widget->query('class:nothing-to-show')->one()->getText()); $this->assertEquals(0, CDBHelper::getCount('SELECT profileid FROM profiles WHERE idx='. zbx_dbstr('web.favorite.graphids')) ); } }