You are here

public function FileFieldPathsGeneralTestCase::testAddField in File (Field) Paths 7

Test that the File (Field) Paths UI works as expected.

File

tests/filefield_paths.general.test, line 26
Tests for the File (Field) Paths module.

Class

FileFieldPathsGeneralTestCase
Class FileFieldPathsGeneralTestCase

Code

public function testAddField() {

  // Create a File field.
  $field_name = drupal_strtolower($this
    ->randomName());
  $instance_settings = array(
    'file_directory' => "fields/{$field_name}",
  );
  $this
    ->createFileField($field_name, $this->content_type, array(), $instance_settings);

  // Ensure File (Field) Paths settings are present.
  $this
    ->drupalGet("admin/structure/types/manage/{$this->content_type}/fields/{$field_name}");
  $this
    ->assertText('Enable File (Field) Paths?', t('File (Field) Path settings are present.'));

  // Ensure that 'Enable File (Field) Paths?' is a direct sibling of
  // 'File (Field) Path settings'.
  $element = $this
    ->xpath('//div[contains(@class, :class)]/following-sibling::*[1]/@id', array(
    ':class' => 'form-item-instance-settings-filefield-paths-enabled',
  ));
  $this
    ->assert(isset($element[0]) && 'edit-instance-settings-filefield-paths' == (string) $element[0], t('Enable checkbox is next to settings fieldset.'));

  // Ensure that the File path used the File directory as it's default value.
  $this
    ->assertFieldByName('instance[settings][filefield_paths][file_path][value]', "fields/{$field_name}");
}