ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ColorTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 
23 use ILIAS\Data;
25 
31 class ColorTest extends TestCase
32 {
33  private ?Data\Factory $f;
34 
35  protected function setUp(): void
36  {
37  $this->f = new Data\Factory();
38  }
39 
40  protected function tearDown(): void
41  {
42  $this->f = null;
43  }
44 
45  public function testFullHexValue(): void
46  {
47  $v = $this->f->color('#0fff2f');
48 
49  $this->assertEquals('#0fff2f', $v->asHex());
50  $this->assertEquals('rgb(15, 255, 47)', $v->asRGBString());
51  $this->assertEquals(array(15, 255, 47), $v->asArray());
52  $this->assertEquals(15, $v->r());
53  $this->assertEquals(255, $v->g());
54  $this->assertEquals(47, $v->b());
55  }
56 
57  public function testShortHexValue(): void
58  {
59  $v = $this->f->color('#f0f');
60  $this->assertEquals('#ff00ff', $v->asHex());
61  $this->assertEquals('rgb(255, 0, 255)', $v->asRGBString());
62  $this->assertEquals(array(255, 0, 255), $v->asArray());
63  }
64 
65  public function testShortHexValue2(): void
66  {
67  $v = $this->f->color('f0f');
68  $this->assertEquals('#ff00ff', $v->asHex());
69  $this->assertEquals('rgb(255, 0, 255)', $v->asRGBString());
70  $this->assertEquals(array(255, 0, 255), $v->asArray());
71  }
72 
73  public function testRBGValue(): void
74  {
75  $v = $this->f->color(array(15,255,47));
76  $this->assertEquals('#0fff2f', $v->asHex());
77  $this->assertEquals('rgb(15, 255, 47)', $v->asRGBString());
78  $this->assertEquals(array(15, 255, 47), $v->asArray());
79  }
80 
81  public function testWrongRBGValue(): void
82  {
83  try {
84  $v = $this->f->color(array(-1,0,0));
85  $this->assertFalse("This should not happen.");
86  } catch (InvalidArgumentException $e) {
87  $this->assertTrue(true);
88  }
89  }
90 
91  public function testWrongRBGValue2(): void
92  {
93  try {
94  $v = $this->f->color(array(256,0,0));
95  $this->assertFalse("This should not happen.");
96  } catch (InvalidArgumentException $e) {
97  $this->assertTrue(true);
98  }
99  }
100 
101  public function testWrongRBGValue3(): void
102  {
103  try {
104  $v = $this->f->color(array(1,1,'123'));
105  $this->assertFalse("This should not happen.");
106  } catch (InvalidArgumentException $e) {
107  $this->assertTrue(true);
108  }
109  }
110 
111  public function testWrongRBGValue4(): void
112  {
113  try {
114  $v = $this->f->color(array());
115  $this->assertFalse("This should not happen.");
116  } catch (InvalidArgumentException $e) {
117  $this->assertTrue(true);
118  }
119  }
120 
121  public function testWrongHexValue(): void
122  {
123  try {
124  $v = $this->f->color('1234');
125  $this->assertFalse("This should not happen.");
126  } catch (InvalidArgumentException $e) {
127  $this->assertTrue(true);
128  }
129  }
130 
131  public function testWrongHexValue2(): void
132  {
133  try {
134  $v = $this->f->color('#ff');
135  $this->assertFalse("This should not happen.");
136  } catch (InvalidArgumentException $e) {
137  $this->assertTrue(true);
138  }
139  }
140 
141  public function testWrongHexValue4(): void
142  {
143  try {
144  $v = $this->f->color('#gg0000');
145  $this->assertFalse("This should not happen.");
146  } catch (InvalidArgumentException $e) {
147  $this->assertTrue(true);
148  }
149  }
150 
151  public function testDarkness(): void
152  {
153  $v = $this->f->color('#6541f4');
154  $this->assertEquals(true, $v->isDark());
155  }
156 
157  public function testDarkness2(): void
158  {
159  $v = $this->f->color('#c1f441');
160  $this->assertEquals(false, $v->isDark());
161  }
162 }
testDarkness2()
Definition: ColorTest.php:157
testWrongHexValue4()
Definition: ColorTest.php:141
testWrongHexValue()
Definition: ColorTest.php:121
testShortHexValue()
Definition: ColorTest.php:57
testWrongRBGValue3()
Definition: ColorTest.php:101
testDarkness()
Definition: ColorTest.php:151
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testFullHexValue()
Definition: ColorTest.php:45
testWrongHexValue2()
Definition: ColorTest.php:131
testRBGValue()
Definition: ColorTest.php:73
Data Factory $f
Definition: ColorTest.php:33
Tests working with color data object.
Definition: ColorTest.php:31
testWrongRBGValue2()
Definition: ColorTest.php:91
testShortHexValue2()
Definition: ColorTest.php:65
testWrongRBGValue4()
Definition: ColorTest.php:111
testWrongRBGValue()
Definition: ColorTest.php:81