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

testFormEventCorrelation.php « selenium « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d311dba5a94a730c12db7f28be013a82c493f933 (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
<?php
/*
** Zabbix
** Copyright (C) 2001-2021 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/CLegacyWebTest.php';

use Facebook\WebDriver\WebDriverBy;

/**
 * @backup correlation
 */
class testFormEventCorrelation extends CLegacyWebTest {

	public static function create() {
		return [
			[
				[
					'name' => 'Test create with all fields',
					'select_tag' => 'New event tag name',
					'tag' => 'Test tag',
					'description' => 'Event correlation with description',
					'operation' => [
						'Close new event'
					]
				]
			],
			[
				[
					'name' => 'Test create with minimum fields',
					'select_tag' => 'Old event tag name',
					'tag' => 'Test tag',
					'operation' => [
						'Close old event'
					]
				]
			],
			[
				[
					'name' => 'Test create with both operations selected',
					'select_tag' => 'Old event tag name',
					'tag' => 'Test tag',
					'operation' => [
						'Close old event',
						'Close new event'
					]
				]
			]
		];
	}

	/**
	 * Test creation of a event correlation with all possible fields and with default values.
	 *
	 * @dataProvider create
	 */
	public function testFormEventCorrelation_Create($data) {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->query('button:Create correlation')->one()->click();
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestInputTypeWait('name', $data['name']);
		$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
		$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('condition-type'));
		$this->zbxTestDropdownSelectWait('condition-type', $data['select_tag']);
		$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('tag'));
		$this->zbxTestInputType('tag', $data['tag']);
		$this->zbxTestClickXpath("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
		COverlayDialogElement::ensureNotPresent();

		if (array_key_exists('description', $data)) {
			$this->zbxTestInputType('description', $data['description']);
		}

		foreach($data['operation'] as $operation) {
			$operation_id = ($operation === 'Close old event') ? 'operation_0_type' : 'operation_1_type';
			$this->zbxTestCheckboxSelect($operation_id);
		}

		$this->zbxTestClick('add');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation added');
		$this->zbxTestTextPresent($data['name']);

		$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($data['name']);
		$this->assertEquals(1, CDBHelper::getCount($sql));
	}

	public static function validation() {
		return [
			[
				[
					'error_header' => 'Cannot update correlation',
					'error_message' => 'Incorrect value for field "name": cannot be empty.'
				]
			],
			[
				[
					'name' => 'Event correlation for update',
					'error_header' => 'Cannot add correlation',
					'error_message' => 'Correlation "Event correlation for update" already exists.'
				]
			],
			[
				[
					'name' => 'Without conditions',
					'error_header' => 'Cannot add correlation',
					'error_message' => 'No "conditions" given for correlation "Without conditions".'
				]
			],
			[
				[
					'name' => 'Without operation',
					'tag' => 'tag name',
					'error_header' => 'Cannot add correlation',
					'error_message' => 'No "operations" given for correlation "Without operation".'
				]
			]
		];
	}

	/**
	 * Test form validations.
	 *
	 * @dataProvider validation
	 */
	public function testFormEventCorrelation_CreateValidation($data) {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->query('button:Create correlation')->one()->click();
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		if (array_key_exists('name', $data)) {
			$this->zbxTestInputType('name', $data['name']);
		}

		if (array_key_exists('tag', $data)) {
			$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
			$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('tag'));
			$this->zbxTestInputType('tag', $data['tag']);
			$this->zbxTestClickXpath("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
			COverlayDialogElement::ensureNotPresent();
		}

		$this->zbxTestClick('add');
		$this->zbxTestWaitUntilMessageTextPresent('msg-bad', $data['error_header']);
		$error = $this->zbxTestGetText('//ul[@class=\'list-dashed msg-details-border\']');
		$this->assertContains($data['error_message'], $error);

		if 	(array_key_exists('name', $data) && $data['name'] === 'Event correlation for update') {
			$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($data['name']);
			$this->assertEquals(1, CDBHelper::getCount($sql));
		}

		if (array_key_exists('name', $data) && $data['name'] != 'Event correlation for update') {
			$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($data['name']);
			$this->assertEquals(0, CDBHelper::getCount($sql));
		}
	}

	public function testFormEventCorrelation_LongNameValidation() {
		$name = 'Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_'
				. 'Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_'
				. 'Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name';
		$db_name = 'Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_'
				. 'Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_Name_'
				. 'Test_With_Long_Name_Test_With_Long_Name_Test_With_Long_';

		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->query('button:Create correlation')->one()->click();
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestInputType('name', $name);
		$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
		$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('tag'));
		$this->zbxTestInputType('tag', 'Test tag');
		$this->zbxTestClickXpath("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
		COverlayDialogElement::ensureNotPresent();

		$this->zbxTestCheckboxSelect('operation_0_type');
		$this->zbxTestClick('add');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation added');

		// Name longer than 255 symbols is truncated on frontend, check the shortened name in DB
		$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($db_name);
		$this->assertEquals(1, CDBHelper::getCount($sql));
	}

	public static function tags() {
		return [
			[
				[
					'name' => 'Test create with New event host group equals',
					'select_tag' => 'New event host group',
					'operator' => 'equals'
				]
			],
			[
				[
					'name' => 'Test create with New event host group does not equa',
					'select_tag' => 'New event host group',
					'operator' => 'does not equal'
				]
			],
			[
				[
					'name' => 'Test create with Event tag pair',
					'select_tag' => 'Event tag pair',
					'oldtag' => 'Old tag',
					'newtag' => 'New tag'
				]
			],
			[
				[
					'name' => 'Test create with Old event tag value equals tag',
					'select_tag' => 'Old event tag value',
					'tag' => 'TagTag',
					'operator' => 'equals',
					'value' => 'TagValue'
				]
			],
			[
				[
					'name' => 'Test create with Old event tag value equals Empty',
					'select_tag' => 'Old event tag value',
					'tag' => 'TagTag',
					'operator' => 'equals',
					'value' => ''
				]
			],
			[
				[
					'name' => 'Test create with Old event tag value does not equal tag',
					'select_tag' => 'Old event tag value',
					'tag' => 'TagTag',
					'operator' => 'does not equal',
					'value' => 'TagValue'
				]
			],
			[
				[
					'name' => 'Test create with Old event tag value contains tag',
					'select_tag' => 'Old event tag value',
					'tag' => 'TagTag',
					'operator' => 'contains',
					'value' => 'TagValue'
				]
			],
			[
				[
					'name' => 'Test create with Old event tag value does not contain tag',
					'select_tag' => 'Old event tag value',
					'tag' => 'TagTag',
					'operator' => 'does not contain',
					'value' => 'TagValue'
				]
			],
			[
				[
					'name' => 'Test create with New event tag value equals tag',
					'select_tag' => 'New event tag value',
					'tag' => 'TagTag',
					'operator' => 'equals',
					'value' => 'TagValue'
				]
			],
			[
				[
					'name' => 'Test create with New event tag value equals Empty',
					'select_tag' => 'New event tag value',
					'tag' => 'TagTag',
					'operator' => 'equals',
					'value' => ''
				]
			],
			[
				[
					'name' => 'Test create with New event tag value does not equal tag',
					'select_tag' => 'New event tag value',
					'tag' => 'TagTag',
					'operator' => 'does not equal',
					'value' => 'TagValue'
				]
			],
			[
				[
					'name' => 'Test create with New event tag value contains tag',
					'select_tag' => 'New event tag value',
					'tag' => 'TagTag',
					'operator' => 'contains',
					'value' => 'TagValue'
				]
			],
			[
				[
					'name' => 'Test create with New event tag value does not contain tag',
					'select_tag' => 'New event tag value',
					'tag' => 'TagTag',
					'operator' => 'does not contain',
					'value' => 'TagValue'
				]
			]
		];
	}

	/**
	 * Test creation with different conditions.
	 *
	 * @dataProvider tags
	 */
	public function testFormEventCorrelation_TestTags($data) {
		$host_group = 'Zabbix servers';

		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->query('button:Create correlation')->one()->click();
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestInputType('name', $data['name']);
		$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
		$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('condition-type'));
		$this->zbxTestDropdownSelectWait('condition-type', $data['select_tag']);

		if (array_key_exists('operator', $data)) {
			$this->zbxTestClickXpathWait('//label[text()="'.$data['operator'].'"]');
		}

		if ($data['select_tag'] === 'New event host group') {
			$this->zbxTestClickButtonMultiselect('groupids_');
			$this->zbxTestLaunchOverlayDialog('Host groups');
			$this->zbxTestClickLinkText($host_group);
		}

		if ($data['select_tag'] === 'Event tag pair') {
			$this->zbxTestInputTypeWait('oldtag', $data['oldtag']);
			$this->zbxTestInputType('newtag', $data['newtag']);
		}

		if ($data['select_tag'] === 'Old event tag value' || $data['select_tag'] === 'New event tag value') {
			$this->zbxTestInputType('tag', $data['tag']);
			$this->zbxTestClickXpathWait('//label[text()="'.$data['operator'].'"]');
			$this->zbxTestInputType('value', $data['value']);
		}

		$this->zbxTestClickXpath("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
		COverlayDialogElement::ensureNotPresent();

		$this->zbxTestCheckboxSelect('operation_0_type');
		$this->zbxTestClick('add');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation added');

		$this->zbxTestTextPresent($data['name']);
		$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($data['name']);
		$this->assertEquals(1, CDBHelper::getCount($sql));
	}

	public static function tagsValidation() {
		return [
			[
				[
					'name' => 'Test empty New event tag',
					'select_tag' => 'New event tag name',
					'error_message' => 'Incorrect value for field "tag": cannot be empty.'
				]
			],
			[
				[
					'name' => 'Test empty New event host group',
					'select_tag' => 'New event host group',
					'error_message' => 'Incorrect value for field "groupid": cannot be empty.'
				]
			],
			[
				[
					'name' => 'Test empty Old tag in Event tag pair',
					'select_tag' => 'Event tag pair',
					'newtag' => 'New tag',
					'error_message' => 'Incorrect value for field "oldtag": cannot be empty.'
				]
			],
			[
				[
					'name' => 'Test empty New tag in Event tag pair',
					'select_tag' => 'Event tag pair',
					'oldtag' => 'Old tag',
					'error_message' => 'Incorrect value for field "newtag": cannot be empty.'
				]
			],
			[
				[
					'name' => 'Test empty tag in Old event tag value',
					'select_tag' => 'Old event tag value',
					'error_message' => 'Incorrect value for field "tag": cannot be empty.'
				]
			],
			[
				[
					'name' => 'Test empty tag in New event tag value',
					'select_tag' => 'New event tag value',
					'error_message' => 'Incorrect value for field "tag": cannot be empty.'
				]
			]
		];
	}

	/**
	 * Test condition value validations.
	 *
	 * @dataProvider tagsValidation
	 */
	public function testFormEventCorrelation_CheckEmptyTagsValue($data) {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->query('button:Create correlation')->one()->click();
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestInputTypeWait('name', $data['name']);
		$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
		$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('condition-type'));
		$this->zbxTestDropdownSelectWait('condition-type', $data['select_tag']);
		COverlayDialogElement::find()->one()->waitUntilReady();

		if ($data['select_tag'] === 'Event tag pair' && array_key_exists('newtag', $data)) {
			$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('newtag'));
			$this->zbxTestInputType('newtag', $data['newtag']);
		}

		if ($data['select_tag'] === 'Event tag pair' && array_key_exists('oldtag', $data)) {
			$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('oldtag'));
			$this->zbxTestInputType('oldtag', $data['oldtag']);
		}

		$this->zbxTestClickXpathWait("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
		$this->zbxTestAssertElementText('//div[@class="msg-details"]', $data['error_message']);
		$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($data['name']);
		$this->assertEquals(0, CDBHelper::getCount($sql));
	}

	public static function calculation() {
		return [
			[
				[
					'name' => 'Test create with calculation And/Or',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1'],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2']
					]
				]
			],
			[
				[
					'name' => 'Test create with calculation And',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1'],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2']
					],
					'calculation' => 'And'
				]
			],
			[
				[
					'name' => 'Test create with calculation OR',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1'],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2']
					],
					'calculation' => 'Or'
				]
			],
			[
				[
					'name' => 'Test create with calculation Custom',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1'],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2'],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag3']

					],
				'calculation' => 'Custom expression',
				'formula' => 'A or (B and not C)'
				]
			]
		];
	}

	/**
	 * Test all types of calculation.
	 *
	 * @dataProvider calculation
	 */
	public function testFormEventCorrelation_CreateCalculation($data) {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->query('button:Create correlation')->one()->click();
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestInputType('name', $data['name']);

		foreach ($data['tags'] as $tag) {
			$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
			COverlayDialogElement::find()->one()->waitUntilReady();
			$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('condition-type'));
			$this->zbxTestDropdownSelectWait('condition-type', $tag['select_tag']);
			COverlayDialogElement::find()->one()->waitUntilReady();
			$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('tag'));
			$this->zbxTestInputType('tag', $tag['tag_name']);
			$this->zbxTestClickXpathWait("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
			COverlayDialogElement::ensureNotPresent();
		}

		if (array_key_exists('calculation', $data)) {
			$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('evaltype'));
			$this->zbxTestDropdownSelectWait('evaltype', $data['calculation']);
			if ($data['calculation'] === 'Custom expression') {
				$this->zbxTestInputType('formula', $data['formula']);
			}
		}

		$this->zbxTestCheckboxSelect('operation_0_type');
		$this->zbxTestClick('add');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation added');

		$this->zbxTestTextPresent($data['name']);
		$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($data['name']);
		$this->assertEquals(1, CDBHelper::getCount($sql));
	}

	public static function formulaValidation() {
		return [
			[
				[
					'name' => 'Test create with empty expression',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1' ],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2' ]
					],
					'formula'=> '',
					'error_message' => 'Incorrect custom expression "" for correlation "Test create with empty expression": expression is empty.'
				]
			],
			[
				[
					'name' => 'Test create with missing argument',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1' ],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2' ],
						['select_tag' => 'Old event tag value', 'tag_name' => 'Test tag3', 'operator' => 'contains','value' => 'Value']
					],
					'formula'=> 'A or B',
					'error_message' => 'Condition "C" is not used in formula "A or B" for correlation "Test create with missing argument".'
				]
			],
			[
				[
					'name' => 'Test create with extra argument',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1' ],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2' ],
						['select_tag' => 'Old event tag value', 'tag_name' => 'Test tag3', 'operator' => 'contains','value' => 'Value']
					],
					'formula'=> '(A or B) and (C or D)',
					'error_message' => 'Condition "D" used in formula "(A or B) and (C or D)" for correlation "Test create with extra argument" is not defined.'
				]
			],
			[
				[
					'name' => 'Test create with wrong formula',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1' ],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2' ],
						['select_tag' => 'Old event tag value', 'tag_name' => 'Test tag3', 'operator' => 'contains','value' => 'Value']
					],
					'formula'=> 'Wrong formula',
					'error_message' => 'Incorrect custom expression "Wrong formula" for correlation "Test create with wrong formula": check expression starting from "Wrong formula".'
				]
			],
			[
				[
					'name' => 'Check case sensitive of operator in formula',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1' ],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2' ]
					],
					'formula'=> 'A and Not B',
					'error_message' => 'Incorrect custom expression "A and Not B" for correlation "Check case sensitive of operator in formula": check expression starting from "Not B".'
				]
			],
			[
				[
					'name' => 'Check case sensitive of first operator in formula',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1' ],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2' ]
					],
					'formula'=> 'NOT A and not B',
					'error_message' => 'Incorrect custom expression "NOT A and not B" for correlation "Check case sensitive of first operator in formula": check expression starting from " A and not B".'
				]
			],
			[
				[
					'name' => 'Test create with only NOT in formula',
					'tags'=>[
						['select_tag' => 'Old event tag name', 'tag_name' => 'Test tag1' ],
						['select_tag' => 'New event tag name', 'tag_name' => 'Test tag2' ]
					],
					'formula'=> 'not A not B',
					'error_message' => 'Incorrect custom expression "not A not B" for correlation "Test create with only NOT in formula": check expression starting from " not B".'
				]
			]
		];
	}

	/**
	 * Test custom expression field validation.
	 *
	 * @dataProvider formulaValidation
	 */
	public function testFormEventCorrelation_FormulaValidation($data) {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->query('button:Create correlation')->one()->click();
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestInputType('name', $data['name']);

		foreach ($data['tags'] as $tag) {
			$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
			$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('condition-type'));
			$this->zbxTestDropdownSelectWait('condition-type', $tag['select_tag']);
			COverlayDialogElement::find()->one()->waitUntilReady();
			$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('tag'));
			$this->zbxTestInputType('tag', $tag['tag_name']);

			if (array_key_exists('operator', $tag)) {
				$this->zbxTestClickXpathWait('//label[text()="'.$tag['operator'].'"]');
				$this->zbxTestInputType('value', $tag['value']);
			}

			$this->zbxTestClickXpathWait("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
			COverlayDialogElement::ensureNotPresent();
		}

		$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('evaltype'));
		$this->zbxTestDropdownSelectWait('evaltype', 'Custom expression');
		$this->zbxTestInputType('formula', $data['formula']);
		$this->zbxTestClick('add');

		$this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Cannot add correlation');
		$error = $this->zbxTestGetText('//ul[@class=\'list-dashed msg-details-border\']');
		$this->assertContains($data['error_message'], $error);

		$sql = 'SELECT NULL FROM correlation WHERE name='.zbx_dbstr($data['name']);
		$this->assertEquals(0, CDBHelper::getCount($sql));
	}

	public function testFormEventCorrelation_Clone() {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->zbxTestClickLinkTextWait('Event correlation for clone');
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestClick('clone');
		$this->zbxTestInputType('name', 'Cloned correlation');
		$this->zbxTestClick('add');

		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation added');
		$this->zbxTestTextPresent('Cloned correlation');

		$sql = "SELECT NULL FROM correlation WHERE name='Cloned correlation' AND description='Test description clone'";
		$this->assertEquals(1, CDBHelper::getCount($sql));

		$sql = "SELECT NULL FROM correlation WHERE name='Event correlation for clone' AND description='Test description clone'";
		$this->assertEquals(1, CDBHelper::getCount($sql));

		$sql = "SELECT NULL FROM corr_condition_tag WHERE tag='clone tag'";
		$this->assertEquals(2, CDBHelper::getCount($sql));
	}

	/**
	 * Test update without any modification of event correlation data.
	 */
	public function testFormEventCorrelation_UpdateNone() {
		$sql_hash = 'SELECT * FROM correlation ORDER BY correlationid';
		$old_hash = CDBHelper::getHash($sql_hash);

		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->zbxTestClickLinkTextWait('Event correlation for update');
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestClick('update');

		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation updated');
		$this->zbxTestTextPresent('Event correlation for update');

		$this->assertEquals($old_hash, CDBHelper::getHash($sql_hash));
	}

	public function testFormEventCorrelation_UpdateAllFields() {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->zbxTestClickLinkTextWait('Event correlation for update');
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestInputTypeOverwrite('name', 'New event correlation for update');

		$this->zbxTestClickXpathWait('//tr[@id=\'conditions_0\']//button[text()=\'Remove\']');

		$this->zbxTestClickXpathWait('//button[text()="Add" and contains(@onclick, "popup.condition.event.corr")]');
		$this->zbxTestWaitUntilElementClickable(WebDriverBy::id('condition-type'));
		$this->zbxTestDropdownSelectWait('condition-type', 'New event tag name');
		$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('tag'));
		$this->zbxTestInputTypeOverwrite('tag', 'New update tag');
		$this->zbxTestClickXpathWait("//div[@class='overlay-dialogue-footer']//button[text()='Add']");
		COverlayDialogElement::ensureNotPresent();

		$this->zbxTestInputTypeOverwrite('description', 'New test description update');

		$this->zbxTestCheckboxSelect('operation_0_type', false);
		$this->zbxTestCheckboxSelect('operation_1_type');
		$this->zbxTestClick('update');

		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation updated');
		$this->zbxTestTextPresent('New event correlation for update');

		$sql = "SELECT NULL FROM correlation WHERE name='New event correlation for update' AND description='New test description update'";
		$this->assertEquals(1, CDBHelper::getCount($sql));

		$sql = "SELECT NULL FROM correlation WHERE name='Event correlation for update'";
		$this->assertEquals(0, CDBHelper::getCount($sql));

		$sql = "SELECT NULL FROM corr_condition_tag WHERE tag='New update tag'";
		$this->assertEquals(1, CDBHelper::getCount($sql));

		$sql = "SELECT NULL FROM corr_condition_tag WHERE tag='update tag'";
		$this->assertEquals(0, CDBHelper::getCount($sql));
	}

	public function testFormEventCorrelation_Delete() {
		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->zbxTestClickLinkTextWait('Event correlation for delete');
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestClickAndAcceptAlert('delete');

		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Correlation deleted');
		$this->zbxTestTextNotVisible('Event correlation for delete');

		$sql = "SELECT NULL FROM correlation WHERE name='Event correlation for delete'";
		$this->assertEquals(0, CDBHelper::getCount($sql));
	}

	public function testFormEventCorrelation_Cancel() {
		$sql_hash = 'SELECT * FROM correlation ORDER BY correlationid';
		$old_hash = CDBHelper::getHash($sql_hash);

		$this->zbxTestLogin('zabbix.php?action=correlation.list');
		$this->zbxTestClickLinkTextWait('Event correlation for cancel');
		$this->zbxTestCheckHeader('Event correlation rules');
		$this->zbxTestCheckTitle('Event correlation rules');

		$this->zbxTestClick('cancel');

		$this->zbxTestTextPresent('Event correlation for cancel');

		$this->assertEquals($old_hash, CDBHelper::getHash($sql_hash));
	}
}