MageTest / BehatMage

Behat for Magento
MIT License
85 stars 31 forks source link

Ability to specify a store view and/or website in a scenario #18

Open Vinai opened 11 years ago

Vinai commented 11 years ago

Any specified store view will be overridden by MageTest\MagentoExtension\Fixture\Product::create()

zuernBernhard commented 8 years ago

I have a step-definition to view a product in a specific store. Perhaps it helps you.

And I visit the product with the sku "123test" in the "Brand abc" store

Step-Definition

/**
   * @Given I visit the product with the sku :sku in the :site store
   */
  public function iVisitTheProductWithTheSkuInTheStore($sku, $site) {
    $websites = Mage::app()->getWebsites();
    foreach ($websites as $website) {
      $name = $website->getName();
      if ($site == $name) {
        // Open Webpage.
        Mage::app()->setCurrentStore($website->getId());
        $product = Mage::getModel('catalog/product')
          ->loadByAttribute('sku', $sku);
        if (!$product) {
          throw new Exception("A product with the sku " . $sku . " does not exist.");
        }
        $url = $product->getProductUrl();

        return $this->visit($url);
      }
    }
    throw new Exception("Website " . $site . " does not exist.");
  }