Magento

Magium was built out of the desire to have an easy to understand but massively useful testing framework for Magento. You can read the story on the blog. With the Magento component you can often do very complex things very easily because a lot of the functionality is intended to be intuitively referenced. (You will probably see the word "intuitive" used a lot here).

To install magium/magento issue the following composer command:

composer require magium/magento

There are a few MUSTs that this project has.

  • It MUST be intuitive - There should be a minimum of guesswork
  • It MUST be reusable - Rewriting boilerplate should be kept to a minimum
  • It MUST be configurable - When changes need to be made they should require a minimal amount of work

The checkout is a good example of how this works. The basic guest checkout can be fully executed as such:

use Magium\Magento\AbstractMagentoTestCase;
use Magium\Magento\Actions\Cart\AddItemToCart;
use Magium\Magento\Actions\Checkout\GuestCheckout;

class GuestCheckoutTest extends AbstractMagentoTestCase
{
    public function testBasicCheckout()
    {
        $this->setPaymentMethod('CashOnDelivery');
        $this->commandOpen($this->getTheme()->getBaseUrl());
        $this->getAction(AddItemToCart::ACTION)->addSimpleProductToCartFromProductPage();
        $guestCheckout = $this->getAction(GuestCheckout::ACTION);
        $guestCheckout->execute();
    }
}

But what if one of your tests was that you wanted to make sure that customers in Canada were able to purchase your products? You can modify your test to do that with one line of code.

class GuestCheckoutTest extends AbstractMagentoTestCase
{
    public function testBasicCheckoutForCanucks()
    {
        // Set the identity's country ID
        $this->getIdentity()->setCountryId('CA');

        $this->setPaymentMethod('CashOnDelivery');
        $this->commandOpen($this->getTheme()->getBaseUrl());
        $this->getAction(AddItemToCart::ACTION)->addSimpleProductToCartFromProductPage();
        $guestCheckout = $this->getAction(GuestCheckout::ACTION);
        $guestCheckout->execute();
    }
}

What if you had the opposite problem? What if you needed to test to make sure that Canadians couldn't order from your website (for shame!). You would want to make sure that those lovable, furry Canucks couldn't purchase your precious widgets (or TV shows). With a little bit of architectural thinking you can completely reuse everything that is there AND inject your assertion into the checkout process.

In other words, Magium allows you to easily test not only functionality, but business rules as well.

class CanadaNotAvailableAssertion extends AbstractAssertion implements StepInterface
{
    public function assert()
    {
        $this->testCase->assertElementNotExists('//option[.="Canada"]', WebDriver::BY_XPATH);
    }

    public function execute()
    {
        $this->assert(); // do the assertion
    }

    public function nextAction()
    {
        return false; // tell the checkout to stop executing after this step
    }

}

class BanTheCanucksTest extends AbstractMagentoTestCase
{
    public function testZimbabweNotAvailable()
    {
        $this->commandOpen($this->getTheme()->getBaseUrl());
        $this->getAction(AddItemToCart::ACTION)->addSimpleProductToCartFromProductPage();
        $guestCheckout = $this->getAction(GuestCheckout::ACTION);

        // Add the assertion before the billing address is entered
        $guestCheckout->addStep(
            $this->get('CanadaNotAvailableAssertion'),
            $this->getAction(BillingAddress::ACTION)
        );
        $guestCheckout->execute();

    }
}

These 3 examples barely scratch the surface of what you can do with Magium. Virtually all of the frontend is supported and a good portion of the admin is supported. So try it out!