ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
UtilitiesTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
26 class UtilitiesTest extends TestCase
27 {
28  protected Utilities $utilities;
29  protected DateFormat $format;
30 
31  protected function setUp(): void
32  {
33  $lng = $this->createMock(\ilLanguage::class);
34  $lng->expects(self::once())->method('loadLanguageModule')->with('meta');
35  $map = ['key1' => 'text', 'key2' => 'text with %s'];
36  $lng->method('txt')->willReturnCallback(function ($arg) use ($map) {
37  return $map[$arg] ?? '';
38  });
39  $lng->method('exists')->willReturnCallback(function ($arg) use ($map) {
40  return key_exists($arg, $map);
41  });
42 
43  $this->format = $this->createMock(DateFormat::class);
44  $user = $this->createMock(\ilObjUser::class);
45  $user->method('getDateFormat')->willReturn($this->format);
46 
47  $this->utilities = new Utilities($lng, $user);
48  }
49 
50  public function testGetUserDateFormat(): void
51  {
52  $this->assertEquals(
53  $this->format,
54  $this->utilities->getUserDateFormat()
55  );
56  }
57 
58  public function testTxt(): void
59  {
60  $this->assertSame(
61  'text',
62  $this->utilities->txt('key1')
63  );
64  }
65 
66  public function testTxtFill(): void
67  {
68  $this->assertSame(
69  'text',
70  $this->utilities->txtFill('key1', 'more text')
71  );
72  $this->assertSame(
73  'text with more text',
74  $this->utilities->txtFill('key2', 'more text')
75  );
76  $this->assertSame(
77  'wrong key first, second',
78  $this->utilities->txtFill('wrong key', 'first', 'second')
79  );
80  }
81 }
A Date Format provides a format definition akin to PHP&#39;s date formatting options, but stores the sing...
Definition: DateFormat.php:26
$lng