public function executeApprove() { $approval = sfApprovalPeer::retrieveByUuid($this->getRequestParameter('uuid')); if (!$approval) { return 'NotFound'; } $object = $approval->getRelatedObject(); $this->setFlash('sf_approvable_object', $object); $class = get_class($object); $peerClass = get_class($object->getPeer()); $destination = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . $class . '_destination', '@homepage'); $approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . $class . '_approved_value', true); $columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . $class . '_column', 'is_approved'); $method = 'set' . call_user_func(array($peerClass, 'translateFieldName'), $columnName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); $ret = null; foreach (sfMixer::getCallables('sfApprovableActions:approve:pre') as $callable) { $ret = call_user_func($callable, $object); } if (!is_null($ret)) { return $ret; } $object->{$method}($approvedValue); $object->save(); $approval->delete(); foreach (sfMixer::getCallables('sfApprovableActions:approve:post') as $callable) { $ret = call_user_func($callable, $object); } if (!is_null($ret)) { return $ret; } $this->redirect($destination); }
} catch (Exception $err) { $t->pass('getApprovalUrl() on an unsaved class throws an exception'); } try { $item1->getApproval(); $t->fail('no code should be executed after throwing exception'); } catch (Exception $err) { $t->pass('getApproval() on an unsaved class throws an exception'); } try { sfApprovalPeer::retrieveOrCreateByObject($item1); $t->fail('no code should be executed after throwing exception'); } catch (Exception $err) { $t->pass('sfApprovalPeer::retrieveOrCreateByObject() on an unsaved class throws an exception'); } $item1->save(); $t->is($item1->getApproval(), null, 'getApproval() returns null for approved objects'); $t->is($item1->getApprovalUrl(), false, 'getApprovalUrl() returns false for approved objects'); $item1->{$approvable_setter}(!$approved_value); $item1->save(); $t->isa_ok($approval = $item1->getApproval(), 'sfApproval', 'Unapproved getApproval() returns and sfApproval object'); $t->isa_ok($item1->getApprovalUrl(), 'string', 'Unapproved getApprovalUrl() returns a string'); $t->isa_ok(sfApprovalPeer::retrieveOrCreateByObject($item1), 'sfApproval', 'retrieveOrCreateByObject() returns an sfApproval object'); $t->isa_ok(sfApprovalPeer::retrieveByUuid($approval->getUuid()), 'sfApproval', 'sfApprovalPeer::retrieveByUuid() returns an instance of sfApproval'); $item1->delete(); try { $item1->getApprovalUrl(); $t->fail('no code should be executed after throwing exception'); } catch (Exception $err) { $t->pass('getApprovalUrl() on an deleted class throws an exception'); }