You are here

protected function PhotosAccessTest::updateAlbumPrivacySettings in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 photos_access/tests/src/Functional/PhotosAccessTest.php \Drupal\Tests\photos\Functional\PhotosAccessTest::updateAlbumPrivacySettings()

Update photos node privacy settings and clear caches.

Parameters

array $edit: Form edit parameters.

1 call to PhotosAccessTest::updateAlbumPrivacySettings()
PhotosAccessTest::testAlbumPrivacySettings in photos_access/tests/src/Functional/PhotosAccessTest.php
Test album privacy settings.

File

photos_access/tests/src/Functional/PhotosAccessTest.php, line 294

Class

PhotosAccessTest
Test photos_access album privacy settings.

Namespace

Drupal\Tests\photos\Functional

Code

protected function updateAlbumPrivacySettings(array $edit = []) {

  // Switch back to album owner.
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet('node/' . $this->album
    ->id() . '/edit');
  if (isset($edit['photos_privacy[viewid]']) && $edit['photos_privacy[viewid]'] == 4) {

    // Check if role access option is enabled.
    $this
      ->assertSession()
      ->responseContains('Role access');
  }
  $this
    ->submitForm($edit, 'Save');

  /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');

  // Must explicitly clear cache to see privacy settings?
  // @see https://www.drupal.org/project/drupal/issues/3040878
  $storage
    ->resetCache([
    $this->album
      ->id(),
  ]);

  // File may have moved. Reset file cache.
  $this->container
    ->get('entity_type.manager')
    ->getStorage('file')
    ->resetCache();

  // Update album variable.
  $this->album = $storage
    ->load($this->album
    ->id());
  if (isset($edit['photos_privacy[viewid]'])) {
    $this
      ->assertEquals($this->album->photos_privacy['viewid'], $edit['photos_privacy[viewid]'], 'Album privacy settings updated successfully.');
  }
}