Welcome to mirror list, hosted at ThFree Co, Russian Federation.

testDashboardTriggerOverviewWidget.php « dashboard « selenium « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 658d2921f3641d44845f3755d79c8f440fbbdfd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 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__).'/../traits/TagTrait.php';
require_once dirname(__FILE__).'/../traits/TableTrait.php';
require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php';

/**
 * @backup widget, profiles, triggers, problem, config
 *
 * @onBefore prepareData
 */
class testDashboardTriggerOverviewWidget extends CWebTest {

	use TagTrait;
	use TableTrait;

	/**
	 * Attach MessageBehavior to the test.
	 *
	 * @return array
	 */
	public function getBehaviors() {
		return [CMessageBehavior::class];
	}

	private static $dashboardid;
	private static $create_page = 'Page for creation';
	private static $update_widget = 'Trigger overview for reference';
	private static $delete_widget = 'Trigger overview for delete';
	private static $resolved_trigger = '1_trigger_Average';
	private static $dependency_trigger = 'Trigger disabled with tags';
	private static $icon_host = 'Host for triggers filtering';

	private static $background_classes = [
		'1_trigger_Average' => 'normal-bg cursor-pointer blink',
		'1_trigger_Disaster' => 'disaster-bg',
		'1_trigger_High' => 'high-bg',
		'1_trigger_Not_classified' => 'na-bg',
		'1_trigger_Warning' => 'warning-bg',
		'2_trigger_Information' => 'info-bg',
		'3_trigger_Average' => 'average-bg',
		'Trigger_for_suppression' => 'average-bg',
		'4_trigger_Average' => 'average-bg',
		'Inheritance trigger with tags' => 'average-bg',
		'3_trigger_Disaster' => 'normal-bg',
		'Dependent trigger ONE' => 'normal-bg',
		'Discovered trigger one' => 'normal-bg',
		'Trigger disabled with tags' => 'normal-bg'
	];

	private static $trigger_icons = [
		'2_trigger_Information' => 'icon-ackn',
		'3_trigger_Average' => 'icon-ackn',
		'4_trigger_Average' => 'icon-ackn',
		'Dependent trigger ONE' => 'icon-depend-down',
		'Inheritance trigger with tags' => 'icon-depend-down',
		'Trigger disabled with tags' => 'icon-depend-up'
	];

	/**
	 * SQL query to get widget and widget_field tables to compare hash values, but without widget_fieldid
	 * because it can change.
	 */
	private $sql = 'SELECT wf.widgetid, wf.type, wf.name, wf.value_int, wf.value_str, wf.value_groupid, wf.value_hostid,'.
			' wf.value_itemid, wf.value_graphid, wf.value_sysmapid, w.widgetid, w.dashboard_pageid, w.type, w.name, w.x, w.y,'.
			' w.width, w.height'.
			' FROM widget_field wf'.
			' INNER JOIN widget w'.
			' ON w.widgetid=wf.widgetid ORDER BY wf.widgetid, wf.name, wf.value_int, wf.value_str, wf.value_groupid, wf.value_hostid,'.
			' wf.value_itemid, wf.value_graphid';

	/**
	 * Function creates dashboards with widgets and adjusts trigger and problems config for the test.
	 */
	public static function prepareData() {
		$response = CDataHelper::call('dashboard.create', [
			[
				'name' => 'Dashboard for Trigger overview widgets',
				'private' => 0,
				'auto_start' => 0,
				'pages' => [
					[
						'name' => 'Page with widgets',
						'widgets' => [
							[
								'type' => 'trigover',
								'name' => self::$update_widget,
								'width' => 24,
								'height' => 4
							],
							[
								'type' => 'trigover',
								'name' => self::$delete_widget,
								'x' => 0,
								'y' => 4,
								'width' => 24,
								'height' => 4,
								'fields' => [
									[
										'type' => 0,
										'name' => 'show_suppressed',
										'value' => 1
									]
								]
							]
						]
					],
					[
						'name' => self::$create_page,
						'widgets' => []
					]
				]
			]
		]);

		self::$dashboardid = $response['dashboardids'][0];
		$timestamp = time();

		// Resolve one of existing problems to create a recent problem.
		$triggerids = CDBHelper::getColumn('SELECT triggerid FROM triggers WHERE description IN ('.
				zbx_dbstr(self::$resolved_trigger).', '.zbx_dbstr(self::$dependency_trigger).')', 'triggerid'
		);
		DBexecute('UPDATE triggers SET value=0 WHERE triggerid='.zbx_dbstr($triggerids[0]));
		DBexecute('UPDATE triggers SET lastchange='.zbx_dbstr($timestamp).' WHERE triggerid='.zbx_dbstr($triggerids[0]));
		DBexecute('UPDATE problem SET r_eventid=9001 WHERE objectid='.zbx_dbstr($triggerids[0]));
		DBexecute('UPDATE problem SET r_clock='.zbx_dbstr($timestamp).' WHERE objectid='.zbx_dbstr($triggerids[0]));

		// Change the resolved triggers blinking period as the default value is too small for this test.
		CDataHelper::call('settings.update', ['blink_period' => '5m']);

		// Enable the trigger that other triggers depend on.
		CDataHelper::call('trigger.update', [['triggerid' => $triggerids[1], 'status' => 0]]);
	}

