function vafDoLevel( $level, $parent_id = 0 ) { $schema = new VF_Schema(); $finder = new VF_Level( $level ); $parentLevel = $schema->getPrevLevel( $level ); if( $parentLevel ) { $entities = $finder->listInUse( array( $parentLevel => $parent_id ) ); } else { $entities = $finder->listInUse(); } echo $level . '["' . $parent_id . '"] = new Array();'; foreach( $entities as $entity ) { ?> var obj = new Array(); obj["title"] = "<?=$entity->getTitle()?>"; obj["id"] = "<?=$entity->getId()?>"; <?=$level?>["<?=$parent_id?>"].push( obj ); <?php if( $level != $schema->getLeafLevel() ) { vafDoLevel( $schema->getNextLevel($level), $entity->getId() ); } echo "\n"; } }
function listEntities($level) { if (!in_array($level, $this->getSchema()->getLevels())) { throw new VF_Level_Exception_InvalidLevel('Invalid level [' . $level . ']'); } $parent_id = 0; $parentLevel = $this->getSchema()->getPrevLevel($level); if ($parentLevel) { $parent_id = $this->getSelected($parentLevel); } $levelObject = new VF_Level($level); if ($this->isNotRootAndHasNoParent($level, $parent_id)) { return array(); } if (!$parentLevel || !$parent_id) { if ($this->shouldListAll()) { return $levelObject->listAll(); } else { return $levelObject->listInUse(array()); } } if ($this->shouldListAll()) { return $levelObject->listAll($parent_id); } else { return $levelObject->listInUse($this->getFlexibleSearch()->getLevelAndValueForSelectedPreviousLevels($level)); } }
function testSaveRootLevel() { $make = new VF_Level('make'); $make->setTitle(self::ENTITY_TITLE); $make = $this->saveAndReload($make); $this->assertNotEquals(0, $make->getId(), 'saved entity should have an id value'); $this->assertSame(self::ENTITY_TITLE, $make->getTitle(), 'saved entity should have correct title value'); }
function listEntities($level) { if ($level != $this->searchStrategy->getSchema()->getRootLevel()) { return array(); } $entity = new VF_Level($level); return $entity->listInUse($this->searchStrategy->getRequestLevels(), $this->getProductId()); }
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 testSaveRootLevel() { $make = new VF_Level('make'); $make->setTitle('Honda'); $make = $this->saveAndReload($make); $make->setTitle('Acura'); $make = $this->saveAndReload($make); $this->assertSame('Acura', $make->getTitle(), 'saved entity should have correct title value'); }
function _toHtml() { $return = '<ul>'; $make = new VF_Level('make'); foreach ($make->listAll() as $eachMake) { $return .= '<li><a href="?make=' . $eachMake->getId() . '"><img src="/logos/' . strtoupper($eachMake->getTitle()) . '.jpg" /></a></li>'; } $return .= '</ul>'; return $return; }
function testShuoldListFromSecondSchema() { $schema = VF_Schema::create('foo,bar'); $vehicle = $this->createVehicle(array('foo' => '123', 'bar' => '456'), $schema); $mapping = new VF_Mapping(1, $vehicle); $mapping->save(); $foo = new VF_Level('foo', null, $schema); $actual = $foo->listInUse(); $this->assertEquals('123', $actual[0], 'should list for level in 2nd schema "foo"'); }
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'); }
function testUsesOneQueryOnMultipleCalls() { $level = new VF_Level('make'); $level->setTitle('make'); $id = $level->save(); $this->getReadAdapter()->getProfiler()->clear(); $this->getReadAdapter()->getProfiler()->setEnabled(true); $level = new VF_Level('make', $id); $level = new VF_Level('make', $id); $queries = $this->getReadAdapter()->getProfiler()->getQueryProfiles(); $this->assertEquals(1, count($queries)); }
function testSameMakeDifferentModel() { $this->importVehiclesList( "make, model, year\n" . "makeA,modelA,2000\n" . "makeB,modelA,2000"); $makeA = new VF_Level( 'make', $this->levelFinder()->findEntityIdByTitle( 'make', 'makeA' ) ); $makeB = new VF_Level( 'make', $this->levelFinder()->findEntityIdByTitle( 'make', 'makeB' ) ); $this->assertEquals( 1, count($makeA->getChildren()), 'when a model name is not unique, should be stored under the proper parent' ); $this->assertEquals( 1, count($makeB->getChildren()), 'when a model name is not unique, should be stored under the proper parent' ); }
function testWithParentYear() { $vehicle1 = $this->createMMY('Acura', 'Integra', '2002'); $vehicle2 = $this->createMMY('Honda', 'Accord', '2002'); $vehicle3 = $this->createMMY('Honda', 'Civic', '2002'); $this->insertMappingMMY($vehicle1); $this->insertMappingMMY($vehicle2); $this->insertMappingMMY($vehicle3); $year = new VF_Level('year'); $actual = $year->listInUseByTitle(array('make' => $vehicle2->getLevel('make')->getTitle(), 'model' => $vehicle2->getLevel('model')->getTitle())); $this->assertEquals(1, count($actual)); $this->assertEquals($vehicle2->getLevel('year')->getId(), $actual[0]->getId()); }
function testShouldNotIncludeOptionsNotInUse() { return $this->markTestIncomplete(); $this->insertProduct('sku1'); $startTime = microtime(); $year = new VF_Level('year'); $year->listInUse(); $endTime = microtime(); echo $endTime-$startTime; //$this->assertTrue( $endTime - $startTime < .03, 'should take less than this much time to list stuff'); }
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'); }
function getLevel($level) { if ($this->hasLoadedLevel($level)) { return $this->levels[$level]; } if ($this->levelIsOutsideFlexibleSelection($level)) { return new VF_Level($level, 0, $this->schema()); } $id = $this->getValue($level); $levelFinder = new VF_Level_Finder($this->schema()); $object = $levelFinder->find($level, $id); if (false == $object) { $object = new VF_Level($level, $id, $this->schema()); if (false == $id) { $title = isset($this->titles[$level]) ? $this->titles[$level] : ''; $object->setTitle($title); } } $this->levels[$level] = $object; return $object; }
function testListAllObeysParentIdForModel() { $y2000 = $this->newYear('2000'); $y2000->save(); $y2001 = $this->newYear('2001'); $y2001->save(); $honda = $this->newMake('Honda'); $honda->save($y2000); $honda = $this->newMake('Honda'); $honda->save($y2001); $civic = $this->newModel('Civic'); $civic->save($honda->getId()); $model = new VF_Level('model'); $models = $model->listAll(array('year'=>$y2000->getId(), 'make'=>$honda->getId())); $this->assertEquals( 0, count($models), 'list all should not find items from different parent id even in global mode' ); }
protected function getParentTitle() { if ($this->getId() && $this->getEntity()->getPrevLevel()) { $entity = new VF_Level($this->getEntity()->getPrevLevel(), $this->getId()); return $entity->getTitle(); } }
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; }
function testYearAsc() { $schemaGenerator = new VF_Schema_Generator(); $schemaGenerator->setSorting('year', 'asc'); $schema = new VF_Schema(); $this->assertEquals('asc', $schema->getSorting('year')); $vehicle1 = $this->createMMY('Honda', 'Civic', '1999'); $vehicle2 = $this->createMMY('Honda', 'Civic', '2000'); $vehicle3 = $this->createMMY('Honda', 'Civic', '2001'); $this->insertMappingMMY($vehicle1); $this->insertMappingMMY($vehicle2); $this->insertMappingMMY($vehicle3); $year = new VF_Level('year'); $actual = $year->listInUse(array('model' => $vehicle1->getLevel('model')->getId())); $this->assertEquals("1999", $actual[0]->getTitle(), 'should return years, in ASC order'); $this->assertEquals("2000", $actual[1]->getTitle(), 'should return years, in ASC order'); $this->assertEquals("2001", $actual[2]->getTitle(), 'should return years, in ASC order'); }
/** * @expectedException Exception */ function testGetChildrenThrowsExceptionForLeafLevel() { $year = new VF_Level( 'year' ); $year->getChildren(); }
function testgetPrevLevelYear() { $entity = new VF_Level('year'); $this->assertEquals( self::ENTITY_TYPE_MODEL, $entity->getPrevLevel(), 'getPrevLevel should return "model" for a entity of type "year"' ); }
/** @return VF_Level */ function findEntityByTitle($type, $title, $parent_id = 0) { $levelId = $this->findEntityIdByTitle($type, $title, $parent_id); if (!$levelId) { return false; } $level = new VF_Level($type, $levelId, $this->getSchema()); $level->setTitle($title); return $level; }
function testShouldListChildrenLevelsInSecondSchema() { $schema = VF_Schema::create('foo,bar'); $vehicle = $this->createVehicle(array('foo' => '123', 'bar' => '456'), $schema); $bar = new VF_Level('bar', null, $schema); $actual = $bar->listAll($vehicle->getValue('foo')); $this->assertEquals('456', $actual[0]->getTitle(), 'should list children levels in 2nd schema'); }
function getItems() { $make = new VF_Level('make'); return $make->listInUse(); }
function listEntities( $level ) { if(!in_array($level,$this->getSchema()->getLevels())) { throw new VF_Level_Exception_InvalidLevel('Invalid level ['.$level.']'); } $parent_id = 0; $parentLevel = $this->getSchema()->getPrevLevel( $level ); if( $parentLevel ) { $parent_id = $this->getSelected( $parentLevel ); } $levelObject = new VF_Level( $level ); if( $this->isNotRootAndHasNoParent( $level, $parent_id ) ) { return array(); } if( !$parentLevel || !$parent_id ) { return $levelObject->listInUse( array() ); } return $levelObject->listInUse( array($parentLevel=>$parent_id) ); }
function testListAllWithParentId() { $vehicle1 = $this->createMMY( 'A', 'A', '1' ); $vehicle2 = $this->createMMY( 'A', 'B', '1' ); $vehicle3 = $this->createMMY( 'B', 'Z', 'Z' ); $this->insertMappingMMY( $vehicle1 ); $this->insertMappingMMY( $vehicle2 ); $this->insertMappingMMY( $vehicle3 ); $model = new VF_Level('model'); $actual = $model->listAll($vehicle1->getLevel('make')->getId()); $this->assertEquals( 'A', $actual[0]->getTitle(), 'should sort items' ); $this->assertEquals( 'B', $actual[1]->getTitle(), 'should sort items' ); }
function newLevel($level, $title) { $level = new VF_Level($level); $level->setTitle($title); return $level; }
/** * 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 testConstructorSetsType() { $entity = new VF_Level('make'); $this->assertSame('make', $entity->getType()); }
function testDeleteFits() { $vehicle = $this->createMMY(); $this->insertMappingMMY( $vehicle, 1 ); $level = new VF_Level( 'year', $vehicle->getLevel('year')->getId() ); $level->deleteFits(); }