protected function MediaBrowserPlusTestBase::folderCreationHelper in Media Browser Plus 7.3
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(), ), ), );
bool $run_asserts: Enable/disable the test assertions.
int $pid: The tid of the parent the term has to be assigned to.
10 calls to MediaBrowserPlusTestBase::folderCreationHelper()
- MediaBrowserPlusBypassTest::testBypassDueProperty in tests/
media_browser_plus.mbp_bypass.test - Test the ability to bypass folder processing setting mbp_bypass property.
- MediaBrowserPlusRootFolderTest::testMovingRootFolder in tests/
media_browser_plus.root_folder.test - Test the ability to move the root folder for media files.
- MediaBrowserPlusTest::testFileMovement in tests/
media_browser_plus.test - Test the ability to delete folders.
- MediaBrowserPlusTest::testFolderCreation in tests/
media_browser_plus.test - Test the ability to create folders.
- MediaBrowserPlusTest::testFolderDeletion in tests/
media_browser_plus.test - Test the ability to delete folders.
File
- tests/
media_browser_plus.base.test, line 60 - Media Browser Plus tests base.
Class
- MediaBrowserPlusTestBase
- Provides some basic functionality for all MBP tests.
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[value]' => $description,
'parent[]' => array(
$pid,
),
);
$this
->drupalPost('admin/structure/taxonomy/media_folders/add', $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);
$parents = taxonomy_get_parents_all($folder->tid);
$parent_count = count($parents) - 2;
$path = media_browser_plus_construct_dir_path($folder);
$this
->assertEqual(substr_count($path, '/'), $parent_count, 'Folder hierarchy structure matches');
foreach (media_get_local_stream_wrappers() as $scheme => $scheme_info) {
$folder_path = file_stream_wrapper_uri_normalize($scheme . '://' . $path);
$this
->assertTrue(is_dir($folder_path), format_string('Folder found. (!path)', array(
'!path' => $folder_path,
)));
}
}
}
}