Commit 4ea1194a authored by Jonathan Day's avatar Jonathan Day

re-enabling the Attributes Fixture loader as first coded by @steverice - YAML...

re-enabling the Attributes Fixture loader as first coded by @steverice - YAML structure is the same as Steve's proposal, needs more work on the cleanAttributes() and runRequiredIndexers() methods.
parent 66923042
......@@ -36,6 +36,8 @@ class EcomDev_PHPUnit_Model_Fixture
// Configuration path for attribute loaders
const XML_PATH_FIXTURE_ATTRIBUTE_LOADERS = 'phpunit/suite/fixture/attribute';
// Default attribute loader class alias
const DEFAULT_ATTRIBUTE_LOADER_CLASS = 'ecomdev_phpunit/fixture_attribute_default';
// Default eav loader class node in loaders configuration
/* @deprecated since 0.3.0 */
......
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2013 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
extends Mage_Core_Model_Abstract
implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
const STORAGE_KEY = 'entities';
// Configuration path for attribute loaders
const XML_PATH_FIXTURE_ATTRIBUTE_LOADERS = 'phpunit/suite/fixture/attribute';
// Default attribute loader class node in loaders configuration
const DEFAULT_ATTRIBUTE_LOADER_NODE = 'default';
// Default attribute loader class alias
const DEFAULT_ATTRIBUTE_LOADER_CLASS = 'ecomdev_phpunit/fixture_attribute_default';
/**
* Initialize fixture resource model
*/
protected function _construct()
{
$this->_init('ecomdev_phpunit/fixture');
}
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
{
return $this;
}
/**
* Retrieves attribute loader for a particular attribute type
*
* @param string $entityType
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
*/
protected function _getAttributeLoader($entityType)
{
$loaders = Mage::getConfig()->getNode(self::XML_PATH_FIXTURE_ATTRIBUTE_LOADERS);
if (isset($loaders->$entityType)) {
$classAlias = (string)$loaders->$entityType;
} elseif (isset($loaders->{self::DEFAULT_ATTRIBUTE_LOADER_NODE})) {
$classAlias = (string)$loaders->{self::DEFAULT_ATTRIBUTE_LOADER_NODE};
} else {
$classAlias = self::DEFAULT_ATTRIBUTE_LOADER_CLASS;
}
return Mage::getResourceSingleton($classAlias);
}
/**
* Apply attribute records from fixture file
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
{
$aAttributeLoaders = array();
$this->getResource()->beginTransaction();
foreach ($data as $entityType => $values) {
$aAttributeLoaders[] = $this->_getAttributeLoader($entityType)
->setFixture($fixture)
->setOptions($fixture->getOptions())
->loadAttribute($entityType, $values);
}
$this->getResource()->commit();
// foreach ($aAttributeLoaders as $oAttributeLoader){
// $oAttributeLoader->runRequiredIndexers();
// }
$fixture->setStorageData(self::STORAGE_KEY, array_keys($data));
return $this;
}
/**
* Discard applied attribute records
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $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_Fixture_Interface::SCOPE_SHARED)) {
$ignoreCleanUp = $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::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();
return $this;
}
}
\ No newline at end of file
......@@ -79,18 +79,27 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
*/
public function cleanAttributes($entityType, array $attributeCodes)
public function cleanAttributes($entityType, array $attributes)
{
$eavSetup = new Mage_Eav_Model_Entity_Setup('core_setup');
try {
if(empty($attributes)) {
throw new Exception('Attribute array cannot be empty');
}
else {
$aAttributeCodes = array();
foreach($attributes as $oAttribute){
$aAttributeCodes[] = $oAttribute->getCode();
}
}
//delete entry from eav/attribute and allow FK cascade to delete all related values
$this->_getWriteAdapter()
->delete(
$this->getTable('eav/attribute'),
array(
'entity_type_id = ?' => $eavSetup->getEntityTypeId($entityType),
'attribute_code IN (?)' => $attributeCodes,
'attribute_code IN (?)' => $aAttributeCodes,
)
);
$this->_getWriteAdapter()->commit();
......
......@@ -94,6 +94,7 @@
<config>ecomdev_phpunit/fixture_processor_config</config>
<config_xml>ecomdev_phpunit/fixture_processor_config</config_xml>
<cache_options>ecomdev_phpunit/fixture_processor_cache</cache_options>
<attributes>ecomdev_phpunit/fixture_processor_attributes</attributes>
<eav>ecomdev_phpunit/fixture_processor_eav</eav>
<tables>ecomdev_phpunit/fixture_processor_tables</tables>
<vfs>ecomdev_phpunit/fixture_processor_vfs</vfs>
......@@ -102,10 +103,9 @@
<!-- Fixture loaders for EAV attributes
Default can be used but does not support extra attribute table configuration -->
<default>ecomdev_phpunit/fixture_attribute_default</default>
<!--<catalog_product>ecomdev_phpunit/fixture_attribute_catalog_product</catalog_product>-->
</attribute>
<eav>
<!-- Here goes the list of fixture loaders for EAV
<!-- Here goes the list of fixture loaders for EAV entities
If no fixture loader is specified for entity, then default will be used
-->
<default>ecomdev_phpunit/fixture_eav_default</default>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment