-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathCssInlinerTest.php
More file actions
3937 lines (3519 loc) · 162 KB
/
CssInlinerTest.php
File metadata and controls
3937 lines (3519 loc) · 162 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 Pelago\Emogrifer\Tests\Unit;
use Pelago\Emogrifier\Css\CssDocument;
use Pelago\Emogrifier\CssInliner;
use Pelago\Emogrifier\HtmlProcessor\AbstractHtmlProcessor;
use Pelago\Emogrifier\Utilities\DeclarationBlockParser;
use Pelago\Emogrifier\Tests\Support\Traits\AssertCss;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
use Symfony\Component\CssSelector\CssSelectorConverter;
use Symfony\Component\CssSelector\Exception\SyntaxErrorException;
use TRegx\PhpUnit\DataProviders\DataProvider;
use function Safe\preg_replace;
/**
* @covers \Pelago\Emogrifier\CssInliner
*/
final class CssInlinerTest extends TestCase
{
use AssertCss;
/**
* Common HTML markup with a variety of elements and attributes for testing with
*/
private const COMMON_TEST_HTML = '
<html>
<body>
<p class="p-1"><span>some text</span></p>
<p class="p-2"><span title="bonjour">some</span> text</p>
<div class="div-3"><span title="buenas dias">some</span> more text</div>
<p class="p-4" id="p4"><span title="avez-vous">some</span> more <span id="text">text</span></p>
<p class="p-5 additional-class"><span title="buenas dias bom dia">some</span> more text</p>
<p class="p-6"><span title="title: subtitle; author">some</span> more text</p>
<p class="p-7">
<a
href="https://example.org/"
data-ascii-1="! " # $ % & ' ( ) * + , - . / : ; < = > ?"
data-ascii-2="@ [ \\ ] ^ _ ` { | } ~"
>
<span id="example-org">link text</span>
</a>
<input disabled>
<input type="text">
<input disabled type="text" value="some anytext text">
<strong><em></em></strong>
</p>
</body>
</html>
';
/**
* selection of at-rules which have no special handling by `CssInliner` but should be passed through and placed in a
* `<style>` element unmodified, for testing that and testing around
*/
private const BLACK_BOX_AT_RULES = [
'@font-face' => '
@font-face {
font-family: "Foo Sans";
src: url("/foo-sans.woff2") format("woff2");
}
',
'@-webkit-keyframes' => '
@-webkit-keyframes bounceIn {
from, 20%, 40%, 60%, 80%, to {
-webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
}
0% {
opacity: 0;
-webkit-transform: scale3d(.3, .3, .3);
transform: scale3d(.3, .3, .3);
}
20% {
-webkit-transform: scale3d(1.1, 1.1, 1.1);
transform: scale3d(1.1, 1.1, 1.1);
}
40% {
-webkit-transform: scale3d(.9, .9, .9);
transform: scale3d(.9, .9, .9);
}
60% {
opacity: 1;
-webkit-transform: scale3d(1.03, 1.03, 1.03);
transform: scale3d(1.03, 1.03, 1.03);
}
80% {
-webkit-transform: scale3d(.97, .97, .97);
transform: scale3d(.97, .97, .97);
}
to {
opacity: 1;
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
}
',
'@keyframes' => '
@keyframes bounceIn {
from, 20%, 40%, 60%, 80%, to {
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
}
0% {
opacity: 0;
transform: scale3d(.3, .3, .3);
}
20% {
transform: scale3d(1.1, 1.1, 1.1);
}
40% {
transform: scale3d(.9, .9, .9);
}
60% {
opacity: 1;
transform: scale3d(1.03, 1.03, 1.03);
}
80% {
transform: scale3d(.97, .97, .97);
}
to {
opacity: 1;
transform: scale3d(1, 1, 1);
}
}
',
'@supports' => '
@supports (display: grid) {
.main {
display: grid;
}
}
',
// This can be used for rules to specifically target the Gecko engine (i.e., for email, Thunderbird).
// The `@document` non-vendor-specific counterpart appears to have no value for emails, which do not have a URL.
'@-moz-document' => '
@-moz-document url-prefix() {
body {
font-size: 15px;
}
}
',
];
/**
* Builds a subject with the given HTML and debug mode enabled.
*
* @param non-empty-string $html
*/
private function buildDebugSubject(string $html): CssInliner
{
$subject = CssInliner::fromHtml($html);
$subject->setDebug(true);
return $subject;
}
/**
* @test
*/
public function fromHtmlReturnsInstanceOfCalledClass(): void
{
$subject = CssInliner::fromHtml('<html></html>');
self::assertInstanceOf(CssInliner::class, $subject);
}
/**
* @test
*/
public function isAbstractHtmlProcessor(): void
{
$subject = CssInliner::fromHtml('<html></html>');
self::assertInstanceOf(AbstractHtmlProcessor::class, $subject);
}
/**
* @test
*/
public function setDebugProvidesFluentInterface(): void
{
$subject = CssInliner::fromHtml('<html></html>');
$result = $subject->setDebug(false);
self::assertSame($subject, $result);
}
/**
* @test
*/
public function inlineCssProvidesFluentInterface(): void
{
$subject = CssInliner::fromHtml('<html><p>Hello world!</p></html>');
$result = $subject->inlineCss();
self::assertSame($subject, $result);
}
/**
* @return array<non-empty-string, array{0: non-empty-string}>
*/
public function wbrTagDataProvider(): array
{
return [
'single <wbr> tag' => ['<body>foo<wbr/>bar</body>'],
'two sibling <wbr> tags' => ['<body>foo<wbr/>bar<wbr/>baz</body>'],
'two non-sibling <wbr> tags' => ['<body><p>foo<wbr/>bar</p><p>bar<wbr/>baz</p></body>'],
];
}
/**
* @test
*
* @param non-empty-string $html
*
* @dataProvider wbrTagDataProvider
*/
public function inlineCssKeepsWbrTag(string $html): void
{
$subject = $this->buildDebugSubject($html);
$subject->inlineCss();
$result = $subject->renderBodyContent();
$expectedWbrTagCount = \substr_count($html, '<wbr');
$resultWbrTagCount = \substr_count($result, '<wbr');
self::assertSame($expectedWbrTagCount, $resultWbrTagCount);
}
/**
* @return array<non-empty-string, array{0: non-empty-string, 1: non-empty-string}>
*/
public function matchedCssDataProvider(): array
{
// The sprintf placeholders %1$s and %2$s will automatically be replaced with CSS declarations
// like 'color: red;' or 'text-align: left;'.
return [
'two declarations from one rule can apply to the same element' => [
'html { %1$s %2$s }',
'<html style="%1$s %2$s">',
],
'two identical matchers with different rules get combined' => [
'p { %1$s } p { %2$s }',
'<p class="p-1" style="%1$s %2$s">',
],
'two different matchers rules matching the same element get combined' => [
'p { %1$s } .p-1 { %2$s }',
'<p class="p-1" style="%1$s %2$s">',
],
'type => one element' => ['html { %1$s }', '<html style="%1$s">'],
'type (case-insensitive) => one element' => ['HTML { %1$s }', '<html style="%1$s">'],
'type => first matching element' => ['p { %1$s }', '<p class="p-1" style="%1$s">'],
'type => second matching element' => ['p { %1$s }', '<p class="p-2" style="%1$s">'],
'class => with class' => ['.p-2 { %1$s }', '<p class="p-2" style="%1$s">'],
'two classes s=> with both classes' => [
'.p-5.additional-class { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
'type & class => type with class' => ['p.p-2 { %1$s }', '<p class="p-2" style="%1$s">'],
'type (case-insensitive) & class => type with class' => ['P.p-2 { %1$s }', '<p class="p-2" style="%1$s">'],
'ID => with ID' => ['#p4 { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
'type & ID => type with ID' => ['p#p4 { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
'type (case-insensitive) & ID => type with ID' => ['P#p4 { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
'universal => HTML' => ['* { %1$s }', '<html style="%1$s">'],
'universal => element with parent and children' => ['* { %1$s }', '<p class="p-1" style="%1$s">'],
'universal => leaf element' => ['* { %1$s }', '<span style="%1$s">'],
':root => HTML' => [':root { %1$s }', '<html style="%1$s">'],
'attribute presence => with attribute' => ['[title] { %1$s }', '<span title="bonjour" style="%1$s">'],
'attribute exact value, double quotes => with exact attribute match' => [
'[title="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'attribute exact value, single quotes => with exact match' => [
'[title=\'bonjour\'] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
// broken: attribute exact value without quotes => with exact match
// broken: attribute exact two-word value, double quotes => with exact attribute value match
// broken: attribute exact two-word value, single quotes => with exact attribute value match
// broken: attribute exact value with ~, double quotes => exact attribute match
// broken: attribute exact value with ~, single quotes => exact attribute match
// broken: attribute exact value with ~, no quotes => exact attribute match
// broken: attribute value with |, double quotes => with exact match
// broken: attribute value with |, single quotes => with exact match
// broken: attribute value with |, no quotes => with exact match
// broken: attribute value with ^, double quotes => with exact match
// broken: attribute value with ^, single quotes => with exact match
// broken: attribute value with ^, no quotes => with exact match
// broken: attribute value with $, double quotes => with exact match
// broken: attribute value with $, single quotes => with exact match
// broken: attribute value with $, no quotes => with exact match
// broken: attribute value with *, double quotes => with exact match
// broken: attribute value with *, single quotes => with exact match
// broken: attribute value with *, no quotes => with exact match
'type & attribute presence => with type & attribute' => [
'span[title] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute exact value, double quotes => with type & exact attribute value match' => [
'span[title="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute exact value, single quotes => with type & exact attribute value match' => [
'span[title=\'bonjour\'] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute exact value without quotes => with type & exact attribute value match' => [
'span[title=bonjour] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute exact two-word value, double quotes => with type & exact attribute value match' => [
'span[title="buenas dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute exact four-word value, double quotes => with type & exact attribute value match' => [
'span[title="buenas dias bom dia"] { %1$s }',
'<span title="buenas dias bom dia" style="%1$s">',
],
'type & attribute exact two-word value, single quotes => with type & exact attribute value match' => [
'span[title=\'buenas dias\'] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute exact four-word value, single quotes => with type & exact attribute value match' => [
'span[title=\'buenas dias bom dia\'] { %1$s }',
'<span title="buenas dias bom dia" style="%1$s">',
],
'type & attribute value with ~, double quotes => with type & exact attribute match' => [
'span[title~="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with ~, single quotes => with type & exact attribute match' => [
'span[title~=\'bonjour\'] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with ~, no quotes => with type & exact attribute match' => [
'span[title~=bonjour] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with ~, double quotes => with type & word as 1st of 2 in attribute' => [
'span[title~="buenas"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with ~, double quotes => with type & word as 2nd of 2 in attribute' => [
'span[title~="dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with ~, double quotes => with type & word as 1st of 4 in attribute' => [
'span[title~="buenas"] { %1$s }',
'<span title="buenas dias bom dia" style="%1$s">',
],
'type & attribute value with ~, double quotes => with type & word as 2nd of 4 in attribute' => [
'span[title~="dias"] { %1$s }',
'<span title="buenas dias bom dia" style="%1$s">',
],
'type & attribute value with ~, double quotes => with type & word as last of 4 in attribute' => [
'span[title~="dia"] { %1$s }',
'<span title="buenas dias bom dia" style="%1$s">',
],
'type & attribute value with |, double quotes => with exact match' => [
'span[title|="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with |, single quotes => with exact match' => [
'span[title|=\'bonjour\'] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with |, no quotes => with exact match' => [
'span[title|=bonjour] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & two-word attribute value with |, double quotes => with exact match' => [
'span[title|="buenas dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with |, double quotes => with match before hyphen & another word' => [
'span[title|="avez"] { %1$s }',
'<span title="avez-vous" style="%1$s">',
],
'type & attribute value with ^, double quotes => with exact match' => [
'span[title^="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with ^, single quotes => with exact match' => [
'span[title^=\'bonjour\'] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with ^, no quotes => with exact match' => [
'span[title^=bonjour] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & two-word attribute value with ^, double quotes => with exact match' => [
'span[title^="buenas dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with ^, double quotes => with prefix math' => [
'span[title^="bon"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with ^, double quotes => with match before another word' => [
'span[title^="buenas"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with $, double quotes => with exact match' => [
'span[title$="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with $, single quotes => with exact match' => [
'span[title$=\'bonjour\'] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with $, no quotes => with exact match' => [
'span[title$=bonjour] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & two-word attribute value with $, double quotes => with exact match' => [
'span[title$="buenas dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with $, double quotes => with suffix math' => [
'span[title$="jour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with $, double quotes => with match after another word' => [
'span[title$="dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & two-word attribute value with *, double quotes => with exact match' => [
'span[title*="buenas dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with *, double quotes => with prefix math' => [
'span[title*="bon"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with *, double quotes => with suffix math' => [
'span[title*="jour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with *, double quotes => with substring math' => [
'span[title*="njo"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'type & attribute value with *, double quotes => with match before another word' => [
'span[title*="buenas"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with *, double quotes => with match after another word' => [
'span[title*="dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & special characters attribute value with *, double quotes => with substring match' => [
'span[title*=": subtitle; author"] { %1$s }',
'<span title="title: subtitle; author" style="%1$s">',
],
// broken: type & attribute exact value, case insensitive => with case insensitive attribute value match
// broken: type & attribute value with ~, case insensitive => with case insensitive attribute word match
// broken: type & attribute value with |, case insensitive => with case insensitive match before hyphen
// broken: type & attribute value with ^, case insensitive => with case insensitive prefix math
// broken: type & attribute value with $, case insensitive => with case insensitive suffix math
// broken: type & attribute value with *, case insensitive => with case insensitive substring math
// broken: :required
// broken: :optional
'adjacent => 2nd of many' => ['p + p { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent => last of many' => ['p + p { %1$s }', '<p class="p-7" style="%1$s">'],
'adjacent (without space after +) => last of many' => ['p +p { %1$s }', '<p class="p-7" style="%1$s">'],
'adjacent (without space before +) => last of many' => ['p+ p { %1$s }', '<p class="p-7" style="%1$s">'],
'adjacent (without space before or after +) => last of many' => [
'p+p { %1$s }',
'<p class="p-7" style="%1$s">',
],
'general sibling => 2nd of many' => ['.p-1 ~ p { %1$s }', '<p class="p-2" style="%1$s">'],
'general sibling => last of many' => ['.p-1 ~ p { %1$s }', '<p class="p-7" style="%1$s">'],
'general sibling (without space after ~) => last of many' => [
'.p-1 ~p { %1$s }',
'<p class="p-7" style="%1$s">',
],
'general sibling (without space before ~) => last of many' => [
'.p-1~ p { %1$s }',
'<p class="p-7" style="%1$s">',
],
'general sibling (without space before or after ~) => last of many' => [
'.p-1~p { %1$s }',
'<p class="p-7" style="%1$s">',
],
'child (with spaces around >) => direct child' => ['p > span { %1$s }', '<span style="%1$s">'],
'child (without space after >) => direct child' => ['p >span { %1$s }', '<span style="%1$s">'],
'child (without space before >) => direct child' => ['p> span { %1$s }', '<span style="%1$s">'],
'child (without space before or after >) => direct child' => ['p>span { %1$s }', '<span style="%1$s">'],
'descendant => child' => ['p span { %1$s }', '<span style="%1$s">'],
'descendant => grandchild' => ['body span { %1$s }', '<span style="%1$s">'],
'adjacent universal => 2nd of many' => ['p + * { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent universal => last of many' => ['p + * { %1$s }', '<p class="p-7" style="%1$s">'],
'adjacent of universal => 2nd of many' => ['* + p { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent of universal => last of many' => ['* + p { %1$s }', '<p class="p-7" style="%1$s">'],
'universal general sibling => 2nd of many' => ['.p-1 ~ * { %1$s }', '<p class="p-2" style="%1$s">'],
'universal general sibling => last of many' => ['.p-1 ~ * { %1$s }', '<p class="p-7" style="%1$s">'],
'general sibling of universal => 2nd of many' => ['* ~ p { %1$s }', '<p class="p-2" style="%1$s">'],
'general sibling of universal => last of many' => ['* ~ p { %1$s }', '<p class="p-7" style="%1$s">'],
'child universal => direct child' => ['body > * { %1$s }', '<p class="p-1" style="%1$s">'],
'child of universal => direct child' => ['* > body { %1$s }', '<body style="%1$s">'],
'descendent universal => child' => ['p * { %1$s }', '<span style="%1$s">'],
'descendent universal => grandchild' => ['body * { %1$s }', '<span style="%1$s">'],
'descendant of universal => child' => ['* body { %1$s }', '<body style="%1$s">'],
'descendant of universal => grandchild' => ['* p { %1$s }', '<p class="p-1" style="%1$s">'],
'descendent attribute presence => with attribute' => [
'body [title] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'descendent attribute exact value => with exact attribute match' => [
'body [title="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'descendent type & attribute presence => with type & attribute' => [
'body span[title] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'descendent type & Boolean attribute presence => with type & attribute' => [
'html input[disabled] { %1$s }',
'<input disabled style="%1$s">',
],
'descendent type & attribute exact value => with type & exact attribute match' => [
'body span[title="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'descendent type & attribute exact two-word value => with type & exact attribute match' => [
'body span[title="buenas dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'descendent type & attribute value with ~ => with type & exact attribute match' => [
'body span[title~="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'descendent type & attribute value with ~ => with type & word as 1st of 2 in attribute' => [
'body span[title~="buenas"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'descendent type & attribute value with ^ => with type & attribute prefix match' => [
'p span[title^=bon] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'descendant of type & class: type & attribute exact value, no quotes => with type & exact match (#381)' => [
'p.p-2 span[title=bonjour] { %1$s }',
'<span title="bonjour" style="%1$s">',
],
'descendant of attribute presence => parent with attribute' => [
'[class] span { %1$s }',
'<p class="p-1"><span style="%1$s">',
],
'descendant of attribute exact value => parent with type & exact attribute match' => [
'[id="p4"] span { %1$s }',
'<p class="p-4" id="p4"><span title="avez-vous" style="%1$s">',
],
'descendant of type & attribute presence => parent with type & attribute' => [
'p[id] span { %1$s }',
'<p class="p-4" id="p4"><span title="avez-vous" style="%1$s">',
],
'descendant of type & attribute exact value => parent with type & exact attribute match' => [
'p[id="p4"] span { %1$s }',
'<p class="p-4" id="p4"><span title="avez-vous" style="%1$s">',
],
'descendant of type & attribute exact two-word value => parent with type & exact attribute match' => [
'p[class="p-5 additional-class"] span { %1$s }',
'<p class="p-5 additional-class"><span title="buenas dias bom dia" style="%1$s">',
],
'descendant of type & attribute value with ~ => parent with type & exact attribute match' => [
'p[class~="p-1"] span { %1$s }',
'<p class="p-1"><span style="%1$s">',
],
'descendant of type & attribute value with ~ => parent with type & word as 1st of 2 in attribute' => [
'p[class~="p-5"] span { %1$s }',
'<p class="p-5 additional-class"><span title="buenas dias bom dia" style="%1$s">',
],
'child of attribute presence with - in name => child of parent with expected attribute' => [
'a[data-ascii-1] > #example-org { %1$s }',
'<span id="example-org" style="%1$s">',
],
'child of attribute value with ^ matching : => child of parent with expected prefix match' => [
'a[href^="https:"] > #example-org { %1$s }',
'<span id="example-org" style="%1$s">',
],
'child of attribute value with ~ matching - => child of parent with expected word match' => [
'a[data-ascii-1~="-"] > #example-org { %1$s }',
'<span id="example-org" style="%1$s">',
],
'child of attribute value with * matching - => child of parent with expected part match' => [
'a[data-ascii-1*="-"] > #example-org { %1$s }',
'<span id="example-org" style="%1$s">',
],
'child of attribute value with ~ matching ; => child of parent with expected word match' => [
'a[data-ascii-1~=";"] > #example-org { %1$s }',
'<span id="example-org" style="%1$s">',
],
'child of attribute value with * matching ; => child of parent with expected part match' => [
'a[data-ascii-1*=";"] > #example-org { %1$s }',
'<span id="example-org" style="%1$s">',
],
'type, attribute exact value & Boolean attribute presence => with exact attribute match' => [
'input[type="text"][disabled] { %1$s }',
'<input disabled type="text" value="some anytext text" style="%1$s">',
],
'type, attribute value with * & attribute exact value => with exact attribute match' => [
'input[value*="anytext"][type="text"] { %1$s }',
'<input disabled type="text" value="some anytext text" style="%1$s">',
],
'descendant of universal, type, attribute value with * & attribute exact value => with attribute match' => [
'* input[value*="anytext"][type="text"] { %1$s }',
'<input disabled type="text" value="some anytext text" style="%1$s">',
],
':first-child => 1st of many' => [':first-child { %1$s }', '<p class="p-1" style="%1$s">'],
'type & :first-child => 1st of many' => ['p:first-child { %1$s }', '<p class="p-1" style="%1$s">'],
'child combinator & :first-child => 1st of many' => [
'body > :first-child { %1$s }',
'<p class="p-1" style="%1$s">',
],
':last-child => last of many' => [':last-child { %1$s }', '<p class="p-7" style="%1$s">'],
'type & :last-child => last of many' => ['p:last-child { %1$s }', '<p class="p-7" style="%1$s">'],
'child combinator & :last-child => last of many' => [
'body > :last-child { %1$s }',
'<p class="p-7" style="%1$s">',
],
':only-child => element without siblings' => [':only-child { %1$s }', '<span style="%1$s">'],
'type & :only-child => element without siblings' => ['span:only-child { %1$s }', '<span style="%1$s">'],
'child combinator & :only-child => element without siblings' => [
'p > :only-child { %1$s }',
'<span style="%1$s">',
],
':nth-child(even) => 2nd of many' => [':nth-child(even) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-child(even) => 4th of many' => [':nth-child(even) { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
':nth-child(2n) => 2nd of many' => [':nth-child(2n) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-child(2n) => 4th of many' => [':nth-child(2n) { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
':nth-child(3) => 3rd of many' => [':nth-child(3) { %1$s }', '<div class="div-3" style="%1$s">'],
':nth-child(2n+3) => 3rd of many' => [':nth-child(2n+3) { %1$s }', '<div class="div-3" style="%1$s">'],
':nth-child(2n+3) => 5th of many' => [
':nth-child(2n+3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
':nth-child(-n+3) => 2nd of many' => [':nth-child(-n+3) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-child(-n+3) => 3rd of many' => [':nth-child(-n+3) { %1$s }', '<div class="div-3" style="%1$s">'],
'type & :nth-child(even) => 2nd of many' => ['p:nth-child(even) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-last-child(even) => 2nd last of many' => [
':nth-last-child(even) { %1$s }',
'<p class="p-6" style="%1$s">',
],
':nth-last-child(even) => 4th last of many' => [
':nth-last-child(even) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
':nth-last-child(2n) => 2nd last of many' => [
':nth-last-child(2n) { %1$s }',
'<p class="p-6" style="%1$s">',
],
':nth-last-child(2n) => 4th last of many' => [
':nth-last-child(2n) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
':nth-last-child(3) => 3rd last of many' => [
':nth-last-child(3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
':nth-last-child(2n+3) => 3rd last of many' => [
':nth-last-child(2n+3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
':nth-last-child(2n+3) => 5th last of many' => [
':nth-last-child(2n+3) { %1$s }',
'<div class="div-3" style="%1$s">',
],
':nth-last-child(-n+3) => 2nd last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<p class="p-6" style="%1$s">',
],
':nth-last-child(-n+3) => 3rd last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
'type & :nth-last-child(even) => 2nd last of many' => [
'p:nth-last-child(even) { %1$s }',
'<p class="p-6" style="%1$s">',
],
// broken: first-of-type without preceding type
'type & :first-of-type => 1st of many' => ['p:first-of-type { %1$s }', '<p class="p-1" style="%1$s">'],
'type & :first-of-type => 1st of that type' => [
'div:first-of-type { %1$s }',
'<div class="div-3" style="%1$s">',
],
// broken: last-of-type without preceding type
'type & :last-of-type => last of many' => ['p:last-of-type { %1$s }', '<p class="p-7" style="%1$s">'],
'type & :last-of-type => last of that type' => [
'div:last-of-type { %1$s }',
'<div class="div-3" style="%1$s">',
],
// broken: only-of-type without preceding type
'type & :only-of-type => only child' => ['span:only-of-type { %1$s }', '<span style="%1$s">'],
'type & :only-of-type => only of that type' => [
'div:only-of-type { %1$s }',
'<div class="div-3" style="%1$s">',
],
// broken: nth-of-type without preceding type
'type & :nth-of-type(even) => 2nd of many of type' => [
'p:nth-of-type(even) { %1$s }',
'<p class="p-2" style="%1$s">',
],
'type & :nth-of-type(even) => 4th of many of type' => [
'p:nth-of-type(even) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
'type & :nth-of-type(2n) => 2nd of many of type' => [
'p:nth-of-type(2n) { %1$s }',
'<p class="p-2" style="%1$s">',
],
'type & :nth-of-type(2n) => 4th of many of type' => [
'p:nth-of-type(2n) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
'type & :nth-of-type(3) => 3rd of many of type' => [
'p:nth-of-type(3) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
'type & :nth-of-type(2n+3) => 3rd of many of type' => [
'p:nth-of-type(2n+3) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
'type & :nth-of-type(2n+3) => 5th of many of type' => [
'p:nth-of-type(2n+3) { %1$s }',
'<p class="p-6" style="%1$s">',
],
'type & :nth-of-type(-n+3) => 2nd of many of type' => [
'p:nth-of-type(-n+3) { %1$s }',
'<p class="p-2" style="%1$s">',
],
'type & :nth-of-type(-n+3) => 3rd of many of type' => [
'p:nth-of-type(-n+3) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
// broken: nth-last-of-type without preceding type
'type & :nth-last-of-type(even) => 2nd last of many of type' => [
'p:nth-last-of-type(even) { %1$s }',
'<p class="p-6" style="%1$s">',
],
'type & :nth-last-of-type(even) => 4th last of many of type' => [
'p:nth-last-of-type(even) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
'type & :nth-last-of-type(2n) => 2nd last of many of type' => [
'p:nth-last-of-type(2n) { %1$s }',
'<p class="p-6" style="%1$s">',
],
'type & :nth-last-of-type(2n) => 4th last of many of type' => [
'p:nth-last-of-type(2n) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
'type & :nth-last-of-type(3) => 3rd last of many of type' => [
'p:nth-last-of-type(3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
'type & :nth-last-of-type(2n+3) => 3rd last of many of type' => [
'p:nth-last-of-type(2n+3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
'type & :nth-last-of-type(2n+3) => 5th last of many of type' => [
'p:nth-last-of-type(2n+3) { %1$s }',
'<p class="p-2" style="%1$s">',
],
'type & :nth-last-of-type(-n+3) => 2nd last of many of type' => [
'p:nth-last-of-type(-n+3) { %1$s }',
'<p class="p-6" style="%1$s">',
],
'type & :nth-last-of-type(-n+3) => 3rd last of many of type' => [
'p:nth-last-of-type(-n+3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
':empty => non-void element without content' => [':empty { %1$s }', '<em style="%1$s">'],
':empty => void element' => [':empty { %1$s }', '<input type="text" style="%1$s">'],
':not with type => other type' => [':not(p) { %1$s }', '<span style="%1$s">'],
':not with class => no class' => [':not(.p-1) { %1$s }', '<span style="%1$s">'],
':not with class => other class' => [':not(.p-1) { %1$s }', '<p class="p-2" style="%1$s">'],
'type & :not with class => without class' => ['span:not(.foo) { %1$s }', '<span style="%1$s">'],
'type & :not with class => with other class' => ['p:not(.foo) { %1$s }', '<p class="p-1" style="%1$s">'],
// broken: child of :any-link => child of anchor with href
];
}
/**
* @test
*
* @param non-empty-string $css CSS statements, potentially with %1$s and $2$s placeholders for a CSS declaration
* @param non-empty-string $expectedHtml HTML, potentially with %1$s and $2$s placeholders for a CSS declaration
*
* @dataProvider matchedCssDataProvider
*/
public function inlineCssAppliesCssToMatchingElements(string $css, string $expectedHtml): void
{
$cssDeclaration1 = 'color: red;';
$cssDeclaration2 = 'text-align: left;';
$needleExpected = \sprintf($expectedHtml, $cssDeclaration1, $cssDeclaration2);
$subject = $this->buildDebugSubject(self::COMMON_TEST_HTML);
$subject->inlineCss(\sprintf($css, $cssDeclaration1, $cssDeclaration2));
$result = $subject->render();
$selector = \trim(\strtok($css, '{'));
$xPathExpression = (new CssSelectorConverter())->toXPath($selector);
$message = 'with converted XPath expression `' . $xPathExpression . '`';
self::assertStringContainsString($needleExpected, $result, $message);
}
/**
* @return array<non-empty-string, array{0: non-empty-string, 1: non-empty-string}>
*/
public function nonMatchedCssDataProvider(): array
{
// The sprintf placeholders %1$s and %2$s will automatically be replaced with CSS declarations
// like 'color: red;' or 'text-align: left;'.
return [
'type => not other type' => ['html { %1$s }', '<body>'],
'class => not other class' => ['.p-2 { %1$s }', '<p class="p-1">'],
'class => not without class' => ['.p-2 { %1$s }', '<body>'],
'two classes => not only first class' => ['.p-1.another-class { %1$s }', '<p class="p-1">'],
'two classes => not only second class' => ['.another-class.p-1 { %1$s }', '<p class="p-1">'],
'type & class => not only type' => ['html.p-1 { %1$s }', '<html>'],
'type & class => not only class' => ['html.p-1 { %1$s }', '<p class="p-1">'],
'ID => not other ID' => ['#yeah { %1$s }', '<p class="p-4" id="p4">'],
'ID => not without ID' => ['#yeah { %1$s }', '<span>'],
'type & ID => not other type with that ID' => ['html#p4 { %1$s }', '<p class="p-4" id="p4">'],
'type & ID => not that type with other ID' => ['p#p5 { %1$s }', '<p class="p-4" id="p4">'],
':root => not BODY' => [':root { %1$s }', '<body>'],
':root => not P' => [':root { %1$s }', '<p class="p-1">'],
'attribute presence => not element without that attribute' => ['[title] { %1$s }', '<span>'],
'attribute exact value => not element without that attribute' => ['[title="bonjour"] { %1$s }', '<span>'],
'attribute exact value => not element with different attribute value' => [
'[title="hi"] { %1$s }',
'<span title="bonjour">',
],
'attribute exact value => not element with only substring match in attribute value' => [
'[title="njo"] { %1$s }',
'<span title="bonjour">',
],
'type & attribute presence => not element of type without that attribute' => [
'span[title] { %1$s }',
'<span>',
],
'type & attribute value with ~ => not element with only prefix match in attribute value' => [
'span[title~="bon"] { %1$s }',
'<span title="bonjour">',
],
'type & attribute value with |, double quotes => not element with match after another word & hyphen' => [
'span[title|="vous"] { %1$s }',
'<span title="avez-vous">',
],
'type & attribute value with ^ => not element with only substring match in attribute value' => [
'span[title^="njo"] { %1$s }',
'<span title="bonjour">',
],
'type & attribute value with ^, double quotes => not element with only suffix match in attribute value' => [
'span[title^="jour"] { %1$s }',
'<span title="bonjour">',
],
'type & two word attribute value with ^ => not element with only substring match in attribute value' => [
'span[title^="dias bom"] { %1$s }',
'<span title="buenas dias bom dia">',
],
'type & two word attribute value with ^ => not element with only suffix match in attribute value' => [
'span[title^="bom dia"] { %1$s }',
'<span title="buenas dias bom dia">',
],
'type & attribute value with $ => not element with only substring match in attribute value' => [
'span[title$="njo"] { %1$s }',
'<span title="bonjour">',
],
'type & attribute value with $, double quotes => not element with only prefix match in attribute value' => [
'span[title$="bon"] { %1$s }',
'<span title="bonjour">',
],
'type & attribute value with * => not element with different attribute value' => [
'span[title*="hi"] { %1$s }',
'<span title="bonjour">',
],
'adjacent => not 1st of many' => ['p + p { %1$s }', '<p class="p-1">'],
'general sibling => not 1st of many' => ['p ~ p { %1$s }', '<p class="p-1">'],
'child => not grandchild' => ['html > span { %1$s }', '<span>'],
'child => not parent' => ['span > html { %1$s }', '<html>'],
'descendant => not sibling' => ['span span { %1$s }', '<span>'],
'descendant => not parent' => ['p body { %1$s }', '<body>'],
'adjacent universal => not 1st of many' => ['p + * { %1$s }', '<p class="p-1">'],
'adjacent universal => not last of many' => ['.p-2 + * { %1$s }', '<p class="p-7">'],
'adjacent universal => not previous of many' => ['.p-2 + * { %1$s }', '<p class="p-1">'],
'adjacent of universal => not 1st of many' => ['* + p { %1$s }', '<p class="p-1">'],
'universal general sibling => not 1st of many' => ['p ~ * { %1$s }', '<p class="p-1">'],
'universal general sibling => not previous of many' => ['.p-2 ~ * { %1$s }', '<p class="p-1">'],
'general sibling of universal => not 1st of many' => ['* ~ p { %1$s }', '<p class="p-1">'],
'child universal => not parent' => ['body > * { %1$s }', '<html>'],
'child universal => not self' => ['body > * { %1$s }', '<body>'],
'child universal => not grandchild' => ['body > * { %1$s }', '<span>'],
'child of universal => not root element' => ['* > html { %1$s }', '<html>'],
'descendent universal => not parent' => ['p * { %1$s }', '<body>'],
'descendent universal => not self' => ['p * { %1$s }', '<p class="p-1">'],
'descendant of universal => not root element' => ['* html { %1$s }', '<html>'],
'descendent type & attribute value with ^ => not element with only substring match in attribute value' => [
'p span[title^=njo] { %1$s }',
'<span title="bonjour">',
],
'child of attribute presence with - in name => not child of parent without expected attribute' => [
'a[data-some-other] > #example-org { %1$s }',
'<span id="example-org">',
],
'child of attribute value with ^ matching : => not child of parent without expected prefix match' => [
'a[href^="ftp:"] > #example-org { %1$s }',
'<span id="example-org">',
],
'child of attribute value with ~ matching - => not child of parent without expected word match' => [
'a[data-ascii-2~="-"] > #example-org { %1$s }',
'<span id="example-org">',
],
'child of attribute value with * matching - => not child of parent without expected part match' => [
'a[data-ascii-2*="-"] > #example-org { %1$s }',
'<span id="example-org">',
],
'child of attribute value with ~ matching ; => not child of parent without expected word match' => [
'a[data-ascii-2~=";"] > #example-org { %1$s }',
'<span id="example-org">',
],
'child of attribute value with * matching ; => not child of parent without expected part match' => [
'a[data-ascii-2*=";"] > #example-org { %1$s }',
'<span id="example-org">',
],
'type, attribute exact value & Boolean attribute presence => not with only exact attribute match' => [
'input[type="text"][disabled] { %1$s }',
'<input type="text">',
],
'type, attribute exact value & Boolean attribute presence => not with only attribute presence' => [
'input[type="text"][disabled] { %1$s }',
'<input disabled>',
],
':first-child => not 2nd of many' => [':first-child { %1$s }', '<p class="p-2">'],
':first-child => not last of many' => [':first-child { %1$s }', '<p class="p-7">'],
'type & :first-child => not 2nd of many' => ['p:first-child { %1$s }', '<p class="p-2">'],
'type & :first-child => not last of many' => ['p:first-child { %1$s }', '<p class="p-7">'],
'child combinator & :first-child => not 2nd of many' => ['body > :first-child { %1$s }', '<p class="p-2">'],
'child combinator & :first-child => not last of many' => [
'body > :first-child { %1$s }',
'<p class="p-7">',
],
':last-child => not 1st of many' => [':last-child { %1$s }', '<p class="p-1">'],
':last-child => not 2nd of many' => [':last-child { %1$s }', '<p class="p-2">'],
'type & :last-child => not 1st of many' => ['p:last-child { %1$s }', '<p class="p-1">'],
'type & :last-child => not 2nd of many' => ['p:last-child { %1$s }', '<p class="p-2">'],
'child combinator & :last-child => not 1st of many' => ['body > :last-child { %1$s }', '<p class="p-1">'],
'child combinator & :last-child => not 2nd of many' => ['body > :last-child { %1$s }', '<p class="p-2">'],
':only-child => not element with siblings' => [':only-child { %1$s }', '<p class="p-1">'],
'type & :only-child => not element with siblings' => ['p:only-child { %1$s }', '<p class="p-1">'],
'child combinator & :only-child => not element with siblings' => [
'body > :only-child { %1$s }',
'<p class="p-1">',
],
':nth-child(even) => not 1st of many' => [':nth-child(even) { %1$s }', '<p class="p-1">'],
':nth-child(even) => not 3rd of many' => [':nth-child(even) { %1$s }', '<div class="div-3">'],
':nth-child(2n) => not 1st of many' => [':nth-child(2n) { %1$s }', '<p class="p-1">'],
':nth-child(2n) => not 3rd of many' => [':nth-child(2n) { %1$s }', '<div class="div-3">'],
':nth-child(3) => not 1st of many' => [':nth-child(3) { %1$s }', '<p class="p-1">'],
':nth-child(3) => not 2nd of many' => [':nth-child(3) { %1$s }', '<p class="p-2">'],
':nth-child(3) => not 4th of many' => [':nth-child(3) { %1$s }', '<p class="p-4" id="p4">'],
':nth-child(3) => not 6th of many' => [':nth-child(3) { %1$s }', '<p class="p-6">'],
':nth-child(2n+3) => not 1st of many' => [':nth-child(2n+3) { %1$s }', '<p class="p-1">'],
':nth-child(2n+3) => not 4th of many' => [':nth-child(2n+3) { %1$s }', '<p class="p-4" id="p4">'],
':nth-child(-n+3) => not 4th of many' => [':nth-child(-n+3) { %1$s }', '<p class="p-4" id="p4">'],
':nth-child(-n+3) => not 5th of many' => [':nth-child(-n+3) { %1$s }', '<p class="p-5 additional-class">'],
':nth-last-child(even) => not last of many' => [':nth-last-child(even) { %1$s }', '<p class="p-7">'],
':nth-last-child(even) => not 3rd last of many' => [
':nth-last-child(even) { %1$s }',
'<p class="p-5 additional-class">',
],
':nth-last-child(2n) => not last of many' => [':nth-last-child(2n) { %1$s }', '<p class="p-7">'],
':nth-last-child(2n) => not 3rd last of many' => [
':nth-last-child(2n) { %1$s }',
'<p class="p-5 additional-class">',
],
':nth-last-child(3) => not last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-7">'],
':nth-last-child(3) => not 2nd last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-6">'],
':nth-last-child(3) => not 4th last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-4" id="p4">'],
':nth-last-child(3) => not 6th last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-2">'],
':nth-last-child(2n+3) => not last of many' => [':nth-last-child(2n+3) { %1$s }', '<p class="p-7">'],
':nth-last-child(2n+3) => not 4th last of many' => [
':nth-last-child(2n+3) { %1$s }',
'<p class="p-4" id="p4">',
],
':nth-last-child(-n+3) => not 4th last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<p class="p-4" id="p4">',
],
':nth-last-child(-n+3) => not 5th last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<div class="div-3">',