1 file.test FileTypeTestCase::testTypesCrudUi()

Test file types CRUD UI.

File

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

Class

FileTypeTestCase
Tests adding support for bundles to the core 'file' entity.

Code

function testTypesCrudUi() {
  $this->backdropGet('admin/structure/file-types');
  $this->assertResponse(403, 'File types UI page is not accessible to unauthorized users.');

  $user = $this->backdropCreateUser(array('administer file types', 'administer fields'));
  $this->backdropLogin($user);

  $this->backdropGet('admin/structure/file-types');
  $this->assertResponse(200, 'File types UI page is accessible to users with adequate permission.');

  // Create new file type.
  $edit = array(
    'name' => t('Test type'),
    'type' => 'test_type',
    // 'module' => 'file',
    'description' => t('This is dummy file type used just for testing.'),
    'mimetypes' => 'image/png',
  );
  $this->backdropGet('admin/structure/file-types/add');
  $this->backdropPost(NULL, $edit, t('Save'));
  $this->assertText(t('The file type @type has been updated.', array('@type' => $edit['name'])), 'New file type successfully created.');
  $this->assertText($edit['name'], 'New file type created: name found.');
  $this->assertText($edit['description'], 'New file type created: description found.');
  $this->assertFieldByXPath("//table//td[1]//div[1]", $edit['name'], 'The label of the newly-created file type is shown in the table.');
  $this->assertFieldByXPath("//table//td[1]//div[2]", '(' . t('Machine name: @machine_name', array('@machine_name' => $edit['type'])) . ')', 'The machine name of the newly-created file type is shown in the table.');
  $this->assertFieldByXPath("//table//td[2]", $edit['description'], 'The description of the newly-created file type is shown in the table.');
  $this->assertFieldByXPath("//table//td[3]", t('Custom'), 'The storage state of the newly-created file type is shown in the table.');
  $this->assertLink(t('Disable'), 0, 'Able to disable newly created file type.');
  $this->assertLink(t('Delete'), 0, 'Able to delete newly created file type.');
  $this->assertLinkByHref('admin/structure/file-types/manage/' . str_replace('_', '-', $edit['type']) . '/disable', 0, 'Disable link disables.');
  $this->assertLinkByHref('admin/structure/file-types/manage/' . str_replace('_', '-', $edit['type']) . '/delete', 0, 'Delete link points to delete confirmation page.');
  $this->assertEqual($edit['type'], config_get('file.type.' . $edit['type'], 'type'), 'The newly-created file type is stored in config.');

  // Edit file type.
  $this->backdropGet('admin/structure/file-types/manage/' . $edit['type'] . '/edit');
  $this->assertRaw(t('Save'), 'Save button found on edit page.');
  $this->assertRaw(t('Delete'), 'Delete button found on edit page.');
  $this->assertRaw($edit['name'], 'name found on file type edit page');
  $this->assertText($edit['description'], 'Description found on file type edit page');
  $this->assertText($edit['mimetypes'], 'Mime-type configuration found on file type edit page');
  $this->assertText(t('Available media types'), 'Mimetype list present on edit form.');

  // Modify file type.
  $edit['name'] = t('New type name');
  $this->backdropPost(NULL, array('name' => $edit['name']), t('Save'));
  $this->assertRaw(t('The file type %type has been updated.', array('%type' => $edit['name'])), 'File type was modified.');
  $this->assertText($edit['name'], 'Modified name found on file types list.');
  $this->assertEqual($edit['name'], config_get('file.type.' . $edit['type'], 'name'), 'The file type name was updated in config.');

  // Disable and re-enable file type.
  $url_type = str_replace('_', '-', $edit['type']);
  $this->clickFileTypeOperationLink(t('Disable'), $url_type . '/disable');
  $this->assertTrue(config_get('file.type.' . $edit['type'], 'disabled'), 'The file type was disabled in config.');
  $this->assertRaw(t('The file type %type has been disabled.', array('%type' => $edit['name'])), 'Disable confirmation message found.');
  $this->assertLink(t('Enable'), 0, 'Able to re-enable newly created file type.');
  $this->clickFileTypeOperationLink(t('Enable'), $url_type . '/enable');
  $this->assertFalse(config_get('file.type.' . $edit['type'], 'disabled'), 'The file type was enabled in config.');
  $this->assertRaw(t('The file type %type has been enabled.', array('%type' => $edit['name'])), 'Enable confirmation message found.');
  $this->assertLink(t('Disable'), 0, 'Able to disable newly created file type again.');

  // Delete newly created type.
  $this->backdropGet('admin/structure/file-types/manage/' . $edit['type'] . '/delete');
  $this->assertText(t('Are you sure you want to delete the file type @type?', array('@type' => $edit['name'])), 'Delete confirmation page found.');
  $this->backdropPost(NULL, array(), t('Delete'));
  $this->assertRaw(t('The file type %type has been deleted.', array('%type' => $edit['name'])), 'Delete confirmation message found.');
  $this->backdropGet('admin/structure/file-types');
  $this->assertNoText($edit['name'], 'File type successfully deleted.');

  // Edit exported file type.
  $this->backdropGet('admin/structure/file-types/manage/image/edit');
  $this->assertRaw(t('Image'), 'name found on file type edit page');
  $this->assertText("image/*", 'Mime-type configuration found on file type edit page');
  $this->backdropPost(NULL, array('name' => t('Funky images')), t('Save'));
  $this->assertText(t('The file type @type has been updated.', array('@type' => t('Funky images'))), 'File type was modified.');
  $this->assertText(t('Funky image'), 'Modified name found on file types list.');
  $this->assertLink(t('Revert'), 0, 'Able to revert overridden file type.');
  $this->assertLinkByHref('admin/structure/file-types/manage/image/revert', 0, 'Revert link points to revert confirmation page.');

  // Revert file type.
  $this->backdropGet('admin/structure/file-types/manage/image/revert');
  $this->assertText(t('Are you sure you want to revert the file type @type?', array('@type' => t('Funky images'))), 'Revert confirmation page found.');
  $this->backdropPost(NULL, array(), t('Revert'));
  $this->assertText(t('The file type @type has been reverted.', array('@type' => t('Funky images'))), 'Revert confirmation message found.');

  $this->assertText(t('Image'), 'Reverted file type found in list.');
  $this->assertNoText(t('Overridden'), 'No overridden file types remain.');
}