ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilStudyProgrammeTypeInfoTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  private const VALID_TITLE_1 = 'Title 1';
26  private const VALID_TITLE_2 = 'Title 2';
27  private const VALID_TITLE_N = null;
28  private const VALID_DESCRIPTION_1 = 'Description 1';
29  private const VALID_DESCRIPTION_2 = 'Description 2';
30  private const VALID_DESCRIPTION_N = null;
31  private const VALID_LNG_CODE_1 = 'de';
32  private const VALID_LNG_CODE_2 = 'en';
33  private const VALID_LNG_CODE_N = null;
34 
35  public function testSuccessCreate(): void
36  {
37  $obj = new ilStudyProgrammeTypeInfo();
38 
39  $this->assertNull($obj->getTitle());
40  $this->assertNull($obj->getDescription());
41  $this->assertNull($obj->getLanguageCode());
42 
43  $obj = new ilStudyProgrammeTypeInfo(
44  self::VALID_TITLE_N,
45  self::VALID_DESCRIPTION_N,
46  self::VALID_LNG_CODE_N
47  );
48 
49  $this->assertNull($obj->getTitle());
50  $this->assertNull($obj->getDescription());
51  $this->assertNull($obj->getLanguageCode());
52 
53  $obj = new ilStudyProgrammeTypeInfo(
54  self::VALID_TITLE_1,
55  self::VALID_DESCRIPTION_1,
56  self::VALID_LNG_CODE_1
57  );
58 
59  $this->assertEquals(self::VALID_TITLE_1, $obj->getTitle());
60  $this->assertEquals(self::VALID_DESCRIPTION_1, $obj->getDescription());
61  $this->assertEquals(self::VALID_LNG_CODE_1, $obj->getLanguageCode());
62  }
63 
64  public function testSuccessfulWithTitle(): void
65  {
66  $obj = new ilStudyProgrammeTypeInfo(
67  self::VALID_TITLE_1,
68  self::VALID_DESCRIPTION_1,
69  self::VALID_LNG_CODE_1
70  );
71 
72  $new = $obj->withTitle(self::VALID_TITLE_2);
73 
74  $this->assertEquals(self::VALID_TITLE_1, $obj->getTitle());
75  $this->assertEquals(self::VALID_DESCRIPTION_1, $obj->getDescription());
76  $this->assertEquals(self::VALID_LNG_CODE_1, $obj->getLanguageCode());
77 
78  $this->assertEquals(self::VALID_TITLE_2, $new->getTitle());
79  $this->assertEquals(self::VALID_DESCRIPTION_1, $new->getDescription());
80  $this->assertEquals(self::VALID_LNG_CODE_1, $new->getLanguageCode());
81  }
82 
83  public function testSuccessfulWithDescription(): void
84  {
85  $obj = new ilStudyProgrammeTypeInfo(
86  self::VALID_TITLE_1,
87  self::VALID_DESCRIPTION_1,
88  self::VALID_LNG_CODE_1
89  );
90 
91  $new = $obj->withDescription(self::VALID_DESCRIPTION_2);
92 
93  $this->assertEquals(self::VALID_TITLE_1, $obj->getTitle());
94  $this->assertEquals(self::VALID_DESCRIPTION_1, $obj->getDescription());
95  $this->assertEquals(self::VALID_LNG_CODE_1, $obj->getLanguageCode());
96 
97  $this->assertEquals(self::VALID_TITLE_1, $new->getTitle());
98  $this->assertEquals(self::VALID_DESCRIPTION_2, $new->getDescription());
99  $this->assertEquals(self::VALID_LNG_CODE_1, $new->getLanguageCode());
100  }
101 
102  public function testSuccessfulWithLanguageCode(): void
103  {
104  $obj = new ilStudyProgrammeTypeInfo(
105  self::VALID_TITLE_1,
106  self::VALID_DESCRIPTION_1,
107  self::VALID_LNG_CODE_1
108  );
109 
110  $new = $obj->withLanguageCode(self::VALID_LNG_CODE_2);
111 
112  $this->assertEquals(self::VALID_TITLE_1, $obj->getTitle());
113  $this->assertEquals(self::VALID_DESCRIPTION_1, $obj->getDescription());
114  $this->assertEquals(self::VALID_LNG_CODE_1, $obj->getLanguageCode());
115 
116  $this->assertEquals(self::VALID_TITLE_1, $new->getTitle());
117  $this->assertEquals(self::VALID_DESCRIPTION_1, $new->getDescription());
118  $this->assertEquals(self::VALID_LNG_CODE_2, $new->getLanguageCode());
119  }
120 
121 
122  public function testToFormInput(): void
123  {
124  $lng = $this->createMock(ilLanguage::class);
125  $df = new ILIAS\Data\Factory();
127 
129  $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
130  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
131  new ILIAS\UI\Implementation\Component\SignalGenerator(),
132  $df,
133  $refinery,
134  $lng
135  );
136 
137  $obj = new ilStudyProgrammeTypeInfo(
138  self::VALID_TITLE_1,
139  self::VALID_DESCRIPTION_1,
140  self::VALID_LNG_CODE_1
141  );
142 
143  $lng_consecutive_calls = [];
144  $lng->expects($this->atLeastOnce())
145  ->method('txt')
146  ->willReturnCallback(
147  function ($txt) use (&$lng_consecutive_calls) {
148  $lng_consecutive_calls[] = $txt;
149  return $txt;
150  }
151  );
152 
153  $expected_consecutive_calls = [
154  'title',
155  'description',
156  'meta_l_de',
157  ];
158 
159  $field = $obj->toFormInput(
160  $f,
161  $lng,
162  $refinery
163  );
164 
165  $this->assertEquals($expected_consecutive_calls, $lng_consecutive_calls);
166 
168  $text = $field->getInputs()['title'];
169 
170  $this->assertInstanceOf(
171  ILIAS\UI\Implementation\Component\Input\Field\Text::class,
172  $text
173  );
174 
176  $textarea = $field->getInputs()['description'];
177 
178  $this->assertInstanceOf(
179  ILIAS\UI\Implementation\Component\Input\Field\Textarea::class,
180  $textarea
181  );
182  }
183 }
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$txt
Definition: error.php:31
global $lng
Definition: privfeed.php:31