You are here

public function MediaBrowserPlusTest::testInvalidFolderCreation in Media Browser Plus 7.3

Test if invalid structures are automatically fixed.

File

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

Class

MediaBrowserPlusTest
Basic media browser plus tests.

Code

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

  // Ensure the link to the taxonomy management is available.
  // Just to have a verbose output.
  $this
    ->drupalGet('admin/content/file/mbp');
  $this
    ->assertLinkByHref('admin/structure/taxonomy/media_folders', 0, 'Found link to folder taxonomy');

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

  // Create a normal folder structure.
  $invalid_hierarchy_term = $this
    ->randomName();
  $hierarchy = array(
    'root_folder' => array(
      $this
        ->randomName() => array(
        $this
          ->randomName() => array(),
      ),
      $this
        ->randomName() => array(
        $this
          ->randomName() => array(),
      ),
    ),
    $invalid_hierarchy_term => array(
      $this
        ->randomName() => array(
        $this
          ->randomName() => array(),
      ),
    ),
  );
  $this
    ->folderCreationHelper($hierarchy, FALSE);
  $root_folder_term = media_browser_plus_get_media_root_folder();
  $folders = taxonomy_get_term_by_name($invalid_hierarchy_term);
  $folder = reset($folders);
  $parents = taxonomy_get_parents($folder->tid);
  if ($this
    ->assertEqual(count($parents), 1, 'Invalid intialized folder has a parent folder.')) {
    $this
      ->assertEqual($parents[$root_folder_term->tid]->tid, $root_folder_term->tid, 'Invalid intialized folder now belongs to the root folder.');
  }
  $path = media_browser_plus_construct_dir_path($folder);
  $this
    ->assertEqual($path, $invalid_hierarchy_term, 'Path for folder matches.');

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