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