public function EntityRenderHandlerTest::testImageAttributeIsSet in Acquia Lift Connector 8.4
@covers ::onCreateCdf
Throws
\Exception
File
- modules/
acquia_lift_publisher/ tests/ src/ Kernel/ EventSubscriber/ Cdf/ EntityRenderHandlerTest.php, line 173
Class
- EntityRenderHandlerTest
- Class EntityRenderHandlerTest.
Namespace
Drupal\Tests\acquia_lift_publisher\Kernel\EventSubscriber\CdfCode
public function testImageAttributeIsSet() {
$this
->createContentType([
'id' => 'article',
'name' => 'Image article content type',
'type' => 'article',
]);
$this
->createImageField('field_image_test', 'article', [], [], [], [], 'Image test on [site:name]');
$image_files = $this
->getTestFiles('image');
$image = File::create((array) current($image_files));
$image
->save();
$entity = $this
->createNode([
'type' => 'article',
'title' => 'Title Test',
'field_image_test' => [
[
'target_id' => $image
->id(),
],
],
]);
$this
->enableViewModeExportFor($entity);
$event = $this
->dispatchWith($entity, []);
$cdfs = $this
->getRenderedEntities($event
->getCdfList());
$cdf = current($cdfs);
$this
->assertNotNull($cdf);
// Assert that image url is correct
$this
->assertEqual($cdf
->getAttribute('preview_image')
->getValue()['und'], ImageStyle::load('acquia_lift_publisher_preview_image')
->buildUrl($image
->getFileUri()), '');
// Ensure that a node with an empty image field can get rendered (LEB-4401).
// Create another node with no image.
$entity = $this
->createNode([
'type' => 'article',
'title' => 'Title test with no image',
]);
$event = $this
->dispatchWith($entity, []);
$rendered_cdfs = $this
->getRenderedEntities($event
->getCdfList());
$this
->assertCount(1, $rendered_cdfs, 'Entity rendered.');
$cdf = current($rendered_cdfs);
// Check that title matches.
$this
->assertEqual($cdf
->getAttribute('label')
->getValue()['en'], 'Title test with no image');
// Check that no image preview is present in CDF.
$this
->assertNull($cdf
->getAttribute('preview_image'), 'No preview image in CDF');
}