示例#1
0
 function testImpossibleCondition()
 {
     $transition = new Tiki_Transition('A', 'B');
     $transition->setStates(array('A', 'C', 'D', 'F'));
     $transition->addGuard('exactly', 4, array('C', 'D', 'E'));
     $this->assertEquals(array(array('class' => 'invalid', 'count' => 4, 'set' => array('C', 'D', 'E'))), $transition->explain());
 }
示例#2
0
 function testUnder()
 {
     $transition = new Tiki_Transition('A', 'B');
     $transition->setStates(array('A', 'C', 'D', 'F'));
     $transition->addGuard('atMost', 4, array('C', 'D', 'E', 'F', 'G'));
     $this->assertEquals(array(), $transition->explain());
 }
示例#3
0
 /**
  * @param $transitionId
  * @param $object
  * @param null $type
  * @return bool
  */
 function triggerTransition($transitionId, $object, $type = null)
 {
     // Make sure the transition exists
     if (!($transition = $this->getTransition($transitionId))) {
         return false;
     }
     // Make sure the user can use it
     $perms = Perms::get(array('type' => 'transition', 'object' => $transitionId));
     if (!$perms->trigger_transition) {
         return false;
     }
     // Verify that the states are consistent
     $states = $this->getCurrentStates($object, $type);
     $tr = new Tiki_Transition($transition['from'], $transition['to']);
     $tr->setStates($states);
     foreach ($transition['guards'] as $guard) {
         call_user_func_array(array($tr, 'addGuard'), $guard);
     }
     if (!$tr->isReady()) {
         return false;
     }
     $this->addState($transition['to'], $object, $type);
     if (!$transition['preserve']) {
         $this->removeState($transition['from'], $object, $type);
     }
     return true;
 }