/**
  * Create and configure forn
  *
  * @param string $formClassName 
  * @author Łukasz Wojciechowski
  */
 public function createAndConfigureForm($formClassName)
 {
     $this->form = new $formClassName($this->object);
     $vs = $this->form->getValidatorSchema();
     foreach ($vs->getFields() as $fieldName => $validator) {
         $this->form->setValidator($fieldName, new sfValidatorPass());
     }
     if (isset($this->form['id'])) {
         unset($this->form['id']);
     }
     $formFieldNames = $this->getFieldNamesOfForm($this->form);
     $this->form->useFields($formFieldNames);
     // making form field default values available for widget XML config file placeholders
     foreach ($formFieldNames as $fieldName) {
         if (!in_array($fieldName, $this->deprecated_placeholders)) {
             $this->{$fieldName} = $this->object->getByName($fieldName, BasePeer::TYPE_FIELDNAME);
         }
     }
 }
 /**
  * 
  * Compares two propel objects and notifies the PHPUnit / Kaltura's listeners
  * @param BaseObject $outputReference
  * @param BaseObject $newResult
  * @return array<> $newErrors, if the objects are equal
  */
 public function comparePropelObjectsByFields($outputReference, $newResult, $validErrorFields)
 {
     //Gets the data peer of the object (used to geting all the obejct feilds)
     $dataPeer = $outputReference->getPeer();
     $outputReferenceId = $outputReference->getId();
     $newResultId = $newResult->getId();
     //Gets all object feilds
     $fields = call_user_func(array($dataPeer, "getFieldNames"), BasePeer::TYPE_PHPNAME);
     $newErrors = array();
     //Create the xml elements by all fields and their values
     foreach ($fields as $field) {
         PHP_Timer::start();
         //If the field is in the valid failure list then we skip him
         if (in_array($field, $validErrorFields)) {
             continue;
         } else {
             $expectedValue = $outputReference->getByName($field);
             $actualValue = $newResult->getByName($field);
             //if this is an array we need to change it to a string
             $this->compareOnField($field, $actualValue, $expectedValue, "assertEquals");
         }
     }
     return $newErrors;
 }
예제 #3
0
 public static function getParamListFromObjectAsArray(BaseObject $obj, $param_names)
 {
     if ($obj == NULL) {
         return NULL;
     }
     if (!$obj instanceof BaseObject) {
         throw new Exception("getParamFromObject should have the first parameter an object of type BaseObject");
     }
     $res = array();
     foreach ($param_names as $param_name) {
         $res[$param_name] = $obj->getByName($param_name, BasePeer::TYPE_FIELDNAME);
     }
     return $res;
 }
예제 #4
0
 /**
  * Finder fluid method to restrict results to a related object
  * Examples:
  *   $commentFinder->relatedTo($article)
  *    => $c->add(CommentPeer::ARTICLE_ID, $article->getId())
  *
  * @param  BaseObject $object The related object to restrict to
  * @return sfPropelFinder the current finder object
  */
 public function relatedTo($object)
 {
     // looking for a 1-n relationship
     $relatedObjectTableName = $object->getPeer()->getTableMap()->getName();
     foreach (sfPropelFinderUtils::getColumnsForPeerClass($this->peerClass) as $c) {
         if ($c->getRelatedTableName() == $relatedObjectTableName) {
             $this->addCondition('and', $c->getFullyQualifiedName(), $object->getByName($c->getRelatedName(), BasePeer::TYPE_COLNAME), Criteria::EQUAL);
             return $this;
         }
     }
     // looking for a n-1 relationship
     $localObjectTableName = $this->object->getPeer()->getTableMap()->getName();
     foreach (sfPropelFinderUtils::getColumnsForPeerClass(get_class($object->getPeer())) as $c) {
         if ($c->getRelatedTableName() == $localObjectTableName) {
             $this->addCondition('and', $c->getRelatedName(), $object->getByName($c->getFullyQualifiedName(), BasePeer::TYPE_COLNAME), Criteria::EQUAL);
             return $this;
         }
     }
     throw new Exception('Could not find a relation with object of class ' . get_class($object));
 }