public function testGetNextStatusListData() { $model = new Item04(); $model->enterWorkflow(); $ar = WorkflowHelper::getNextStatusListData($model); $expected = ['Item04Workflow/A' => 'Entry', 'Item04Workflow/B' => 'Published']; $this->assertEquals(2, count($ar)); $this->assertEquals(2, count(array_intersect_assoc($expected, $ar))); $model->sendTostatus('B'); $ar = WorkflowHelper::getNextStatusListData($model, false, false, true); $this->assertEquals(3, count($ar)); $this->assertEquals(3, count(array_intersect_assoc(['Item04Workflow/A' => 'Entry', 'Item04Workflow/B' => 'Published', 'Item04Workflow/C' => 'node C'], $ar))); }
public function testGetStatusDropDownData() { $model = new Item04(); $model->enterWorkflow(); $ar = WorkflowHelper::GetStatusDropDownData($model); $listData = WorkflowHelper::getAllStatusListData($model->getWorkflow()->getId(), $model->getWorkflowSource()); codecept_debug($ar); $expected = ['Item04Workflow/A' => 'Entry', 'Item04Workflow/B' => 'Published']; $this->assertTrue(is_array($ar)); $this->assertTrue(isset($ar['items']) && is_array($ar['items'])); $this->assertTrue(isset($ar['options']) && is_array($ar['options'])); $this->assertEquals(2, count($ar)); foreach ($listData as $status => $label) { $this->assertTrue(array_key_exists($status, $ar['items'])); } $this->assertTrue($ar['options']['Item04Workflow/C']['disabled']); $this->assertTrue($ar['options']['Item04Workflow/D']['disabled']); }
/** * Returns the status string of the next valid status from the list of transitions * * @param BaseActiveRecord|SimpleWorkflowBehavior $model * @return string */ public static function getNextStatus($model) { $currentStatus = $model->getAttribute('status'); $statusList = $model->getWorkflowSource()->getAllStatuses($model->getWorkflow()->getId()); $transitions = array_keys(WorkflowHelper::getNextStatusListData($this->owner)); $started = false; foreach ($statusList as $status) { $status_id = $status->getId(); if ($started) { if (in_array($status_id, $transitions) && static::isValidNextStatus($model, $status_id)) { return $status_id; } } if ($status_id == $currentStatus) { $started = true; } } return $currentStatus; }