2017 © Pedro Peláez
 

opencart-extension opencart-test-suite

Testing Suite for OpenCart Development

image

beyondit/opencart-test-suite

Testing Suite for OpenCart Development

  • Thursday, March 15, 2018
  • by openmandragora
  • Repository
  • 11 Watchers
  • 37 Stars
  • 1,759 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 24 Forks
  • 1 Open issues
  • 17 Versions
  • 13 % Grown

The README.md

Build Status, (*1)

OpenCart Testing Suite

Supported OpenCart Versions

OpenCart version opencart-test-suite version build status
~3.0 ~3.0 Build Status
~2.2.0 ~2.2.0 Build Status
~2.3.0 ~2.3.0 Build Status

Motivation

The intend of this project is to provide a simple approach for setting up a test suite for custom OpenCart development., (*2)

Getting started from scratch

  • Create a new OpenCart instance (maybe follow this guide)
  • Add opencart-test-suite as a dependency composer require beyondit/opencart-test-suite --dev
  • Use composer require beyondit/opencart-test-suite:3.0 --dev for OpenCart version 3.0 respectively
  • Create a tests folder and add respective tests (see examples below)
  • Add a phpunit.xml which includes testsuites (e.g. admin and catalog) and set an env variable to the opencart root directory (see example phpunit.xml below)
  • Now tests can be run via vendor/bin/phpunit --testsuite catalog-tests command

Our OpenCart project template might simplify setup for you., (*3)

Example of a phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
    <testsuites>
        <testsuite name="catalog-tests">
            <directory suffix="Test.php">./tests/catalog/</directory>
        </testsuite>
        <testsuite name="admin-tests">
            <directory suffix="AdminTest.php">./tests/admin/</directory>
        </testsuite>
    </testsuites>
    <php>
        <env name="OC_ROOT" value="/../opencart/root-folder" />
        <env name="HTTP_SERVER" value="http://localhost:8080/" />
        <env name="TEST_CONFIG" value="test-config" />
    </php>
</phpunit>

Test Examples

Testing a Model

namespace Tests;

class ModelCatalogManufacturerTest extends OpenCartTest
{
    public function testASpecificManufacturer()
    {
        // load the manufacturer model
        $model = $this->loadModel("catalog/manufacturer");
        $manufacturer = $model->getManufacturer(5);

        // test a specific assertion
        $this->assertEquals('HTC', $manufacturer['name']);

    }
}

Testing a Controller

namespace Tests;

class ControllerCheckoutCartTest extends OpenCartTest
{
    public function testAddingASpecificProductToTheCart()
    {
        $response = $this->dispatchAction('checkout/cart/add','POST',['product_id' => 28]);
        $output = json_decode($response->getOutput(),true);

        $this->assertTrue(isset($output['success']) && isset($output['total']));
        $this->assertRegExp('/HTC Touch HD/', $output['success']);
    }
}

Testing with logged in Customers

class ControllerAccountEditTest extends OpenCartTest {  
    public function testEditAccountWithLoggedInCustomer() {

        $this->login('somebody@test.com','password');

        $response = $this->dispatchAction('account/edit');
        $this->assertRegExp('/Your Personal Details/',$response->getOutput());

        $this->logout();

    }   
}

Testing with logged in Users inside Admin

In order to test classes inside the admin folder just call your test class ending with AdminTest e.g. ModelCatalogCategoryAdminTest, (*4)

class ControllerCommonDashboardAdminTest extends OpenCartTest {  
    public function testShowDashboardWithLoggedInUser() {

        $this->login('admin','admin');

        $response = $this->dispatchAction('common/dashboard');
        $this->assertRegExp('/Total Sales/', $response->getOutput());

        $this->logout();

    }   
}

The Versions

15/03 2018

dev-master

9999999-dev

Testing Suite for OpenCart Development

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

phpunit opencart

21/07 2017

3.0.x-dev

3.0.9999999.9999999-dev

Testing Suite for OpenCart Development

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

phpunit opencart

21/07 2017

3.0.0

3.0.0.0

Testing Suite for OpenCart Development

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

phpunit opencart

02/12 2016
02/12 2016
01/08 2016

0.3.3

0.3.3.0

Testing Suite for OpenCart Development

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

11/07 2016

0.3.2

0.3.2.0

Testing Suite for OpenCart Development

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

16/06 2016

0.3.1

0.3.1.0

Testing Suite for OpenCart Development

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

17/05 2016

0.3

0.3.0.0

Testing Suite for OpenCart Development

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

14/04 2013

0.2.1

0.2.1.0

Testing suite for OpenCart Extension Development

  Sources   Download

GPL-3.0

The Requires

 

12/04 2013

0.2.0

0.2.0.0

Testing suite for OpenCart Extension Development

  Sources   Download

GPL-3.0

The Requires

 

11/04 2013

0.1.4

0.1.4.0

Testing suite for OpenCart Extension Development

  Sources   Download

GPL-3.0

The Requires

 

10/04 2013

0.1.3

0.1.3.0

Testing suite for OpenCart Extension Development

  Sources   Download

GPL-3.0

The Requires

 

10/04 2013

0.1.2

0.1.2.0

Testing suite for OpenCart Extension Development

  Sources   Download

GPL-3.0

The Requires

 

10/04 2013

0.1.0

0.1.0.0

Testing suite for OpenCart Extension Development

  Sources   Download

GPL-3.0

The Requires