Make WordPress Core

Ticket #64113: colordClampHue.php

File colordClampHue.php, 2.7 KB (added by fishtron, 12 months ago)

tests/phpunit/tests/wp-duotone/colordClampHue.php

Line 
1<?php
2
3class Tests_colordClampHue extends WP_UnitTestCase {
4
5 public function set_up() {
6 parent::set_up();
7 }
8
9 public function tear_down() {
10 parent::tear_down();
11 }
12
13 /**
14 * Test case: A negative degree (angle) is clamped.
15 */
16 public function test_colord_clamp_hue_negative_value() {
17 $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
18 $result = $method->invokeArgs( null, [ -1 ] );
19 $this->assertEquals( 359, $result );
20 }
21
22 /**
23 * Test case: An angle that's greater than 360 is clamped.
24 */
25 public function test_colord_clamp_hue_value_above_max() {
26 $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
27 $result = $method->invokeArgs( null, [ 361 ] );
28 $this->assertEquals( 1, $result );
29 }
30
31 /**
32 * Test case: The value is a valid angle and not clamped.
33 */
34 public function test_colord_clamp_hue_value_within_bounds() {
35 $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
36 $result = $method->invokeArgs( null, [ 42 ] );
37 $this->assertEquals( 42, $result );
38 }
39
40 /**
41 * Test case: A zero degree angle is clamped to be 360 (a circle).
42 */
43 public function test_colord_clamp_hue_value_at_zero() {
44 $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
45 $result = $method->invokeArgs( null, [ 0 ] );
46 $this->assertEquals( 360, $result );
47 }
48
49 /**
50 * Test case: The angle is NaN
51 */
52 public function test_colord_clamp_hue_value_nan() {
53 $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
54 $result = $method->invokeArgs( null, [ NAN ] );
55 $this->assertEquals( 360, $result );
56 }
57
58 /**
59 * Test case: The angle is Inf
60 */
61 public function test_colord_clamp_hue_value_inf() {
62 $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
63 $result = $method->invokeArgs( null, [ INF ] );
64 $this->assertEquals( 360, $result );
65 }
66
67 /**
68 * Test case: The angle is -Inf
69 */
70 public function test_colord_clamp_hue_value_negative_inf() {
71 $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
72 $result = $method->invokeArgs( null, [ -INF ] );
73 $this->assertEquals( 360, $result );
74 }
75
76 /**
77 * Helper method to access WP_Duotone's private methods for testing.
78 *
79 * @param string $className Class name to reflect on.
80 * @param string $methodName Method name to retrieve.
81 *
82 * @return ReflectionMethod The reflected method.
83 */
84 private function getPrivateMethod( $className, $methodName ) {
85 $reflection = new \ReflectionClass( $className );
86 $method = $reflection->getMethod( $methodName );
87 $method->setAccessible( true );
88
89 return $method;
90 }
91}