‪TYPO3CMS  10.4
ParserTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪ParserTest extends UnitTestCase
24 {
25  private const ‪TYPES = [
26  ‪SimpleNode::TYPE_ELEMENT => 'ELEMENT',
27  ‪SimpleNode::TYPE_TEXT => 'TEXT',
28  ‪SimpleNode::TYPE_CDATA => 'CDATA',
29  ‪SimpleNode::TYPE_COMMENT => 'COMMENT',
30  ];
31 
35  public function ‪nodesAreResolvedDataProvider(): array
36  {
37  return [
38  [
39  'text',
40  ['[TEXT]: text'],
41  ],
42  [
43  '<element>',
44  ['[ELEMENT]: <element>'],
45  ],
46  [
47  '</element>',
48  ['[ELEMENT]: </element>'],
49  ],
50  [
51  '<!-- comment -->',
52  ['[COMMENT]: <!-- comment -->'],
53  ],
54  [
55  '<![CDATA[ cdata ]]>',
56  ['[CDATA]: <![CDATA[ cdata ]]>'],
57  ],
58  [
59  '<![CDATA[ <!-- comment --> ]]>',
60  ['[CDATA]: <![CDATA[ <!-- comment --> ]]>'],
61  ],
62  [
63  '<!-- <![CDATA[ cdata ]]> -->',
64  ['[COMMENT]: <!-- <![CDATA[ cdata ]]> -->'],
65  ],
66  [
67  '<text',
68  [], // invalid element start, therefore ignored
69  ],
70  [
71  '< text',
72  ['[TEXT]: < text'],
73  ],
74  [
75  'x < y',
76  ['[TEXT]: x < y'],
77  ],
78  [
79  'text>',
80  ['[TEXT]: text>'],
81  ],
82  [
83  'text >',
84  ['[TEXT]: text >'],
85  ],
86  [
87  'x > y',
88  ['[TEXT]: x > y'],
89  ],
90  [
91  'x < y > z',
92  ['[TEXT]: x < y > z'],
93  ],
94  [
95  'x <= y >= z',
96  ['[TEXT]: x <= y >= z'],
97  ],
98  [
99  'x =<y>= z',
100  ['[TEXT]: x =', '[ELEMENT]: <y>', '[TEXT]: = z'],
101  ],
102  ];
103  }
104 
111  public function ‪nodesAreResolved(string $html, array $expectation): void
112  {
114  $nodes = array_map(
115  function (‪SimpleNode $node) {
116  return sprintf('[%s]: %s', self::TYPES[$node->‪getType()], $node);
117  },
118  ‪$parser->getNodes()
119  );
120  self::assertSame($expectation, $nodes);
121  }
122 }
‪TYPO3\CMS\Core\Html\SimpleNode\getType
‪int getType()
Definition: SimpleNode.php:63
‪TYPO3\CMS\Core\Tests\Unit\Html\Parser\ParserTest\nodesAreResolved
‪nodesAreResolved(string $html, array $expectation)
Definition: ParserTest.php:111
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_ELEMENT
‪const TYPE_ELEMENT
Definition: SimpleNode.php:26
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_TEXT
‪const TYPE_TEXT
Definition: SimpleNode.php:27
‪TYPO3\CMS\Core\Tests\Unit\Html\Parser
Definition: ParserTest.php:18
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_COMMENT
‪const TYPE_COMMENT
Definition: SimpleNode.php:29
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_CDATA
‪const TYPE_CDATA
Definition: SimpleNode.php:28
‪TYPO3\CMS\Core\Html\SimpleParser\fromString
‪static fromString(string $string)
Definition: SimpleParser.php:49
‪TYPO3\CMS\Core\Tests\Unit\Html\Parser\ParserTest\TYPES
‪const TYPES
Definition: ParserTest.php:25
‪TYPO3\CMS\Core\Html\SimpleNode
Definition: SimpleNode.php:24
‪TYPO3\CMS\Core\Tests\Unit\Html\Parser\ParserTest\nodesAreResolvedDataProvider
‪string[] nodesAreResolvedDataProvider()
Definition: ParserTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Html\Parser\ParserTest
Definition: ParserTest.php:24