function FileEntityAdminTestCase::testFilesAdminPages in File Entity (fieldable files) 7.2
Same name and namespace in other branches
- 7.3 file_entity.test \FileEntityAdminTestCase::testFilesAdminPages()
Tests files overview with different user permissions.
File
- ./
file_entity.test, line 715 - Test integration for the file_entity module.
Class
- FileEntityAdminTestCase
- Test file administration page functionality.
Code
function testFilesAdminPages() {
$this
->drupalLogin($this->admin_user);
$files['public_image'] = $this
->createFileEntity(array(
'scheme' => 'public',
'uid' => $this->base_user_1->uid,
'type' => 'image',
));
$files['public_document'] = $this
->createFileEntity(array(
'scheme' => 'public',
'uid' => $this->base_user_2->uid,
'type' => 'document',
));
$files['private_image'] = $this
->createFileEntity(array(
'scheme' => 'private',
'uid' => $this->base_user_1->uid,
'type' => 'image',
));
$files['private_document'] = $this
->createFileEntity(array(
'scheme' => 'private',
'uid' => $this->base_user_2->uid,
'type' => 'document',
));
// Verify view, usage, edit, and delete links for any file.
$this
->drupalGet('admin/content/file');
$this
->assertResponse(200);
foreach ($files as $file) {
$this
->assertLinkByHref('file/' . $file->fid);
$this
->assertLinkByHref('file/' . $file->fid . '/usage');
$this
->assertLinkByHref('file/' . $file->fid . '/edit');
$this
->assertLinkByHref('file/' . $file->fid . '/delete');
// Verify tableselect.
$this
->assertFieldByName('files[' . $file->fid . ']', '', t('Tableselect found.'));
}
// Verify no operation links are displayed for regular users.
$this
->drupalLogout();
$this
->drupalLogin($this->base_user_1);
$this
->drupalGet('admin/content/file');
$this
->assertResponse(200);
$this
->assertLinkByHref('file/' . $files['public_image']->fid);
$this
->assertLinkByHref('file/' . $files['public_document']->fid);
$this
->assertNoLinkByHref('file/' . $files['public_image']->fid . '/edit');
$this
->assertNoLinkByHref('file/' . $files['public_image']->fid . '/delete');
$this
->assertNoLinkByHref('file/' . $files['public_document']->fid . '/edit');
$this
->assertNoLinkByHref('file/' . $files['public_document']->fid . '/delete');
// Verify no tableselect.
$this
->assertNoFieldByName('files[' . $files['public_image']->fid . ']', '', t('No tableselect found.'));
// Verify private file is displayed with permission.
$this
->drupalLogout();
$this
->drupalLogin($this->base_user_2);
$this
->drupalGet('admin/content/file');
$this
->assertResponse(200);
$this
->assertLinkByHref('file/' . $files['private_document']->fid);
// Verify no operation links are displayed.
$this
->assertNoLinkByHref('file/' . $files['private_document']->fid . '/edit');
$this
->assertNoLinkByHref('file/' . $files['private_document']->fid . '/delete');
// Verify user cannot see private file of other users.
$this
->assertNoLinkByHref('file/' . $files['private_image']->fid);
$this
->assertNoLinkByHref('file/' . $files['private_image']->fid . '/edit');
$this
->assertNoLinkByHref('file/' . $files['private_image']->fid . '/delete');
// Verify no tableselect.
$this
->assertNoFieldByName('files[' . $files['private_document']->fid . ']', '', t('No tableselect found.'));
// Verify private file is displayed with permission.
$this
->drupalLogout();
$this
->drupalLogin($this->base_user_3);
$this
->drupalGet('admin/content/file');
$this
->assertResponse(200);
// Verify user can see private file of other users.
$this
->assertLinkByHref('file/' . $files['private_document']->fid);
$this
->assertLinkByHref('file/' . $files['private_image']->fid);
// Verify operation links are displayed for users with appropriate permission.
$this
->drupalLogout();
$this
->drupalLogin($this->base_user_4);
$this
->drupalGet('admin/content/file');
$this
->assertResponse(200);
foreach ($files as $file) {
$this
->assertLinkByHref('file/' . $file->fid);
$this
->assertLinkByHref('file/' . $file->fid . '/usage');
$this
->assertLinkByHref('file/' . $file->fid . '/edit');
$this
->assertLinkByHref('file/' . $file->fid . '/delete');
}
// Verify file access can be bypassed.
$this
->drupalLogout();
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('admin/content/file');
$this
->assertResponse(200);
foreach ($files as $file) {
$this
->assertLinkByHref('file/' . $file->fid);
$this
->assertLinkByHref('file/' . $file->fid . '/usage');
$this
->assertLinkByHref('file/' . $file->fid . '/edit');
$this
->assertLinkByHref('file/' . $file->fid . '/delete');
}
}