Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/MageTest/Manager/FixtureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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())
{
Expand Down
21 changes: 20 additions & 1 deletion tests/MageTest/Manager/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ 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);
}

public function testDeleteSimpleProduct()
{
$this->productFixture = $this->manager->loadFixture('catalog/product');

$this->manager->clear();

$session = $this->getSession();
Expand All @@ -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 ()));
Expand All @@ -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);
}
}