• No results found

Automated Testing with Magento. Meet-Magento DE

N/A
N/A
Protected

Academic year: 2021

Share "Automated Testing with Magento. Meet-Magento DE"

Copied!
61
0
0

Loading.... (view fulltext now)

Full text

(1)

Automated

Testing with

Magento

Meet-Magento DE 2013

(2)

Anonymous Magento Developer

"It's impossible to test Magento"

(3)

Whats available?

Magento Test Automation Framework

Backport of Magento 2 Tests

EcomDev_PHPUnit

Mage-Test

(4)

MTAF

Magento Test Automation Framework

PHPUnit & Selenium2 QA Testing

(5)

MTAF

Magento Inc.

(6)

MTAF

(7)

MTAF

Setup

Up to date installation instructions

on the Magento

bugathon wiki

(8)

MTAF

Setup

The Magento Instance and

(9)

MTAF

Directory Structure

taf/ ├── fixture/ ├── framework/ └── testsuite/

(10)

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

(11)

MTAF

Load yml Fixtures

// Load the section "product_special_price" from the file "Product.yml"

(12)

MTAF

Helpers

(13)

MTAF

UI Maps

product_detail: mca: %productUrlKey%.html title: %productName% uimap: fieldsets: price_box: pageelements:

(14)

MTAF

Using UI Maps

$this->frontend('product_detail');

