CreatePhotosAlbumTest.php in Album Photos 8.5
File
tests/src/Kernel/CreatePhotosAlbumTest.php
View source
<?php
namespace Drupal\Tests\photos\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\photos\PhotosAlbum;
use Drupal\user\Entity\User;
class CreatePhotosAlbumTest extends EntityKernelTestBase {
public static $modules = [
'node',
'file',
'system',
'field',
'user',
'photos',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'system',
]);
$this
->installEntitySchema('file');
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$this
->installSchema('file', [
'file_usage',
]);
$this
->installSchema('photos', [
'photos_album',
'photos_count',
]);
$user = User::create([
'uid' => 1,
'name' => $this
->randomMachineName(),
]);
$user
->enforceIsNew();
$user
->save();
\Drupal::currentUser()
->setAccount($user);
}
public function testCreatePhotosAlbum() {
$user = $this
->createUser();
$container = \Drupal::getContainer();
$container
->get('current_user')
->setAccount($user);
$albumTitle = $this
->randomMachineName();
$album = Node::create([
'type' => 'photos',
'title' => $albumTitle,
'language' => 'en',
]);
$album
->save();
$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);
}
}