Inheritance: extends yii\db\ActiveRecord
 public function testEnterWorkflowFails2()
 {
     $item = new Item04();
     $this->specify('enterWorkflow fails if workflow not found for ID', function () use($item) {
         $this->setExpectedException('raoul2000\\workflow\\base\\WorkflowException', 'failed to load workflow definition : Class tests\\codeception\\unit\\models\\INVALIDID does not exist');
         $item->enterWorkflow('INVALIDID');
     });
 }
 public function testEnterWorkflowFails2()
 {
     /** @var ActiveWorkflowBehavior $item */
     $item = new Item04();
     $this->specify('enterWorkflow fails if workflow not found for ID', function () use($item) {
         $this->setExpectedException('fproject\\workflow\\core\\WorkflowException', 'Failed to load workflow definition : Class tests\\codeception\\unit\\models\\INVALIDIDSource does not exist');
         $item->enterWorkflow('INVALIDID');
     });
 }
 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 testReturnReportWithEventsOnEnterWorkflow()
 {
     $model = new Item04();
     $model->on(WorkflowEvent::beforeEnterStatus('Item04Workflow/A'), function ($event) {
         $event->invalidate('my error message');
     });
     $report = $model->getNextStatuses(false, true);
     $this->assertCount(1, $report);
     $this->assertArrayHasKey('Item04Workflow/A', $report);
     $this->assertInstanceOf('raoul2000\\workflow\\base\\Status', $report['Item04Workflow/A']['status']);
     $this->assertCount(3, $report['Item04Workflow/A']['event']);
     $this->assertEquals([0 => ['name' => SimpleWorkflowBehavior::EVENT_BEFORE_CHANGE_STATUS, 'success' => null], 1 => ['name' => 'beforeEnterWorkflow{Item04Workflow}', 'success' => null], 2 => ['name' => 'beforeEnterStatus{Item04Workflow/A}', 'success' => false, 'messages' => [0 => 'my error message']]], $report['Item04Workflow/A']['event']);
     $this->assertEquals(false, $report['Item04Workflow/A']['isValid']);
 }
 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']);
 }
 public function testConvertionOnLeaveWorkflow()
 {
     $item = new Item04();
     $item->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'statusConverter' => 'converter']);
     $this->assertEquals(null, $item->status);
     $this->assertEquals('Item04Workflow/B', $item->getWorkflowStatus()->getId());
     $this->specify('convertion is done when leaving workflow', function () use($item) {
         $item->sendToStatus(null);
         expect('item to not be in a workflow', $item->getWorkflow())->equals(null);
         expect('item to not have status', $item->hasWorkflowStatus())->false();
         expect('status attribut to be converted into 55', $item->status)->equals(55);
     });
 }
 public function testReturnReportWithEventsOnEnterWorkflow()
 {
     /** @var Item04|ActiveWorkflowBehavior $model */
     $model = new Item04();
     $model->on(WorkflowEvent::beforeEnterStatus('Item04Workflow/A'), function ($event) {
         /** @var WorkflowEvent $event*/
         $event->invalidate('my error message');
     });
     $report = $model->getNextStatuses(false, true);
     $this->assertCount(1, $report);
     $this->assertArrayHasKey('Item04Workflow/A', $report);
     $this->assertInstanceOf('fproject\\workflow\\core\\Status', $report['Item04Workflow/A']['status']);
     $this->assertCount(2, $report['Item04Workflow/A']['event']);
     $this->assertEquals([0 => ['name' => 'beforeEnterWorkflow{Item04Workflow}', 'success' => null], 1 => ['name' => 'beforeEnterStatus{Item04Workflow/A}', 'success' => false, 'messages' => [0 => 'my error message']]], $report['Item04Workflow/A']['event']);
     $this->assertEquals(false, $report['Item04Workflow/A']['isValid']);
 }
 public function testStatusEqualsFails()
 {
     /** @var ActiveWorkflowBehavior $item */
     $item = new Item04();
     $item->sendToStatus('A');
     expect_not($item->statusEquals('B'));
     expect_not($item->statusEquals('Item04Workflow/B'));
     expect_not($item->statusEquals('NOTFOUND'));
     expect_not($item->statusEquals('Item04Workflow/NOTFOUND'));
     expect_not($item->statusEquals('NOTFOUND/NOTFOUND'));
     expect_not($item->statusEquals('invalid name'));
     expect_not($item->statusEquals(''));
     expect_not($item->statusEquals(null));
     $statusA = $item->getWorkflowStatus();
     $item->sendToStatus('B');
     verify($item->statusEquals('B'));
     expect_not($item->statusEquals($statusA));
 }