Mercurial > hg > isophonics-drupal-site
comparison core/modules/node/tests/src/Functional/NodeCreationTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
58 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); | 58 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); |
59 $this->assertTrue($node, 'Node found in database.'); | 59 $this->assertTrue($node, 'Node found in database.'); |
60 | 60 |
61 // Verify that pages do not show submitted information by default. | 61 // Verify that pages do not show submitted information by default. |
62 $this->drupalGet('node/' . $node->id()); | 62 $this->drupalGet('node/' . $node->id()); |
63 $this->assertNoText($node->getOwner()->getUsername()); | 63 $this->assertNoText($node->getOwner()->getAccountName()); |
64 $this->assertNoText(format_date($node->getCreatedTime())); | 64 $this->assertNoText($this->container->get('date.formatter')->format($node->getCreatedTime())); |
65 | 65 |
66 // Change the node type setting to show submitted by information. | 66 // Change the node type setting to show submitted by information. |
67 /** @var \Drupal\node\NodeTypeInterface $node_type */ | 67 /** @var \Drupal\node\NodeTypeInterface $node_type */ |
68 $node_type = $node_type_storage->load('page'); | 68 $node_type = $node_type_storage->load('page'); |
69 $node_type->setDisplaySubmitted(TRUE); | 69 $node_type->setDisplaySubmitted(TRUE); |
70 $node_type->save(); | 70 $node_type->save(); |
71 | 71 |
72 $this->drupalGet('node/' . $node->id()); | 72 $this->drupalGet('node/' . $node->id()); |
73 $this->assertText($node->getOwner()->getUsername()); | 73 $this->assertText($node->getOwner()->getAccountName()); |
74 $this->assertText(format_date($node->getCreatedTime())); | 74 $this->assertText($this->container->get('date.formatter')->format($node->getCreatedTime())); |
75 | 75 |
76 // Check if the node revision checkbox is not rendered on node creation form. | 76 // Check if the node revision checkbox is not rendered on node creation form. |
77 $admin_user = $this->drupalCreateUser(['administer nodes', 'create page content']); | 77 $admin_user = $this->drupalCreateUser(['administer nodes', 'create page content']); |
78 $this->drupalLogin($admin_user); | 78 $this->drupalLogin($admin_user); |
79 $this->drupalGet('node/add/page'); | 79 $this->drupalGet('node/add/page'); |
150 $this->assertText(t('@post @title has been created.', ['@post' => 'Basic page', '@title' => $edit['title[0][value]']])); | 150 $this->assertText(t('@post @title has been created.', ['@post' => 'Basic page', '@title' => $edit['title[0][value]']])); |
151 | 151 |
152 // Verify that the creation message contains a link to a node. | 152 // Verify that the creation message contains a link to a node. |
153 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']); | 153 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']); |
154 $this->assert(isset($view_link), 'The message area contains a link to a node'); | 154 $this->assert(isset($view_link), 'The message area contains a link to a node'); |
155 } | |
156 | |
157 /** | |
158 * Creates nodes with different authored dates. | |
159 */ | |
160 public function testAuthoredDate() { | |
161 $now = \Drupal::time()->getRequestTime(); | |
162 $admin = $this->drupalCreateUser([], NULL, TRUE); | |
163 $this->drupalLogin($admin); | |
164 | |
165 // Create a node with the default creation date. | |
166 $edit = [ | |
167 'title[0][value]' => $this->randomMachineName(8), | |
168 'body[0][value]' => $this->randomMachineName(16), | |
169 ]; | |
170 $this->drupalPostForm('node/add/page', $edit, 'Save'); | |
171 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); | |
172 $this->assertNotNull($node->getCreatedTime()); | |
173 | |
174 // Create a node with the custom creation date in the past. | |
175 $date = $now - 86400; | |
176 $edit = [ | |
177 'title[0][value]' => $this->randomMachineName(8), | |
178 'body[0][value]' => $this->randomMachineName(16), | |
179 'created[0][value][date]' => date('Y-m-d', $date), | |
180 'created[0][value][time]' => date('H:i:s', $date), | |
181 ]; | |
182 $this->drupalPostForm('node/add/page', $edit, 'Save'); | |
183 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); | |
184 $this->assertEquals($date, $node->getCreatedTime()); | |
185 | |
186 // Create a node with the custom creation date in the future. | |
187 $date = $now + 86400; | |
188 $edit = [ | |
189 'title[0][value]' => $this->randomMachineName(8), | |
190 'body[0][value]' => $this->randomMachineName(16), | |
191 'created[0][value][date]' => date('Y-m-d', $date), | |
192 'created[0][value][time]' => date('H:i:s', $date), | |
193 ]; | |
194 $this->drupalPostForm('node/add/page', $edit, 'Save'); | |
195 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); | |
196 $this->assertEquals($date, $node->getCreatedTime()); | |
197 | |
198 // Test an invalid date. | |
199 $edit = [ | |
200 'title[0][value]' => $this->randomMachineName(8), | |
201 'body[0][value]' => $this->randomMachineName(16), | |
202 'created[0][value][date]' => '2013-13-13', | |
203 'created[0][value][time]' => '11:00:00', | |
204 ]; | |
205 $this->drupalPostForm('node/add/page', $edit, 'Save'); | |
206 $this->assertSession()->pageTextContains('The Authored on date is invalid.'); | |
207 $this->assertFalse($this->drupalGetNodeByTitle($edit['title[0][value]'])); | |
208 | |
209 // Test an invalid time. | |
210 $edit = [ | |
211 'title[0][value]' => $this->randomMachineName(8), | |
212 'body[0][value]' => $this->randomMachineName(16), | |
213 'created[0][value][date]' => '2012-01-01', | |
214 'created[0][value][time]' => '30:00:00', | |
215 ]; | |
216 $this->drupalPostForm('node/add/page', $edit, 'Save'); | |
217 $this->assertSession()->pageTextContains('The Authored on date is invalid.'); | |
218 $this->assertFalse($this->drupalGetNodeByTitle($edit['title[0][value]'])); | |
155 } | 219 } |
156 | 220 |
157 /** | 221 /** |
158 * Tests the author autocompletion textfield. | 222 * Tests the author autocompletion textfield. |
159 */ | 223 */ |