You are here

protected function MediaBrowserPlusTest::folderCreationHelper in Media Browser Plus 7.2

Helper to create a folder structure based on an given array.

Parameters

array $hierarchy: An array that represents the hierarchy to create. E.g. array( 'root_folder' => array( 'level_1_1' => array( 'level_1_1_1' => array(), ), 'level_1_2' => array( 'level_1_2_1' => array(), ), ), );

boolean $run_asserts: Enable/disable the test assertions.

integer $pid: The tid of the parent the term has to be assigned to.

3 calls to MediaBrowserPlusTest::folderCreationHelper()
MediaBrowserPlusTest::testFolderCreation in tests/media_browser_plus.test
Test the ability to create folders.
MediaBrowserPlusTest::testFolderMovemet in tests/media_browser_plus.test
Test the ability to move folders.
MediaBrowserPlusTest::testMovingRootFolder in tests/media_browser_plus.test
Test the ability to move the root folder for media files.

File

tests/media_browser_plus.test, line 63
Media Browser Plus tests.

Class

MediaBrowserPlusTest
Defines media entity creation and management test cases.

Code

protected function folderCreationHelper($hierarchy, $run_asserts = TRUE, $pid = 0) {
  if (is_array($hierarchy)) {
    foreach ($hierarchy as $parent => $folder_name) {
      if ($parent == 'root_folder') {
        $folder = media_browser_plus_get_media_root_folder();
        $parent = $folder->name;
      }
      else {
        $this
          ->folderCreationHelper($parent, $run_asserts, $pid);
        $folders = taxonomy_get_term_by_name($parent);
        $folder = reset($folders);
      }
      if (!empty($folder_name)) {
        $this
          ->folderCreationHelper($folder_name, $run_asserts, $folder->tid);
      }
    }
  }
  else {
    $description = $this
      ->randomString(50);
    $edit = array(
      'name' => $hierarchy,
      'description' => $description,
      'pid' => $pid,
    );
    $this
      ->drupalPost('admin/content/file/add_folder', $edit, t('Save'));
    if ($run_asserts) {

      // Check if the creation was successful.
      $this
        ->assertText('Folder ' . $hierarchy . ' created successfully');

      // Check if the related folder was created in the filesystem.
      $folders = taxonomy_get_term_by_name($hierarchy);
      $folder = reset($folders);
      $path = media_browser_plus_construct_dir_path($folder);
      $this
        ->assertTrue(is_dir($path), format_string('Folder found. (!path)', array(
        '!path' => $path,
      )));
    }
  }
}