public function DateTimezoneTest::testDateSubfield in Double Field 8.3
Same name and namespace in other branches
- 4.x tests/src/Functional/DateTimezoneTest.php \Drupal\Tests\double_field\Functional\DateTimezoneTest::testDateSubfield()
Test callback.
File
- tests/
src/ Functional/ DateTimezoneTest.php, line 47
Class
- DateTimezoneTest
- A test for date timezone calculations.
Namespace
Drupal\Tests\double_field\FunctionalCode
public function testDateSubfield() : void {
$edit = [
'title[0][value]' => 'Example',
$this->fieldName . '[0][first][date]' => '2020-01-18',
$this->fieldName . '[0][first][time]' => '03:12:00',
$this->fieldName . '[0][second][date]' => '2020-01-15',
];
$this
->drupalPostForm('node/add/' . $this->contentTypeId, $edit, 'Save');
// -- Test formatter.
$xpath = [
'//div[@class = "double-field-first"]',
'/time[@datetime = "2020-01-18T03:12:00Z" and text() = "2020-01-18T03:12:00+0300"]',
];
$this
->assertXpath($xpath);
$xpath = [
'//div[@class = "double-field-second"]',
'/time[@datetime = "2020-01-15T15:00:00Z" and text() = "2020-01-15T12:00:00+0000"]',
];
$this
->assertXpath($xpath);
$this
->drupalGet('node/1/edit');
// -- Test widget.
$xpath = [
'//div[contains(@class, "double-field-elements")]',
sprintf('/div[@id = "edit-%s-0-first" and position() = 1]', $this->fieldName),
'/div[position() = 1]/input[@type = "date" and @value = "2020-01-18"]',
'/../..',
'/div[position() = 2]/input[@type = "time" and @value = "03:12:00"]',
];
$this
->assertXpath($xpath);
$xpath = [
'//div[contains(@class, "double-field-elements")]',
sprintf('/div[@id = "edit-%s-0-second" and position() = 2]', $this->fieldName),
'/div[position() = 1]/input[@type = "date" and @value = "2020-01-15"]',
];
$this
->assertXpath($xpath);
// Date only field should not have time element.
$xpath = [
'//div[contains(@class, "double-field-elements")]',
sprintf('/div[@id = "edit-%s-0-second" and position() = 2]', $this->fieldName),
'//input[@type = "time"]',
];
$this
->assertNoXpath($xpath);
}