Test the workflow content controller.
More...
List of all members.
Public Member Functions |
| _getContentsByType ($types) |
| Helper function to return list of entries having given content type(s).
|
| _verifyChangeStateJsonResponse (array $changedEntries, array $failedEntries=array(), $errors=null) |
| Helper function to verify json response of changed-state action.
|
| _verifyEntriesWorkflow (array $entryIds, $state, $scheduledState=null, $scheduledTime=null) |
| Helper function, verify that all given entries (specified by their ids) have given workflow state.
|
| testChangeStateFail () |
| Test changing workflow state on multiple entries where not all entries can be changed.
|
| testChangeStateForce () |
| Test changing workflow state on multiple entries with using 'forced' parameter.
|
| testChangeStateNoWorkflow () |
| Test changing workflow state on multiple entries with some entries not under workflow.
|
| testChangeStateSuccess () |
| Test successful changing workflow state on multiple entries.
|
Protected Member Functions |
| _createWorkflowsAndTypes ($entriesPerType=0) |
| Helper function, creates workflows, content types (one for each workflow + one with no workflow) and optionally specified number of entries for each content type, ids are derived from content type ids with appended number 1 to <number of="" entries>="">.
|
Detailed Description
Test the workflow content controller.
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Member Function Documentation
Workflow_Test_ContentControllerTest::_createWorkflowsAndTypes |
( |
$ |
entriesPerType = 0 | ) |
[protected] |
Helper function, creates workflows, content types (one for each workflow + one with no workflow) and optionally specified number of entries for each content type, ids are derived from content type ids with appended number 1 to <number of="" entries>="">.
- Parameters:
-
int | $entriesPerType | optional, number entries to create for each content type |
{
Workflow_Model_Workflow::store(
array(
'id' => 'simple',
'states' => "
[draft]
label = 'Draft'
transitions.review.label = 'Promote to reviw'
transitions.published.label = 'Publish'
[review]
label = 'Review'
transitions.draft.label = 'Demote to Draft'
transitions.published.label = 'Publish'
[published]
label = 'Published'
transitions.review.label = 'Demote to Review'
transitions.draft.label = 'Demote to Draft'"
)
);
Workflow_Model_Workflow::store(
array(
'id' => 'basic',
'states' => "
[draft]
label = 'Preliminary'
transitions.published.label = 'Go Live'
[published]
label = 'Live'
transitions.draft.label = 'Demote to Preliminary'"
)
);
Workflow_Model_Workflow::store(
array(
'id' => 'private',
'states' => "
[draft]
label = 'Private'
transitions.published.label = 'Publish'
transitions.published.conditions[] = 'False'
[published]
label = 'Public'
transitions.draft.label = 'Demote to Private'"
)
);
foreach (Workflow_Model_Workflow::fetchAll() as $workflow) {
P4Cms_Content_Type::store(
array(
'id' => $workflow->getId(),
'elements' => array(
'title' => array(
'type' => 'text'
)
),
'workflow' => $workflow->getId()
)
);
}
P4Cms_Content_Type::store(
array(
'id' => 'no-workflow',
'elements' => array(
'title' => array(
'type' => 'text'
)
)
)
);
if ($entriesPerType) {
$entry = P4Cms_Content::create(
array('title' => 'test')
);
foreach (P4Cms_Content_Type::fetchAll() as $type) {
$typeId = $type->getId();
$entry->setContentType($typeId);
for ($i = 1; $i <= $entriesPerType; $i++) {
$entry->setId($typeId . $i);
$entry->save();
}
}
}
}
Workflow_Test_ContentControllerTest::_getContentsByType |
( |
$ |
types | ) |
|
Helper function to return list of entries having given content type(s).
- Parameters:
-
string | array | $types | list of content types |
- Returns:
- P4Cms_Model_Iterator list of entries having given content type(s)
Workflow_Test_ContentControllerTest::_verifyChangeStateJsonResponse |
( |
array $ |
changedEntries, |
|
|
array $ |
failedEntries = array() , |
|
|
$ |
errors = null |
|
) |
| |
Helper function to verify json response of changed-state action.
- Parameters:
-
array | $changedEntries | list of expected entry ids that have been changed |
array | $failedEntries | list of expected entry ids that have failed |
string | null | $errors | expected errors |
{
$response = Zend_Json::decode($this->response->getBody());
$this->assertSame(
$changedEntries,
$response['changedEntries'],
"Expected list of changed entries."
);
$this->assertSame(
$failedEntries,
$response['failedEntries'],
"Expected list of failed entries."
);
$this->assertSame(
$errors,
$response['errors'],
"Expected errors message."
);
}
Workflow_Test_ContentControllerTest::_verifyEntriesWorkflow |
( |
array $ |
entryIds, |
|
|
$ |
state, |
|
|
$ |
scheduledState = null , |
|
|
$ |
scheduledTime = null |
|
) |
| |
Helper function, verify that all given entries (specified by their ids) have given workflow state.
Also verifies, that they have been submitted in one change list.
- Parameters:
-
array | $entryIds | list with entry ids to verify |
string | $state | workflow state assumed to be the current entries state of workflow |
string | null | $scheduledState | optional, workflow state assumed to be scheduled for the entries, if null then it won't be checked |
string | null | $scheduledTime | optional, timestamp of scheduled transition for given entries |
{
$workflowsByType = Workflow_Model_Workflow::fetchTypeMap();
$entryChanges = array();
$entries = P4Cms_Content::fetchAll(array('ids' => $entryIds));
foreach ($entries as $entry) {
$type = $entry->getContentTypeId();
if (!isset($workflowsByType[$type])) {
$this->fail("Unexpected entry with no workflow.");
}
$workflow = $workflowsByType[$type];
$this->assertSame(
$state,
$workflow->getStateOf($entry)->getId(),
"Expected entry has '$state' workflow state."
);
if ($scheduledState) {
$this->assertSame(
$scheduledState,
$workflow->getScheduledStateOf($entry)->getId(),
"Expected entry has '$scheduledState' as scheduled workflow state."
);
}
if ($scheduledTime) {
$this->assertSame(
$scheduledTime,
$workflow->getScheduledTimeOf($entry),
"Expected scheduled time of the scheduled workflow transition."
);
}
$entryChanges[] = $entry->toP4File()->getChange()->getId();
}
$this->assertSame(
1,
count(array_unique($entryChanges)),
"Expected all entries have been submitted in the same changelist."
);
}
Workflow_Test_ContentControllerTest::testChangeStateFail |
( |
| ) |
|
Test changing workflow state on multiple entries where not all entries can be changed.
{
$this->utility->impersonate('administrator');
$this->_createWorkflowsAndTypes(3);
$ids = $this->_getContentsByType(array('simple', 'private'))->invoke('getId');
$this->request->setMethod('POST');
$this->request->setPost(
array(
'workflows' => array('simple', 'private'),
'ids' => $ids,
'state' => 'published',
'scheduled' => 'false'
)
);
$this->dispatch('/workflow/content/change-state/format/json');
$this->assertModule('workflow', __LINE__ .': Last module run should be workflow module.');
$this->assertController('content', __LINE__ .': Expected controller');
$this->assertAction('change-state', __LINE__ .': Expected action');
$response = Zend_Json::decode($this->response->getBody());
$this->_verifyChangeStateJsonResponse(
array(),
$this->_getContentsByType('private')->invoke('getId')
);
$simpleWorkflow = Workflow_Model_Workflow::fetch('simple');
foreach ($this->_getContentsByType('simple') as $entry) {
$this->assertSame(
'draft',
$simpleWorkflow->getStateOf($entry)->getId(),
"Expected simple entries were not changed."
);
}
}
Workflow_Test_ContentControllerTest::testChangeStateForce |
( |
| ) |
|
Test changing workflow state on multiple entries with using 'forced' parameter.
{
$this->utility->impersonate('administrator');
$this->_createWorkflowsAndTypes(3);
$ids = $this->_getContentsByType(array('simple', 'private'))->invoke('getId');
$this->request->setMethod('POST');
$this->request->setPost(
array(
'workflows' => array('simple', 'private'),
'ids' => $ids,
'state' => 'published',
'scheduled' => 'false'
)
);
$this->dispatch('/workflow/content/change-state/format/json/forced/true');
$this->assertModule('workflow', __LINE__ .': Last module run should be workflow module.');
$this->assertController('content', __LINE__ .': Expected controller');
$this->assertAction('change-state', __LINE__ .': Expected action');
$response = Zend_Json::decode($this->response->getBody());
$simpleEntries = $this->_getContentsByType('simple');
$privateEntries = $this->_getContentsByType('private');
$this->_verifyChangeStateJsonResponse(
$simpleEntries->invoke('getId'),
array()
);
$this->_verifyEntriesWorkflow($simpleEntries->invoke('getId'), 'published');
$privateWorkflow = Workflow_Model_Workflow::fetch('private');
foreach ($privateEntries as $entry) {
$this->assertSame(
'draft',
$privateWorkflow->getStateOf($entry)->getId(),
"Expected private entries were not changed."
);
}
}
Workflow_Test_ContentControllerTest::testChangeStateNoWorkflow |
( |
| ) |
|
Test changing workflow state on multiple entries with some entries not under workflow.
{
$this->utility->impersonate('administrator');
$this->_createWorkflowsAndTypes(1);
$ids = array('simple1', 'no-workflow1');
$this->request->setMethod('POST');
$this->request->setPost(
array(
'workflows' => array('simple'),
'ids' => $ids,
'state' => 'review',
'scheduled' => 'false'
)
);
$this->dispatch('/workflow/content/change-state/format/json');
$this->assertModule('workflow', __LINE__ .': Last module run should be workflow module.');
$this->assertController('content', __LINE__ .': Expected controller');
$this->assertAction('change-state', __LINE__ .': Expected action');
$response = Zend_Json::decode($this->response->getBody());
$this->_verifyChangeStateJsonResponse(array(), array('no-workflow1'));
$entry = P4Cms_Content::fetch('simple1');
$simpleWorkflow = Workflow_Model_Workflow::fetchByContent($entry);
$this->assertSame(
'draft',
$simpleWorkflow->getStateOf($entry)->getId(),
"Expected state of the simple1 entry."
);
}
Workflow_Test_ContentControllerTest::testChangeStateSuccess |
( |
| ) |
|
Test successful changing workflow state on multiple entries.
{
$this->utility->impersonate('administrator');
$this->_createWorkflowsAndTypes(3);
$ids = array('simple1', 'simple3');
$this->request->setMethod('POST');
$this->request->setPost(
array(
'workflows' => array('simple'),
'ids' => $ids,
'state' => 'review',
'scheduled' => 'false'
)
);
$this->dispatch('/workflow/content/change-state/format/json');
$this->assertModule('workflow', __LINE__ .': Last module run should be workflow module.');
$this->assertController('content', __LINE__ .': Expected controller');
$this->assertAction('change-state', __LINE__ .': Expected action');
$this->_verifyChangeStateJsonResponse($ids);
$this->_verifyEntriesWorkflow($ids, 'review');
$this->resetRequest()->resetResponse();
$ids = $this->_getContentsByType(array('simple', 'basic'))->invoke('getId');
$this->request->setMethod('POST');
$this->request->setPost(
array(
'workflows' => array('simple', 'basic'),
'ids' => $ids,
'state' => 'published',
'scheduled' => 'false'
)
);
$this->dispatch('/workflow/content/change-state/format/json');
$this->assertModule('workflow', __LINE__ .': Last module run should be workflow module.');
$this->assertController('content', __LINE__ .': Expected controller');
$this->assertAction('change-state', __LINE__ .': Expected action');
$this->_verifyChangeStateJsonResponse($ids);
$this->_verifyEntriesWorkflow($ids, 'published');
}
The documentation for this class was generated from the following file:
- ContentControllerTest.php