/** * Handle scope row data * * @param string $type * @param array $row * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * @return boolean|Mage_Core_Model_Abstract */ protected function _handleScopeRow($type, $row, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { $previousScope = array(); if ($fixture->isScopeLocal() && $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED) !== null) { $previousScope = $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED); } if (isset($previousScope[$type][$row[$type . '_id']])) { return false; } $scopeModel = Mage::getModel($this->modelByType[$type]); $scopeModel->setData($row); // Change property for saving new objects with specified ids EcomDev_Utils_Reflection::setRestrictedPropertyValues($scopeModel->getResource(), array('_isPkAutoIncrement' => false)); try { $scopeModel->isObjectNew(true); $scopeModel->save(); } catch (Exception $e) { Mage::logException($e); // Skip duplicated key violation, since it might be a problem // of previous run with fatal error // Revert changed property EcomDev_Utils_Reflection::setRestrictedPropertyValues($scopeModel->getResource(), array('_isPkAutoIncrement' => true)); // Load to make possible deletion $scopeModel->load($row[$type . '_id']); } // Revert changed property EcomDev_Utils_Reflection::setRestrictedPropertyValues($scopeModel->getResource(), array('_isPkAutoIncrement' => true)); return $scopeModel; }
/** * Apply 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 apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { if ($fixture->isScopeLocal() && ($parentData = $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED))) { $data = array_merge_recursive($parentData, $data); } $fixture->getVfs()->apply($data); $fixture->setStorageData(self::STORAGE_KEY, $data); 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 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; }
/** * 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 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; }