Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Tests for the core_rtlcss class.
19
 *
20
 * The core_rtlcss class extends \MoodleHQ\RTLCSS\RTLCSS library which depends on sabberworm/php-css-parser library.
21
 * This test verifies that css parsing works as expected should any of the above change.
22
 *
23
 * @package    core
24
 * @category   phpunit
25
 * @copyright  2019 Jake Dallimore <jrhdallimore@gmail.com>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
defined('MOODLE_INTERNAL') || die();
29
 
30
use Sabberworm\CSS\Parser;
31
use Sabberworm\CSS\OutputFormat;
32
 
33
/**
34
 * Class rtlcss_test.
35
 */
1441 ariadna 36
final class rtlcss_test extends basic_testcase {
1 efrain 37
    /**
38
     * Data provider.
39
     * @return array
40
     */
1441 ariadna 41
    public static function background_image_provider(): array {
1 efrain 42
        return [
1441 ariadna 43
            // Not supported by MoodleHQ/RTLCSS yet.
1 efrain 44
            [[
45
                'should' => 'Should process string map in url (processUrls:true)',
46
                'expected' => 'div { background-image: url(images/rtl.png), url(images/right.png);}',
47
                'input'    => 'div { background-image: url(images/ltr.png), url(images/left.png);}',
48
                'reversable' => true,
49
                'options' => [ 'processUrls' => true ],
50
                'skip' => true
51
            ]],
52
            [[
53
                'should' => 'Should not negate color value for linear gradient',
54
                'expected' => 'div { background-image: linear-gradient(rgba(255, 255, 255, 0.3) 0%, #ff8 100%);}',
55
                'input'    => 'div { background-image: linear-gradient(rgba(255, 255, 255, 0.3) 0%, #ff8 100%);}',
56
                'reversable' => true,
57
                'skip' => true
58
            ]],
59
            [[
60
                'should' => 'Should not negate color value for linear gradient with calc',
61
                'expected' => 'div { background-image: linear-gradient(rgba(255, 255, calc((125 * 2) + 5), 0.3) 0%, #ff8 100%);}',
62
                'input'    => 'div { background-image: linear-gradient(rgba(255, 255, calc((125 * 2) + 5), 0.3) 0%, #ff8 100%);}',
63
                'reversable' => true,
64
                'skip' => true
65
            ]],
66
            [[
67
                'should' => 'Should negate angle value for linear gradient',
68
                'expected' => 'div { background-image: linear-gradient(13.25deg, rgba(255, 255, 255, .15) 25%, transparent 25%);}',
69
                'input'    => 'div { background-image: linear-gradient(-13.25deg, rgba(255, 255, 255, .15) 25%, transparent 25%);}',
70
                'reversable' => true,
71
                'skip' => true
72
            ]]
73
        ];
74
    }
75
 
76
    /**
77
     * Data provider.
78
     * @return array
79
     */
1441 ariadna 80
    public static function background_position_provider(): array {
1 efrain 81
        return [
82
            [[
83
                'should' => 'Should complement percentage horizontal position ',
84
                'expected' => 'div {background-position:100% 75%;}',
85
                'input' => 'div {background-position:0 75%;}',
86
                'reversable' => false
87
            ]],
88
            /* Not supported by MoodleHQ/RTLCSS yet.
89
            [[
90
                'should' => 'Should complement percentage horizontal position with calc',
91
                'expected' => 'div {background-position:calc(100% - (30% + 50px)) 75%;}',
92
                'input' => 'div {background-position:calc(30% + 50px) 75%;}',
93
                'reversable' => false,
94
                'skip' => true
95
            ]],
96
            [[
97
                'should' => 'Should complement percentage horizontal position ',
98
                'expected' => 'div {background-position:81.25% 75%, 10.75% top;}',
99
                'input' => 'div {background-position:18.75% 75%, 89.25% top;}',
100
                'reversable' => true,
101
                'skip' => true
102
            ]],
103
            [[
104
                'should' => 'Should complement percentage horizontal position with calc',
105
                'expected' => 'div {background-position:calc(100% - (30% + 50px)) calc(30% + 50px), 10.75% top;}',
106
                'input' => 'div {background-position:calc(30% + 50px) calc(30% + 50px), 89.25% top;}',
107
                'reversable' => false,
108
                'skip' => true
109
            ]],
110
            [[
111
                'should' => 'Should swap left with right',
112
                'expected' => 'div {background-position:right 75%, left top;}',
113
                'input' => 'div {background-position:left 75%, right top;}',
114
                'reversable' => true,
115
                'skip' => true
116
            ]],
117
            [[
118
                'should' => 'Should swap left with right wit calc',
119
                'expected' => 'div {background-position:right -ms-calc(30% + 50px), left top;}',
120
                'input' => 'div {background-position:left -ms-calc(30% + 50px), right top;}',
121
                'reversable' => true,
122
                'skip' => true
123
            ]],
124
            */
125
            [[
126
                'should' => 'Should complement percentage: position-x (treat 0 as 0%)',
127
                'expected' => 'div {background-position-x:100%, 0%;}',
128
                'input' => 'div {background-position-x:0, 100%;}',
129
                'reversable' => false
130
            ]],
131
            [[
132
                'should' => 'Should complement percentage: position-x',
133
                'expected' => 'div {background-position-x:81.75%, 11%;}',
134
                'input' => 'div {background-position-x:18.25%, 89%;}',
135
                'reversable' => true
136
            ]],
137
            /* Not supported by MoodleHQ/RTLCSS yet.
138
            [[
139
                'should' => 'Should complement percentage with calc: position-x',
140
                'expected' => 'div {background-position-x:calc(100% - (30% + 50px)), -webkit-calc(100% - (30% + 50px));}',
141
                'input' => 'div {background-position-x:calc(30% + 50px), -webkit-calc(30% + 50px);}',
142
                'reversable' => false,
143
                'skip' => true
144
            ]],
145
            */
146
            [[
147
                'should' => 'Should swap left with right: position-x',
148
                'expected' => 'div {background-position-x:right, left;}',
149
                'input' => 'div {background-position-x:left, right;}',
150
                'reversable' => true
151
            ]],
152
            [[
153
                'should' => 'Should keep as is: position-x',
154
                'expected' => 'div {background-position-x:100px, 0px;}',
155
                'input' => 'div {background-position-x:100px, 0px;}',
156
                'reversable' => true
157
            ]],
158
 
159
            [[
160
                'should' => 'Should flip when using 3 positions',
161
                'expected' => 'div {background-position:center right 1px;}',
162
                'input' => 'div {background-position:center left 1px;}',
163
                'reversable' => true
164
            ]],
165
            [[
166
                'should' => 'Should flip when using 4 positions',
167
                'expected' => 'div {background-position:center 2px right 1px;}',
168
                'input' => 'div {background-position:center 2px left 1px;}',
169
                'reversable' => true
170
            ]],
171
            [[
172
                'should' => 'Should flip when using 4 positions mixed',
173
                'expected' => 'div {background-position:right 2px bottom 1px;}',
174
                'input' => 'div {background-position:left 2px bottom 1px;}',
175
                'reversable' => true
176
            ]]
177
        ];
178
    }
179
 
180
    /**
181
     * Data provider.
182
     * @return array
183
     */
1441 ariadna 184
    public static function background_provider(): array {
1 efrain 185
        return [
186
            [[
187
                'should' => 'Should treat 0 as 0%',
188
                'expected' => '.banner { background: 100% top url("topbanner.png") #00d repeat-y fixed; }',
189
                'input' => '.banner { background: 0 top url("topbanner.png") #00d repeat-y fixed; }',
190
                'reversable' => false
191
            ]],
192
            [[
193
                'should' => 'Should complement percentage horizontal position',
194
                'expected' => '.banner { background: 81% top url("topbanner.png") #00d repeat-y fixed; }',
195
                'input' => '.banner { background: 19% top url("topbanner.png") #00d repeat-y fixed; }',
196
                'reversable' => true
197
            ]],
198
            /* Not supported by MoodleHQ/RTLCSS yet.
199
            [[
200
                'should' => 'Should complement calc horizontal position',
201
                'expected' => '.banner { background: calc(100% - (19% + 2px)) top url(topbanner.png) #00d repeat-y fixed; }',
202
                'input' => '.banner { background: calc(19% + 2px) top url(topbanner.png) #00d repeat-y fixed; }',
203
                'reversable' => false,
204
                'skip' => true
205
            ]],
206
            */
207
            [[
208
                'should' => 'Should mirror keyword horizontal position',
209
                'expected' => '.banner { background: right top url("topbanner.png") #00d repeat-y fixed; }',
210
                'input' => '.banner { background: left top url("topbanner.png") #00d repeat-y fixed; }',
211
                'reversable' => true
212
            ]],
213
            [[
214
                'should' => 'Should not process string map in url (default)',
215
                'expected' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
216
                'input' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
217
                'reversable' => true
218
            ]],
219
            /* Not supported by MoodleHQ/RTLCSS yet.
220
            [[
221
                'should' => 'Should process string map in url (processUrls:true)',
222
                'expected' => '.banner { background: 10px top url(rtl-top-left-banner.png) #00d repeat-y fixed; }',
223
                'input' => '.banner { background: 10px top url(ltr-top-right-banner.png) #00d repeat-y fixed; }',
224
                'reversable' => true,
225
                'options' => [ 'processUrls' => true ],
226
                'skip' => true
227
            ]],
228
            [[
229
                'should' => 'Should process string map in url (processUrls:{decl:true})',
230
                'expected' => '.banner { background: 10px top url(rtl-top-left-banner.png) #00d repeat-y fixed; }',
231
                'input' => '.banner { background: 10px top url(ltr-top-right-banner.png) #00d repeat-y fixed; }',
232
                'reversable' => true,
233
                'options' => [ 'processUrls' => [ 'decl' => true ] ],
234
                'skip' => true
235
            ]],
236
            */
237
            [[
238
                'should' => 'Should not process string map in url (processUrls:{atrule:true})',
239
                'expected' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
240
                'input' => '.banner { background: 10px top url("ltr-top-right-banner.png") #00d repeat-y fixed; }',
241
                'reversable' => true,
242
                'options' => [ 'processUrls' => [ 'atrule' => true ] ]
243
            ]],
244
            [[
245
                'should' => 'Should not swap bright:bleft, ultra:urtla',
246
                'expected' => '.banner { background: 10px top url("ultra/bright.png") #00d repeat-y fixed; }',
247
                'input' => '.banner { background: 10px top url("ultra/bright.png") #00d repeat-y fixed; }',
248
                'reversable' => true
249
            ]],
250
            /* Not supported by MoodleHQ/RTLCSS yet.
251
            [[
252
                'should' => 'Should swap bright:bleft, ultra:urtla (processUrls: true, greedy)',
253
                'expected' => '.banner { background: 10px top url("urtla/bleft.png") #00d repeat-y fixed; }',
254
                'input' => '.banner { background: 10px top url("ultra/bright.png") #00d repeat-y fixed; }',
255
                'reversable' => true,
256
                'options' => [ 'processUrls' => true, 'greedy' => true ],
257
                'skip' => true
258
            ]],
259
            */
260
            [[
261
                'should' => 'Should not flip hex colors ',
262
                'expected' => '.banner { background: #ff0; }',
263
                'input' => '.banner { background: #ff0; }',
264
                'reversable' => true
265
            ]]
266
        ];
267
    }
268
 
269
    /**
270
     * Data provider.
271
     * @return array
272
     */
1441 ariadna 273
    public static function directives_provider(): array {
1 efrain 274
        return [
275
            [[
276
                'should' => 'Should ignore flipping - rule level (default)',
277
                'expected' => 'div {left:10px;text-align:right;}',
278
                'input' => '/*rtl:ignore*/div { left:10px; text-align:right;}',
279
                'reversable' => false
280
            ]],
281
            [[
282
                'should' => 'Should ignore flipping - rule level (!important comment)',
283
                'expected' => 'div {left:10px;text-align:right;}',
284
                'input' => '/*!rtl:ignore*/div { left:10px; text-align:right;}',
285
                'reversable' => false,
286
            ]],
287
            // Not supported by MoodleHQ/RTLCSS yet.
288
            //[[
289
            //    'should' => 'Should ignore flipping - decl. level (default)',
290
            //    'expected' => 'div {left:10px;text-align:left;}',
291
            //    'input' => 'div {left:10px/*rtl:ignore*/;text-align:right;}',
292
            //    'reversable' => false,
293
            //    'skip' => true
294
            //]],
295
            [[
296
                'should' => 'Should add raw css rules',
297
                'expected' => 'div {left:10px;text-align:right;} a {display:block;}',
298
                'input' => '/*rtl:raw: div { left:10px;text-align:right;}*/ a {display:block;}',
299
                'reversable' => false
300
            ]],
301
            [[
302
                'should' => 'Should add raw css declarations',
303
                'expected' => 'div {font-family:"Droid Kufi Arabic";right:10px;text-align:left;}',
304
                'input' => 'div { /*rtl:raw: font-family: "Droid Kufi Arabic";*/ left:10px;text-align:right;}',
305
                'reversable' => false
306
            ]],
307
            [[
308
                'should' => 'Should support block-style',
309
                'expected' => 'div {left:10px;text-align:right;}',
310
                'input' => ' div {/*rtl:begin:ignore*/left:10px;/*rtl:end:ignore*/ text-align:left;}',
311
                'reversable' => false
312
            ]],
313
            [[
314
                'should' => 'Should support none block-style',
315
                'expected' => 'div {left:10px;text-align:left;}',
316
                'input' => ' /*rtl:ignore*/div {left:10px; text-align:left;}',
317
                'reversable' => false
318
            ]],
319
            [[
320
                'should' => 'Should remove rules (block-style)',
321
                'expected' => 'b {float:right;}',
322
                'input' => ' /*rtl:begin:remove*/div {left:10px; text-align:left;} a { display:block;} /*rtl:end:remove*/ b{float:left;}',
323
                'reversable' => false
324
            ]],
325
            [[
326
                'should' => 'Should remove rules',
327
                'expected' => 'a {display:block;} b {float:right;}',
328
                'input' => ' /*rtl:remove*/div {left:10px; text-align:left;} a { display:block;} b{float:left;}',
329
                'reversable' => false
330
            ]],
331
            [[
332
                'should' => 'Should remove declarations',
333
                'expected' => 'div {text-align:right;}',
334
                'input' => 'div {/*rtl:remove*/left:10px; text-align:left;}',
335
                'reversable' => false
336
            ]],
337
            [[
338
                'should' => 'Should remove declarations (block-style)',
339
                'expected' => 'div {display:inline;}',
340
                'input' => 'div {/*rtl:begin:remove*/left:10px; text-align:left;/*rtl:end:remove*/ display:inline;}',
341
                'reversable' => false
342
            ]],
343
            // Not supported by MoodleHQ/RTLCSS yet.
344
            //[[
345
            //    'should' => 'Final/trailing comment ignored bug (block style): note a tag rules are NOT flipped as they should be',
346
            //    'expected' => 'div {left:10px;text-align:left;} a {right:10px;}',
347
            //    'input' => 'div {/*rtl:begin:ignore*/left:10px; text-align:left;/*rtl:end:ignore*/} a {left:10px;}',
348
            //    'reversable' => false,
349
            //    'skip' => true
350
            //]]
351
        ];
352
    }
353
 
354
    /**
355
     * Data provider.
356
     * @return array
357
     */
1441 ariadna 358
    public static function properties_provider(): array {
1 efrain 359
        return [
360
            [[
361
                'should' => 'Should mirror property name: border-top-right-radius',
362
                'expected' => 'div { border-top-left-radius:15px; }',
363
                'input' => 'div { border-top-right-radius:15px; }',
364
                'reversable' => true
365
            ]],
366
            [[
367
                'should' => 'Should mirror property name: border-bottom-right-radius',
368
                'expected' => 'div { border-bottom-left-radius:15px; }',
369
                'input' => 'div { border-bottom-right-radius:15px; }',
370
                'reversable' => true
371
            ]],
372
            [[
373
                'should' => 'Should mirror property name: border-left',
374
                'expected' => 'div { border-right:1px solid black; }',
375
                'input' => 'div { border-left:1px solid black; }',
376
                'reversable' => true
377
            ]],
378
            [[
379
                'should' => 'Should mirror property name: border-left-color',
380
                'expected' => 'div { border-right-color:black; }',
381
                'input' => 'div { border-left-color:black; }',
382
                'reversable' => true
383
            ]],
384
            [[
385
                'should' => 'Should mirror property name: border-left-style',
386
                'expected' => 'div { border-right-style:solid; }',
387
                'input' => 'div { border-left-style:solid; }',
388
                'reversable' => true
389
            ]],
390
            [[
391
                'should' => 'Should mirror property name: border-left-width',
392
                'expected' => 'div { border-right-width:1em; }',
393
                'input' => 'div { border-left-width:1em; }',
394
                'reversable' => true
395
            ]],
396
            [[
397
                'should' => 'Should mirror property name: left',
398
                'expected' => 'div { right:auto; }',
399
                'input' => 'div { left:auto; }',
400
                'reversable' => true
401
            ]],
402
            [[
403
                'should' => 'Should mirror property name: margin-left',
404
                'expected' => 'div { margin-right:2em; }',
405
                'input' => 'div { margin-left:2em; }',
406
                'reversable' => true
407
            ]],
408
            [[
409
                'should' => 'Should mirror property name: padding-left',
410
                'expected' => 'div { padding-right:2em; }',
411
                'input' => 'div { padding-left:2em; }',
412
                'reversable' => true
413
            ]]
414
        ];
415
    }
416
 
417
    /**
418
     * Data provider.
419
     * @return array
420
     */
1441 ariadna 421
    public static function special_provider(): array {
1 efrain 422
        return [
1441 ariadna 423
            // Not supported by MoodleHQ/RTLCSS yet.
1 efrain 424
            [[
425
                'should' => 'Should not negate tokens',
426
                'expected' => 'div { box-shadow: rgba(0, 128, 128, .98) inset -5em 1em 0;}',
427
                'input' => 'div { box-shadow: rgba(0, 128, 128, .98) inset 5em 1em 0;}',
428
                'reversable' => true,
429
                'skip' => true,
430
            ]]
431
        ];
432
    }
433
 
434
    /**
435
     * Data provider.
436
     * @return array
437
     */
1441 ariadna 438
    public static function transform_origin_provider(): array {
1 efrain 439
        return [
440
            [[
441
                'should' => 'Should mirror (x-offset: 0 means 0%)',
442
                'expected' => 'div { transform-origin:100%; }',
443
                'input' => 'div { transform-origin:0; }',
444
                'reversable' => false
445
            ]],
446
            [[
447
                'should' => 'Should mirror (x-offset)',
448
                'expected' => 'div { transform-origin:90.25%; }',
449
                'input' => 'div { transform-origin:9.75%; }',
450
                'reversable' => true
451
            ]],
452
            /* Not supported by MoodleHQ/RTLCSS yet.
453
            [[
454
                'should' => 'Should mirror calc (x-offset)',
455
                'expected' => 'div { transform-origin: -moz-calc(100% - (((25%/2) * 10px))); }',
456
                'input' => 'div { transform-origin: -moz-calc(((25%/2) * 10px)); }',
457
                'reversable' => false,
458
                'skip' => true
459
            ]],
460
            */
461
            [[
462
                'should' => 'Should not mirror (x-offset: not percent, not calc)',
463
                'expected' => 'div { transform-origin:10.75px; }',
464
                'input' => 'div { transform-origin:10.75px; }',
465
                'reversable' => false
466
            ]],
467
            [[
468
                'should' => 'Should mirror (offset-keyword)',
469
                'expected' => 'div { transform-origin:right; }',
470
                'input' => 'div { transform-origin:left; }',
471
                'reversable' => true
472
            ]],
473
            [[
474
                'should' => 'Should mirror (x-offset y-offset: 0 means 0%)',
475
                'expected' => 'div { transform-origin:100% 0; }',
476
                'input' => 'div { transform-origin:0 0; }',
477
                'reversable' => false
478
            ]],
479
            /* Not supported by MoodleHQ/RTLCSS yet.
480
            [[
481
                'should' => 'Should mirror with y being calc (x-offset y-offset: 0 means 0%)',
482
                'expected' => 'div { transform-origin:100% -webkit-calc(15% * (3/2)); }',
483
                'input' => 'div { transform-origin:0 -webkit-calc(15% * (3/2)); }',
484
                'reversable' => false,
485
                'skip' => true
486
            ]],
487
            */
488
            [[
489
                'should' => 'Should mirror percent (x-offset y-offset)',
490
                'expected' => 'div { transform-origin:30.25% 10%; }',
491
                'input' => 'div { transform-origin:69.75% 10%; }',
492
                'reversable' => true
493
            ]],
494
            /* Not supported by MoodleHQ/RTLCSS yet.
495
            [[
496
                'should' => 'Should mirror with x being calc (x-offset y-offset)',
497
                'expected' => 'div { transform-origin: -webkit-calc(100% - (15% * (3/2))) 30.25%; }',
498
                'input' => 'div { transform-origin: -webkit-calc(15% * (3/2)) 30.25%; }',
499
                'reversable' => false,
500
                'skip' => true
501
            ]],
502
            [[
503
                'should' => 'Should mirror with y being calc (x-offset y-offset)',
504
                'expected' => 'div { transform-origin:30.25% calc(15% * (3/2)); }',
505
                'input' => 'div { transform-origin:69.75% calc(15% * (3/2)); }',
506
                'reversable' => true,
507
                'skip' => true
508
            ]],
509
            */
510
            [[
511
                'should' => 'Should mirror (y-offset x-offset-keyword)',
512
                'expected' => 'div { transform-origin:70% right; }',
513
                'input' => 'div { transform-origin:70% left; }',
514
                'reversable' => true
515
            ]],
516
            /* Not supported by MoodleHQ/RTLCSS yet.
517
            [[
518
                'should' => 'Should mirror with calc (y-offset x-offset-keyword)',
519
                'expected' => 'div { transform-origin:-ms-calc(140%/2) right; }',
520
                'input' => 'div { transform-origin:-ms-calc(140%/2) left; }',
521
                'reversable' => true,
522
                'skip' => true
523
            ]],
524
            */
525
            [[
526
                'should' => 'Should mirror (x-offset-keyword y-offset)',
527
                'expected' => 'div { transform-origin:right 70%; }',
528
                'input' => 'div { transform-origin:left 70%; }',
529
                'reversable' => true
530
            ]],
531
            /* Not supported by MoodleHQ/RTLCSS yet.
532
            [[
533
                'should' => 'Should mirror with calc (x-offset-keyword y-offset)',
534
                'expected' => 'div { transform-origin:right -moz-calc(((140%/2))); }',
535
                'input' => 'div { transform-origin:left -moz-calc(((140%/2))); }',
536
                'reversable' => true,
537
                'skip' => true
538
            ]],
539
            */
540
            [[
541
                'should' => 'Should mirror (y-offset-keyword x-offset)',
542
                'expected' => 'div { transform-origin:top 30.25%; }',
543
                'input' => 'div { transform-origin:top 69.75%; }',
544
                'reversable' => true
545
            ]],
546
            /* Not supported by MoodleHQ/RTLCSS yet.
547
            [[
548
                'should' => 'Should not mirror with x being calc (y-offset-keyword x-offset)',
549
                'expected' => 'div { transform-origin:top calc(100% - (((140%/2)))); }',
550
                'input' => 'div { transform-origin:top calc(((140%/2))); }',
551
                'reversable' => false,
552
                'skip' => true
553
            ]],
554
            */
555
            [[
556
                'should' => 'Should mirror (x-offset-keyword y-offset-keyword)',
557
                'expected' => 'div { transform-origin:right top; }',
558
                'input' => 'div { transform-origin:left top; }',
559
                'reversable' => true
560
            ]],
561
            [[
562
                'should' => 'Should mirror (y-offset-keyword x-offset-keyword)',
563
                'expected' => 'div { transform-origin:top right; }',
564
                'input' => 'div { transform-origin:top left; }',
565
                'reversable' => true
566
            ]],
567
            [[
568
                'should' => 'Should mirror (x-offset y-offset z-offset)',
569
                'expected' => 'div { transform-origin:80.25% 30% 10%; }',
570
                'input' => 'div { transform-origin:19.75% 30% 10%; }',
571
                'reversable' => true
572
            ]],
573
            /* Not supported by MoodleHQ/RTLCSS yet.
574
            [[
575
                'should' => 'Should mirror with x being calc (x-offset y-offset z-offset)',
576
                'expected' => 'div { transform-origin: calc(100% - (25% * 3 + 20px)) 30% 10%; }',
577
                'input' => 'div { transform-origin: calc(25% * 3 + 20px) 30% 10%; }',
578
                'reversable' => false,
579
                'skip' => true
580
            ]],
581
            */
582
            [[
583
                'should' => 'Should mirror (y-offset x-offset-keyword z-offset)',
584
                'expected' => 'div { transform-origin:20% right 10%; }',
585
                'input' => 'div { transform-origin:20% left 10%; }',
586
                'reversable' => true
587
            ]],
588
            [[
589
                'should' => 'Should mirror (x-offset-keyword y-offset z-offset)',
590
                'expected' => 'div { transform-origin:left 20% 10%; }',
591
                'input' => 'div { transform-origin:right 20% 10%; }',
592
                'reversable' => true
593
            ]],
594
            [[
595
                'should' => 'Should mirror (x-offset-keyword y-offset-keyword z-offset)',
596
                'expected' => 'div { transform-origin:left bottom 10%; }',
597
                'input' => 'div { transform-origin:right bottom 10%; }',
598
                'reversable' => true
599
            ]],
600
            [[
601
                'should' => 'Should mirror (y-offset-keyword x-offset-keyword z-offset)',
602
                'expected' => 'div { transform-origin:bottom left 10%; }',
603
                'input' => 'div { transform-origin:bottom right 10%; }',
604
                'reversable' => true
605
            ]]
606
        ];
607
    }
608
 
609
    /**
610
     * Data provider.
611
     * @return array
612
     */
1441 ariadna 613
    public static function transforms_provider(): array {
1 efrain 614
        return [
1441 ariadna 615
            // Not supported by MoodleHQ/RTLCSS yet.
1 efrain 616
            [[
617
                'should' => 'Should mirror transform : matrix',
618
                'expected' => 'div { transform: matrix(2, 0.1, 20.75, 2, 2, 2); }',
619
                'input' => 'div { transform: matrix(2, -0.1, -20.75, 2, -2, 2); }',
620
                'reversable' => true,
621
                'skip' => true
622
            ]],
623
            [[
624
                'should' => 'Should mirror transform (with no digits before dot): matrix',
625
                'expected' => 'div { transform: matrix(2, 0.1, 0.75, 2, 2, 2); }',
626
                'input' => 'div { transform: matrix(2, -0.1, -.75, 2, -2, 2); }',
627
                'reversable' => false,
628
                'skip' => true
629
            ]],
630
            [[
631
                'should' => 'Should mirror transform with calc: matrix',
632
                'expected' => 'div { transform: matrix( -moz-calc(((25%/2) * 10px)), calc(-1*(((25%/2) * 10px))), 20.75, 2, 2, 2 ); }',
633
                'input' => 'div { transform: matrix( -moz-calc(((25%/2) * 10px)), calc(((25%/2) * 10px)), -20.75, 2, -2, 2 ); }',
634
                'reversable' => false,
635
                'skip' => true
636
            ]],
637
            [[
638
                'should' => 'Should mirror transform : matrix3d',
639
                'expected' => 'div { transform:matrix3d(0.227114470162179, 0.127248412323519, 0, 0.000811630714323203, 0.113139853456515, 1.53997196559414, 0, 0.000596368270149729, 0, 0, 1, 0, -165, 67, 0, 1); }',
640
                'input' => 'div { transform:matrix3d(0.227114470162179, -0.127248412323519, 0, -0.000811630714323203, -0.113139853456515, 1.53997196559414, 0, 0.000596368270149729, 0, 0, 1, 0, 165, 67, 0, 1); }',
641
                'reversable' => true,
642
                'skip' => true
643
            ]],
644
            [[
645
                'should' => 'Should mirror transform (with no digits before dot): matrix3d',
646
                'expected' => 'div { transform:matrix3d(0.227114470162179, 0.127248412323519, 0, 0.000811630714323203, 0.113139853456515, 1.53997196559414, 0, 0.000596368270149729, 0, 0, 1, 0, -165, 67, 0, 1); }',
647
                'input' => 'div { transform:matrix3d(0.227114470162179, -.127248412323519, 0, -0.000811630714323203, -0.113139853456515, 1.53997196559414, 0, 0.000596368270149729, 0, 0, 1, 0, 165, 67, 0, 1); }',
648
                'reversable' => false,
649
                'skip' => true
650
            ]],
651
            [[
652
                'should' => 'Should mirror transform with calc : matrix3d',
653
                'expected' => 'div { transform:matrix3d(0.227114470162179, 0.127248412323519, 0, 0.000811630714323203, 0.113139853456515, 1.53997196559414, 0, 0.000596368270149729, 0, 0, 1, 0, calc(-1*(((25%/2) * 10px))), 67, 0, 1); }',
654
                'input' => 'div { transform:matrix3d(0.227114470162179, -0.127248412323519, 0, -0.000811630714323203, -0.113139853456515, 1.53997196559414, 0, 0.000596368270149729, 0, 0, 1, 0, calc(((25%/2) * 10px)), 67, 0, 1); }',
655
                'reversable' => false,
656
                'skip' => true
657
            ]],
658
            [[
659
                'should' => 'Should mirror transform : translate',
660
                'expected' => 'div { transform: translate(-10.75px); }',
661
                'input' => 'div { transform: translate(10.75px); }',
662
                'reversable' => true,
663
                'skip' => true
664
            ]],
665
            [[
666
                'should' => 'Should mirror transform (with no digits before dot): translate',
667
                'expected' => 'div { transform: translate(-0.75px); }',
668
                'input' => 'div { transform: translate(.75px); }',
669
                'reversable' => false,
670
                'skip' => true
671
            ]],
672
            [[
673
                'should' => 'Should mirror transform with calc: translate',
674
                'expected' => 'div { transform: translate(-moz-calc(-1*(((25%/2) * 10px)))); }',
675
                'input' => 'div { transform: translate(-moz-calc(((25%/2) * 10px))); }',
676
                'reversable' => false,
677
                'skip' => true
678
            ]],
679
            [[
680
                'should' => 'Should mirror transform : translateX',
681
                'expected' => 'div { transform: translateX(-50.25px); }',
682
                'input' => 'div { transform: translateX(50.25px); }',
683
                'reversable' => true,
684
                'skip' => true
685
            ]],
686
            [[
687
                'should' => 'Should mirror transform (with no digits before dot): translateX',
688
                'expected' => 'div { transform: translateX(-0.25px); }',
689
                'input' => 'div { transform: translateX(.25px); }',
690
                'reversable' => false,
691
                'skip' => true
692
            ]],
693
            [[
694
                'should' => 'Should mirror transform with calc : translateX',
695
                'expected' => 'div { transform: translateX(-ms-calc(-1*(((25%/2) * 10px))))); }',
696
                'input' => 'div { transform: translateX(-ms-calc(((25%/2) * 10px)))); }',
697
                'reversable' => false,
698
                'skip' => true
699
            ]],
700
            [[
701
                'should' => 'Should mirror transform : translate3d',
702
                'expected' => 'div { transform: translate3d(-12.75px, 50%, 3em); }',
703
                'input' => 'div { transform: translate3d(12.75px, 50%, 3em); }',
704
                'reversable' => true,
705
                'skip' => true
706
            ]],
707
            [[
708
                'should' => 'Should mirror transform (with no digits before dot): translate3d',
709
                'expected' => 'div { transform: translate3d(-0.75px, 50%, 3em); }',
710
                'input' => 'div { transform: translate3d(.75px, 50%, 3em); }',
711
                'reversable' => false,
712
                'skip' => true
713
            ]],
714
            [[
715
                'should' => 'Should mirror transform with calc: translate3d',
716
                'expected' => 'div { transform: translate3d(-webkit-calc(-1*(((25%/2) * 10px))))), 50%, calc(((25%/2) * 10px))))); }',
717
                'input' => 'div { transform: translate3d(-webkit-calc(((25%/2) * 10px)))), 50%, calc(((25%/2) * 10px))))); }',
718
                'reversable' => false,
719
                'skip' => true
720
            ]],
721
            [[
722
                'should' => 'Should mirror transform : rotate',
723
                'expected' => 'div { transform: rotate(-20.75deg); }',
724
                'input' => 'div { transform: rotate(20.75deg); }',
725
                'reversable' => true,
726
                'skip' => true
727
            ]],
728
            [[
729
                'should' => 'Should mirror transform (with no digits before dot): rotate',
730
                'expected' => 'div { transform: rotate(-0.75deg); }',
731
                'input' => 'div { transform: rotate(.75deg); }',
732
                'reversable' => false,
733
                'skip' => true
734
            ]],
735
            [[
736
                'should' => 'Should mirror transform with calc: rotate',
737
                'expected' => 'div { transform: rotate(calc(-1*(((25%/2) * 10deg)))); }',
738
                'input' => 'div { transform: rotate(calc(((25%/2) * 10deg))); }',
739
                'reversable' => false,
740
                'skip' => true
741
            ]],
742
            [[
743
                'should' => 'Should mirror transform : rotate3d',
744
                'expected' => 'div { transform: rotate3d(10, -20.15, 10, -45.14deg); }',
745
                'input' => 'div { transform: rotate3d(10, 20.15, 10, 45.14deg); }',
746
                'reversable' => true,
747
                'skip' => true
748
            ]],
749
            [[
750
                'should' => 'Should mirror transform (with no digits before dot): rotate3d',
751
                'expected' => 'div { transform: rotate3d(10, -20, 10, -0.14deg); }',
752
                'input' => 'div { transform: rotate3d(10, 20, 10, .14deg); }',
753
                'reversable' => false,
754
                'skip' => true
755
            ]],
756
            [[
757
                'should' => 'Should mirror transform with calc: rotate3d',
758
                'expected' => 'div { transform: rotate3d(10, -20.15, 10, calc(-1*(((25%/2) * 10deg)))); }',
759
                'input' => 'div { transform: rotate3d(10, 20.15, 10, calc(((25%/2) * 10deg))); }',
760
                'reversable' => false,
761
                'skip' => true
762
            ]],
763
            [[
764
                'should' => 'Should not mirror transform : rotateX',
765
                'expected' => 'div { transform: rotateX(45deg); }',
766
                'input' => 'div { transform: rotateX(45deg); }',
767
                'reversable' => false,
768
                'skip' => true
769
            ]],
770
            [[
771
                'should' => 'Should not mirror transform with calc: rotateX',
772
                'expected' => 'div { transform: rotateX(calc(((25%/2) * 10deg))); }',
773
                'input' => 'div { transform: rotateX(calc(((25%/2) * 10deg))); }',
774
                'reversable' => false,
775
                'skip' => true
776
            ]],
777
            [[
778
                'should' => 'Should not mirror transform : rotateY',
779
                'expected' => 'div { transform: rotateY(45deg); }',
780
                'input' => 'div { transform: rotateY(45deg); }',
781
                'reversable' => false,
782
                'skip' => true
783
            ]],
784
            [[
785
                'should' => 'Should not mirror transform with calc: rotateY',
786
                'expected' => 'div { transform: rotateY(calc(((25%/2) * 10deg))); }',
787
                'input' => 'div { transform: rotateY(calc(((25%/2) * 10deg))); }',
788
                'reversable' => false,
789
                'skip' => true
790
            ]],
791
            [[
792
                'should' => 'Should mirror transform : rotateZ',
793
                'expected' => 'div { transform: rotateZ(-45.75deg); }',
794
                'input' => 'div { transform: rotateZ(45.75deg); }',
795
                'reversable' => true,
796
                'skip' => true
797
            ]],
798
            [[
799
                'should' => 'Should mirror transform (with no digits before dot): rotateZ',
800
                'expected' => 'div { transform: rotateZ(-0.75deg); }',
801
                'input' => 'div { transform: rotateZ(.75deg); }',
802
                'reversable' => false,
803
                'skip' => true
804
            ]],
805
            [[
806
                'should' => 'Should mirror transform with calc: rotateZ',
807
                'expected' => 'div { transform: rotateZ(-ms-calc(-1*(((25%/2) * 10deg)))); }',
808
                'input' => 'div { transform: rotateZ(-ms-calc(((25%/2) * 10deg))); }',
809
                'reversable' => false,
810
                'skip' => true
811
            ]],
812
            [[
813
                'should' => 'Should mirror transform : skew',
814
                'expected' => 'div { transform: skew(-20.25rad,-30deg); }',
815
                'input' => 'div { transform: skew(20.25rad,30deg); }',
816
                'reversable' => true,
817
                'skip' => true
818
            ]],
819
            [[
820
                'should' => 'Should mirror transform (with no digits before dot): skew',
821
                'expected' => 'div { transform: skew(-0.25rad,-30deg); }',
822
                'input' => 'div { transform: skew(.25rad,30deg); }',
823
                'reversable' => false,
824
                'skip' => true
825
            ]],
826
            [[
827
                'should' => 'Should mirror transform with calc: skew',
828
                'expected' => 'div { transform: skew(calc(-1*(((25%/2) * 10rad))),calc(-1*(((25%/2) * 10deg)))); }',
829
                'input' => 'div { transform: skew(calc(((25%/2) * 10rad)),calc(((25%/2) * 10deg))); }',
830
                'reversable' => false,
831
                'skip' => true
832
            ]],
833
            [[
834
                'should' => 'Should mirror transform : skewX',
835
                'expected' => 'div { transform: skewX(-20.75rad); }',
836
                'input' => 'div { transform: skewX(20.75rad); }',
837
                'reversable' => true,
838
                'skip' => true
839
            ]],
840
            [[
841
                'should' => 'Should mirror transform (with no digits before dot): skewX',
842
                'expected' => 'div { transform: skewX(-0.75rad); }',
843
                'input' => 'div { transform: skewX(.75rad); }',
844
                'reversable' => false,
845
                'skip' => true
846
            ]],
847
            [[
848
                'should' => 'Should mirror transform with calc: skewX',
849
                'expected' => 'div { transform: skewX(-moz-calc(-1*(((25%/2) * 10rad)))); }',
850
                'input' => 'div { transform: skewX(-moz-calc(((25%/2) * 10rad))); }',
851
                'reversable' => false,
852
                'skip' => true
853
            ]],
854
            [[
855
                'should' => 'Should mirror transform : skewY',
856
                'expected' => 'div { transform: skewY(-10.75grad); }',
857
                'input' => 'div { transform: skewY(10.75grad); }',
858
                'reversable' => true,
859
                'skip' => true
860
            ]],
861
            [[
862
                'should' => 'Should mirror transform (with no digits before dot): skewY',
863
                'expected' => 'div { transform: skewY(-0.75grad); }',
864
                'input' => 'div { transform: skewY(.75grad); }',
865
                'reversable' => false,
866
                'skip' => true
867
            ]],
868
            [[
869
                'should' => 'Should mirror transform with calc: skewY',
870
                'expected' => 'div { transform: skewY(calc(-1*(((25%/2) * 10grad)))); }',
871
                'input' => 'div { transform: skewY(calc(((25%/2) * 10grad))); }',
872
                'reversable' => false,
873
                'skip' => true
874
            ]],
875
            [[
876
                'should' => 'Should mirror multiple transforms : translateX translateY Rotate',
877
                'expected' => 'div { transform: translateX(-50.25px) translateY(50.25px) rotate(-20.75deg); }',
878
                'input' => 'div { transform: translateX(50.25px) translateY(50.25px) rotate(20.75deg); }',
879
                'reversable' => true,
880
                'skip' => true
881
            ]],
882
            [[
883
                'should' => 'Should mirror multiple transforms with calc : translateX translateY Rotate',
884
                'expected' => 'div { transform: translateX(-ms-calc(-1*(((25%/2) * 10px)))) translateY(-moz-calc(((25%/2) * 10rad))) rotate(calc(-1*(((25%/2) * 10grad)))); }',
885
                'input' => 'div { transform: translateX(-ms-calc(((25%/2) * 10px))) translateY(-moz-calc(((25%/2) * 10rad))) rotate(calc(((25%/2) * 10grad))); }',
886
                'reversable' => false,
887
                'skip' => true
888
            ]]
889
        ];
890
    }
891
 
892
    /**
893
     * Data provider.
894
     * @return array
895
     */
1441 ariadna 896
    public static function values_nsyntax_provider(): array {
1 efrain 897
        return [
898
            [[
899
                'should' => 'Should mirror property value: border-radius (4 values)',
900
                'expected' => 'div { border-radius: 40.25px 10.5px 10.75px 40.3px; }',
901
                'input' => 'div { border-radius: 10.5px 40.25px 40.3px 10.75px; }',
902
                'reversable' => true
903
            ]],
904
            [[
905
                'should' => 'Should mirror property value: border-radius (3 values)',
906
                'expected' => 'div { border-radius: 40.75px 10.75px 40.75px 40.3px; }',
907
                'input' => 'div { border-radius: 10.75px 40.75px 40.3px; }',
908
                'reversable' => false
909
            ]],
910
            [[
911
                'should' => 'Should mirror property value: border-radius (2 values)',
912
                'expected' => 'div { border-radius: 40.25px 10.75px; }',
913
                'input' => 'div { border-radius: 10.75px 40.25px; }',
914
                'reversable' => true
915
            ]],
916
            /* Not supported by MoodleHQ/RTLCSS yet.
917
            [[
918
                'should' => 'Should mirror property value: border-radius (4 values - double)',
919
                'expected' => 'div { border-radius: 40.25px 10.75px .5px 40.75px / .4em 1em 1em 4.5em; }',
920
                'input' => 'div { border-radius: 10.75px 40.25px 40.75px .5px / 1em .4em 4.5em 1em; }',
921
                'reversable' => true,
922
                'skip' => true
923
            ]],
924
            [[
925
                'should' => 'Should mirror property value: border-radius (3 values - double)',
926
                'expected' => 'div { border-radius: .40px 10.5px .40px 40px / 4em 1em 4em 3em; }',
927
                'input' => 'div { border-radius: 10.5px .40px 40px / 1em 4em 3em; }',
928
                'reversable' => false,
929
                'skip' => true
930
            ]],
931
            [[
932
                'should' => 'Should mirror property value: border-radius (2 values- double)',
933
                'expected' => 'div { border-radius: 40px 10px / 2.5em .75em; }',
934
                'input' => 'div { border-radius: 10px 40px / .75em 2.5em; }',
935
                'reversable' => true,
936
                'skip' => true
937
            ]],
938
            */
939
            [[
940
                'should' => 'Should mirror property value: border-width',
941
                'expected' => 'div { border-width: 1px 4px .3em 2.5em; }',
942
                'input' => 'div { border-width: 1px 2.5em .3em 4px; }',
943
                'reversable' => true
944
            ]],
945
            [[
946
                'should' => 'Should mirror property value: border-width (none length)',
947
                'expected' => 'div { border-width: thin medium thick none; }',
948
                'input' => 'div { border-width: thin none thick medium; }',
949
                'reversable' => true
950
            ]],
951
            [[
952
                'should' => 'Should mirror property value: border-style (4 values)',
953
                'expected' => 'div { border-style: none dashed dotted solid; }',
954
                'input' => 'div { border-style: none solid dotted dashed; }',
955
                'reversable' => true
956
            ]],
957
            [[
958
                'should' => 'Should mirror property value: border-color (4 values)',
959
                'expected' => 'div { border-color: rgba(255, 255, 255, 1) rgb(0, 0, 0) rgb(0, 0, 0) hsla(0, 100%, 50%, 1); }',
960
                'input' => 'div { border-color: rgba(255, 255, 255, 1) hsla(0, 100%, 50%, 1) rgb(0, 0, 0) rgb(0, 0, 0); }',
961
                'reversable' => true
962
            ]],
963
            [[
964
                'should' => 'Should not mirror property value: border-color (3 values)',
965
                'expected' => 'div { border-color: rgb(0, 0, 0) rgb(0, 0, 0) hsla(0, 100%, 50%, 1); }',
966
                'input' => 'div { border-color: #000 rgb(0, 0, 0) hsla(0, 100%, 50%, 1); }',
967
                'reversable' => false
968
            ]],
969
            [[
970
                'should' => 'Should not mirror property value: border-color (2 values)',
971
                'expected' => 'div { border-color: rgb(0, 0, 0) hsla(0, 100%, 50%, 1); }',
972
                'input' => 'div { border-color: rgb(0, 0, 0) hsla(0, 100%, 50%, 1); }',
973
                'reversable' => false
974
            ]],
975
            [[
976
                'should' => 'Should mirror property value: margin',
977
                'expected' => 'div { margin: .1em auto 3.5rem 2px; }',
978
                'input' => 'div { margin: .1em 2px 3.5rem auto; }',
979
                'reversable' => true
980
            ]],
981
            [[
982
                'should' => 'Should mirror property value: padding',
983
                'expected' => 'div { padding: 1px 4px .3rem 2.5em; }',
984
                'input' => 'div { padding: 1px 2.5em .3rem 4px; }',
985
                'reversable' => true
986
            ]],
987
            /* Not supported by MoodleHQ/RTLCSS yet.
988
            [[
989
                'should' => 'Should mirror property value: box-shadow',
990
                'expected' => 'div { box-shadow: -60px -16px rgba(0, 128, 128, 0.98), -10.25px 5px 5px #ff0, inset -0.5em 1em 0 white; }',
991
                'input' => 'div { box-shadow: 60px -16px rgba(0, 128, 128, 0.98), 10.25px 5px 5px #ff0, inset 0.5em 1em 0 white; }',
992
                'reversable' => true,
993
                'skip' => true
994
            ]],
995
            [[
996
                'should' => 'Should mirror property value: text-shadow',
997
                'expected' => 'div { text-shadow: -60px -16px rgba(0, 128, 128, 0.98), -10.25px 5px 5px #ff0, inset -0.5em 1em 0 white; }',
998
                'input' => 'div { text-shadow: 60px -16px rgba(0, 128, 128, 0.98), 10.25px 5px 5px #ff0, inset 0.5em 1em 0 white; }',
999
                'reversable' => true,
1000
                'skip' => true
1001
            ]],
1002
            [[
1003
                'should' => 'Should mirror property value (no digit before the dot): box-shadow, text-shadow',
1004
                'expected' => 'div { box-shadow: inset -0.5em 1em 0 white; text-shadow: inset -0.5em 1em 0 white; }',
1005
                'input' => 'div { box-shadow: inset .5em 1em 0 white; text-shadow: inset .5em 1em 0 white; }',
1006
                'reversable' => false,
1007
                'skip' => true
1008
            ]]
1009
            */
1010
        ];
1011
    }
1012
 
1013
    /**
1014
     * Data provider.
1015
     * @return array
1016
     */
1441 ariadna 1017
    public static function values_provider(): array {
1 efrain 1018
        return [
1019
            [[
1020
                'should' => 'Should mirror property value: clear',
1021
                'expected' => 'div { clear:right; }',
1022
                'input' => 'div { clear:left; }',
1023
                'reversable' => true
1024
            ]],
1025
            [[
1026
                'should' => 'Should mirror property value: direction',
1027
                'expected' => 'div { direction:ltr; }',
1028
                'input' => 'div { direction:rtl; }',
1029
                'reversable' => true
1030
            ]],
1031
            [[
1032
                'should' => 'Should mirror property value: float',
1033
                'expected' => 'div { float:right; }',
1034
                'input' => 'div { float:left; }',
1035
                'reversable' => true
1036
            ]],
1037
            [[
1038
                'should' => 'Should mirror property value: text-align',
1039
                'expected' => 'div { text-align:right; }',
1040
                'input' => 'div { text-align:left; }',
1041
                'reversable' => true
1042
            ]],
1043
            [[
1044
                'should' => 'Should mirror property value: cursor nw',
1045
                'expected' => 'div { cursor:nw-resize; }',
1046
                'input' => 'div { cursor:ne-resize; }',
1047
                'reversable' => true
1048
            ]],
1049
            [[
1050
                'should' => 'Should mirror property value: cursor sw',
1051
                'expected' => 'div { cursor:sw-resize; }',
1052
                'input' => 'div { cursor:se-resize; }',
1053
                'reversable' => true
1054
            ]],
1055
            [[
1056
                'should' => 'Should mirror property value: cursor nesw',
1057
                'expected' => 'div { cursor:nesw-resize; }',
1058
                'input' => 'div { cursor:nwse-resize; }',
1059
                'reversable' => true
1060
            ]],
1061
            [[
1062
                'should' => 'Should keep property value as is: cursor ew',
1063
                'expected' => 'div { cursor:ew-resize; }',
1064
                'input' => 'div { cursor:ew-resize; }',
1065
                'reversable' => false
1066
            ]],
1067
            /* Not supported by MoodleHQ/RTLCSS yet.
1068
            [[
1069
                'should' => 'Should process string map in url: cursor (processUrls: true)',
1070
                'expected' => '.foo { cursor: url(right.cur), url(rtl.cur), se-resize, auto }',
1071
                'input' => '.foo { cursor: url(left.cur), url(ltr.cur), sw-resize, auto }',
1072
                'reversable' => true,
1073
                'options' => [ 'processUrls' => true ],
1074
                'skip' => true
1075
            ]],
1076
            */
1077
            [[
1078
                'should' => 'Should mirror property value: transition',
1079
                'expected' => '.foo { transition:right .3s ease .1s,left .3s ease .1s,margin-right .3s ease,margin-left .3s ease,padding-right .3s ease,padding-left .3s ease; }',
1080
                'input' => '.foo { transition:left .3s ease .1s,right .3s ease .1s,margin-left .3s ease,margin-right .3s ease,padding-left .3s ease,padding-right .3s ease; }',
1081
                'reversable' => true
1082
            ]],
1083
            [[
1084
                'should' => 'Should mirror property value: transition-property',
1085
                'expected' => '.foo { transition-property:right; }',
1086
                'input' => '.foo { transition-property:left; }',
1087
                'reversable' => true
1088
            ]]
1089
        ];
1090
    }
1091
 
1092
    /**
1093
     * Assert that the provided data flips.
1094
     *
1095
     * @param string $expected The expected output.
1096
     * @param string $input The input.
1097
     * @param string $description The description of the assertion.
1098
     * @param OutputFormat $output The output format to use.
1099
     */
1100
    protected function assert_flips($expected, $input, $description, $output = null) {
1101
        $parser = new Parser($input);
1102
        $tree = $parser->parse();
1103
        $rtlcss = new core_rtlcss($tree);
1104
        $flipped = $rtlcss->flip();
1105
        $this->assertEquals($expected, $flipped->render($output), $description);
1106
    }
1107
 
1108
    /**
1109
     * Assert data.
1110
     *
1111
     * @param array $data With the keys: 'input', 'expected', 'reversable', 'should', and 'skip'.
1112
     * @param OutputFormat $output The output format to use.
1113
     */
1114
    protected function assert_sample($data, $output = null) {
1115
        if (!empty($data['skip'])) {
1116
            $this->markTestSkipped('Not yet supported!');
1117
        }
1118
        $this->assert_flips($data['expected'], $data['input'], $data['should'], $output);
1119
        if (!empty($data['reversable'])) {
1120
            $this->assert_flips($data['input'], $data['expected'], $data['should'] . ' (reversed)', $output);
1121
        }
1122
    }
1123
 
1124
    /**
1125
     * Test background images.
1126
     * @param array $data the provider data.
1127
     * @dataProvider background_image_provider
1128
     */
11 efrain 1129
    public function test_background_image($data): void {
1 efrain 1130
        $this->markTestSkipped('Not yet supported!');
1131
        $output = new OutputFormat();
1132
        $this->assert_sample($data, $output);
1133
    }
1134
 
1135
    /**
1136
     * Test background position.
1137
     * @param array $data the provider data.
1138
     * @dataProvider background_position_provider
1139
     */
11 efrain 1140
    public function test_background_position($data): void {
1 efrain 1141
        $output = new OutputFormat();
1142
        $output->set('SpaceAfterRuleName', '');
1143
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1144
        $this->assert_sample($data, $output);
1145
    }
1146
 
1147
    /**
1148
     * Test background.
1149
     * @param array $data the provider data.
1150
     * @dataProvider background_provider
1151
     */
11 efrain 1152
    public function test_background($data): void {
1 efrain 1153
        $output = new OutputFormat();
1154
        $output->set('SpaceAfterRuleName', ' ');
1155
        $output->set('SpaceBeforeRules', ' ');
1156
        $output->set('SpaceAfterRules', ' ');
1157
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1158
        $this->assert_sample($data, $output);
1159
    }
1160
 
1161
    /**
1162
     * Test directives.
1163
     * @param array $data the provider data.
1164
     * @dataProvider directives_provider
1165
     */
11 efrain 1166
    public function test_directives($data): void {
1 efrain 1167
        $output = new OutputFormat();
1168
        $output->set('SpaceAfterRuleName', '');
1169
        $output->set('SpaceBeforeRules', '');
1170
        $output->set('SpaceAfterRules', '');
1171
        $output->set('SpaceBetweenRules', '');
1172
        $output->set('SpaceBetweenBlocks', ' ');
1173
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1174
        $this->assert_sample($data, $output);
1175
    }
1176
 
1177
    /**
1178
     * Test properties.
1179
     * @param array $data the provider data.
1180
     * @dataProvider properties_provider
1181
     */
11 efrain 1182
    public function test_properties($data): void {
1 efrain 1183
        $output = new OutputFormat();
1184
        $output->set('SpaceAfterRuleName', '');
1185
        $output->set('SpaceBeforeRules', ' ');
1186
        $output->set('SpaceAfterRules', ' ');
1187
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1188
        $this->assert_sample($data, $output);
1189
    }
1190
 
1191
    /**
1192
     * Test special.
1193
     * @param array $data the provider data.
1194
     * @dataProvider special_provider
1195
     */
11 efrain 1196
    public function test_special($data): void {
1 efrain 1197
        $this->markTestSkipped('Not yet supported!');
1198
        $output = new OutputFormat();
1199
        $output->set('SpaceBeforeRules', ' ');
1200
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1201
        $this->assert_sample($data, $output);
1202
    }
1203
 
1204
    /**
1205
     * Test transform original.
1206
     * @param array $data the provider data.
1207
     * @dataProvider transform_origin_provider
1208
     */
11 efrain 1209
    public function test_transform_origin($data): void {
1 efrain 1210
        $output = new OutputFormat();
1211
        $output->set('SpaceAfterRuleName', '');
1212
        $output->set('SpaceBeforeRules', ' ');
1213
        $output->set('SpaceAfterRules', ' ');
1214
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1215
        $this->assert_sample($data, $output);
1216
    }
1217
 
1218
 
1219
    /**
1220
     * Test transform.
1221
     * @param array $data the provider data.
1222
     * @dataProvider transforms_provider
1223
     */
11 efrain 1224
    public function test_transforms($data): void {
1 efrain 1225
        $this->markTestSkipped('Not yet supported!');
1226
        $output = new OutputFormat();
1227
        $output->set('SpaceBeforeRules', ' ');
1228
        $output->set('SpaceAfterRules', ' ');
1229
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1230
        $this->assert_sample($data, $output);
1231
    }
1232
 
1233
    /**
1234
     * Test values n-syntax.
1235
     * @param array $data the provider data.
1236
     * @dataProvider values_nsyntax_provider
1237
     */
11 efrain 1238
    public function test_values_nsyntax($data): void {
1 efrain 1239
        $output = new OutputFormat();
1240
        $output->set('SpaceBeforeRules', ' ');
1241
        $output->set('SpaceAfterRules', ' ');
1242
        $output->set('RGBHashNotation', false);
1243
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1244
        $this->assert_sample($data, $output);
1245
    }
1246
 
1247
    /**
1248
     * Test values.
1249
     * @param array $data the provider data.
1250
     * @dataProvider values_provider
1251
     */
11 efrain 1252
    public function test_values($data): void {
1 efrain 1253
        $output = new OutputFormat();
1254
        $output->set('SpaceAfterRuleName', '');
1255
        $output->set('SpaceBeforeRules', ' ');
1256
        $output->set('SpaceAfterRules', ' ');
1257
        $output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
1258
        $this->assert_sample($data, $output);
1259
    }
1260
}