Skip to content

Commit 1f7d7c2

Browse files
committed
Add test cases
1 parent a142c41 commit 1f7d7c2

File tree

1 file changed

+99
-17
lines changed

1 file changed

+99
-17
lines changed

tests/MoodleHQ/RTLCSS/RTLCSSTest.php

Lines changed: 99 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,74 @@ public function backgroundImageProvider() {
4343

4444
public function backgroundPositionProvider() {
4545
return [
46+
[[
47+
'should' => 'Should mirror position (keywords only)',
48+
'expected' => 'div {background-position:top left, right bottom}',
49+
'input' => 'div {background-position:top right, left bottom}',
50+
'reversable' => true,
51+
'skip' => true, // broken in PHPCssParser: https://github.com/sabberworm/PHP-CSS-Parser/issues/123
52+
]],
53+
[[
54+
'should' => 'Should ignore mirroring invalid position',
55+
'expected' => 'div {background-position:25% left, right 25%;}',
56+
'input' => 'div {background-position:75% left, left 25%;}',
57+
'reversable' => true,
58+
'skip' => true, // broken in PHPCssParser: https://github.com/sabberworm/PHP-CSS-Parser/issues/123
59+
]],
60+
[[
61+
'should' => 'Should complement percentage horizontal position',
62+
'expected' => 'div {background-position:25%;}',
63+
'input' => 'div {background-position:75%;}',
64+
'reversable' => true
65+
]],
66+
[[
67+
'should' => 'Should flip left offset',
68+
'expected' => 'div {background-position:right 25px center;}',
69+
'input' => 'div {background-position:left 25px center;}',
70+
'reversable' => true,
71+
]],
72+
[[
73+
'should' => 'Should flip left and right',
74+
'expected' => 'div {background-position:right;}',
75+
'input' => 'div {background-position:left;}',
76+
'reversable' => true
77+
]],
78+
[[
79+
'should' => 'Should not flip top',
80+
'expected' => 'div {background-position:top;}',
81+
'input' => 'div {background-position:top;}',
82+
'reversable' => true
83+
]],
84+
[[
85+
'should' => 'Should not flip bottom',
86+
'expected' => 'div {background-position:bottom;}',
87+
'input' => 'div {background-position:bottom;}',
88+
'reversable' => true
89+
]],
90+
[[
91+
'should' => 'Should flip X offset but not Y offset',
92+
'expected' => 'div {background-position:left 25px top;}',
93+
'input' => 'div {background-position:right 25px top;}',
94+
'reversable' => true,
95+
]],
96+
[[
97+
'should' => 'Should flip X offset but not Y offset',
98+
'expected' => 'div {background-position:25% bottom;}',
99+
'input' => 'div {background-position:75% bottom;}',
100+
'reversable' => true
101+
]],
102+
[[
103+
'should' => 'Should flip X offset but not Y offset',
104+
'expected' => 'div {background-position:left top;}',
105+
'input' => 'div {background-position:right top;}',
106+
'reversable' => true
107+
]],
108+
[[
109+
'should' => 'Should flip X offset but not Y offset',
110+
'expected' => 'div {background-position:bottom right;}',
111+
'input' => 'div {background-position:bottom left;}',
112+
'reversable' => true
113+
]],
46114
[[
47115
'should' => 'Should complement percentage horizontal position ',
48116
'expected' => 'div {background-position:100% 75%;}',
@@ -71,23 +139,23 @@ public function backgroundPositionProvider() {
71139
'skip' => true
72140
]],
73141
[[
74-
'should' => 'Should swap left with right',
142+
'should' => 'Should mirror background-position',
75143
'expected' => 'div {background-position:right 75%, left top;}',
76144
'input' => 'div {background-position:left 75%, right top;}',
77145
'reversable' => true,
78146
'skip' => true
79147
]],
80148
[[
81-
'should' => 'Should swap left with right wit calc',
149+
'should' => 'Should mirror background-position (calc)',
82150
'expected' => 'div {background-position:right -ms-calc(30% + 50px), left top;}',
83151
'input' => 'div {background-position:left -ms-calc(30% + 50px), right top;}',
84152
'reversable' => true,
85153
'skip' => true
86154
]],
87155
[[
88-
'should' => 'Should complement percentage: position-x (treat 0 as 0%)',
156+
'should' => 'Should complement percentage: position-x',
89157
'expected' => 'div {background-position-x:100%, 0%;}',
90-
'input' => 'div {background-position-x:0, 100%;}',
158+
'input' => 'div {background-position-x:0%, 100%;}',
91159
'reversable' => false
92160
]],
93161
[[
@@ -101,21 +169,35 @@ public function backgroundPositionProvider() {
101169
'expected' => 'div {background-position-x:calc(100% - (30% + 50px)), -webkit-calc(100% - (30% + 50px));}',
102170
'input' => 'div {background-position-x:calc(30% + 50px), -webkit-calc(30% + 50px);}',
103171
'reversable' => false,
104-
'skip' => true
172+
'skip' => true, // calc is not parsed by PHPCssParser
105173
]],
106174
[[
107-
'should' => 'Should swap left with right: position-x',
175+
'should' => 'Should mirror position-x',
108176
'expected' => 'div {background-position-x:right, left;}',
109177
'input' => 'div {background-position-x:left, right;}',
110178
'reversable' => true
111179
]],
112180
[[
113-
'should' => 'Should keep as is: position-x',
114-
'expected' => 'div {background-position-x:100px, 0px;}',
115-
'input' => 'div {background-position-x:100px, 0px;}',
116-
'reversable' => true
181+
'should' => 'Should mirror position-x (calc)',
182+
'expected' => 'div {background-position-x:calc(100% - (30% + 50px)), calc(100% - (50px * 5));}',
183+
'input' => 'div {background-position-x:calc(30% + 50px), calc(50px * 5);}',
184+
'reversable' => false,
185+
'skip' => true, // calc is not parsed by PHPCssParser
186+
]],
187+
[[
188+
'should' => 'Should mirror background-position edge offsets (4 values)',
189+
'expected' => 'div {background-position:left 5px bottom 5px, bottom 15px right 15px;}',
190+
'input' => 'div {background-position:right 5px bottom 5px, bottom 15px left 15px;}',
191+
'reversable' => true,
192+
'skip' => true, // broken in PHPCssParser: https://github.com/sabberworm/PHP-CSS-Parser/issues/123
193+
]],
194+
[[
195+
'should' => 'Should mirror background-position edge offsets (3 values)',
196+
'expected' => 'div {background-position:left 5px bottom, top 15px right;}',
197+
'input' => 'div {background-position:right 5px bottom, top 15px left;}',
198+
'reversable' => true,
199+
'skip' => true, // broken in PHPCssParser: https://github.com/sabberworm/PHP-CSS-Parser/issues/123
117200
]],
118-
119201
[[
120202
'should' => 'Should flip when using 3 positions',
121203
'expected' => 'div {background-position:center right 1px;}',
@@ -166,42 +248,42 @@ public function backgroundProvider() {
166248
]],
167249
[[
168250
'should' => 'Should not process string map in url (default)',
169-
'expected' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
251+
'expected' => '.banner { background: right 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
170252
'input' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
171253
'reversable' => true
172254
]],
173255
[[
174256
'should' => 'Should process string map in url (processUrls:true)',
175-
'expected' => '.banner { background: 10px top url(rtl-top-left-banner.png) #00d repeat-y fixed; }',
257+
'expected' => '.banner { background: right 10px top url(rtl-top-left-banner.png) #00d repeat-y fixed; }',
176258
'input' => '.banner { background: 10px top url(ltr-top-right-banner.png) #00d repeat-y fixed; }',
177259
'reversable' => true,
178260
'options' => [ 'processUrls' => true ],
179261
'skip' => true
180262
]],
181263
[[
182264
'should' => 'Should process string map in url (processUrls:{decl:true})',
183-
'expected' => '.banner { background: 10px top url(rtl-top-left-banner.png) #00d repeat-y fixed; }',
265+
'expected' => '.banner { background: right 10px top url(rtl-top-left-banner.png) #00d repeat-y fixed; }',
184266
'input' => '.banner { background: 10px top url(ltr-top-right-banner.png) #00d repeat-y fixed; }',
185267
'reversable' => true,
186268
'options' => [ 'processUrls' => [ 'decl' => true ] ],
187269
'skip' => true
188270
]],
189271
[[
190272
'should' => 'Should not process string map in url (processUrls:{atrule:true})',
191-
'expected' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
273+
'expected' => '.banner { background: right 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
192274
'input' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
193275
'reversable' => true,
194276
'options' => [ 'processUrls' => [ 'atrule' => true ] ]
195277
]],
196278
[[
197279
'should' => 'Should not swap bright:bleft, ultra:urtla',
198-
'expected' => '.banner { background: 10px top url("ultra/bright.png") #00d repeat-y fixed; }',
280+
'expected' => '.banner { background: right 10px top url("ultra/bright.png") #00d repeat-y fixed; }',
199281
'input' => '.banner { background: 10px top url("ultra/bright.png") #00d repeat-y fixed; }',
200282
'reversable' => true
201283
]],
202284
[[
203285
'should' => 'Should swap bright:bleft, ultra:urtla (processUrls: true, greedy)',
204-
'expected' => '.banner { background: 10px top url("urtla/bleft.png") #00d repeat-y fixed; }',
286+
'expected' => '.banner { background: right 10px top url("urtla/bleft.png") #00d repeat-y fixed; }',
205287
'input' => '.banner { background: 10px top url("ultra/bright.png") #00d repeat-y fixed; }',
206288
'reversable' => true,
207289
'options' => [ 'processUrls' => true, 'greedy' => true ],

0 commit comments

Comments
 (0)