The test
WC_Tests_API_Functions::test_wc_rest_upload_image_from_url_should_download_image_and_return_array()
was failing on Travis with the error below due images being kept on
accros different tests. To fix this problem, this commit makes sure that
every test that creates an image, removes it after the assertions.
```
1) WC_Tests_API_Functions::test_wc_rest_upload_image_from_url_should_download_image_and_return_array
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 'file' => '/tmp/wordpress/wp-content/uploads/2020/01/Dr1Bczxq4q.png'
- 'url' => 'http://example.org/wp-content/uploads/2020/01/Dr1Bczxq4q.png'
+ 'file' => '/tmp/wordpress/wp-content/uploads/2020/01/Dr1Bczxq4q-3.png'
+ 'url' => 'http://example.org/wp-content/uploads/2020/01/Dr1Bczxq4q-3.png'
/home/travis/build/woocommerce/woocommerce-rest-api/unit-tests/Tests/Version3/functions.php:113
```
(https://travis-ci.org/woocommerce/woocommerce-rest-api/jobs/634921426#L719)
This commit fixes a problem in the script that configures the
environment to run the unit tests in the Travis build jobs. The script
was not running `composer install` in the WooCommerce directory, leaving
it installation incomplete and thus the tests were failing.
To fix this problem, this commit adds a call to `composer install` right
after WooCommerce is downloaded in the setup script
(`unit-tests/bin/install.sh`).
This implements two changes to WC_Tests_REST_System_Status test class:
- It simplifies the tests by setting the user in the setUp method
instead of in each test.
- Improves the performance of the tests by creating a new admin user
only once when the class is instantiated instead of once for every
single test that is executed.
This commit fixes the unit test
WC_Tests_API_Functions::test_wc_rest_upload_image_from_url_should_return_error_when_invalid_image_is_passed() which was failing due to a change in a WordPress core message with the following error:
```
2) WC_Tests_API_Functions::test_wc_rest_upload_image_from_url_should_return_error_when_invalid_image_is_passed
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Invalid image: File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.'
+'Invalid image: File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini file or by post_max_size being defined as smaller than upload_max_filesize in php.ini.'
/home/travis/build/woocommerce/woocommerce/tests/unit-tests/util/api-functions.php:89
```
(https://travis-ci.org/woocommerce/woocommerce/jobs/637353161#L402)
This test only fails when using WordPress nightly build (the yet to be
released WP 5.4).
To fix this problem, this commit adds an if statement to check for different error
messages depending on the WordPress version that is being used to run
the tests. In the future, we might want to refactor this test to remove
its dependency to a WordPress error message to make it more robust and
stable.