You are here

class DateDataTypeTest in Search API 8

Tests functionality of the "Date" data type plugin.

@coversDefaultClass \Drupal\search_api\Plugin\search_api\data_type\DateDataType

@group search_api

Hierarchy

Expanded class hierarchy of DateDataTypeTest

File

tests/src/Unit/DateDataTypeTest.php, line 15

Namespace

Drupal\Tests\search_api\Unit
View source
class DateDataTypeTest extends UnitTestCase {

  /**
   * The data type plugin to test.
   *
   * @var \Drupal\search_api\Plugin\search_api\data_type\DateDataType
   */
  protected $plugin;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Make sure the default timezone isn't UTC.
    date_default_timezone_set('America/Chicago');
    $this->plugin = new DateDataType([], '', []);
  }

  /**
   * Tests value conversion.
   *
   * @param mixed $value
   *   The incoming value.
   * @param int $expected
   *   The expected converted value.
   *
   * @dataProvider getValueTestDataProvider
   */
  public function testGetValue($value, $expected) {
    $value = $this->plugin
      ->getValue($value);
    $this
      ->assertSame($expected, $value);
  }

  /**
   * Provides test data for testGetValue().
   *
   * @return array[]
   *   An array of argument arrays for testGetValue().
   *
   * @see \Drupal\Tests\search_api\Unit\DateDataTypeTest::testGetValue()
   */
  public function getValueTestDataProvider() {
    $t = 1400000000;
    $f = 'Y-m-d H:i:s';
    return [
      'timestamp' => [
        $t,
        $t,
      ],
      'string timestamp' => [
        "{$t}",
        $t,
      ],
      'float timestamp' => [
        $t + 0.12,
        $t,
      ],
      'date string' => [
        gmdate($f, $t),
        $t,
      ],
      'date string with timezone' => [
        date($f . 'P', $t),
        $t,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DateDataTypeTest::$plugin protected property The data type plugin to test.
DateDataTypeTest::getValueTestDataProvider public function Provides test data for testGetValue().
DateDataTypeTest::setUp protected function Overrides UnitTestCase::setUp
DateDataTypeTest::testGetValue public function Tests value conversion.
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.
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.