| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | class Tests_colordClamp 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: The value is clamped to the minimum bound.
|
|---|
| 15 | */
|
|---|
| 16 | public function test_colord_clamp_value_below_min() {
|
|---|
| 17 | $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
|
|---|
| 18 | $result = $method->invokeArgs( null, [ -5, 0, 10 ] );
|
|---|
| 19 | $this->assertEquals( 0, $result );
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | /**
|
|---|
| 23 | * Test case: The value is clamped to the maximum bound.
|
|---|
| 24 | */
|
|---|
| 25 | public function test_colord_clamp_value_above_max() {
|
|---|
| 26 | $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
|
|---|
| 27 | $result = $method->invokeArgs( null, [ 15, 0, 10 ] );
|
|---|
| 28 | $this->assertEquals( 10, $result );
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * Test case: The value is within the bounds and not clamped.
|
|---|
| 33 | */
|
|---|
| 34 | public function test_colord_clamp_value_within_bounds() {
|
|---|
| 35 | $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
|
|---|
| 36 | $result = $method->invokeArgs( null, [ 5, 0, 10 ] );
|
|---|
| 37 | $this->assertEquals( 5, $result );
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | /**
|
|---|
| 41 | * Test case: The value equals the minimum bound.
|
|---|
| 42 | */
|
|---|
| 43 | public function test_colord_clamp_value_at_min_bound() {
|
|---|
| 44 | $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
|
|---|
| 45 | $result = $method->invokeArgs( null, [ 0, 0, 10 ] );
|
|---|
| 46 | $this->assertEquals( 0, $result );
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | /**
|
|---|
| 50 | * Test case: The value equals the maximum bound.
|
|---|
| 51 | */
|
|---|
| 52 | public function test_colord_clamp_value_at_max_bound() {
|
|---|
| 53 | $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
|
|---|
| 54 | $result = $method->invokeArgs( null, [ 10, 0, 10 ] );
|
|---|
| 55 | $this->assertEquals( 10, $result );
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | /**
|
|---|
| 59 | * Test case: Negative minimum and maximum bounds.
|
|---|
| 60 | */
|
|---|
| 61 | public function test_colord_clamp_negative_bounds() {
|
|---|
| 62 | $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
|
|---|
| 63 | $result = $method->invokeArgs( null, [ -5, -10, -1 ] );
|
|---|
| 64 | $this->assertEquals( - 5, $result );
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | /**
|
|---|
| 68 | * Helper method to access WP_Duotone's private methods for testing.
|
|---|
| 69 | *
|
|---|
| 70 | * @param string $className Class name to reflect on.
|
|---|
| 71 | * @param string $methodName Method name to retrieve.
|
|---|
| 72 | *
|
|---|
| 73 | * @return ReflectionMethod The reflected method.
|
|---|
| 74 | */
|
|---|
| 75 | private function getPrivateMethod( $className, $methodName ) {
|
|---|
| 76 | $reflection = new \ReflectionClass( $className );
|
|---|
| 77 | $method = $reflection->getMethod( $methodName );
|
|---|
| 78 | $method->setAccessible( true );
|
|---|
| 79 |
|
|---|
| 80 | return $method;
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|