ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UtilitiesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
25use ILIAS\Refinery\Factory as Refinery;
26use ILIAS\Refinery\Encode\Group as EncodeGroup;
28
29class UtilitiesTest extends TestCase
30{
33
34 protected function setUp(): void
35 {
36 $lng = $this->createMock(\ilLanguage::class);
37 $lng->expects(self::once())->method('loadLanguageModule')->with('meta');
38 $map = ['key1' => 'text', 'key2' => 'text with %s'];
39 $lng->method('txt')->willReturnCallback(function ($arg) use ($map) {
40 return $map[$arg] ?? '';
41 });
42 $lng->method('exists')->willReturnCallback(function ($arg) use ($map) {
43 return key_exists($arg, $map);
44 });
45
46 $this->format = $this->createMock(DateFormat::class);
47 $user = $this->createMock(\ilObjUser::class);
48 $user->method('getDateFormat')->willReturn($this->format);
49
50 $refinery = $this->createMock(Refinery::class);
51 $encoding_group = $this->createMock(EncodeGroup::class);
52 $transformation = $this->createMock(Transformation::class);
53 $transformation->method('transform')->willReturnCallback(function ($arg) {
54 return '~encoded:' . $arg . '~';
55 });
56 $encoding_group->method('htmlSpecialCharsAsEntities')->willReturn($transformation);
57 $refinery->method('encode')->willReturn($encoding_group);
58
59 $this->utilities = new Utilities($lng, $user, $refinery);
60 }
61
62 public function testGetUserDateFormat(): void
63 {
64 $this->assertEquals(
65 $this->format,
66 $this->utilities->getUserDateFormat()
67 );
68 }
69
70 public function testTxt(): void
71 {
72 $this->assertSame(
73 'text',
74 $this->utilities->txt('key1')
75 );
76 }
77
78 public function testTxtFill(): void
79 {
80 $this->assertSame(
81 'text',
82 $this->utilities->txtFill('key1', 'more text')
83 );
84 $this->assertSame(
85 'text with more text',
86 $this->utilities->txtFill('key2', 'more text')
87 );
88 $this->assertSame(
89 'wrong key first, second',
90 $this->utilities->txtFill('wrong key', 'first', 'second')
91 );
92 }
93
94 public function testSanitizeForHTML(): void
95 {
96 $this->assertSame(
97 '~encoded:some text~',
98 $this->utilities->sanitizeForHTML('some text')
99 );
100 }
101}
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition: DateFormat.php:27
Builds data types.
Definition: Factory.php:36
A transformation is a function from one datatype to another.
global $lng
Definition: privfeed.php:31