1 file.test protected FileFieldAnonymousSubmission::_testNodeWithFileWithoutTitle()

Helper method to test file submissions with missing node titles.

File

core/modules/file/tests/file.test, line 2051
Tests for file.module.

Class

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

Code

protected function _testNodeWithFileWithoutTitle() {
  $type_name = 'page';
  $bundle_label = 'Page';
  $node_title = 'Test page';

  $field_name = strtolower($this->randomName());
  $this->createFileField($field_name, $type_name);

  // Load the node form.
  $this->backdropGet('node/add/page');
  $this->assertResponse(200, 'Loaded the page node form.');
  $this->assertText(strip_tags(t('Create @name', array('@name' => $bundle_label))));

  // Generate a file.
  $test_file = $this->getTestFile('text');

  // Submit the form but exclude the title field.
  $edit = array(
    'body[und][0][value]' => 'Test page',
    'body[und][0][format]' => 'filtered_html',
    'files[' . $field_name . '_und_0]' => backdrop_realpath($test_file->uri),
    'path[auto]' => FALSE,
    'path[alias]' => '',
  );
  $this->backdropPost(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->backdropPost(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_name}[LANGUAGE_NONE][0]['filename'], $test_file->filename, 'The file was uploaded successfully.');
  }
}