	public function testDashboardTriggerOverviewWidget_Layout() {
		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid);
		$form = CDashboardElement::find()->one()->edit()->addWidget()->asForm();
		$form->fill(['Type' => CFormElement::RELOADABLE_FILL('Trigger overview')]);
		$this->assertEquals(['Type', 'Name', 'Refresh interval', 'Show', 'Host groups', 'Hosts', 'Tags',
				'Show suppressed problems', 'Hosts location'], $form->getLabels()->asText()
		);

		$default_values = [
			'Show header' => true,
			'Name' => '',
			'Refresh interval' => 'Default (1 minute)',
			'Show' => 'Recent problems',
			'Host groups' => '',
			'Hosts' => '',
			'id:evaltype' => 'And/Or',
			'id:tags_0_tag' => '',
			'id:tags_0_value' => '',
			'id:tags_0_operator' => 'Contains',
			'Show suppressed problems' => false,
			'Hosts location' => 'Left'
		];

		$form->checkValue($default_values);

		// Check field lengths and placeholders.
		foreach (['Name' => 'default', 'id:tags_0_tag' => 'tag', 'id:tags_0_value' => 'value'] as $field => $placeholder) {
			$field = $form->getField($field);
			$this->assertEquals(255, $field->getAttribute('maxlength'));
			$this->assertEquals($placeholder, $field->getAttribute('placeholder'));
		}

		// Check operators dropdown options.
		$this->assertEquals(['Exists', 'Equals', 'Contains', 'Does not exist', 'Does not equal',
				'Does not contain'], $form->getField('id:tags_0_operator')->asDropdown()->getOptions()->asText()
		);

		// Check possible values of radio buttons.
		$radio_buttons = [
			'Show' => ['Recent problems', 'Problems', 'Any'],
			'Tags' => ['And/Or', 'Or'],
			'Hosts location' => ['Left', 'Top']
		];

		foreach ($radio_buttons as $radio_button => $values) {
			$radio_element = $form->getField($radio_button);
			$this->assertEquals($values, $radio_element->getLabels()->asText());
		}

		// Check buttons in Tags table.
		$this->assertEquals(2, $form->query('id:tags_table_tags')->one()->query('button', ['Add', 'Remove'])->all()
				->filter(new CElementFilter(CElementFilter::CLICKABLE))->count()
		);

