Skip to content

Commit c480c94

Browse files
committed
basic support for the color class. and by basic i mean empty. :D
1 parent b8f1aeb commit c480c94

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
// Copyright 2012-present Element 34
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
include_once('WebDriverExceptions.php');
17+
18+
class PHPWebDriver_Support_Color {
19+
public function __construct($color) {
20+
$this->color = $color;
21+
return $this;
22+
}
23+
24+
public function rgb() {}
25+
26+
public function rgba() {}
27+
28+
public function hex() {}
29+
30+
}

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
<tasks:replace from="@package_version@" to="version" type="package-info" />
5151
</file>
5252
</dir>
53+
<file baseinstalldir="/" name="WebDriverColor.php" role="php">
54+
<tasks:replace from="@package_version@" to="version" type="package-info" />
55+
</file>
5356
</dir>
5457
<file baseinstalldir="/" name="WebDriver.php" role="php">
5558
<tasks:replace from="@package_version@" to="version" type="package-info" />

test/support/ColorTest.php

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
require_once(dirname(__FILE__) . '/../../PHPWebDriver/Support/WebDriverColor.php');
3+
4+
class LocationTest extends PHPUnit_Framework_TestCase {
5+
protected static $session;
6+
7+
/**
8+
* @test
9+
* @group color
10+
*/
11+
public function rgbToRgb() {
12+
$rgb = "rgb(1, 2, 3)";
13+
$c = new PHPWebDriver_Support_Color($rgb);
14+
$this->assertEquals($rgb, $c->rgb());
15+
}
16+
17+
/**
18+
* @test
19+
* @group color
20+
*/
21+
public function rgbToRgba() {
22+
$rgb = "rgb(1, 2, 3)";
23+
$c = new PHPWebDriver_Support_Color($rgb);
24+
$this->assertEquals("rgba(1, 2, 3, 1)", $c->rgba());
25+
}
26+
27+
/**
28+
* @test
29+
* @group color
30+
*/
31+
public function rgbPctToRgba() {
32+
$rgba = "rgb(10%, 20%, 30%)";
33+
$c = new PHPWebDriver_Support_Color($rgba);
34+
$this->assertEquals("rgba(25, 51, 76, 1)", $c->rgba());
35+
}
36+
37+
/**
38+
* @test
39+
* @group color
40+
*/
41+
public function rgbAllowsWhitespace() {
42+
$rgb = "rgb(\t1, 2 , 3)";
43+
$canonicalRgb = "rgb(1, 2, 3)";
44+
$c = new PHPWebDriver_Support_Color($rgb);
45+
$this->assertEquals($canonicalRgb, $c->rgb());
46+
}
47+
48+
/**
49+
* @test
50+
* @group color
51+
*/
52+
public function rgbaToRgba() {
53+
$rgba = "rgba(1, 2, 3, 0.5)";
54+
$c = new PHPWebDriver_Support_Color($rgba);
55+
$this->assertEquals($rgba, $c->rgba());
56+
}
57+
58+
/**
59+
* @test
60+
* @group color
61+
*/
62+
public function rgbaPctToRgba() {
63+
$rgba = "rgba(10%, 20%, 30%, 0.5)";
64+
$c = new PHPWebDriver_Support_Color($rgba);
65+
$this->assertEquals("rgba(25, 51, 76, 0.5)", $c->rgba());
66+
}
67+
68+
/**
69+
* @test
70+
* @group color
71+
*/
72+
public function hexToHex() {
73+
$hex = "#ff00a0";
74+
$c = new PHPWebDriver_Support_Color($hex);
75+
$this->assertEquals($hex, $c->hex());
76+
}
77+
78+
/**
79+
* @test
80+
* @group color
81+
*/
82+
public function hexToRgb() {
83+
$hex = "#01Ff03";
84+
$rgb = "rgb(1, 255, 3)";
85+
$c = new PHPWebDriver_Support_Color($hex);
86+
$this->assertEquals($rgb, $c->hex());
87+
}
88+
89+
/**
90+
* @test
91+
* @group color
92+
*/
93+
public function hexToRgba() {
94+
$hex = "#01Ff03";
95+
$rgba = "rgba(1, 255, 3, 1)";
96+
$c = new PHPWebDriver_Support_Color($hex);
97+
$this->assertEquals($rgba, $c->hex());
98+
99+
// same test data as hex3 below
100+
$hex = "#00ff33";
101+
$rgba = "rgba(0, 255, 51, 1)";
102+
$c = new PHPWebDriver_Support_Color($hex);
103+
$this->assertEquals($rgba, $c->hex());
104+
}
105+
106+
/**
107+
* @test
108+
* @group color
109+
*/
110+
public function rgbToHex() {
111+
$hex = "#01ff03";
112+
$rgb = "rgb(1, 255, 3)";
113+
$c = new PHPWebDriver_Support_Color($rgb);
114+
$this->assertEquals($hex, $c->rgb());
115+
}
116+
117+
/**
118+
* @test
119+
* @group color
120+
*/
121+
public function hex3ToRgba() {
122+
$hex = "#0f3";
123+
$rgba = "rgba(0, 255, 51, 1)";
124+
$c = new PHPWebDriver_Support_Color($hex);
125+
$this->assertEquals($rgba, $c->rgba());
126+
}
127+
128+
/**
129+
* @test
130+
* @group color
131+
*/
132+
public function hslToRgba() {
133+
$hsl = "hsl(120, 100%, 25%)";
134+
$rgba = "rgba(0, 128, 0, 1)";
135+
$c = new PHPWebDriver_Support_Color($hsl);
136+
$this->assertEquals($rgba, $c->rgba());
137+
138+
$hsl = "hsl(100, 0%, 50%)";
139+
$rgba = "rgba(128, 128, 128, 1)";
140+
$c = new PHPWebDriver_Support_Color($hsl);
141+
$this->assertEquals($rgba, $c->rgba());
142+
}
143+
144+
/**
145+
* @test
146+
* @group color
147+
*/
148+
public function hslaToRgba() {
149+
$hsla = "hsla(120, 100%, 25%, 1)";
150+
$rgba = "rgba(0, 128, 0, 1)";
151+
$c = new PHPWebDriver_Support_Color($hsla);
152+
$this->assertEquals($rgba, $c->rgba());
153+
154+
$hsla = "hsla(100, 0%, 50%, 0.5)";
155+
$rgba = "rgba(128, 128, 128, 0.5)";
156+
$c = new PHPWebDriver_Support_Color($hsla);
157+
$this->assertEquals($rgba, $c->rgba());
158+
}
159+
}

0 commit comments

Comments
 (0)