You are here

public function FileFieldAnonymousSubmissionTest::testAnonymousNode in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php \Drupal\Tests\file\Functional\FileFieldAnonymousSubmissionTest::testAnonymousNode()
  2. 9 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 36

Class

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

Namespace

Drupal\Tests\file\Functional

Code

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.');
  }
}