<?php

class Tests_colordClamp extends WP_UnitTestCase {

  public function set_up() {
    parent::set_up();
  }

  public function tear_down() {
    parent::tear_down();
  }

  /**
   * Test case: The value is clamped to the minimum bound.
   */
  public function test_colord_clamp_value_below_min() {
    $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
    $result = $method->invokeArgs( null, [ -5, 0, 10 ] );
    $this->assertEquals( 0, $result );
  }

  /**
   * Test case: The value is clamped to the maximum bound.
   */
  public function test_colord_clamp_value_above_max() {
   $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
   $result = $method->invokeArgs( null, [ 15, 0, 10 ] );
   $this->assertEquals( 10, $result );
 }

  /**
   * Test case: The value is within the bounds and not clamped.
   */
  public function test_colord_clamp_value_within_bounds() {
   $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
   $result = $method->invokeArgs( null, [ 5, 0, 10 ] );
   $this->assertEquals( 5, $result );
 }

  /**
   * Test case: The value equals the minimum bound.
   */
  public function test_colord_clamp_value_at_min_bound() {
   $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
   $result = $method->invokeArgs( null, [ 0, 0, 10 ] );
   $this->assertEquals( 0, $result );
 }

  /**
   * Test case: The value equals the maximum bound.
   */
  public function test_colord_clamp_value_at_max_bound() {
   $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
   $result = $method->invokeArgs( null, [ 10, 0, 10 ] );
   $this->assertEquals( 10, $result );
 }

  /**
   * Test case: Negative minimum and maximum bounds.
   */
  public function test_colord_clamp_negative_bounds() {
   $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp' );
   $result = $method->invokeArgs( null, [ -5, -10, -1 ] );
   $this->assertEquals( - 5, $result );
 }

  /**
   * Helper method to access WP_Duotone's private methods for testing.
   *
   * @param string $className Class name to reflect on.
   * @param string $methodName Method name to retrieve.
   *
   * @return ReflectionMethod The reflected method.
   */
  private function getPrivateMethod( $className, $methodName ) {
   $reflection = new \ReflectionClass( $className );
   $method     = $reflection->getMethod( $methodName );
   $method->setAccessible( true );

   return $method;
 }
}
