-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssertsElement.php
More file actions
1015 lines (842 loc) · 36.1 KB
/
AssertsElement.php
File metadata and controls
1015 lines (842 loc) · 36.1 KB
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
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
namespace Ziadoz\AssertableHtml\Concerns\Asserts;
use PHPUnit\Framework\Assert as PHPUnit;
use Ziadoz\AssertableHtml\Dom\AssertableAttributesList;
use Ziadoz\AssertableHtml\Dom\AssertableClassesList;
use Ziadoz\AssertableHtml\Dom\AssertableElement;
use Ziadoz\AssertableHtml\Dom\AssertableText;
trait AssertsElement
{
/*
|--------------------------------------------------------------------------
| Assert Tag
|--------------------------------------------------------------------------
*/
/** Assert the element's tag matches the given tag. */
public function assertTagEquals(string $tag, ?string $message = null): static
{
PHPUnit::assertSame(
$expected = strtolower($tag),
strtolower($this->element->tagName),
$message ?? sprintf(
"The element [%s] tag doesn't equal the given tag [%s].",
$this->identifier(),
$expected,
),
);
return $this;
}
/** Assert the element's tag matches the given tag. */
public function assertTagDoesntEqual(string $tag, ?string $message = null): static
{
PHPUnit::assertNotSame(
$expected = strtolower($tag),
strtolower($this->element->tagName),
$message ?? sprintf(
'The element [%s] tag equals the given tag [%s].',
$this->identifier(),
$expected,
),
);
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Element
|--------------------------------------------------------------------------
*/
/**
* Assert the element passes the given callback.
*
* @param callable(AssertableElement $element): bool $callback
*/
public function assertElement(callable $callback, ?string $message = null): static
{
PHPUnit::assertTrue(
$callback($this),
$message ?? sprintf(
"The element [%s] doesn't pass the given callback.",
$this->identifier(),
),
);
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Matches Selector
|--------------------------------------------------------------------------
*/
/** Assert the element matches the given selector. */
public function assertMatchesSelector(string $selector, ?string $message = null): static
{
PHPUnit::assertTrue(
$this->element->matches($selector),
$message ?? sprintf(
"The element [%s] doesn't match the given selector [%s].",
$this->identifier(),
$selector,
),
);
return $this;
}
/** Assert the element doesn't match the given selector. */
public function assertDoesntMatchSelector(string $selector, ?string $message = null): static
{
PHPUnit::assertFalse(
$this->element->matches($selector),
$message ?? sprintf(
'The element [%s] matches the given selector [%s].',
$this->identifier(),
$selector,
),
);
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Elements Count
|--------------------------------------------------------------------------
*/
/** Assert the element the expected number of elements matching the given selector. */
public function assertNumberOfElements(string $selector, string $comparison, int $count, ?string $message = null): static
{
return match ($comparison) {
'=' => $this->assertElementsCount($selector, $count, $message),
'!=' => $this->assertElementsNotCount($selector, $count, $message),
'>' => $this->assertElementsCountGreaterThan($selector, $count, $message),
'>=' => $this->assertElementsCountGreaterThanOrEqual($selector, $count, $message),
'<' => $this->assertElementsCountLessThan($selector, $count, $message),
'<=' => $this->assertElementsCountLessThanOrEqual($selector, $count, $message),
};
}
/** Assert the element contains the exact number of elements matching the given selector. */
public function assertElementsCount(string $selector, int $count, ?string $message = null): static
{
$this->querySelectorAll($selector)->assertCount($count, $message ?? sprintf(
"The element [%s] doesn't have exactly [%d] elements matching the given selector [%s].",
$this->identifier(),
$count,
$selector,
));
return $this;
}
/** Assert the element doesn't contain the exact number of elements matching the given selector. */
public function assertElementsNotCount(string $selector, int $count, ?string $message = null): static
{
$this->querySelectorAll($selector)->assertNotCount($count, $message ?? sprintf(
'The element [%s] has exactly [%d] elements matching the given selector [%s].',
$this->identifier(),
$count,
$selector,
));
return $this;
}
/** Assert the element contains greater than the number of elements matching the given selector. */
public function assertElementsCountGreaterThan(string $selector, int $count, ?string $message = null): static
{
$this->querySelectorAll($selector)->assertCountGreaterThan($count, $message ?? sprintf(
"The element [%s] doesn't have greater than [%d] elements matching the given selector [%s].",
$this->identifier(),
$count,
$selector,
));
return $this;
}
/** Assert the element contains greater than or equal the number of elements matching the given selector. */
public function assertElementsCountGreaterThanOrEqual(string $selector, int $count, ?string $message = null): static
{
$this->querySelectorAll($selector)->assertCountGreaterThanOrEqual($count, $message ?? sprintf(
"The element [%s] doesn't have greater than or equal to [%d] elements matching the given selector [%s].",
$this->identifier(),
$count,
$selector,
));
return $this;
}
/** Assert the element contains less than the number of elements matching the given selector. */
public function assertElementsCountLessThan(string $selector, int $count, ?string $message = null): static
{
$this->querySelectorAll($selector)->assertCountLessThan($count, $message ?? sprintf(
"The element [%s] doesn't have less than [%d] elements matching the given selector [%s].",
$this->identifier(),
$count,
$selector,
));
return $this;
}
/** Assert the element contains less than or equal the number of elements matching the given selector. */
public function assertElementsCountLessThanOrEqual(string $selector, int $count, ?string $message = null): static
{
$this->querySelectorAll($selector)->assertCountLessThanOrEqual($count, $message ?? sprintf(
"The element [%s] doesn't have less than or equal to [%d] elements matching the given selector [%s].",
$this->identifier(),
$count,
$selector,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Elements Present/Missing
|--------------------------------------------------------------------------
*/
/** Assert the element contains one or more elements matching the given selector. */
public function assertElementsPresent(string $selector, ?string $message = null): static
{
$this->assertElementsCountGreaterThan($selector, 0, $message ?? sprintf(
"The element [%s] doesn't have one or more elements matching the given selector [%s].",
$this->identifier(),
$selector,
));
return $this;
}
/** Assert the element contains no elements matching the given selector. */
public function assertElementsMissing(string $selector, ?string $message = null): static
{
$this->assertElementsCount($selector, 0, $message ?? sprintf(
'The element [%s] has one or more elements matching the given selector [%s].',
$this->identifier(),
$selector,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Text
|--------------------------------------------------------------------------
*/
/**
* Assert the element's text passes the given callback.
*
* @param callable(AssertableText $text): bool $callback
*/
public function assertText(callable $callback, ?string $message = null): static
{
$this->text->assertText($callback, $message ?? sprintf(
"The element [%s] text doesn't pass the given callback.",
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Text Equals
|--------------------------------------------------------------------------
*/
/** Assert the element's text equals the given text. */
public function assertTextEquals(string $text, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertEquals($text, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] text doesn't equal the given text.",
$this->identifier(),
));
return $this;
}
/** Assert the element's text doesn't equal the given text. */
public function assertTextDoesntEqual(string $text, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertDoesntEqual($text, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] text equals the given text.',
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Text Starts / Ends With
|--------------------------------------------------------------------------
*/
/** Assert the element's text starts with the given text. */
public function assertTextStartsWith(string $prefix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertStartsWith($prefix, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] text doesn't start with the given prefix.",
$this->identifier(),
));
return $this;
}
/** Assert the element's text starts doesn't start with the given text. */
public function assertTextDoesntStartWith(string $prefix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertDoesntStartWith($prefix, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] text starts with the given prefix.',
$this->identifier(),
));
return $this;
}
/** Assert the element's text ends with the given text. */
public function assertTextEndsWith(string $suffix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertEndsWith($suffix, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] text doesn't end with the given suffix.",
$this->identifier(),
));
return $this;
}
/** Assert the element's text doesn't end with the given text. */
public function assertTextDoesntEndWith(string $suffix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertDoesntEndWith($suffix, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] text ends with the given suffix.',
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Text Contains
|--------------------------------------------------------------------------
*/
/** Assert the element's text contains the given text. */
public function assertTextContains(string $text, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertContains($text, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] text doesn't contain the given text.",
$this->identifier(),
));
return $this;
}
/** Alias for assertTextContains() */
public function assertSeeIn(string $text, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertTextContains($text, $normaliseWhitespace, $message);
return $this;
}
/** Assert the element's text doesn't contain the given text. */
public function assertTextDoesntContain(string $text, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->text->assertDoesntContain($text, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] text contains the given text.',
$this->identifier(),
));
return $this;
}
/** Alias for assertTextDoesntContain() */
public function assertDontSeeIn(string $text, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertTextDoesntContain($text, $normaliseWhitespace, $message);
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert ID Present/Missing
|--------------------------------------------------------------------------
*/
/** Assert the element has an ID. */
public function assertIdPresent(): static
{
$this->attributes->assertPresent('id', sprintf(
'The element [%s] is missing the id attribute.',
$this->identifier(),
));
return $this;
}
/** Assert the element is missing an ID. */
public function assertIdMissing(): static
{
$this->attributes->assertMissing('id', sprintf(
'The element [%s] has the id attribute.',
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert ID Equals
|--------------------------------------------------------------------------
*/
/** Assert the element's ID equals the given value. */
public function assertIdEquals(string $value, ?string $message = null): static
{
$this->attributes->assertEquals('id', $value, false, $message ?? sprintf(
"The element [%s] id doesn't equal the given value [%s].",
$this->identifier(),
$value,
));
return $this;
}
/** Assert the element's ID doesn't equal the given value. */
public function assertIdDoesntEqual(string $value, ?string $message = null): static
{
$this->attributes->assertDoesntEqual('id', $value, false, $message ?? sprintf(
'The element [%s] id equals the given value [%s].',
$this->identifier(),
$value,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Class
|--------------------------------------------------------------------------
*/
/**
* Assert the element's class passes the given callback.
*
* @param callable(AssertableClassesList $classes): bool $callback
*/
public function assertClass(callable $callback, ?string $message = null): static
{
$this->classes->assertClasses($callback, $message ?? sprintf(
"The element [%s] class doesn't pass the given callback.",
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Class Empty
|--------------------------------------------------------------------------
*/
/** Assert the element's class list is empty. */
public function assertClassEmpty(?string $message = null): static
{
$this->classes->assertEmpty($message ?? sprintf(
"The element [%s] class list isn't empty.",
$this->identifier(),
));
return $this;
}
/** Assert the element's class list isn't empty. */
public function assertClassNotEmpty(?string $message = null): static
{
$this->classes->assertNotEmpty($message ?? sprintf(
'The element [%s] class list is empty.',
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Class Present/Missing
|--------------------------------------------------------------------------
*/
/** Assert the element has a class. */
public function assertClassPresent(): static
{
$this->attributes->assertPresent('class', sprintf(
'The element [%s] is missing the class attribute.',
$this->identifier(),
));
return $this;
}
/** Assert the element is missing a class. */
public function assertClassMissing(): static
{
$this->attributes->assertMissing('class', sprintf(
'The element [%s] has the class attribute.',
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Class Equals
|--------------------------------------------------------------------------
*/
/** Assert the element's class equals the given class. */
public function assertClassEquals(string $class, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->classes->assertValueEquals($class, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] class doesn't equal the given class [%s].",
$this->identifier(),
$class,
));
return $this;
}
/** Assert the element's class doesn't equal the given class. */
public function assertClassDoesntEqual(string $class, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->classes->assertValueDoesntEqual($class, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] class equals the given class [%s].',
$this->identifier(),
$class,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Class Contains
|--------------------------------------------------------------------------
*/
/** Assert the element's class contains the given class. */
public function assertClassContains(string $class, ?string $message = null): static
{
$this->classes->assertContains($class, $message ?? sprintf(
"The element [%s] class doesn't contain the given class [%s].",
$this->identifier(),
$class,
));
return $this;
}
/** Assert the element's class doesn't contain the given class. */
public function assertClassDoesntContain(string $class, ?string $message = null): static
{
$this->classes->assertDoesntContain($class, $message ?? sprintf(
'The element [%s] class contains the given class [%s].',
$this->identifier(),
$class,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Class Contains Any / All
|--------------------------------------------------------------------------
*/
/** Assert the element's class contains any of the given classes. */
public function assertClassContainsAny(array $classes, ?string $message = null): static
{
$this->classes->assertContainsAny($classes, $message ?? sprintf(
"The element [%s] class doesn't contain any of the given classes [%s].",
$this->identifier(),
implode(' ', $classes),
));
return $this;
}
/** Assert the element's class doesn't contain any of the given classes. */
public function assertClassDoesntContainAny(array $classes, ?string $message = null): static
{
$this->classes->assertDoesntContainAny($classes, $message ?? sprintf(
'The element [%s] class contains some of the given classes [%s].',
$this->identifier(),
implode(' ', $classes),
));
return $this;
}
/** Assert the element's class contains all the given classes. */
public function assertClassContainsAll(array $classes, ?string $message = null): static
{
$this->classes->assertContainsAll($classes, $message ?? sprintf(
"The element [%s] class doesn't contain all the given classes [%s].",
$this->identifier(),
implode(' ', $classes),
));
return $this;
}
/** Assert the element's class doesn't contain all the given classes. */
public function assertClassDoesntContainAll(array $classes, ?string $message = null): static
{
$this->classes->assertDoesntContainAll($classes, $message ?? sprintf(
'The element [%s] class contains all the given classes [%s].',
$this->identifier(),
implode(' ', $classes),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Attribute
|--------------------------------------------------------------------------
*/
/**
* Assert the element's attributes pass the given callback.
*
* @param callable(AssertableAttributesList $value): bool $callback
*/
public function assertAttributes(callable $callback, ?string $message = null): static
{
$this->attributes->assertAttributes($callback, $message ?? sprintf(
"The element [%s] attributes don't pass the given callback.",
$this->identifier(),
));
return $this;
}
/**
* Assert the element's attribute passes the given callback.
*
* @param callable(?string $value): bool $callback
*/
public function assertAttribute(string $attribute, callable $callback, ?string $message = null): static
{
$this->attributes->assertAttribute($attribute, $callback, $message ?? sprintf(
"The element [%s] attribute [%s] doesn't pass the given callback.",
$this->identifier(),
$attribute,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Attribute Array
|--------------------------------------------------------------------------
*/
/** Assert the given associative array of attributes equals the attribute list. */
public function assertAttributesEqualArray(array $attributes, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertEqualsArray($attributes, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] attributes don't equal the given array.",
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Attributes Empty
|--------------------------------------------------------------------------
*/
/** Assert the element's attributes list is empty. */
public function assertAttributesEmpty(?string $message = null): static
{
$this->attributes->assertEmpty($message ?? sprintf(
"The element [%s] attribute list isn't empty.",
$this->identifier(),
));
return $this;
}
/** Assert the element's attribute list isn't empty. */
public function assertAttributesNotEmpty(?string $message = null): static
{
$this->attributes->assertNotEmpty($message ?? sprintf(
'The element [%s] attribute list is empty.',
$this->identifier(),
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Attribute Present/Missing
|--------------------------------------------------------------------------
*/
/** Assert the element has the given attribute. */
public function assertAttributePresent(string $attribute, ?string $message = null): static
{
$this->attributes->assertPresent($attribute, $message ?? sprintf(
'The element [%s] is missing the given attribute [%s].',
$this->identifier(),
$attribute,
));
return $this;
}
/** Assert the element is missing the given attribute. */
public function assertAttributeMissing(string $attribute, ?string $message = null): static
{
$this->attributes->assertMissing($attribute, $message ?? sprintf(
'The element [%s] has the given attribute [%s].',
$this->identifier(),
$attribute,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Attribute Equals
|--------------------------------------------------------------------------
*/
/** Assert the given element's attribute equals the given value. */
public function assertAttributeEquals(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertEquals($attribute, $value, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] attribute [%s] doesn't equal the given value [%s].",
$this->identifier(),
$attribute,
$value,
));
return $this;
}
/** Assert the given element's attribute doesn't equal the given value. */
public function assertAttributeDoesntEqual(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertDoesntEqual($attribute, $value, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] attribute [%s] equals the given value [%s].',
$this->identifier(),
$attribute,
$value,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Attribute Contains
|--------------------------------------------------------------------------
*/
/** Assert the given element's attribute contains the given value. */
public function assertAttributeContains(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertContains($attribute, $value, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] attribute [%s] doesn't contain the given value [%s].",
$this->identifier(),
$attribute,
$value,
));
return $this;
}
/** Assert the given element's class doesn't contain the given value. */
public function assertAttributeDoesntContain(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertDoesntContain($attribute, $value, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] attribute [%s] contains the given value [%s].',
$this->identifier(),
$attribute,
$value,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Attribute Starts / Ends With
|--------------------------------------------------------------------------
*/
/** Assert the attribute starts with the given prefix. */
public function assertAttributeStartsWith(string $attribute, string $prefix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertStartsWith($attribute, $prefix, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] attribute [%s] doesn't start with the given prefix [%s].",
$this->identifier(),
$attribute,
$prefix,
));
return $this;
}
/** Assert the attribute doesn't start with the given prefix. */
public function assertAttributeDoesntStartWith(string $attribute, string $prefix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertDoesntStartWith($attribute, $prefix, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] attribute [%s] starts with the given prefix [%s].',
$this->identifier(),
$attribute,
$prefix,
));
return $this;
}
/** Assert the attribute ends with the given prefix. */
public function assertAttributeEndsWith(string $attribute, string $suffix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertEndsWith($attribute, $suffix, $normaliseWhitespace, $message ?? sprintf(
"The element [%s] attribute [%s] doesn't end with the given suffix [%s].",
$this->identifier(),
$attribute,
$suffix,
));
return $this;
}
/** Assert the attribute doesn't start with the given prefix. */
public function assertAttributeDoesntEndWith(string $attribute, string $suffix, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->attributes->assertDoesntEndWith($attribute, $suffix, $normaliseWhitespace, $message ?? sprintf(
'The element [%s] attribute [%s] ends with the given suffix [%s].',
$this->identifier(),
$attribute,
$suffix,
));
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Data Attribute
|--------------------------------------------------------------------------
*/
/**
* Assert the element's data attribute passes the given callback.
*
* @param callable(?string $value): bool $callback
*/
public function assertDataAttribute(string $attribute, callable $callback, ?string $message = null): static
{
$this->assertAttribute($this->prefixDataAttribute($attribute), $callback, $message);
return $this;
}
/** Assert the element has the given data attribute. */
public function assertDataAttributePresent(string $attribute, ?string $message = null): static
{
$this->assertAttributePresent($this->prefixDataAttribute($attribute), $message);
return $this;
}
/** Assert the element is missing the given data attribute. */
public function assertDataAttributeMissing(string $attribute, ?string $message = null): static
{
$this->assertAttributeMissing($this->prefixDataAttribute($attribute), $message);
return $this;
}
/** Assert the given element's data attribute equals the given value. */
public function assertDataAttributeEquals(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeEquals($this->prefixDataAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/** Assert the given element's attribute doesn't equal the given value. */
public function assertDataAttributeDoesntEqual(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeDoesntEqual($this->prefixDataAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/** Assert the given element's data attribute contains the given value. */
public function assertDataAttributeContains(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeContains($this->prefixDataAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/** Assert the given element's data attribute doesn't contain the given value. */
public function assertDataAttributeDoesntContain(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeDoesntContain($this->prefixDataAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/*
|--------------------------------------------------------------------------
| Assert Aria Attribute
|--------------------------------------------------------------------------
*/
/**
* Assert the element's data attribute passes the given callback.
*
* @param callable(?string $value): bool $callback
*/
public function assertAriaAttribute(string $attribute, callable $callback, ?string $message = null): static
{
$this->assertAttribute($this->prefixAriaAttribute($attribute), $callback, $message);
return $this;
}
/** Assert the element has the given data attribute. */
public function assertAriaAttributePresent(string $attribute, ?string $message = null): static
{
$this->assertAttributePresent($this->prefixAriaAttribute($attribute), $message);
return $this;
}
/** Assert the element is missing the given data attribute. */
public function assertAriaAttributeMissing(string $attribute, ?string $message = null): static
{
$this->assertAttributeMissing($this->prefixAriaAttribute($attribute), $message);
return $this;
}
/** Assert the given element's data attribute equals the given value. */
public function assertAriaAttributeEquals(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeEquals($this->prefixAriaAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/** Assert the given element's attribute doesn't equal the given value. */
public function assertAriaAttributeDoesntEqual(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeDoesntEqual($this->prefixAriaAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/** Assert the given element's data attribute contains the given value. */
public function assertAriaAttributeContains(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeContains($this->prefixAriaAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/** Assert the given element's data attribute doesn't contain the given value. */
public function assertAriaAttributeDoesntContain(string $attribute, string $value, bool $normaliseWhitespace = false, ?string $message = null): static
{
$this->assertAttributeDoesntContain($this->prefixAriaAttribute($attribute), $value, $normaliseWhitespace, $message);
return $this;
}
/*
|--------------------------------------------------------------------------
| Internal