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