You are here

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

Confirm private file access works when the visitor DOES have access.

File

tests/fpp.file_access.test, line 68
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 testFileAccessWithCorrectAuth() {

  // 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);

  // 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.');

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

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