You are here

class TimeTest in Node Revision Delete 8

Tests the Time class methods.

@group node_revision_delete @coversDefaultClass \Drupal\node_revision_delete\Utility\Time

Hierarchy

Expanded class hierarchy of TimeTest

File

tests/src/Unit/Utility/TimeTest.php, line 14

Namespace

Drupal\Tests\node_revision_delete\Unit\Utility
View source
class TimeTest extends UnitTestCase {

  /**
   * Tests the convertWordToTime() method.
   *
   * @param int $expected
   *   The expected result from calling the function.
   * @param string $word
   *   The old word to map.
   *
   * @covers ::convertWordToTime
   * @dataProvider providerConvertWordToTime
   */
  public function testConvertWordToTime($expected, $word) {

    // Testing the function.
    $this
      ->assertEquals($expected, Time::convertWordToTime($word));
  }

  /**
   * Data provider for testConvertWordToTime().
   *
   * @return array
   *   An array of arrays, each containing:
   *   - 'expected' - Expected return from Time::convertWordToTime().
   *   - 'word' - The old word to map.
   *
   * @see testConvertWordToTime()
   */
  public function providerConvertWordToTime() {
    $all_values = [
      'never' => '-1',
      'every_time' => '0',
      'every_hour' => '3600',
      'everyday' => '86400',
      'every_week' => '604800',
      'every_10_days' => '864000',
      'every_15_days' => '1296000',
      'every_month' => '2592000',
      'every_3_months' => '7776000',
      'every_6_months' => '15552000',
      'every_year' => '31536000',
      'every_2_years' => '63072000',
    ];
    $tests[] = [
      $all_values,
      NULL,
    ];
    $tests[] = [
      $all_values['never'],
      'never',
    ];
    $tests[] = [
      $all_values['every_time'],
      'every_time',
    ];
    $tests[] = [
      $all_values['every_hour'],
      'every_hour',
    ];
    $tests[] = [
      $all_values['everyday'],
      'everyday',
    ];
    $tests[] = [
      $all_values['every_week'],
      'every_week',
    ];
    $tests[] = [
      $all_values['every_10_days'],
      'every_10_days',
    ];
    $tests[] = [
      $all_values['every_15_days'],
      'every_15_days',
    ];
    $tests[] = [
      $all_values['every_month'],
      'every_month',
    ];
    $tests[] = [
      $all_values['every_3_months'],
      'every_3_months',
    ];
    $tests[] = [
      $all_values['every_6_months'],
      'every_6_months',
    ];
    $tests[] = [
      $all_values['every_year'],
      'every_year',
    ];
    $tests[] = [
      $all_values['every_2_years'],
      'every_2_years',
    ];
    return $tests;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
TimeTest::providerConvertWordToTime public function Data provider for testConvertWordToTime().
TimeTest::testConvertWordToTime public function Tests the convertWordToTime() method.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340