woocommerce/tests
James Koster 3823b78318 Add/product galleries (#11665)
* register prettyPhoto but don't enqueue. #10721

* Remove lightbox option. #10721

Also registers the prettyPhoto styles instead of enqueueing

* Stip all prettyPhoto related stuff from the templates and tidy up some logic. #10721

* Add flexslider assets #10721

* styling and re-adds `woocommerce_single_product_image_thumbnail_html`. #10721.

* Add zoom functionality. #10721

* Move js to single-product.js. #10721

* styling of the gallery thumbnails when using the `product_page` shortcode. #10721

* Only enable the zoom if the image is large enough. #10721

* Use a 4 column layout by default. #10721

* Make the carousel options filterable. #10721

* rtl styles for gallery. #10721

* Don't zoom on handheld devices. #10721

* markup tweaks in prep for photoswipe

* disable zoom for now

* Add and enqueue photoswipe assets

* add the photoswipe template

* initialise photoswipe - it's alive!

* tidy up js. add title. add separate trigger. #10721

* Move photoswipe functions to single-product.js. #10721

* reactivate the zoom! #10721

* style the photoswipe trigger. #10721

* disable flexslider animation loop. #10721

* js tidy up. #10721

* Fix jshint

* Abstract the product gallery scripts

* Minify

* Fixed conflict with the admin bar

* Photoswipe conflict with admin bar

* Index. #10721

* photoswipe button styles. #10721

* Styling. #10721

* No animation on zoom
* Image width on mobile

* No shadows please. #10721

Looking at you, Twenty Twelve.

* code tidy and add class to placeholder figure. #10721

* simplify rtl query

* photoswipe button styles

* Comma should not be here

* zoom icon #10721

* gallery thumb styles. #10721

* trigger icon. #10721

* Image margins. #10721

* icon hover states. #10721

* Variation handling

* Fix zoom and heights

* Resize after timeout
2016-10-13 15:25:42 +01:00
..
bin Stop coveralls for PHP 5.3 2016-09-13 20:55:58 -03:00
framework Add/product galleries (#11665) 2016-10-13 15:25:42 +01:00
unit-tests Fix strings case (#12069) 2016-10-12 11:16:30 +01:00
README.md Adjusts all references of 'woothemes' to 'woocommerce' in relevant URLs, excluding the Travis CI integration which correctly uses 'woocommerce/woocommerce'. 2016-09-28 12:17:40 +02:00
bootstrap.php WordPress.WhiteSpace.ControlStructureSpacing.BlankLineAfterEnd 2016-08-27 08:57:05 +03:00

README.md

WooCommerce Unit Tests

Initial Setup

  1. Install PHPUnit by following their installation guide. If you've installed it correctly, this should display the version:

    $ phpunit --version

  2. Install WordPress and the WP Unit Test lib using the install.sh script. Change to the plugin root directory and type:

    $ tests/bin/install.sh [db-host]

Sample usage:

$ tests/bin/install.sh woocommerce_tests root root

Important: The <db-name> database will be created if it doesn't exist and all data will be removed during testing.

Running Tests

Simply change to the plugin root directory and type:

$ phpunit

The tests will execute and you'll be presented with a summary. Code coverage documentation is automatically generated as HTML in the tmp/coverage directory.

You can run specific tests by providing the path and filename to the test class:

$ phpunit tests/unit-tests/api/webhooks

A text code coverage summary can be displayed using the --coverage-text option:

$ phpunit --coverage-text

Writing Tests

  • Each test file should roughly correspond to an associated source file, e.g. the formatting/functions.php test file covers code in the wc-formatting-functions.php file
  • Each test method should cover a single method or function with one or more assertions
  • A single method or function can have multiple associated test methods if it's a large or complex method
  • Use the test coverage HTML report (under tmp/coverage/index.html) to examine which lines your tests are covering and aim for 100% coverage
  • For code that cannot be tested (e.g. they require a certain PHP version), you can exclude them from coverage using a comment: // @codeCoverageIgnoreStart and // @codeCoverageIgnoreEnd. For example, see wc_round_tax_total()
  • In addition to covering each line of a method/function, make sure to test common input and edge cases.
  • Prefer assertsEquals() where possible as it tests both type & equality
  • Remember that only methods prefixed with test will be run so use helper methods liberally to keep test methods small and reduce code duplication. If there is a common helper method used in multiple test files, consider adding it to the WC_Unit_Test_Case class so it can be shared by all test cases
  • Filters persist between test cases so be sure to remove them in your test method or in the tearDown() method.
  • Use data providers where possible. Be sure that their name is like data_provider_function_to_test (i.e. the data provider for test_is_postcode would be data_provider_test_is_postcode). Read more about data providers here.

Automated Tests

Tests are automatically run with Travis-CI for each commit and pull request.

Code Coverage

Code coverage is available on Coveralls which receives updated data after each Travis build.