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
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api\Unit\DateDataTypeTest
Expanded class hierarchy of DateDataTypeTest
File
- tests/
src/ Unit/ DateDataTypeTest.php, line 15
Namespace
Drupal\Tests\search_api\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DateDataTypeTest:: |
protected | property | The data type plugin to test. | |
DateDataTypeTest:: |
public | function | Provides test data for testGetValue(). | |
DateDataTypeTest:: |
protected | function |
Overrides UnitTestCase:: |
|
DateDataTypeTest:: |
public | function | Tests value conversion. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |