/** * Initializes fixture processor before applying data * * @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture * @return EcomDev_PHPUnit_Model_Fixture_Processor_Interface */ public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $generateData = $fixture->getFixtureValue('generate'); $fixtureData = array(); foreach ($generateData as $generateByTypes) { foreach ($generateByTypes as $type => $data) { if (!isset($this->fixtures[$type]['path'])) { continue; } $path = $this->fixtures[$type]['path']; $fixtureType = isset($this->fixtures[$type]['type']) ? $this->fixtures[$type]['type'] : 'tables'; if (!isset($fixtureData[$fixtureType][$path])) { $fixtureData[$fixtureType][$path] = array(); } $fixtureData[$fixtureType][$path] = array_merge($fixtureData[$fixtureType][$path], Mage::getSingleton($this->fixtures[$type]['model'])->process($data)); } } foreach ($fixtureData as $type => $entities) { $fixtureValue = $fixture->getFixtureValue($type); foreach ($entities as $path => $records) { Mage::helper('hackathon_fixturegenerator')->updatePathValue($path, $records, $fixtureValue); } $fixture->setFixtureValue($type, $fixtureValue); } return $this; }
/** * Discard applied table records * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Tables */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $restoreTableData = array(); // Data for tables used in shared fixture if ($fixture->isScopeLocal() && $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) { $restoreTableData = $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED); } $this->getResource()->beginTransaction(); foreach (array_reverse(array_keys($data)) as $tableEntity) { $this->getResource()->cleanTable($tableEntity); } foreach (array_keys($data) as $tableEntity) { if (isset($restoreTableData[$tableEntity])) { $this->getResource()->loadTableData($tableEntity, $restoreTableData[$tableEntity]); } } $this->getResource()->commit(); $fixture->setStorageData(self::STORAGE_KEY, null); return $this; }
/** * Discard applied scope models * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { if ($fixture->getStorageData(self::STORAGE_KEY) === null) { return $this; } EcomDev_PHPUnit_Test_Case_Util::app()->disableEvents(); $scope = array_reverse($fixture->getStorageData(self::STORAGE_KEY)); foreach ($scope as $models) { foreach ($models as $model) { $model->delete(); } } $fixture->setStorageData(self::STORAGE_KEY, null); EcomDev_PHPUnit_Test_Case_Util::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array(Mage_Core_Model_Store::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG, Mage_Core_Model_Website::CACHE_TAG)); EcomDev_PHPUnit_Test_Case_Util::app()->enableEvents(); EcomDev_PHPUnit_Test_Case_Util::app()->reinitStores(); return $this; }
/** * Discard applied attribute records * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $ignoreCleanUp = array(); // Ignore cleaning of entities if shared fixture loaded something for them if ($fixture->isScopeLocal() && $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) { $ignoreCleanUp = $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED); } $this->getResource()->beginTransaction(); foreach (array_keys($data) as $entityType) { if (in_array($entityType, $ignoreCleanUp)) { continue; } $this->_getAttributeLoader($entityType)->cleanAttributes($entityType, $data); } $this->getResource()->commit(); EcomDev_PHPUnit_Test_Case_Util::replaceRegistry('_singleton/eav/config', null); //clean out the EAV cache return $this; }
/** * Initializes fixture processor before applying data * * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * @return EcomDev_PHPUnit_Model_Fixture_Processor_Registry */ public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $options = $fixture->getOptions(); $registry = array(); foreach (array('singleton', 'resource', 'helper', 'registry') as $type) { if (!isset($options[$type])) { continue; } foreach ($options[$type] as $name) { $registry[$type][] = $name; } } if ($registry) { $fixture->setFixtureValue('registry', $registry); } return $this; }
/** * Discard applied eav records * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $ignoreCleanUp = array(); // Ignore cleaning of entities if shared fixture loaded something for them if ($fixture->isScopeLocal() && $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) { $ignoreCleanUp = $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED); } $typesToRestore = array(); $this->getResource()->beginTransaction(); foreach (array_keys($data) as $entityType) { $eavLoader = $this->_getEavLoader($entityType); if (in_array($entityType, $ignoreCleanUp)) { if ($eavLoader instanceof EcomDev_PHPUnit_Model_Mysql4_Fixture_RestoreAwareInterface) { $eavLoader->clearData($entityType); } continue; } $eavLoader->cleanEntity($entityType); if ($eavLoader instanceof EcomDev_PHPUnit_Model_Mysql4_Fixture_RestoreAwareInterface) { $typesToRestore[$entityType] = $eavLoader; } } $this->getResource()->commit(); if ($typesToRestore) { $this->getResource()->beginTransaction(); foreach ($typesToRestore as $entityType => $eavLoader) { $eavLoader->restoreData($entityType)->clearData($entityType); } $this->getResource()->commit(); } return $this; }
/** * Discard applied cache options * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { EcomDev_PHPUnit_Test_Case_Util::app()->setCacheOptions($fixture->getStorageData(self::STORAGE_KEY)); return $this; }
/** * Discard applied eav records * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $ignoreCleanUp = array(); // Ignore cleaning of entities if shared fixture loaded something for them if ($fixture->isScopeLocal() && $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) { $ignoreCleanUp = $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED); } $this->getResource()->beginTransaction(); foreach (array_keys($data) as $entityType) { if (in_array($entityType, $ignoreCleanUp)) { continue; } $this->_getEavLoader($entityType)->cleanEntity($entityType); } $this->getResource()->commit(); return $this; }
/** * Discard applied virtual file system structure * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $fixture->getVfs()->discard(); $fixture->setStorageData(self::STORAGE_KEY, null); return $this; }