ILIAS  release_8 Revision v8.24
ColorTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2017 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
6
7require_once("libs/composer/vendor/autoload.php");
8
9use ILIAS\Data;
10use PHPUnit\Framework\TestCase;
11
17class ColorTest extends TestCase
18{
19 private ?Data\Factory $f;
20
21 protected function setUp(): void
22 {
23 $this->f = new Data\Factory();
24 }
25
26 protected function tearDown(): void
27 {
28 $this->f = null;
29 }
30
31 public function testFullHexValue(): void
32 {
33 $v = $this->f->color('#0fff2f');
34
35 $this->assertEquals('#0fff2f', $v->asHex());
36 $this->assertEquals('rgb(15, 255, 47)', $v->asRGBString());
37 $this->assertEquals(array(15, 255, 47), $v->asArray());
38 $this->assertEquals(15, $v->r());
39 $this->assertEquals(255, $v->g());
40 $this->assertEquals(47, $v->b());
41 }
42
43 public function testShortHexValue(): void
44 {
45 $v = $this->f->color('#f0f');
46 $this->assertEquals('#ff00ff', $v->asHex());
47 $this->assertEquals('rgb(255, 0, 255)', $v->asRGBString());
48 $this->assertEquals(array(255, 0, 255), $v->asArray());
49 }
50
51 public function testShortHexValue2(): void
52 {
53 $v = $this->f->color('f0f');
54 $this->assertEquals('#ff00ff', $v->asHex());
55 $this->assertEquals('rgb(255, 0, 255)', $v->asRGBString());
56 $this->assertEquals(array(255, 0, 255), $v->asArray());
57 }
58
59 public function testRBGValue(): void
60 {
61 $v = $this->f->color(array(15,255,47));
62 $this->assertEquals('#0fff2f', $v->asHex());
63 $this->assertEquals('rgb(15, 255, 47)', $v->asRGBString());
64 $this->assertEquals(array(15, 255, 47), $v->asArray());
65 }
66
67 public function testWrongRBGValue(): void
68 {
69 try {
70 $v = $this->f->color(array(-1,0,0));
71 $this->assertFalse("This should not happen.");
72 } catch (InvalidArgumentException $e) {
73 $this->assertTrue(true);
74 }
75 }
76
77 public function testWrongRBGValue2(): void
78 {
79 try {
80 $v = $this->f->color(array(256,0,0));
81 $this->assertFalse("This should not happen.");
82 } catch (InvalidArgumentException $e) {
83 $this->assertTrue(true);
84 }
85 }
86
87 public function testWrongRBGValue3(): void
88 {
89 try {
90 $v = $this->f->color(array(1,1,'123'));
91 $this->assertFalse("This should not happen.");
92 } catch (InvalidArgumentException $e) {
93 $this->assertTrue(true);
94 }
95 }
96
97 public function testWrongRBGValue4(): void
98 {
99 try {
100 $v = $this->f->color(array());
101 $this->assertFalse("This should not happen.");
102 } catch (InvalidArgumentException $e) {
103 $this->assertTrue(true);
104 }
105 }
106
107 public function testWrongHexValue(): void
108 {
109 try {
110 $v = $this->f->color('1234');
111 $this->assertFalse("This should not happen.");
112 } catch (InvalidArgumentException $e) {
113 $this->assertTrue(true);
114 }
115 }
116
117 public function testWrongHexValue2(): void
118 {
119 try {
120 $v = $this->f->color('#ff');
121 $this->assertFalse("This should not happen.");
122 } catch (InvalidArgumentException $e) {
123 $this->assertTrue(true);
124 }
125 }
126
127 public function testWrongHexValue4(): void
128 {
129 try {
130 $v = $this->f->color('#gg0000');
131 $this->assertFalse("This should not happen.");
132 } catch (InvalidArgumentException $e) {
133 $this->assertTrue(true);
134 }
135 }
136
137 public function testDarkness(): void
138 {
139 $v = $this->f->color('#6541f4');
140 $this->assertEquals(true, $v->isDark());
141 }
142
143 public function testDarkness2(): void
144 {
145 $v = $this->f->color('#c1f441');
146 $this->assertEquals(false, $v->isDark());
147 }
148}
Tests working with color data object.
Definition: ColorTest.php:18
testShortHexValue2()
Definition: ColorTest.php:51
testWrongRBGValue()
Definition: ColorTest.php:67
testWrongRBGValue2()
Definition: ColorTest.php:77
testDarkness()
Definition: ColorTest.php:137
testWrongHexValue()
Definition: ColorTest.php:107
Data Factory $f
Definition: ColorTest.php:19
testRBGValue()
Definition: ColorTest.php:59
testFullHexValue()
Definition: ColorTest.php:31
testWrongRBGValue4()
Definition: ColorTest.php:97
testWrongRBGValue3()
Definition: ColorTest.php:87
testDarkness2()
Definition: ColorTest.php:143
testWrongHexValue2()
Definition: ColorTest.php:117
testShortHexValue()
Definition: ColorTest.php:43
testWrongHexValue4()
Definition: ColorTest.php:127
Builds data types.
Definition: Factory.php:21