ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
OptionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
26 class OptionTest extends TestCase
27 {
28  public function testIsPersistedFalse(): void
29  {
30  $option = new OptionImplementation(5);
31  $this->assertFalse($option->isPersisted());
32  }
33 
34  public function testIsPersistedTrue(): void
35  {
36  $option = new OptionImplementation(5, 13);
37  $this->assertTrue($option->isPersisted());
38  }
39 
40  public function testContainsChangesInPosition(): void
41  {
42  $option = new OptionImplementation(1, 13);
43  $option->setPosition(103);
44  $this->assertTrue($option->containsChanges());
45  }
46 
47  public function testHasTranslationInLanguageTrue(): void
48  {
49  $translation = new OptionTranslationImplementation('lang', '');
50  $option = new OptionImplementation(5, 13, $translation);
51  $this->assertTrue($option->hasTranslationInLanguage('lang'));
52  }
53 
54  public function testHasTranslationInLanguageFalse(): void
55  {
56  $translation = new OptionTranslationImplementation('lang', '');
57  $option = new OptionImplementation(5, 13, $translation);
58  $this->assertFalse($option->hasTranslationInLanguage('other lang'));
59  }
60 
61  public function testGetTranslationInLanguage(): void
62  {
63  $translation = new OptionTranslationImplementation('lang', '');
64  $option = new OptionImplementation(5, 13, $translation);
65  $this->assertSame(
66  $translation,
67  $option->getTranslationInLanguage('lang')
68  );
69  }
70 
71  public function testAddTranslation(): void
72  {
73  $option = new OptionImplementation(13);
74  $translation = $option->addTranslation('lang');
75  $this->assertSame(
76  $translation,
77  $option->getTranslations()->current()
78  );
79  }
80 
82  {
83  $translation = new OptionTranslationImplementation('lang', '');
84  $option = new OptionImplementation(5, 13, $translation);
85 
86  $this->expectException(Exception::class);
87  $option->addTranslation('lang');
88  }
89 
90  public function testRemoveTranslation(): void
91  {
92  $translation = new OptionTranslationImplementation('lang', '');
93  $option = new OptionImplementation(5, 13, $translation);
94  $option->removeTranslation('lang');
95  $this->assertFalse($option->hasTranslationInLanguage('lang'));
96  }
97 
98  public function testContainsChangesTranslationRemoved(): void
99  {
100  $translation = new OptionTranslationImplementation('lang', '', true);
101  $option = new OptionImplementation(5, 13, $translation);
102  $option->removeTranslation('lang');
103  $this->assertTrue($option->containsChanges());
104  }
105 }