		// Close the widget configuration form dialog to avoid possible alerts in following tests.
		COverlayDialogElement::find()->one()->close();
	}

	public function getWidgetData() {
		return [
			// Create a widget with default values including default name.
			[
				[
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_Average',
							'1_trigger_Disaster',
							'1_trigger_High',
							'1_trigger_Not_classified',
							'1_trigger_Warning',
							'2_trigger_Information'
						],
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average'
						],
						'4_Host_to_check_Monitoring_Overview' => [
							'4_trigger_Average'
						],
						'Host for triggers filtering' => [
							'Inheritance trigger with tags'
						]
					]
				]
			],
			// Create a widget that displays only problems.
			[
				[
					'fields' => [
						'Name' => 'Show problems',
						'Show' => 'Problems'
					],
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_Disaster',
							'1_trigger_High',
							'1_trigger_Not_classified',
							'1_trigger_Warning',
							'2_trigger_Information'
						],
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average'
						],
						'4_Host_to_check_Monitoring_Overview' => [
							'4_trigger_Average'
						],
						'Host for triggers filtering' => [
							'Inheritance trigger with tags'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Show all triggers for specific host',
						'Show' => 'Any',
						'Hosts' => ['3_Host_to_check_Monitoring_Overview']
					],
					'expected' => [
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average',
							'3_trigger_Disaster'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Show problems for specific hostgroup',
						'Show' => 'Problems',
						'Host groups' => ['Group to check Overview']
					],
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_Disaster',
							'1_trigger_High',
							'1_trigger_Not_classified',
							'1_trigger_Warning',
							'2_trigger_Information'
						],
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Show problems for multiple hostgroups',
						'Show' => 'Problems',
						'Host groups' => ['Group to check Overview', 'Another group to check Overview']
					],
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_Disaster',
							'1_trigger_High',
							'1_trigger_Not_classified',
							'1_trigger_Warning',
							'2_trigger_Information'
						],
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average'
						],
						'4_Host_to_check_Monitoring_Overview' => [
							'4_trigger_Average'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Show recent problems for multiple hosts',
						'Show' => 'Any',
						'Hosts' => ['3_Host_to_check_Monitoring_Overview', '4_Host_to_check_Monitoring_Overview']
					],
					'expected' => [
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average',
							'3_trigger_Disaster'
						],
						'4_Host_to_check_Monitoring_Overview' => [
							'4_trigger_Average'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Hostgroup without triggers',
						'Host groups' => ['Dynamic widgets HG1 (H1 and H2)']
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Host without triggers',
						'Hosts' => ['Dynamic widgets H1']
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Combination of non-related Host and Hostgroup',
						'Host groups' => ['Group to check Overview'],
						'Hosts' => ['4_Host_to_check_Monitoring_Overview']
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Show suppressed problems + hosts on top',
						'Show suppressed problems' => true,
						'Hosts location' => 'Top'
					],
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_Average',
							'1_trigger_Disaster',
							'1_trigger_High',
							'1_trigger_Not_classified',
							'1_trigger_Warning',
							'2_trigger_Information'
						],
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average'
						],
						'4_Host_to_check_Monitoring_Overview' => [
							'4_trigger_Average'
						],
						'Host for suppression' => [
							'Trigger_for_suppression'
						],
						'Host for triggers filtering' => [
							'Inheritance trigger with tags'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Filter triggers by tag with default operator'
					],
					'tags' => [
						['name' => 'server', 'operator' => 'Contains', 'value' => 'sel']
					],
					'expected' => [
						'Host for triggers filtering' => [
							'Inheritance trigger with tags'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Filter triggers by 2 tags with Or operator',
						'Tags' => 'Or'
					],
					'tags' => [
						['name' => 'Street', 'operator' => 'Exists'],
						['name' => 'webhook', 'operator' => 'Equals', 'value' => '1']
					],
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_High'
						],
						'Host for triggers filtering' => [
							'Inheritance trigger with tags'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Does not exists and Does not equal tag operators',
						'Show' => 'Problems'
					],
					'tags' => [
						['name' => 'Street', 'operator' => 'Does not exist'],
						['name' => 'webhook', 'operator' => 'Does not equal', 'value' => '1']
					],
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_Disaster',
							'1_trigger_Not_classified',
							'1_trigger_Warning',
							'2_trigger_Information'
						],
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average'
						],
						'4_Host_to_check_Monitoring_Overview' => [
							'4_trigger_Average'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Виджет с tag + 良い1日を un žšī!@#$%^&*()_ vardā'
					],
					'tags' => [
						['name' => 'Street', 'operator' => 'Does not contain', 'value' => 'elza']
					],
					'expected' => [
						'1_Host_to_check_Monitoring_Overview' => [
							'1_trigger_Average',
							'1_trigger_Disaster',
							'1_trigger_High',
							'1_trigger_Not_classified',
							'1_trigger_Warning',
							'2_trigger_Information'
						],
						'3_Host_to_check_Monitoring_Overview' => [
							'3_trigger_Average'
						],
						'4_Host_to_check_Monitoring_Overview' => [
							'4_trigger_Average'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'No result - filter triggers by 2 tags with And operator'
					],
					'tags' => [
						['name' => 'server', 'operator' => 'Contains', 'value' => 'sel'],
						['name' => 'webhook', 'operator' => 'Equals', 'value' => '1']
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Filter by 2 tags without value',
						'Tags' => 'Or'
					],
					'tags' => [
						['name' => 'server', 'operator' => 'Contains', 'value' => ''],
						['name' => 'webhook', 'operator' => 'Equals', 'value' => '']
					],
					'expected' => [
						'Host for triggers filtering' => [
							'Inheritance trigger with tags'
						]
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Only tag specified only by value'
					],
					'tags' => [
						['name' => '', 'operator' => 'Contains', 'value' => '1']
					]
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Check triggers with dependency icons',
						'Show' => 'Any',
						'Hosts' => [self::$icon_host]
					],
					'expected' => [
						'Host for triggers filtering' => [
							'Dependent trigger ONE',
							'Discovered trigger one',
							'Inheritance trigger with tags',
							'Trigger disabled with tags'
						]
					]
				]
			]
		];
	}

	/**
	 * @dataProvider getWidgetData
	 */
	public function testDashboardTriggerOverviewWidget_Create($data) {
		$this->checkWidgetAction($data);
	}

	/**
	 * @dataProvider getWidgetData
	 */
	public function testDashboardTriggerOverviewWidget_Update($data) {
		$this->checkWidgetAction($data, false);
	}

	public function testDashboardTriggerOverviewWidget_SimpleUpdate() {
		$old_hash = CDBHelper::getHash($this->sql);

		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid);
		$dashboard = CDashboardElement::find()->one();
		$dashboard->edit();

		$form = $dashboard->getWidget(self::$update_widget)->edit();
		$form->submit();
		COverlayDialogElement::ensureNotPresent();

		$widget = $dashboard->getWidget(self::$update_widget);
		$widget->waitUntilReady();
		$dashboard->save();

		$this->assertMessage(TEST_GOOD, 'Dashboard updated');
		$this->assertEquals($old_hash, CDBHelper::getHash($this->sql));
	}

	public function getCancelActionsData() {
		return [
			// Cancel update widget.
			[
				[
					'update' => true,
					'save_widget' => true,
					'save_dashboard' => false
				]
			],
			[
				[
					'update' => true,
					'save_widget' => false,
					'save_dashboard' => true
				]
			],
			// Cancel create widget.
			[
				[
					'save_widget' => true,
					'save_dashboard' => false
				]
			],
			[
				[
					'save_widget' => false,
					'save_dashboard' => true
				]
			]
		];
	}

	/**
	 * @dataProvider getCancelActionsData
	 */
	public function testDashboardTriggerOverviewWidget_Cancel($data) {
		$old_hash = CDBHelper::getHash($this->sql);
		$new_name = 'Widget to be cancelled';

		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid);
		$dashboard = CDashboardElement::find()->one()->edit();

		// Start updating or creating a widget.
		if (CTestArrayHelper::get($data, 'update', false)) {
			$form = $dashboard->getWidget(self::$update_widget)->edit();
		}
		else {
			$form = $dashboard->addWidget()->asForm();

			if ($form->getField('Type')->getValue() !== 'Trigger overview') {
				$form->getField('Type')->fill('Trigger overview');
				$form->invalidate();
			}
		}

		$form->fill([
			'Name' => $new_name,
			'Refresh interval' => '10 minutes',
			'Show' => 'Any',
			'Host groups' => ['Another group to check Overview'],
			'Hosts' => ['4_Host_to_check_Monitoring_Overview'],
			'Tags' => 'Or',
			'Show suppressed problems' => 'true',
			'Hosts location' => 'Top'
		]);

		$this->setTagSelector('id:tags_table_tags');
		$this->setTags([['name' => 'webhook', 'operator' => 'Equals', 'value' => '1']]);

		// Save or cancel widget.
		if (CTestArrayHelper::get($data, 'save_widget', false)) {
			$form->submit();

			// Check that changes took place on the unsaved dashboard (widget got renamed).
			$this->assertTrue($dashboard->getWidget($new_name)->isValid());
		}
		else {
			$dialog = COverlayDialogElement::find()->one();
			$dialog->query('button:Cancel')->one()->click();
			$dialog->ensureNotPresent();

			if (CTestArrayHelper::get($data, 'update', false)) {
				foreach ([self::$update_widget => true, $new_name => false] as $name => $valid) {
					$this->assertTrue($dashboard->getWidget($name, $valid)->isValid($valid));
				}
			}
		}

		// Save or cancel dashboard update.
		if (CTestArrayHelper::get($data, 'save_dashboard', false)) {
			$dashboard->save();
		}
		else {
			$dashboard->cancelEditing();
		}
		// Confirm that no changes were made to the widget.
		$this->assertEquals($old_hash, CDBHelper::getHash($this->sql));
	}

	public function testDashboardSlaReportWidget_Delete() {
		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid);
		$dashboard = CDashboardElement::find()->one()->edit();
		$widget = $dashboard->getWidget(self::$delete_widget);

		$dashboard->deleteWidget(self::$delete_widget);
		$widget->waitUntilNotPresent();
		$dashboard->save();
		$this->assertMessage(TEST_GOOD, 'Dashboard updated');

		// Confirm that widget is not present on dashboard.
		$this->assertFalse($dashboard->getWidget(self::$delete_widget, false)->isValid());
		$widget_sql = 'SELECT null FROM widget_field wf'.
				' LEFT JOIN widget w'.
					' ON w.widgetid=wf.widgetid'.
					' WHERE w.name='.zbx_dbstr(self::$delete_widget);

		$this->assertEquals(0, CDBHelper::getCount($widget_sql));
	}

	/**
	 * Function checks the content of the Dependent and Depends on popups.
	 * Icons with Acknowledge popup menus are not checked as they are covered in testPageTriggerUrl test.
	 */
	public function testDashboardTriggerOverviewWidget_CheckDependencyPopups() {
		$popup_content = [
			'Dependent trigger ONE' => [
				'Depends on' => ['Trigger disabled with tags']
			],
			'Inheritance trigger with tags' => [
				'Depends on' => ['Trigger disabled with tags']
			],
			'Trigger disabled with tags' => [
				'Dependent' => ['Inheritance trigger with tags', 'Dependent trigger ONE']
			]
		];

		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid);
		$dashboard = CDashboardElement::find()->one()->edit();

		$form = $dashboard->getWidget(self::$update_widget)->edit();
		$form->fill(['Show' => 'Any', 'Hosts' => [self::$icon_host]]);
		$form->submit();

		// Wait for the widget to be ready and save dashboard (the wait is performed within the getWidget() method).
		$dashboard->getWidget(self::$update_widget);
		$dashboard->save();

		// Get the table row with all triggers (since all of them belong to a single host).
		$row = $dashboard->getWidget(self::$update_widget)->getContent()->asTable()->findRow('Hosts', self::$icon_host);

		foreach ($popup_content as $trigger => $dependency) {
			// Locate hint and check table headers in hint.
			$hint_table = $row->getColumn($trigger)->query('class:hint-box')->one()->asTable();
			$this->assertEquals(array_keys($dependency), $hint_table->getHeadersText());

			// Gather data from rows and compare result with reference.
			$hint_rows = $hint_table->getRows()->asText();

			$this->assertEquals(array_values($dependency), [$hint_rows]);
		}
	}

	/**
	 * Create or update a Trigger overview widget and check the result.
	 *
	 * @param array		$data		widget related data from data provider
	 * @param boolean	$create		flag that specifies whether a create action is performed
	 */
	public function checkWidgetAction($data, $create = true) {
		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid='.self::$dashboardid);
		$dashboard = CDashboardElement::find()->one();
		$dashboard->edit();

		if ($create) {
			$dashboard->selectPage(self::$create_page);
			$form = $dashboard->addWidget()->asForm();

			// Set type to Trigger overview in case if this field has a different value.
			if ($form->getField('Type')->getValue() !== 'Trigger overview') {
				$form->fill(['Type' => CFormElement::RELOADABLE_FILL('Trigger overview')]);
			}
		}
		else {
			$form = $dashboard->getWidget(self::$update_widget)->edit();

			// Values from the previous cases should be cleaned-up in case of update scenario before filling-in data.
			$this->cleanupFormBeforeFill($form, CTestArrayHelper::get($data, 'fields', []));
		}

		// Fill form in case if values that are different from widget default configuration should be filled.
		if (array_key_exists('fields', $data)) {
			$form->fill($data['fields']);
		}

		if (CTestArrayHelper::get($data,'tags', false)) {
			$this->setTagSelector('id:tags_table_tags');
			$this->setTags($data['tags']);
		}

		$form->submit();
		COverlayDialogElement::ensureNotPresent();

		$widget_name = (array_key_exists('fields', $data)) ? $data['fields']['Name'] : 'Trigger overview';
		$widget = $dashboard->getWidget($widget_name);
		$dashboard->save();
		$this->assertMessage(TEST_GOOD, 'Dashboard updated');

		if ($create) {
			$dashboard->selectPage(self::$create_page);
		}
		else {
			self::$update_widget = (array_key_exists('fields', $data)) ? $data['fields']['Name'] : 'Trigger overview';
		}

		$table = $widget->getContent()->asTable();

		if (CTestArrayHelper::get($data, 'fields.Hosts location') === 'Top') {
			$expected_headers = ['Triggers'];
			$expected_rows = [];
		}
		else {
			$expected_headers = ['Hosts'];
			$expected_rows = array_keys(CTestArrayHelper::get($data, 'expected', []));
		}

		// Check empty result widget and proceed to next case.
		if (!array_key_exists('expected', $data)) {
			$this->assertEquals($expected_headers, $table->getHeadersText());
			$this->assertTableData(null, "xpath://h4[text()=".CXPathHelper::escapeQuotes($data['fields']['Name']).
					"]/../..//table"
			);

			return;
		}

		// Check widget content based on the alignment chosen in Hosts location field.
		foreach ($data['expected'] as $host => $triggers) {
			if (CTestArrayHelper::get($data, 'fields.Hosts location') === 'Top') {
				$expected_headers[] = $host;
				foreach ($triggers as $trigger) {
					$expected_rows[] = $trigger;
					$cell = $table->findRow('Triggers', $trigger)->getColumn($host);
					$this->checkTriggerCell($cell, $trigger);
				}
			}
			else {
				$row = $table->findRow('Hosts', $host);

				foreach ($triggers as $trigger) {
					$expected_headers[] = $trigger;
					$cell = $row->getColumn($trigger);
					$this->checkTriggerCell($cell, $trigger);
				}
			}
		}

		// Rows are sorted alphabetically in widget, so the same should apply to the reference array.
		$expected_rows = array_values($expected_rows);
		sort($expected_rows);

		$this->assertEquals($expected_headers, $table->getHeadersText());
		$this->assertTableDataColumn($expected_rows, $expected_headers[0], 'xpath://h4[text()='.
				CXPathHelper::escapeQuotes($widget_name).']/../..//table[@class="list-table"]'
		);
	}

	/**
	 * Remove the previously entered values from widget configuration form.
	 *
	 * @param CFormElement $form	widget configuration form element
	 */
	private function cleanupFormBeforeFill($form) {
		$default_values = [
			'Name' => '',
			'Show' => 'Recent problems',
			'Host groups' => '',
			'Hosts' => '',
			'Tags' => 'And/Or',
			'Show suppressed problems' => false,
			'Hosts location' => 'Left'
		];

		foreach ($default_values as $field_name => $value) {
			$field = $form->getField($field_name);

			if ($field->getValue() !== $value) {
				if (in_array($field, ['Host groups', 'Hosts'])) {
					$field->clear();
				}
				else {
					$field->fill($value);
				}
			}
		}

		// Remove tags left from previous case and add a blank row for new data.
		if ($form->getField('id:tags_0_tag')->getValue() !== '' || $form->getField('id:tags_0_value')->getValue() !== '') {
			$form->query('button:Remove')->all()->click();
			$form->query('button:Add')->one()->click();
		}
	}

	/**
	 * Check the severity and the icon displayed in the table cell under attention.
	 *
	 * @param CElement	$cell		table cell that represents the trigger to be checked
	 * @param string	$trigger	the name of the trigger that is represented by the trigger cell
	 */
	private function checkTriggerCell ($cell, $trigger) {
		// Check the colour of the background.
		$this->assertStringStartsWith(self::$background_classes[$trigger], $cell->getAttribute('class'));

		// Check trigger icon if such should exist.
		if (in_array($trigger, self::$trigger_icons)) {
			$element = (self::$trigger_icons[$trigger] === 'icon-ackn') ? 'span' : 'a';
			$icon = $cell->query('xpath:.//'.$element)->one();
			$this->assertTrue($icon->isValid());
			$this->assertStringStartsWith(self::$trigger_icons[$trigger], $cell->getAttribute('class'));
		}
	}
}