function FileFieldAnonymousSubmissionTest::testAnonymousNode
Tests the basic node submission for an anonymous visitor.
File
- 
              core/
modules/ file/ tests/ src/ Functional/ FileFieldAnonymousSubmissionTest.php, line 36  
Class
- FileFieldAnonymousSubmissionTest
 - Confirm that file field submissions work correctly for anonymous visitors.
 
Namespace
Drupal\Tests\file\FunctionalCode
public function testAnonymousNode() {
  $type = 'Article';
  $title = 'test page';
  // Load the node form.
  $this->drupalLogout();
  $this->drupalGet('node/add/article');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->pageTextContains("Create {$type}");
  $edit = [
    'title[0][value]' => $title,
    'body[0][value]' => 'Test article',
  ];
  $this->submitForm($edit, 'Save');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->pageTextContains("{$type} {$title} has been created.");
  $matches = [];
  if (preg_match('@node/(\\d+)$@', $this->getUrl(), $matches)) {
    $nid = end($matches);
    $this->assertNotEquals(0, $nid, 'The node ID was extracted from the URL.');
    $node = Node::load($nid);
    $this->assertNotNull($node, 'The node was loaded successfully.');
  }
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.