/** * 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()); } }
function testSelected() { $this->switchSchema('make,model,year'); $vehicle = $this->createMMY('Honda', 'Civic', '2000'); $request = new Zend_Controller_Request_Http(); $request->setParams($vehicle->toTitleArray()); $search = new VF_Search_Form(); VF_Singleton::getInstance()->setRequest($request); $this->assertEquals($vehicle->getValue('model'), $search->getSelected('model')); }