You are here

public function FppFileAccessTest::testFileAccessWithIncorrectAuth in Fieldable Panels Panes (FPP) 7

Confirm private file access works when the visitor does NOT have access.

File

tests/fpp.file_access.test, line 101
Tests for the Fieldable Panels Panes module to ensure file access works.

Class

FppFileAccessTest
Tests for the Fieldable Panels Panes module to ensure file access works.

Code

public function testFileAccessWithIncorrectAuth() {

  // Create a user with the admin permission.
  $this->adminUser = $this
    ->createAdminUser();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->addPrivateImageField();

  // Create the FPP object.
  $fpp = $this
    ->createTestFppObject();

  // Make the FPP only accessible by the admin private.
  $fpp = $this
    ->makeFppObjectPrivate($fpp);
  $this
    ->assertNotEqual($fpp, NULL);

  // Get the file object.
  $file = file_load($fpp->field_fpp_image[LANGUAGE_NONE][0]['fid']);
  $this
    ->assertNotEqual($file, NULL);
  $url = file_create_url($file->uri);
  $this
    ->assertNotEqual($url, NULL);
  $this
    ->assertTrue(strpos($url, 'system/files'), 'File is stored in the private file system.');

  // Logout so all future requests will be by an anonymous visitor.
  $this
    ->drupalLogout();

  // Confirm the FPP page is not accessible.
  $this
    ->drupalGet('admin/structure/fieldable-panels-panes/view/' . $fpp->fpid);
  $this
    ->assertResponse(403);

  // Confirm the file is not accessible.
  $this
    ->drupalGet($url);
  $this
    ->assertResponse(403);
}