Skip to content

Commit

Permalink
Merge pull request #79 from elvetemedve/feature/improve-product-fixture
Browse files Browse the repository at this point in the history
Fill attribute_set_id and default type_id
  • Loading branch information
James Cowie committed Dec 14, 2014
2 parents f4a79f2 + 14076c0 commit 4875540
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/MageTest/MagentoExtension/Fixture/ProductSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function let()

$this->model->shouldReceive('getResource')->andReturn($productResourceModel);
$this->model->shouldReceive('getAttributes')->andReturn(array());
$this->model->shouldReceive('setAttributeSetId')->andReturn($productModel);
$this->model->shouldReceive('setTypeId')->andReturn($productModel);
}

function it_should_throw_exception_if_sku_is_not_defined()
Expand Down Expand Up @@ -221,4 +223,23 @@ function it_should_load_object_and_delete_it_when_delete_is_requested()

$this->delete(554);
}

function it_should_fill_attribute_set_and_type_id_before_loading_attributes()
{
$productData = array(
'sku' => 'test_sku',
'attribute_set_id' => 123,
);

$this->model->shouldReceive('setData')->andReturn($this->model);
$this->model->shouldReceive('setCreatedAt')->andReturn($this->model);
$this->model->shouldReceive('setWebsiteIds')->andReturn($this->model);
$this->model->shouldReceive('getIdBySku')->andReturn(false);

$this->model->shouldReceive('setAttributeSetId')->with(123)->once()->ordered();
$this->model->shouldReceive('setTypeId')->with('simple')->atLeast()->once()->ordered();
$this->model->shouldReceive('getAttributes')->atLeast()->once()->ordered();

$this->create($productData);
}
}
9 changes: 9 additions & 0 deletions src/MageTest/MagentoExtension/Fixture/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function create(array $attributes)
$this->model->setTypeId($attributes['type_id']);
}

if (!empty($attributes['attribute_set_id'])) {
$this->model->setAttributeSetId($attributes['attribute_set_id']);
}

$this->validateAttributes(array_keys($attributes));

\Mage::app()->setCurrentStore(\Mage_Core_Model_App::ADMIN_STORE_ID);
Expand Down Expand Up @@ -169,6 +173,11 @@ private function attributeExists($attribute)
protected function getDefaultAttributes()
{
$productModel = $this->serviceContainer['productModel']();

if ($productModel->getTypeId() == '') {
$productModel->setTypeId(\Mage_Catalog_Model_Product_Type::TYPE_SIMPLE);
}

$typeId = $productModel->getTypeId();

if ($this->defaultAttributes[$typeId]) {
Expand Down

0 comments on commit 4875540

Please sign in to comment.