Automated
Testing with
Magento
Meet-Magento DE 2013
Anonymous Magento Developer
"It's impossible to test Magento"
Whats available?
Magento Test Automation Framework
Backport of Magento 2 Tests
EcomDev_PHPUnit
Mage-Test
MTAF
Magento Test Automation Framework
PHPUnit & Selenium2 QA Testing
MTAF
Magento Inc.
MTAF
MTAF
Setup
Up to date installation instructions
on the Magento
bugathon wiki
MTAF
Setup
The Magento Instance and
MTAF
Directory Structure
taf/ ├── fixture/ ├── framework/ └── testsuite/MTAF
Define Fixtures in yml
product_special_price:
product_attribute_set: Default
general_name: Special Price Simple Product(%randomize%)
general_sku: special_price_sku_%randomize%
general_url_key: special-price-product-%randomize% general_status: Enabled
...
inventory_qty: 999
inventory_stock_availability: In Stock websites: Main Website
MTAF
Load yml Fixtures
// Load the section "product_special_price" from the file "Product.yml"
MTAF
Helpers
MTAF
UI Maps
product_detail: mca: %productUrlKey%.html title: %productName% uimap: fieldsets: price_box: pageelements:MTAF
Using UI Maps
$this->frontend('product_detail');
$this->assertTrue(
$this->controlIsPresent('pageelement', 'special_price'), 'Special price not found on product detail page.'
MTAF
Example
Is product special price is displayed on frontend?
(
on github
)
Backport of Magento 2 Tests
PHPUnit-Magento Integration
Backported by
Backport of Magento 2 Tests
TechDivision_MagentoUnitTesting
Backport of Magento 2 Tests
~1200 Integration, ~33 Unit
(sans skipped/incomplete)
Backport of Magento 2 Tests
Backport of Magento 2 Tests
Directory Structure
htdocs/ ├── app/ ├── dev/ │ └── tests/ │ ├── integration/ │ │ ├── framework/ │ │ └── testsuite/ │ ├── performance/ │ ├── static/ │ └── unit/ └── skin/Backport of Magento 2 Tests
Data Fixtures
Kinda like setup scripts
/*** @magentoDataFixture Vinai/Catalog/_files/filterCollectionProducts.php */
Backport of Magento 2 Tests
Config Fixtures
/**
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 0 */
Backport of Magento 2 Tests
Test Isolation
/**
* Reset config and db cache and re-initialize app for each test * @magentoAppIsolation enabled
Backport of Magento 2 Tests
Testing Controllers
classMagento_Test_TestCase_ControllerAbstract ... { publicfunctiondispatch() {}
publicfunctionassertHeaderPcre() {} publicfunctiongetRequest() {}
publicfunctiongetResponse() {} }
Backport of Magento 2 Tests
Rewriting of Tests
/**
* @magentoRewriteTestMethod Mage_Catalog_Helper_DataTest::testGetProductUrl() */
Backport of Magento 2 Tests
Mocks
Backport of Magento 2 Tests
Example
Test collection filtering by custom attribute
(
on github
)
EcomDev_PHPUnit
PHPUnit-Magento Integration
By
@IvanChepurnyi
of
EcomDev
EcomDev_PHPUnit
on github
EcomDev_PHPUnit
Tests live under the module directories
EcomDev_PHPUnit
[Acme_Foo] ├── Test/ │ └── Model/ │ ├── FooTest.php │ ├── expectations/ │ │ └── testFooDoesX.yaml │ ├── fixtures/ │ │ └── testFooDoesX.yaml │ └── providers/ │ └── testFooDoesX.yaml └── etc/ └── config.xmlEcomDev_PHPUnit
EcomDev_PHPUnit
Fixtures
Scope Fixtures
(Websites, Store Groups & Store Views)
scope:website:
- website_id: 1
code: base
name: Main Website default_group_id: 1
EcomDev_PHPUnit
Fixtures
Config Fixtures
config: default/catalog/frontend/flat_catalog_product: 0 stores/german/catalog/frontend/list_allow_all: 1EcomDev_PHPUnit
Fixtures
Table Fixtures
tables: customer/customer_group: - customer_group_id: 5customer_group_code: Test Group tax_class_id: 3
EcomDev_PHPUnit
Fixtures
EAV Fixtures
eav: catalog_product: - entity_id: 1 type_id: simple sku: product1name: Product One url_key: product_one stock: qty: 1000.00 is_in_stock: 1 website_ids: - base price: 12.99 status: 1
EcomDev_PHPUnit
Fixtures
Class scope fixtures
/*** @loadSharedFixture */
EcomDev_PHPUnit
Fixtures
Test scope fixtures
Stacks onto shared fixtures!
/*** @loadFixture */
EcomDev_PHPUnit
More Annotations
Registry clean-up
/** * @singleton core/session * @helper catalog/product_flat */EcomDev_PHPUnit
Mocks
$mockAddress = $this->getModelMock('customer/address');
EcomDev_PHPUnit
Testing Controllers
classEcomDev_PHPUnit_Test_Case_Controller ... { publicfunctiondispatch() {}
publicfunctionassertRequest() {}
publicfunctionassertRequestDispatched() {} publicfunctionassertRequestForwarded() {} publicfunctionassertRequestRoute() {}
publicfunctionassertRequestRouteName() {}
publicfunctionassertRequestControllerName() {} publicfunctionassertRequestControllerModule() {} publicfunctionassertRequestActionName() {}
publicfunctionassertRequestBeforeForwardedRoute() {} publicfunctionassertResponseHeaderSent() {}
publicfunctionassertResponseBodyContains() {} publicfunctionassertResponseBodyRegExp() {} publicfunctionassertResponseBodyJson() {} publicfunctionassertResponseHttpCode() {} publicfunctionassertRedirect() {}
EcomDev_PHPUnit Test
Example
Test customer authentication
(
on github
)
MageTest
Light Weight PHPUnit-Magento Integration
by
@AlistairStead
of
Inviqa Session Digital
/
MageTest
MageTest
Directory Structure
htdocs/ ├── app/ ├── tests │ ├── bootstrap.php │ ├── integration │ ├── phpunit.xml.dist │ └── unit ├── skin/ ├── ... └── var/MageTest
Fixture Factories
Factories for customers, products, orders & invoices
MageTest
Mock Singletons & Models
$mockCustomer = $this->getModck('Mage_Customer_Model_Customer');
MageTest
Testing Controllers
classMageTest_PHPUnit_Framework_ControllerTestCase ... { publicfunctionassertControllerModule() {}
publicfunctiondispatch() {} publicfunctionassertRoute() {} publicfunctionassertNotRoute() {} }
MageTest
Example
Test catalog/product_url returns the correct SEO URL
(
on github
)
BehatMage
Behat-Magento Integration
By
,
& more
(Started at MageHack London 2012)
BehatMage
Test BUSINESS SPECIFICATIONS
(NOT TECH SPECS)
BehatMage
BehatMage
Directory Structure
project/ ├── features/ │ ├── admin_configures_guest_checkout.feature │ └── bootstrap/ │ ├── FeatureContext.php │ └── GuestCheckoutContext.php ├── htdocs/ │ ├── app/ │ ├── ... │ └── var/ └── vendor/BehatMage
Features
Feature: The Admin User can disable or enable guest checkout So the amount of charge backs can be minimized,
as an Admin User,
BehatMage
Scenarios
Scenario: Admin User disables guest checkout
Given the Admin User has disabled guest checkout And the following products exist:
| sku | name | is_in_stock | qty | | test1 | Test Product 1 | 1 | 99999 | When I am not logged in as a customer
And I add "test1" to the cart And I go the the checkout