AddPhotosAlbumImageTest.php in Album Photos 8.4
File
tests/src/Functional/AddPhotosAlbumImageTest.php
View source
<?php
namespace Drupal\Tests\photos\Functional;
use Drupal\node\Entity\Node;
use Drupal\photos\PhotosAlbum;
use Drupal\photos\PhotosImage;
use Drupal\Tests\BrowserTestBase;
class AddPhotosAlbumImageTest extends BrowserTestBase {
public static $modules = [
'node',
'file',
'image',
'comment',
'photos',
];
protected $defaultTheme = 'stark';
protected $account;
protected function setUp() {
parent::setUp();
$this->account = $this
->drupalCreateUser([
'view photo',
'create photo',
'edit own photo',
'delete own photo',
]);
$this
->drupalLogin($this->account);
}
public function testAccessPhotosImageEditForm() {
$album = Node::create([
'type' => 'photos',
'title' => $this
->randomMachineName(),
]);
$album
->save();
$testPhotoUri = drupal_get_path('module', 'photos') . '/tests/images/photos-test-picture.jpg';
$fileSystem = \Drupal::service('file_system');
$edit = [
'files[images_0]' => $fileSystem
->realpath($testPhotoUri),
'title_0' => 'Test photo title',
'des_0' => 'Test photos description',
];
$this
->drupalPostForm('node/' . $album
->id() . '/photos', $edit, 'Confirm upload');
$photosAlbum = new PhotosAlbum($album
->id());
$albumImages = $photosAlbum
->getImages(1);
$imageFid = $albumImages[0]->fid;
$this
->drupalGet('photos/image/' . $imageFid . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'title' => 'Test new title',
];
$this
->drupalPostForm(NULL, $edit, 'Confirm changes');
$photosImage = new PhotosImage($imageFid);
$photosImageData = $photosImage
->load();
$this
->assertEquals($edit['title'], $photosImageData->title);
}
}