public function testbean_implements()
 {
     error_reporting(E_ERROR | E_PARSE);
     $aowProcessed = new AOW_Processed();
     $this->assertEquals(false, $aowProcessed->bean_implements(''));
     //test with blank value
     $this->assertEquals(false, $aowProcessed->bean_implements('test'));
     //test with invalid value
     $this->assertEquals(true, $aowProcessed->bean_implements('ACL'));
     //test with valid value
 }
 public function testrun_actions()
 {
     $aowWorkFlow = new AOW_WorkFlow();
     //prepare the required objects and variables
     $aowWorkFlow->id = 1;
     $call = new Call();
     $call->id = 1;
     //execute the method and verify if it creates records in processed table
     $result = $aowWorkFlow->run_actions($call);
     //test for a entry in AOW_Processed table.
     $processed = new AOW_Processed();
     $processed->retrieve_by_string_fields(array('aow_workflow_id' => 1, 'parent_id' => 1));
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($processed->id));
     $this->assertEquals(36, strlen($processed->id));
     //mark the record as deleted and verify that this record cannot be retrieved anymore.
     $processed->mark_deleted($processed->id);
     $result = $processed->retrieve($processed->id);
     $this->assertEquals(null, $result);
 }
 /**
  * Run the actions against the passed $bean
  */
 function run_actions(SugarBean $bean)
 {
     require_once 'modules/AOW_Processed/AOW_Processed.php';
     $processed = new AOW_Processed();
     if (!$this->multiple_runs) {
         $processed->retrieve_by_string_fields(array('aow_workflow_id' => $this->id, 'parent_id' => $bean->id));
         if ($processed->status == 'Complete') {
             //should not have gotten this far, so return
             return true;
         }
     }
     $processed->aow_workflow_id = $this->id;
     $processed->parent_id = $bean->id;
     $processed->parent_type = $bean->module_dir;
     $processed->status = 'Running';
     $processed->save(false);
     $processed->load_relationship('aow_actions');
     $pass = true;
     $sql = "SELECT id FROM aow_actions WHERE aow_workflow_id = '" . $this->id . "' AND deleted = 0 ORDER BY action_order ASC";
     $result = $this->db->query($sql);
     while ($row = $this->db->fetchByAssoc($result)) {
         $action = new AOW_Action();
         $action->retrieve($row['id']);
         if ($this->multiple_runs || !$processed->db->getOne("select id from aow_processed_aow_actions where aow_processed_id = '" . $processed->id . "' AND aow_action_id = '" . $action->id . "' AND status = 'Complete'")) {
             $action_name = 'action' . $action->action;
             if (file_exists('custom/modules/AOW_Actions/actions/' . $action_name . '.php')) {
                 require_once 'custom/modules/AOW_Actions/actions/' . $action_name . '.php';
             } else {
                 if (file_exists('modules/AOW_Actions/actions/' . $action_name . '.php')) {
                     require_once 'modules/AOW_Actions/actions/' . $action_name . '.php';
                 } else {
                     return false;
                 }
             }
             $flow_action = new $action_name($action->id);
             if (!$flow_action->run_action($bean, unserialize(base64_decode($action->parameters)))) {
                 $pass = false;
                 $processed->aow_actions->add($action->id, array('status' => 'Failed'));
             } else {
                 $processed->aow_actions->add($action->id, array('status' => 'Complete'));
             }
         }
     }
     if ($pass) {
         $processed->status = 'Complete';
     } else {
         $processed->status = 'Failed';
     }
     $processed->save(false);
     return $pass;
 }