ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilTermsOfServiceTrimmedDocumentPurifierTest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
13 public function stringsToTrimProvider() : array
14 {
15 return [
16 'Text with or without Spaces' => [' phpunit ', 'phpunit',],
17 'Text with or without Line Endings and Tabs' => ["\n\r\tphpunit\n\r\t", 'phpunit',],
18 ];
19 }
20
24 public function stringElementsArrayToTrimProvider() : array
25 {
26 return [
27 'Text with or without Spaces' => [[' phpunit '], ['phpunit'],],
28 'Text with or without Line Endings and Tabs' => [["\n\r\tphpunit\n\r\t"], ['phpunit'],],
29 ];
30 }
31
38 public function testSingleStringIsTrimmed(string $text, string $expectedResult) : void
39 {
40 $aggregated = $this
41 ->getMockBuilder(ilHtmlPurifierInterface::class)
42 ->getMock();
43
44 $aggregated
45 ->expects($this->once())
46 ->method('purify')
47 ->with($text)
48 ->willReturn($text);
49
50 $purifier = new ilTermsOfServiceTrimmedDocumentPurifier($aggregated);
51
52 $this->assertEquals($expectedResult, $purifier->purify($text));
53 }
54
61 public function testArrayOfStringElementsIsTrimmed(array $texts, array $expectedResult) : void
62 {
63 $aggregated = $this
64 ->getMockBuilder(ilHtmlPurifierInterface::class)
65 ->getMock();
66
67 $aggregated
68 ->expects($this->exactly(count($texts)))
69 ->method('purify')
70 ->with($this->isType('string'))
71 ->willReturnArgument(0);
72
73 $purifier = new ilTermsOfServiceTrimmedDocumentPurifier($aggregated);
74
75 $this->assertEquals($expectedResult, $purifier->purifyArray($texts));
76 }
77}
An exception for terminatinating execution or to throw for unit testing.
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceTrimmedDocumentPurifierTest.
testArrayOfStringElementsIsTrimmed(array $texts, array $expectedResult)
@dataProvider stringElementsArrayToTrimProvider
testSingleStringIsTrimmed(string $text, string $expectedResult)
@dataProvider stringsToTrimProvider