function FileFieldAnonymousSubmissionTest::testAnonymousNode

Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php \Drupal\Tests\file\Functional\FileFieldAnonymousSubmissionTest::testAnonymousNode()
  2. 8.9.x core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php \Drupal\Tests\file\Functional\FileFieldAnonymousSubmissionTest::testAnonymousNode()
  3. 11.x core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php \Drupal\Tests\file\Functional\FileFieldAnonymousSubmissionTest::testAnonymousNode()

Tests the basic node submission for an anonymous visitor.

File

core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php, line 38

Class

FileFieldAnonymousSubmissionTest
Confirm that file field submissions work correctly for anonymous visitors.

Namespace

Drupal\Tests\file\Functional

Code

public function testAnonymousNode() : void {
    $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.