You are here

class TimeTest in Time Field For Drupal 8.x / 9.x 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/TimeTest.php \Drupal\Tests\time_field\Unit\TimeTest

Tests time.

@group time_field

Hierarchy

  • class \Drupal\Tests\time_field\Unit\TimeTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of TimeTest

File

tests/src/Unit/TimeTest.php, line 13

Namespace

Drupal\Tests\time_field\Unit
View source
class TimeTest extends TestCase {

  /**
   * Tests Time class creation.
   */
  public function testCreationWithInvalidArguments() {
    $this
      ->expectException(\InvalidArgumentException::class);
    new Time(50);
  }

  /**
   * Test it can be created by html5 string.
   */
  public function testItCanBeCreatedByHtml5String() {
    $time = Time::createFromHtml5Format('13:40:30');
    $this
      ->assertEquals('13', $time
      ->getHour());
    $this
      ->assertEquals('40', $time
      ->getMinute());
    $this
      ->assertEquals('30', $time
      ->getSecond());
    $time = Time::createFromHtml5Format('14:50');
    $this
      ->assertEquals('14', $time
      ->getHour());
    $this
      ->assertEquals('50', $time
      ->getMinute());
    $this
      ->assertEquals('0', $time
      ->getSecond());
  }

  /**
   * Test time can attach to specific date.
   */
  public function testTimeOnDate() {
    $time = new Time(13, 40, 30);
    $dateTime = $time
      ->on(new \DateTime());
    $this
      ->assertEquals('13:40:30', $dateTime
      ->format('H:i:s'));
  }

  /**
   * Test it can be created from day timestamp.
   */
  public function testItCanBeCreatedFromDayTimestamp() {
    $time = Time::createFromTimestamp(3700);
    $this
      ->assertEquals('01:01:40', $time
      ->format('H:i:s'));
  }

  /**
   * Test it formats for widgets in expected format.
   */
  public function testItFormatsForWidgetsInExpectedFormat() {
    $time = new Time(13, 40, 30);
    $this
      ->assertEquals('13:40:30', $time
      ->formatForWidget());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TimeTest::testCreationWithInvalidArguments public function Tests Time class creation.
TimeTest::testItCanBeCreatedByHtml5String public function Test it can be created by html5 string.
TimeTest::testItCanBeCreatedFromDayTimestamp public function Test it can be created from day timestamp.
TimeTest::testItFormatsForWidgetsInExpectedFormat public function Test it formats for widgets in expected format.
TimeTest::testTimeOnDate public function Test time can attach to specific date.