TYPO3 CMS  TYPO3_7-6
SpacelessViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
17 
22 {
27  {
28  $instance = new SpacelessViewHelper();
29  $viewHelperNodeProphecy = $this->prophesize(ViewHelperNode::class);
30  $instance->setViewHelperNode($viewHelperNodeProphecy->reveal());
31  $renderingContextInterfaceProphecy = $this->prophesize(RenderingContextInterface::class);
32  $instance->setRenderingContext($renderingContextInterfaceProphecy->reveal());
33  $instance->setArguments([]);
34  // the render method would not return an empty string in a real usage. The render method just
35  // calls renderStatic, which does the actual work. The tests for this are done in the
36  // renderStatic test directly. The render method test only makes sure the method call
37  // raises no fatal error.
38  $this->assertEquals('', $instance->render());
39  }
40 
48  public function testRenderStatic($input, $expected)
49  {
50  $context = $this->getMock(RenderingContextInterface::class);
51 
52  $this->assertEquals($expected,
53  SpacelessViewHelper::renderStatic([], function () use ($input) {
54  return $input;
55  }, $context));
56  }
57 
61  public function testRenderStaticDataProvider()
62  {
63  return [
64  'extra whitespace between tags' => [
65  '<div>foo</div> <div>bar</div>',
66  '<div>foo</div><div>bar</div>',
67  ],
68  'whitespace preserved in text node' => [
69  PHP_EOL . '<div>' . PHP_EOL . 'foo</div>',
70  '<div>' . PHP_EOL . 'foo</div>',
71  ],
72  'whitespace removed from non-text node' => [
73  PHP_EOL . '<div>' . PHP_EOL . '<div>foo</div></div>',
74  '<div><div>foo</div></div>',
75  ],
76  ];
77  }
78 }
static renderStatic(array $arguments, \Closure $childClosure, RenderingContextInterface $renderingContext)