public function MediaBrowserPlusTest::testFolderMovemet in Media Browser Plus 7.2
Same name and namespace in other branches
- 7.3 tests/media_browser_plus.test \MediaBrowserPlusTest::testFolderMovemet()
Test the ability to move folders.
File
- tests/
media_browser_plus.test, line 203 - Media Browser Plus tests.
Class
- MediaBrowserPlusTest
- Defines media entity creation and management test cases.
Code
public function testFolderMovemet() {
$this
->drupalLogin($this->admin_user);
// Create test folder structure.
$folders = array(
'source' => $this
->randomName(),
'source_child' => $this
->randomName(),
'source_child_child' => $this
->randomName(),
'destination' => $this
->randomName(),
);
$hierarchy = array(
'root_folder' => array(
$folders['source'] => array(
$folders['source_child'] => array(
$folders['source_child_child'] => array(),
),
),
$folders['destination'] => 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);
$files[$type][] = $this
->createTestFile('text/plain', $folder);
$files[$type][] = $this
->createTestFile('image/jpg', $folder);
}
// Just to have a verbose output.
$this
->drupalGet('admin/content/file/list');
$original_source_path = media_browser_plus_construct_dir_path($folders['source']);
$destination_path = media_browser_plus_construct_dir_path($folders['destination']);
// Now move the folder.
$data['pid'] = $folders['destination']->tid;
$this
->drupalPost('admin/content/file/folder/' . $folders['source']->tid . '/edit', $data, t('Save'));
// Reset the different caches.
drupal_static_reset('taxonomy_get_parents');
drupal_static_reset('taxonomy_get_parents_all');
entity_get_controller('taxonomy_term')
->resetCache();
entity_get_controller('file')
->resetCache();
// Check if the path of the source has changed.
$updated_source_path = media_browser_plus_construct_dir_path($folders['source']);
if ($this
->assertNotEqual($original_source_path, $updated_source_path, 'Source folder changed')) {
// Check paths and files of source and its children.
$new_parent_folder = 'destination';
foreach (array(
'source',
'source_child',
'source_child_child',
) as $type) {
$folders[$type] = taxonomy_term_load($folders[$type]->tid);
$source_path = media_browser_plus_construct_dir_path($folders[$type]);
$destination_path = media_browser_plus_construct_dir_path($folders[$new_parent_folder]);
// Check if the new path is a child folder of the destination.
$this
->assertTrue(stristr($source_path, $destination_path) !== FALSE, 'Source folder is child folder of destination.');
// Check if the old path was really deleted.
$this
->assertFalse(is_dir($original_source_path), 'Old source folder deleted');
// Now check the files.
foreach ($files[$type] as $file) {
// Refresh cached object.
$file = file_load($file->fid);
// Check if the new path is a child folder of the destination.
$this
->assertTrue(stristr($file->uri, $destination_path) !== FALSE, 'Source file is child of new destination.');
}
$new_parent_folder = $type;
}
}
// Just to have a verbose output.
$this
->drupalGet('admin/content/file/folder_list');
}