public function getApproval(BaseObject $object) { if ($object->isNew() === true || $object->isModified() === true || $object->isDeleted() === true) { throw new Exception('You can only approve an object which has already been saved'); } $columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_column', 'is_approved'); $approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_approved_value', true); $disabledApplications = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_disabled_applications'); // Test if we should crated an approval - is the column value different to out required value? // If our object is already approved then we can delete other $columnGetter = 'get' . sfInflector::camelize($columnName); if ($approvedValue != $object->{$columnGetter}()) { return sfApprovalPeer::retrieveOrCreateByObject($object); } else { sfApprovalPeer::deleteByObject($object); return null; } }
} 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'); }