private function PublishOnlyRenderedTest::getCdfMock in Acquia Lift Connector 8.4
Returns a testable CDF object.
Return value
object The object containing the original CDF array, the rendered entity and the source entity.
Throws
\Exception
1 call to PublishOnlyRenderedTest::getCdfMock()
- PublishOnlyRenderedTest::testOnPrunePublishCdfEntities in modules/
acquia_lift_publisher/ tests/ src/ Kernel/ EventSubscriber/ Publish/ PublishOnlyRenderedTest.php - @covers ::onPrunePublishCdfEntities
File
- modules/
acquia_lift_publisher/ tests/ src/ Kernel/ EventSubscriber/ Publish/ PublishOnlyRenderedTest.php, line 251
Class
- PublishOnlyRenderedTest
- Class PublishOnlyRenderedTest.
Namespace
Drupal\Tests\acquia_lift_publisher\Kernel\EventSubscriber\PublishCode
private function getCdfMock() : \stdClass {
$uuid = \Drupal::getContainer()
->get('uuid');
$time = time();
$cdfs = [];
// Add random CDFs.
$no_cdfs = 11;
$origin = $uuid
->generate();
for ($i = 0; $i < $no_cdfs; $i++) {
$cdfs[] = new CDFObject('drupal8_content_entity', $uuid
->generate(), $time, $time, $origin);
}
$source_entity = new CDFObject('drupal8_content_entity', $uuid
->generate(), $time, $time, $origin);
$cdfs[] = $source_entity;
// Add a few tags to source entity.
$tags = array_slice($cdfs, 0, 3);
$tag_uuids = [];
/** @var \Acquia\ContentHubClient\CDF\CDFObject $tag */
foreach ($tags as $tag) {
$tag_uuids[] = $tag
->getUuid();
}
$source_entity
->addAttribute('tags', CDFAttribute::TYPE_ARRAY_REFERENCE, $tag_uuids);
$rendered1 = new CDFObject('rendered_entity', $uuid
->generate(), $time, $time, $origin);
$rendered1
->addAttribute('source_entity', CDFAttribute::TYPE_STRING, $source_entity
->getUuid());
$rendered2 = new CDFObject('rendered_entity', $uuid
->generate(), $time, $time, $origin);
$rendered2
->addAttribute('source_entity', CDFAttribute::TYPE_STRING, $source_entity
->getUuid());
$cdfs[] = $rendered1;
$cdfs[] = $rendered2;
// Construct an easily testable object containing the original CDF array,
// the rendered entity, and its source entity.
$cdf_mock = new \stdClass();
$cdf_mock->original = $cdfs;
$cdf_mock->rendered_entities = [
$rendered1,
$rendered2,
];
$cdf_mock->expected = array_merge([
$source_entity,
], $tags, $cdf_mock->rendered_entities);
return $cdf_mock;
}