TYPO3 CMS  TYPO3_7-6
EvaluateDisplayConditionsTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
30  protected $subject;
31 
32  protected function setUp()
33  {
34  $this->subject = new EvaluateDisplayConditions();
35  }
36 
41  {
42  $input = [
43  'databaseRow' => [
44  'aField' => 'aField',
45  'bField' => 'bField',
46  'cField' => 1,
47  ],
48  'recordTypeValue' => 'aType',
49  'processedTca' => [
50  'types' => [
51  'aType' => [
52  'showitem' => '--palette--;aPalette;2,bField,cField'
53  ],
54  ],
55  'palettes' => [
56  '2' => [
57  'showitem' => 'aField',
58  ],
59  ],
60  'columns' => [
61  'aField' => [
62  'displayCond' => 'FIELD:cField:=:0',
63  'config' => [
64  'type' => 'input',
65  ]
66  ],
67  'bField' => [
68  'displayCond' => 'FIELD:cField:=:1',
69  'config' => [
70  'type' => 'input',
71  ]
72  ],
73  'cField' => [
74  'config' => [
75  'type' => 'input',
76  ]
77  ]
78  ]
79  ]
80  ];
81 
82  $expected = $input;
83  unset($expected['processedTca']['columns']['aField']);
84 
85  $this->assertSame($expected, $this->subject->addData($input));
86  }
87 
92  {
93  $input = [
94  'databaseRow' => [
95  'aField' => [
96  'data' => [
97  'sGeneral' => [
98  'lDEF' => [
99  'mmType' => [
100  'vDEF' => [
101  0 => 'video',
102  ],
103  ],
104  'mmUseHTML5' => [
105  'vDEF' => '0',
106  ],
107  ],
108  ],
109  'sVideo' => [
110  'lDEF' => [],
111  ],
112  'sAudio' => [
113  'lDEF' => []
114  ],
115  ]
116  ]
117  ],
118  'processedTca' => [
119  'columns' => [
120  'aField' => [
121  'config' => [
122  'type' => 'flex',
123  'ds' => [
124  'meta' => [],
125  'sheets' => [
126  'sGeneral' => [
127  'ROOT' => [
128  'type' => 'array',
129  'el' => [
130  'mmType' => [
131  'config' => [
132  'type' => 'select',
133  'items' => [],
134  ],
135  ],
136  'mmUseHTML5' => [
137  'displayCond' => 'FIELD:mmType:!=:audio',
138  'config' => [
139  'type' => 'check',
140  'default' => '0',
141  'items' => [],
142  ],
143  ],
144  ],
145  'sheetTitle' => 'sGeneral',
146  ],
147  ],
148  'sVideo' => [
149  'ROOT' => [
150  'type' => 'array',
151  'el' => [],
152  'sheetTitle' => 'sVideo',
153  'displayCond' => 'FIELD:sGeneral.mmType:!=:audio',
154  ],
155  ],
156  'sAudio' => [
157  'ROOT' => [
158  'type' => 'array',
159  'el' => [],
160  'sheetTitle' => 'sAudio',
161  'displayCond' => 'FIELD:sGeneral.mmType:=:audio',
162  ],
163  ],
164  ],
165  ],
166  ],
167  ],
168  ],
169  ],
170  ];
171 
172  $expected = $input;
173  unset($expected['processedTca']['columns']['aField']['config']['ds']['sheets']['sAudio']);
174  $this->assertSame($expected, $this->subject->addData($input));
175  }
176 
181  {
182  $input = [
183  'databaseRow' => [
184  'aField' => [
185  'data' => [
186  'sGeneral' => [
187  'lDEF' => [
188  'mmType' => [
189  'vDEF' => [
190  0 => 'audio',
191  ],
192  ],
193  'mmUseHTML5' => [
194  'vDEF' => '0',
195  ],
196  ],
197  ],
198  ]
199  ]
200  ],
201  'processedTca' => [
202  'columns' => [
203  'aField' => [
204  'config' => [
205  'type' => 'flex',
206  'ds_pointerField' => 'list_type,CType',
207  'ds' => [
208  'meta' => [],
209  'sheets' => [
210  'sGeneral' => [
211  'ROOT' => [
212  'type' => 'array',
213  'el' => [
214  'mmType' => [
215  'config' => [
216  'type' => 'select',
217  'items' => [],
218  ],
219  ],
220  'mmUseHTML5' => [
221  'displayCond' => 'FIELD:mmType:!=:audio',
222  'config' => [
223  'type' => 'check',
224  'default' => '0',
225  'items' => [],
226  ],
227  ],
228  'mmUseCurl' => [
229  'displayCond' => 'FIELD:mmType:=:audio',
230  'config' => [
231  'type' => 'check',
232  'default' => '0',
233  'items' => [],
234  ],
235  ],
236  ],
237  'sheetTitle' => 'aTitle',
238  ],
239  ],
240  'secondSheet' => [
241  'ROOT' => [
242  'type' => 'array',
243  'el' => [
244  'foo' => [
245  'config' => [
246  'type' => 'select',
247  'items' => [],
248  ],
249  ],
250  ],
251  'sheetTitle' => 'bTitle',
252  ],
253  ],
254  ],
255  ],
256  ],
257  ],
258  ],
259  ],
260  ];
261 
262  $expected = $input;
263  unset($expected['processedTca']['columns']['aField']['config']['ds']['sheets']['sGeneral']['ROOT']['el']['mmUseHTML5']);
264 
265  $this->assertSame($expected, $this->subject->addData($input));
266  }
267 
271  public function matchHideForNonAdminsReturnsTrueIfBackendUserIsAdmin()
272  {
273  $input = [
274  'databaseRow' => [],
275  'processedTca' => [
276  'columns' => [
277  'aField' => [
278  'displayCond' => 'HIDE_FOR_NON_ADMINS',
279  'config' => [
280  'type' => 'input',
281  ]
282  ],
283  ]
284  ]
285  ];
286 
288  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
289  $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
290  $backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(true);
291 
292  $expected = $input;
293 
294  $this->assertSame($expected, $this->subject->addData($input));
295  }
296 
300  public function matchHideForNonAdminsReturnsFalseIfBackendUserIsNotAdmin()
301  {
302  $input = [
303  'databaseRow' => [],
304  'processedTca' => [
305  'columns' => [
306  'aField' => [
307  'displayCond' => 'HIDE_FOR_NON_ADMINS',
308  'config' => [
309  'type' => 'input',
310  ]
311  ],
312  ]
313  ]
314  ];
315 
317  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
318  $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
319  $backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(false);
320 
321  $expected = $input;
322  unset($expected['processedTca']['columns']['aField']);
323  $this->assertSame($expected, $this->subject->addData($input));
324  }
325 
332  {
333  $input = [
334  'databaseRow' => [],
335  'processedTca' => [
336  'columns' => [
337  'aField' => [
338  'displayCond' => 'HIDE_L10N_SIBLINGS',
339  'config' => [
340  'type' => 'input',
341  ]
342  ],
343  ]
344  ]
345  ];
346 
347  $expected = $input;
348 
349  $this->assertSame($expected, $this->subject->addData($input));
350  }
351 
356  {
357  $input = [
358  'databaseRow' => [],
359  'processedTca' => [
360  'columns' => [
361  'aField' => [
362  'displayCond' => 'HIDE_L10N_SIBLINGS:except_admin',
363  'config' => [
364  'type' => 'input',
365  ]
366  ],
367  ]
368  ]
369  ];
370 
371  $expected = $input;
372 
373  $this->assertSame($expected, $this->subject->addData($input));
374  }
375 
385  public function conditionStringDataProvider()
386  {
387  return [
388  'Invalid condition string' => [
389  'xINVALIDx:',
390  [],
391  false,
392  ],
393  'Not loaded extension compares to loaded as FALSE' => [
394  'EXT:neverloadedext:LOADED:TRUE',
395  [],
396  false,
397  ],
398  'Not loaded extension compares to not loaded as TRUE' => [
399  'EXT:neverloadedext:LOADED:FALSE',
400  [],
401  true,
402  ],
403  'Loaded extension compares to TRUE' => [
404  'EXT:backend:LOADED:TRUE',
405  [],
406  true,
407  ],
408  'Loaded extension compares to FALSE' => [
409  'EXT:backend:LOADED:FALSE',
410  [],
411  false,
412  ],
413  'Field is not greater zero if not given' => [
414  'FIELD:uid:>:0',
415  [],
416  false,
417  ],
418  'Field is not equal 0 if not given' => [
419  'FIELD:uid:=:0',
420  [],
421  false,
422  ],
423  'Field is not present if empty array given' => [
424  'REQ:foo:TRUE',
425  ['foo' => []],
426  false,
427  ],
428  'Field is not greater zero if empty array given' => [
429  'FIELD:foo:>:0',
430  ['foo' => []],
431  false,
432  ],
433  'Field is not greater than or equal to zero if empty array given' => [
434  'FIELD:foo:>=:0',
435  ['foo' => []],
436  false,
437  ],
438  'Field is less than 1 if empty array given' => [
439  'FIELD:foo:<:1',
440  ['foo' => []],
441  true,
442  ],
443  'Field is less than or equal to 1 if empty array given' => [
444  'FIELD:foo:<=:1',
445  ['foo' => []],
446  true,
447  ],
448  'Field does not equal 0 if empty array given' => [
449  'FIELD:foo:=:0',
450  ['foo' => []],
451  false,
452  ],
453  'Field value string comparison' => [
454  'FIELD:foo:=:bar',
455  ['foo' => 'bar'],
456  true,
457  ],
458  'Field value string comparison against list' => [
459  'FIELD:foo:IN:bar,baz',
460  ['foo' => 'baz'],
461  true,
462  ],
463  'Field value comparison of 1 against multi-value field of 5 returns true' => [
464  'FIELD:content:BIT:1',
465  ['content' => '5'],
466  true
467  ],
468  'Field value comparison of 2 against multi-value field of 5 returns false' => [
469  'FIELD:content:BIT:2',
470  ['content' => '5'],
471  false
472  ],
473  'Field value of 5 negated comparison against multi-value field of 5 returns false' => [
474  'FIELD:content:!BIT:5',
475  ['content' => '5'],
476  false
477  ],
478  'Field value comparison for required value is false for different value' => [
479  'FIELD:foo:REQ:FALSE',
480  ['foo' => 'bar'],
481  false,
482  ],
483  'Field value string not equal comparison' => [
484  'FIELD:foo:!=:baz',
485  ['foo' => 'bar'],
486  true,
487  ],
488  'Field value string not equal comparison against list' => [
489  'FIELD:foo:!IN:bar,baz',
490  ['foo' => 'foo'],
491  true,
492  ],
493  'Field value in range' => [
494  'FIELD:uid:-:3-42',
495  ['uid' => '23'],
496  true,
497  ],
498  'Field value greater than' => [
499  'FIELD:uid:>=:42',
500  ['uid' => '23'],
501  false,
502  ],
503  'Field is value for default language without flexform' => [
504  'HIDE_L10N_SIBLINGS',
505  [],
506  true,
507  ],
508  'New is TRUE for new comparison with TRUE' => [
509  'REC:NEW:TRUE',
510  ['uid' => null],
511  true,
512  ],
513  'New is FALSE for new comparison with FALSE' => [
514  'REC:NEW:FALSE',
515  ['uid' => null],
516  false,
517  ],
518  'New is FALSE for not new element' => [
519  'REC:NEW:TRUE',
520  ['uid' => 42],
521  false,
522  ],
523  'New is TRUE for not new element compared to FALSE' => [
524  'REC:NEW:FALSE',
525  ['uid' => 42],
526  true,
527  ],
528  'Version is TRUE for versioned row' => [
529  'VERSION:IS:TRUE',
530  [
531  'uid' => 42,
532  'pid' => -1
533  ],
534  true,
535  ],
536  'Version is TRUE for not versioned row compared with FALSE' => [
537  'VERSION:IS:FALSE',
538  [
539  'uid' => 42,
540  'pid' => 1
541  ],
542  true,
543  ],
544  'Version is TRUE for NULL row compared with TRUE' => [
545  'VERSION:IS:TRUE',
546  [
547  'uid' => null,
548  'pid' => null,
549  ],
550  false,
551  ],
552  'Multiple conditions with AND compare to TRUE if all are OK' => [
553  [
554  'AND' => [
555  'FIELD:testField:>:9',
556  'FIELD:testField:<:11',
557  ],
558  ],
559  [
560  'testField' => 10
561  ],
562  true,
563  ],
564  'Multiple conditions with AND compare to FALSE if one fails' => [
565  [
566  'AND' => [
567  'FIELD:testField:>:9',
568  'FIELD:testField:<:11',
569  ]
570  ],
571  [
572  'testField' => 99
573  ],
574  false,
575  ],
576  'Multiple conditions with OR compare to TRUE if one is OK' => [
577  [
578  'OR' => [
579  'FIELD:testField:<:9',
580  'FIELD:testField:<:11',
581  ],
582  ],
583  [
584  'testField' => 10
585  ],
586  true,
587  ],
588  'Multiple conditions with OR compare to FALSE is all fail' => [
589  [
590  'OR' => [
591  'FIELD:testField:<:9',
592  'FIELD:testField:<:11',
593  ],
594  ],
595  [
596  'testField' => 99
597  ],
598  false,
599  ],
600  'Multiple conditions without operator due to misconfiguration compare to TRUE' => [
601  [
602  '' => [
603  'FIELD:testField:<:9',
604  'FIELD:testField:>:11',
605  ]
606  ],
607  [
608  'testField' => 99
609  ],
610  true,
611  ],
612  'Multiple nested conditions evaluate to TRUE' => [
613  [
614  'AND' => [
615  'FIELD:testField:>:9',
616  'OR' => [
617  'FIELD:testField:<:100',
618  'FIELD:testField:>:-100',
619  ],
620  ],
621  ],
622  [
623  'testField' => 10
624  ],
625  true,
626  ],
627  'Multiple nested conditions evaluate to FALSE' => [
628  [
629  'AND' => [
630  'FIELD:testField:>:9',
631  'OR' => [
632  'FIELD:testField:<:100',
633  'FIELD:testField:>:-100',
634  ],
635  ],
636  ],
637  [
638  'testField' => -999
639  ],
640  false,
641  ],
642  ];
643  }
644 
652  public function matchConditionStrings($condition, array $record, $expectedResult)
653  {
654  $input = [
655  'databaseRow' => $record,
656  'processedTca' => [
657  'columns' => [
658  'testField' => [
659  'displayCond' => $condition,
660  'config' => [
661  'type' => 'input',
662  ]
663  ],
664  ]
665  ]
666  ];
667 
668  $expected = $input;
669  if (!$expectedResult) {
670  unset($expected['processedTca']['columns']['testField']);
671  }
672  $this->assertSame($expected, $this->subject->addData($input));
673  }
674 
683  public function matchConditionStringsWithRecordTestFieldBeingArray($condition, array $record, $expectedResult)
684  {
685  $input = [
686  'processedTca' => [
687  'columns' => [
688  'testField' => [
689  'displayCond' => $condition,
690  'config' => [
691  'type' => 'input',
692  ],
693  ],
694  ],
695  ],
696  ];
697  $input['databaseRow'] = $record ?: ['testField' => ['key' => $record['testField']]];
698 
699  $expected = $input;
700  if (!$expectedResult) {
701  unset($expected['processedTca']['columns']['testField']);
702  }
703  $this->assertSame($expected, $this->subject->addData($input));
704  }
705 
716  {
717  return [
718  'Flexform value invalid comparison' => [
719  'FIELD:foo:=:bar',
720  [
721  'foo' => 'bar',
722  'testField' => [
723  'data' => [
724  'sDEF' => [
725  'lDEF' => [],
726  ],
727  ],
728  ],
729  ],
730  false,
731  ],
732  'Flexform value valid comparison' => [
733  'FIELD:parentRec.foo:=:bar',
734  [
735  'foo' => 'bar',
736  'testField' => [
737  'data' => [
738  'sDEF' => [
739  'lDEF' => [],
740  ],
741  ],
742  ],
743  ],
744  true,
745  ],
746  ];
747  }
748 
756  public function matchFlexformConditionStrings($condition, array $record, $expectedResult)
757  {
758  $input = [
759  'databaseRow' => $record,
760  'processedTca' => [
761  'columns' => [
762  'testField' => [
763  'config' => [
764  'type' => 'flex',
765  'ds' => [
766  'meta' => [],
767  'sheets' => [
768  'sDEF' => [
769  'ROOT' => [
770  'type' => 'array',
771  'el' => [
772  'flexTestField' => [
773  'displayCond' => $condition,
774  'config' => [
775  'type' => 'input',
776  ],
777  ],
778  ],
779  ],
780  ],
781  ]
782  ],
783  ],
784  ],
785  ],
786  ],
787  ];
788 
789  $expected = $input;
790  if (!$expectedResult) {
791  unset($expected['processedTca']['columns']['testField']['config']['ds']['sheets']['sDEF']['ROOT']['el']['flexTestField']);
792  }
793  $this->assertSame($expected, $this->subject->addData($input));
794  }
795 
800  {
801  $input = [
802  'databaseRow' => [
803  'foo' => 'bar',
804  'testField' => [
805  'data' => [
806  'sDEF' => [
807  'lDEF' => [
808  'flex.TestField' => [
809  'vDEF' => [
810  0 => 0,
811  ],
812  ],
813  ],
814  ],
815  ],
816  ],
817  ],
818  'processedTca' => [
819  'columns' => [
820  'testField' => [
821  'config' => [
822  'type' => 'flex',
823  'ds' => [
824  'meta' => [],
825  'sheets' => [
826  'sDEF' => [
827  'ROOT' => [
828  'type' => 'array',
829  'el' => [
830  'flex.TestField' => [
831  'config' => [
832  'type' => 'input',
833  ],
834  ],
835  ],
836  ],
837  ],
838  'sTest' => [
839  'ROOT' => [
840  'type' => 'array',
841  'el' => [],
842  'sheetTitle' => 'sVideo',
843  'displayCond' => 'FIELD:sDEF.flex.TestField:!=:0',
844  ],
845  ],
846  ]
847  ],
848  ],
849  ],
850  ],
851  ],
852  ];
853 
854  $expected = $input;
855  unset($expected['processedTca']['columns']['testField']['config']['ds']['sheets']['sTest']);
856  $this->assertSame($expected, $this->subject->addData($input));
857  }
858 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']