You are here

public function MediaBrowserPlusTest::testFolderDeletionWithUsedFiles in Media Browser Plus 7.3

Test the ability to delete folders when files are used.

File

tests/media_browser_plus.test, line 298
Media Browser Plus basic tests.

Class

MediaBrowserPlusTest
Basic media browser plus tests.

Code

public function testFolderDeletionWithUsedFiles() {
  $this
    ->drupalLogin($this->adminUser);

  // Create test folder structure.
  $folders = array(
    'source' => $this
      ->randomName(),
    'source_child' => $this
      ->randomName(),
    'source_child_child' => $this
      ->randomName(),
  );
  $hierarchy = array(
    'root_folder' => array(
      $folders['source'] => array(
        $folders['source_child'] => array(
          $folders['source_child_child'] => array(),
        ),
      ),
    ),
  );
  $this
    ->folderCreationHelper($hierarchy, FALSE);

  // Create test files.
  $files = array();
  foreach ($folders as $type => $folder_name) {
    $terms = taxonomy_get_term_by_name($folder_name);
    $folder = $folders[$type] = reset($terms);
    foreach (media_get_local_stream_wrappers() as $scheme => $scheme_info) {
      $files[$scheme][$type][] = $this
        ->createTestFile('text/plain', $folder, $scheme);
      $files[$scheme][$type][] = $file = $this
        ->createTestFile('image/jpg', $folder, $scheme);

      // Mark one file as used.
      file_usage_add($file, 'node', 'node', 1);
    }
  }

  // Just to have a verbose output.
  $this
    ->drupalGet('admin/content/file/list');
  $folder_path = media_browser_plus_construct_dir_path($folders['source']);

  // Delete the folder.
  $this
    ->drupalPost('taxonomy/term/' . $folders['source']->tid . '/edit', array(), t('Delete'));
  $this
    ->drupalPost(NULL, array(), t('Delete'));
  foreach (media_get_local_stream_wrappers() as $scheme => $scheme_info) {
    $directory = file_stream_wrapper_uri_normalize($scheme . '://' . $folder_path);
    $this
      ->assertTrue(file_exists($directory), 'Folder still exists');
  }

  // Just to have a verbose output.
  $this
    ->drupalGet('admin/structure/taxonomy/media_folders');
}