You are here

public function CreatePhotosAlbumTest::testCreatePhotosAlbum in Album Photos 8.5

Same name and namespace in other branches
  1. 8.4 tests/src/Kernel/CreatePhotosAlbumTest.php \Drupal\Tests\photos\Kernel\CreatePhotosAlbumTest::testCreatePhotosAlbum()
  2. 6.0.x tests/src/Kernel/CreatePhotosAlbumTest.php \Drupal\Tests\photos\Kernel\CreatePhotosAlbumTest::testCreatePhotosAlbum()

Tests creating a photo album node.

File

tests/src/Kernel/CreatePhotosAlbumTest.php, line 57

Class

CreatePhotosAlbumTest
Tests creating photo album node.

Namespace

Drupal\Tests\photos\Kernel

Code

public function testCreatePhotosAlbum() {
  $user = $this
    ->createUser();
  $container = \Drupal::getContainer();
  $container
    ->get('current_user')
    ->setAccount($user);

  // Create a test node.
  $albumTitle = $this
    ->randomMachineName();
  $album = Node::create([
    'type' => 'photos',
    'title' => $albumTitle,
    'language' => 'en',
  ]);
  $album
    ->save();

  // Test PhotosAlbum::userAlbumOptions.
  $choice = new \stdClass();
  $choice->option = [
    $album
      ->id() => $albumTitle,
  ];
  $testOutput[$album
    ->id()] = $choice;
  $albumOptions = PhotosAlbum::userAlbumOptions($user
    ->id(), 0);
  $this
    ->assertSame($albumOptions[$album
    ->id()]->option, $testOutput[$album
    ->id()]->option);
}