<?php

class Tests_colordClampHue extends WP_UnitTestCase {

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

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

  /**
   * Test case: A negative degree (angle) is clamped.
   */
  public function test_colord_clamp_hue_negative_value() {
    $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
    $result = $method->invokeArgs( null, [ -1 ] );
    $this->assertEquals( 359, $result );
  }

  /**
   * Test case: An angle that's greater than 360 is clamped.
   */
  public function test_colord_clamp_hue_value_above_max() {
    $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
    $result = $method->invokeArgs( null, [ 361 ] );
    $this->assertEquals( 1, $result );
  }

  /**
   * Test case: The value is a valid angle and not clamped.
   */
  public function test_colord_clamp_hue_value_within_bounds() {
   $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
   $result = $method->invokeArgs( null, [ 42 ] );
   $this->assertEquals( 42, $result );
 }

  /**
   * Test case: A zero degree angle is clamped to be 360 (a circle).
   */
  public function test_colord_clamp_hue_value_at_zero() {
   $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );
   $result = $method->invokeArgs( null, [ 0 ] );
   $this->assertEquals( 360, $result );
 }

  /**
   * Test case: The angle is NaN
   */
  public function test_colord_clamp_hue_value_nan() {
    $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );   
    $result = $method->invokeArgs( null, [ NAN ] );
    $this->assertEquals( 360, $result );
  }

  /**
   * Test case: The angle is Inf
   */
  public function test_colord_clamp_hue_value_inf() {
    $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );   
    $result = $method->invokeArgs( null, [ INF ] );
    $this->assertEquals( 360, $result );
  }

  /**
   * Test case: The angle is -Inf
   */
  public function test_colord_clamp_hue_value_negative_inf() {
    $method = $this->getPrivateMethod( 'WP_Duotone', 'colord_clamp_hue' );   
    $result = $method->invokeArgs( null, [ -INF ] );
    $this->assertEquals( 360, $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;
  }
}
