diff --git a/src/Extension/Engine/SiteTreePublishingEngine.php b/src/Extension/Engine/SiteTreePublishingEngine.php index 669ac429..ab79eb67 100644 --- a/src/Extension/Engine/SiteTreePublishingEngine.php +++ b/src/Extension/Engine/SiteTreePublishingEngine.php @@ -279,7 +279,7 @@ public function collectChanges($context) } // The page does not include the required extension, and it doesn't implement a Trigger - if (!$siteTree->hasExtension(PublishableSiteTree::class) && !($siteTree instanceof StaticPublishingTrigger)) { + if (!$siteTree->hasExtension(StaticPublishingTrigger::class) && !($siteTree instanceof StaticPublishingTrigger)) { return; } diff --git a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php index 5c427a1c..32a52e06 100644 --- a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php +++ b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php @@ -14,6 +14,8 @@ use SilverStripe\StaticPublishQueue\Job\GenerateStaticCacheJob; use SilverStripe\StaticPublishQueue\Service\UrlBundleService; use SilverStripe\StaticPublishQueue\Test\QueuedJobsTestService; +use SilverStripe\StaticPublishQueue\Test\StaticPublisherTest\Model\ExtensionAddsTrigger; +use SilverStripe\StaticPublishQueue\Test\StaticPublisherTest\Model\DataObjectNoTrigger; use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; use Symbiote\QueuedJobs\Services\QueuedJob; use Symbiote\QueuedJobs\Services\QueuedJobHandler; @@ -232,6 +234,39 @@ public function testDoUnpublish(): void $this->assertEqualsCanonicalizing($expectedUrls, $resultUrls); } + public function testStaticPublishingTriggerOnExtension(): void + { + // Inclusion of parent/child is tested in PublishableSiteTreeTest + SiteTree::config()->set('regenerate_parents', PublishableSiteTree::REGENERATE_RELATIONS_NONE); + SiteTree::config()->set('regenerate_children', PublishableSiteTree::REGENERATE_RELATIONS_NONE); + + DataObjectNoTrigger::add_extension(ExtensionAddsTrigger::class); + DataObjectNoTrigger::add_extension(SiteTreePublishingEngine::class); + + /** @var QueuedJobsTestService $service */ + $service = QueuedJobService::singleton(); + + $dataObject = DataObjectNoTrigger::create()->write(); + $dataObject->publishRecursive(); + + $jobs = $service->getJobs(); + + // We should only have 1 job queued + $this->assertCount(1, $jobs); + + // Let's grab the job and inspect the contents + /** @var GenerateStaticCacheJob $updateJob */ + $updateJob = $this->getJobByClassName($jobs, GenerateStaticCacheJob::class); + + $expectedUrls = [ + 'http://example.com/subpage/dataobject-1', + ]; + $resultUrls = array_keys($updateJob->getJobData()->jobData->URLsToProcess); + + $this->assertInstanceOf(GenerateStaticCacheJob::class, $updateJob); + $this->assertEqualsCanonicalizing($expectedUrls, $resultUrls); + } + protected function getJobByClassName(array $jobs, string $className): ?QueuedJob { foreach ($jobs as $job) { diff --git a/tests/php/StaticPublisherTest/Model/DataObjectNoTrigger.php b/tests/php/StaticPublisherTest/Model/DataObjectNoTrigger.php new file mode 100644 index 00000000..fa7021e7 --- /dev/null +++ b/tests/php/StaticPublisherTest/Model/DataObjectNoTrigger.php @@ -0,0 +1,15 @@ +owner->AbsoluteLink() => 0]; + } + + public function objectsToUpdate($context) + { + return $this->owner; + } + + public function objectsToDelete($context) + { + return []; + } +} +