function FileFieldAnonymousSubmission::_testNodeWithFileWithoutTitle

Helper method to test file submissions with missing node titles.

2 calls to FileFieldAnonymousSubmission::_testNodeWithFileWithoutTitle()
FileFieldAnonymousSubmission::testAnonymousNodeWithFileWithoutTitle in modules/file/tests/file.test
Tests file submission for an anonymous visitor with a missing node title.
FileFieldAnonymousSubmission::testAuthenticatedNodeWithFileWithoutTitle in modules/file/tests/file.test
Tests file submission for an authenticated user with a missing node title.

File

modules/file/tests/file.test, line 1886

Class

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

Code

protected function _testNodeWithFileWithoutTitle() {
    $bundle_label = 'Article';
    $node_title = 'Test page';
    // Load the node form.
    $this->drupalGet('node/add/article');
    $this->assertResponse(200, 'Loaded the article node form.');
    $this->assertText(strip_tags(t('Create @name', array(
        '@name' => $bundle_label,
    ))));
    // Generate an image file.
    $image = $this->getTestImage();
    // Submit the form but exclude the title field.
    $edit = array(
        'body[und][0][value]' => 'Test article',
        'body[und][0][format]' => 'filtered_html',
        'files[field_image_und_0]' => drupal_realpath($image->uri),
    );
    $this->drupalPost(NULL, $edit, t('Save'));
    $this->assertResponse(200);
    $t_args = array(
        '@type' => $bundle_label,
        '%title' => $node_title,
    );
    $this->assertNoText(strip_tags(t('@type %title has been created.', $t_args)), 'The node was created.');
    $this->assertText(t('!name field is required.', array(
        '!name' => t('Title'),
    )));
    // Submit the form again but this time with the missing title field. This
    // should still work.
    $edit = array(
        'title' => $node_title,
    );
    $this->drupalPost(NULL, $edit, t('Save'));
    // Confirm the final submission actually worked.
    $t_args = array(
        '@type' => $bundle_label,
        '%title' => $node_title,
    );
    $this->assertText(strip_tags(t('@type %title has been created.', $t_args)), 'The node was created.');
    $matches = array();
    if (preg_match('@node/(\\d+)$@', $this->getUrl(), $matches)) {
        $nid = end($matches);
        $this->assertNotEqual($nid, 0, 'The node ID was extracted from the URL.');
        $node = node_load($nid);
        $this->assertNotEqual($node, NULL, 'The node was loaded successfully.');
        $this->assertEqual($node->field_image[LANGUAGE_NONE][0]['filename'], $image->filename, 'The image was uploaded successfully.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.