diff --git a/src/MageTest/Manager/FixtureManager.php b/src/MageTest/Manager/FixtureManager.php index 25473c7..ba2e2b9 100644 --- a/src/MageTest/Manager/FixtureManager.php +++ b/src/MageTest/Manager/FixtureManager.php @@ -38,7 +38,7 @@ public function __construct(ProviderInterface $attributesProvider) * @param $fixtureFile * @return mixed */ - public function loadFixture($fixtureType, $userFixtureFile = null) + public function loadFixture($fixtureType, $userFixtureFile = null, $overrideAttributes = null) { $attributesProvider = clone $this->attributesProvider; @@ -52,8 +52,14 @@ public function loadFixture($fixtureType, $userFixtureFile = null) $attributesProvider->readFile($fixtureFile); } + $modelAttributes = $attributesProvider->readAttributes(); + + if(!is_null($overrideAttributes)) { + $modelAttributes = array_replace($modelAttributes, $overrideAttributes); + } + $builder = $this->getBuilder($attributesProvider->getModelType()); - $builder->setAttributes($attributesProvider->readAttributes()); + $builder->setAttributes($modelAttributes); if($attributesProvider->hasFixtureDependencies()) { diff --git a/tests/MageTest/Manager/ProductTest.php b/tests/MageTest/Manager/ProductTest.php index 83154cd..d8f6306 100644 --- a/tests/MageTest/Manager/ProductTest.php +++ b/tests/MageTest/Manager/ProductTest.php @@ -8,11 +8,13 @@ class ProductTest extends WebTestCase protected function setUp() { parent::setUp(); - $this->productFixture = $this->manager->loadFixture('catalog/product'); + } public function testCreateSimpleProduct() { + $this->productFixture = $this->manager->loadFixture('catalog/product'); + $session = $this->getSession(); $session->visit(getenv('BASE_URL') . '/catalog/product/view/id/' . $this->productFixture->getId()); $this->assertSession()->statusCodeEquals(200); @@ -20,6 +22,8 @@ public function testCreateSimpleProduct() public function testDeleteSimpleProduct() { + $this->productFixture = $this->manager->loadFixture('catalog/product'); + $this->manager->clear(); $session = $this->getSession(); @@ -29,6 +33,8 @@ public function testDeleteSimpleProduct() public function testCreateSimpleProductWithImage() { + $this->productFixture = $this->manager->loadFixture('catalog/product'); + $imageURL = getcwd() . '/tests/MageTest/Manager/Assets/370x370.jpg'; $this->productFixture->setMediaGallery (array('images'=>array (), 'values'=>array ())); @@ -39,4 +45,17 @@ public function testCreateSimpleProductWithImage() $session->visit(getenv('BASE_URL') . '/catalog/product/view/id/' . $this->productFixture->getId()); $this->assertSession()->elementExists('css', '#image'); } + + public function testOverrideDefaultValues() + { + $this->productFixture = $this->manager->loadFixture('catalog/product', null, array( + 'name' => 'Overridden Product Name', + )); + + $session = $this->getSession(); + $session->visit(getenv('BASE_URL') . '/catalog/product/view/id/' . $this->productFixture->getId()); + + $this->assertSession()->pageTextContains('Overridden Product Name'); + $this->assertSession()->statusCodeEquals(200); + } } \ No newline at end of file