$this->assertTrue(

$this->controlIsPresent('pageelement', 'special_price'), 'Special price not found on product detail page.'

(15)

MTAF

Example

Is product special price is displayed on frontend?

(

on github

)

(16)

Backport of Magento 2 Tests

PHPUnit-Magento Integration

Backported by

(17)

Backport of Magento 2 Tests

TechDivision_MagentoUnitTesting

(18)

Backport of Magento 2 Tests

~1200 Integration, ~33 Unit

(sans skipped/incomplete)

(19)

Backport of Magento 2 Tests

(20)

Backport of Magento 2 Tests

Directory Structure

htdocs/ ├── app/ ├── dev/ │ └── tests/ │ ├── integration/ │ │ ├── framework/ │ │ └── testsuite/ │ ├── performance/ │ ├── static/ │ └── unit/ └── skin/

(21)

Backport of Magento 2 Tests

Data Fixtures

Kinda like setup scripts

/**

* @magentoDataFixture Vinai/Catalog/_files/filterCollectionProducts.php */

(22)

Backport of Magento 2 Tests

Config Fixtures

/**

* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 0 */

(23)

Backport of Magento 2 Tests

Test Isolation

/**

* Reset config and db cache and re-initialize app for each test * @magentoAppIsolation enabled

(24)

Backport of Magento 2 Tests

Testing Controllers

classMagento_Test_TestCase_ControllerAbstract ... { publicfunctiondispatch() {}

publicfunctionassertHeaderPcre() {} publicfunctiongetRequest() {}

publicfunctiongetResponse() {} }

(25)

Backport of Magento 2 Tests

Rewriting of Tests

/**

* @magentoRewriteTestMethod Mage_Catalog_Helper_DataTest::testGetProductUrl() */

(26)

Backport of Magento 2 Tests

Mocks

(27)

Backport of Magento 2 Tests

Example

Test collection filtering by custom attribute

(

on github

)

(28)

EcomDev_PHPUnit

PHPUnit-Magento Integration

By

@IvanChepurnyi

of

EcomDev

(29)

EcomDev_PHPUnit

on github

(30)

EcomDev_PHPUnit

Tests live under the module directories

(31)

EcomDev_PHPUnit

[Acme_Foo] ├── Test/ │ └── Model/ │ ├── FooTest.php │ ├── expectations/ │ │ └── testFooDoesX.yaml │ ├── fixtures/ │ │ └── testFooDoesX.yaml │ └── providers/ │ └── testFooDoesX.yaml └── etc/ └── config.xml

(32)

EcomDev_PHPUnit

(33)

EcomDev_PHPUnit

Fixtures

Scope Fixtures

(Websites, Store Groups & Store Views)

scope:

website:

- website_id: 1

code: base

name: Main Website default_group_id: 1

(34)

EcomDev_PHPUnit

Fixtures

Config Fixtures

config: default/catalog/frontend/flat_catalog_product: 0 stores/german/catalog/frontend/list_allow_all: 1

(35)

EcomDev_PHPUnit

Fixtures

Table Fixtures

tables: customer/customer_group: - customer_group_id: 5

customer_group_code: Test Group tax_class_id: 3

(36)

EcomDev_PHPUnit

Fixtures

EAV Fixtures

eav: catalog_product: - entity_id: 1 type_id: simple sku: product1

name: Product One url_key: product_one stock: qty: 1000.00 is_in_stock: 1 website_ids: - base price: 12.99 status: 1

(37)

EcomDev_PHPUnit

Fixtures

Class scope fixtures

/**

* @loadSharedFixture */

(38)

EcomDev_PHPUnit

Fixtures

Test scope fixtures

Stacks onto shared fixtures!

/**

* @loadFixture */

(39)

EcomDev_PHPUnit

More Annotations

Registry clean-up

/** * @singleton core/session * @helper catalog/product_flat */

(40)

EcomDev_PHPUnit

Mocks

$mockAddress = $this->getModelMock('customer/address');

(41)

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() {}

(42)

EcomDev_PHPUnit Test

Example

Test customer authentication

(

on github

)

(43)

MageTest

Light Weight PHPUnit-Magento Integration

by

@AlistairStead

of

Inviqa Session Digital

/

(44)

MageTest

(45)

MageTest

Directory Structure

htdocs/ ├── app/ ├── tests │ ├── bootstrap.php │ ├── integration │ ├── phpunit.xml.dist │ └── unit ├── skin/ ├── ... └── var/

(46)

MageTest

Fixture Factories

Factories for customers, products, orders & invoices

(47)

MageTest

Mock Singletons & Models

$mockCustomer = $this->getModck('Mage_Customer_Model_Customer');

(48)

MageTest

Testing Controllers

classMageTest_PHPUnit_Framework_ControllerTestCase ... { publicfunctionassertControllerModule() {}

publicfunctiondispatch() {} publicfunctionassertRoute() {} publicfunctionassertNotRoute() {} }

(49)

MageTest

Example

Test catalog/product_url returns the correct SEO URL

(

on github

)

(50)

BehatMage

Behat-Magento Integration

By

,

& more

(Started at MageHack London 2012)

(51)

BehatMage

Test BUSINESS SPECIFICATIONS

(NOT TECH SPECS)

(52)

BehatMage

(53)

BehatMage

Directory Structure

project/ ├── features/ │ ├── admin_configures_guest_checkout.feature │ └── bootstrap/ │ ├── FeatureContext.php │ └── GuestCheckoutContext.php ├── htdocs/ │ ├── app/ │ ├── ... │ └── var/ └── vendor/

(54)

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,

(55)

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

(56)

BehatMage

Fixture Factories

Products

Admin Users

Admin session

(57)

BehatMage

Translate Business Specifications into PHP Code

Check specifications via Mink WebDriver

(58)

BehatMage

Example

Check that the guest checkout can be disabled

(

on github

)

(59)

More...

MageSpec, Testify

Do you know more?

(60)

What should I build my tests

with?

(61)

Thank you!

if ($q = $you->getQuestion()) { $a = $this->query($q); var_dump($a); }

@VinaiKopp

References

Related documents

Zaključno možemo reći da time što je visok unos soli uzrokovao inhibiciju, a niski unos soli u organizam povećao aktivnost RAAS-a, određivanje pojedinih komponenti RAAS-

• Consumers, plan members, employers, employee benefit consultants, plans, healthcare providers increasingly. converge via

extraction of parameters of parts. In addition, equipment such as conveyor, parts detector on the conveyor belt and parts separator can be added to above components. The choice of

The aim of plugin-based technologies is generally to create a richer user experience by providing rich multimedia (video, audio), vector graphics and animation support, by

Formal position uncertainty as a function of magnitude for the 2820 Gaia sources identified as optical counterparts of quasars in the ICRF3-prototype.. The solid red line is a

More specif- ically, this thesis contains the first applications of proof mining to the theory of partial differential equations and moreover to the theory of accretive, set-

Results suggest that college attendance does not lead to a major increase or shift in sexual behavior, although college attenders do have higher rates of frequent heavy

We report herein a case of highly recurrent, locally invasive DFSP that failed both postoperative radiation therapy and complete trial of Imatinib, but was successfully treated