function testSaveIsRepeatable()
 {
     $vehicle = $this->createVehicle(array('make' => 'Honda', 'model' => 'Civic', 'year' => 2000));
     $model = new VF_Level('model');
     $model->setTitle('Civic');
     $model->save($vehicle->getValue('make'));
     $this->assertEquals($vehicle->getValue('model'), $model->getId(), 'saving multiple times should keep the same id');
 }
 function testShouldLoadMultipleYear()
 {
     $vehicle1 = $this->createMMY();
     $vehicle2 = $this->createMMY();
     $year_reloaded = new VF_Level('year', $vehicle1->getValue('year'));
     $year_reloaded2 = new VF_Level('year', $vehicle2->getValue('year'));
     $this->assertEquals($vehicle1->getValue('year'), $year_reloaded->getId());
     $this->assertEquals($vehicle2->getValue('year'), $year_reloaded2->getId(), 'should load multiple year');
 }
 function testConformsLevelMake()
 {
     return $this->markTestIncomplete();
     $honda = new VF_Level('make');
     $honda->setTitle('Honda');
     $honda->save();
     $honda2 = new VF_Level('make');
     $honda2->setTitle('Honda');
     $honda2->save();
     $this->assertEquals($honda->getId(), $honda2->getId(), 'when saving two makes with same title, they should get the same id');
 }
Example #4
0
 function testDoesntConformModelFromDiffrentMake()
 {
     $honda = new VF_Level('make');
     $honda->setTitle('Honda');
     $honda_make_id = $honda->save();
     $civic = new VF_Level('model');
     $civic->setTitle('Civic');
     $civic->save($honda_make_id);
     $ford = new VF_Level('make');
     $ford->setTitle('Ford');
     $ford_make_id = $ford->save();
     $civic2 = new VF_Level('model');
     $civic2->setTitle('Civic');
     $civic2->save($ford_make_id);
     $this->assertEquals($civic->getId(), $civic2->getId(), 'when saving two models with same title, but under different makes, they should get same ids');
 }
Example #5
0
 function listInUse(VF_Level $entity, $parents = array(), $product_id = 0)
 {
     unset($parents[$entity->getType()]);
     if (isset($this->objs_in_use[$entity->getType()][$entity->getId()])) {
         return $this->objs_in_use[$entity->getType()][$entity->getId()];
     }
     $result = $this->doListInUse($entity, $parents, $product_id);
     $this->objs_in_use[$entity->getType()][$entity->getId()] = array();
     while ($row = $result->fetchObject()) {
         $obj = $entity->createEntity($entity->getType(), 0);
         $obj->setId($row->id);
         $obj->setTitle($row->title);
         array_push($this->objs_in_use[$entity->getType()][$entity->getId()], $obj);
     }
     return $this->objs_in_use[$entity->getType()][$entity->getId()];
 }
 function saveAction()
 {
     $id = (int) $this->getRequest()->getParam('save');
     $entity = new VF_Level($this->getEntity()->getType(), $id);
     $entity->setTitle($this->getRequest()->getParam('title'));
     $entity->save($this->requestLevels());
     if ($this->getRequest()->isXmlHttpRequest()) {
         echo $entity->getId();
         exit;
     }
     $this->doSave();
 }
Example #7
0
 /**
  * Check if an entity is the selected one for this 'level'
  *
  * @param VF_Level $levelObject - level to check if is selected
  *
  * @return bool if this is the one that is supposed to be currently selected
  */
 function isLevelSelected($levelObject)
 {
     if ($this->level != $this->leafLevel()) {
         return (bool) ($levelObject->getId() == $this->searchForm->getSelected($this->level));
     }
     VF_Singleton::getInstance()->setRequest($this->searchForm->getRequest());
     $currentSelection = VF_Singleton::getInstance()->vehicleSelection();
     if (false === $currentSelection) {
         return false;
     }
     if ('year_start' == $this->yearRangeAlias) {
         return (bool) ($levelObject->getTitle() == $this->earliestYearInVehicles($currentSelection));
     } else {
         if ('year_end' == $this->yearRangeAlias) {
             return (bool) ($levelObject->getTitle() == $this->latestYearInVehicles($currentSelection));
         }
     }
     $level = false;
     if (is_array($currentSelection) && count($currentSelection) == 1) {
         $firstVehicle = $currentSelection[0];
         /** @var VF_Vehicle $firstVehicle */
         $level = $firstVehicle->getLevel($this->leafLevel());
     } elseif ($currentSelection instanceof VF_Vehicle) {
         $level = $currentSelection->getLevel($this->leafLevel());
     }
     if ($level) {
         return (bool) ($levelObject->getTitle() == $level->getTitle());
     }
 }
Example #8
0
 public function assertArrayDoesNotHaveLevelIDPresent(array $levels, VF_Level $actualLevel)
 {
     foreach ($levels as $level) {
         /** @var $level VF_Level */
         if ($level->getId() == $actualLevel->getId()) {
             $this->fail(sprintf("Level ID %s was not supposed to be in result but was found.", $actualLevel->getId()));
         }
     }
     return;
 }