class SqliteDateSqlTest
Same name in other branches
- 9 core/modules/views/tests/src/Unit/Plugin/views/query/SqliteDateSqlTest.php \Drupal\Tests\views\Unit\Plugin\views\query\SqliteDateSqlTest
- 8.9.x core/modules/views/tests/src/Unit/Plugin/views/query/SqliteDateSqlTest.php \Drupal\Tests\views\Unit\Plugin\views\query\SqliteDateSqlTest
- 11.x core/modules/views/tests/src/Unit/Plugin/views/query/SqliteDateSqlTest.php \Drupal\Tests\views\Unit\Plugin\views\query\SqliteDateSqlTest
Tests the MySQL-specific date query handler.
@coversDefaultClass \Drupal\views\Plugin\views\query\SqliteDateSql
@group views
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\views\Unit\Plugin\views\query\SqliteDateSqlTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of SqliteDateSqlTest
File
-
core/
modules/ views/ tests/ src/ Unit/ Plugin/ views/ query/ SqliteDateSqlTest.php, line 20
Namespace
Drupal\Tests\views\Unit\Plugin\views\queryView source
class SqliteDateSqlTest extends UnitTestCase {
/**
* The mocked database service.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->database = $this->prophesize(Connection::class)
->reveal();
}
/**
* Tests the getDateField method.
*
* @covers ::getDateField
*/
public function testGetDateField() : void {
$date_sql = new SqliteDateSql($this->database);
$expected = "strftime('%s', foo.field)";
$this->assertEquals($expected, $date_sql->getDateField('foo.field', TRUE));
$expected = 'foo.field';
$this->assertEquals($expected, $date_sql->getDateField('foo.field', FALSE));
}
/**
* Tests date formatting replacement.
*
* @covers ::getDateFormat
*
* @dataProvider providerTestGetDateFormat
*/
public function testGetDateFormat($field, $format, $expected) : void {
$date_sql = new SqliteDateSql($this->database);
$this->assertEquals($expected, $date_sql->getDateFormat($field, $format));
}
/**
* Provider for date formatting test.
*/
public static function providerTestGetDateFormat() {
return [
[
'foo.field',
'Y-y-M-m',
"strftime('%Y-%Y-%m-%m', foo.field, 'unixepoch')",
],
[
'bar.field',
'n-F D d l',
"strftime('%m-%m %d %d %d', bar.field, 'unixepoch')",
],
[
'baz.bar_field',
'j/W/H-h i s A',
"strftime('%d/%W/%H-%H %M %S ', baz.bar_field, 'unixepoch')",
],
[
'foo.field',
'W',
"CAST(((strftime('%j', date(strftime('%Y-%m-%d', foo.field, 'unixepoch'), '-3 days', 'weekday 4')) - 1) / 7 + 1) AS NUMERIC)",
],
];
}
/**
* Tests timezone offset formatting.
*
* @covers ::setFieldTimezoneOffset
*/
public function testSetFieldTimezoneOffset() : void {
$date_sql = new SqliteDateSql($this->database);
$field = 'foobar.field';
$date_sql->setFieldTimezoneOffset($field, 42);
$this->assertEquals("(foobar.field + 42)", $field);
}
/**
* Tests setting the database offset.
*
* @covers ::setTimezoneOffset
*/
public function testSetTimezoneOffset() : void {
$database = $this->prophesize(Connection::class);
$database->query()
->shouldNotBeCalled();
$date_sql = new SqliteDateSql($database->reveal());
$date_sql->setTimezoneOffset(42);
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
SqliteDateSqlTest::$database | protected | property | The mocked database service. | |||
SqliteDateSqlTest::providerTestGetDateFormat | public static | function | Provider for date formatting test. | |||
SqliteDateSqlTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
SqliteDateSqlTest::testGetDateField | public | function | Tests the getDateField method. | |||
SqliteDateSqlTest::testGetDateFormat | public | function | Tests date formatting replacement. | |||
SqliteDateSqlTest::testSetFieldTimezoneOffset | public | function | Tests timezone offset formatting. | |||
SqliteDateSqlTest::testSetTimezoneOffset | public | function | Tests setting the database offset. | |||
UnitTestCase::$root | protected | property | The app root. | 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::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.