Skip to content

Commit

Permalink
FIX Update tests and fixtures, implement symfony/yaml (used in core) …
Browse files Browse the repository at this point in the history
…to replace sfYamlParser
  • Loading branch information
robbieaverill committed Sep 21, 2017
1 parent 50a5f5f commit 7b9fba3
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 77 deletions.
12 changes: 0 additions & 12 deletions _config/workflowconfig.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
Name: workflowconfig
After:
- 'framework/*'
- 'cms/*'
---
SilverStripe\CMS\Model\SiteTree:
extensions:
Expand All @@ -16,12 +13,3 @@ SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest:
SilverStripe\Admin\LeftAndMain:
extra_requirements_css:
- advancedworkflow/css/AdvancedWorkflowAdmin.css
---
Name: workflow_jobs
Only:
moduleexists: queuedjobs
---
SilverStripe\Core\Injector\Injector:
Symbiote\AdvancedWorkflow\Jobs\WorkflowReminderJob:
properties:
queuedJobService: %$Symbiote\QueuedJobs\Services\QueuedJobService
9 changes: 9 additions & 0 deletions _config/workflowjobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
Name: workflow_jobs
Only:
moduleexists: queuedjobs
---
SilverStripe\Core\Injector\Injector:
Symbiote\AdvancedWorkflow\Jobs\WorkflowReminderJob:
properties:
queuedJobService: %$Symbiote\QueuedJobs\Services\QueuedJobService
8 changes: 4 additions & 4 deletions code/actions/PublishItemWorkflowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public function execute(WorkflowInstance $workflow)
$target->DesiredPublishDate = '';
$target->write();
} else {
if ($target->hasMethod('doPublish')) {
$target->doPublish();
if ($target->hasMethod('publishSingle')) {
$target->publishSingle();
}
}
} else {
if ($target->hasMethod('doPublish')) {
$target->doPublish();
if ($target->hasMethod('publishSingle')) {
$target->publishSingle();
}
}

Expand Down
2 changes: 1 addition & 1 deletion code/admin/WorkflowDefinitionExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private function ssVersion()
// Remove colons so they don't screw with YAML parsing
$versionSapphire = str_replace(':', '', singleton(SapphireInfo::class)->Version());
$versionLeftMain = str_replace(':', '', singleton(LeftAndMain::class)->CMSVersion());
if ($versionSapphire != _t('LeftAndMain.VersionUnknown')) {
if ($versionSapphire != _t('SilverStripe\\Admin\\LeftAndMain.VersionUnknown', 'Unknown')) {
return $versionSapphire;
}
return $versionLeftMain;
Expand Down
8 changes: 2 additions & 6 deletions code/admin/WorkflowDefinitionImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Symbiote\AdvancedWorkflow\Admin;

use Exception;
use sfYamlParser;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationException;
use Symbiote\AdvancedWorkflow\DataObjects\ImportedWorkflowTemplate;
use Symbiote\AdvancedWorkflow\Templates\WorkflowTemplate;
use Symfony\Component\Yaml\Yaml;

/**
* Workflow definition import-specific logic. @see {@link WorkflowDefinitionExporter}.
Expand Down Expand Up @@ -62,10 +62,6 @@ public function parseYAMLImport($source)
$source = file_get_contents($source);
}

// @todo update, use composer
require_once('thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYamlParser.php');
$parser = new sfYamlParser();

// Make sure the linefeeds are all converted to \n, PCRE '$' will not match anything else.
$convertLF = str_replace(array("\r\n", "\r"), "\n", $source);
/*
Expand All @@ -83,7 +79,7 @@ public function parseYAMLImport($source)
}

try {
$parsed = $parser->parse($parts[1]);
$parsed = Yaml::parse($parts[1]);
return $parsed;
} catch (Exception $e) {
$msg = _t('WorkflowDefinitionImporter.INVALID_YML_FORMAT_NO_PARSE', 'Invalid YAML format. Unable to parse.');
Expand Down
5 changes: 3 additions & 2 deletions code/dataobjects/WorkflowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ public function onAfterDelete()
{
parent::onAfterDelete();
$wfActionInstances = WorkflowActionInstance::get()
->leftJoin(WorkflowInstance::class, '"WorkflowInstance"."ID" = "WorkflowActionInstance"."WorkflowID"')
->where(sprintf('"BaseActionID" = %d AND ("WorkflowStatus" IN (\'Active\',\'Paused\'))', $this->ID));
/** @skipUpgrade */
->leftJoin('WorkflowInstance', '"WorkflowInstance"."ID" = "WorkflowActionInstance"."WorkflowID"')
->where(sprintf('"BaseActionID" = %d AND ("WorkflowStatus" IN (\'Active\',\'Paused\'))', $this->ID));
foreach ($wfActionInstances as $wfActionInstance) {
$wfInstances = WorkflowInstance::get()->filter('CurrentActionID', $wfActionInstance->ID);
foreach ($wfInstances as $wfInstance) {
Expand Down
9 changes: 5 additions & 4 deletions code/dataobjects/WorkflowInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class WorkflowInstance extends DataObject
private static $db = array(
'Title' => 'Varchar(128)',
'WorkflowStatus' => "Enum('Active,Paused,Complete,Cancelled','Active')",
'TargetClass' => 'Varchar(64)',
'TargetClass' => 'Varchar(255)',
'TargetID' => 'Int',
);

Expand Down Expand Up @@ -758,9 +758,10 @@ public function getCurrentAction()
{
$join = '"WorkflowAction"."ID" = "WorkflowActionInstance"."BaseActionID"';
$action = WorkflowAction::get()
->leftJoin(WorkflowActionInstance::class, $join)
->where('"WorkflowActionInstance"."ID" = '.$this->CurrentActionID)
->first();
/** @skipUpgrade */
->leftJoin('WorkflowActionInstance', $join)
->where('"WorkflowActionInstance"."ID" = '.$this->CurrentActionID)
->first();
if (!$action) {
return 'N/A';
}
Expand Down
3 changes: 2 additions & 1 deletion code/extensions/WorkflowEmbargoExpiryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SilverStripe\Versioned\Versioned;
use Symbiote\AdvancedWorkflow\Forms\AWRequiredFields;
use Symbiote\AdvancedWorkflow\Jobs\WorkflowPublishTargetJob;
use Symbiote\AdvancedWorkflow\Services\WorkflowService;
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Services\QueuedJobService;

Expand Down Expand Up @@ -539,7 +540,7 @@ public function getIsUnPublishScheduled()
public function canEdit($member)
{
if (!Permission::check('EDIT_EMBARGOED_WORKFLOW') && // not given global/override permission to edit
!$this->AllowEmbargoedEditing) { // item flagged as not editable
!$this->owner->AllowEmbargoedEditing) { // item flagged as not editable
$now = strtotime(DBDatetime::now()->getTimestamp());
$publishTime = strtotime($this->owner->PublishOnDate);

Expand Down
2 changes: 1 addition & 1 deletion code/jobs/WorkflowReminderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function process()
try {
$instance->write();
} catch (Exception $ex) {
Injector::inst()->get(LoggerInterface::class)->warning($ex->getMessage())
Injector::inst()->get(LoggerInterface::class)->warning($ex->getMessage());
}
}

Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"require": {
"silverstripe/cms": "^4",
"silverstripe/framework": "^4",
"silverstripe/versioned": "^1"
"silverstripe/admin": "^1",
"silverstripe/versioned": "^1",
"symfony/yaml": "~3.2"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
Expand All @@ -32,7 +34,7 @@
"autoload": {
"psr-4": {
"Symbiote\\AdvandedWorkflow\\": "code/",
"Symbiote\\AdvandedWorkflow\\Tests\\": "tests/",
"Symbiote\\AdvandedWorkflow\\Tests\\": "tests/"
}
},
"replace": {
Expand Down
27 changes: 11 additions & 16 deletions tests/WorkflowEmbargoExpiryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Symbiote\AdvancedWorkflow\Tests;

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
Expand All @@ -15,6 +16,7 @@
use Symbiote\AdvancedWorkflow\Extensions\WorkflowEmbargoExpiryExtension;
use Symbiote\AdvancedWorkflow\Services\WorkflowService;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJobService;

/**
* @author marcus@symbiote.com.au
Expand All @@ -30,11 +32,13 @@ protected function setUp()

DBDatetime::set_mock_now('2014-01-05 12:00:00');


// Prevent failure if queuedjobs module isn't installed.
if (!class_exists(AbstractQueuedJob::class, false)) {
if (!class_exists(AbstractQueuedJob::class)) {
$this->markTestSkipped("This test requires queuedjobs");
}

// This doesn't play nicely with PHPUnit
Config::modify()->set(QueuedJobService::class, 'use_shutdown_function', false);
}

protected function tearDown()
Expand All @@ -50,26 +54,18 @@ protected function tearDown()
SiteTree::class => array(
WorkflowEmbargoExpiryExtension::class,
Versioned::class,
)
),
);

/**
* @var array
*/
protected $illegal_extensions = array(
protected static $illegal_extensions = array(
SiteTree::class => array(
Translatable::class,
)
),
);

public function __construct()
{
if (!class_exists(AbstractQueuedJob::class)) {
$this->skipTest = true;
}
parent::__construct();
}

/**
* Start a workflow for a page,
* this will set it into a state where a workflow is currently being processes
Expand Down Expand Up @@ -103,7 +99,7 @@ private function finishWorkflow($obj)
$svc = singleton(WorkflowService::class);
$svc->startWorkflow($obj, $obj->WorkflowDefinitionID);

$obj = DataObject::get_by_id($obj->ClassName, $obj->ID);
$obj = DataObject::get($obj->ClassName)->byID($obj->ID);
return $obj;
}

Expand All @@ -117,7 +113,7 @@ private function getLive($obj)
{
$oldMode = Versioned::get_reading_mode();
Versioned::set_reading_mode(Versioned::LIVE);
$live = DataObject::get_by_id($obj->ClassName, $obj->ID);
$live = DataObject::get($obj->ClassName)->byID($obj->ID);
Versioned::set_reading_mode($oldMode);

return $live;
Expand Down Expand Up @@ -163,7 +159,6 @@ public function testPastEmbargo()
$this->assertEquals(0, $page->UnPublishJobID);

$publish = strtotime($page->PublishJob()->StartAfter);

$this->assertFalse($publish);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/WorkflowEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function testDeleteWorkflowTargetStillWorks()
$page->write();

// Check $page is in draft, pre-deletion
$status = ($page->getIsAddedToStage() && !$page->getExistsOnLive());
$status = ($page->isOnDraftOnly() && !$page->isPublished());
$this->assertTrue($status);

// 2). Step the content into that workflow
Expand All @@ -270,7 +270,7 @@ public function testDeleteWorkflowTargetStillWorks()
$def->delete();

// Check $testPage is _still_ in draft, post-deletion
$status = ($testPage->getIsAddedToStage() && !$testPage->getExistsOnLive());
$status = ($testPage->isOnDraftOnly() && !$testPage->isPublished());
$this->assertTrue($status);

/*
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testDeleteWorkflowTargetStillWorks()
$testPage->publishRecursive();

// Check $testPage is published, pre-deletion (getStatusFlags() returns empty array)
$this->assertTrue($testPage->getExistsOnLive());
$this->assertTrue($testPage->isPublished());

$instance = new WorkflowInstance();
$instance->beginWorkflow($newDef2, $testPage);
Expand All @@ -317,7 +317,7 @@ public function testDeleteWorkflowTargetStillWorks()
$newDef2->delete();

// Check $testPage is _still_ published, post-deletion (getStatusFlags() returns empty array)
$this->assertTrue($testPage->getExistsOnLive());
$this->assertTrue($testPage->isPublished());
}

/**
Expand Down
Loading

0 comments on commit 7b9fba3

Please sign in to comment.