Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/trigger in dataextensions #214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Extension/Engine/SiteTreePublishingEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/php/Extension/Engine/SiteTreePublishingEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions tests/php/StaticPublisherTest/Model/DataObjectNoTrigger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace SilverStripe\StaticPublishQueue\Test\StaticPublisherTest\Model;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;

class DataObjectNoTrigger extends DataObject implements TestOnly
{
public function AbsoluteLink()
{
return 'http://example.com/subpage/dataobject-1';
}
}

27 changes: 27 additions & 0 deletions tests/php/StaticPublisherTest/Model/ExtensionAddsTrigger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace SilverStripe\StaticPublishQueue\Test\StaticPublisherTest\Model;

use SilverStripe\Dev\TestOnly;
use SilverStripe\Core\Extension;
use SilverStripe\StaticPublishQueue\Contract\StaticPublishingTrigger;
use SilverStripe\StaticPublishQueue\Contract\StaticallyPublishable;

class ExtensionAddsTrigger extends Extension implements StaticallyPublishable, StaticPublishingTrigger, TestOnly
{
public function urlsToCache()
{
return [$this->owner->AbsoluteLink() => 0];
}

public function objectsToUpdate($context)
{
return $this->owner;
}

public function objectsToDelete($context)
{
return [];
}
}