diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php index 4a8ee38..74cd432 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php @@ -30,39 +30,59 @@ public static function getInfo() { public function setUp() { parent::setUp(); - state()->set('node_access_test.private', TRUE); - } + // Remove access content permission from registered users. + user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array('access content')); - public function testTaxonomyImageAccess() { - $this->drupalGet('node'); - $user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'access user profiles')); - $this->drupalLogin($user); - $files = $this->drupalGetTestFiles('image'); - $file = entity_create('file', (array) array_pop($files)); - $file->save(); - $vocabulary = $this->createVocabulary(); + $this->vocabulary = $this->createVocabulary(); // Add a field instance to the vocabulary. $field = array( 'field_name' => 'field_test', 'type' => 'image', + 'settings' => array( + 'uri_scheme' => 'private', + ), ); field_create_field($field); $instance = array( 'field_name' => 'field_test', 'entity_type' => 'taxonomy_term', - 'bundle' => $vocabulary->id(), - 'settings' => array( - 'default_image' => $file->fid, - ) + 'bundle' => $this->vocabulary->id(), + 'settings' => array(), ); field_create_instance($instance); + entity_get_display('taxonomy_term', $this->vocabulary->id(), 'default') + ->setComponent('field_test', array( + 'type' => 'image', + 'settings' => array(), + )) + ->save(); + } + + public function testTaxonomyImageAccess() { + $user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'access user profiles')); + $this->drupalLogin($user); + + // Create a term and upload the image. + $term = $this->createTerm($this->vocabulary); + $uri = $term->uri(); + $files = $this->drupalGetTestFiles('image'); + $image = array_pop($files); + $edit['files[field_test_' . LANGUAGE_NOT_SPECIFIED . '_0]'] = drupal_realpath($image->uri); + $this->drupalPost($uri['path'] . '/edit', $edit, t('Save')); + $term = taxonomy_term_load($term->id()); + $this->assertText(t('Updated term @name.', array('@name' => $term->label()))); - $display = entity_get_display('taxonomy_term', $vocabulary->uri(), 'default'); - debug($display->getComponents()); + // Create a user that should have access to the file and one that doesn't. + $access_user = $this->drupalCreateUser(array('access content')); + $no_access_user = $this->drupalCreateUser(); + $image = file_load($term->field_test[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $this->drupalLogin($access_user); + $this->drupalGet(file_create_url($image->uri)); + $this->assertResponse(200, 'Private image on term is accessible with right permission'); - $term = $this->createTerm($vocabulary); - $this->drupalGet('taxonomy/term/1'); - $this->drupalGet('taxonomy/term/1/edit'); + $this->drupalLogin($no_access_user); + $this->drupalGet(file_create_url($image->uri)); + $this->assertResponse(403, 'Private image on term not accessible without right permission'); } }