Skip to content
Snippets Groups Projects
Unverified Commit 3b1eea2a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2031183 by Berdir, marthinal, martin107, Krzysztof Domański, Cyberwolf,...

Issue #2031183 by Berdir, marthinal, martin107, Krzysztof Domański, Cyberwolf, tim.plunkett, jhedstrom, tassoman, jhodgdon, Kristen Pol: Improve test coverage for node authored on widget
parent 7c9ecd6c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -154,6 +154,70 @@ public function testUnpublishedNodeCreation() {
$this->assert(isset($view_link), 'The message area contains a link to a node');
}
/**
* Creates nodes with different authored dates.
*/
public function testAuthoredDate() {
$now = \Drupal::time()->getRequestTime();
$admin = $this->drupalCreateUser([], NULL, TRUE);
$this->drupalLogin($admin);
// Create a node with the default creation date.
$edit = [
'title[0][value]' => $this->randomMachineName(8),
'body[0][value]' => $this->randomMachineName(16),
];
$this->drupalPostForm('node/add/page', $edit, 'Save');
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertNotNull($node->getCreatedTime());
// Create a node with the custom creation date in the past.
$date = $now - 86400;
$edit = [
'title[0][value]' => $this->randomMachineName(8),
'body[0][value]' => $this->randomMachineName(16),
'created[0][value][date]' => date('Y-m-d', $date),
'created[0][value][time]' => date('H:i:s', $date),
];
$this->drupalPostForm('node/add/page', $edit, 'Save');
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertEquals($date, $node->getCreatedTime());
// Create a node with the custom creation date in the future.
$date = $now + 86400;
$edit = [
'title[0][value]' => $this->randomMachineName(8),
'body[0][value]' => $this->randomMachineName(16),
'created[0][value][date]' => date('Y-m-d', $date),
'created[0][value][time]' => date('H:i:s', $date),
];
$this->drupalPostForm('node/add/page', $edit, 'Save');
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertEquals($date, $node->getCreatedTime());
// Test an invalid date.
$edit = [
'title[0][value]' => $this->randomMachineName(8),
'body[0][value]' => $this->randomMachineName(16),
'created[0][value][date]' => '2013-13-13',
'created[0][value][time]' => '11:00:00',
];
$this->drupalPostForm('node/add/page', $edit, 'Save');
$this->assertSession()->pageTextContains('The Authored on date is invalid.');
$this->assertFalse($this->drupalGetNodeByTitle($edit['title[0][value]']));
// Test an invalid time.
$edit = [
'title[0][value]' => $this->randomMachineName(8),
'body[0][value]' => $this->randomMachineName(16),
'created[0][value][date]' => '2012-01-01',
'created[0][value][time]' => '30:00:00',
];
$this->drupalPostForm('node/add/page', $edit, 'Save');
$this->assertSession()->pageTextContains('The Authored on date is invalid.');
$this->assertFalse($this->drupalGetNodeByTitle($edit['title[0][value]']));
}
/**
* Tests the author autocompletion textfield.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment