From 880b82a0373b5b019294409b4d29f861b8964261 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Thu, 23 Jul 2020 00:29:41 +0530 Subject: [PATCH] Keep only source to merge with core. --- .editorconfig | 24 - .gitattributes | 7 - .gitignore | 35 - .scrutinizer.yml | 118 - .travis.yml | 26 - README.md | 67 - composer.json | 46 - composer.lock | 1934 ----------------- package-lock.json | 1618 -------------- package.json | 31 - phpcs.xml | 40 - phpunit.xml | 17 - unit-tests/AbstractRestApiTest.php | 213 -- unit-tests/Bootstrap.php | 134 -- unit-tests/Helpers/AdminNotesHelper.php | 83 - unit-tests/Helpers/CouponHelper.php | 147 -- unit-tests/Helpers/CustomerHelper.php | 138 -- unit-tests/Helpers/OrderHelper.php | 129 -- unit-tests/Helpers/ProductHelper.php | 310 --- unit-tests/Helpers/QueueHelper.php | 62 - unit-tests/Helpers/SettingsHelper.php | 82 - unit-tests/Helpers/ShippingHelper.php | 50 - unit-tests/Tests/Version2/coupons.php | 471 ---- unit-tests/Tests/Version2/customers.php | 566 ----- unit-tests/Tests/Version2/orders.php | 721 ------ .../Tests/Version2/payment-gateways.php | 337 --- unit-tests/Tests/Version2/product-reviews.php | 468 ---- .../Tests/Version2/product-variations.php | 495 ----- unit-tests/Tests/Version2/products.php | 536 ----- unit-tests/Tests/Version2/settings.php | 892 -------- .../Tests/Version2/shipping-methods.php | 143 -- unit-tests/Tests/Version2/shipping-zones.php | 800 ------- unit-tests/Tests/Version2/system-status.php | 355 --- unit-tests/Tests/Version3/coupons.php | 471 ---- unit-tests/Tests/Version3/customers.php | 634 ------ unit-tests/Tests/Version3/functions.php | 251 --- unit-tests/Tests/Version3/orders.php | 778 ------- .../Tests/Version3/payment-gateways.php | 345 --- unit-tests/Tests/Version3/product-reviews.php | 470 ---- .../Tests/Version3/product-variations.php | 496 ----- unit-tests/Tests/Version3/products.php | 861 -------- .../Tests/Version3/reports-coupons-totals.php | 103 - .../Version3/reports-customers-totals.php | 119 - .../Tests/Version3/reports-orders-totals.php | 92 - .../Version3/reports-products-totals.php | 99 - .../Tests/Version3/reports-reviews-totals.php | 98 - unit-tests/Tests/Version3/settings.php | 895 -------- .../Tests/Version3/shipping-methods.php | 143 -- unit-tests/Tests/Version3/shipping-zones.php | 825 ------- unit-tests/Tests/Version3/system-status.php | 487 ----- unit-tests/bin/install.sh | 202 -- unit-tests/bin/phpcs.sh | 11 - unit-tests/bin/phpunit.sh | 2 - unit-tests/data/Dr1Bczxq4q.png | Bin 10325 -> 0 bytes unit-tests/data/file.txt | 1 - woocommerce-rest-api.php | 68 - 56 files changed, 18546 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .gitattributes delete mode 100644 .gitignore delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml delete mode 100644 README.md delete mode 100644 composer.json delete mode 100644 composer.lock delete mode 100644 package-lock.json delete mode 100644 package.json delete mode 100644 phpcs.xml delete mode 100644 phpunit.xml delete mode 100644 unit-tests/AbstractRestApiTest.php delete mode 100755 unit-tests/Bootstrap.php delete mode 100644 unit-tests/Helpers/AdminNotesHelper.php delete mode 100644 unit-tests/Helpers/CouponHelper.php delete mode 100644 unit-tests/Helpers/CustomerHelper.php delete mode 100644 unit-tests/Helpers/OrderHelper.php delete mode 100644 unit-tests/Helpers/ProductHelper.php delete mode 100644 unit-tests/Helpers/QueueHelper.php delete mode 100644 unit-tests/Helpers/SettingsHelper.php delete mode 100644 unit-tests/Helpers/ShippingHelper.php delete mode 100644 unit-tests/Tests/Version2/coupons.php delete mode 100644 unit-tests/Tests/Version2/customers.php delete mode 100644 unit-tests/Tests/Version2/orders.php delete mode 100644 unit-tests/Tests/Version2/payment-gateways.php delete mode 100644 unit-tests/Tests/Version2/product-reviews.php delete mode 100644 unit-tests/Tests/Version2/product-variations.php delete mode 100644 unit-tests/Tests/Version2/products.php delete mode 100644 unit-tests/Tests/Version2/settings.php delete mode 100644 unit-tests/Tests/Version2/shipping-methods.php delete mode 100644 unit-tests/Tests/Version2/shipping-zones.php delete mode 100644 unit-tests/Tests/Version2/system-status.php delete mode 100644 unit-tests/Tests/Version3/coupons.php delete mode 100644 unit-tests/Tests/Version3/customers.php delete mode 100644 unit-tests/Tests/Version3/functions.php delete mode 100644 unit-tests/Tests/Version3/orders.php delete mode 100644 unit-tests/Tests/Version3/payment-gateways.php delete mode 100644 unit-tests/Tests/Version3/product-reviews.php delete mode 100644 unit-tests/Tests/Version3/product-variations.php delete mode 100644 unit-tests/Tests/Version3/products.php delete mode 100644 unit-tests/Tests/Version3/reports-coupons-totals.php delete mode 100644 unit-tests/Tests/Version3/reports-customers-totals.php delete mode 100644 unit-tests/Tests/Version3/reports-orders-totals.php delete mode 100644 unit-tests/Tests/Version3/reports-products-totals.php delete mode 100644 unit-tests/Tests/Version3/reports-reviews-totals.php delete mode 100644 unit-tests/Tests/Version3/settings.php delete mode 100644 unit-tests/Tests/Version3/shipping-methods.php delete mode 100644 unit-tests/Tests/Version3/shipping-zones.php delete mode 100644 unit-tests/Tests/Version3/system-status.php delete mode 100755 unit-tests/bin/install.sh delete mode 100755 unit-tests/bin/phpcs.sh delete mode 100755 unit-tests/bin/phpunit.sh delete mode 100644 unit-tests/data/Dr1Bczxq4q.png delete mode 100644 unit-tests/data/file.txt delete mode 100644 woocommerce-rest-api.php diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index c3dfa83750f..00000000000 --- a/.editorconfig +++ /dev/null @@ -1,24 +0,0 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - -# WordPress Coding Standards -# https://make.wordpress.org/core/handbook/coding-standards/ - -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_size = 4 -tab_width = 4 -indent_style = tab -insert_final_newline = true -trim_trailing_whitespace = true - -[*.txt] -trim_trailing_whitespace = false - -[*.{md,json,yml}] -trim_trailing_whitespace = false -indent_style = space -indent_size = 2 diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index b5d3da03cbb..00000000000 --- a/.gitattributes +++ /dev/null @@ -1,7 +0,0 @@ -/.* export-ignore -/phpcs.xml export-ignore -/phpunit.* export-ignore -/unit-tests export-ignore -/vendor export-ignore -/README.md export-ignore -/readme.txt export-ignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b19a8d1f0ae..00000000000 --- a/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ -# Editors -project.xml -project.properties -/nbproject/private/ -.buildpath -.project -.settings* -.idea -.vscode -*.sublime-project -*.sublime-workspace -.sublimelinterrc - -# Grunt -/node_modules/ -none - -# Sass -.sass-cache/ - -# OS X metadata -.DS_Store - -# Windows junk -Thumbs.db - -# Unit tests -/tmp -/unit-tests/bin/tmp - -# Logs -/logs - -# composer -vendor/ diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 04bbd2b73b4..00000000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,118 +0,0 @@ -tools: - php_code_sniffer: - config: - standard: WordPress - sensiolabs_security_checker: true -checks: - php: - avoid_closing_tag: false - avoid_superglobals: false - coding_standard: - name: WordPress - no_exit: false - no_global_keyword: false - one_class_per_file: false - psr2_class_declaration: false - psr2_control_structure_declaration: false - psr2_switch_declaration: false - variable_existence: false - verify_access_scope_valid: false - verify_argument_usable_as_reference: false - verify_property_names: false -filter: - dependency_paths: - - wordpress/ - - woocommerce/ - excluded_paths: - - src/Controllers/Version1/ - - src/Controllers/Version2/ - - src/Controllers/Version3/ - - tests/ - - vendor/ - - classmap.php -coding_style: - php: - indentation: - general: - use_tabs: true - size: 4 - switch: - indent_case: true - spaces: - around_operators: - concatenation: true - negation: true - within: - brackets: true - grouping: true - function_call: true - function_declaration: true - if: true - for: true - while: true - switch: true - catch: true - before_left_brace: - class: true - function: true - if: true - else: true - for: true - while: true - do: true - switch: true - try: true - catch: true - finally: true - before_keywords: - else: true - while: true - catch: true - finally: true - ternary_operator: - before_condition: true - after_condition: true - before_alternative: true - after_alternative: true - in_short_version: false - other: - before_comma: false - after_comma: true - before_semicolon: false - after_semicolon: true - after_type_cast: true - braces: - classes_functions: - class: end-of-line - function: end-of-line - closure: end-of-line - if: - opening: undefined - always: true - else_on_new_line: false - for: - opening: undefined - always: true - while: - opening: undefined - always: true - do_while: - opening: undefined - always: true - while_on_new_line: false - switch: - opening: undefined - try: - opening: undefined - catch_on_new_line: false - finally_on_new_line: false -build: - tests: - override: - command: "php -v" - nodes: - analysis: - dependencies: - before: - - composer require --dev johnpbloch/wordpress-core - - composer require --dev woocommerce/woocommerce diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c907c8983a9..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: php -dist: trusty -sudo: required -cache: - directories: - - vendor - - $HOME/.composer/cache -matrix: - include: - - name: "PHP 7.2 unit tests, PHP Coding standards check" - php: 7.2 - env: WP_VERSION=latest WP_MULTISITE=0 WP_CORE_DIR=/tmp/wordpress RUN_PHPCS=1 - - name: "PHP 7.1 unit tests" - php: 7.1 - env: WP_VERSION=latest WP_MULTISITE=0 WP_CORE_DIR=/tmp/wordpress - -before_script: - - export PATH="$HOME/.composer/vendor/bin:$PATH" - - phpenv config-rm xdebug.ini - - composer install - - composer global require "phpunit/phpunit=4.8.*|6.5.*" - - bash unit-tests/bin/install.sh woocommerce_test root '' localhost $WP_VERSION - -script: - - bash unit-tests/bin/phpunit.sh - - bash unit-tests/bin/phpcs.sh diff --git a/README.md b/README.md deleted file mode 100644 index 9a2eff0a244..00000000000 --- a/README.md +++ /dev/null @@ -1,67 +0,0 @@ -WooCommerce REST API -=== - -license -Latest Stable Version -Build Status -Scrutinizer Code Quality - -This repository is home to the WooCommerce REST API package. - -The stable version of this package is bundled with [WooCommerce core](https://github.com/woocommerce/woocommerce) releases, but it can also be used as a standalone plugin so bleeding-edge API features can be tested or used by other feature plugins. - -## Using this package as a plugin - -After checking out the code to your `wp-content/plugins` directory, you'll need to run `composer install` in the plugin directory (`wp-content/plugins/woocommerce-rest-api`) to install dependencies and to enable the autoloader. Without performing this step, if you activate the plugin it will simply show an admin notice. - -## API documentation - -- [Usage documentation for the REST API can be found here](https://github.com/woocommerce/woocommerce/wiki/Getting-started-with-the-REST-API). -- [Contribution documentation can be found here.](https://github.com/woocommerce/woocommerce/wiki/Contributing-to-the-WooCommerce-REST-API) - -### Versions - -| Namespace | Status | Docs | -| -------- | -------- | -------- | -| `wc/v4` | Development | [Link](https://woocommerce.github.io/woocommerce-rest-api-docs/) | -| `wc/v3` | Stable | [Link](https://woocommerce.github.io/woocommerce-rest-api-docs/) | -| `wc/v2` | Deprecated - October 2020 | [Link](https://woocommerce.github.io/woocommerce-rest-api-docs/wp-api-v2.html) | -| `wc/v1` | Deprecated - April 2019 | [Link](https://woocommerce.github.io/woocommerce-rest-api-docs/wp-api-v1.html) | - -Note: API Versions are kept around for 2 years after being replaced, and may be removed in the next major version after that date passes. - -## Using this package in other projects - -This package is [hosted on Packagist](https://packagist.org/packages/woocommerce/woocommerce-rest-api) and can be included using composer.json: - -```json -"require": { - "woocommerce/woocommerce-rest-api": "1.0" -}, -``` - -Since multiple versions of this package may be included at the same time, it includes a special package-version autoloader. This dependency is also on Packagist: - -```json - "automattic/jetpack-autoloader": "^1" -``` - -And using this autoloader requires the following include in your codebase: - -``` -$autoloader = __DIR__ . '/vendor/autoload_packages.php'; -``` - -If you choose to use your own autoloader, please note you won't be able to determine which version of the package is running since it could use the version in WooCommerce core or your version. The namespaces would conflict. All of our feature plugins and packages use the package autoloader. - -## Contributing - -Please read the [WooCommerce contributor guidelines](https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md) for more information how you can contribute to WooCommerce, and [the REST API contribution documentation here](https://github.com/woocommerce/woocommerce/wiki/Contributing-to-the-WooCommerce-REST-API). - -Within this package, namespaces and endpoint classes are located within the `src/RestAPI/` directory. If you need to change the behavior of an endpoint, you can do so in these classes. - -Run tests using `phpunit` in the root of the package. All pull-requests must pass unit tests in order to be accepted. - -## Translation - -For strings located in API endpoints, use `woocommerce` as your text-domain. These endpoints will be translated in the WooCommerce Core PO/MO files. diff --git a/composer.json b/composer.json deleted file mode 100644 index 537262ed3c2..00000000000 --- a/composer.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "woocommerce/woocommerce-rest-api", - "description": "The WooCommerce core REST API.", - "homepage": "https://github.com/woocommerce/woocommerce-rest-api", - "license": "GPL-3.0-or-later", - "type": "wordpress-plugin", - "prefer-stable": true, - "minimum-stability": "dev", - "require": { - "automattic/jetpack-autoloader": "^1.6.0" - }, - "require-dev": { - "phpunit/phpunit": "6.5.14", - "woocommerce/woocommerce-sniffs": "0.0.9" - }, - "scripts": { - "post-install-cmd": [ - "composer dump-autoload" - ], - "post-update-cmd": [ - "composer dump-autoload" - ], - "test": [ - "phpunit" - ], - "phpcs": [ - "phpcs -s -p" - ], - "phpcs-pre-commit": [ - "phpcs -s -p -n" - ], - "phpcbf": [ - "phpcbf -p" - ] - }, - "autoload": { - "classmap": [ - "src/Controllers/Version1", - "src/Controllers/Version2", - "src/Controllers/Version3" - ], - "psr-4": { - "Automattic\\WooCommerce\\RestApi\\": "src" - } - } -} diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 35c89885f43..00000000000 --- a/composer.lock +++ /dev/null @@ -1,1934 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "18fc7a15ab7921e538dea77490edd41b", - "packages": [ - { - "name": "automattic/jetpack-autoloader", - "version": "v1.6.0", - "source": { - "type": "git", - "url": "https://github.com/Automattic/jetpack-autoloader.git", - "reference": "3bcbe1ae19febd6beeb181cf11af0bf0b7abe7e7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Automattic/jetpack-autoloader/zipball/3bcbe1ae19febd6beeb181cf11af0bf0b7abe7e7", - "reference": "3bcbe1ae19febd6beeb181cf11af0bf0b7abe7e7", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1" - }, - "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5" - }, - "type": "composer-plugin", - "extra": { - "class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin" - }, - "autoload": { - "psr-4": { - "Automattic\\Jetpack\\Autoloader\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0-or-later" - ], - "description": "Creates a custom autoloader for a plugin or theme.", - "time": "2020-03-26T07:57:53+00:00" - } - ], - "packages-dev": [ - { - "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.5.0", - "source": { - "type": "git", - "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "e749410375ff6fb7a040a68878c656c2e610b132" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132", - "reference": "e749410375ff6fb7a040a68878c656c2e610b132", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.0", - "php": "^5.3|^7", - "squizlabs/php_codesniffer": "^2|^3" - }, - "require-dev": { - "composer/composer": "*", - "phpcompatibility/php-compatibility": "^9.0", - "sensiolabs/security-checker": "^4.1.0" - }, - "type": "composer-plugin", - "extra": { - "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" - }, - "autoload": { - "psr-4": { - "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Franck Nijhof", - "email": "franck.nijhof@dealerdirect.com", - "homepage": "http://www.frenck.nl", - "role": "Developer / IT Manager" - } - ], - "description": "PHP_CodeSniffer Standards Composer Installer Plugin", - "homepage": "http://www.dealerdirect.com", - "keywords": [ - "PHPCodeSniffer", - "PHP_CodeSniffer", - "code quality", - "codesniffer", - "composer", - "installer", - "phpcs", - "plugin", - "qa", - "quality", - "standard", - "standards", - "style guide", - "stylecheck", - "tests" - ], - "time": "2018-10-26T13:21:45+00:00" - }, - { - "name": "doctrine/instantiator", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "doctrine/coding-standard": "^6.0", - "ext-pdo": "*", - "ext-phar": "*", - "phpbench/phpbench": "^0.13", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-shim": "^0.11", - "phpunit/phpunit": "^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://www.doctrine-project.org/projects/instantiator.html", - "keywords": [ - "constructor", - "instantiate" - ], - "time": "2019-10-21T16:45:58+00:00" - }, - { - "name": "myclabs/deep-copy", - "version": "1.9.3", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", - "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "replace": { - "myclabs/deep-copy": "self.version" - }, - "require-dev": { - "doctrine/collections": "^1.0", - "doctrine/common": "^2.6", - "phpunit/phpunit": "^7.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - }, - "files": [ - "src/DeepCopy/deep_copy.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Create deep copies (clones) of your objects", - "keywords": [ - "clone", - "copy", - "duplicate", - "object", - "object graph" - ], - "time": "2019-08-09T12:45:53+00:00" - }, - { - "name": "phar-io/manifest", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/phar-io/manifest.git", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-phar": "*", - "phar-io/version": "^1.0.1", - "php": "^5.6 || ^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2017-03-05T18:14:27+00:00" - }, - { - "name": "phar-io/version", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/phar-io/version.git", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Library for handling version information and constraints", - "time": "2017-03-05T17:38:23+00:00" - }, - { - "name": "phpcompatibility/php-compatibility", - "version": "9.3.4", - "source": { - "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", - "reference": "1f37659196e4f3113ea506a7efba201c52303bf1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/1f37659196e4f3113ea506a7efba201c52303bf1", - "reference": "1f37659196e4f3113ea506a7efba201c52303bf1", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" - }, - "conflict": { - "squizlabs/php_codesniffer": "2.6.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Wim Godden", - "homepage": "https://github.com/wimg", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "homepage": "https://github.com/jrfnl", - "role": "lead" - }, - { - "name": "Contributors", - "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" - } - ], - "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", - "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", - "keywords": [ - "compatibility", - "phpcs", - "standards" - ], - "time": "2019-11-15T04:12:02+00:00" - }, - { - "name": "phpcompatibility/phpcompatibility-paragonie", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", - "reference": "b862bc32f7e860d0b164b199bd995e690b4b191c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/b862bc32f7e860d0b164b199bd995e690b4b191c", - "reference": "b862bc32f7e860d0b164b199bd995e690b4b191c", - "shasum": "" - }, - "require": { - "phpcompatibility/php-compatibility": "^9.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5", - "paragonie/random_compat": "dev-master", - "paragonie/sodium_compat": "dev-master" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Wim Godden", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "lead" - } - ], - "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", - "homepage": "http://phpcompatibility.com/", - "keywords": [ - "compatibility", - "paragonie", - "phpcs", - "polyfill", - "standards" - ], - "time": "2019-11-04T15:17:54+00:00" - }, - { - "name": "phpcompatibility/phpcompatibility-wp", - "version": "2.1.0", - "source": { - "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", - "reference": "41bef18ba688af638b7310666db28e1ea9158b2f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/41bef18ba688af638b7310666db28e1ea9158b2f", - "reference": "41bef18ba688af638b7310666db28e1ea9158b2f", - "shasum": "" - }, - "require": { - "phpcompatibility/php-compatibility": "^9.0", - "phpcompatibility/phpcompatibility-paragonie": "^1.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Wim Godden", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "lead" - } - ], - "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", - "homepage": "http://phpcompatibility.com/", - "keywords": [ - "compatibility", - "phpcs", - "standards", - "wordpress" - ], - "time": "2019-08-28T14:22:28+00:00" - }, - { - "name": "phpdocumentor/reflection-common", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "require-dev": { - "phpunit/phpunit": "~6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" - } - ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", - "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" - ], - "time": "2018-08-07T13:53:10+00:00" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "4.3.2", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", - "shasum": "" - }, - "require": { - "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", - "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", - "webmozart/assert": "^1.0" - }, - "require-dev": { - "doctrine/instantiator": "^1.0.5", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^6.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-09-12T14:27:41+00:00" - }, - { - "name": "phpdocumentor/type-resolver", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", - "shasum": "" - }, - "require": { - "php": "^7.1", - "phpdocumentor/reflection-common": "^2.0" - }, - "require-dev": { - "ext-tokenizer": "^7.1", - "mockery/mockery": "~1", - "phpunit/phpunit": "^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2019-08-22T18:11:29+00:00" - }, - { - "name": "phpspec/prophecy", - "version": "1.9.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", - "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", - "sebastian/comparator": "^1.1|^2.0|^3.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" - }, - "require-dev": { - "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.8.x-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\": "src/Prophecy" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "time": "2019-10-03T11:07:50+00:00" - }, - { - "name": "phpunit/php-code-coverage", - "version": "5.3.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "c89677919c5dd6d3b3852f230a663118762218ac" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c89677919c5dd6d3b3852f230a663118762218ac", - "reference": "c89677919c5dd6d3b3852f230a663118762218ac", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-xmlwriter": "*", - "php": "^7.0", - "phpunit/php-file-iterator": "^1.4.2", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^2.0.1", - "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.0", - "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "suggest": { - "ext-xdebug": "^2.5.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2018-04-06T15:36:58+00:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.4.5", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2017-11-27T13:52:08+00:00" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2015-06-21T13:50:34+00:00" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.9", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2017-02-26T11:10:40+00:00" - }, - { - "name": "phpunit/php-token-stream", - "version": "2.0.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "791198a2c6254db10131eecfe8c06670700904db" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", - "reference": "791198a2c6254db10131eecfe8c06670700904db", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.2.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2017-11-27T05:48:46+00:00" - }, - { - "name": "phpunit/phpunit", - "version": "6.5.14", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "bac23fe7ff13dbdb461481f706f0e9fe746334b7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bac23fe7ff13dbdb461481f706f0e9fe746334b7", - "reference": "bac23fe7ff13dbdb461481f706f0e9fe746334b7", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-xml": "*", - "myclabs/deep-copy": "^1.6.1", - "phar-io/manifest": "^1.0.1", - "phar-io/version": "^1.0", - "php": "^7.0", - "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^5.3", - "phpunit/php-file-iterator": "^1.4.3", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^1.0.9", - "phpunit/phpunit-mock-objects": "^5.0.9", - "sebastian/comparator": "^2.1", - "sebastian/diff": "^2.0", - "sebastian/environment": "^3.1", - "sebastian/exporter": "^3.1", - "sebastian/global-state": "^2.0", - "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^1.0", - "sebastian/version": "^2.0.1" - }, - "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2", - "phpunit/dbunit": "<3.0" - }, - "require-dev": { - "ext-pdo": "*" - }, - "suggest": { - "ext-xdebug": "*", - "phpunit/php-invoker": "^1.1" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "6.5.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2019-02-01T05:22:47+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "5.0.10", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/cd1cf05c553ecfec36b170070573e540b67d3f1f", - "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.5", - "php": "^7.0", - "phpunit/php-text-template": "^1.2.1", - "sebastian/exporter": "^3.1" - }, - "conflict": { - "phpunit/phpunit": "<6.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.5.11" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "abandoned": true, - "time": "2018-08-09T05:50:03+00:00" - }, - { - "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Looks up which function or method a line of code belongs to", - "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" - }, - { - "name": "sebastian/comparator", - "version": "2.1.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", - "shasum": "" - }, - "require": { - "php": "^7.0", - "sebastian/diff": "^2.0 || ^3.0", - "sebastian/exporter": "^3.1" - }, - "require-dev": { - "phpunit/phpunit": "^6.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "https://github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "time": "2018-02-01T13:46:46+00:00" - }, - { - "name": "sebastian/diff", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", - "shasum": "" - }, - "require": { - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "https://github.com/sebastianbergmann/diff", - "keywords": [ - "diff" - ], - "time": "2017-08-03T08:09:46+00:00" - }, - { - "name": "sebastian/environment", - "version": "3.1.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", - "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", - "shasum": "" - }, - "require": { - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "time": "2017-07-01T08:51:00+00:00" - }, - { - "name": "sebastian/exporter", - "version": "3.1.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", - "shasum": "" - }, - "require": { - "php": "^7.0", - "sebastian/recursion-context": "^3.0" - }, - "require-dev": { - "ext-mbstring": "*", - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "time": "2019-09-14T09:02:43+00:00" - }, - { - "name": "sebastian/global-state", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", - "shasum": "" - }, - "require": { - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "suggest": { - "ext-uopz": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "time": "2017-04-27T15:39:26+00:00" - }, - { - "name": "sebastian/object-enumerator", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "shasum": "" - }, - "require": { - "php": "^7.0", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Traverses array structures and object graphs to enumerate all referenced objects", - "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-08-03T12:35:26+00:00" - }, - { - "name": "sebastian/object-reflector", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "773f97c67f28de00d397be301821b06708fca0be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", - "reference": "773f97c67f28de00d397be301821b06708fca0be", - "shasum": "" - }, - "require": { - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Allows reflection of object attributes, including inherited and non-public ones", - "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2017-03-29T09:07:27+00:00" - }, - { - "name": "sebastian/recursion-context", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "shasum": "" - }, - "require": { - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-03-03T06:23:57+00:00" - }, - { - "name": "sebastian/resource-operations", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "shasum": "" - }, - "require": { - "php": ">=5.6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides a list of PHP built-in functions that operate on resources", - "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" - }, - { - "name": "sebastian/version", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "3.5.3", - "source": { - "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/557a1fc7ac702c66b0bbfe16ab3d55839ef724cb", - "reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb", - "shasum": "" - }, - "require": { - "ext-simplexml": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" - }, - "bin": [ - "bin/phpcs", - "bin/phpcbf" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", - "keywords": [ - "phpcs", - "standards" - ], - "time": "2019-12-04T04:46:47+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.13.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.13-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "time": "2019-11-27T13:56:44+00:00" - }, - { - "name": "theseer/tokenizer", - "version": "1.1.3", - "source": { - "type": "git", - "url": "https://github.com/theseer/tokenizer.git", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": "^7.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - } - ], - "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2019-06-13T22:48:21+00:00" - }, - { - "name": "webmozart/assert", - "version": "1.6.0", - "source": { - "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0", - "symfony/polyfill-ctype": "^1.8" - }, - "conflict": { - "vimeo/psalm": "<3.6.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^7.5.13" - }, - "type": "library", - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "time": "2019-11-24T13:36:37+00:00" - }, - { - "name": "woocommerce/woocommerce-sniffs", - "version": "0.0.9", - "source": { - "type": "git", - "url": "https://github.com/woocommerce/woocommerce-sniffs.git", - "reference": "7677a84e9a355fe1e088f704090be891e7a6d427" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-sniffs/zipball/7677a84e9a355fe1e088f704090be891e7a6d427", - "reference": "7677a84e9a355fe1e088f704090be891e7a6d427", - "shasum": "" - }, - "require": { - "dealerdirect/phpcodesniffer-composer-installer": "0.5.0", - "php": ">=7.0", - "phpcompatibility/phpcompatibility-wp": "2.1.0", - "wp-coding-standards/wpcs": "2.2.0" - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Claudio Sanches", - "email": "claudio@automattic.com" - } - ], - "description": "WooCommerce sniffs", - "keywords": [ - "phpcs", - "standards", - "woocommerce", - "wordpress" - ], - "time": "2019-11-11T15:48:34+00:00" - }, - { - "name": "wp-coding-standards/wpcs", - "version": "2.2.0", - "source": { - "type": "git", - "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "f90e8692ce97b693633db7ab20bfa78d930f536a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/f90e8692ce97b693633db7ab20bfa78d930f536a", - "reference": "f90e8692ce97b693633db7ab20bfa78d930f536a", - "shasum": "" - }, - "require": { - "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.3.1" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", - "phpcompatibility/php-compatibility": "^9.0", - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Contributors", - "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" - } - ], - "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", - "keywords": [ - "phpcs", - "standards", - "wordpress" - ], - "time": "2019-11-11T12:34:03+00:00" - } - ], - "aliases": [], - "minimum-stability": "dev", - "stability-flags": [], - "prefer-stable": true, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index b1506082765..00000000000 --- a/package-lock.json +++ /dev/null @@ -1,1618 +0,0 @@ -{ - "name": "woocommerce-rest-api", - "version": "1.0.5", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@babel/code-frame": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz", - "integrity": "sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g==", - "dev": true, - "requires": { - "@babel/highlight": "^7.8.3" - } - }, - "@babel/highlight": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.8.3.tgz", - "integrity": "sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg==", - "dev": true, - "requires": { - "chalk": "^2.0.0", - "esutils": "^2.0.2", - "js-tokens": "^4.0.0" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, - "@babel/runtime": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.3.tgz", - "integrity": "sha512-fVHx1rzEmwB130VTkLnxR+HmxcTjGzH12LYQcFFoBwakMd3aOMD4OsRN7tGG/UOYE2ektgFrS8uACAoRk1CY0w==", - "dev": true, - "requires": { - "regenerator-runtime": "^0.13.2" - } - }, - "@nodelib/fs.scandir": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", - "integrity": "sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw==", - "dev": true, - "requires": { - "@nodelib/fs.stat": "2.0.3", - "run-parallel": "^1.1.9" - } - }, - "@nodelib/fs.stat": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz", - "integrity": "sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA==", - "dev": true - }, - "@nodelib/fs.walk": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.4.tgz", - "integrity": "sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ==", - "dev": true, - "requires": { - "@nodelib/fs.scandir": "2.1.3", - "fastq": "^1.6.0" - } - }, - "@samverschueren/stream-to-observable": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz", - "integrity": "sha512-MI4Xx6LHs4Webyvi6EbspgyAb4D2Q2VtnCQ1blOJcoLS6mVa8lNN2rkIy1CVxfTUpoyIbCTkXES1rLXztFD1lg==", - "dev": true, - "requires": { - "any-observable": "^0.3.0" - } - }, - "@types/color-name": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", - "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", - "dev": true - }, - "@types/events": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", - "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==", - "dev": true - }, - "@types/glob": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz", - "integrity": "sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==", - "dev": true, - "requires": { - "@types/events": "*", - "@types/minimatch": "*", - "@types/node": "*" - } - }, - "@types/minimatch": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", - "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", - "dev": true - }, - "@types/node": { - "version": "13.5.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.5.0.tgz", - "integrity": "sha512-Onhn+z72D2O2Pb2ql2xukJ55rglumsVo1H6Fmyi8mlU9SvKdBk/pUSUAiBY/d9bAOF7VVWajX3sths/+g6ZiAQ==", - "dev": true - }, - "@types/parse-json": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz", - "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", - "dev": true - }, - "aggregate-error": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", - "integrity": "sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA==", - "dev": true, - "requires": { - "clean-stack": "^2.0.0", - "indent-string": "^4.0.0" - } - }, - "ansi-escapes": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", - "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", - "dev": true - }, - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true - }, - "ansi-styles": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", - "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", - "dev": true, - "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" - } - }, - "any-observable": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/any-observable/-/any-observable-0.3.0.tgz", - "integrity": "sha512-/FQM1EDkTsf63Ub2C6O7GuYFDsSXUwsaZDurV0np41ocwq0jthUAYCmhBX9f+KwlaCgIuWyr/4WlUQUBfKfZog==", - "dev": true - }, - "argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, - "requires": { - "sprintf-js": "~1.0.2" - } - }, - "array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", - "dev": true - }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, - "requires": { - "fill-range": "^7.0.1" - } - }, - "caller-callsite": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/caller-callsite/-/caller-callsite-2.0.0.tgz", - "integrity": "sha1-hH4PzgoiN1CpoCfFSzNzGtMVQTQ=", - "dev": true, - "requires": { - "callsites": "^2.0.0" - }, - "dependencies": { - "callsites": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz", - "integrity": "sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA=", - "dev": true - } - } - }, - "caller-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-2.0.0.tgz", - "integrity": "sha1-Ro+DBE42mrIBD6xfBs7uFbsssfQ=", - "dev": true, - "requires": { - "caller-callsite": "^2.0.0" - } - }, - "callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", - "dev": true - }, - "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", - "dev": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "ci-info": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", - "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", - "dev": true - }, - "clean-stack": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", - "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", - "dev": true - }, - "cli-cursor": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", - "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", - "dev": true, - "requires": { - "restore-cursor": "^2.0.0" - } - }, - "cli-truncate": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-0.2.1.tgz", - "integrity": "sha1-nxXPuwcFAFNpIWxiasfQWrkN1XQ=", - "dev": true, - "requires": { - "slice-ansi": "0.0.4", - "string-width": "^1.0.1" - } - }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "cosmiconfig": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz", - "integrity": "sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg==", - "dev": true, - "requires": { - "@types/parse-json": "^4.0.0", - "import-fresh": "^3.1.0", - "parse-json": "^5.0.0", - "path-type": "^4.0.0", - "yaml": "^1.7.2" - } - }, - "cross-spawn": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.1.tgz", - "integrity": "sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==", - "dev": true, - "requires": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - } - }, - "date-fns": { - "version": "1.30.1", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz", - "integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==", - "dev": true - }, - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, - "requires": { - "ms": "^2.1.1" - } - }, - "dedent": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz", - "integrity": "sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=", - "dev": true - }, - "del": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/del/-/del-5.1.0.tgz", - "integrity": "sha512-wH9xOVHnczo9jN2IW68BabcecVPxacIA3g/7z6vhSU/4stOKQzeCRK0yD0A24WiAAUJmmVpWqrERcTxnLo3AnA==", - "dev": true, - "requires": { - "globby": "^10.0.1", - "graceful-fs": "^4.2.2", - "is-glob": "^4.0.1", - "is-path-cwd": "^2.2.0", - "is-path-inside": "^3.0.1", - "p-map": "^3.0.0", - "rimraf": "^3.0.0", - "slash": "^3.0.0" - } - }, - "dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, - "requires": { - "path-type": "^4.0.0" - } - }, - "elegant-spinner": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/elegant-spinner/-/elegant-spinner-1.0.1.tgz", - "integrity": "sha1-2wQ1IcldfjA/2PNFvtwzSc+wcp4=", - "dev": true - }, - "end-of-stream": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", - "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, - "requires": { - "once": "^1.4.0" - } - }, - "error-ex": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", - "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", - "dev": true, - "requires": { - "is-arrayish": "^0.2.1" - } - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true - }, - "esutils": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", - "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", - "dev": true - }, - "execa": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-2.1.0.tgz", - "integrity": "sha512-Y/URAVapfbYy2Xp/gb6A0E7iR8xeqOCXsuuaoMn7A5PzrXUK84E1gyiEfq0wQd/GHA6GsoHWwhNq8anb0mleIw==", - "dev": true, - "requires": { - "cross-spawn": "^7.0.0", - "get-stream": "^5.0.0", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^3.0.0", - "onetime": "^5.1.0", - "p-finally": "^2.0.0", - "signal-exit": "^3.0.2", - "strip-final-newline": "^2.0.0" - } - }, - "fast-glob": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.1.1.tgz", - "integrity": "sha512-nTCREpBY8w8r+boyFYAx21iL6faSsQynliPHM4Uf56SbkyohCNxpVPEH9xrF5TXKy+IsjkPUHDKiUkzBVRXn9g==", - "dev": true, - "requires": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.0", - "merge2": "^1.3.0", - "micromatch": "^4.0.2" - } - }, - "fastq": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.6.0.tgz", - "integrity": "sha512-jmxqQ3Z/nXoeyDmWAzF9kH1aGZSis6e/SbfPmJpUnyZ0ogr6iscHQaml4wsEepEWSdtmpy+eVXmCRIMpxaXqOA==", - "dev": true, - "requires": { - "reusify": "^1.0.0" - } - }, - "figures": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", - "integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=", - "dev": true, - "requires": { - "escape-string-regexp": "^1.0.5", - "object-assign": "^4.1.0" - } - }, - "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, - "requires": { - "to-regex-range": "^5.0.1" - } - }, - "find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "dev": true, - "requires": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - } - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "get-own-enumerable-property-symbols": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz", - "integrity": "sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==", - "dev": true - }, - "get-stream": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", - "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, - "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "glob-parent": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.0.tgz", - "integrity": "sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw==", - "dev": true, - "requires": { - "is-glob": "^4.0.1" - } - }, - "globby": { - "version": "10.0.2", - "resolved": "https://registry.npmjs.org/globby/-/globby-10.0.2.tgz", - "integrity": "sha512-7dUi7RvCoT/xast/o/dLN53oqND4yk0nsHkhRgn9w65C4PofCLOoJ39iSOg+qVDdWQPIEj+eszMHQ+aLVwwQSg==", - "dev": true, - "requires": { - "@types/glob": "^7.1.1", - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.0.3", - "glob": "^7.1.3", - "ignore": "^5.1.1", - "merge2": "^1.2.3", - "slash": "^3.0.0" - } - }, - "graceful-fs": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", - "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", - "dev": true - }, - "has-ansi": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true - }, - "husky": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/husky/-/husky-4.0.10.tgz", - "integrity": "sha512-Ptm4k2DqOwxeK/kzu5RaJmNRoGvESrgDXObFcZ8aJZcyXyMBHhM2FqZj6zYKdetadmP3wCwxEHCBuB9xGlRp8A==", - "dev": true, - "requires": { - "chalk": "^3.0.0", - "ci-info": "^2.0.0", - "cosmiconfig": "^6.0.0", - "opencollective-postinstall": "^2.0.2", - "pkg-dir": "^4.2.0", - "please-upgrade-node": "^3.2.0", - "slash": "^3.0.0", - "which-pm-runs": "^1.0.0" - } - }, - "ignore": { - "version": "5.1.4", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", - "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", - "dev": true - }, - "import-fresh": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", - "integrity": "sha512-6e1q1cnWP2RXD9/keSkxHScg508CdXqXWgWBaETNhyuBFz+kUZlKboh+ISK+bU++DmbHimVBrOz/zzPe0sZ3sQ==", - "dev": true, - "requires": { - "parent-module": "^1.0.0", - "resolve-from": "^4.0.0" - } - }, - "indent-string": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", - "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", - "dev": true - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true - }, - "is-arrayish": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", - "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", - "dev": true - }, - "is-directory": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz", - "integrity": "sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=", - "dev": true - }, - "is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "dev": true, - "requires": { - "number-is-nan": "^1.0.0" - } - }, - "is-glob": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", - "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", - "dev": true, - "requires": { - "is-extglob": "^2.1.1" - } - }, - "is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true - }, - "is-obj": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", - "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", - "dev": true - }, - "is-observable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-observable/-/is-observable-1.1.0.tgz", - "integrity": "sha512-NqCa4Sa2d+u7BWc6CukaObG3Fh+CU9bvixbpcXYhy2VvYS7vVGIdAgnIS5Ks3A/cqk4rebLJ9s8zBstT2aKnIA==", - "dev": true, - "requires": { - "symbol-observable": "^1.1.0" - } - }, - "is-path-cwd": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz", - "integrity": "sha512-w942bTcih8fdJPJmQHFzkS76NEP8Kzzvmw92cXsazb8intwLqPibPPdXf4ANdKV3rYMuuQYGIWtvz9JilB3NFQ==", - "dev": true - }, - "is-path-inside": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.2.tgz", - "integrity": "sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg==", - "dev": true - }, - "is-promise": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", - "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", - "dev": true - }, - "is-regexp": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz", - "integrity": "sha1-/S2INUXEa6xaYz57mgnof6LLUGk=", - "dev": true - }, - "is-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", - "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==", - "dev": true - }, - "isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true - }, - "js-tokens": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true - }, - "js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", - "dev": true, - "requires": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" - } - }, - "json-parse-better-errors": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", - "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", - "dev": true - }, - "lines-and-columns": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", - "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=", - "dev": true - }, - "lint-staged": { - "version": "9.5.0", - "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-9.5.0.tgz", - "integrity": "sha512-nawMob9cb/G1J98nb8v3VC/E8rcX1rryUYXVZ69aT9kde6YWX+uvNOEHY5yf2gcWcTJGiD0kqXmCnS3oD75GIA==", - "dev": true, - "requires": { - "chalk": "^2.4.2", - "commander": "^2.20.0", - "cosmiconfig": "^5.2.1", - "debug": "^4.1.1", - "dedent": "^0.7.0", - "del": "^5.0.0", - "execa": "^2.0.3", - "listr": "^0.14.3", - "log-symbols": "^3.0.0", - "micromatch": "^4.0.2", - "normalize-path": "^3.0.0", - "please-upgrade-node": "^3.1.1", - "string-argv": "^0.3.0", - "stringify-object": "^3.3.0" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "cosmiconfig": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz", - "integrity": "sha512-H65gsXo1SKjf8zmrJ67eJk8aIRKV5ff2D4uKZIBZShbhGSpEmsQOPW/SKMKYhSTrqR7ufy6RP69rPogdaPh/kA==", - "dev": true, - "requires": { - "import-fresh": "^2.0.0", - "is-directory": "^0.3.1", - "js-yaml": "^3.13.1", - "parse-json": "^4.0.0" - } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "import-fresh": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz", - "integrity": "sha1-2BNVwVYS04bGH53dOSLUMEgipUY=", - "dev": true, - "requires": { - "caller-path": "^2.0.0", - "resolve-from": "^3.0.0" - } - }, - "parse-json": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", - "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", - "dev": true, - "requires": { - "error-ex": "^1.3.1", - "json-parse-better-errors": "^1.0.1" - } - }, - "resolve-from": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", - "integrity": "sha1-six699nWiBvItuZTM17rywoYh0g=", - "dev": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, - "listr": { - "version": "0.14.3", - "resolved": "https://registry.npmjs.org/listr/-/listr-0.14.3.tgz", - "integrity": "sha512-RmAl7su35BFd/xoMamRjpIE4j3v+L28o8CT5YhAXQJm1fD+1l9ngXY8JAQRJ+tFK2i5njvi0iRUKV09vPwA0iA==", - "dev": true, - "requires": { - "@samverschueren/stream-to-observable": "^0.3.0", - "is-observable": "^1.1.0", - "is-promise": "^2.1.0", - "is-stream": "^1.1.0", - "listr-silent-renderer": "^1.1.1", - "listr-update-renderer": "^0.5.0", - "listr-verbose-renderer": "^0.5.0", - "p-map": "^2.0.0", - "rxjs": "^6.3.3" - }, - "dependencies": { - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", - "dev": true - }, - "p-map": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-map/-/p-map-2.1.0.tgz", - "integrity": "sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==", - "dev": true - } - } - }, - "listr-silent-renderer": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/listr-silent-renderer/-/listr-silent-renderer-1.1.1.tgz", - "integrity": "sha1-kktaN1cVN3C/Go4/v3S4u/P5JC4=", - "dev": true - }, - "listr-update-renderer": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/listr-update-renderer/-/listr-update-renderer-0.5.0.tgz", - "integrity": "sha512-tKRsZpKz8GSGqoI/+caPmfrypiaq+OQCbd+CovEC24uk1h952lVj5sC7SqyFUm+OaJ5HN/a1YLt5cit2FMNsFA==", - "dev": true, - "requires": { - "chalk": "^1.1.3", - "cli-truncate": "^0.2.1", - "elegant-spinner": "^1.0.1", - "figures": "^1.7.0", - "indent-string": "^3.0.0", - "log-symbols": "^1.0.2", - "log-update": "^2.3.0", - "strip-ansi": "^3.0.1" - }, - "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, - "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - } - }, - "indent-string": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-3.2.0.tgz", - "integrity": "sha1-Sl/W0nzDMvN+VBmlBNu4NxBckok=", - "dev": true - }, - "log-symbols": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-1.0.2.tgz", - "integrity": "sha1-N2/3tY6jCGoPCfrMdGF+ylAeGhg=", - "dev": true, - "requires": { - "chalk": "^1.0.0" - } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true - } - } - }, - "listr-verbose-renderer": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/listr-verbose-renderer/-/listr-verbose-renderer-0.5.0.tgz", - "integrity": "sha512-04PDPqSlsqIOaaaGZ+41vq5FejI9auqTInicFRndCBgE3bXG8D6W1I+mWhk+1nqbHmyhla/6BUrd5OSiHwKRXw==", - "dev": true, - "requires": { - "chalk": "^2.4.1", - "cli-cursor": "^2.1.0", - "date-fns": "^1.27.2", - "figures": "^2.0.0" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "figures": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", - "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", - "dev": true, - "requires": { - "escape-string-regexp": "^1.0.5" - } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, - "locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dev": true, - "requires": { - "p-locate": "^4.1.0" - } - }, - "log-symbols": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-3.0.0.tgz", - "integrity": "sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ==", - "dev": true, - "requires": { - "chalk": "^2.4.2" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, - "log-update": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/log-update/-/log-update-2.3.0.tgz", - "integrity": "sha1-iDKP19HOeTiykoN0bwsbwSayRwg=", - "dev": true, - "requires": { - "ansi-escapes": "^3.0.0", - "cli-cursor": "^2.0.0", - "wrap-ansi": "^3.0.1" - } - }, - "merge-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true - }, - "merge2": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.3.0.tgz", - "integrity": "sha512-2j4DAdlBOkiSZIsaXk4mTE3sRS02yBHAtfy127xRV3bQUFqXkjHCHLW6Scv7DwNRbIWNHH8zpnz9zMaKXIdvYw==", - "dev": true - }, - "micromatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", - "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==", - "dev": true, - "requires": { - "braces": "^3.0.1", - "picomatch": "^2.0.5" - } - }, - "mimic-fn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", - "dev": true - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, - "normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true - }, - "npm-run-path": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-3.1.0.tgz", - "integrity": "sha512-Dbl4A/VfiVGLgQv29URL9xshU8XDY1GeLy+fsaZ1AA8JDSfjvr5P5+pzRbWqRSBxk6/DW7MIh8lTM/PaGnP2kg==", - "dev": true, - "requires": { - "path-key": "^3.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1" - } - }, - "onetime": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz", - "integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==", - "dev": true, - "requires": { - "mimic-fn": "^2.1.0" - } - }, - "opencollective-postinstall": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz", - "integrity": "sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw==", - "dev": true - }, - "p-finally": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-2.0.1.tgz", - "integrity": "sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw==", - "dev": true - }, - "p-limit": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz", - "integrity": "sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ==", - "dev": true, - "requires": { - "p-try": "^2.0.0" - } - }, - "p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "dev": true, - "requires": { - "p-limit": "^2.2.0" - } - }, - "p-map": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz", - "integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==", - "dev": true, - "requires": { - "aggregate-error": "^3.0.0" - } - }, - "p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true - }, - "parent-module": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", - "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, - "requires": { - "callsites": "^3.0.0" - } - }, - "parse-json": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.0.0.tgz", - "integrity": "sha512-OOY5b7PAEFV0E2Fir1KOkxchnZNCdowAJgQ5NuxjpBKTRP3pQhwkrkxqQjeoKJ+fO7bCpmIZaogI4eZGDMEGOw==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "error-ex": "^1.3.1", - "json-parse-better-errors": "^1.0.1", - "lines-and-columns": "^1.1.6" - } - }, - "path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true - }, - "path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true - }, - "path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true - }, - "picomatch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.1.tgz", - "integrity": "sha512-ISBaA8xQNmwELC7eOjqFKMESB2VIqt4PPDD0nsS95b/9dZXvVKOlz9keMSnoGGKcOHXfTvDD6WMaRoSc9UuhRA==", - "dev": true - }, - "pkg-dir": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", - "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", - "dev": true, - "requires": { - "find-up": "^4.0.0" - } - }, - "please-upgrade-node": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz", - "integrity": "sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==", - "dev": true, - "requires": { - "semver-compare": "^1.0.0" - } - }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "regenerator-runtime": { - "version": "0.13.3", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", - "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==", - "dev": true - }, - "resolve-from": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true - }, - "restore-cursor": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", - "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", - "dev": true, - "requires": { - "onetime": "^2.0.0", - "signal-exit": "^3.0.2" - }, - "dependencies": { - "mimic-fn": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", - "dev": true - }, - "onetime": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", - "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", - "dev": true, - "requires": { - "mimic-fn": "^1.0.0" - } - } - } - }, - "reusify": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", - "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", - "dev": true - }, - "rimraf": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz", - "integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==", - "dev": true, - "requires": { - "glob": "^7.1.3" - } - }, - "run-parallel": { - "version": "1.1.9", - "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz", - "integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==", - "dev": true - }, - "rxjs": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", - "integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", - "dev": true, - "requires": { - "tslib": "^1.9.0" - } - }, - "semver-compare": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", - "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=", - "dev": true - }, - "shebang-command": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", - "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, - "requires": { - "shebang-regex": "^3.0.0" - } - }, - "shebang-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true - }, - "signal-exit": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", - "dev": true - }, - "slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true - }, - "slice-ansi": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz", - "integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU=", - "dev": true - }, - "sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true - }, - "string-argv": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", - "integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==", - "dev": true - }, - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "dev": true, - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" - } - }, - "stringify-object": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.3.0.tgz", - "integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==", - "dev": true, - "requires": { - "get-own-enumerable-property-symbols": "^3.0.0", - "is-obj": "^1.0.1", - "is-regexp": "^1.0.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", - "dev": true - }, - "supports-color": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", - "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", - "dev": true, - "requires": { - "has-flag": "^4.0.0" - } - }, - "symbol-observable": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz", - "integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==", - "dev": true - }, - "to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, - "requires": { - "is-number": "^7.0.0" - } - }, - "tslib": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", - "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", - "dev": true - }, - "which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, - "requires": { - "isexe": "^2.0.0" - } - }, - "which-pm-runs": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz", - "integrity": "sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=", - "dev": true - }, - "wrap-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-3.0.1.tgz", - "integrity": "sha1-KIoE2H7aXChuBg3+jxNc6NAH+Lo=", - "dev": true, - "requires": { - "string-width": "^2.1.1", - "strip-ansi": "^4.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "dev": true - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, - "requires": { - "ansi-regex": "^3.0.0" - } - } - } - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - }, - "yaml": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.7.2.tgz", - "integrity": "sha512-qXROVp90sb83XtAoqE8bP9RwAkTTZbugRUTm5YeFCBfNRPEp2YzTeqWiz7m5OORHzEvrA/qcGS8hp/E+MMROYw==", - "dev": true, - "requires": { - "@babel/runtime": "^7.6.3" - } - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 2d17f61330a..00000000000 --- a/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "woocommerce-rest-api", - "title": "WooCommerce REST API", - "version": "1.0.10", - "homepage": "https://woocommerce.com/", - "repository": { - "type": "git", - "url": "https://github.com/woocommerce/woocommerce-rest-api.git" - }, - "license": "GPL-3.0+", - "main": "Gruntfile.js", - "devDependencies": { - "husky": "4.0.10", - "lint-staged": "9.5.0" - }, - "engines": { - "node": ">=10.15.0", - "npm": ">=6.4.1" - }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } - }, - "lint-staged": { - "*.php": [ - "php -d display_errors=1 -l", - "composer run-script phpcs-pre-commit" - ] - } -} diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index ceb59896bf8..00000000000 --- a/phpcs.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - WooCommerce dev PHP_CodeSniffer ruleset. - - - tests/ - apigen/ - */node_modules/* - */vendor/* - - - - - - - - - - - - - - - - tests/ - - - - * - - - - tests/ - - - - i18n/ - * - - diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 9119520176d..00000000000 --- a/phpunit.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./unit-tests/Tests - - - diff --git a/unit-tests/AbstractRestApiTest.php b/unit-tests/AbstractRestApiTest.php deleted file mode 100644 index 3646b4681ff..00000000000 --- a/unit-tests/AbstractRestApiTest.php +++ /dev/null @@ -1,213 +0,0 @@ -user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Setup test class. - */ - public function setUp() { - parent::setUp(); - wp_set_current_user( self::$user ); - } - - /** - * Test route registration. - */ - public function test_register_routes() { - $actual_routes = $this->server->get_routes(); - $expected_routes = $this->routes; - - foreach ( $expected_routes as $expected_route ) { - $this->assertArrayHasKey( $expected_route, $actual_routes ); - } - } - - /** - * Validate that the returned API schema matches what is expected. - * - * @return void - */ - public function test_schema_properties() { - $request = new \WP_REST_Request( 'OPTIONS', $this->routes[0] ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( count( array_keys( $this->properties ) ), count( $properties ), print_r( array_diff( array_keys( $properties ), array_keys( $this->properties ) ), true ) ); - - foreach ( array_keys( $this->properties ) as $property ) { - $this->assertArrayHasKey( $property, $properties ); - } - } - - /** - * Test creation using this method. - * If read-only, test to confirm this. - */ - abstract public function test_create(); - - /** - * Test get/read using this method. - */ - abstract public function test_read(); - - /** - * Test updates using this method. - * If read-only, test to confirm this. - */ - abstract public function test_update(); - - /** - * Test delete using this method. - * If read-only, test to confirm this. - */ - abstract public function test_delete(); - - /** - * Perform a request and return the status and returned data. - * - * @param string $endpoint Endpoint to hit. - * @param string $type Type of request e.g GET or POST. - * @param array $params Request body or query. - * @return object - */ - protected function do_request( $endpoint, $type = 'GET', $params = [] ) { - $request = new \WP_REST_Request( $type, untrailingslashit( $endpoint ) ); - 'GET' === $type ? $request->set_query_params( $params ) : $request->set_body_params( $params ); - $response = $this->server->dispatch( $request ); - - return (object) array( - 'status' => $response->get_status(), - 'data' => json_decode( wp_json_encode( $response->get_data() ), true ), - 'raw' => $response->get_data(), - ); - } - - /** - * Test the request/response matched the data we sent. - * - * @param array $response Array of response data from do_request above. - * @param int $status_code Expected status code. - * @param array $data Array of expected data. - */ - protected function assertExpectedResponse( $response, $status_code = 200, $data = array() ) { - $this->assertObjectHasAttribute( 'status', $response ); - $this->assertObjectHasAttribute( 'data', $response ); - $this->assertEquals( $status_code, $response->status, print_r( $response->data, true ) ); - - if ( $data ) { - foreach ( $data as $key => $value ) { - if ( ! isset( $response->data[ $key ] ) ) { - continue; - } - switch ( $key ) { - case 'meta_data': - $this->assertMetaData( $value, $response->data[ $key ] ); - break; - default: - if ( is_array( $value ) ) { - $this->assertArraySubset( $value, $response->data[ $key ] ); - } else { - $this->assertEquals( $value, $response->data[ $key ] ); - } - } - } - } - } - - /** - * Test meta data in a response matches what we expect. - * - * @param array $expected_meta_data Array of data. - * @param array $actual_meta_data Array of data. - */ - protected function assertMetaData( $expected_meta_data, $actual_meta_data ) { - $this->assertTrue( is_array( $actual_meta_data ) ); - $this->assertEquals( count( $expected_meta_data ), count( $actual_meta_data ) ); - - foreach ( $actual_meta_data as $key => $meta ) { - $this->assertArrayHasKey( 'id', $meta ); - $this->assertArrayHasKey( 'key', $meta ); - $this->assertArrayHasKey( 'value', $meta ); - $this->assertEquals( $expected_meta_data[ $key ]['key'], $meta['key'] ); - $this->assertEquals( $expected_meta_data[ $key ]['value'], $meta['value'] ); - } - } - - /** - * Return array of properties for a given context. - * - * @param string $context Context to use. - * @return array - */ - protected function get_properties( $context = 'edit' ) { - return array_keys( array_filter( $this->properties, function( $contexts ) use( $context ) { - return in_array( $context, $contexts ); - } ) ); - } -} diff --git a/unit-tests/Bootstrap.php b/unit-tests/Bootstrap.php deleted file mode 100755 index b10c7f8eae5..00000000000 --- a/unit-tests/Bootstrap.php +++ /dev/null @@ -1,134 +0,0 @@ -wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; - $this->tests_dir = dirname( __FILE__ ); - $this->plugin_dir = dirname( $this->tests_dir ); - - if ( file_exists( dirname( $this->plugin_dir ) . '/woocommerce/woocommerce.php' ) ) { - // From plugin directory. - $this->plugins_dir = dirname( $this->plugin_dir ); - } else { - // Travis. - $this->plugins_dir = getenv( 'WP_CORE_DIR' ) . '/wp-content/plugins'; - } - - $this->wc_tests_dir = $this->plugins_dir . '/woocommerce/tests'; - - $this->setup_hooks(); - $this->load_framework(); - } - - /** - * Get tests dir. - * - * @return string - */ - public function get_dir() { - return dirname( __FILE__ ); - } - - /** - * Setup hooks. - */ - protected function setup_hooks() { - // Give access to tests_add_filter() function. - require_once $this->wp_tests_dir . '/includes/functions.php'; - - \tests_add_filter( 'muplugins_loaded', function() { - require_once $this->plugins_dir . '/woocommerce/woocommerce.php'; - require_once $this->plugin_dir . '/woocommerce-rest-api.php'; - } ); - - \tests_add_filter( 'setup_theme', function() { - echo \esc_html( 'Installing WooCommerce...' . PHP_EOL ); - - define( 'WP_UNINSTALL_PLUGIN', true ); - define( 'WC_REMOVE_ALL_DATA', true ); - include $this->plugins_dir . '/woocommerce/uninstall.php'; - - \WC_Install::install(); - - $GLOBALS['wp_roles'] = null; // WPCS: override ok. - \wp_roles(); - } ); - } - - /** - * Load the testing framework. - */ - protected function load_framework() { - // Start up the WP testing environment. - require_once $this->wp_tests_dir . '/includes/bootstrap.php'; - - // WooCommerce Core Testing Framework. - require_once $this->wc_tests_dir . '/legacy/framework/class-wc-unit-test-factory.php'; - require_once $this->wc_tests_dir . '/legacy/framework/vendor/class-wp-test-spy-rest-server.php'; - require_once $this->wc_tests_dir . '/legacy/includes/wp-http-testcase.php'; - require_once $this->wc_tests_dir . '/legacy/framework/class-wc-unit-test-case.php'; - require_once $this->wc_tests_dir . '/legacy/framework/class-wc-rest-unit-test-case.php'; - - require_once $this->tests_dir . '/Helpers/AdminNotesHelper.php'; - require_once $this->tests_dir . '/Helpers/CouponHelper.php'; - require_once $this->tests_dir . '/Helpers/CustomerHelper.php'; - require_once $this->tests_dir . '/Helpers/OrderHelper.php'; - require_once $this->tests_dir . '/Helpers/ProductHelper.php'; - require_once $this->tests_dir . '/Helpers/ShippingHelper.php'; - require_once $this->tests_dir . '/Helpers/SettingsHelper.php'; - require_once $this->tests_dir . '/Helpers/QueueHelper.php'; - require_once $this->tests_dir . '/AbstractRestApiTest.php'; - } -} - -Bootstrap::instance()->init(); diff --git a/unit-tests/Helpers/AdminNotesHelper.php b/unit-tests/Helpers/AdminNotesHelper.php deleted file mode 100644 index de1c6c9da13..00000000000 --- a/unit-tests/Helpers/AdminNotesHelper.php +++ /dev/null @@ -1,83 +0,0 @@ -query( "TRUNCATE TABLE {$wpdb->prefix}wc_admin_notes" ); // @codingStandardsIgnoreLine. - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}wc_admin_note_actions" ); // @codingStandardsIgnoreLine. - } - - /** - * Create two notes that we can use for notes REST API tests - */ - public static function add_notes_for_tests() { - $data_store = WC_Data_Store::load( 'admin-note' ); - - $note_1 = new WC_Admin_Note(); - $note_1->set_title( 'PHPUNIT_TEST_NOTE_1_TITLE' ); - $note_1->set_content( 'PHPUNIT_TEST_NOTE_1_CONTENT' ); - $note_1->set_content_data( (object) array( 'amount' => 1.23 ) ); - $note_1->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); - $note_1->set_icon( 'info' ); - $note_1->set_name( 'PHPUNIT_TEST_NOTE_NAME' ); - $note_1->set_source( 'PHPUNIT_TEST' ); - $note_1->add_action( - 'PHPUNIT_TEST_NOTE_1_ACTION_1_SLUG', - 'PHPUNIT_TEST_NOTE_1_ACTION_1_LABEL', - '?s=PHPUNIT_TEST_NOTE_1_ACTION_1_URL' - ); - $note_1->add_action( - 'PHPUNIT_TEST_NOTE_1_ACTION_2_SLUG', - 'PHPUNIT_TEST_NOTE_1_ACTION_2_LABEL', - '?s=PHPUNIT_TEST_NOTE_1_ACTION_2_URL' - ); - $note_1->save(); - - $note_2 = new WC_Admin_Note(); - $note_2->set_title( 'PHPUNIT_TEST_NOTE_2_TITLE' ); - $note_2->set_content( 'PHPUNIT_TEST_NOTE_2_CONTENT' ); - $note_2->set_content_data( (object) array( 'amount' => 4.56 ) ); - $note_2->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_WARNING ); - $note_2->set_icon( 'info' ); - $note_2->set_name( 'PHPUNIT_TEST_NOTE_NAME' ); - $note_2->set_source( 'PHPUNIT_TEST' ); - $note_2->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED ); - // This note has no actions. - $note_2->save(); - - $note_3 = new WC_Admin_Note(); - $note_3->set_title( 'PHPUNIT_TEST_NOTE_3_TITLE' ); - $note_3->set_content( 'PHPUNIT_TEST_NOTE_3_CONTENT' ); - $note_3->set_content_data( (object) array( 'amount' => 7.89 ) ); - $note_3->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); - $note_3->set_icon( 'info' ); - $note_3->set_name( 'PHPUNIT_TEST_NOTE_NAME' ); - $note_3->set_source( 'PHPUNIT_TEST' ); - $note_3->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_SNOOZED ); - $note_3->set_date_reminder( time() - HOUR_IN_SECONDS ); - // This note has no actions. - $note_3->save(); - - } -} diff --git a/unit-tests/Helpers/CouponHelper.php b/unit-tests/Helpers/CouponHelper.php deleted file mode 100644 index 2b65987bff5..00000000000 --- a/unit-tests/Helpers/CouponHelper.php +++ /dev/null @@ -1,147 +0,0 @@ - $coupon_code, - 'post_type' => 'shop_coupon', - 'post_status' => 'publish', - 'post_excerpt' => 'This is a dummy coupon', - ) - ); - - $meta = wp_parse_args( - $meta, - array( - 'discount_type' => 'fixed_cart', - 'coupon_amount' => '1', - 'individual_use' => 'no', - 'product_ids' => '', - 'exclude_product_ids' => '', - 'usage_limit' => '', - 'usage_limit_per_user' => '', - 'limit_usage_to_x_items' => '', - 'expiry_date' => '', - 'free_shipping' => 'no', - 'exclude_sale_items' => 'no', - 'product_categories' => array(), - 'exclude_product_categories' => array(), - 'minimum_amount' => '', - 'maximum_amount' => '', - 'customer_email' => array(), - 'usage_count' => '0', - ) - ); - - // Update meta. - foreach ( $meta as $key => $value ) { - update_post_meta( $coupon_id, $key, $value ); - } - - return new WC_Coupon( $coupon_code ); - } - - /** - * Delete a coupon. - * - * @param $coupon_id - * - * @return bool - */ - public static function delete_coupon( $coupon_id ) { - wp_delete_post( $coupon_id, true ); - - return true; - } - - /** - * Register a custom coupon type. - * - * @param string $coupon_type - */ - public static function register_custom_type( $coupon_type ) { - static $filters_added = false; - if ( isset( self::$custom_types[ $coupon_type ] ) ) { - return; - } - - self::$custom_types[ $coupon_type ] = "Testing custom type {$coupon_type}"; - - if ( ! $filters_added ) { - add_filter( 'woocommerce_coupon_discount_types', array( __CLASS__, 'filter_discount_types' ) ); - add_filter( 'woocommerce_coupon_get_discount_amount', array( __CLASS__, 'filter_get_discount_amount' ), 10, 5 ); - add_filter( 'woocommerce_coupon_is_valid_for_product', '__return_true' ); - $filters_added = true; - } - } - - /** - * Unregister custom coupon type. - * - * @param $coupon_type - */ - public static function unregister_custom_type( $coupon_type ) { - unset( self::$custom_types[ $coupon_type ] ); - if ( empty( self::$custom_types ) ) { - remove_filter( 'woocommerce_coupon_discount_types', array( __CLASS__, 'filter_discount_types' ) ); - remove_filter( 'woocommerce_coupon_get_discount_amount', array( __CLASS__, 'filter_get_discount_amount' ) ); - remove_filter( 'woocommerce_coupon_is_valid_for_product', '__return_true' ); - } - } - - /** - * Register custom discount types. - * - * @param array $discount_types - * @return array - */ - public static function filter_discount_types( $discount_types ) { - return array_merge( $discount_types, self::$custom_types ); - } - - /** - * Get custom discount type amount. Works like 'percent' type. - * - * @param float $discount - * @param float $discounting_amount - * @param array|null $item - * @param bool $single - * @param WC_Coupon $coupon - * - * @return float - */ - public static function filter_get_discount_amount( $discount, $discounting_amount, $item, $single, $coupon ) { - if ( ! isset( self::$custom_types [ $coupon->get_discount_type() ] ) ) { - return $discount; - } - - return (float) $coupon->get_amount() * ( $discounting_amount / 100 ); - } -} diff --git a/unit-tests/Helpers/CustomerHelper.php b/unit-tests/Helpers/CustomerHelper.php deleted file mode 100644 index 5751cf31f32..00000000000 --- a/unit-tests/Helpers/CustomerHelper.php +++ /dev/null @@ -1,138 +0,0 @@ - 0, - 'date_modified' => null, - 'country' => 'US', - 'state' => 'PA', - 'postcode' => '19123', - 'city' => 'Philadelphia', - 'address' => '123 South Street', - 'address_2' => 'Apt 1', - 'shipping_country' => 'US', - 'shipping_state' => 'PA', - 'shipping_postcode' => '19123', - 'shipping_city' => 'Philadelphia', - 'shipping_address' => '123 South Street', - 'shipping_address_2' => 'Apt 1', - 'is_vat_exempt' => false, - 'calculated_shipping' => false, - ); - - self::set_customer_details( $customer_data ); - - $customer = new WC_Customer( 0, true ); - - return $customer; - } - - /** - * Creates a customer in the tests DB. - */ - public static function create_customer( $username = 'testcustomer', $password = 'hunter2', $email = 'test@woo.local' ) { - $customer = new WC_Customer(); - $customer->set_billing_country( 'US' ); - $customer->set_first_name( 'Justin' ); - $customer->set_billing_state( 'PA' ); - $customer->set_billing_postcode( '19123' ); - $customer->set_billing_city( 'Philadelphia' ); - $customer->set_billing_address( '123 South Street' ); - $customer->set_billing_address_2( 'Apt 1' ); - $customer->set_shipping_country( 'US' ); - $customer->set_shipping_state( 'PA' ); - $customer->set_shipping_postcode( '19123' ); - $customer->set_shipping_city( 'Philadelphia' ); - $customer->set_shipping_address( '123 South Street' ); - $customer->set_shipping_address_2( 'Apt 1' ); - $customer->set_username( $username ); - $customer->set_password( $password ); - $customer->set_email( $email ); - $customer->save(); - return $customer; - } - - /** - * Get the expected output for the store's base location settings. - * - * @return array - */ - public static function get_expected_store_location() { - return array( 'GB', '', '', '' ); - } - - /** - * Get the customer's shipping and billing info from the session. - * - * @return array - */ - public static function get_customer_details() { - return WC()->session->get( 'customer' ); - } - - /** - * Get the user's chosen shipping method. - * - * @return array - */ - public static function get_chosen_shipping_methods() { - return WC()->session->get( 'chosen_shipping_methods' ); - } - - /** - * Get the "Tax Based On" WooCommerce option. - * - * @return string base or billing - */ - public static function get_tax_based_on() { - return get_option( 'woocommerce_tax_based_on' ); - } - - /** - * Set the the current customer's billing details in the session. - * - * @param string $default_shipping_method Shipping Method slug - */ - public static function set_customer_details( $customer_details ) { - WC()->session->set( 'customer', array_map( 'strval', $customer_details ) ); - } - - /** - * Set the user's chosen shipping method. - * - * @param string $chosen_shipping_method Shipping Method slug - */ - public static function set_chosen_shipping_methods( $chosen_shipping_methods ) { - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); - } - - /** - * Set the "Tax Based On" WooCommerce option. - * - * @param string $default_shipping_method Shipping Method slug - */ - public static function set_tax_based_on( $default_shipping_method ) { - update_option( 'woocommerce_tax_based_on', $default_shipping_method ); - } -} diff --git a/unit-tests/Helpers/OrderHelper.php b/unit-tests/Helpers/OrderHelper.php deleted file mode 100644 index 59f72d1dcb2..00000000000 --- a/unit-tests/Helpers/OrderHelper.php +++ /dev/null @@ -1,129 +0,0 @@ -get_items() as $item ) { - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::delete_product( $item['product_id'] ); - } - - ShippingHelper::delete_simple_flat_rate(); - - // Delete the order post. - $order->delete( true ); - } - - /** - * Create a order. - * - * @since 2.4 - * @version 3.0 New parameter $product. - * - * @param int $customer_id - * @param WC_Product $product - * - * @return WC_Order - */ - public static function create_order( $customer_id = 1, $product = null ) { - - if ( ! is_a( $product, 'WC_Product' ) ) { - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - } - - ShippingHelper::create_simple_flat_rate(); - - $order_data = array( - 'status' => 'pending', - 'customer_id' => $customer_id, - 'customer_note' => '', - 'total' => '', - ); - - $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Required, else wc_create_order throws an exception - $order = wc_create_order( $order_data ); - - // Add order products - $item = new WC_Order_Item_Product(); - $item->set_props( - array( - 'product' => $product, - 'quantity' => 4, - 'subtotal' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ), - 'total' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ), - ) - ); - $item->save(); - $order->add_item( $item ); - - // Set billing address - $order->set_billing_first_name( 'Jeroen' ); - $order->set_billing_last_name( 'Sormani' ); - $order->set_billing_company( 'WooCompany' ); - $order->set_billing_address_1( 'WooAddress' ); - $order->set_billing_address_2( '' ); - $order->set_billing_city( 'WooCity' ); - $order->set_billing_state( 'NY' ); - $order->set_billing_postcode( '123456' ); - $order->set_billing_country( 'US' ); - $order->set_billing_email( 'admin@example.org' ); - $order->set_billing_phone( '555-32123' ); - - // Add shipping costs - $shipping_taxes = WC_Tax::calc_shipping_tax( '10', WC_Tax::get_shipping_tax_rates() ); - $rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate' ); - $item = new WC_Order_Item_Shipping(); - $item->set_props( - array( - 'method_title' => $rate->label, - 'method_id' => $rate->id, - 'total' => wc_format_decimal( $rate->cost ), - 'taxes' => $rate->taxes, - ) - ); - foreach ( $rate->get_meta_data() as $key => $value ) { - $item->add_meta_data( $key, $value, true ); - } - $order->add_item( $item ); - - // Set payment gateway - $payment_gateways = WC()->payment_gateways->payment_gateways(); - $order->set_payment_method( $payment_gateways['bacs'] ); - - // Set totals - $order->set_shipping_total( 10 ); - $order->set_discount_total( 0 ); - $order->set_discount_tax( 0 ); - $order->set_cart_tax( 0 ); - $order->set_shipping_tax( 0 ); - $order->set_total( 50 ); // 4 x $10 simple helper product - $order->save(); - - return $order; - } -} diff --git a/unit-tests/Helpers/ProductHelper.php b/unit-tests/Helpers/ProductHelper.php deleted file mode 100644 index 78d4333610e..00000000000 --- a/unit-tests/Helpers/ProductHelper.php +++ /dev/null @@ -1,310 +0,0 @@ -delete( true ); - } - } - - /** - * Create simple product. - * - * @since 2.3 - * @param bool $save Save or return object. - * @return WC_Product_Simple - */ - public static function create_simple_product( $save = true ) { - $product = new WC_Product_Simple(); - $product->set_props( - array( - 'name' => 'Dummy Product', - 'regular_price' => 10, - 'price' => 10, - 'sku' => 'DUMMY SKU', - 'manage_stock' => false, - 'tax_status' => 'taxable', - 'downloadable' => false, - 'virtual' => false, - 'stock_status' => 'instock', - 'weight' => '1.1', - ) - ); - - if ( $save ) { - $product->save(); - return \wc_get_product( $product->get_id() ); - } else { - return $product; - } - } - - /** - * Create external product. - * - * @since 3.0.0 - * @return WC_Product_External - */ - public static function create_external_product() { - $product = new WC_Product_External(); - $product->set_props( - array( - 'name' => 'Dummy External Product', - 'regular_price' => 10, - 'sku' => 'DUMMY EXTERNAL SKU', - 'product_url' => 'http://woocommerce.com', - 'button_text' => 'Buy external product', - ) - ); - $product->save(); - - return \wc_get_product( $product->get_id() ); - } - - /** - * Create grouped product. - * - * @since 3.0.0 - * @return WC_Product_Grouped - */ - public static function create_grouped_product() { - $simple_product_1 = self::create_simple_product(); - $simple_product_2 = self::create_simple_product(); - $product = new WC_Product_Grouped(); - $product->set_props( - array( - 'name' => 'Dummy Grouped Product', - 'sku' => 'DUMMY GROUPED SKU', - ) - ); - $product->set_children( array( $simple_product_1->get_id(), $simple_product_2->get_id() ) ); - $product->save(); - - return \wc_get_product( $product->get_id() ); - } - - /** - * Create a dummy variation product. - * - * @since 2.3 - * - * @return WC_Product_Variable - */ - public static function create_variation_product() { - $product = new WC_Product_Variable(); - $product->set_props( - array( - 'name' => 'Dummy Variable Product', - 'sku' => 'DUMMY VARIABLE SKU', - ) - ); - - $attribute_data = self::create_attribute( 'size', array( 'small', 'large' ) ); // Create all attribute related things. - $attributes = array(); - $attribute = new WC_Product_Attribute(); - $attribute->set_id( $attribute_data['attribute_id'] ); - $attribute->set_name( $attribute_data['attribute_taxonomy'] ); - $attribute->set_options( $attribute_data['term_ids'] ); - $attribute->set_position( 1 ); - $attribute->set_visible( true ); - $attribute->set_variation( true ); - $attributes[] = $attribute; - - $product->set_attributes( $attributes ); - $product->save(); - - $variation_1 = new WC_Product_Variation(); - $variation_1->set_props( - array( - 'parent_id' => $product->get_id(), - 'sku' => 'DUMMY SKU VARIABLE SMALL', - 'regular_price' => 10, - ) - ); - $variation_1->set_attributes( array( 'pa_size' => 'small' ) ); - $variation_1->save(); - - $variation_2 = new WC_Product_Variation(); - $variation_2->set_props( - array( - 'parent_id' => $product->get_id(), - 'sku' => 'DUMMY SKU VARIABLE LARGE', - 'regular_price' => 15, - ) - ); - $variation_2->set_attributes( array( 'pa_size' => 'large' ) ); - $variation_2->save(); - - return \wc_get_product( $product->get_id() ); - } - - /** - * Create a dummy attribute. - * - * @since 2.3 - * - * @param string $raw_name Name of attribute to create. - * @param array(string) $terms Terms to create for the attribute. - * @return array - */ - public static function create_attribute( $raw_name = 'size', $terms = array( 'small' ) ) { - global $wpdb, $wc_product_attributes; - - // Make sure caches are clean. - \delete_transient( 'wc_attribute_taxonomies' ); - if ( method_exists( '\WC_Cache_Helper', 'invalidate_cache_group' ) ) { - \WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' ); - } else { - \WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' ); - } - - // These are exported as labels, so convert the label to a name if possible first. - $attribute_labels = \wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' ); - $attribute_name = \array_search( $raw_name, $attribute_labels, true ); - - if ( ! $attribute_name ) { - $attribute_name = \wc_sanitize_taxonomy_name( $raw_name ); - } - - $attribute_id = \wc_attribute_taxonomy_id_by_name( $attribute_name ); - - if ( ! $attribute_id ) { - $taxonomy_name = \wc_attribute_taxonomy_name( $attribute_name ); - - // Degister taxonomy which other tests may have created... - \unregister_taxonomy( $taxonomy_name ); - - $attribute_id = \wc_create_attribute( - array( - 'name' => $raw_name, - 'slug' => $attribute_name, - 'type' => 'select', - 'order_by' => 'menu_order', - 'has_archives' => 0, - ) - ); - - // Register as taxonomy. - \register_taxonomy( - $taxonomy_name, - apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, array( 'product' ) ), - apply_filters( - 'woocommerce_taxonomy_args_' . $taxonomy_name, - array( - 'labels' => array( - 'name' => $raw_name, - ), - 'hierarchical' => false, - 'show_ui' => false, - 'query_var' => true, - 'rewrite' => false, - ) - ) - ); - - // Set product attributes global. - $wc_product_attributes = array(); - - foreach ( \wc_get_attribute_taxonomies() as $taxonomy ) { - $wc_product_attributes[ \wc_attribute_taxonomy_name( $taxonomy->attribute_name ) ] = $taxonomy; - } - } - - $attribute = \wc_get_attribute( $attribute_id ); - $return = array( - 'attribute_name' => $attribute->name, - 'attribute_taxonomy' => $attribute->slug, - 'attribute_id' => $attribute_id, - 'term_ids' => array(), - ); - - foreach ( $terms as $term ) { - $result = \term_exists( $term, $attribute->slug ); - - if ( ! $result ) { - $result = wp_insert_term( $term, $attribute->slug ); - $return['term_ids'][] = $result['term_id']; - } else { - $return['term_ids'][] = $result['term_id']; - } - } - - return $return; - } - - /** - * Delete an attribute. - * - * @param int $attribute_id ID to delete. - * - * @since 2.3 - */ - public static function delete_attribute( $attribute_id ) { - global $wpdb; - - $attribute_id = \absint( $attribute_id ); - - $wpdb->query( - $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = %d", $attribute_id ) - ); - } - - /** - * Creates a new product review on a specific product. - * - * @since 3.0 - * @param int $product_id integer Product ID that the review is for. - * @param string $review_content string Content to use for the product review. - * @return integer Product Review ID. - */ - public static function create_product_review( $product_id, $review_content = 'Review content here' ) { - $data = array( - 'comment_post_ID' => $product_id, - 'comment_author' => 'admin', - 'comment_author_email' => 'woo@woo.local', - 'comment_author_url' => '', - 'comment_date' => '2016-01-01T11:11:11', - 'comment_content' => $review_content, - 'comment_approved' => 1, - 'comment_type' => 'review', - ); - return \wp_insert_comment( $data ); - } - - /** - * A helper function for hooking into save_post during the test_product_meta_save_post test. - * @since 3.0.1 - * - * @param int $id ID to update. - */ - public static function save_post_test_update_meta_data_direct( $id ) { - \update_post_meta( $id, '_test2', 'world' ); - } -} diff --git a/unit-tests/Helpers/QueueHelper.php b/unit-tests/Helpers/QueueHelper.php deleted file mode 100644 index b0afec4c6fd..00000000000 --- a/unit-tests/Helpers/QueueHelper.php +++ /dev/null @@ -1,62 +0,0 @@ -queue()->search( - array( - 'per_page' => -1, - 'status' => 'pending', - 'claimed' => false, - ) - ); - - return $jobs; - } - - /** - * Run all pending queued actions. - * - * @return void - */ - public static function run_all_pending() { - $jobs = self::get_all_pending(); - - foreach ( $jobs as $job ) { - $job->execute(); - } - } - - /** - * Run all pending queued actions. - * - * @return void - */ - public static function process_pending() { - $jobs = self::get_all_pending(); - - $queue_runner = new \ActionScheduler_QueueRunner(); - foreach ( $jobs as $job_id => $job ) { - $queue_runner->process_action( $job_id ); - } - } -} diff --git a/unit-tests/Helpers/SettingsHelper.php b/unit-tests/Helpers/SettingsHelper.php deleted file mode 100644 index d7a8efd979d..00000000000 --- a/unit-tests/Helpers/SettingsHelper.php +++ /dev/null @@ -1,82 +0,0 @@ - 'test', - 'bad' => 'value', - 'label' => 'Test extension', - 'description' => 'My awesome test settings.', - 'option_key' => '', - ); - $groups[] = array( - 'id' => 'sub-test', - 'parent_id' => 'test', - 'label' => 'Sub test', - 'description' => '', - 'option_key' => '', - ); - $groups[] = array( - 'id' => 'coupon-data', - 'label' => 'Coupon data', - 'option_key' => '', - ); - $groups[] = array( - 'id' => 'invalid', - 'option_key' => '', - ); - return $groups; - } - - /** - * Registers some example settings. - * - * @since 3.0.0 - * @param array $settings - * @return array - */ - public static function register_test_settings( $settings ) { - $settings[] = array( - 'id' => 'woocommerce_shop_page_display', - 'label' => 'Shop page display', - 'description' => 'This controls what is shown on the product archive.', - 'default' => '', - 'type' => 'select', - 'options' => array( - '' => 'Show products', - 'subcategories' => 'Show categories & subcategories', - 'both' => 'Show both', - ), - 'option_key' => 'woocommerce_shop_page_display', - ); - return $settings; - } -} diff --git a/unit-tests/Helpers/ShippingHelper.php b/unit-tests/Helpers/ShippingHelper.php deleted file mode 100644 index 04d17e4274c..00000000000 --- a/unit-tests/Helpers/ShippingHelper.php +++ /dev/null @@ -1,50 +0,0 @@ - 'yes', - 'title' => 'Flat rate', - 'availability' => 'all', - 'countries' => '', - 'tax_status' => 'taxable', - 'cost' => '10', - ); - - update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings ); - update_option( 'woocommerce_flat_rate', array() ); - WC_Cache_Helper::get_transient_version( 'shipping', true ); - WC()->shipping()->load_shipping_methods(); - } - - /** - * Delete the simple flat rate. - * - * @since 2.3 - */ - public static function delete_simple_flat_rate() { - delete_option( 'woocommerce_flat_rate_settings' ); - delete_option( 'woocommerce_flat_rate' ); - WC_Cache_Helper::get_transient_version( 'shipping', true ); - WC()->shipping()->unregister_shipping_methods(); - } -} diff --git a/unit-tests/Tests/Version2/coupons.php b/unit-tests/Tests/Version2/coupons.php deleted file mode 100644 index 8c4d6024d70..00000000000 --- a/unit-tests/Tests/Version2/coupons.php +++ /dev/null @@ -1,471 +0,0 @@ -endpoint = new WC_REST_Coupons_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/coupons', $routes ); - $this->assertArrayHasKey( '/wc/v2/coupons/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v2/coupons/batch', $routes ); - } - - /** - * Test getting coupons. - * @since 3.0.0 - */ - public function test_get_coupons() { - wp_set_current_user( $this->user ); - - $coupon_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post_1 = get_post( $coupon_1->get_id() ); - $coupon_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons' ) ); - $coupons = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $coupons ) ); - $this->assertContains( - array( - 'id' => $coupon_1->get_id(), - 'code' => 'dummycoupon-1', - 'amount' => '1.00', - 'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ), - 'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ), - 'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ), - 'discount_type' => 'fixed_cart', - 'description' => 'This is a dummy coupon', - 'date_expires' => '', - 'date_expires_gmt' => '', - 'usage_count' => 0, - 'individual_use' => false, - 'product_ids' => array(), - 'excluded_product_ids' => array(), - 'usage_limit' => '', - 'usage_limit_per_user' => '', - 'limit_usage_to_x_items' => null, - 'free_shipping' => false, - 'product_categories' => array(), - 'excluded_product_categories' => array(), - 'exclude_sale_items' => false, - 'minimum_amount' => '0.00', - 'maximum_amount' => '0.00', - 'email_restrictions' => array(), - 'used_by' => array(), - 'meta_data' => array(), - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/coupons/' . $coupon_1->get_id() ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/coupons' ), - ), - ), - ), - ), - $coupons - ); - } - - /** - * Test getting coupons without valid permissions. - * @since 3.0.0 - */ - public function test_get_coupons_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single coupon. - * @since 3.0.0 - */ - public function test_get_coupon() { - wp_set_current_user( $this->user ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post = get_post( $coupon->get_id() ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $coupon->get_id(), - 'code' => 'dummycoupon-1', - 'amount' => '1.00', - 'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ), - 'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ), - 'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ), - 'discount_type' => 'fixed_cart', - 'description' => 'This is a dummy coupon', - 'date_expires' => null, - 'date_expires_gmt' => null, - 'usage_count' => 0, - 'individual_use' => false, - 'product_ids' => array(), - 'excluded_product_ids' => array(), - 'usage_limit' => null, - 'usage_limit_per_user' => null, - 'limit_usage_to_x_items' => null, - 'free_shipping' => false, - 'product_categories' => array(), - 'excluded_product_categories' => array(), - 'exclude_sale_items' => false, - 'minimum_amount' => '0.00', - 'maximum_amount' => '0.00', - 'email_restrictions' => array(), - 'used_by' => array(), - 'meta_data' => array(), - ), - $data - ); - } - - /** - * Test getting a single coupon with an invalid ID. - * @since 3.0.0 - */ - public function test_get_coupon_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting a single coupon without valid permissions. - * @since 3.0.0 - */ - public function test_get_coupon_without_permission() { - wp_set_current_user( 0 ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test creating a single coupon. - * @since 3.0.0 - */ - public function test_create_coupon() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'POST', '/wc/v2/coupons' ); - $request->set_body_params( - array( - 'code' => 'test', - 'amount' => '5.00', - 'discount_type' => 'fixed_product', - 'description' => 'Test', - 'usage_limit' => 10, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'code' => 'test', - 'amount' => '5.00', - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'discount_type' => 'fixed_product', - 'description' => 'Test', - 'date_expires' => null, - 'date_expires_gmt' => null, - 'usage_count' => 0, - 'individual_use' => false, - 'product_ids' => array(), - 'excluded_product_ids' => array(), - 'usage_limit' => 10, - 'usage_limit_per_user' => null, - 'limit_usage_to_x_items' => null, - 'free_shipping' => false, - 'product_categories' => array(), - 'excluded_product_categories' => array(), - 'exclude_sale_items' => false, - 'minimum_amount' => '0.00', - 'maximum_amount' => '0.00', - 'email_restrictions' => array(), - 'used_by' => array(), - 'meta_data' => array(), - ), - $data - ); - } - - /** - * Test creating a single coupon with invalid fields. - * @since 3.0.0 - */ - public function test_create_coupon_invalid_fields() { - wp_set_current_user( $this->user ); - - // test no code... - $request = new WP_REST_Request( 'POST', '/wc/v2/coupons' ); - $request->set_body_params( - array( - 'amount' => '5.00', - 'discount_type' => 'fixed_product', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating a single coupon without valid permissions. - * @since 3.0.0 - */ - public function test_create_coupon_without_permission() { - wp_set_current_user( 0 ); - - // test no code... - $request = new WP_REST_Request( 'POST', '/wc/v2/coupons' ); - $request->set_body_params( - array( - 'code' => 'fail', - 'amount' => '5.00', - 'discount_type' => 'fixed_product', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single coupon. - * @since 3.0.0 - */ - public function test_update_coupon() { - wp_set_current_user( $this->user ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post = get_post( $coupon->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) ); - $data = $response->get_data(); - $this->assertEquals( 'This is a dummy coupon', $data['description'] ); - $this->assertEquals( 'fixed_cart', $data['discount_type'] ); - $this->assertEquals( '1.00', $data['amount'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() ); - $request->set_body_params( - array( - 'amount' => '10.00', - 'description' => 'New description', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '10.00', $data['amount'] ); - $this->assertEquals( 'New description', $data['description'] ); - $this->assertEquals( 'fixed_cart', $data['discount_type'] ); - } - - /** - * Test updating a single coupon with an invalid ID. - * @since 3.0.0 - */ - public function test_update_coupon_invalid_id() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/0' ); - $request->set_body_params( - array( - 'code' => 'tester', - 'amount' => '10.00', - 'description' => 'New description', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test updating a single coupon without valid permissions. - * @since 3.0.0 - */ - public function test_update_coupon_without_permission() { - wp_set_current_user( 0 ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post = get_post( $coupon->get_id() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() ); - $request->set_body_params( - array( - 'amount' => '10.00', - 'description' => 'New description', - ) - ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single coupon. - * @since 3.0.0 - */ - public function test_delete_coupon() { - wp_set_current_user( $this->user ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/' . $coupon->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a single coupon with an invalid ID. - * @since 3.0.0 - */ - public function test_delete_coupon_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test deleting a single coupon without valid permissions. - * @since 3.0.0 - */ - public function test_delete_coupon_without_permission() { - wp_set_current_user( 0 ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/' . $coupon->get_id() ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test batch operations on coupons. - * @since 3.0.0 - */ - public function test_batch_coupon() { - wp_set_current_user( $this->user ); - - $coupon_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $coupon_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' ); - $coupon_3 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-3' ); - $coupon_4 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-4' ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/coupons/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $coupon_1->get_id(), - 'amount' => '5.15', - ), - ), - 'delete' => array( - $coupon_2->get_id(), - $coupon_3->get_id(), - ), - 'create' => array( - array( - 'code' => 'new-coupon', - 'amount' => '11.00', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '5.15', $data['update'][0]['amount'] ); - $this->assertEquals( '11.00', $data['create'][0]['amount'] ); - $this->assertEquals( 'new-coupon', $data['create'][0]['code'] ); - $this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] ); - $this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v2/coupons' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test coupon schema. - * @since 3.0.0 - */ - public function test_coupon_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/coupons' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 27, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'code', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'date_modified', $properties ); - $this->assertArrayHasKey( 'date_modified_gmt', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'discount_type', $properties ); - $this->assertArrayHasKey( 'amount', $properties ); - $this->assertArrayHasKey( 'date_expires', $properties ); - $this->assertArrayHasKey( 'date_expires_gmt', $properties ); - $this->assertArrayHasKey( 'usage_count', $properties ); - $this->assertArrayHasKey( 'individual_use', $properties ); - $this->assertArrayHasKey( 'product_ids', $properties ); - $this->assertArrayHasKey( 'excluded_product_ids', $properties ); - $this->assertArrayHasKey( 'usage_limit', $properties ); - $this->assertArrayHasKey( 'usage_limit_per_user', $properties ); - $this->assertArrayHasKey( 'limit_usage_to_x_items', $properties ); - $this->assertArrayHasKey( 'free_shipping', $properties ); - $this->assertArrayHasKey( 'product_categories', $properties ); - $this->assertArrayHasKey( 'excluded_product_categories', $properties ); - $this->assertArrayHasKey( 'exclude_sale_items', $properties ); - $this->assertArrayHasKey( 'minimum_amount', $properties ); - $this->assertArrayHasKey( 'maximum_amount', $properties ); - $this->assertArrayHasKey( 'email_restrictions', $properties ); - $this->assertArrayHasKey( 'used_by', $properties ); - } -} diff --git a/unit-tests/Tests/Version2/customers.php b/unit-tests/Tests/Version2/customers.php deleted file mode 100644 index f9a4d5acca1..00000000000 --- a/unit-tests/Tests/Version2/customers.php +++ /dev/null @@ -1,566 +0,0 @@ -endpoint = new WC_REST_Customers_Controller(); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - - $this->assertArrayHasKey( '/wc/v2/customers', $routes ); - $this->assertArrayHasKey( '/wc/v2/customers/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v2/customers/batch', $routes ); - } - - /** - * Test getting customers. - * - * @since 3.0.0 - */ - public function test_get_customers() { - wp_set_current_user( 1 ); - - $customer_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer(); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test2', 'test2', 'test2@woo.local' ); - - $request = new WP_REST_Request( 'GET', '/wc/v2/customers' ); - $request->set_query_params( - array( - 'orderby' => 'id', - ) - ); - $response = $this->server->dispatch( $request ); - $customers = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $customers ) ); - - $this->assertContains( - array( - 'id' => $customer_1->get_id(), - 'date_created' => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ), - 'date_created_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_created() ), - 'date_modified' => wc_rest_prepare_date_response( $customer_1->get_date_modified(), false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_modified() ), - 'email' => 'test@woo.local', - 'first_name' => 'Justin', - 'last_name' => '', - 'role' => 'customer', - 'username' => 'testcustomer', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - ), - 'is_paying_customer' => false, - 'orders_count' => 0, - 'total_spent' => '0.00', - 'avatar_url' => $customer_1->get_avatar_url(), - 'meta_data' => array(), - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/customers/' . $customer_1->get_id() . '' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/customers' ), - ), - ), - ), - ), - $customers - ); - } - - /** - * Test getting customers without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_customers_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test creating a new customer. - * - * @since 3.0.0 - */ - public function test_create_customer() { - wp_set_current_user( 1 ); - - // Test just the basics first.. - $request = new WP_REST_Request( 'POST', '/wc/v2/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test', - 'password' => 'test123', - 'email' => 'create_customer_test@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'email' => 'create_customer_test@woo.local', - 'first_name' => '', - 'last_name' => '', - 'role' => 'customer', - 'username' => 'create_customer_test', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => '', - 'postcode' => '', - 'country' => '', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => '', - 'postcode' => '', - 'country' => '', - ), - 'is_paying_customer' => false, - 'meta_data' => array(), - 'orders_count' => 0, - 'total_spent' => '0.00', - 'avatar_url' => $data['avatar_url'], - ), - $data - ); - - // Test extra data - $request = new WP_REST_Request( 'POST', '/wc/v2/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test2', - 'password' => 'test123', - 'email' => 'create_customer_test2@woo.local', - 'first_name' => 'Test', - 'last_name' => 'McTestFace', - 'billing' => array( - 'country' => 'US', - 'state' => 'WA', - ), - 'shipping' => array( - 'state' => 'CA', - 'country' => 'US', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'email' => 'create_customer_test2@woo.local', - 'first_name' => 'Test', - 'last_name' => 'McTestFace', - 'role' => 'customer', - 'username' => 'create_customer_test2', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => 'WA', - 'postcode' => '', - 'country' => 'US', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => 'CA', - 'postcode' => '', - 'country' => 'US', - ), - 'is_paying_customer' => false, - 'meta_data' => array(), - 'orders_count' => 0, - 'total_spent' => '0.00', - 'avatar_url' => $data['avatar_url'], - ), - $data - ); - - // Test without required field - $request = new WP_REST_Request( 'POST', '/wc/v2/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test3', - 'first_name' => 'Test', - 'last_name' => 'McTestFace', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating customers without valid permissions. - * - * @since 3.0.0 - */ - public function test_create_customer_without_permission() { - wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'POST', '/wc/v2/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test_without_permission', - 'password' => 'test123', - 'email' => 'create_customer_test_without_permission@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single customer. - * - * @since 3.0.0 - */ - public function test_get_customer() { - wp_set_current_user( 1 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'get_customer_test', 'test123', 'get_customer_test@woo.local' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'email' => 'get_customer_test@woo.local', - 'first_name' => 'Justin', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - ), - 'is_paying_customer' => false, - 'meta_data' => array(), - 'last_name' => '', - 'role' => 'customer', - 'username' => 'get_customer_test', - 'orders_count' => 0, - 'total_spent' => '0.00', - 'avatar_url' => $data['avatar_url'], - ), - $data - ); - } - - /** - * Test getting a single customer without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_customer_without_permission() { - wp_set_current_user( 0 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'get_customer_test_without_permission', 'test123', 'get_customer_test_without_permission@woo.local' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single customer with an invalid ID. - * - * @since 3.0.0 - */ - public function test_get_customer_invalid_id() { - wp_set_current_user( 1 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test updating a customer. - * - * @since 3.0.0 - */ - public function test_update_customer() { - wp_set_current_user( 1 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'update_customer_test', 'test123', 'update_customer_test@woo.local' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) ); - $data = $response->get_data(); - $this->assertEquals( 'update_customer_test', $data['username'] ); - $this->assertEquals( 'update_customer_test@woo.local', $data['email'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/customers/' . $customer->get_id() ); - $request->set_body_params( - array( - 'email' => 'updated_email@woo.local', - 'first_name' => 'UpdatedTest', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'updated_email@woo.local', $data['email'] ); - $this->assertEquals( 'UpdatedTest', $data['first_name'] ); - } - - /** - * Test updating a customer without valid permissions. - * - * @since 3.0.0 - */ - public function test_update_customer_without_permission() { - wp_set_current_user( 0 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'update_customer_test_without_permission', 'test123', 'update_customer_test_without_permission@woo.local' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a customer with an invalid ID. - * - * @since 3.0.0 - */ - public function test_update_customer_invalid_id() { - wp_set_current_user( 1 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - - /** - * Test deleting a customer. - * - * @since 3.0.0 - */ - public function test_delete_customer() { - wp_set_current_user( 1 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'delete_customer_test', 'test123', 'delete_customer_test@woo.local' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/customers/' . $customer->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a customer with an invalid ID. - * - * @since 3.0.0 - */ - public function test_delete_customer_invalid_id() { - wp_set_current_user( 1 ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/customers/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test deleting a customer without valid permissions. - * - * @since 3.0.0 - */ - public function test_delete_customer_without_permission() { - wp_set_current_user( 0 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'delete_customer_test_without_permission', 'test123', 'delete_customer_test_without_permission@woo.local' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/customers/' . $customer->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test customer batch endpoint. - * - * @since 3.0.0 - */ - public function test_batch_customer() { - wp_set_current_user( 1 ); - - $customer_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer', 'test123', 'test_batch_customer@woo.local' ); - $customer_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer2', 'test123', 'test_batch_customer2@woo.local' ); - $customer_3 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer3', 'test123', 'test_batch_customer3@woo.local' ); - $customer_4 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer4', 'test123', 'test_batch_customer4@woo.local' ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/customers/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $customer_1->get_id(), - 'last_name' => 'McTest', - ), - ), - 'delete' => array( - $customer_2->get_id(), - $customer_3->get_id(), - ), - 'create' => array( - array( - 'username' => 'newuser', - 'password' => 'test123', - 'email' => 'newuser@woo.local', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'McTest', $data['update'][0]['last_name'] ); - $this->assertEquals( 'newuser', $data['create'][0]['username'] ); - $this->assertEmpty( $data['create'][0]['last_name'] ); - $this->assertEquals( $customer_2->get_id(), $data['delete'][0]['id'] ); - $this->assertEquals( $customer_3->get_id(), $data['delete'][1]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v2/customers' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test customer schema. - * - * @since 3.0.0 - */ - public function test_customer_schema() { - wp_set_current_user( 1 ); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/customers' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 18, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'date_modified', $properties ); - $this->assertArrayHasKey( 'date_modified_gmt', $properties ); - $this->assertArrayHasKey( 'email', $properties ); - $this->assertArrayHasKey( 'first_name', $properties ); - $this->assertArrayHasKey( 'last_name', $properties ); - $this->assertArrayHasKey( 'role', $properties ); - $this->assertArrayHasKey( 'username', $properties ); - $this->assertArrayHasKey( 'password', $properties ); - $this->assertArrayHasKey( 'orders_count', $properties ); - $this->assertArrayHasKey( 'total_spent', $properties ); - $this->assertArrayHasKey( 'avatar_url', $properties ); - $this->assertArrayHasKey( 'billing', $properties ); - $this->assertArrayHasKey( 'first_name', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'last_name', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'company', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'address_1', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'address_2', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'city', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'state', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'postcode', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'country', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'email', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'phone', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'shipping', $properties ); - $this->assertArrayHasKey( 'first_name', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'last_name', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'company', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'address_1', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'address_2', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'city', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'state', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'postcode', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'country', $properties['shipping']['properties'] ); - } -} diff --git a/unit-tests/Tests/Version2/orders.php b/unit-tests/Tests/Version2/orders.php deleted file mode 100644 index e80fbab5fb8..00000000000 --- a/unit-tests/Tests/Version2/orders.php +++ /dev/null @@ -1,721 +0,0 @@ -endpoint = new WC_REST_Orders_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/orders', $routes ); - $this->assertArrayHasKey( '/wc/v2/orders/batch', $routes ); - $this->assertArrayHasKey( '/wc/v2/orders/(?P[\d]+)', $routes ); - } - - /** - * Test getting all orders. - * @since 3.0.0 - */ - public function test_get_items() { - wp_set_current_user( $this->user ); - - // Create 10 orders. - for ( $i = 0; $i < 10; $i++ ) { - $this->orders[] = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $this->user ); - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders' ) ); - $orders = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 10, count( $orders ) ); - } - - /** - * Tests to make sure orders cannot be viewed without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_items_without_permission() { - wp_set_current_user( 0 ); - $this->orders[] = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a single order. - * @since 3.0.0 - */ - public function test_get_item() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order->add_meta_data( 'key', 'value' ); - $order->add_meta_data( 'key2', 'value2' ); - $order->save(); - $this->orders[] = $order; - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $order->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $order->get_id(), $data['id'] ); - - // Test meta data is set. - $this->assertEquals( 'key', $data['meta_data'][0]->key ); - $this->assertEquals( 'value', $data['meta_data'][0]->value ); - $this->assertEquals( 'key2', $data['meta_data'][1]->key ); - $this->assertEquals( 'value2', $data['meta_data'][1]->value ); - } - - /** - * Tests getting a single order without the correct permissions. - * @since 3.0.0 - */ - public function test_get_item_without_permission() { - wp_set_current_user( 0 ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $this->orders[] = $order; - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $order->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting an order with an invalid ID. - * @since 3.0.0 - */ - public function test_get_item_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/99999999' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests getting an order with an invalid ID. - * @since 3.5.0 - */ - public function test_get_item_refund_id() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $refund = wc_create_refund( - array( - 'order_id' => $order->get_id(), - ) - ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $refund->get_id() ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests creating an order. - * @since 3.0.0 - */ - public function test_create_order() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v2/orders' ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => 'Direct Bank Transfer', - 'set_paid' => true, - 'billing' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - 'email' => 'john.doe@example.com', - 'phone' => '(555) 555-5555', - ), - 'shipping' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - ), - 'line_items' => array( - array( - 'product_id' => $product->get_id(), - 'quantity' => 2, - ), - ), - 'shipping_lines' => array( - array( - 'method_id' => 'flat_rate', - 'method_title' => 'Flat rate', - 'total' => '10.00', - 'instance_id' => '1', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $order = wc_get_order( $data['id'] ); - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); - $this->assertEquals( $order->get_payment_method_title(), $data['payment_method_title'] ); - $this->assertEquals( $order->get_billing_first_name(), $data['billing']['first_name'] ); - $this->assertEquals( $order->get_billing_last_name(), $data['billing']['last_name'] ); - $this->assertEquals( '', $data['billing']['company'] ); - $this->assertEquals( $order->get_billing_address_1(), $data['billing']['address_1'] ); - $this->assertEquals( $order->get_billing_address_2(), $data['billing']['address_2'] ); - $this->assertEquals( $order->get_billing_city(), $data['billing']['city'] ); - $this->assertEquals( $order->get_billing_state(), $data['billing']['state'] ); - $this->assertEquals( $order->get_billing_postcode(), $data['billing']['postcode'] ); - $this->assertEquals( $order->get_billing_country(), $data['billing']['country'] ); - $this->assertEquals( $order->get_billing_email(), $data['billing']['email'] ); - $this->assertEquals( $order->get_billing_phone(), $data['billing']['phone'] ); - $this->assertEquals( $order->get_shipping_first_name(), $data['shipping']['first_name'] ); - $this->assertEquals( $order->get_shipping_last_name(), $data['shipping']['last_name'] ); - $this->assertEquals( '', $data['shipping']['company'] ); - $this->assertEquals( $order->get_shipping_address_1(), $data['shipping']['address_1'] ); - $this->assertEquals( $order->get_shipping_address_2(), $data['shipping']['address_2'] ); - $this->assertEquals( $order->get_shipping_city(), $data['shipping']['city'] ); - $this->assertEquals( $order->get_shipping_state(), $data['shipping']['state'] ); - $this->assertEquals( $order->get_shipping_postcode(), $data['shipping']['postcode'] ); - $this->assertEquals( $order->get_shipping_country(), $data['shipping']['country'] ); - $this->assertEquals( 1, count( $data['line_items'] ) ); - $this->assertEquals( 1, count( $data['shipping_lines'] ) ); - $shipping = current( $order->get_items( 'shipping' ) ); - $expected = array( - 'id' => $shipping->get_id(), - 'method_title' => $shipping->get_method_title(), - 'method_id' => $shipping->get_method_id(), - 'instance_id' => $shipping->get_instance_id(), - 'total' => wc_format_decimal( $shipping->get_total(), '' ), - 'total_tax' => wc_format_decimal( $shipping->get_total_tax(), '' ), - 'taxes' => array(), - 'meta_data' => $shipping->get_meta_data(), - ); - $this->assertEquals( $expected, $data['shipping_lines'][0] ); - } - - /** - * Test the sanitization of the payment_method_title field through the API. - * - * @since 3.5.2 - */ - public function test_create_update_order_payment_method_title_sanitize() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - // Test when creating order. - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => '

Sanitize this

', - 'set_paid' => true, - 'billing' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - 'email' => 'john.doe@example.com', - 'phone' => '(555) 555-5555', - ), - 'shipping' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - ), - 'line_items' => array( - array( - 'product_id' => $product->get_id(), - 'quantity' => 2, - ), - ), - 'shipping_lines' => array( - array( - 'method_id' => 'flat_rate', - 'method_title' => 'Flat rate', - 'total' => '10', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $order = wc_get_order( $data['id'] ); - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); - $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this' ); - - // Test when updating order. - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $data['id'] ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => '

Sanitize this too

', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $order = wc_get_order( $data['id'] ); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); - $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this too' ); - } - - /** - * Tests creating an order without required fields. - * @since 3.0.0 - */ - public function test_create_order_invalid_fields() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - // non-existent customer - $request = new WP_REST_Request( 'POST', '/wc/v2/orders' ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => 'Direct Bank Transfer', - 'set_paid' => true, - 'customer_id' => 99999, - 'billing' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - 'email' => 'john.doe@example.com', - 'phone' => '(555) 555-5555', - ), - 'shipping' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - ), - 'line_items' => array( - array( - 'product_id' => $product->get_id(), - 'quantity' => 2, - ), - ), - 'shipping_lines' => array( - array( - 'method_id' => 'flat_rate', - 'method_title' => 'Flat rate', - 'total' => 10, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests create an order with an invalid product. - * - * @since 3.9.0 - */ - public function test_create_order_with_invalid_product() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/orders' ); - $request->set_body_params( - array( - 'line_items' => array( - array( - 'quantity' => 2, - ), - ), - ) - ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'woocommerce_rest_required_product_reference', $data['code'] ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests updating an order. - * - * @since 3.0.0 - */ - public function test_update_order() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() ); - $request->set_body_params( - array( - 'payment_method' => 'test-update', - 'billing' => array( - 'first_name' => 'Fish', - 'last_name' => 'Face', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'test-update', $data['payment_method'] ); - $this->assertEquals( 'Fish', $data['billing']['first_name'] ); - $this->assertEquals( 'Face', $data['billing']['last_name'] ); - } - - /** - * Tests updating an order and removing items. - * - * @since 3.0.0 - */ - public function test_update_order_remove_items() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $fee = new WC_Order_Item_Fee(); - $fee->set_props( - array( - 'name' => 'Some Fee', - 'tax_status' => 'taxable', - 'total' => '100', - 'tax_class' => '', - ) - ); - $order->add_item( $fee ); - $order->save(); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() ); - $fee_data = current( $order->get_items( 'fee' ) ); - - $request->set_body_params( - array( - 'fee_lines' => array( - array( - 'id' => $fee_data->get_id(), - 'name' => null, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertTrue( empty( $data['fee_lines'] ) ); - } - - /** - * Tests updating an order after deleting a product. - * - * @since 3.9.0 - */ - public function test_update_order_after_delete_product() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( 1, $product ); - $product->delete( true ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() ); - $line_items = $order->get_items( 'line_item' ); - $item = current( $line_items ); - - $request->set_body_params( - array( - 'line_items' => array( - array( - 'id' => $item->get_id(), - 'quantity' => 10, - ), - ), - ) - ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $expected = array( - 'id' => $item->get_id(), - 'name' => 'Dummy Product', - 'product_id' => 0, - 'variation_id' => 0, - 'quantity' => 10, - 'tax_class' => '', - 'subtotal' => '40.00', - 'subtotal_tax' => '0.00', - 'total' => '40.00', - 'total_tax' => '0.00', - 'taxes' => array(), - 'meta_data' => array(), - 'sku' => null, - 'price' => 4, - ); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $expected, $data['line_items'][0] ); - } - - /** - * Tests updating an order and adding a coupon. - * - * @since 3.3.0 - */ - public function test_update_order_add_coupons() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order_item = current( $order->get_items() ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' ); - $coupon->set_amount( 5 ); - $coupon->save(); - $request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() ); - $request->set_body_params( - array( - 'coupon_lines' => array( - array( - 'code' => 'fake-coupon', - 'discount_total' => '5', - 'discount_tax' => '0', - ), - ), - 'line_items' => array( - array( - 'id' => $order_item->get_id(), - 'product_id' => $order_item->get_product_id(), - 'total' => '35.00', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertCount( 1, $data['coupon_lines'] ); - $this->assertEquals( '45.00', $data['total'] ); - } - - /** - * Tests updating an order and removing a coupon. - * - * @since 3.3.0 - */ - public function test_update_order_remove_coupons() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order_item = current( $order->get_items() ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' ); - $coupon->set_amount( 5 ); - $coupon->save(); - - $order->apply_coupon( $coupon ); - $order->save(); - - // Check that the coupon is applied. - $this->assertEquals( '45.00', $order->get_total() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() ); - $coupon_data = current( $order->get_items( 'coupon' ) ); - - $request->set_body_params( - array( - 'coupon_lines' => array( - array( - 'id' => $coupon_data->get_id(), - 'code' => null, - ), - ), - 'line_items' => array( - array( - 'id' => $order_item->get_id(), - 'product_id' => $order_item->get_product_id(), - 'total' => '40.00', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertTrue( empty( $data['coupon_lines'] ) ); - $this->assertEquals( '50.00', $data['total'] ); - } - - /** - * Tests updating an order without the correct permissions. - * - * @since 3.0.0 - */ - public function test_update_order_without_permission() { - wp_set_current_user( 0 ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() ); - $request->set_body_params( - array( - 'payment_method' => 'test-update', - 'billing' => array( - 'first_name' => 'Fish', - 'last_name' => 'Face', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests that updating an order with an invalid id fails. - * @since 3.0.0 - */ - public function test_update_order_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'POST', '/wc/v2/orders/999999' ); - $request->set_body_params( - array( - 'payment_method' => 'test-update', - 'billing' => array( - 'first_name' => 'Fish', - 'last_name' => 'Face', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test deleting an order. - * @since 3.0.0 - */ - public function test_delete_order() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/orders/' . $order->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( null, get_post( $order->get_id() ) ); - } - - /** - * Test deleting an order without permission/creds. - * @since 3.0.0 - */ - public function test_delete_order_without_permission() { - wp_set_current_user( 0 ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/orders/' . $order->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting an order with an invalid id. - * - * @since 3.0.0 - */ - public function test_delete_order_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/orders/9999999' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test batch managing product reviews. - */ - public function test_orders_batch() { - wp_set_current_user( $this->user ); - - $order1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order3 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - - $request = new WP_REST_Request( 'POST', '/wc/v2/orders/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $order1->get_id(), - 'payment_method' => 'updated', - ), - ), - 'delete' => array( - $order2->get_id(), - $order3->get_id(), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'updated', $data['update'][0]['payment_method'] ); - $this->assertEquals( $order2->get_id(), $data['delete'][0]['id'] ); - $this->assertEquals( $order3->get_id(), $data['delete'][1]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v2/orders' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 1, count( $data ) ); - } - - /** - * Test the order schema. - * @since 3.0.0 - */ - public function test_order_schema() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/orders/' . $order->get_id() ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 42, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - } -} diff --git a/unit-tests/Tests/Version2/payment-gateways.php b/unit-tests/Tests/Version2/payment-gateways.php deleted file mode 100644 index d8757c5d31d..00000000000 --- a/unit-tests/Tests/Version2/payment-gateways.php +++ /dev/null @@ -1,337 +0,0 @@ -endpoint = new WC_REST_Payment_Gateways_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/payment_gateways', $routes ); - $this->assertArrayHasKey( '/wc/v2/payment_gateways/(?P[\w-]+)', $routes ); - } - - /** - * Test getting all payment gateways. - * - * @since 3.0.0 - */ - public function test_get_payment_gateways() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/payment_gateways' ) ); - $gateways = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertContains( - array( - 'id' => 'cheque', - 'title' => 'Check payments', - 'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', - 'order' => '', - 'enabled' => false, - 'method_title' => 'Check payments', - 'method_description' => 'Take payments in person via checks. This offline gateway can also be useful to test purchases.', - 'settings' => array_diff_key( - $this->get_settings( 'WC_Gateway_Cheque' ), - array( - 'enabled' => false, - 'description' => false, - ) - ), - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/payment_gateways/cheque' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/payment_gateways' ), - ), - ), - ), - ), - $gateways - ); - } - - /** - * Tests to make sure payment gateways cannot viewed without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_payment_gateways_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/payment_gateways' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single payment gateway. - * - * @since 3.0.0 - */ - public function test_get_payment_gateway() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/payment_gateways/paypal' ) ); - $paypal = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => 'paypal', - 'title' => 'PayPal', - 'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.", - 'order' => '', - 'enabled' => false, - 'method_title' => 'PayPal', - 'method_description' => 'PayPal Standard redirects customers to PayPal to enter their payment information.', - 'settings' => array_diff_key( - $this->get_settings( 'WC_Gateway_Paypal' ), - array( - 'enabled' => false, - 'description' => false, - ) - ), - ), - $paypal - ); - } - - /** - * Test getting a payment gateway without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_payment_gateway_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/payment_gateways/paypal' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a payment gateway with an invalid id. - * - * @since 3.0.0 - */ - public function test_get_payment_gateway_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/payment_gateways/totally_fake_method' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test updating a single payment gateway. - * - * @since 3.0.0 - */ - public function test_update_payment_gateway() { - wp_set_current_user( $this->user ); - - // Test defaults - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/payment_gateways/paypal' ) ); - $paypal = $response->get_data(); - - $this->assertEquals( 'PayPal', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'admin@example.org', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'no', $paypal['settings']['testmode']['value'] ); - - // test updating single setting - $request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'email' => 'woo@woo.local', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'PayPal', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'woo@woo.local', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'no', $paypal['settings']['testmode']['value'] ); - - // test updating multiple settings - $request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'testmode' => 'yes', - 'title' => 'PayPal - New Title', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'PayPal - New Title', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'woo@woo.local', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'yes', $paypal['settings']['testmode']['value'] ); - - // Test other parameters, and recheck settings - $request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'enabled' => false, - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - - $this->assertFalse( $paypal['enabled'] ); - $this->assertEquals( 2, $paypal['order'] ); - $this->assertEquals( 'PayPal - New Title', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'woo@woo.local', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'yes', $paypal['settings']['testmode']['value'] ); - - // test bogus - $request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'paymentaction' => 'afasfasf', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'paymentaction' => 'authorization', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - $this->assertEquals( 'authorization', $paypal['settings']['paymentaction']['value'] ); - } - - /** - * Test updating a payment gateway without valid permissions. - * - * @since 3.0.0 - */ - public function test_update_payment_gateway_without_permission() { - wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'testmode' => 'yes', - 'title' => 'PayPal - New Title', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a payment gateway with an invalid id. - * - * @since 3.0.0 - */ - public function test_update_payment_gateway_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/totally_fake_method' ); - $request->set_body_params( - array( - 'enabled' => true, - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test the payment gateway schema. - * - * @since 3.0.0 - */ - public function test_payment_gateway_schema() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/payment_gateways' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 8, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'title', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'order', $properties ); - $this->assertArrayHasKey( 'enabled', $properties ); - $this->assertArrayHasKey( 'method_title', $properties ); - $this->assertArrayHasKey( 'method_description', $properties ); - $this->assertArrayHasKey( 'settings', $properties ); - } - - /** - * Loads a particular gateway's settings so we can correctly test API output. - * - * @since 3.0.0 - * @param string $gateway_class Name of WC_Payment_Gateway class. - */ - private function get_settings( $gateway_class ) { - $gateway = new $gateway_class(); - $settings = array(); - $gateway->init_form_fields(); - foreach ( $gateway->form_fields as $id => $field ) { - // Make sure we at least have a title and type - if ( empty( $field['title'] ) || empty( $field['type'] ) ) { - continue; - } - // Ignore 'title' settings/fields -- they are UI only - if ( 'title' === $field['type'] ) { - continue; - } - $data = array( - 'id' => $id, - 'label' => empty( $field['label'] ) ? $field['title'] : $field['label'], - 'description' => empty( $field['description'] ) ? '' : $field['description'], - 'type' => $field['type'], - 'value' => $gateway->settings[ $id ], - 'default' => empty( $field['default'] ) ? '' : $field['default'], - 'tip' => empty( $field['description'] ) ? '' : $field['description'], - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], - ); - if ( ! empty( $field['options'] ) ) { - $data['options'] = $field['options']; - } - $settings[ $id ] = $data; - } - return $settings; - } - -} diff --git a/unit-tests/Tests/Version2/product-reviews.php b/unit-tests/Tests/Version2/product-reviews.php deleted file mode 100644 index 57f8804c1c9..00000000000 --- a/unit-tests/Tests/Version2/product-reviews.php +++ /dev/null @@ -1,468 +0,0 @@ -user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/products/reviews', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/reviews/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/reviews/batch', $routes ); - } - - /** - * Test getting all product reviews. - * - * @since 3.0.0 - */ - public function test_get_product_reviews() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - // Create 10 products reviews for the product - for ( $i = 0; $i < 10; $i++ ) { - $review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); - $product_reviews = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 10, count( $product_reviews ) ); - $this->assertContains( - array( - 'id' => $review_id, - 'date_created' => $product_reviews[0]['date_created'], - 'date_created_gmt' => $product_reviews[0]['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => "

Review content here

\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $product_reviews[0]['reviewer_avatar_urls'], - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews/' . $review_id ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews' ), - ), - ), - 'up' => array( - array( - 'href' => rest_url( '/wc/v3/products/' . $product->get_id() ), - ), - ), - ), - ), - $product_reviews - ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_product_reviews_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests to make sure an error is returned when an invalid product is loaded. - * - * @since 3.0.0 - */ - public function test_get_product_reviews_invalid_product() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/0/reviews' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests getting a single product review. - * - * @since 3.0.0 - */ - public function test_get_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $product_review_id, - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => "

Review content here

\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests getting a single product review without the correct permissions. - * - * @since 3.0.0 - */ - public function test_get_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a product review with an invalid ID. - * - * @since 3.0.0 - */ - public function test_get_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests creating a product review. - * - * @since 3.0.0 - */ - public function test_create_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'rating' => '5', - 'product_id' => $product->get_id(), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => 'Hello world.', - 'rating' => 5, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests creating a product review without required fields. - * - * @since 3.0.0 - */ - public function test_create_product_review_invalid_fields() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - // missing review - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // Missing reviewer. - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // missing reviewer_email - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests updating a product review. - * - * @since 3.0.0 - */ - public function test_update_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - $this->assertEquals( "

Review content here

\n", $data['review'] ); - $this->assertEquals( 'admin', $data['reviewer'] ); - $this->assertEquals( 'woo@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 0, $data['rating'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world - updated.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo2@woo.local', - 'rating' => 3, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'Hello world - updated.', $data['review'] ); - $this->assertEquals( 'Justin', $data['reviewer'] ); - $this->assertEquals( 'woo2@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 3, $data['rating'] ); - } - - /** - * Tests updating a product review without the correct permissions. - * - * @since 3.0.0 - */ - public function test_update_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests that updating a product review with an invalid id fails. - * - * @since 3.0.0 - */ - public function test_update_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/0' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test deleting a product review. - * - * @since 3.0.0 - */ - public function test_delete_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a product review without permission/creds. - * - * @since 3.0.0 - */ - public function test_delete_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a product review with an invalid id. - * - * @since 3.0.0 - */ - public function test_delete_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test batch managing product reviews. - */ - public function test_product_reviews_batch() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - $review_1_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $review_2_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $review_3_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $review_4_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $review_1_id, - 'review' => 'Updated review.', - ), - ), - 'delete' => array( - $review_2_id, - $review_3_id, - ), - 'create' => array( - array( - 'review' => 'New review.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo3@woo.local', - 'product_id' => $product->get_id(), - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'Updated review.', $data['update'][0]['review'] ); - $this->assertEquals( 'New review.', $data['create'][0]['review'] ); - $this->assertEquals( $review_2_id, $data['delete'][0]['previous']['id'] ); - $this->assertEquals( $review_3_id, $data['delete'][1]['previous']['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ); - $request->set_param( 'product', $product->get_id() ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test the product review schema. - * - * @since 3.0.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/reviews' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 11, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'product_id', $properties ); - $this->assertArrayHasKey( 'status', $properties ); - $this->assertArrayHasKey( 'reviewer', $properties ); - $this->assertArrayHasKey( 'reviewer_email', $properties ); - $this->assertArrayHasKey( 'review', $properties ); - $this->assertArrayHasKey( 'rating', $properties ); - $this->assertArrayHasKey( 'verified', $properties ); - - if ( get_option( 'show_avatars' ) ) { - $this->assertArrayHasKey( 'reviewer_avatar_urls', $properties ); - } - } -} diff --git a/unit-tests/Tests/Version2/product-variations.php b/unit-tests/Tests/Version2/product-variations.php deleted file mode 100644 index 22a53d4d829..00000000000 --- a/unit-tests/Tests/Version2/product-variations.php +++ /dev/null @@ -1,495 +0,0 @@ -endpoint = new WC_REST_Product_Variations_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/products/(?P[\d]+)/variations', $routes ); - $this->assertArrayHasKey( '/wc/v2/products/(?P[\d]+)/variations/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v2/products/(?P[\d]+)/variations/batch', $routes ); - } - - /** - * Test getting variations. - * - * @since 3.0.0 - */ - public function test_get_variations() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $variations ) ); - $this->assertEquals( 'DUMMY SKU VARIABLE LARGE', $variations[0]['sku'] ); - $this->assertEquals( 'size', $variations[0]['attributes'][0]['name'] ); - } - - /** - * Test getting variations with an orderby clause. - * - * @since 3.9.0 - */ - public function test_get_variations_with_orderby() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $request = new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ); - $request->set_query_params( array( 'orderby' => 'menu_order' ) ); - $response = $this->server->dispatch( $request ); - $variations = $response->get_data(); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $variations ) ); - $this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variations[0]['sku'] ); - $this->assertEquals( 'size', $variations[0]['attributes'][0]['name'] ); - } - - /** - * Test getting variations without permission. - * - * @since 3.0.0 - */ - public function test_get_variations_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single variation. - * - * @since 3.0.0 - */ - public function test_get_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ) ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $variation_id, $variation['id'] ); - $this->assertEquals( 'size', $variation['attributes'][0]['name'] ); - } - - /** - * Test getting single variation without permission. - * - * @since 3.0.0 - */ - public function test_get_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single variation. - * - * @since 3.0.0 - */ - public function test_delete_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 1, count( $variations ) ); - } - - /** - * Test deleting a single variation without permission. - * - * @since 3.0.0 - */ - public function test_delete_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single variation with an invalid ID. - * - * @since 3.0.0 - */ - public function test_delete_variation_with_invalid_id() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test editing a single variation. - * - * @since 3.0.0 - */ - public function test_update_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ) ); - $variation = $response->get_data(); - - $this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variation['sku'] ); - $this->assertEquals( 10, $variation['regular_price'] ); - $this->assertEmpty( $variation['sale_price'] ); - $this->assertEquals( 'small', $variation['attributes'][0]['option'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU', - 'sale_price' => '8', - 'description' => 'O_O', - 'image' => array( - 'position' => 0, - 'src' => 'http://cldup.com/Dr1Bczxq4q.png', - 'alt' => 'test upload image', - ), - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertTrue( isset( $variation['description'] ), print_r( $variation, true ) ); - $this->assertContains( 'O_O', $variation['description'], print_r( $variation, true ) ); - $this->assertEquals( '8', $variation['price'], print_r( $variation, true ) ); - $this->assertEquals( '8', $variation['sale_price'], print_r( $variation, true ) ); - $this->assertEquals( '10', $variation['regular_price'], print_r( $variation, true ) ); - $this->assertEquals( 'FIXED-SKU', $variation['sku'], print_r( $variation, true ) ); - $this->assertEquals( 'medium', $variation['attributes'][0]['option'], print_r( $variation, true ) ); - $this->assertContains( 'Dr1Bczxq4q', $variation['image']['src'], print_r( $variation, true ) ); - $this->assertContains( 'test upload image', $variation['image']['alt'], print_r( $variation, true ) ); - - wp_delete_attachment( $variation['image']['id'], true ); - } - - /** - * Test updating a single variation without permission. - * - * @since 3.0.0 - */ - public function test_update_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-NO-PERMISSION', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single variation with an invalid ID. - * - * @since 3.0.0 - */ - public function test_update_variation_with_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/0' ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-NO-PERMISSION', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating a single variation. - * - * @since 3.0.0 - */ - public function test_create_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 2, count( $variations ) ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/products/' . $product->get_id() . '/variations' ); - $request->set_body_params( - array( - 'sku' => 'DUMMY SKU VARIABLE MEDIUM', - 'regular_price' => '12', - 'description' => 'A medium size.', - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertContains( 'A medium size.', $variation['description'] ); - $this->assertEquals( '12', $variation['price'] ); - $this->assertEquals( '12', $variation['regular_price'] ); - $this->assertTrue( $variation['purchasable'] ); - $this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $variation['sku'] ); - $this->assertEquals( 'medium', $variation['attributes'][0]['option'] ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 3, count( $variations ) ); - } - - /** - * Test creating a single variation without permission. - * - * @since 3.0.0 - */ - public function test_create_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - - $request = new WP_REST_Request( 'POST', '/wc/v2/products/' . $product->get_id() . '/variations' ); - $request->set_body_params( - array( - 'sku' => 'DUMMY SKU VARIABLE MEDIUM', - 'regular_price' => '12', - 'description' => 'A medium size.', - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test batch managing product variations. - */ - public function test_product_variations_batch() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $request = new WP_REST_Request( 'POST', '/wc/v2/products/' . $product->get_id() . '/variations/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $children[0], - 'description' => 'Updated description.', - 'image' => array( - 'position' => 0, - 'src' => 'http://cldup.com/Dr1Bczxq4q.png', - 'alt' => 'test upload image', - ), - ), - ), - 'delete' => array( - $children[1], - ), - 'create' => array( - array( - 'sku' => 'DUMMY SKU VARIABLE MEDIUM', - 'regular_price' => '12', - 'description' => 'A medium size.', - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertContains( 'Updated description.', $data['update'][0]['description'] ); - $this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku'] ); - $this->assertEquals( 'medium', $data['create'][0]['attributes'][0]['option'] ); - $this->assertEquals( $children[1], $data['delete'][0]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 2, count( $data ) ); - - wp_delete_attachment( $data[1]['image']['id'], true ); - } - - /** - * Test variation schema. - * - * @since 3.0.0 - */ - public function test_variation_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/products/' . $product->get_id() . '/variations' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 37, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_modified', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'permalink', $properties ); - $this->assertArrayHasKey( 'sku', $properties ); - $this->assertArrayHasKey( 'price', $properties ); - $this->assertArrayHasKey( 'regular_price', $properties ); - $this->assertArrayHasKey( 'sale_price', $properties ); - $this->assertArrayHasKey( 'date_on_sale_from', $properties ); - $this->assertArrayHasKey( 'date_on_sale_to', $properties ); - $this->assertArrayHasKey( 'on_sale', $properties ); - $this->assertArrayHasKey( 'visible', $properties ); - $this->assertArrayHasKey( 'purchasable', $properties ); - $this->assertArrayHasKey( 'virtual', $properties ); - $this->assertArrayHasKey( 'downloadable', $properties ); - $this->assertArrayHasKey( 'downloads', $properties ); - $this->assertArrayHasKey( 'download_limit', $properties ); - $this->assertArrayHasKey( 'download_expiry', $properties ); - $this->assertArrayHasKey( 'tax_status', $properties ); - $this->assertArrayHasKey( 'tax_class', $properties ); - $this->assertArrayHasKey( 'manage_stock', $properties ); - $this->assertArrayHasKey( 'stock_quantity', $properties ); - $this->assertArrayHasKey( 'in_stock', $properties ); - $this->assertArrayHasKey( 'backorders', $properties ); - $this->assertArrayHasKey( 'backorders_allowed', $properties ); - $this->assertArrayHasKey( 'backordered', $properties ); - $this->assertArrayHasKey( 'weight', $properties ); - $this->assertArrayHasKey( 'dimensions', $properties ); - $this->assertArrayHasKey( 'shipping_class', $properties ); - $this->assertArrayHasKey( 'shipping_class_id', $properties ); - $this->assertArrayHasKey( 'image', $properties ); - $this->assertArrayHasKey( 'attributes', $properties ); - $this->assertArrayHasKey( 'menu_order', $properties ); - $this->assertArrayHasKey( 'meta_data', $properties ); - } - - /** - * Test updating a variation stock. - * - * @since 3.0.0 - */ - public function test_update_variation_manage_stock() { - wp_set_current_user( $this->user ); - - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $product->set_manage_stock( false ); - $product->save(); - - $children = $product->get_children(); - $variation_id = $children[0]; - - // Set stock to true. - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'manage_stock' => true, - ) - ); - - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( true, $variation['manage_stock'] ); - - // Set stock to false. - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'manage_stock' => false, - ) - ); - - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( false, $variation['manage_stock'] ); - - // Set stock to false but parent is managing stock. - $product->set_manage_stock( true ); - $product->save(); - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'manage_stock' => false, - ) - ); - - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'parent', $variation['manage_stock'] ); - } -} diff --git a/unit-tests/Tests/Version2/products.php b/unit-tests/Tests/Version2/products.php deleted file mode 100644 index ea67735ae4e..00000000000 --- a/unit-tests/Tests/Version2/products.php +++ /dev/null @@ -1,536 +0,0 @@ -endpoint = new WC_REST_Products_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/products', $routes ); - $this->assertArrayHasKey( '/wc/v2/products/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v2/products/batch', $routes ); - } - - /** - * Test getting products. - * - * @since 3.0.0 - */ - public function test_get_products() { - wp_set_current_user( $this->user ); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); - sleep( 1 ); // So both products have different timestamps. - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) ); - $products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertEquals( 2, count( $products ) ); - $this->assertEquals( 'Dummy Product', $products[0]['name'] ); - $this->assertEquals( 'DUMMY SKU', $products[0]['sku'] ); - $this->assertEquals( 'Dummy External Product', $products[1]['name'] ); - $this->assertEquals( 'DUMMY EXTERNAL SKU', $products[1]['sku'] ); - } - - /** - * Test getting products without permission. - * - * @since 3.0.0 - */ - public function test_get_products_without_permission() { - wp_set_current_user( 0 ); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single product. - * - * @since 3.0.0 - */ - public function test_get_product() { - wp_set_current_user( $this->user ); - $simple = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $simple->get_id() ) ); - $product = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertContains( - array( - 'id' => $simple->get_id(), - 'name' => 'Dummy External Product', - 'type' => 'simple', - 'status' => 'publish', - 'sku' => 'DUMMY EXTERNAL SKU', - 'regular_price' => 10, - ), - $product - ); - } - - /** - * Test getting single product without permission. - * - * @since 3.0.0 - */ - public function test_get_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single product. - * - * @since 3.0.0 - */ - public function test_delete_product() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - $request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) ); - $variations = $response->get_data(); - $this->assertEquals( 0, count( $variations ) ); - } - - /** - * Test deleting a single product without permission. - * - * @since 3.0.0 - */ - public function test_delete_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single product with an invalid ID. - * - * @since 3.0.0 - */ - public function test_delete_product_with_invalid_id() { - wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/products/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test editing a single product. Tests multiple product types. - * - * @since 3.0.0 - */ - public function test_update_product() { - wp_set_current_user( $this->user ); - - // test simple products. - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 'DUMMY SKU', $data['sku'] ); - $this->assertEquals( 10, $data['regular_price'] ); - $this->assertEmpty( $data['sale_price'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU', - 'sale_price' => '8', - 'description' => 'Testing', - 'images' => array( - array( - 'position' => 0, - 'src' => 'http://cldup.com/Dr1Bczxq4q.png', - 'alt' => 'test upload image', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertContains( 'Testing', $data['description'] ); - $this->assertEquals( '8', $data['price'] ); - $this->assertEquals( '8', $data['sale_price'] ); - $this->assertEquals( '10', $data['regular_price'] ); - $this->assertEquals( 'FIXED-SKU', $data['sku'] ); - $this->assertContains( 'Dr1Bczxq4q', $data['images'][0]['src'] ); - $this->assertContains( 'test upload image', $data['images'][0]['alt'] ); - $product->delete( true ); - wp_delete_attachment( $data['images'][0]['id'], true ); - - // test variable product (variations are tested in product-variations.php). - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) ); - $data = $response->get_data(); - - foreach ( array( 'small', 'large' ) as $term_name ) { - $this->assertContains( $term_name, $data['attributes'][0]['options'] ); - } - - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'attributes' => array( - array( - 'id' => 0, - 'name' => 'pa_color', - 'options' => array( - 'red', - 'yellow', - ), - 'visible' => false, - 'variation' => 1, - ), - array( - 'id' => 0, - 'name' => 'pa_size', - 'options' => array( - 'small', - ), - 'visible' => false, - 'variation' => 1, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( array( 'small' ), $data['attributes'][0]['options'] ); - $this->assertEquals( array( 'red', 'yellow' ), $data['attributes'][1]['options'] ); - $product->delete( true ); - - // test external product. - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 'Buy external product', $data['button_text'] ); - $this->assertEquals( 'http://woocommerce.com', $data['external_url'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'button_text' => 'Test API Update', - 'external_url' => 'http://automattic.com', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'Test API Update', $data['button_text'] ); - $this->assertEquals( 'http://automattic.com', $data['external_url'] ); - } - - /** - * Test updating a single product without permission. - * - * @since 3.0.0 - */ - public function test_update_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-NO-PERMISSION', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single product with an invalid ID. - * - * @since 3.0.0 - */ - public function test_update_product_with_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/0' ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-INVALID-ID', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating a single product. - * - * @since 3.0.0 - */ - public function test_create_product() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/products/shipping_classes' ); - $request->set_body_params( - array( - 'name' => 'Test', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $shipping_class_id = $data['id']; - - // Create simple. - $request = new WP_REST_Request( 'POST', '/wc/v2/products' ); - $request->set_body_params( - array( - 'type' => 'simple', - 'name' => 'Test Simple Product', - 'sku' => 'DUMMY SKU SIMPLE API', - 'regular_price' => '10', - 'shipping_class' => 'test', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '10', $data['price'] ); - $this->assertEquals( '10', $data['regular_price'] ); - $this->assertTrue( $data['purchasable'] ); - $this->assertEquals( 'DUMMY SKU SIMPLE API', $data['sku'] ); - $this->assertEquals( 'Test Simple Product', $data['name'] ); - $this->assertEquals( 'simple', $data['type'] ); - $this->assertEquals( $shipping_class_id, $data['shipping_class_id'] ); - - // Create external. - $request = new WP_REST_Request( 'POST', '/wc/v2/products' ); - $request->set_body_params( - array( - 'type' => 'external', - 'name' => 'Test External Product', - 'sku' => 'DUMMY SKU EXTERNAL API', - 'regular_price' => '10', - 'button_text' => 'Test Button', - 'external_url' => 'https://wordpress.org', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '10', $data['price'] ); - $this->assertEquals( '10', $data['regular_price'] ); - $this->assertFalse( $data['purchasable'] ); - $this->assertEquals( 'DUMMY SKU EXTERNAL API', $data['sku'] ); - $this->assertEquals( 'Test External Product', $data['name'] ); - $this->assertEquals( 'external', $data['type'] ); - $this->assertEquals( 'Test Button', $data['button_text'] ); - $this->assertEquals( 'https://wordpress.org', $data['external_url'] ); - - // Create variable. - $request = new WP_REST_Request( 'POST', '/wc/v2/products' ); - $request->set_body_params( - array( - 'type' => 'variable', - 'name' => 'Test Variable Product', - 'sku' => 'DUMMY SKU VARIABLE API', - 'attributes' => array( - array( - 'id' => 0, - 'name' => 'pa_size', - 'options' => array( - 'small', - 'medium', - ), - 'visible' => false, - 'variation' => 1, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'DUMMY SKU VARIABLE API', $data['sku'] ); - $this->assertEquals( 'Test Variable Product', $data['name'] ); - $this->assertEquals( 'variable', $data['type'] ); - $this->assertEquals( array( 'small', 'medium' ), $data['attributes'][0]['options'] ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) ); - $products = $response->get_data(); - $this->assertEquals( 3, count( $products ) ); - } - - /** - * Test creating a single product without permission. - * - * @since 3.0.0 - */ - public function test_create_product_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/products' ); - $request->set_body_params( - array( - 'name' => 'Test Product', - 'regular_price' => '12', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test batch managing products. - */ - public function test_products_batch() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v2/products/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $product->get_id(), - 'description' => 'Updated description.', - ), - ), - 'delete' => array( - $product_2->get_id(), - ), - 'create' => array( - array( - 'sku' => 'DUMMY SKU BATCH TEST 1', - 'regular_price' => '10', - 'name' => 'Test Batch Create 1', - 'type' => 'external', - 'button_text' => 'Test Button', - ), - array( - 'sku' => 'DUMMY SKU BATCH TEST 2', - 'regular_price' => '20', - 'name' => 'Test Batch Create 2', - 'type' => 'simple', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertContains( 'Updated description.', $data['update'][0]['description'] ); - $this->assertEquals( 'DUMMY SKU BATCH TEST 1', $data['create'][0]['sku'] ); - $this->assertEquals( 'DUMMY SKU BATCH TEST 2', $data['create'][1]['sku'] ); - $this->assertEquals( 'Test Button', $data['create'][0]['button_text'] ); - $this->assertEquals( 'external', $data['create'][0]['type'] ); - $this->assertEquals( 'simple', $data['create'][1]['type'] ); - $this->assertEquals( $product_2->get_id(), $data['delete'][0]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Tests to make sure you can filter products post statuses by both - * the status query arg and WP_Query. - * - * @since 3.0.0 - */ - public function test_products_filter_post_status() { - wp_set_current_user( $this->user ); - for ( $i = 0; $i < 8; $i++ ) { - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - if ( 0 === $i % 2 ) { - wp_update_post( - array( - 'ID' => $product->get_id(), - 'post_status' => 'draft', - ) - ); - } - } - - // Test filtering with status=publish. - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_param( 'status', 'publish' ); - $response = $this->server->dispatch( $request ); - $products = $response->get_data(); - - $this->assertEquals( 4, count( $products ) ); - foreach ( $products as $product ) { - $this->assertEquals( 'publish', $product['status'] ); - } - - // Test filtering with status=draft. - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_param( 'status', 'draft' ); - $response = $this->server->dispatch( $request ); - $products = $response->get_data(); - - $this->assertEquals( 4, count( $products ) ); - foreach ( $products as $product ) { - $this->assertEquals( 'draft', $product['status'] ); - } - - // Test filtering with no filters - which should return 'any' (all 8). - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $response = $this->server->dispatch( $request ); - $products = $response->get_data(); - - $this->assertEquals( 8, count( $products ) ); - } - - /** - * Test product schema. - * - * @since 3.0.0 - */ - public function test_product_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/products/' . $product->get_id() ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 65, count( $properties ) ); - } -} diff --git a/unit-tests/Tests/Version2/settings.php b/unit-tests/Tests/Version2/settings.php deleted file mode 100644 index 12baa1aca4e..00000000000 --- a/unit-tests/Tests/Version2/settings.php +++ /dev/null @@ -1,892 +0,0 @@ -endpoint = new WC_REST_Setting_Options_Controller(); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/settings', $routes ); - $this->assertArrayHasKey( '/wc/v2/settings/(?P[\w-]+)', $routes ); - $this->assertArrayHasKey( '/wc/v2/settings/(?P[\w-]+)/(?P[\w-]+)', $routes ); - } - - /** - * Test getting all groups. - * - * @since 3.0.0 - */ - public function test_get_groups() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertContains( - array( - 'id' => 'test', - 'label' => 'Test extension', - 'parent_id' => '', - 'description' => 'My awesome test settings.', - 'sub_groups' => array( 'sub-test' ), - '_links' => array( - 'options' => array( - array( - 'href' => rest_url( '/wc/v2/settings/test' ), - ), - ), - ), - ), - $data - ); - - $this->assertContains( - array( - 'id' => 'sub-test', - 'label' => 'Sub test', - 'parent_id' => 'test', - 'description' => '', - 'sub_groups' => array(), - '_links' => array( - 'options' => array( - array( - 'href' => rest_url( '/wc/v2/settings/sub-test' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test /settings without valid permissions/creds. - * - * @since 3.0.0 - */ - public function test_get_groups_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test /settings without valid permissions/creds. - * - * @since 3.0.0 - * @covers WC_Rest_Settings_Controller::get_items - */ - public function test_get_groups_none_registered() { - wp_set_current_user( $this->user ); - - remove_all_filters( 'woocommerce_settings_groups' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) ); - $this->assertEquals( 500, $response->get_status() ); - - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register(); - } - - /** - * Test groups schema. - * - * @since 3.0.0 - */ - public function test_get_group_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 5, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'parent_id', $properties ); - $this->assertArrayHasKey( 'label', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'sub_groups', $properties ); - } - - /** - * Test settings schema. - * - * @since 3.0.0 - */ - public function test_get_setting_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings/test/woocommerce_shop_page_display' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 9, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'label', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'value', $properties ); - $this->assertArrayHasKey( 'default', $properties ); - $this->assertArrayHasKey( 'tip', $properties ); - $this->assertArrayHasKey( 'placeholder', $properties ); - $this->assertArrayHasKey( 'type', $properties ); - $this->assertArrayHasKey( 'options', $properties ); - } - - /** - * Test getting a single group. - * - * @since 3.0.0 - */ - public function test_get_group() { - wp_set_current_user( $this->user ); - - // test route callback receiving an empty group id - $result = $this->endpoint->get_group_settings( '' ); - $this->assertWPError( $result ); - - // test getting a group that does not exist - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/not-real' ) ); - $this->assertEquals( 404, $response->get_status() ); - - // test getting the 'invalid' group - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/invalid' ) ); - $this->assertEquals( 404, $response->get_status() ); - - // test getting a valid group with settings attached to it - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) ); - $data = $response->get_data(); - $this->assertEquals( 1, count( $data ) ); - $this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] ); - $this->assertEmpty( $data[0]['value'] ); - } - - /** - * Test getting a single group without permission. - * - * @since 3.0.0 - */ - public function test_get_group_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/coupon-data' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single setting. - * - * @since 3.0.0 - */ - public function test_update_setting() { - wp_set_current_user( $this->user ); - - // test defaults first - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) ); - $data = $response->get_data(); - $this->assertEquals( '', $data['value'] ); - - // test updating shop display setting - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => 'both', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'both', $data['value'] ); - $this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => 'subcategories', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'subcategories', $data['value'] ); - $this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => '', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '', $data['value'] ); - $this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) ); - } - - /** - * Test updating multiple settings at once. - * - * @since 3.0.0 - */ - public function test_update_settings() { - wp_set_current_user( $this->user ); - - // test defaults first - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) ); - $data = $response->get_data(); - $this->assertEquals( '', $data[0]['value'] ); - - // test setting both at once - $request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => 'woocommerce_shop_page_display', - 'value' => 'both', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'both', $data['update'][0]['value'] ); - $this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) ); - - // test updating one, but making sure the other value stays the same - $request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => 'woocommerce_shop_page_display', - 'value' => 'subcategories', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'subcategories', $data['update'][0]['value'] ); - $this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) ); - } - - /** - * Test getting a single setting. - * - * @since 3.0.0 - */ - public function test_get_setting() { - wp_set_current_user( $this->user ); - - // test getting an invalid setting from a group that does not exist - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/not-real/woocommerce_shop_page_display' ) ); - $data = $response->get_data(); - $this->assertEquals( 404, $response->get_status() ); - - // test getting an invalid setting from a group that does exist - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/invalid/invalid' ) ); - $data = $response->get_data(); - $this->assertEquals( 404, $response->get_status() ); - - // test getting a valid setting - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertEquals( 'woocommerce_shop_page_display', $data['id'] ); - $this->assertEquals( 'Shop page display', $data['label'] ); - $this->assertEquals( '', $data['default'] ); - $this->assertEquals( 'select', $data['type'] ); - $this->assertEquals( '', $data['value'] ); - } - - /** - * Test getting a single setting without valid user permissions. - * - * @since 3.0.0 - */ - public function test_get_setting_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests the GET single setting route handler receiving an empty setting ID. - * - * @since 3.0.0 - */ - public function test_get_setting_empty_setting_id() { - $result = $this->endpoint->get_setting( 'test', '' ); - - $this->assertWPError( $result ); - } - - /** - * Tests the GET single setting route handler receiving an invalid setting ID. - * - * @since 3.0.0 - */ - public function test_get_setting_invalid_setting_id() { - $result = $this->endpoint->get_setting( 'test', 'invalid' ); - - $this->assertWPError( $result ); - } - - /** - * Tests the GET single setting route handler encountering an invalid setting type. - * - * @since 3.0.0 - */ - public function test_get_setting_invalid_setting_type() { - // $controller = $this->getMock( 'WC_Rest_Setting_Options_Controller', array( 'get_group_settings', 'is_setting_type_valid' ) ); - $controller = $this->getMockBuilder( 'WC_Rest_Setting_Options_Controller' )->setMethods( array( 'get_group_settings', 'is_setting_type_valid' ) )->getMock(); - - $controller - ->expects( $this->any() ) - ->method( 'get_group_settings' ) - ->will( $this->returnValue( \Automattic\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register_test_settings( array() ) ) ); - - $controller - ->expects( $this->any() ) - ->method( 'is_setting_type_valid' ) - ->will( $this->returnValue( false ) ); - - $result = $controller->get_setting( 'test', 'woocommerce_shop_page_display' ); - - $this->assertWPError( $result ); - } - - /** - * Test updating a single setting without valid user permissions. - * - * @since 3.0.0 - */ - public function test_update_setting_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => 'subcategories', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - - /** - * Test updating multiple settings without valid user permissions. - * - * @since 3.0.0 - */ - public function test_update_settings_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => 'woocommerce_shop_page_display', - 'value' => 'subcategories', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a bad setting ID. - * - * @since 3.0.0 - * @covers WC_Rest_Setting_Options_Controller::update_item - */ - public function test_update_setting_bad_setting_id() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/test/invalid' ); - $request->set_body_params( - array( - 'value' => 'test', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests our classic setting registration to make sure settings added for WP-Admin are available over the API. - * - * @since 3.0.0 - */ - public function test_classic_settings() { - wp_set_current_user( $this->user ); - - // Make sure the group is properly registered - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products' ) ); - $data = $response->get_data(); - $this->assertTrue( is_array( $data ) ); - $this->assertContains( - array( - 'id' => 'woocommerce_downloads_require_login', - 'label' => 'Access restriction', - 'description' => 'Downloads require login', - 'type' => 'checkbox', - 'default' => 'no', - 'tip' => 'This setting does not apply to guest purchases.', - 'value' => 'no', - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/settings/products/woocommerce_downloads_require_login' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/settings/products' ), - ), - ), - ), - ), - $data - ); - - // test get single - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products/woocommerce_dimension_unit' ) ); - $data = $response->get_data(); - - $this->assertEquals( 'cm', $data['default'] ); - - // test update - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) ); - $request->set_body_params( - array( - 'value' => 'yd', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'yd', $data['value'] ); - $this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) ); - } - - /** - * Tests our email etting registration to make sure settings added for WP-Admin are available over the API. - * - * @since 3.0.0 - */ - public function test_email_settings() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order' ) ); - $settings = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertContains( - array( - 'id' => 'recipient', - 'label' => 'Recipient(s)', - 'description' => 'Enter recipients (comma separated) for this email. Defaults to admin@example.org.', - 'type' => 'text', - 'default' => '', - 'tip' => 'Enter recipients (comma separated) for this email. Defaults to admin@example.org.', - 'value' => '', - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/settings/email_new_order/recipient' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/settings/email_new_order' ), - ), - ), - ), - ), - $settings - ); - - // test get single - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) ); - $setting = $response->get_data(); - - $this->assertEquals( - array( - 'id' => 'subject', - 'label' => 'Subject', - 'description' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'type' => 'text', - 'default' => '', - 'tip' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'value' => '', - ), - $setting - ); - - // test update - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_new_order', 'subject' ) ); - $request->set_body_params( - array( - 'value' => 'This is my subject', - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - - $this->assertEquals( - array( - 'id' => 'subject', - 'label' => 'Subject', - 'description' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'type' => 'text', - 'default' => '', - 'tip' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'value' => 'This is my subject', - ), - $setting - ); - - // test updating another subject and making sure it works with a "similar" id - $request = new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - - $this->assertEmpty( $setting['value'] ); - - // test update - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); - $request->set_body_params( - array( - 'value' => 'This is my new subject', - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - - $this->assertEquals( 'This is my new subject', $setting['value'] ); - - // make sure the other is what we left it - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) ); - $setting = $response->get_data(); - - $this->assertEquals( 'This is my subject', $setting['value'] ); - } - - /** - * Test validation of checkbox settings. - * - * @since 3.0.0 - */ - public function test_validation_checkbox() { - wp_set_current_user( $this->user ); - - // test bogus value - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); - $request->set_body_params( - array( - 'value' => 'not_yes_or_no', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // test yes - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); - $request->set_body_params( - array( - 'value' => 'yes', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - - // test no - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); - $request->set_body_params( - array( - 'value' => 'no', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test validation of radio settings. - * - * @since 3.0.0 - */ - public function test_validation_radio() { - wp_set_current_user( $this->user ); - - // not a valid option - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) ); - $request->set_body_params( - array( - 'value' => 'billing2', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // valid - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) ); - $request->set_body_params( - array( - 'value' => 'billing', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test validation of multiselect. - * - * @since 3.0.0 - */ - public function test_validation_multiselect() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ) ); - $setting = $response->get_data(); - $this->assertEmpty( $setting['value'] ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ); - $request->set_body_params( - array( - 'value' => array( 'AX', 'DZ', 'MMM' ), - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] ); - } - - /** - * Test validation of select. - * - * @since 3.0.0 - */ - public function test_validation_select() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ) ); - $setting = $response->get_data(); - $this->assertEquals( 'kg', $setting['value'] ); - - // invalid - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ); - $request->set_body_params( - array( - 'value' => 'pounds', // invalid, should be lbs - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // valid - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ); - $request->set_body_params( - array( - 'value' => 'lbs', // invalid, should be lbs - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( 'lbs', $setting['value'] ); - } - - /** - * Test to make sure the 'base location' setting is present in the response. - * That it is returned as 'select' and not 'single_select_country', - * and that both state and country options are returned. - * - * @since 3.0.7 - */ - public function test_woocommerce_default_country() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_default_country' ) ); - $setting = $response->get_data(); - - $this->assertEquals( 'select', $setting['type'] ); - $this->assertArrayHasKey( 'GB', $setting['options'] ); - $this->assertArrayHasKey( 'US:OR', $setting['options'] ); - } - - /** - * Test to make sure the store address setting can be fetched and updated. - * - * @since 3.1.1 - */ - public function test_woocommerce_store_address() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_address' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } - - /** - * Test to make sure the store address 2 (line 2) setting can be fetched and updated. - * - * @since 3.1.1 - */ - public function test_woocommerce_store_address_2() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_address_2' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } - - /** - * Test to make sure the store city setting can be fetched and updated. - * - * @since 3.1.1 - */ - public function test_woocommerce_store_city() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_city' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } - - /** - * Test to make sure the store postcode setting can be fetched and updated. - * - * @since 3.1.1 - */ - public function test_woocommerce_store_postcode() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_postcode' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } -} diff --git a/unit-tests/Tests/Version2/shipping-methods.php b/unit-tests/Tests/Version2/shipping-methods.php deleted file mode 100644 index 65c153e8f31..00000000000 --- a/unit-tests/Tests/Version2/shipping-methods.php +++ /dev/null @@ -1,143 +0,0 @@ -endpoint = new WC_REST_Shipping_Methods_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/shipping_methods', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping_methods/(?P[\w-]+)', $routes ); - } - - /** - * Test getting all shipping methods. - * - * @since 3.0.0 - */ - public function test_get_shipping_methods() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods' ) ); - $methods = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertContains( - array( - 'id' => 'free_shipping', - 'title' => 'Free shipping', - 'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.', - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/shipping_methods/free_shipping' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping_methods' ), - ), - ), - ), - ), - $methods - ); - } - - /** - * Tests to make sure shipping methods cannot viewed without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_shipping_methods_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a single shipping method. - * - * @since 3.0.0 - */ - public function test_get_shipping_method() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods/local_pickup' ) ); - $method = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => 'local_pickup', - 'title' => 'Local pickup', - 'description' => 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.', - ), - $method - ); - } - - /** - * Tests getting a single shipping method without the correct permissions. - * - * @since 3.0.0 - */ - public function test_get_shipping_method_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods/local_pickup' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a shipping method with an invalid ID. - * - * @since 3.0.0 - */ - public function test_get_shipping_method_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods/fake_method' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test the shipping method schema. - * - * @since 3.0.0 - */ - public function test_shipping_method_schema() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/shipping_methods' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'title', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - } -} diff --git a/unit-tests/Tests/Version2/shipping-zones.php b/unit-tests/Tests/Version2/shipping-zones.php deleted file mode 100644 index 1d9ea5368d3..00000000000 --- a/unit-tests/Tests/Version2/shipping-zones.php +++ /dev/null @@ -1,800 +0,0 @@ -endpoint = new WC_REST_Shipping_Zones_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - $this->zones = array(); - } - - /** - * Helper method to create a Shipping Zone. - * - * @param string $name Zone name. - * @param int $order Optional. Zone sort order. - * @return WC_Shipping_Zone - */ - protected function create_shipping_zone( $name, $order = 0, $locations = array() ) { - $zone = new WC_Shipping_Zone( null ); - $zone->set_zone_name( $name ); - $zone->set_zone_order( $order ); - $zone->set_locations( $locations ); - $zone->save(); - - $this->zones[] = $zone; - - return $zone; - } - - /** - * Test route registration. - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/shipping/zones', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/locations', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/methods', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/methods/(?P[\d]+)', $routes ); - } - - /** - * Test getting all Shipping Zones. - * @since 3.0.0 - */ - public function test_get_zones() { - wp_set_current_user( $this->user ); - - // "Rest of the World" zone exists by default - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 1 ); - $this->assertContains( - array( - 'id' => $data[0]['id'], - 'name' => 'Locations not covered by your other zones', - 'order' => 0, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $data[0]['id'] ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $data[0]['id'] . '/locations' ), - ), - ), - ), - ), - $data - ); - - // Create a zone and make sure it's in the response - $this->create_shipping_zone( 'Zone 1' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 2 ); - $this->assertContains( - array( - 'id' => $data[1]['id'], - 'name' => 'Zone 1', - 'order' => 0, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $data[1]['id'] ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $data[1]['id'] . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test /shipping/zones without valid permissions/creds. - * @since 3.0.0 - */ - public function test_get_shipping_zones_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test /shipping/zones while Shipping is disabled in WooCommerce. - * @since 3.0.0 - */ - public function test_get_shipping_zones_disabled_shipping() { - wp_set_current_user( $this->user ); - - add_filter( 'wc_shipping_enabled', '__return_false' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) ); - $this->assertEquals( 404, $response->get_status() ); - - remove_filter( 'wc_shipping_enabled', '__return_false' ); - } - - /** - * Test Shipping Zone schema. - * @since 3.0.0 - */ - public function test_get_shipping_zone_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/shipping/zones' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertTrue( $properties['id']['readonly'] ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'order', $properties ); - } - - /** - * Test Shipping Zone create endpoint. - * @since 3.0.0 - */ - public function test_create_shipping_zone() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones' ); - $request->set_body_params( - array( - 'name' => 'Test Zone', - 'order' => 1, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'name' => 'Test Zone', - 'order' => 1, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $data['id'] ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $data['id'] . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test Shipping Zone create endpoint. - * @since 3.0.0 - */ - public function test_create_shipping_zone_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones' ); - $request->set_body_params( - array( - 'name' => 'Test Zone', - 'order' => 1, - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test Shipping Zone update endpoint. - * @since 3.0.0 - */ - public function test_update_shipping_zone() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Test Zone' ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/' . $zone->get_id() ); - $request->set_body_params( - array( - 'name' => 'Zone Test', - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $zone->get_id(), - 'name' => 'Zone Test', - 'order' => 2, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test Shipping Zone update endpoint with a bad zone ID. - * @since 3.0.0 - */ - public function test_update_shipping_zone_invalid_id() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/555555' ); - $request->set_body_params( - array( - 'name' => 'Zone Test', - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test Shipping Zone delete endpoint. - * @since 3.0.0 - */ - public function test_delete_shipping_zone() { - wp_set_current_user( $this->user ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/' . $zone->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test Shipping Zone delete endpoint without permissions. - * @since 3.0.0 - */ - public function test_delete_shipping_zone_without_permission() { - wp_set_current_user( 0 ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/' . $zone->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test Shipping Zone delete endpoint with a bad zone ID. - * @since 3.0.0 - */ - public function test_delete_shipping_zone_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/555555' ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting a single Shipping Zone. - * @since 3.0.0 - */ - public function test_get_single_shipping_zone() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Test Zone' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $zone->get_id(), - 'name' => 'Test Zone', - 'order' => 0, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test getting a single Shipping Zone with a bad zone ID. - * @since 3.0.0 - */ - public function test_get_single_shipping_zone_invalid_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting Shipping Zone Locations. - * @since 3.0.0 - */ - public function test_get_locations() { - wp_set_current_user( $this->user ); - - // Create a zone - $zone = $this->create_shipping_zone( - 'Zone 1', - 0, - array( - array( - 'code' => 'US', - 'type' => 'country', - ), - ) - ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 1 ); - $this->assertEquals( - array( - array( - 'code' => 'US', - 'type' => 'country', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test getting Shipping Zone Locations with a bad zone ID. - * @since 3.0.0 - */ - public function test_get_locations_invalid_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1/locations' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test Shipping Zone Locations update endpoint. - * @since 3.0.0 - */ - public function test_update_locations() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Test Zone' ); - - $request = new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ); - $request->add_header( 'Content-Type', 'application/json' ); - $request->set_body( - json_encode( - array( - array( - 'code' => 'UK', - 'type' => 'country', - ), - array( - 'code' => 'US', // test that locations missing "type" treated as country. - ), - array( - 'code' => 'SW1A0AA', - 'type' => 'postcode', - ), - array( - 'type' => 'continent', // test that locations missing "code" aren't saved - ), - ) - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - $this->assertEquals( - array( - array( - 'code' => 'UK', - 'type' => 'country', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - array( - 'code' => 'US', - 'type' => 'country', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - array( - 'code' => 'SW1A0AA', - 'type' => 'postcode', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test updating Shipping Zone Locations with a bad zone ID. - * @since 3.0.0 - */ - public function test_update_locations_invalid_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/1/locations' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting all Shipping Zone Methods and getting a single Shipping Zone Method. - * @since 3.0.0 - */ - public function test_get_methods() { - wp_set_current_user( $this->user ); - - // Create a shipping method and make sure it's in the response - $zone = $this->create_shipping_zone( 'Zone 1' ); - $instance_id = $zone->add_shipping_method( 'flat_rate' ); - $methods = $zone->get_shipping_methods(); - $method = $methods[ $instance_id ]; - - $settings = array(); - $method->init_instance_settings(); - foreach ( $method->get_instance_form_fields() as $id => $field ) { - $data = array( - 'id' => $id, - 'label' => $field['title'], - 'description' => ( empty( $field['description'] ) ? '' : $field['description'] ), - 'type' => $field['type'], - 'value' => $method->instance_settings[ $id ], - 'default' => ( empty( $field['default'] ) ? '' : $field['default'] ), - 'tip' => ( empty( $field['description'] ) ? '' : $field['description'] ), - 'placeholder' => ( empty( $field['placeholder'] ) ? '' : $field['placeholder'] ), - ); - if ( ! empty( $field['options'] ) ) { - $data['options'] = $field['options']; - } - $settings[ $id ] = $data; - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods' ) ); - $data = $response->get_data(); - $expected = array( - 'id' => $instance_id, - 'instance_id' => $instance_id, - 'title' => $method->instance_settings['title'], - 'order' => $method->method_order, - 'enabled' => ( 'yes' === $method->enabled ), - 'method_id' => $method->id, - 'method_title' => $method->method_title, - 'method_description' => $method->method_description, - 'settings' => $settings, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 1 ); - $this->assertContains( $expected, $data ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $expected, $data ); - } - - /** - * Test getting all Shipping Zone Methods with a bad zone ID. - * @since 3.0.0 - */ - public function test_get_methods_invalid_zone_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1/methods' ) ); - - $this->assertEquals( 404, $response->get_status() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1/methods/1' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting a single Shipping Zone Method with a bad ID. - * @since 3.0.0 - */ - public function test_get_methods_invalid_method_id() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Zone 1' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/1' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test updating a Shipping Zone Method. - * @since 3.0.0 - */ - public function test_update_methods() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Zone 1' ); - $instance_id = $zone->add_shipping_method( 'flat_rate' ); - $methods = $zone->get_shipping_methods(); - $method = $methods[ $instance_id ]; - - // Test defaults - $request = new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'title', $data['settings'] ); - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); - $this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '0', $data['settings']['cost']['value'] ); - - // Update a single value - $request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'settings' => array( - 'cost' => 5, - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'title', $data['settings'] ); - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); - $this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '5', $data['settings']['cost']['value'] ); - - // Test multiple settings - $request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'settings' => array( - 'cost' => 10, - 'tax_status' => 'none', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'title', $data['settings'] ); - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); - $this->assertEquals( 'none', $data['settings']['tax_status']['value'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '10', $data['settings']['cost']['value'] ); - - // Test bogus - $request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'settings' => array( - 'cost' => 10, - 'tax_status' => 'this_is_not_a_valid_option', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // Test other parameters - $this->assertTrue( $data['enabled'] ); - $this->assertEquals( 1, $data['order'] ); - - $request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'enabled' => false, - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertFalse( $data['enabled'] ); - $this->assertEquals( 2, $data['order'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '10', $data['settings']['cost']['value'] ); - } - - /** - * Test creating a Shipping Zone Method. - * @since 3.0.0 - */ - public function test_create_method() { - wp_set_current_user( $this->user ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - $request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods' ); - $request->set_body_params( - array( - 'method_id' => 'flat_rate', - 'enabled' => false, - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertFalse( $data['enabled'] ); - $this->assertEquals( 2, $data['order'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '0', $data['settings']['cost']['value'] ); - } - - /** - * Test deleting a Shipping Zone Method. - * @since 3.0.0 - */ - public function test_delete_method() { - wp_set_current_user( $this->user ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - $instance_id = $zone->add_shipping_method( 'flat_rate' ); - $methods = $zone->get_shipping_methods(); - $method = $methods[ $instance_id ]; - $request = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } -} diff --git a/unit-tests/Tests/Version2/system-status.php b/unit-tests/Tests/Version2/system-status.php deleted file mode 100644 index cb359b0630b..00000000000 --- a/unit-tests/Tests/Version2/system-status.php +++ /dev/null @@ -1,355 +0,0 @@ -endpoint = new WC_REST_System_Status_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/system_status', $routes ); - $this->assertArrayHasKey( '/wc/v2/system_status/tools', $routes ); - $this->assertArrayHasKey( '/wc/v2/system_status/tools/(?P[\w-]+)', $routes ); - } - - /** - * Test to make sure system status cannot be accessed without valid creds - * - * @since 3.0.0 - */ - public function test_get_system_status_info_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test to make sure root properties are present. - * (environment, theme, database, etc). - * - * @since 3.0.0 - */ - public function test_get_system_status_info_returns_root_properties() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'environment', $data ); - $this->assertArrayHasKey( 'database', $data ); - $this->assertArrayHasKey( 'active_plugins', $data ); - $this->assertArrayHasKey( 'theme', $data ); - $this->assertArrayHasKey( 'settings', $data ); - $this->assertArrayHasKey( 'security', $data ); - $this->assertArrayHasKey( 'pages', $data ); - } - - /** - * Test to make sure environment response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_status_info_environment() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $data = $response->get_data(); - $environment = (array) $data['environment']; - - // Make sure all expected data is present. - $this->assertEquals( 32, count( $environment ) ); - - // Test some responses to make sure they match up. - $this->assertEquals( get_option( 'home' ), $environment['home_url'] ); - $this->assertEquals( get_option( 'siteurl' ), $environment['site_url'] ); - $this->assertEquals( WC()->version, $environment['version'] ); - } - - /** - * Test to make sure database response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_status_info_database() { - global $wpdb; - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $data = $response->get_data(); - $database = (array) $data['database']; - - $this->assertEquals( get_option( 'woocommerce_db_version' ), $database['wc_database_version'] ); - $this->assertEquals( $wpdb->prefix, $database['database_prefix'] ); - $this->assertArrayHasKey( 'woocommerce', $database['database_tables'], print_r( $database, true ) ); - $this->assertArrayHasKey( $wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], print_r( $database, true ) ); - } - - /** - * Test to make sure active plugins response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_status_info_active_plugins() { - wp_set_current_user( $this->user ); - - $actual_plugins = array( 'hello.php' ); - update_option( 'active_plugins', $actual_plugins ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - update_option( 'active_plugins', array() ); - - $data = $response->get_data(); - $plugins = (array) $data['active_plugins']; - - $this->assertEquals( 1, count( $plugins ) ); - $this->assertEquals( 'Hello Dolly', $plugins[0]['name'] ); - } - - /** - * Test to make sure theme response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_status_info_theme() { - wp_set_current_user( $this->user ); - $active_theme = wp_get_theme(); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $data = $response->get_data(); - $theme = (array) $data['theme']; - - $this->assertEquals( 13, count( $theme ) ); - $this->assertEquals( $active_theme->Name, $theme['name'] ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar - } - - /** - * Test to make sure settings response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_status_info_settings() { - wp_set_current_user( $this->user ); - - $term_response = array(); - $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); - foreach ( $terms as $term ) { - $term_response[ $term->slug ] = strtolower( $term->name ); - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $data = $response->get_data(); - $settings = (array) $data['settings']; - - $this->assertEquals( 12, count( $settings ) ); - $this->assertEquals( ( 'yes' === get_option( 'woocommerce_api_enabled' ) ), $settings['api_enabled'] ); - $this->assertEquals( get_woocommerce_currency(), $settings['currency'] ); - $this->assertEquals( $term_response, $settings['taxonomies'] ); - } - - /** - * Test to make sure security response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_status_info_security() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $data = $response->get_data(); - $settings = (array) $data['security']; - - $this->assertEquals( 2, count( $settings ) ); - $this->assertEquals( 'https' === substr( wc_get_page_permalink( 'shop' ), 0, 5 ), $settings['secure_connection'] ); - $this->assertEquals( ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), $settings['hide_errors'] ); - } - - /** - * Test to make sure pages response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_status_info_pages() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) ); - $data = $response->get_data(); - $pages = $data['pages']; - $this->assertEquals( 5, count( $pages ) ); - } - - /** - * Test system status schema. - * - * @since 3.0.0 - */ - public function test_system_status_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/system_status' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 10, count( $properties ) ); - $this->assertArrayHasKey( 'environment', $properties ); - $this->assertArrayHasKey( 'database', $properties ); - $this->assertArrayHasKey( 'active_plugins', $properties ); - $this->assertArrayHasKey( 'theme', $properties ); - $this->assertArrayHasKey( 'settings', $properties ); - $this->assertArrayHasKey( 'security', $properties ); - $this->assertArrayHasKey( 'pages', $properties ); - } - - /** - * Test to make sure get_items (all tools) response is correct. - * - * @since 3.0.0 - */ - public function test_get_system_tools() { - wp_set_current_user( $this->user ); - - $tools_controller = new WC_REST_System_Status_Tools_Controller(); - $raw_tools = $tools_controller->get_tools(); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $raw_tools ), count( $data ) ); - $this->assertContains( - array( - 'id' => 'regenerate_thumbnails', - 'name' => 'Regenerate shop thumbnails', - 'action' => 'Regenerate', - 'description' => 'This will regenerate all shop thumbnails to match your theme and/or image settings.', - '_links' => array( - 'item' => array( - array( - 'href' => rest_url( '/wc/v2/system_status/tools/regenerate_thumbnails' ), - 'embeddable' => true, - ), - ), - ), - ), - $data - ); - } - - /** - * Test to make sure system status tools cannot be accessed without valid creds - * - * @since 3.0.0 - */ - public function test_get_system_status_tools_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test to make sure we can load a single tool correctly. - * - * @since 3.0.0 - */ - public function test_get_system_tool() { - wp_set_current_user( $this->user ); - - $tools_controller = new WC_REST_System_Status_Tools_Controller(); - $raw_tools = $tools_controller->get_tools(); - $raw_tool = $raw_tools['recount_terms']; - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools/recount_terms' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertEquals( 'recount_terms', $data['id'] ); - $this->assertEquals( 'Term counts', $data['name'] ); - $this->assertEquals( 'Recount terms', $data['action'] ); - $this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] ); - } - - /** - * Test to make sure a single system status toolscannot be accessed without valid creds. - * - * @since 3.0.0 - */ - public function test_get_system_status_tool_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools/recount_terms' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test to make sure we can RUN a tool correctly. - * - * @since 3.0.0 - */ - public function test_execute_system_tool() { - wp_set_current_user( $this->user ); - - $tools_controller = new WC_REST_System_Status_Tools_Controller(); - $raw_tools = $tools_controller->get_tools(); - $raw_tool = $raw_tools['recount_terms']; - - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v2/system_status/tools/recount_terms' ) ); - $data = $response->get_data(); - - $this->assertEquals( 'recount_terms', $data['id'] ); - $this->assertEquals( 'Term counts', $data['name'] ); - $this->assertEquals( 'Recount terms', $data['action'] ); - $this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] ); - $this->assertTrue( $data['success'] ); - $this->assertEquals( 1, did_action( 'woocommerce_rest_insert_system_status_tool' ) ); - - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v2/system_status/tools/not_a_real_tool' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test to make sure a tool cannot be run without valid creds. - * - * @since 3.0.0 - */ - public function test_execute_system_status_tool_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v2/system_status/tools/recount_terms' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test system status schema. - * - * @since 3.0.0 - */ - public function test_system_status_tool_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v2/system_status/tools' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 6, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'action', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'success', $properties ); - $this->assertArrayHasKey( 'message', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/coupons.php b/unit-tests/Tests/Version3/coupons.php deleted file mode 100644 index bd0564de6be..00000000000 --- a/unit-tests/Tests/Version3/coupons.php +++ /dev/null @@ -1,471 +0,0 @@ -endpoint = new WC_REST_Coupons_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/coupons', $routes ); - $this->assertArrayHasKey( '/wc/v3/coupons/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/coupons/batch', $routes ); - } - - /** - * Test getting coupons. - * @since 3.5.0 - */ - public function test_get_coupons() { - wp_set_current_user( $this->user ); - - $coupon_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post_1 = get_post( $coupon_1->get_id() ); - $coupon_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons' ) ); - $coupons = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $coupons ) ); - $this->assertContains( - array( - 'id' => $coupon_1->get_id(), - 'code' => 'dummycoupon-1', - 'amount' => '1.00', - 'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ), - 'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ), - 'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ), - 'discount_type' => 'fixed_cart', - 'description' => 'This is a dummy coupon', - 'date_expires' => '', - 'date_expires_gmt' => '', - 'usage_count' => 0, - 'individual_use' => false, - 'product_ids' => array(), - 'excluded_product_ids' => array(), - 'usage_limit' => '', - 'usage_limit_per_user' => '', - 'limit_usage_to_x_items' => null, - 'free_shipping' => false, - 'product_categories' => array(), - 'excluded_product_categories' => array(), - 'exclude_sale_items' => false, - 'minimum_amount' => '0.00', - 'maximum_amount' => '0.00', - 'email_restrictions' => array(), - 'used_by' => array(), - 'meta_data' => array(), - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/coupons/' . $coupon_1->get_id() ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/coupons' ), - ), - ), - ), - ), - $coupons - ); - } - - /** - * Test getting coupons without valid permissions. - * @since 3.5.0 - */ - public function test_get_coupons_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single coupon. - * @since 3.5.0 - */ - public function test_get_coupon() { - wp_set_current_user( $this->user ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post = get_post( $coupon->get_id() ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $coupon->get_id(), - 'code' => 'dummycoupon-1', - 'amount' => '1.00', - 'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ), - 'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ), - 'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ), - 'discount_type' => 'fixed_cart', - 'description' => 'This is a dummy coupon', - 'date_expires' => null, - 'date_expires_gmt' => null, - 'usage_count' => 0, - 'individual_use' => false, - 'product_ids' => array(), - 'excluded_product_ids' => array(), - 'usage_limit' => null, - 'usage_limit_per_user' => null, - 'limit_usage_to_x_items' => null, - 'free_shipping' => false, - 'product_categories' => array(), - 'excluded_product_categories' => array(), - 'exclude_sale_items' => false, - 'minimum_amount' => '0.00', - 'maximum_amount' => '0.00', - 'email_restrictions' => array(), - 'used_by' => array(), - 'meta_data' => array(), - ), - $data - ); - } - - /** - * Test getting a single coupon with an invalid ID. - * @since 3.5.0 - */ - public function test_get_coupon_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting a single coupon without valid permissions. - * @since 3.5.0 - */ - public function test_get_coupon_without_permission() { - wp_set_current_user( 0 ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test creating a single coupon. - * @since 3.5.0 - */ - public function test_create_coupon() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons' ); - $request->set_body_params( - array( - 'code' => 'test', - 'amount' => '5.00', - 'discount_type' => 'fixed_product', - 'description' => 'Test', - 'usage_limit' => 10, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'code' => 'test', - 'amount' => '5.00', - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'discount_type' => 'fixed_product', - 'description' => 'Test', - 'date_expires' => null, - 'date_expires_gmt' => null, - 'usage_count' => 0, - 'individual_use' => false, - 'product_ids' => array(), - 'excluded_product_ids' => array(), - 'usage_limit' => 10, - 'usage_limit_per_user' => null, - 'limit_usage_to_x_items' => null, - 'free_shipping' => false, - 'product_categories' => array(), - 'excluded_product_categories' => array(), - 'exclude_sale_items' => false, - 'minimum_amount' => '0.00', - 'maximum_amount' => '0.00', - 'email_restrictions' => array(), - 'used_by' => array(), - 'meta_data' => array(), - ), - $data - ); - } - - /** - * Test creating a single coupon with invalid fields. - * @since 3.5.0 - */ - public function test_create_coupon_invalid_fields() { - wp_set_current_user( $this->user ); - - // test no code... - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons' ); - $request->set_body_params( - array( - 'amount' => '5.00', - 'discount_type' => 'fixed_product', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating a single coupon without valid permissions. - * @since 3.5.0 - */ - public function test_create_coupon_without_permission() { - wp_set_current_user( 0 ); - - // test no code... - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons' ); - $request->set_body_params( - array( - 'code' => 'fail', - 'amount' => '5.00', - 'discount_type' => 'fixed_product', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single coupon. - * @since 3.5.0 - */ - public function test_update_coupon() { - wp_set_current_user( $this->user ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post = get_post( $coupon->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) ); - $data = $response->get_data(); - $this->assertEquals( 'This is a dummy coupon', $data['description'] ); - $this->assertEquals( 'fixed_cart', $data['discount_type'] ); - $this->assertEquals( '1.00', $data['amount'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() ); - $request->set_body_params( - array( - 'amount' => '10.00', - 'description' => 'New description', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '10.00', $data['amount'] ); - $this->assertEquals( 'New description', $data['description'] ); - $this->assertEquals( 'fixed_cart', $data['discount_type'] ); - } - - /** - * Test updating a single coupon with an invalid ID. - * @since 3.5.0 - */ - public function test_update_coupon_invalid_id() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/0' ); - $request->set_body_params( - array( - 'code' => 'tester', - 'amount' => '10.00', - 'description' => 'New description', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test updating a single coupon without valid permissions. - * @since 3.5.0 - */ - public function test_update_coupon_without_permission() { - wp_set_current_user( 0 ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $post = get_post( $coupon->get_id() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() ); - $request->set_body_params( - array( - 'amount' => '10.00', - 'description' => 'New description', - ) - ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single coupon. - * @since 3.5.0 - */ - public function test_delete_coupon() { - wp_set_current_user( $this->user ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/' . $coupon->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a single coupon with an invalid ID. - * @since 3.5.0 - */ - public function test_delete_coupon_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test deleting a single coupon without valid permissions. - * @since 3.5.0 - */ - public function test_delete_coupon_without_permission() { - wp_set_current_user( 0 ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/' . $coupon->get_id() ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test batch operations on coupons. - * @since 3.5.0 - */ - public function test_batch_coupon() { - wp_set_current_user( $this->user ); - - $coupon_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); - $coupon_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' ); - $coupon_3 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-3' ); - $coupon_4 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-4' ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $coupon_1->get_id(), - 'amount' => '5.15', - ), - ), - 'delete' => array( - $coupon_2->get_id(), - $coupon_3->get_id(), - ), - 'create' => array( - array( - 'code' => 'new-coupon', - 'amount' => '11.00', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '5.15', $data['update'][0]['amount'] ); - $this->assertEquals( '11.00', $data['create'][0]['amount'] ); - $this->assertEquals( 'new-coupon', $data['create'][0]['code'] ); - $this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] ); - $this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/coupons' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test coupon schema. - * @since 3.5.0 - */ - public function test_coupon_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/coupons' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 27, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'code', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'date_modified', $properties ); - $this->assertArrayHasKey( 'date_modified_gmt', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'discount_type', $properties ); - $this->assertArrayHasKey( 'amount', $properties ); - $this->assertArrayHasKey( 'date_expires', $properties ); - $this->assertArrayHasKey( 'date_expires_gmt', $properties ); - $this->assertArrayHasKey( 'usage_count', $properties ); - $this->assertArrayHasKey( 'individual_use', $properties ); - $this->assertArrayHasKey( 'product_ids', $properties ); - $this->assertArrayHasKey( 'excluded_product_ids', $properties ); - $this->assertArrayHasKey( 'usage_limit', $properties ); - $this->assertArrayHasKey( 'usage_limit_per_user', $properties ); - $this->assertArrayHasKey( 'limit_usage_to_x_items', $properties ); - $this->assertArrayHasKey( 'free_shipping', $properties ); - $this->assertArrayHasKey( 'product_categories', $properties ); - $this->assertArrayHasKey( 'excluded_product_categories', $properties ); - $this->assertArrayHasKey( 'exclude_sale_items', $properties ); - $this->assertArrayHasKey( 'minimum_amount', $properties ); - $this->assertArrayHasKey( 'maximum_amount', $properties ); - $this->assertArrayHasKey( 'email_restrictions', $properties ); - $this->assertArrayHasKey( 'used_by', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/customers.php b/unit-tests/Tests/Version3/customers.php deleted file mode 100644 index 8d4508bade4..00000000000 --- a/unit-tests/Tests/Version3/customers.php +++ /dev/null @@ -1,634 +0,0 @@ -endpoint = new WC_REST_Customers_Controller(); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - - $this->assertArrayHasKey( '/wc/v3/customers', $routes ); - $this->assertArrayHasKey( '/wc/v3/customers/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/customers/batch', $routes ); - } - - /** - * Test getting customers. - * - * @since 3.5.0 - */ - public function test_get_customers() { - wp_set_current_user( 1 ); - - $customer_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer(); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test2', 'test2', 'test2@woo.local' ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/customers' ); - $request->set_query_params( - array( - 'orderby' => 'id', - ) - ); - $response = $this->server->dispatch( $request ); - $customers = $response->get_data(); - $date_created = get_date_from_gmt( date( 'Y-m-d H:i:s', strtotime( $customer_1->get_date_created() ) ) ); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $customers ) ); - - $this->assertContains( - array( - 'id' => $customer_1->get_id(), - 'date_created' => wc_rest_prepare_date_response( $date_created, false ), - 'date_created_gmt' => wc_rest_prepare_date_response( $date_created ), - 'date_modified' => wc_rest_prepare_date_response( $customer_1->get_date_modified(), false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_modified() ), - 'email' => 'test@woo.local', - 'first_name' => 'Justin', - 'last_name' => '', - 'role' => 'customer', - 'username' => 'testcustomer', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - ), - 'is_paying_customer' => false, - 'avatar_url' => $customer_1->get_avatar_url(), - 'meta_data' => array(), - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/customers/' . $customer_1->get_id() . '' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/customers' ), - ), - ), - ), - ), - $customers - ); - - update_option( 'timezone_tring', 'America/New York' ); - $customer_3 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'timezonetest', 'timezonetest', 'timezonetest@woo.local' ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/customers' ); - $request->set_query_params( - array( - 'orderby' => 'id', - ) - ); - $response = $this->server->dispatch( $request ); - $customers = $response->get_data(); - $date_created = get_date_from_gmt( date( 'Y-m-d H:i:s', strtotime( $customer_3->get_date_created() ) ) ); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertContains( - array( - 'id' => $customer_3->get_id(), - 'date_created' => wc_rest_prepare_date_response( $date_created, false ), - 'date_created_gmt' => wc_rest_prepare_date_response( $date_created ), - 'date_modified' => wc_rest_prepare_date_response( $customer_3->get_date_modified(), false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( $customer_3->get_date_modified() ), - 'email' => 'timezonetest@woo.local', - 'first_name' => 'Justin', - 'last_name' => '', - 'role' => 'customer', - 'username' => 'timezonetest', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - ), - 'is_paying_customer' => false, - 'avatar_url' => $customer_3->get_avatar_url(), - 'meta_data' => array(), - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/customers/' . $customer_3->get_id() . '' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/customers' ), - ), - ), - ), - ), - $customers - ); - - } - - /** - * Test getting customers without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_customers_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/customers' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test creating a new customer. - * - * @since 3.5.0 - */ - public function test_create_customer() { - wp_set_current_user( 1 ); - - // Test just the basics first.. - $request = new WP_REST_Request( 'POST', '/wc/v3/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test', - 'password' => 'test123', - 'email' => 'create_customer_test@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'email' => 'create_customer_test@woo.local', - 'first_name' => '', - 'last_name' => '', - 'role' => 'customer', - 'username' => 'create_customer_test', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => '', - 'postcode' => '', - 'country' => '', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => '', - 'postcode' => '', - 'country' => '', - ), - 'is_paying_customer' => false, - 'meta_data' => array(), - 'avatar_url' => $data['avatar_url'], - ), - $data - ); - - // Test extra data. - $request = new WP_REST_Request( 'POST', '/wc/v3/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test2', - 'password' => 'test123', - 'email' => 'create_customer_test2@woo.local', - 'first_name' => 'Test', - 'last_name' => 'McTestFace', - 'billing' => array( - 'country' => 'US', - 'state' => 'WA', - ), - 'shipping' => array( - 'state' => 'CA', - 'country' => 'US', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'email' => 'create_customer_test2@woo.local', - 'first_name' => 'Test', - 'last_name' => 'McTestFace', - 'role' => 'customer', - 'username' => 'create_customer_test2', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => 'WA', - 'postcode' => '', - 'country' => 'US', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '', - 'address_2' => '', - 'city' => '', - 'state' => 'CA', - 'postcode' => '', - 'country' => 'US', - ), - 'is_paying_customer' => false, - 'meta_data' => array(), - 'avatar_url' => $data['avatar_url'], - ), - $data - ); - - // Test without required field. - $request = new WP_REST_Request( 'POST', '/wc/v3/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test3', - 'first_name' => 'Test', - 'last_name' => 'McTestFace', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating customers without valid permissions. - * - * @since 3.5.0 - */ - public function test_create_customer_without_permission() { - wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'POST', '/wc/v3/customers' ); - $request->set_body_params( - array( - 'username' => 'create_customer_test_without_permission', - 'password' => 'test123', - 'email' => 'create_customer_test_without_permission@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single customer. - * - * @since 3.5.0 - */ - public function test_get_customer() { - wp_set_current_user( 1 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'get_customer_test', 'test123', 'get_customer_test@woo.local' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/customers/' . $customer->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'date_modified' => $data['date_modified'], - 'date_modified_gmt' => $data['date_modified_gmt'], - 'email' => 'get_customer_test@woo.local', - 'first_name' => 'Justin', - 'billing' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - 'email' => '', - 'phone' => '', - ), - 'shipping' => array( - 'first_name' => '', - 'last_name' => '', - 'company' => '', - 'address_1' => '123 South Street', - 'address_2' => 'Apt 1', - 'city' => 'Philadelphia', - 'state' => 'PA', - 'postcode' => '19123', - 'country' => 'US', - ), - 'is_paying_customer' => false, - 'meta_data' => array(), - 'last_name' => '', - 'role' => 'customer', - 'username' => 'get_customer_test', - 'avatar_url' => $data['avatar_url'], - ), - $data - ); - } - - /** - * Test getting a single customer without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_customer_without_permission() { - wp_set_current_user( 0 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'get_customer_test_without_permission', 'test123', 'get_customer_test_without_permission@woo.local' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/customers/' . $customer->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single customer with an invalid ID. - * - * @since 3.5.0 - */ - public function test_get_customer_invalid_id() { - wp_set_current_user( 1 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/customers/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test updating a customer. - * - * @since 3.5.0 - */ - public function test_update_customer() { - wp_set_current_user( 1 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'update_customer_test', 'test123', 'update_customer_test@woo.local' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/customers/' . $customer->get_id() ) ); - $data = $response->get_data(); - $this->assertEquals( 'update_customer_test', $data['username'] ); - $this->assertEquals( 'update_customer_test@woo.local', $data['email'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/customers/' . $customer->get_id() ); - $request->set_body_params( - array( - 'email' => 'updated_email@woo.local', - 'first_name' => 'UpdatedTest', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'updated_email@woo.local', $data['email'] ); - $this->assertEquals( 'UpdatedTest', $data['first_name'] ); - } - - /** - * Test updating a customer without valid permissions. - * - * @since 3.5.0 - */ - public function test_update_customer_without_permission() { - wp_set_current_user( 0 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'update_customer_test_without_permission', 'test123', 'update_customer_test_without_permission@woo.local' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/customers/' . $customer->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a customer with an invalid ID. - * - * @since 3.5.0 - */ - public function test_update_customer_invalid_id() { - wp_set_current_user( 1 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/customers/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - - /** - * Test deleting a customer. - * - * @since 3.5.0 - */ - public function test_delete_customer() { - wp_set_current_user( 1 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'delete_customer_test', 'test123', 'delete_customer_test@woo.local' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/customers/' . $customer->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a customer with an invalid ID. - * - * @since 3.5.0 - */ - public function test_delete_customer_invalid_id() { - wp_set_current_user( 1 ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/customers/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test deleting a customer without valid permissions. - * - * @since 3.5.0 - */ - public function test_delete_customer_without_permission() { - wp_set_current_user( 0 ); - $customer = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'delete_customer_test_without_permission', 'test123', 'delete_customer_test_without_permission@woo.local' ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/customers/' . $customer->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test customer batch endpoint. - * - * @since 3.5.0 - */ - public function test_batch_customer() { - wp_set_current_user( 1 ); - - $customer_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer', 'test123', 'test_batch_customer@woo.local' ); - $customer_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer2', 'test123', 'test_batch_customer2@woo.local' ); - $customer_3 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer3', 'test123', 'test_batch_customer3@woo.local' ); - $customer_4 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer4', 'test123', 'test_batch_customer4@woo.local' ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/customers/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $customer_1->get_id(), - 'last_name' => 'McTest', - ), - ), - 'delete' => array( - $customer_2->get_id(), - $customer_3->get_id(), - ), - 'create' => array( - array( - 'username' => 'newuser', - 'password' => 'test123', - 'email' => 'newuser@woo.local', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'McTest', $data['update'][0]['last_name'] ); - $this->assertEquals( 'newuser', $data['create'][0]['username'] ); - $this->assertEmpty( $data['create'][0]['last_name'] ); - $this->assertEquals( $customer_2->get_id(), $data['delete'][0]['id'] ); - $this->assertEquals( $customer_3->get_id(), $data['delete'][1]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/customers' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test customer schema. - * - * @since 3.5.0 - */ - public function test_customer_schema() { - wp_set_current_user( 1 ); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/customers' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 16, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'date_modified', $properties ); - $this->assertArrayHasKey( 'date_modified_gmt', $properties ); - $this->assertArrayHasKey( 'email', $properties ); - $this->assertArrayHasKey( 'first_name', $properties ); - $this->assertArrayHasKey( 'last_name', $properties ); - $this->assertArrayHasKey( 'role', $properties ); - $this->assertArrayHasKey( 'username', $properties ); - $this->assertArrayHasKey( 'password', $properties ); - $this->assertArrayHasKey( 'avatar_url', $properties ); - $this->assertArrayHasKey( 'billing', $properties ); - $this->assertArrayHasKey( 'first_name', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'last_name', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'company', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'address_1', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'address_2', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'city', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'state', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'postcode', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'country', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'email', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'phone', $properties['billing']['properties'] ); - $this->assertArrayHasKey( 'shipping', $properties ); - $this->assertArrayHasKey( 'first_name', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'last_name', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'company', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'address_1', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'address_2', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'city', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'state', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'postcode', $properties['shipping']['properties'] ); - $this->assertArrayHasKey( 'country', $properties['shipping']['properties'] ); - } -} diff --git a/unit-tests/Tests/Version3/functions.php b/unit-tests/Tests/Version3/functions.php deleted file mode 100644 index 3b3b27eb5c9..00000000000 --- a/unit-tests/Tests/Version3/functions.php +++ /dev/null @@ -1,251 +0,0 @@ -http_responder = array( $this, 'mock_http_responses' ); - - $upload_dir_info = wp_upload_dir(); - $this->upload_dir_path = $upload_dir_info['path']; - $this->upload_dir_url = $upload_dir_info['url']; - $this->file_name = 'Dr1Bczxq4q.png'; - } - - /** - * Run tear down code for unit tests. - */ - public function tearDown() { - parent::tearDown(); - - // remove files created in the wc_rest_upload_image_from_url() tests. - $file_path = $this->upload_dir_path . '/' . $this->file_name; - - if ( file_exists( $file_path ) ) { - unlink( $file_path ); - } - } - - /** - * Test wc_rest_prepare_date_response(). - * - * @since 2.6.0 - */ - public function test_wc_rest_prepare_date_response() { - $this->assertEquals( '2016-06-06T06:06:06', wc_rest_prepare_date_response( '2016-06-06 06:06:06' ) ); - } - - /** - * Test wc_rest_upload_image_from_url() should return error when unable to download image. - */ - public function test_wc_rest_upload_image_from_url_should_return_error_when_unable_to_download_image() { - $expected_error_message = 'Error getting remote image http://somedomain.com/nonexistent-image.png. Error: Not found.'; - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/nonexistent-image.png' ); - - $this->assertWPError( $result ); - $this->assertEquals( $expected_error_message, $result->get_error_message() ); - } - - /** - * Test wc_rest_upload_image_from_url() should return error when invalid image is passed. - * - * @requires PHP 5.4 - */ - public function test_wc_rest_upload_image_from_url_should_return_error_when_invalid_image_is_passed() { - // empty file. - $expected_error_message = 'Invalid image: File is empty.'; - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/invalid-image-1.png' ); - - $this->assertWPError( $result ); - $this->assertStringStartsWith( $expected_error_message, $result->get_error_message() ); - - // unsupported mime type. - $expected_error_message = 'Invalid image: Sorry, this file type is not permitted for security reasons.'; - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/invalid-image-2.png' ); - - $this->assertWPError( $result ); - $this->assertEquals( $expected_error_message, $result->get_error_message() ); - } - - /** - * Test wc_rest_upload_image_from_url() should download image and return an array containing - * information about it. - * - * @requires PHP 5.4 - */ - public function test_wc_rest_upload_image_from_url_should_download_image_and_return_array() { - $expected_result = array( - 'file' => $this->upload_dir_path . '/' . $this->file_name, - 'url' => $this->upload_dir_url . '/' . $this->file_name, - 'type' => 'image/png', - ); - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/' . $this->file_name ); - - $this->assertEquals( $expected_result, $result ); - } - - /** - * Test wc_rest_set_uploaded_image_as_attachment(). - * - * @since 2.6.0 - */ - public function test_wc_rest_set_uploaded_image_as_attachment() { - $this->assertInternalType( - 'int', - wc_rest_set_uploaded_image_as_attachment( - array( - 'file' => '', - 'url' => '', - ) - ) - ); - } - - /** - * Test wc_rest_validate_reports_request_arg(). - * - * @since 2.6.0 - */ - public function test_wc_rest_validate_reports_request_arg() { - $request = new WP_REST_Request( - 'GET', - '/wc/v3/foo', - array( - 'args' => array( - 'date' => array( - 'type' => 'string', - 'format' => 'date', - ), - ), - ) - ); - - // Success. - $this->assertTrue( wc_rest_validate_reports_request_arg( '2016-06-06', $request, 'date' ) ); - - // Error. - $error = wc_rest_validate_reports_request_arg( 'foo', $request, 'date' ); - $this->assertEquals( 'The date you provided is invalid.', $error->get_error_message() ); - } - - /** - * Test wc_rest_urlencode_rfc3986(). - * - * @since 2.6.0 - */ - public function test_wc_rest_urlencode_rfc3986() { - $this->assertEquals( 'https%3A%2F%2Fwoocommerce.com%2F', wc_rest_urlencode_rfc3986( 'https://woocommerce.com/' ) ); - } - - /** - * Test wc_rest_check_post_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_post_permissions() { - $this->assertFalse( wc_rest_check_post_permissions( 'shop_order' ) ); - } - - /** - * Test wc_rest_check_user_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_user_permissions() { - $this->assertFalse( wc_rest_check_user_permissions() ); - } - - /** - * Test wc_rest_check_product_term_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_product_term_permissions() { - $this->assertFalse( wc_rest_check_product_term_permissions( 'product_cat' ) ); - } - - /** - * Test wc_rest_check_manager_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_manager_permissions() { - $this->assertFalse( wc_rest_check_manager_permissions( 'reports' ) ); - } - - /** - * Helper method to define mocked HTTP responses using WP_HTTP_TestCase. - * Thanks to WP_HTTP_TestCase, it is not necessary to perform a regular request - * to an external server which would significantly slow down the tests. - * - * This function is called by WP_HTTP_TestCase::http_request_listner(). - * - * @param array $request Request arguments. - * @param string $url URL of the request. - * - * @return array|false mocked response or false to let WP perform a regular request. - */ - protected function mock_http_responses( $request, $url ) { - $mocked_response = false; - - if ( 'http://somedomain.com/nonexistent-image.png' === $url ) { - $mocked_response = array( - 'response' => array( - 'code' => 404, - 'message' => 'Not found.', - ), - ); - } elseif ( 'http://somedomain.com/invalid-image-1.png' === $url ) { - // empty image. - $mocked_response = array( - 'response' => array( 'code' => 200 ), - ); - } elseif ( 'http://somedomain.com/invalid-image-2.png' === $url ) { - // image with an unsupported mime type. - // we need to manually copy the file as we are mocking the request. without this an empty file is created. - copy( Automattic\WooCommerce\RestApi\UnitTests\Bootstrap::instance()->get_dir() . '/data/file.txt', $request['filename'] ); - - $mocked_response = array( - 'response' => array( 'code' => 200 ), - ); - } elseif ( 'http://somedomain.com/' . $this->file_name === $url ) { - // we need to manually copy the file as we are mocking the request. without this an empty file is created. - copy( Automattic\WooCommerce\RestApi\UnitTests\Bootstrap::instance()->get_dir() . '/data/Dr1Bczxq4q.png', $request['filename'] ); - - $mocked_response = array( - 'response' => array( 'code' => 200 ), - ); - } - - return $mocked_response; - } -} diff --git a/unit-tests/Tests/Version3/orders.php b/unit-tests/Tests/Version3/orders.php deleted file mode 100644 index 6ebb7477ae0..00000000000 --- a/unit-tests/Tests/Version3/orders.php +++ /dev/null @@ -1,778 +0,0 @@ -endpoint = new WC_REST_Orders_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/orders', $routes ); - $this->assertArrayHasKey( '/wc/v3/orders/batch', $routes ); - $this->assertArrayHasKey( '/wc/v3/orders/(?P[\d]+)', $routes ); - } - - /** - * Test getting all orders. - * @since 3.5.0 - */ - public function test_get_items() { - wp_set_current_user( $this->user ); - - // Create 10 orders. - for ( $i = 0; $i < 10; $i++ ) { - $this->orders[] = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $this->user ); - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders' ) ); - $orders = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 10, count( $orders ) ); - } - - /** - * Test getting all orders sorted by modified date. - */ - public function test_get_items_ordered_by_modified() { - wp_set_current_user( $this->user ); - - $order1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $this->user ); - $order2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $this->user ); - - $order1->set_status( 'completed' ); - $order1->save(); - sleep( 1 ); - $order2->set_status( 'completed' ); - $order2->save(); - - $request = new WP_REST_Request( 'GET', '/wc/v3/orders' ); - $request->set_query_params( array( 'orderby' => 'modified', 'order' => 'asc' ) ); - $response = $this->server->dispatch( $request ); - $orders = $response->get_data(); - $this->assertEquals( $order1->get_id(), $orders[0]['id'] ); - - $request->set_query_params( array( 'orderby' => 'modified', 'order' => 'desc' ) ); - $response = $this->server->dispatch( $request ); - $orders = $response->get_data(); - $this->assertEquals( $order2->get_id(), $orders[0]['id'] ); - } - - /** - * Tests to make sure orders cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_items_without_permission() { - wp_set_current_user( 0 ); - $this->orders[] = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a single order. - * @since 3.5.0 - */ - public function test_get_item() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order->add_meta_data( 'key', 'value' ); - $order->add_meta_data( 'key2', 'value2' ); - $order->save(); - $this->orders[] = $order; - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/' . $order->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $order->get_id(), $data['id'] ); - - // Test meta data is set. - $this->assertEquals( 'key', $data['meta_data'][0]->key ); - $this->assertEquals( 'value', $data['meta_data'][0]->value ); - $this->assertEquals( 'key2', $data['meta_data'][1]->key ); - $this->assertEquals( 'value2', $data['meta_data'][1]->value ); - } - - /** - * Tests getting a single order without the correct permissions. - * @since 3.5.0 - */ - public function test_get_item_without_permission() { - wp_set_current_user( 0 ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $this->orders[] = $order; - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/' . $order->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting an order with an invalid ID. - * @since 3.5.0 - */ - public function test_get_item_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/99999999' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests getting an order with an invalid ID. - * @since 3.5.0 - */ - public function test_get_item_refund_id() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $refund = wc_create_refund( - array( - 'order_id' => $order->get_id(), - ) - ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/' . $refund->get_id() ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests creating an order. - * @since 3.5.0 - */ - public function test_create_order() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => 'Direct Bank Transfer', - 'set_paid' => true, - 'billing' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - 'email' => 'john.doe@example.com', - 'phone' => '(555) 555-5555', - ), - 'shipping' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - ), - 'line_items' => array( - array( - 'product_id' => $product->get_id(), - 'quantity' => 2, - ), - ), - 'shipping_lines' => array( - array( - 'method_id' => 'flat_rate', - 'method_title' => 'Flat rate', - 'total' => '10.00', - 'instance_id' => '1', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $order = wc_get_order( $data['id'] ); - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); - $this->assertEquals( $order->get_payment_method_title(), $data['payment_method_title'] ); - $this->assertEquals( $order->get_billing_first_name(), $data['billing']['first_name'] ); - $this->assertEquals( $order->get_billing_last_name(), $data['billing']['last_name'] ); - $this->assertEquals( '', $data['billing']['company'] ); - $this->assertEquals( $order->get_billing_address_1(), $data['billing']['address_1'] ); - $this->assertEquals( $order->get_billing_address_2(), $data['billing']['address_2'] ); - $this->assertEquals( $order->get_billing_city(), $data['billing']['city'] ); - $this->assertEquals( $order->get_billing_state(), $data['billing']['state'] ); - $this->assertEquals( $order->get_billing_postcode(), $data['billing']['postcode'] ); - $this->assertEquals( $order->get_billing_country(), $data['billing']['country'] ); - $this->assertEquals( $order->get_billing_email(), $data['billing']['email'] ); - $this->assertEquals( $order->get_billing_phone(), $data['billing']['phone'] ); - $this->assertEquals( $order->get_shipping_first_name(), $data['shipping']['first_name'] ); - $this->assertEquals( $order->get_shipping_last_name(), $data['shipping']['last_name'] ); - $this->assertEquals( '', $data['shipping']['company'] ); - $this->assertEquals( $order->get_shipping_address_1(), $data['shipping']['address_1'] ); - $this->assertEquals( $order->get_shipping_address_2(), $data['shipping']['address_2'] ); - $this->assertEquals( $order->get_shipping_city(), $data['shipping']['city'] ); - $this->assertEquals( $order->get_shipping_state(), $data['shipping']['state'] ); - $this->assertEquals( $order->get_shipping_postcode(), $data['shipping']['postcode'] ); - $this->assertEquals( $order->get_shipping_country(), $data['shipping']['country'] ); - $this->assertEquals( 1, count( $data['line_items'] ) ); - $this->assertEquals( 1, count( $data['shipping_lines'] ) ); - $shipping = current( $order->get_items( 'shipping' ) ); - $expected = array( - 'id' => $shipping->get_id(), - 'method_title' => $shipping->get_method_title(), - 'method_id' => $shipping->get_method_id(), - 'instance_id' => $shipping->get_instance_id(), - 'total' => wc_format_decimal( $shipping->get_total(), '' ), - 'total_tax' => wc_format_decimal( $shipping->get_total_tax(), '' ), - 'taxes' => array(), - 'meta_data' => $shipping->get_meta_data(), - ); - $this->assertEquals( $expected, $data['shipping_lines'][0] ); - } - - /** - * Test the sanitization of the payment_method_title field through the API. - * - * @since 3.5.2 - */ - public function test_create_update_order_payment_method_title_sanitize() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - // Test when creating order. - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => '

Sanitize this

', - 'set_paid' => true, - 'billing' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - 'email' => 'john.doe@example.com', - 'phone' => '(555) 555-5555', - ), - 'shipping' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - ), - 'line_items' => array( - array( - 'product_id' => $product->get_id(), - 'quantity' => 2, - ), - ), - 'shipping_lines' => array( - array( - 'method_id' => 'flat_rate', - 'method_title' => 'Flat rate', - 'total' => '10', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $order = wc_get_order( $data['id'] ); - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); - $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this' ); - - // Test when updating order. - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $data['id'] ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => '

Sanitize this too

', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $order = wc_get_order( $data['id'] ); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); - $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this too' ); - } - - /** - * Tests creating an order without required fields. - * @since 3.5.0 - */ - public function test_create_order_invalid_fields() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - // Non-existent customer. - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); - $request->set_body_params( - array( - 'payment_method' => 'bacs', - 'payment_method_title' => 'Direct Bank Transfer', - 'set_paid' => true, - 'customer_id' => 99999, - 'billing' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - 'email' => 'john.doe@example.com', - 'phone' => '(555) 555-5555', - ), - 'shipping' => array( - 'first_name' => 'John', - 'last_name' => 'Doe', - 'address_1' => '969 Market', - 'address_2' => '', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postcode' => '94103', - 'country' => 'US', - ), - 'line_items' => array( - array( - 'product_id' => $product->get_id(), - 'quantity' => 2, - ), - ), - 'shipping_lines' => array( - array( - 'method_id' => 'flat_rate', - 'method_title' => 'Flat rate', - 'total' => 10, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests create an order with an invalid product. - * - * @since 3.9.0 - */ - public function test_create_order_with_invalid_product() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); - $request->set_body_params( - array( - 'line_items' => array( - array( - 'quantity' => 2, - ), - ), - ) - ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'woocommerce_rest_required_product_reference', $data['code'] ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests updating an order. - * - * @since 3.5.0 - */ - public function test_update_order() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); - $request->set_body_params( - array( - 'payment_method' => 'test-update', - 'billing' => array( - 'first_name' => 'Fish', - 'last_name' => 'Face', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'test-update', $data['payment_method'] ); - $this->assertEquals( 'Fish', $data['billing']['first_name'] ); - $this->assertEquals( 'Face', $data['billing']['last_name'] ); - } - - /** - * Tests updating an order and removing items. - * - * @since 3.5.0 - */ - public function test_update_order_remove_items() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $fee = new WC_Order_Item_Fee(); - $fee->set_props( - array( - 'name' => 'Some Fee', - 'tax_status' => 'taxable', - 'total' => '100', - 'tax_class' => '', - ) - ); - $order->add_item( $fee ); - $order->save(); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); - $fee_data = current( $order->get_items( 'fee' ) ); - - $request->set_body_params( - array( - 'fee_lines' => array( - array( - 'id' => $fee_data->get_id(), - 'name' => null, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertTrue( empty( $data['fee_lines'] ) ); - } - - /** - * Tests updating an order after deleting a product. - * - * @since 3.9.0 - */ - public function test_update_order_after_delete_product() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( 1, $product ); - $product->delete( true ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); - $line_items = $order->get_items( 'line_item' ); - $item = current( $line_items ); - - $request->set_body_params( - array( - 'line_items' => array( - array( - 'id' => $item->get_id(), - 'quantity' => 10, - ), - ), - ) - ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $expected = array( - 'id' => $item->get_id(), - 'name' => 'Dummy Product', - 'product_id' => 0, - 'variation_id' => 0, - 'quantity' => 10, - 'tax_class' => '', - 'subtotal' => '40.00', - 'subtotal_tax' => '0.00', - 'total' => '40.00', - 'total_tax' => '0.00', - 'taxes' => array(), - 'meta_data' => array(), - 'sku' => null, - 'price' => 4, - ); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $expected, $data['line_items'][0] ); - } - - /** - * Tests updating an order and adding a coupon. - * - * @since 3.5.0 - */ - public function test_update_order_add_coupons() { - wp_set_current_user( $this->user ); - - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order_item = current( $order->get_items() ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' ); - $coupon->set_amount( 5 ); - $coupon->save(); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); - $request->set_body_params( - array( - 'coupon_lines' => array( - array( - 'code' => 'fake-coupon', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertCount( 1, $data['coupon_lines'] ); - $this->assertEquals( '45.00', $data['total'] ); - } - - /** - * Tests updating an order and removing a coupon. - * - * @since 3.5.0 - */ - public function test_update_order_remove_coupons() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order_item = current( $order->get_items() ); - $coupon = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' ); - $coupon->set_amount( 5 ); - $coupon->save(); - - $order->apply_coupon( $coupon ); - $order->save(); - - // Check that the coupon is applied. - $this->assertEquals( '45.00', $order->get_total() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); - $coupon_data = current( $order->get_items( 'coupon' ) ); - - $request->set_body_params( - array( - 'coupon_lines' => array( - array( - 'id' => $coupon_data->get_id(), - 'code' => null, - ), - ), - 'line_items' => array( - array( - 'id' => $order_item->get_id(), - 'product_id' => $order_item->get_product_id(), - 'total' => '40.00', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertTrue( empty( $data['coupon_lines'] ) ); - $this->assertEquals( '50.00', $data['total'] ); - } - - /** - * Tests updating an order with an invalid coupon. - * - * @since 3.5.0 - */ - public function test_invalid_coupon() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); - - $request->set_body_params( - array( - 'coupon_lines' => array( - array( - 'code' => 'NON_EXISTING_COUPON', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - $this->assertEquals( 'woocommerce_rest_invalid_coupon', $data['code'] ); - $this->assertEquals( 'Coupon "non_existing_coupon" does not exist!', $data['message'] ); - } - - /** - * Tests updating an order without the correct permissions. - * - * @since 3.5.0 - */ - public function test_update_order_without_permission() { - wp_set_current_user( 0 ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); - $request->set_body_params( - array( - 'payment_method' => 'test-update', - 'billing' => array( - 'first_name' => 'Fish', - 'last_name' => 'Face', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests that updating an order with an invalid id fails. - * - * @since 3.5.0 - */ - public function test_update_order_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'POST', '/wc/v3/orders/999999' ); - $request->set_body_params( - array( - 'payment_method' => 'test-update', - 'billing' => array( - 'first_name' => 'Fish', - 'last_name' => 'Face', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test deleting an order. - * - * @since 3.5.0 - */ - public function test_delete_order() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/orders/' . $order->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( null, get_post( $order->get_id() ) ); - } - - /** - * Test deleting an order without permission/creds. - * - * @since 3.5.0 - */ - public function test_delete_order_without_permission() { - wp_set_current_user( 0 ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/orders/' . $order->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting an order with an invalid id. - * - * @since 3.5.0 - */ - public function test_delete_order_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/orders/9999999' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test batch managing product reviews. - * - * @since 3.5.0 - */ - public function test_orders_batch() { - wp_set_current_user( $this->user ); - - $order1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $order3 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - - $request = new WP_REST_Request( 'POST', '/wc/v3/orders/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $order1->get_id(), - 'payment_method' => 'updated', - ), - ), - 'delete' => array( - $order2->get_id(), - $order3->get_id(), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'updated', $data['update'][0]['payment_method'] ); - $this->assertEquals( $order2->get_id(), $data['delete'][0]['id'] ); - $this->assertEquals( $order3->get_id(), $data['delete'][1]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/orders' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 1, count( $data ) ); - } - - /** - * Test the order schema. - * - * @since 3.5.0 - */ - public function test_order_schema() { - wp_set_current_user( $this->user ); - $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/orders/' . $order->get_id() ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 42, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/payment-gateways.php b/unit-tests/Tests/Version3/payment-gateways.php deleted file mode 100644 index f9a43b64e5f..00000000000 --- a/unit-tests/Tests/Version3/payment-gateways.php +++ /dev/null @@ -1,345 +0,0 @@ -endpoint = new WC_REST_Payment_Gateways_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/payment_gateways', $routes ); - $this->assertArrayHasKey( '/wc/v3/payment_gateways/(?P[\w-]+)', $routes ); - } - - /** - * Test getting all payment gateways. - * - * @since 3.5.0 - */ - public function test_get_payment_gateways() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways' ) ); - $gateways = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertContains( - array( - 'id' => 'cheque', - 'title' => 'Check payments', - 'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', - 'order' => '', - 'enabled' => false, - 'method_title' => 'Check payments', - 'method_description' => 'Take payments in person via checks. This offline gateway can also be useful to test purchases.', - 'method_supports' => array( - 'products', - ), - 'settings' => array_diff_key( - $this->get_settings( 'WC_Gateway_Cheque' ), - array( - 'enabled' => false, - 'description' => false, - ) - ), - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/payment_gateways/cheque' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/payment_gateways' ), - ), - ), - ), - ), - $gateways - ); - } - - /** - * Tests to make sure payment gateways cannot viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_payment_gateways_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single payment gateway. - * - * @since 3.5.0 - */ - public function test_get_payment_gateway() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/paypal' ) ); - $paypal = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => 'paypal', - 'title' => 'PayPal', - 'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.", - 'order' => '', - 'enabled' => false, - 'method_title' => 'PayPal', - 'method_description' => 'PayPal Standard redirects customers to PayPal to enter their payment information.', - 'method_supports' => array( - 'products', - 'refunds', - ), - 'settings' => array_diff_key( - $this->get_settings( 'WC_Gateway_Paypal' ), - array( - 'enabled' => false, - 'description' => false, - ) - ), - ), - $paypal - ); - } - - /** - * Test getting a payment gateway without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_payment_gateway_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/paypal' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a payment gateway with an invalid id. - * - * @since 3.5.0 - */ - public function test_get_payment_gateway_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/totally_fake_method' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test updating a single payment gateway. - * - * @since 3.5.0 - */ - public function test_update_payment_gateway() { - wp_set_current_user( $this->user ); - - // Test defaults - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/paypal' ) ); - $paypal = $response->get_data(); - - $this->assertEquals( 'PayPal', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'admin@example.org', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'no', $paypal['settings']['testmode']['value'] ); - - // test updating single setting - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'email' => 'woo@woo.local', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'PayPal', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'woo@woo.local', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'no', $paypal['settings']['testmode']['value'] ); - - // test updating multiple settings - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'testmode' => 'yes', - 'title' => 'PayPal - New Title', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'PayPal - New Title', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'woo@woo.local', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'yes', $paypal['settings']['testmode']['value'] ); - - // Test other parameters, and recheck settings - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'enabled' => false, - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - - $this->assertFalse( $paypal['enabled'] ); - $this->assertEquals( 2, $paypal['order'] ); - $this->assertEquals( 'PayPal - New Title', $paypal['settings']['title']['value'] ); - $this->assertEquals( 'woo@woo.local', $paypal['settings']['email']['value'] ); - $this->assertEquals( 'yes', $paypal['settings']['testmode']['value'] ); - - // test bogus - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'paymentaction' => 'afasfasf', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'paymentaction' => 'authorization', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $paypal = $response->get_data(); - $this->assertEquals( 'authorization', $paypal['settings']['paymentaction']['value'] ); - } - - /** - * Test updating a payment gateway without valid permissions. - * - * @since 3.5.0 - */ - public function test_update_payment_gateway_without_permission() { - wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); - $request->set_body_params( - array( - 'settings' => array( - 'testmode' => 'yes', - 'title' => 'PayPal - New Title', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a payment gateway with an invalid id. - * - * @since 3.5.0 - */ - public function test_update_payment_gateway_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/totally_fake_method' ); - $request->set_body_params( - array( - 'enabled' => true, - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test the payment gateway schema. - * - * @since 3.5.0 - */ - public function test_payment_gateway_schema() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/payment_gateways' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 9, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'title', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'order', $properties ); - $this->assertArrayHasKey( 'enabled', $properties ); - $this->assertArrayHasKey( 'method_title', $properties ); - $this->assertArrayHasKey( 'method_description', $properties ); - $this->assertArrayHasKey( 'method_supports', $properties ); - $this->assertArrayHasKey( 'settings', $properties ); - } - - /** - * Loads a particular gateway's settings so we can correctly test API output. - * - * @since 3.5.0 - * @param string $gateway_class Name of WC_Payment_Gateway class. - */ - private function get_settings( $gateway_class ) { - $gateway = new $gateway_class(); - $settings = array(); - $gateway->init_form_fields(); - foreach ( $gateway->form_fields as $id => $field ) { - // Make sure we at least have a title and type - if ( empty( $field['title'] ) || empty( $field['type'] ) ) { - continue; - } - // Ignore 'enabled' and 'description', to be in line with \WC_REST_Payment_Gateways_Controller::get_settings. - if ( in_array( $id, array( 'enabled', 'description' ), true ) ) { - continue; - } - $data = array( - 'id' => $id, - 'label' => empty( $field['label'] ) ? $field['title'] : $field['label'], - 'description' => empty( $field['description'] ) ? '' : $field['description'], - 'type' => $field['type'], - 'value' => $gateway->settings[ $id ], - 'default' => empty( $field['default'] ) ? '' : $field['default'], - 'tip' => empty( $field['description'] ) ? '' : $field['description'], - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], - ); - if ( ! empty( $field['options'] ) ) { - $data['options'] = $field['options']; - } - $settings[ $id ] = $data; - } - return $settings; - } - -} diff --git a/unit-tests/Tests/Version3/product-reviews.php b/unit-tests/Tests/Version3/product-reviews.php deleted file mode 100644 index 9a69f06a863..00000000000 --- a/unit-tests/Tests/Version3/product-reviews.php +++ /dev/null @@ -1,470 +0,0 @@ -user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/products/reviews', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/reviews/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/reviews/batch', $routes ); - } - - /** - * Test getting all product reviews. - * - * @since 3.5.0 - */ - public function test_get_product_reviews() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - // Create 10 products reviews for the product - for ( $i = 0; $i < 10; $i++ ) { - $review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); - $product_reviews = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 10, count( $product_reviews ) ); - $this->assertContains( - array( - 'id' => $review_id, - 'date_created' => $product_reviews[0]['date_created'], - 'date_created_gmt' => $product_reviews[0]['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => "

Review content here

\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $product_reviews[0]['reviewer_avatar_urls'], - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews/' . $review_id ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews' ), - ), - ), - 'up' => array( - array( - 'href' => rest_url( '/wc/v3/products/' . $product->get_id() ), - ), - ), - ), - ), - $product_reviews - ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_product_reviews_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests to make sure an error is returned when an invalid product is loaded. - * - * @since 3.5.0 - */ - public function test_get_product_reviews_invalid_product() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/0/reviews' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests getting a single product review. - * - * @since 3.5.0 - */ - public function test_get_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $product_review_id, - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => "

Review content here

\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests getting a single product review without the correct permissions. - * - * @since 3.5.0 - */ - public function test_get_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a product review with an invalid ID. - * - * @since 3.5.0 - */ - public function test_get_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests creating a product review. - * - * @since 3.5.0 - */ - public function test_create_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'rating' => '5', - 'product_id' => $product->get_id(), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => 'Hello world.', - 'rating' => 5, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests creating a product review without required fields. - * - * @since 3.5.0 - */ - public function test_create_product_review_invalid_fields() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - // missing review - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // Missing reviewer. - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // missing reviewer_email - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests updating a product review. - * - * @since 3.5.0 - */ - public function test_update_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - $this->assertEquals( "

Review content here

\n", $data['review'] ); - $this->assertEquals( 'admin', $data['reviewer'] ); - $this->assertEquals( 'woo@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 0, $data['rating'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world - updated.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo2@woo.local', - 'rating' => 3, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'Hello world - updated.', $data['review'] ); - $this->assertEquals( 'Justin', $data['reviewer'] ); - $this->assertEquals( 'woo2@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 3, $data['rating'] ); - } - - /** - * Tests updating a product review without the correct permissions. - * - * @since 3.5.0 - */ - public function test_update_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests that updating a product review with an invalid id fails. - * - * @since 3.5.0 - */ - public function test_update_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/0' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test deleting a product review. - * - * @since 3.5.0 - */ - public function test_delete_product_review() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a product review without permission/creds. - * - * @since 3.5.0 - */ - public function test_delete_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a product review with an invalid id. - * - * @since 3.5.0 - */ - public function test_delete_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_review_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test batch managing product reviews. - * - * @since 3.5.0 - */ - public function test_product_reviews_batch() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - $review_1_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $review_2_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $review_3_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - $review_4_id = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $review_1_id, - 'review' => 'Updated review.', - ), - ), - 'delete' => array( - $review_2_id, - $review_3_id, - ), - 'create' => array( - array( - 'review' => 'New review.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo3@woo.local', - 'product_id' => $product->get_id(), - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'Updated review.', $data['update'][0]['review'] ); - $this->assertEquals( 'New review.', $data['create'][0]['review'] ); - $this->assertEquals( $review_2_id, $data['delete'][0]['previous']['id'] ); - $this->assertEquals( $review_3_id, $data['delete'][1]['previous']['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ); - $request->set_param( 'product', $product->get_id() ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test the product review schema. - * - * @since 3.5.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/reviews' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 11, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'product_id', $properties ); - $this->assertArrayHasKey( 'status', $properties ); - $this->assertArrayHasKey( 'reviewer', $properties ); - $this->assertArrayHasKey( 'reviewer_email', $properties ); - $this->assertArrayHasKey( 'review', $properties ); - $this->assertArrayHasKey( 'rating', $properties ); - $this->assertArrayHasKey( 'verified', $properties ); - - if ( get_option( 'show_avatars' ) ) { - $this->assertArrayHasKey( 'reviewer_avatar_urls', $properties ); - } - } -} diff --git a/unit-tests/Tests/Version3/product-variations.php b/unit-tests/Tests/Version3/product-variations.php deleted file mode 100644 index 98bfda23c6b..00000000000 --- a/unit-tests/Tests/Version3/product-variations.php +++ /dev/null @@ -1,496 +0,0 @@ -endpoint = new WC_REST_Product_Variations_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/products/(?P[\d]+)/variations', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/(?P[\d]+)/variations/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/(?P[\d]+)/variations/batch', $routes ); - } - - /** - * Test getting variations. - * - * @since 3.5.0 - */ - public function test_get_variations() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $variations ) ); - $this->assertEquals( 'DUMMY SKU VARIABLE LARGE', $variations[0]['sku'] ); - $this->assertEquals( 'size', $variations[0]['attributes'][0]['name'] ); - } - - /** - * Test getting variations with an orderby clause. - * - * @since 3.9.0 - */ - public function test_get_variations_with_orderby() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $request = new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ); - $request->set_query_params( array( 'orderby' => 'menu_order' ) ); - $response = $this->server->dispatch( $request ); - $variations = $response->get_data(); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $variations ) ); - $this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variations[0]['sku'] ); - $this->assertEquals( 'size', $variations[0]['attributes'][0]['name'] ); - } - - /** - * Test getting variations without permission. - * - * @since 3.5.0 - */ - public function test_get_variations_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single variation. - * - * @since 3.5.0 - */ - public function test_get_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ) ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $variation_id, $variation['id'] ); - $this->assertEquals( 'size', $variation['attributes'][0]['name'] ); - } - - /** - * Test getting single variation without permission. - * - * @since 3.5.0 - */ - public function test_get_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single variation. - * - * @since 3.5.0 - */ - public function test_delete_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 1, count( $variations ) ); - } - - /** - * Test deleting a single variation without permission. - * - * @since 3.5.0 - */ - public function test_delete_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single variation with an invalid ID. - * - * @since 3.5.0 - */ - public function test_delete_variation_with_invalid_id() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test editing a single variation. - * - * @since 3.5.0 - */ - public function test_update_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ) ); - $variation = $response->get_data(); - - $this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variation['sku'] ); - $this->assertEquals( 10, $variation['regular_price'] ); - $this->assertEmpty( $variation['sale_price'] ); - $this->assertEquals( 'small', $variation['attributes'][0]['option'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'sku' => 'FIXED-\'SKU', - 'sale_price' => '8', - 'description' => 'O_O', - 'image' => array( - 'position' => 0, - 'src' => 'http://cldup.com/Dr1Bczxq4q.png', - 'alt' => 'test upload image', - ), - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertTrue( isset( $variation['description'] ), print_r( $variation, true ) ); - $this->assertContains( 'O_O', $variation['description'], print_r( $variation, true ) ); - $this->assertEquals( '8', $variation['price'], print_r( $variation, true ) ); - $this->assertEquals( '8', $variation['sale_price'], print_r( $variation, true ) ); - $this->assertEquals( '10', $variation['regular_price'], print_r( $variation, true ) ); - $this->assertEquals( 'FIXED-\'SKU', $variation['sku'], print_r( $variation, true ) ); - $this->assertEquals( 'medium', $variation['attributes'][0]['option'], print_r( $variation, true ) ); - $this->assertContains( 'Dr1Bczxq4q', $variation['image']['src'], print_r( $variation, true ) ); - $this->assertContains( 'test upload image', $variation['image']['alt'], print_r( $variation, true ) ); - - wp_delete_attachment( $variation['image']['id'], true ); - } - - /** - * Test updating a single variation without permission. - * - * @since 3.5.0 - */ - public function test_update_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $variation_id = $children[0]; - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-NO-PERMISSION', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single variation with an invalid ID. - * - * @since 3.5.0 - */ - public function test_update_variation_with_invalid_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/0' ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-NO-PERMISSION', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating a single variation. - * - * @since 3.5.0 - */ - public function test_create_variation() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 2, count( $variations ) ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products/' . $product->get_id() . '/variations' ); - $request->set_body_params( - array( - 'sku' => 'DUMMY SKU VARIABLE MEDIUM', - 'regular_price' => '12', - 'description' => 'A medium size.', - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertContains( 'A medium size.', $variation['description'] ); - $this->assertEquals( '12', $variation['price'] ); - $this->assertEquals( '12', $variation['regular_price'] ); - $this->assertTrue( $variation['purchasable'] ); - $this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $variation['sku'] ); - $this->assertEquals( 'medium', $variation['attributes'][0]['option'] ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); - $variations = $response->get_data(); - $this->assertEquals( 3, count( $variations ) ); - } - - /** - * Test creating a single variation without permission. - * - * @since 3.5.0 - */ - public function test_create_variation_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products/' . $product->get_id() . '/variations' ); - $request->set_body_params( - array( - 'sku' => 'DUMMY SKU VARIABLE MEDIUM', - 'regular_price' => '12', - 'description' => 'A medium size.', - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test batch managing product variations. - * - * @since 3.5.0 - */ - public function test_product_variations_batch() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $children = $product->get_children(); - $request = new WP_REST_Request( 'POST', '/wc/v3/products/' . $product->get_id() . '/variations/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $children[0], - 'description' => 'Updated description.', - 'image' => array( - 'position' => 0, - 'src' => 'http://cldup.com/Dr1Bczxq4q.png', - 'alt' => 'test upload image', - ), - ), - ), - 'delete' => array( - $children[1], - ), - 'create' => array( - array( - 'sku' => 'DUMMY SKU VARIABLE MEDIUM', - 'regular_price' => '12', - 'description' => 'A medium size.', - 'attributes' => array( - array( - 'name' => 'pa_size', - 'option' => 'medium', - ), - ), - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertContains( 'Updated description.', $data['update'][0]['description'] ); - $this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku'] ); - $this->assertEquals( 'medium', $data['create'][0]['attributes'][0]['option'] ); - $this->assertEquals( $children[1], $data['delete'][0]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 2, count( $data ) ); - - wp_delete_attachment( $data[1]['image']['id'], true ); - } - - /** - * Test variation schema. - * - * @since 3.5.0 - */ - public function test_variation_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/' . $product->get_id() . '/variations' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 37, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_modified', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'permalink', $properties ); - $this->assertArrayHasKey( 'sku', $properties ); - $this->assertArrayHasKey( 'price', $properties ); - $this->assertArrayHasKey( 'regular_price', $properties ); - $this->assertArrayHasKey( 'sale_price', $properties ); - $this->assertArrayHasKey( 'date_on_sale_from', $properties ); - $this->assertArrayHasKey( 'date_on_sale_to', $properties ); - $this->assertArrayHasKey( 'on_sale', $properties ); - $this->assertArrayHasKey( 'purchasable', $properties ); - $this->assertArrayHasKey( 'virtual', $properties ); - $this->assertArrayHasKey( 'downloadable', $properties ); - $this->assertArrayHasKey( 'downloads', $properties ); - $this->assertArrayHasKey( 'download_limit', $properties ); - $this->assertArrayHasKey( 'download_expiry', $properties ); - $this->assertArrayHasKey( 'tax_status', $properties ); - $this->assertArrayHasKey( 'tax_class', $properties ); - $this->assertArrayHasKey( 'manage_stock', $properties ); - $this->assertArrayHasKey( 'stock_quantity', $properties ); - $this->assertArrayHasKey( 'stock_status', $properties ); - $this->assertArrayHasKey( 'backorders', $properties ); - $this->assertArrayHasKey( 'backorders_allowed', $properties ); - $this->assertArrayHasKey( 'backordered', $properties ); - $this->assertArrayHasKey( 'weight', $properties ); - $this->assertArrayHasKey( 'dimensions', $properties ); - $this->assertArrayHasKey( 'shipping_class', $properties ); - $this->assertArrayHasKey( 'shipping_class_id', $properties ); - $this->assertArrayHasKey( 'image', $properties ); - $this->assertArrayHasKey( 'attributes', $properties ); - $this->assertArrayHasKey( 'menu_order', $properties ); - $this->assertArrayHasKey( 'meta_data', $properties ); - } - - /** - * Test updating a variation stock. - * - * @since 3.5.0 - */ - public function test_update_variation_manage_stock() { - wp_set_current_user( $this->user ); - - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $product->set_manage_stock( false ); - $product->save(); - - $children = $product->get_children(); - $variation_id = $children[0]; - - // Set stock to true. - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'manage_stock' => true, - ) - ); - - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( true, $variation['manage_stock'] ); - - // Set stock to false. - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'manage_stock' => false, - ) - ); - - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( false, $variation['manage_stock'] ); - - // Set stock to false but parent is managing stock. - $product->set_manage_stock( true ); - $product->save(); - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); - $request->set_body_params( - array( - 'manage_stock' => false, - ) - ); - - $response = $this->server->dispatch( $request ); - $variation = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'parent', $variation['manage_stock'] ); - } -} diff --git a/unit-tests/Tests/Version3/products.php b/unit-tests/Tests/Version3/products.php deleted file mode 100644 index 22351897134..00000000000 --- a/unit-tests/Tests/Version3/products.php +++ /dev/null @@ -1,861 +0,0 @@ -endpoint = new WC_REST_Products_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/products', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/products/batch', $routes ); - } - - /** - * Test getting products. - * - * @since 3.5.0 - */ - public function test_get_products() { - wp_set_current_user( $this->user ); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); - sleep( 1 ); // So both products have different timestamps. - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); - $products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertEquals( 2, count( $products ) ); - $this->assertEquals( 'Dummy Product', $products[0]['name'] ); - $this->assertEquals( 'DUMMY SKU', $products[0]['sku'] ); - $this->assertEquals( 'Dummy External Product', $products[1]['name'] ); - $this->assertEquals( 'DUMMY EXTERNAL SKU', $products[1]['sku'] ); - } - - /** - * Test getting trashed products. - */ - public function test_get_trashed_products() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $data_store = WC_Data_Store::load( 'product' ); - $data_store->delete( $product ); - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); - $request->set_query_params( array( 'status' => 'trash' ) ); - $response = $this->server->dispatch( $request ); - $products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 1, count( $products ) ); - $this->assertEquals( $product->get_name(), $products[0]['name'] ); - $this->assertEquals( $product->get_id(), $products[0]['id'] ); - } - - /** - * Trashed products should not be returned by default. - */ - public function test_get_trashed_products_not_returned_by_default() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $data_store = WC_Data_Store::load( 'product' ); - $data_store->delete( $product ); - - $response = $this->server->dispatch( - new WP_REST_Request( 'GET', '/wc/v3/products' ) - ); - $products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 0, count( $products ) ); - } - - /** - * Trashed product can be fetched directly. - */ - public function test_get_trashed_products_returned_by_id() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $data_store = WC_Data_Store::load( 'product' ); - $data_store->delete( $product ); - - $response = $this->server->dispatch( - new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) - ); - - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test getting products without permission. - * - * @since 3.5.0 - */ - public function test_get_products_without_permission() { - wp_set_current_user( 0 ); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test getting a single product. - * - * @since 3.5.0 - */ - public function test_get_product() { - wp_set_current_user( $this->user ); - $simple = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $simple->get_id() ) ); - $product = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertContains( - array( - 'id' => $simple->get_id(), - 'name' => 'Dummy External Product', - 'type' => 'simple', - 'status' => 'publish', - 'sku' => 'DUMMY EXTERNAL SKU', - 'regular_price' => 10, - ), - $product - ); - } - - /** - * Test getting single product without permission. - * - * @since 3.5.0 - */ - public function test_get_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single product. - * - * @since 3.5.0 - */ - public function test_delete_product() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); - $variations = $response->get_data(); - $this->assertEquals( 0, count( $variations ) ); - } - - /** - * Test deleting a single product without permission. - * - * @since 3.5.0 - */ - public function test_delete_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a single product with an invalid ID. - * - * @since 3.5.0 - */ - public function test_delete_product_with_invalid_id() { - wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test editing a single product. Tests multiple product types. - * - * @since 3.5.0 - */ - public function test_update_product() { - wp_set_current_user( $this->user ); - - // test simple products. - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); - $data = $response->get_data(); - $date_created = date( 'Y-m-d\TH:i:s', current_time( 'timestamp' ) ); - - $this->assertEquals( 'DUMMY SKU', $data['sku'] ); - $this->assertEquals( 10, $data['regular_price'] ); - $this->assertEmpty( $data['sale_price'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU', - 'sale_price' => '8', - 'description' => 'Testing', - 'date_created' => $date_created, - 'images' => array( - array( - 'position' => 0, - 'src' => 'http://cldup.com/Dr1Bczxq4q.png', - 'alt' => 'test upload image', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertContains( 'Testing', $data['description'] ); - $this->assertEquals( '8', $data['price'] ); - $this->assertEquals( '8', $data['sale_price'] ); - $this->assertEquals( '10', $data['regular_price'] ); - $this->assertEquals( 'FIXED-SKU', $data['sku'] ); - $this->assertEquals( $date_created, $data['date_created'] ); - $this->assertContains( 'Dr1Bczxq4q', $data['images'][0]['src'] ); - $this->assertContains( 'test upload image', $data['images'][0]['alt'] ); - $product->delete( true ); - wp_delete_attachment( $data['images'][0]['id'], true ); - - // test variable product (variations are tested in product-variations.php). - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); - $data = $response->get_data(); - - foreach ( array( 'small', 'large' ) as $term_name ) { - $this->assertContains( $term_name, $data['attributes'][0]['options'] ); - } - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'attributes' => array( - array( - 'id' => 0, - 'name' => 'pa_color', - 'options' => array( - 'red', - 'yellow', - ), - 'visible' => false, - 'variation' => 1, - ), - array( - 'id' => 0, - 'name' => 'pa_size', - 'options' => array( - 'small', - ), - 'visible' => false, - 'variation' => 1, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( array( 'small' ), $data['attributes'][0]['options'] ); - - foreach ( array( 'red', 'yellow' ) as $term_name ) { - $this->assertContains( $term_name, $data['attributes'][1]['options'] ); - } - - $product->delete( true ); - - // test external product. - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 'Buy external product', $data['button_text'] ); - $this->assertEquals( 'http://woocommerce.com', $data['external_url'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'button_text' => 'Test API Update', - 'external_url' => 'http://automattic.com', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'Test API Update', $data['button_text'] ); - $this->assertEquals( 'http://automattic.com', $data['external_url'] ); - } - - /** - * Test updating a single product without permission. - * - * @since 3.5.0 - */ - public function test_update_product_without_permission() { - wp_set_current_user( 0 ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-NO-PERMISSION', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single product with an invalid ID. - * - * @since 3.5.0 - */ - public function test_update_product_with_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/0' ); - $request->set_body_params( - array( - 'sku' => 'FIXED-SKU-INVALID-ID', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Test creating a single product. - * - * @since 3.5.0 - */ - public function test_create_product() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products/shipping_classes' ); - $request->set_body_params( - array( - 'name' => 'Test', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $shipping_class_id = $data['id']; - - // Create simple. - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); - $request->set_body_params( - array( - 'type' => 'simple', - 'name' => 'Test Simple Product', - 'sku' => 'DUMMY SKU SIMPLE API', - 'regular_price' => '10', - 'shipping_class' => 'test', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '10', $data['price'] ); - $this->assertEquals( '10', $data['regular_price'] ); - $this->assertTrue( $data['purchasable'] ); - $this->assertEquals( 'DUMMY SKU SIMPLE API', $data['sku'] ); - $this->assertEquals( 'Test Simple Product', $data['name'] ); - $this->assertEquals( 'simple', $data['type'] ); - $this->assertEquals( $shipping_class_id, $data['shipping_class_id'] ); - - // Create external. - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); - $request->set_body_params( - array( - 'type' => 'external', - 'name' => 'Test External Product', - 'sku' => 'DUMMY SKU EXTERNAL API', - 'regular_price' => '10', - 'button_text' => 'Test Button', - 'external_url' => 'https://wordpress.org', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '10', $data['price'] ); - $this->assertEquals( '10', $data['regular_price'] ); - $this->assertFalse( $data['purchasable'] ); - $this->assertEquals( 'DUMMY SKU EXTERNAL API', $data['sku'] ); - $this->assertEquals( 'Test External Product', $data['name'] ); - $this->assertEquals( 'external', $data['type'] ); - $this->assertEquals( 'Test Button', $data['button_text'] ); - $this->assertEquals( 'https://wordpress.org', $data['external_url'] ); - - // Create variable. - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); - $request->set_body_params( - array( - 'type' => 'variable', - 'name' => 'Test Variable Product', - 'sku' => 'DUMMY SKU VARIABLE API', - 'attributes' => array( - array( - 'id' => 0, - 'name' => 'pa_size', - 'options' => array( - 'small', - 'medium', - ), - 'visible' => false, - 'variation' => 1, - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'DUMMY SKU VARIABLE API', $data['sku'] ); - $this->assertEquals( 'Test Variable Product', $data['name'] ); - $this->assertEquals( 'variable', $data['type'] ); - $this->assertEquals( array( 'small', 'medium' ), $data['attributes'][0]['options'] ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); - $products = $response->get_data(); - $this->assertEquals( 3, count( $products ) ); - } - - /** - * Test creating a single product without permission. - * - * @since 3.5.0 - */ - public function test_create_product_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); - $request->set_body_params( - array( - 'name' => 'Test Product', - 'regular_price' => '12', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test batch managing products. - * - * @since 3.5.0 - */ - public function test_products_batch() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v3/products/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $product->get_id(), - 'description' => 'Updated description.', - ), - ), - 'delete' => array( - $product_2->get_id(), - ), - 'create' => array( - array( - 'sku' => 'DUMMY SKU BATCH TEST 1', - 'regular_price' => '10', - 'name' => 'Test Batch Create 1', - 'type' => 'external', - 'button_text' => 'Test Button', - ), - array( - 'sku' => 'DUMMY SKU BATCH TEST 2', - 'regular_price' => '20', - 'name' => 'Test Batch Create 2', - 'type' => 'simple', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertContains( 'Updated description.', $data['update'][0]['description'] ); - $this->assertEquals( 'DUMMY SKU BATCH TEST 1', $data['create'][0]['sku'] ); - $this->assertEquals( 'DUMMY SKU BATCH TEST 2', $data['create'][1]['sku'] ); - $this->assertEquals( 'Test Button', $data['create'][0]['button_text'] ); - $this->assertEquals( 'external', $data['create'][0]['type'] ); - $this->assertEquals( 'simple', $data['create'][1]['type'] ); - $this->assertEquals( $product_2->get_id(), $data['delete'][0]['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Tests to make sure you can filter products post statuses by both - * the status query arg and WP_Query. - * - * @since 3.5.0 - */ - public function test_products_filter_post_status() { - wp_set_current_user( $this->user ); - for ( $i = 0; $i < 8; $i++ ) { - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - if ( 0 === $i % 2 ) { - wp_update_post( - array( - 'ID' => $product->get_id(), - 'post_status' => 'draft', - ) - ); - } - } - - // Test filtering with status=publish. - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); - $request->set_param( 'status', 'publish' ); - $response = $this->server->dispatch( $request ); - $products = $response->get_data(); - - $this->assertEquals( 4, count( $products ) ); - foreach ( $products as $product ) { - $this->assertEquals( 'publish', $product['status'] ); - } - - // Test filtering with status=draft. - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); - $request->set_param( 'status', 'draft' ); - $response = $this->server->dispatch( $request ); - $products = $response->get_data(); - - $this->assertEquals( 4, count( $products ) ); - foreach ( $products as $product ) { - $this->assertEquals( 'draft', $product['status'] ); - } - - // Test filtering with no filters - which should return 'any' (all 8). - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); - $response = $this->server->dispatch( $request ); - $products = $response->get_data(); - - $this->assertEquals( 8, count( $products ) ); - } - - /** - * Test product schema. - * - * @since 3.5.0 - */ - public function test_product_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/' . $product->get_id() ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 65, count( $properties ) ); - } - - /** - * Test product category. - * - * @since 3.5.0 - */ - public function test_get_products_by_category() { - wp_set_current_user( $this->user ); - - // Create one product with a category. - $category = wp_insert_term( 'Some Category', 'product_cat' ); - - $product = new WC_Product_Simple(); - $product->set_category_ids( array( $category['term_id'] ) ); - $product->save(); - - // Create one product without category, i.e. Uncategorized. - $product_2 = new WC_Product_Simple(); - $product_2->save(); - - // Test product assigned to a single category. - $query_params = array( - 'category' => (string) $category['term_id'], - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - foreach ( $response_products as $response_product ) { - $this->assertEquals( $product->get_id(), $response_product['id'] ); - $this->assertEquals( $product->get_category_ids(), wp_list_pluck( $response_product['categories'], 'id' ) ); - } - - // Test product without categories. - $request = new WP_REST_Request( 'GET', '/wc/v2/products/' . $product_2->get_id() ); - $response = $this->server->dispatch( $request ); - $response_product = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertCount( 1, $response_product['categories'], print_r( $response_product, true ) ); - $this->assertEquals( 'uncategorized', $response_product['categories'][0]['slug'] ); - - } - - /** - * Test getting products by product type. - * - * @since 3.5.0 - */ - public function test_get_products_by_type() { - wp_set_current_user( $this->user ); - - $simple = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $external = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); - $grouped = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_grouped_product(); - $variable = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - - $product_ids_for_type = array( - 'simple' => array( $simple->get_id() ), - 'external' => array( $external->get_id() ), - 'grouped' => array( $grouped->get_id() ), - 'variable' => array( $variable->get_id() ), - ); - - foreach ( $grouped->get_children() as $additional_product ) { - $product_ids_for_type['simple'][] = $additional_product; - } - - foreach ( $product_ids_for_type as $product_type => $product_ids ) { - $query_params = array( - 'type' => $product_type, - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $product_ids ), count( $response_products ) ); - foreach ( $response_products as $response_product ) { - $this->assertContains( $response_product['id'], $product_ids_for_type[ $product_type ], 'REST API: ' . $product_type . ' not found correctly' ); - } - } - } - - /** - * Test getting products by featured property. - * - * @since 3.5.0 - */ - public function test_get_featured_products() { - wp_set_current_user( $this->user ); - - // Create a featured product. - $feat_product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $feat_product->set_featured( true ); - $feat_product->save(); - - // Create a non-featured product. - $nonfeat_product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $nonfeat_product->save(); - - $query_params = array( - 'featured' => 'true', - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - foreach ( $response_products as $response_product ) { - $this->assertEquals( $feat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly' ); - } - - $query_params = array( - 'featured' => 'false', - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - foreach ( $response_products as $response_product ) { - $this->assertEquals( $nonfeat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly' ); - } - } - - /** - * Test getting products by shipping class property. - * - * @since 3.5.0 - */ - public function test_get_products_by_shipping_class() { - wp_set_current_user( $this->user ); - - $shipping_class_1 = wp_insert_term( 'Bulky', 'product_shipping_class' ); - - $product_1 = new WC_Product_Simple(); - $product_1->set_shipping_class_id( $shipping_class_1['term_id'] ); - $product_1->save(); - - $query_params = array( - 'shipping_class' => (string) $shipping_class_1['term_id'], - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - foreach ( $response_products as $response_product ) { - $this->assertEquals( $product_1->get_id(), $response_product['id'] ); - } - } - - /** - * Test getting products by tag. - * - * @since 3.5.0 - */ - public function test_get_products_by_tag() { - wp_set_current_user( $this->user ); - - $test_tag_1 = wp_insert_term( 'Tag 1', 'product_tag' ); - - // Product with a tag. - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product->set_tag_ids( array( $test_tag_1['term_id'] ) ); - $product->save(); - - // Product without a tag. - $product_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - $query_params = array( - 'tag' => (string) $test_tag_1['term_id'], - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - foreach ( $response_products as $response_product ) { - $this->assertEquals( $product->get_id(), $response_product['id'] ); - } - } - - /** - * Test getting products by global attribute. - * - * @since 3.5.0 - */ - public function test_get_products_by_attribute() { - global $wpdb; - wp_set_current_user( $this->user ); - - // Variable product with 2 different variations. - $variable_product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); - - // Terms created by variable product. - $term_large = get_term_by( 'slug', 'large', 'pa_size' ); - $term_small = get_term_by( 'slug', 'small', 'pa_size' ); - - // Simple product without attribute. - $product_1 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - - // Simple product with attribute size = large. - $product_2 = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $product_2->set_attributes( array( 'pa_size' => 'large' ) ); - $product_2->save(); - - // Link the product to the term. - $wpdb->insert( - $wpdb->prefix . 'term_relationships', - array( - 'object_id' => $product_2->get_id(), - 'term_taxonomy_id' => $term_large->term_id, - 'term_order' => 0, - ) - ); - - // Products with attribute size == large. - $expected_product_ids = array( - $variable_product->get_id(), - $product_2->get_id(), - ); - $query_params = array( - 'attribute' => 'pa_size', - 'attribute_term' => (string) $term_large->term_id, - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $expected_product_ids ), count( $response_products ) ); - foreach ( $response_products as $response_product ) { - $this->assertContains( $response_product['id'], $expected_product_ids ); - } - - // Products with attribute size == small. - $expected_product_ids = array( - $variable_product->get_id(), - ); - $query_params = array( - 'attribute' => 'pa_size', - 'attribute_term' => (string) $term_small->term_id, - ); - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $response_products = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $expected_product_ids ), count( $response_products ) ); - foreach ( $response_products as $response_product ) { - $this->assertContains( $response_product['id'], $expected_product_ids ); - } - } -} diff --git a/unit-tests/Tests/Version3/reports-coupons-totals.php b/unit-tests/Tests/Version3/reports-coupons-totals.php deleted file mode 100644 index 162b8af7ef7..00000000000 --- a/unit-tests/Tests/Version3/reports-coupons-totals.php +++ /dev/null @@ -1,103 +0,0 @@ -user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/reports/coupons/totals', $routes ); - } - - /** - * Test getting all product reviews. - * - * @since 3.5.0 - */ - public function test_get_reports() { - global $wpdb; - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/coupons/totals' ) ); - $report = $response->get_data(); - $types = wc_get_coupon_types(); - $data = array(); - - foreach ( $types as $slug => $name ) { - $results = $wpdb->get_results( - $wpdb->prepare( - " - SELECT count(meta_id) AS total - FROM $wpdb->postmeta - WHERE meta_key = 'discount_type' - AND meta_value = %s - ", - $slug - ) - ); - - $total = isset( $results[0] ) ? (int) $results[0]->total : 0; - - $data[] = array( - 'slug' => $slug, - 'name' => $name, - 'total' => $total, - ); - } - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $types ), count( $report ) ); - $this->assertEquals( $data, $report ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_reports_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/coupons/totals' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test the product review schema. - * - * @since 3.5.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/coupons/totals' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'slug', $properties ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'total', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/reports-customers-totals.php b/unit-tests/Tests/Version3/reports-customers-totals.php deleted file mode 100644 index cd0e58f886f..00000000000 --- a/unit-tests/Tests/Version3/reports-customers-totals.php +++ /dev/null @@ -1,119 +0,0 @@ -user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/reports/customers/totals', $routes ); - } - - /** - * Test getting all product reviews. - * - * @since 3.5.0 - */ - public function test_get_reports() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/customers/totals' ) ); - $report = $response->get_data(); - $users_count = count_users(); - $total_customers = 0; - - foreach ( $users_count['avail_roles'] as $role => $total ) { - if ( in_array( $role, array( 'administrator', 'shop_manager' ), true ) ) { - continue; - } - - $total_customers += (int) $total; - } - - $customers_query = new WP_User_Query( - array( - 'role__not_in' => array( 'administrator', 'shop_manager' ), - 'number' => 0, - 'fields' => 'ID', - 'count_total' => true, - 'meta_query' => array( // WPCS: slow query ok. - array( - 'key' => 'paying_customer', - 'value' => 1, - 'compare' => '=', - ), - ), - ) - ); - - $total_paying = (int) $customers_query->get_total(); - - $data = array( - array( - 'slug' => 'paying', - 'name' => __( 'Paying customer', 'woocommerce' ), - 'total' => $total_paying, - ), - array( - 'slug' => 'non_paying', - 'name' => __( 'Non-paying customer', 'woocommerce' ), - 'total' => $total_customers - $total_paying, - ), - ); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 2, count( $report ) ); - $this->assertEquals( $data, $report ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_reports_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/customers/totals' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test the product review schema. - * - * @since 3.5.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/customers/totals' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'slug', $properties ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'total', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/reports-orders-totals.php b/unit-tests/Tests/Version3/reports-orders-totals.php deleted file mode 100644 index 93a21a87634..00000000000 --- a/unit-tests/Tests/Version3/reports-orders-totals.php +++ /dev/null @@ -1,92 +0,0 @@ -user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/reports/orders/totals', $routes ); - } - - /** - * Test getting all product reviews. - * - * @since 3.5.0 - */ - public function test_get_reports() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/orders/totals' ) ); - $report = $response->get_data(); - $totals = wp_count_posts( 'shop_order' ); - $data = array(); - - foreach ( wc_get_order_statuses() as $slug => $name ) { - if ( ! isset( $totals->$slug ) ) { - continue; - } - - $data[] = array( - 'slug' => str_replace( 'wc-', '', $slug ), - 'name' => $name, - 'total' => (int) $totals->$slug, - ); - } - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( wc_get_order_statuses() ), count( $report ) ); - $this->assertEquals( $data, $report ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_reports_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/orders/totals' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test the product review schema. - * - * @since 3.5.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/orders/totals' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'slug', $properties ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'total', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/reports-products-totals.php b/unit-tests/Tests/Version3/reports-products-totals.php deleted file mode 100644 index 6243786ffad..00000000000 --- a/unit-tests/Tests/Version3/reports-products-totals.php +++ /dev/null @@ -1,99 +0,0 @@ -user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/reports/products/totals', $routes ); - } - - /** - * Test getting all product reviews. - * - * @since 3.5.0 - */ - public function test_get_reports() { - wp_set_current_user( $this->user ); - WC_Install::create_terms(); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/products/totals' ) ); - $report = $response->get_data(); - $types = wc_get_product_types(); - $terms = get_terms( - array( - 'taxonomy' => 'product_type', - 'hide_empty' => false, - ) - ); - $data = array(); - - foreach ( $terms as $product_type ) { - if ( ! isset( $types[ $product_type->name ] ) ) { - continue; - } - - $data[] = array( - 'slug' => $product_type->name, - 'name' => $types[ $product_type->name ], - 'total' => (int) $product_type->count, - ); - } - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $types ), count( $report ) ); - $this->assertEquals( $data, $report ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_reports_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/products/totals' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test the product review schema. - * - * @since 3.5.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/products/totals' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'slug', $properties ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'total', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/reports-reviews-totals.php b/unit-tests/Tests/Version3/reports-reviews-totals.php deleted file mode 100644 index 3a2dc1622ff..00000000000 --- a/unit-tests/Tests/Version3/reports-reviews-totals.php +++ /dev/null @@ -1,98 +0,0 @@ -user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/reports/reviews/totals', $routes ); - } - - /** - * Test getting all product reviews. - * - * @since 3.5.0 - */ - public function test_get_reports() { - global $wpdb; - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/reviews/totals' ) ); - $report = $response->get_data(); - $data = array(); - - $query_data = array( - 'count' => true, - 'post_type' => 'product', - 'meta_key' => 'rating', // WPCS: slow query ok. - 'meta_value' => '', // WPCS: slow query ok. - ); - - for ( $i = 1; $i <= 5; $i++ ) { - $query_data['meta_value'] = $i; - - $data[] = array( - 'slug' => 'rated_' . $i . '_out_of_5', - /* translators: %s: average rating */ - 'name' => sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $i ), - 'total' => (int) get_comments( $query_data ), - ); - } - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), count( $report ) ); - $this->assertEquals( $data, $report ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_reports_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/reviews/totals' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test the product review schema. - * - * @since 3.5.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/reviews/totals' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'slug', $properties ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'total', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/settings.php b/unit-tests/Tests/Version3/settings.php deleted file mode 100644 index 4c764de1f6c..00000000000 --- a/unit-tests/Tests/Version3/settings.php +++ /dev/null @@ -1,895 +0,0 @@ -endpoint = new WC_REST_Setting_Options_Controller(); - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/settings', $routes ); - $this->assertArrayHasKey( '/wc/v3/settings/(?P[\w-]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/settings/(?P[\w-]+)/(?P[\w-]+)', $routes ); - } - - /** - * Test getting all groups. - * - * @since 3.5.0 - */ - public function test_get_groups() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertContains( - array( - 'id' => 'test', - 'label' => 'Test extension', - 'parent_id' => '', - 'description' => 'My awesome test settings.', - 'sub_groups' => array( 'sub-test' ), - '_links' => array( - 'options' => array( - array( - 'href' => rest_url( '/wc/v3/settings/test' ), - ), - ), - ), - ), - $data - ); - - $this->assertContains( - array( - 'id' => 'sub-test', - 'label' => 'Sub test', - 'parent_id' => 'test', - 'description' => '', - 'sub_groups' => array(), - '_links' => array( - 'options' => array( - array( - 'href' => rest_url( '/wc/v3/settings/sub-test' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test /settings without valid permissions/creds. - * - * @since 3.5.0 - */ - public function test_get_groups_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test /settings without valid permissions/creds. - * - * @since 3.5.0 - * @covers WC_Rest_Settings_Controller::get_items - */ - public function test_get_groups_none_registered() { - wp_set_current_user( $this->user ); - - remove_all_filters( 'woocommerce_settings_groups' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) ); - $this->assertEquals( 500, $response->get_status() ); - - \Automattic\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register(); - } - - /** - * Test groups schema. - * - * @since 3.5.0 - */ - public function test_get_group_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 5, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'parent_id', $properties ); - $this->assertArrayHasKey( 'label', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'sub_groups', $properties ); - } - - /** - * Test settings schema. - * - * @since 3.5.0 - */ - public function test_get_setting_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings/test/woocommerce_shop_page_display' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 10, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'label', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'value', $properties ); - $this->assertArrayHasKey( 'default', $properties ); - $this->assertArrayHasKey( 'tip', $properties ); - $this->assertArrayHasKey( 'placeholder', $properties ); - $this->assertArrayHasKey( 'type', $properties ); - $this->assertArrayHasKey( 'options', $properties ); - $this->assertArrayHasKey( 'group_id', $properties ); - } - - /** - * Test getting a single group. - * - * @since 3.5.0 - */ - public function test_get_group() { - wp_set_current_user( $this->user ); - - // test route callback receiving an empty group id - $result = $this->endpoint->get_group_settings( '' ); - $this->assertWPError( $result ); - - // test getting a group that does not exist - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/not-real' ) ); - $this->assertEquals( 404, $response->get_status() ); - - // test getting the 'invalid' group - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/invalid' ) ); - $this->assertEquals( 404, $response->get_status() ); - - // test getting a valid group with settings attached to it - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) ); - $data = $response->get_data(); - $this->assertEquals( 1, count( $data ) ); - $this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] ); - $this->assertEmpty( $data[0]['value'] ); - } - - /** - * Test getting a single group without permission. - * - * @since 3.5.0 - */ - public function test_get_group_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/coupon-data' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a single setting. - * - * @since 3.5.0 - */ - public function test_update_setting() { - wp_set_current_user( $this->user ); - - // test defaults first - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) ); - $data = $response->get_data(); - $this->assertEquals( '', $data['value'] ); - - // test updating shop display setting - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => 'both', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'both', $data['value'] ); - $this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => 'subcategories', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'subcategories', $data['value'] ); - $this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => '', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( '', $data['value'] ); - $this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) ); - } - - /** - * Test updating multiple settings at once. - * - * @since 3.5.0 - */ - public function test_update_settings() { - wp_set_current_user( $this->user ); - - // test defaults first - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) ); - $data = $response->get_data(); - $this->assertEquals( '', $data[0]['value'] ); - - // test setting both at once - $request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => 'woocommerce_shop_page_display', - 'value' => 'both', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'both', $data['update'][0]['value'] ); - $this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) ); - - // test updating one, but making sure the other value stays the same - $request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => 'woocommerce_shop_page_display', - 'value' => 'subcategories', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'subcategories', $data['update'][0]['value'] ); - $this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) ); - } - - /** - * Test getting a single setting. - * - * @since 3.5.0 - */ - public function test_get_setting() { - wp_set_current_user( $this->user ); - - // test getting an invalid setting from a group that does not exist - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/not-real/woocommerce_shop_page_display' ) ); - $data = $response->get_data(); - $this->assertEquals( 404, $response->get_status() ); - - // test getting an invalid setting from a group that does exist - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/invalid/invalid' ) ); - $data = $response->get_data(); - $this->assertEquals( 404, $response->get_status() ); - - // test getting a valid setting - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertEquals( 'woocommerce_shop_page_display', $data['id'] ); - $this->assertEquals( 'Shop page display', $data['label'] ); - $this->assertEquals( '', $data['default'] ); - $this->assertEquals( 'select', $data['type'] ); - $this->assertEquals( '', $data['value'] ); - } - - /** - * Test getting a single setting without valid user permissions. - * - * @since 3.5.0 - */ - public function test_get_setting_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests the GET single setting route handler receiving an empty setting ID. - * - * @since 3.5.0 - */ - public function test_get_setting_empty_setting_id() { - $result = $this->endpoint->get_setting( 'test', '' ); - - $this->assertWPError( $result ); - } - - /** - * Tests the GET single setting route handler receiving an invalid setting ID. - * - * @since 3.5.0 - */ - public function test_get_setting_invalid_setting_id() { - $result = $this->endpoint->get_setting( 'test', 'invalid' ); - - $this->assertWPError( $result ); - } - - /** - * Tests the GET single setting route handler encountering an invalid setting type. - * - * @since 3.5.0 - */ - public function test_get_setting_invalid_setting_type() { - // $controller = $this->getMock( 'WC_Rest_Setting_Options_Controller', array( 'get_group_settings', 'is_setting_type_valid' ) ); - $controller = $this->getMockBuilder( 'WC_Rest_Setting_Options_Controller' )->setMethods( array( 'get_group_settings', 'is_setting_type_valid' ) )->getMock(); - - $controller - ->expects( $this->any() ) - ->method( 'get_group_settings' ) - ->will( $this->returnValue( \Automattic\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register_test_settings( array() ) ) ); - - $controller - ->expects( $this->any() ) - ->method( 'is_setting_type_valid' ) - ->will( $this->returnValue( false ) ); - - $result = $controller->get_setting( 'test', 'woocommerce_shop_page_display' ); - - $this->assertWPError( $result ); - } - - /** - * Test updating a single setting without valid user permissions. - * - * @since 3.5.0 - */ - public function test_update_setting_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); - $request->set_body_params( - array( - 'value' => 'subcategories', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - - /** - * Test updating multiple settings without valid user permissions. - * - * @since 3.5.0 - */ - public function test_update_settings_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => 'woocommerce_shop_page_display', - 'value' => 'subcategories', - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test updating a bad setting ID. - * - * @since 3.5.0 - * @covers WC_Rest_Setting_Options_Controller::update_item - */ - public function test_update_setting_bad_setting_id() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/test/invalid' ); - $request->set_body_params( - array( - 'value' => 'test', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests our classic setting registration to make sure settings added for WP-Admin are available over the API. - * - * @since 3.5.0 - */ - public function test_classic_settings() { - wp_set_current_user( $this->user ); - - // Make sure the group is properly registered - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products' ) ); - $data = $response->get_data(); - $this->assertTrue( is_array( $data ) ); - $this->assertContains( - array( - 'id' => 'woocommerce_downloads_require_login', - 'label' => 'Access restriction', - 'description' => 'Downloads require login', - 'type' => 'checkbox', - 'default' => 'no', - 'tip' => 'This setting does not apply to guest purchases.', - 'value' => 'no', - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/settings/products/woocommerce_downloads_require_login' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/settings/products' ), - ), - ), - ), - ), - $data - ); - - // test get single - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products/woocommerce_dimension_unit' ) ); - $data = $response->get_data(); - - $this->assertEquals( 'cm', $data['default'] ); - - // test update - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) ); - $request->set_body_params( - array( - 'value' => 'yd', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'yd', $data['value'] ); - $this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) ); - } - - /** - * Tests our email etting registration to make sure settings added for WP-Admin are available over the API. - * - * @since 3.5.0 - */ - public function test_email_settings() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order' ) ); - $settings = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertContains( - array( - 'id' => 'recipient', - 'label' => 'Recipient(s)', - 'description' => 'Enter recipients (comma separated) for this email. Defaults to admin@example.org.', - 'type' => 'text', - 'default' => '', - 'tip' => 'Enter recipients (comma separated) for this email. Defaults to admin@example.org.', - 'value' => '', - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/settings/email_new_order/recipient' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/settings/email_new_order' ), - ), - ), - ), - ), - $settings - ); - - // test get single - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) ); - $setting = $response->get_data(); - - $this->assertEquals( - array( - 'id' => 'subject', - 'label' => 'Subject', - 'description' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'type' => 'text', - 'default' => '', - 'tip' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'value' => '', - 'group_id' => 'email_new_order', - ), - $setting - ); - - // test update - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_new_order', 'subject' ) ); - $request->set_body_params( - array( - 'value' => 'This is my subject', - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - - $this->assertEquals( - array( - 'id' => 'subject', - 'label' => 'Subject', - 'description' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'type' => 'text', - 'default' => '', - 'tip' => 'Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}', - 'value' => 'This is my subject', - 'group_id' => 'email_new_order', - ), - $setting - ); - - // test updating another subject and making sure it works with a "similar" id - $request = new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - - $this->assertEmpty( $setting['value'] ); - - // test update - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); - $request->set_body_params( - array( - 'value' => 'This is my new subject', - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - - $this->assertEquals( 'This is my new subject', $setting['value'] ); - - // make sure the other is what we left it - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) ); - $setting = $response->get_data(); - - $this->assertEquals( 'This is my subject', $setting['value'] ); - } - - /** - * Test validation of checkbox settings. - * - * @since 3.5.0 - */ - public function test_validation_checkbox() { - wp_set_current_user( $this->user ); - - // test bogus value - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); - $request->set_body_params( - array( - 'value' => 'not_yes_or_no', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // test yes - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); - $request->set_body_params( - array( - 'value' => 'yes', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - - // test no - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); - $request->set_body_params( - array( - 'value' => 'no', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test validation of radio settings. - * - * @since 3.5.0 - */ - public function test_validation_radio() { - wp_set_current_user( $this->user ); - - // not a valid option - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) ); - $request->set_body_params( - array( - 'value' => 'billing2', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // valid - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) ); - $request->set_body_params( - array( - 'value' => 'billing', - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test validation of multiselect. - * - * @since 3.5.0 - */ - public function test_validation_multiselect() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ) ); - $setting = $response->get_data(); - $this->assertEmpty( $setting['value'] ); - - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ); - $request->set_body_params( - array( - 'value' => array( 'AX', 'DZ', 'MMM' ), - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] ); - } - - /** - * Test validation of select. - * - * @since 3.5.0 - */ - public function test_validation_select() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ) ); - $setting = $response->get_data(); - $this->assertEquals( 'kg', $setting['value'] ); - - // invalid - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ); - $request->set_body_params( - array( - 'value' => 'pounds', // invalid, should be lbs - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // valid - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ); - $request->set_body_params( - array( - 'value' => 'lbs', // invalid, should be lbs - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( 'lbs', $setting['value'] ); - } - - /** - * Test to make sure the 'base location' setting is present in the response. - * That it is returned as 'select' and not 'single_select_country', - * and that both state and country options are returned. - * - * @since 3.5.0 - */ - public function test_woocommerce_default_country() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_default_country' ) ); - $setting = $response->get_data(); - - $this->assertEquals( 'select', $setting['type'] ); - $this->assertArrayHasKey( 'GB', $setting['options'] ); - $this->assertArrayHasKey( 'US:OR', $setting['options'] ); - } - - /** - * Test to make sure the store address setting can be fetched and updated. - * - * @since 3.5.0 - */ - public function test_woocommerce_store_address() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_address' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } - - /** - * Test to make sure the store address 2 (line 2) setting can be fetched and updated. - * - * @since 3.5.0 - */ - public function test_woocommerce_store_address_2() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_address_2' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } - - /** - * Test to make sure the store city setting can be fetched and updated. - * - * @since 3.5.0 - */ - public function test_woocommerce_store_city() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_city' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } - - /** - * Test to make sure the store postcode setting can be fetched and updated. - * - * @since 3.5.0 - */ - public function test_woocommerce_store_postcode() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_postcode' ) ); - $setting = $response->get_data(); - $this->assertEquals( 'text', $setting['type'] ); - - // Repalce the old value with something uniquely new - $old_value = $setting['value']; - $new_value = $old_value . ' ' . rand( 1000, 9999 ); - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' ); - $request->set_body_params( - array( - 'value' => $new_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $new_value, $setting['value'] ); - - // Put the original value back - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' ); - $request->set_body_params( - array( - 'value' => $old_value, - ) - ); - $response = $this->server->dispatch( $request ); - $setting = $response->get_data(); - $this->assertEquals( $old_value, $setting['value'] ); - } -} diff --git a/unit-tests/Tests/Version3/shipping-methods.php b/unit-tests/Tests/Version3/shipping-methods.php deleted file mode 100644 index ad139c427af..00000000000 --- a/unit-tests/Tests/Version3/shipping-methods.php +++ /dev/null @@ -1,143 +0,0 @@ -endpoint = new WC_REST_Shipping_Methods_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/shipping_methods', $routes ); - $this->assertArrayHasKey( '/wc/v3/shipping_methods/(?P[\w-]+)', $routes ); - } - - /** - * Test getting all shipping methods. - * - * @since 3.5.0 - */ - public function test_get_shipping_methods() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods' ) ); - $methods = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertContains( - array( - 'id' => 'free_shipping', - 'title' => 'Free shipping', - 'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.', - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/shipping_methods/free_shipping' ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping_methods' ), - ), - ), - ), - ), - $methods - ); - } - - /** - * Tests to make sure shipping methods cannot viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_shipping_methods_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a single shipping method. - * - * @since 3.5.0 - */ - public function test_get_shipping_method() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods/local_pickup' ) ); - $method = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => 'local_pickup', - 'title' => 'Local pickup', - 'description' => 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.', - ), - $method - ); - } - - /** - * Tests getting a single shipping method without the correct permissions. - * - * @since 3.5.0 - */ - public function test_get_shipping_method_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods/local_pickup' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a shipping method with an invalid ID. - * - * @since 3.5.0 - */ - public function test_get_shipping_method_invalid_id() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods/fake_method' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test the shipping method schema. - * - * @since 3.5.0 - */ - public function test_shipping_method_schema() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/shipping_methods' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'title', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - } -} diff --git a/unit-tests/Tests/Version3/shipping-zones.php b/unit-tests/Tests/Version3/shipping-zones.php deleted file mode 100644 index a735357b41f..00000000000 --- a/unit-tests/Tests/Version3/shipping-zones.php +++ /dev/null @@ -1,825 +0,0 @@ -endpoint = new WC_REST_Shipping_Zones_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - $this->zones = array(); - } - - /** - * Helper method to create a Shipping Zone. - * - * @param string $name Zone name. - * @param int $order Optional. Zone sort order. - * @return WC_Shipping_Zone - */ - protected function create_shipping_zone( $name, $order = 0, $locations = array() ) { - $zone = new WC_Shipping_Zone( null ); - $zone->set_zone_name( $name ); - $zone->set_zone_order( $order ); - $zone->set_locations( $locations ); - $zone->save(); - - $this->zones[] = $zone; - - return $zone; - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/shipping/zones', $routes ); - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)', $routes ); - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)/locations', $routes ); - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)/methods', $routes ); - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)/methods/(?P[\d]+)', $routes ); - } - - /** - * Test getting all Shipping Zones. - * - * @since 3.5.0 - */ - public function test_get_zones() { - wp_set_current_user( $this->user ); - - // "Rest of the World" zone exists by default - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 1 ); - $this->assertContains( - array( - 'id' => $data[0]['id'], - 'name' => 'Locations not covered by your other zones', - 'order' => 0, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[0]['id'] ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[0]['id'] . '/locations' ), - ), - ), - ), - ), - $data - ); - - // Create a zone and make sure it's in the response - $this->create_shipping_zone( 'Zone 1' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 2 ); - $this->assertContains( - array( - 'id' => $data[1]['id'], - 'name' => 'Zone 1', - 'order' => 0, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[1]['id'] ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[1]['id'] . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test /shipping/zones without valid permissions/creds. - * - * @since 3.5.0 - */ - public function test_get_shipping_zones_without_permission() { - wp_set_current_user( 0 ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test /shipping/zones while Shipping is disabled in WooCommerce. - * - * @since 3.5.0 - */ - public function test_get_shipping_zones_disabled_shipping() { - wp_set_current_user( $this->user ); - - add_filter( 'wc_shipping_enabled', '__return_false' ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); - $this->assertEquals( 404, $response->get_status() ); - - remove_filter( 'wc_shipping_enabled', '__return_false' ); - } - - /** - * Test Shipping Zone schema. - * - * @since 3.5.0 - */ - public function test_get_shipping_zone_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/shipping/zones' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 3, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertTrue( $properties['id']['readonly'] ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'order', $properties ); - } - - /** - * Test Shipping Zone create endpoint. - * - * @since 3.5.0 - */ - public function test_create_shipping_zone() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones' ); - $request->set_body_params( - array( - 'name' => 'Test Zone', - 'order' => 1, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'name' => 'Test Zone', - 'order' => 1, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data['id'] ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data['id'] . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test Shipping Zone create endpoint. - * - * @since 3.5.0 - */ - public function test_create_shipping_zone_without_permission() { - wp_set_current_user( 0 ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones' ); - $request->set_body_params( - array( - 'name' => 'Test Zone', - 'order' => 1, - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test Shipping Zone update endpoint. - * - * @since 3.5.0 - */ - public function test_update_shipping_zone() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Test Zone' ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/' . $zone->get_id() ); - $request->set_body_params( - array( - 'name' => 'Zone Test', - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $zone->get_id(), - 'name' => 'Zone Test', - 'order' => 2, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test Shipping Zone update endpoint with a bad zone ID. - * - * @since 3.5.0 - */ - public function test_update_shipping_zone_invalid_id() { - wp_set_current_user( $this->user ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/555555' ); - $request->set_body_params( - array( - 'name' => 'Zone Test', - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test Shipping Zone delete endpoint. - * - * @since 3.5.0 - */ - public function test_delete_shipping_zone() { - wp_set_current_user( $this->user ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/' . $zone->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test Shipping Zone delete endpoint without permissions. - * - * @since 3.5.0 - */ - public function test_delete_shipping_zone_without_permission() { - wp_set_current_user( 0 ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/' . $zone->get_id() ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test Shipping Zone delete endpoint with a bad zone ID. - * - * @since 3.5.0 - */ - public function test_delete_shipping_zone_invalid_id() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/555555' ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting a single Shipping Zone. - * - * @since 3.5.0 - */ - public function test_get_single_shipping_zone() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Test Zone' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $zone->get_id(), - 'name' => 'Test Zone', - 'order' => 0, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones' ), - ), - ), - 'describedby' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test getting a single Shipping Zone with a bad zone ID. - * - * @since 3.5.0 - */ - public function test_get_single_shipping_zone_invalid_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting Shipping Zone Locations. - * - * @since 3.5.0 - */ - public function test_get_locations() { - wp_set_current_user( $this->user ); - - // Create a zone - $zone = $this->create_shipping_zone( - 'Zone 1', - 0, - array( - array( - 'code' => 'US', - 'type' => 'country', - ), - ) - ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 1 ); - $this->assertEquals( - array( - array( - 'code' => 'US', - 'type' => 'country', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test getting Shipping Zone Locations with a bad zone ID. - * - * @since 3.5.0 - */ - public function test_get_locations_invalid_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1/locations' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test Shipping Zone Locations update endpoint. - * - * @since 3.5.0 - */ - public function test_update_locations() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Test Zone' ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ); - $request->add_header( 'Content-Type', 'application/json' ); - $request->set_body( - json_encode( - array( - array( - 'code' => 'UK', - 'type' => 'country', - ), - array( - 'code' => 'US', // test that locations missing "type" treated as country. - ), - array( - 'code' => 'SW1A0AA', - 'type' => 'postcode', - ), - array( - 'type' => 'continent', // test that locations missing "code" aren't saved - ), - ) - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - $this->assertEquals( - array( - array( - 'code' => 'UK', - 'type' => 'country', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - array( - 'code' => 'US', - 'type' => 'country', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - array( - 'code' => 'SW1A0AA', - 'type' => 'postcode', - '_links' => array( - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ), - ), - $data - ); - } - - /** - * Test updating Shipping Zone Locations with a bad zone ID. - * - * @since 3.5.0 - */ - public function test_update_locations_invalid_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/1/locations' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting all Shipping Zone Methods and getting a single Shipping Zone Method. - * - * @since 3.5.0 - */ - public function test_get_methods() { - wp_set_current_user( $this->user ); - - // Create a shipping method and make sure it's in the response - $zone = $this->create_shipping_zone( 'Zone 1' ); - $instance_id = $zone->add_shipping_method( 'flat_rate' ); - $methods = $zone->get_shipping_methods(); - $method = $methods[ $instance_id ]; - - $settings = array(); - $method->init_instance_settings(); - foreach ( $method->get_instance_form_fields() as $id => $field ) { - $data = array( - 'id' => $id, - 'label' => $field['title'], - 'description' => ( empty( $field['description'] ) ? '' : $field['description'] ), - 'type' => $field['type'], - 'value' => $method->instance_settings[ $id ], - 'default' => ( empty( $field['default'] ) ? '' : $field['default'] ), - 'tip' => ( empty( $field['description'] ) ? '' : $field['description'] ), - 'placeholder' => ( empty( $field['placeholder'] ) ? '' : $field['placeholder'] ), - ); - if ( ! empty( $field['options'] ) ) { - $data['options'] = $field['options']; - } - $settings[ $id ] = $data; - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods' ) ); - $data = $response->get_data(); - $expected = array( - 'id' => $instance_id, - 'instance_id' => $instance_id, - 'title' => $method->instance_settings['title'], - 'order' => $method->method_order, - 'enabled' => ( 'yes' === $method->enabled ), - 'method_id' => $method->id, - 'method_title' => $method->method_title, - 'method_description' => $method->method_description, - 'settings' => $settings, - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods' ), - ), - ), - 'describes' => array( - array( - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), - ), - ), - ), - ); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $data ), 1 ); - $this->assertContains( $expected, $data ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( $expected, $data ); - } - - /** - * Test getting all Shipping Zone Methods with a bad zone ID. - * - * @since 3.5.0 - */ - public function test_get_methods_invalid_zone_id() { - wp_set_current_user( $this->user ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1/methods' ) ); - - $this->assertEquals( 404, $response->get_status() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1/methods/1' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test getting a single Shipping Zone Method with a bad ID. - * - * @since 3.5.0 - */ - public function test_get_methods_invalid_method_id() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Zone 1' ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/1' ) ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test updating a Shipping Zone Method. - * - * @since 3.5.0 - */ - public function test_update_methods() { - wp_set_current_user( $this->user ); - - $zone = $this->create_shipping_zone( 'Zone 1' ); - $instance_id = $zone->add_shipping_method( 'flat_rate' ); - $methods = $zone->get_shipping_methods(); - $method = $methods[ $instance_id ]; - - // Test defaults - $request = new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'title', $data['settings'] ); - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); - $this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '0', $data['settings']['cost']['value'] ); - - // Update a single value - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'settings' => array( - 'cost' => 5, - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'title', $data['settings'] ); - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); - $this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '5', $data['settings']['cost']['value'] ); - - // Test multiple settings - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'settings' => array( - 'cost' => 10, - 'tax_status' => 'none', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'title', $data['settings'] ); - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); - $this->assertEquals( 'none', $data['settings']['tax_status']['value'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '10', $data['settings']['cost']['value'] ); - - // Test bogus - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'settings' => array( - 'cost' => 10, - 'tax_status' => 'this_is_not_a_valid_option', - ), - ) - ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - - // Test other parameters - $this->assertTrue( $data['enabled'] ); - $this->assertEquals( 1, $data['order'] ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_body_params( - array( - 'enabled' => false, - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertFalse( $data['enabled'] ); - $this->assertEquals( 2, $data['order'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '10', $data['settings']['cost']['value'] ); - } - - /** - * Test creating a Shipping Zone Method. - * - * @since 3.5.0 - */ - public function test_create_method() { - wp_set_current_user( $this->user ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods' ); - $request->set_body_params( - array( - 'method_id' => 'flat_rate', - 'enabled' => false, - 'order' => 2, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertFalse( $data['enabled'] ); - $this->assertEquals( 2, $data['order'] ); - $this->assertArrayHasKey( 'cost', $data['settings'] ); - $this->assertEquals( '0', $data['settings']['cost']['value'] ); - } - - /** - * Test deleting a Shipping Zone Method. - * - * @since 3.5.0 - */ - public function test_delete_method() { - wp_set_current_user( $this->user ); - $zone = $this->create_shipping_zone( 'Zone 1' ); - $instance_id = $zone->add_shipping_method( 'flat_rate' ); - $methods = $zone->get_shipping_methods(); - $method = $methods[ $instance_id ]; - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } -} diff --git a/unit-tests/Tests/Version3/system-status.php b/unit-tests/Tests/Version3/system-status.php deleted file mode 100644 index cdf30aedaef..00000000000 --- a/unit-tests/Tests/Version3/system-status.php +++ /dev/null @@ -1,487 +0,0 @@ -user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Setup our test server. - */ - public function setUp() { - parent::setUp(); - - wp_set_current_user( self::$user ); - - $this->endpoint = new WC_REST_System_Status_Controller(); - - // Callback used by WP_HTTP_TestCase to decide whether to perform HTTP requests or to provide a mocked response. - $this->http_responder = array( $this, 'mock_http_responses' ); - } - - /** - * Test route registration. - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/system_status', $routes ); - $this->assertArrayHasKey( '/wc/v3/system_status/tools', $routes ); - $this->assertArrayHasKey( '/wc/v3/system_status/tools/(?P[\w-]+)', $routes ); - } - - /** - * Test to make sure system status cannot be accessed without valid creds - * - * @since 3.5.0 - */ - public function test_get_system_status_info_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test to make sure root properties are present. - * (environment, theme, database, etc). - * - * @since 3.5.0 - */ - public function test_get_system_status_info_returns_root_properties() { - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $data = $response->get_data(); - - $this->assertArrayHasKey( 'environment', $data ); - $this->assertArrayHasKey( 'database', $data ); - $this->assertArrayHasKey( 'active_plugins', $data ); - $this->assertArrayHasKey( 'theme', $data ); - $this->assertArrayHasKey( 'settings', $data ); - $this->assertArrayHasKey( 'security', $data ); - $this->assertArrayHasKey( 'pages', $data ); - } - - /** - * Test to make sure environment response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_status_info_environment() { - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $data = $response->get_data(); - $environment = (array) $data['environment']; - - // Make sure all expected data is present. - $this->assertEquals( 32, count( $environment ) ); - - // Test some responses to make sure they match up. - $this->assertEquals( get_option( 'home' ), $environment['home_url'] ); - $this->assertEquals( get_option( 'siteurl' ), $environment['site_url'] ); - $this->assertEquals( WC()->version, $environment['version'] ); - } - - /** - * Test to make sure that it is possible to filter - * the environment fields returned in the response. - */ - public function test_get_system_status_info_environment_filtered_by_field() { - $expected_data = array( - 'environment' => array( - 'version' => WC()->version - ) - ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/system_status' ); - $request->set_query_params( array( '_fields' => 'environment.version' ) ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( $expected_data, $data ); - } - - /** - * Test to make sure database response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_status_info_database() { - global $wpdb; - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $data = $response->get_data(); - $database = (array) $data['database']; - - $this->assertEquals( get_option( 'woocommerce_db_version' ), $database['wc_database_version'] ); - $this->assertEquals( $wpdb->prefix, $database['database_prefix'] ); - $this->assertArrayHasKey( 'woocommerce', $database['database_tables'], wc_print_r( $database, true ) ); - $this->assertArrayHasKey( $wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], wc_print_r( $database, true ) ); - } - - /** - * Test to make sure active plugins response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_status_info_active_plugins() { - $actual_plugins = array( 'hello.php' ); - update_option( 'active_plugins', $actual_plugins ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - update_option( 'active_plugins', array() ); - - $data = $response->get_data(); - $plugins = (array) $data['active_plugins']; - - $this->assertEquals( 1, count( $plugins ) ); - $this->assertEquals( 'Hello Dolly', $plugins[0]['name'] ); - } - - /** - * Test to make sure theme response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_status_info_theme() { - $active_theme = wp_get_theme(); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $data = $response->get_data(); - $theme = (array) $data['theme']; - - $this->assertEquals( 13, count( $theme ) ); - $this->assertEquals( $active_theme->Name, $theme['name'] ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar - } - - /** - * Test to make sure settings response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_status_info_settings() { - $term_response = array(); - $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); - foreach ( $terms as $term ) { - $term_response[ $term->slug ] = strtolower( $term->name ); - } - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $data = $response->get_data(); - $settings = (array) $data['settings']; - - $this->assertEquals( 12, count( $settings ) ); - $this->assertEquals( ( 'yes' === get_option( 'woocommerce_api_enabled' ) ), $settings['api_enabled'] ); - $this->assertEquals( get_woocommerce_currency(), $settings['currency'] ); - $this->assertEquals( $term_response, $settings['taxonomies'] ); - } - - /** - * Test to make sure security response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_status_info_security() { - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $data = $response->get_data(); - $settings = (array) $data['security']; - - $this->assertEquals( 2, count( $settings ) ); - $this->assertEquals( 'https' === substr( wc_get_page_permalink( 'shop' ), 0, 5 ), $settings['secure_connection'] ); - $this->assertEquals( ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), $settings['hide_errors'] ); - } - - /** - * Test to make sure pages response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_status_info_pages() { - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); - $data = $response->get_data(); - $pages = $data['pages']; - $this->assertEquals( 5, count( $pages ) ); - } - - /** - * Test system status schema. - * - * @since 3.5.0 - */ - public function test_system_status_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/system_status' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertEquals( 10, count( $properties ) ); - $this->assertArrayHasKey( 'environment', $properties ); - $this->assertArrayHasKey( 'database', $properties ); - $this->assertArrayHasKey( 'active_plugins', $properties ); - $this->assertArrayHasKey( 'theme', $properties ); - $this->assertArrayHasKey( 'settings', $properties ); - $this->assertArrayHasKey( 'security', $properties ); - $this->assertArrayHasKey( 'pages', $properties ); - } - - /** - * Test to make sure get_items (all tools) response is correct. - * - * @since 3.5.0 - */ - public function test_get_system_tools() { - $tools_controller = new WC_REST_System_Status_Tools_Controller(); - $raw_tools = $tools_controller->get_tools(); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $raw_tools ), count( $data ) ); - $this->assertContains( - array( - 'id' => 'regenerate_thumbnails', - 'name' => 'Regenerate shop thumbnails', - 'action' => 'Regenerate', - 'description' => 'This will regenerate all shop thumbnails to match your theme and/or image settings.', - '_links' => array( - 'item' => array( - array( - 'href' => rest_url( '/wc/v3/system_status/tools/regenerate_thumbnails' ), - 'embeddable' => 1, - ), - ), - ), - ), - $data - ); - - $query_params = array( - '_fields' => 'id,name,nonexisting', - ); - $request = new WP_REST_Request( 'GET', '/wc/v3/system_status/tools' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( count( $raw_tools ), count( $data ) ); - $this->assertContains( - array( - 'id' => 'regenerate_thumbnails', - 'name' => 'Regenerate shop thumbnails', - ), - $data - ); - foreach ( $data as $item ) { - // Fields that are not requested are not returned in response. - $this->assertArrayNotHasKey( 'action', $item ); - $this->assertArrayNotHasKey( 'description', $item ); - // Links are part of data in collections, so excluded if not explicitly requested. - $this->assertArrayNotHasKey( '_links', $item ); - // Non existing field is ignored. - $this->assertArrayNotHasKey( 'nonexisting', $item ); - } - - // Links are part of data, not links in collections. - $links = $response->get_links(); - $this->assertEquals( 0, count( $links ) ); - } - - /** - * Test to make sure system status tools cannot be accessed without valid creds - * - * @since 3.5.0 - */ - public function test_get_system_status_tools_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test to make sure we can load a single tool correctly. - * - * @since 3.5.0 - */ - public function test_get_system_tool() { - $tools_controller = new WC_REST_System_Status_Tools_Controller(); - $raw_tools = $tools_controller->get_tools(); - $raw_tool = $raw_tools['recount_terms']; - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools/recount_terms' ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertEquals( 'recount_terms', $data['id'] ); - $this->assertEquals( 'Term counts', $data['name'] ); - $this->assertEquals( 'Recount terms', $data['action'] ); - $this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] ); - - // Test for _fields query parameter. - $query_params = array( - '_fields' => 'id,name,nonexisting', - ); - $request = new WP_REST_Request( 'GET', '/wc/v3/system_status/tools/recount_terms' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - - $this->assertEquals( 'recount_terms', $data['id'] ); - $this->assertEquals( 'Term counts', $data['name'] ); - $this->assertArrayNotHasKey( 'action', $data ); - $this->assertArrayNotHasKey( 'description', $data ); - // Links are part of links, not data in single items. - $this->assertArrayNotHasKey( '_links', $data ); - - // Links are part of links, not data in single item response. - $links = $response->get_links(); - $this->assertEquals( 1, count( $links ) ); - } - - /** - * Test to make sure a single system status toolscannot be accessed without valid creds. - * - * @since 3.5.0 - */ - public function test_get_system_status_tool_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools/recount_terms' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test to make sure we can RUN a tool correctly. - * - * @since 3.5.0 - */ - public function test_execute_system_tool() { - $tools_controller = new WC_REST_System_Status_Tools_Controller(); - $raw_tools = $tools_controller->get_tools(); - $raw_tool = $raw_tools['recount_terms']; - - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v3/system_status/tools/recount_terms' ) ); - $data = $response->get_data(); - - $this->assertEquals( 'recount_terms', $data['id'] ); - $this->assertEquals( 'Term counts', $data['name'] ); - $this->assertEquals( 'Recount terms', $data['action'] ); - $this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] ); - $this->assertTrue( $data['success'] ); - $this->assertEquals( 1, did_action( 'woocommerce_rest_insert_system_status_tool' ) ); - - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v3/system_status/tools/not_a_real_tool' ) ); - $this->assertEquals( 404, $response->get_status() ); - - // Test _fields for execute system tool request. - $query_params = array( - '_fields' => 'id,success,nonexisting', - ); - $request = new WP_REST_Request( 'PUT', '/wc/v3/system_status/tools/recount_terms' ); - $request->set_query_params( $query_params ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( 'recount_terms', $data['id'] ); - $this->assertTrue( $data['success'] ); - - // Fields that are not requested are not returned in response. - $this->assertArrayNotHasKey( 'action', $data ); - $this->assertArrayNotHasKey( 'name', $data ); - $this->assertArrayNotHasKey( 'description', $data ); - // Links are part of links, not data in single item response. - $this->assertArrayNotHasKey( '_links', $data ); - // Non existing field is ignored. - $this->assertArrayNotHasKey( 'nonexisting', $data ); - - // Links are part of links, not data in single item response. - $links = $response->get_links(); - $this->assertEquals( 1, count( $links ) ); - } - - /** - * Test to make sure a tool cannot be run without valid creds. - * - * @since 3.5.0 - */ - public function test_execute_system_status_tool_without_permission() { - wp_set_current_user( 0 ); - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v3/system_status/tools/recount_terms' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test system status schema. - * - * @since 3.5.0 - */ - public function test_system_status_tool_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/system_status/tools' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 6, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'name', $properties ); - $this->assertArrayHasKey( 'action', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'success', $properties ); - $this->assertArrayHasKey( 'message', $properties ); - } - - /** - * Provides a mocked response for external requests performed by WC_REST_System_Status_Controller. - * This way it is not necessary to perform a regular request to an external server which would - * significantly slow down the tests. - * - * This function is called by WP_HTTP_TestCase::http_request_listner(). - * - * @param array $request Request arguments. - * @param string $url URL of the request. - * - * @return array|false mocked response or false to let WP perform a regular request. - */ - protected function mock_http_responses( $request, $url ) { - $mocked_response = false; - - if ( in_array( $url, array( 'https://www.paypal.com/cgi-bin/webscr', 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=0' ), true ) ) { - $mocked_response = array( - 'response' => array( 'code' => 200 ), - ); - } elseif ( 'https://api.wordpress.org/themes/info/1.0/' === $url ) { - $mocked_response = array( - 'body' => 'O:8:"stdClass":12:{s:4:"name";s:7:"Default";s:4:"slug";s:7:"default";s:7:"version";s:5:"1.7.2";s:11:"preview_url";s:29:"https://wp-themes.com/default";s:6:"author";s:15:"wordpressdotorg";s:14:"screenshot_url";s:61:"//ts.w.org/wp-content/themes/default/screenshot.png?ver=1.7.2";s:6:"rating";d:100;s:11:"num_ratings";s:1:"3";s:10:"downloaded";i:296618;s:12:"last_updated";s:10:"2010-06-14";s:8:"homepage";s:37:"https://wordpress.org/themes/default/";s:13:"download_link";s:55:"https://downloads.wordpress.org/theme/default.1.7.2.zip";}', - 'response' => array( 'code' => 200 ), - ); - } - - return $mocked_response; - } -} diff --git a/unit-tests/bin/install.sh b/unit-tests/bin/install.sh deleted file mode 100755 index 8ab83ff1a13..00000000000 --- a/unit-tests/bin/install.sh +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/env bash - -if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" - exit 1 -fi - -DB_NAME=$1 -DB_USER=$2 -DB_PASS=$3 -DB_HOST=${4-localhost} -WP_VERSION=${5-latest} -SKIP_DB_CREATE=${6-false} - -TMPDIR=${TMPDIR-/tmp} -TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") -WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} -WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} - -# Error if WP < 5 -if [[ $WP_VERSION =~ ^([0-9]+)[0-9\.]+\-? ]]; then - if [ "5" -gt "${BASH_REMATCH[1]}" ]; then - echo "You must use WordPress 5.0 or greater." - exit 1 - fi -fi - -download() { - if [ `which curl` ]; then - curl -s "$1" > "$2"; - elif [ `which wget` ]; then - wget -nv -O "$2" "$1" - fi -} - -if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then - WP_TESTS_TAG="branches/$WP_VERSION" -elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - WP_TESTS_TAG="tags/${WP_VERSION%??}" - else - WP_TESTS_TAG="tags/$WP_VERSION" - fi -elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - WP_TESTS_TAG="trunk" -else - # http serves a single offer, whereas https serves multiple. we only want one - download http://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json - grep '[0-9]+\.[0-9]+(\.[0-9]+)?' $TMPDIR/wp-latest.json - LATEST_VERSION=$(grep -o '"version":"[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//') - if [[ -z "$LATEST_VERSION" ]]; then - echo "Latest WordPress version could not be found" - exit 1 - fi - WP_TESTS_TAG="tags/$LATEST_VERSION" -fi - -set -ex - -install_wp() { - - if [ -d $WP_CORE_DIR ]; then - return; - fi - - mkdir -p $WP_CORE_DIR - - if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - mkdir -p $TMPDIR/wordpress-nightly - download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip - unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/ - mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR - else - if [ $WP_VERSION == 'latest' ]; then - local ARCHIVE_NAME='latest' - elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then - # https serves multiple offers, whereas http serves single. - download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - LATEST_VERSION=${WP_VERSION%??} - else - # otherwise, scan the releases and get the most up to date minor version of the major release - local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'` - LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) - fi - if [[ -z "$LATEST_VERSION" ]]; then - local ARCHIVE_NAME="wordpress-$WP_VERSION" - else - local ARCHIVE_NAME="wordpress-$LATEST_VERSION" - fi - else - local ARCHIVE_NAME="wordpress-$WP_VERSION" - fi - download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz - tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR - fi - - download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php -} - -install_test_suite() { - # portable in-place argument for both GNU sed and Mac OSX sed - if [[ $(uname -s) == 'Darwin' ]]; then - local ioption='-i .bak' - else - local ioption='-i' - fi - - # set up testing suite if it doesn't yet exist - if [ ! -d $WP_TESTS_DIR ]; then - # set up testing suite - mkdir -p $WP_TESTS_DIR - svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes - svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data - fi - - if [ ! -f wp-tests-config.php ]; then - download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php - # remove all forward slashes in the end - WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") - sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php - fi - -} - -install_db() { - - if [ ${SKIP_DB_CREATE} = "true" ]; then - return 0 - fi - - # parse DB_HOST for port or socket references - local PARTS=(${DB_HOST//\:/ }) - local DB_HOSTNAME=${PARTS[0]}; - local DB_SOCK_OR_PORT=${PARTS[1]}; - local EXTRA="" - - if ! [ -z $DB_HOSTNAME ] ; then - if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then - EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" - elif ! [ -z $DB_SOCK_OR_PORT ] ; then - EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ] ; then - EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" - fi - fi - - # create database - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA -} - -install_deps() { - - # Script Variables - WP_SITE_URL="http://local.wordpress.test" - BRANCH=$TRAVIS_BRANCH - REPO=$TRAVIS_REPO_SLUG - WORKING_DIR="$PWD" - - if [ "$TRAVIS_PULL_REQUEST_BRANCH" != "" ]; then - BRANCH=$TRAVIS_PULL_REQUEST_BRANCH - REPO=$TRAVIS_PULL_REQUEST_SLUG - fi - - # Set up WordPress using wp-cli - mkdir -p "$WP_CORE_DIR" - cd "$WP_CORE_DIR" - - curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar - php wp-cli.phar core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --dbprefix=wptests_ - php wp-cli.phar core install --url="$WP_SITE_URL" --title="Example" --admin_user=admin --admin_password=password --admin_email=info@example.com --path=$WP_CORE_DIR --skip-email - - # Install WooCommerce and WooCommerce Admin - cd "wp-content/plugins/" - - git clone --depth 1 https://github.com/woocommerce/woocommerce.git - - cd "woocommerce" - composer install - - cd "$WP_CORE_DIR" - php wp-cli.phar plugin activate woocommerce - - if [ "$BRANCH" != "" ]; then - # Install the correct branch of the plugin, if running from Travis CI. - php wp-cli.phar plugin install https://github.com/$REPO/archive/$BRANCH.zip --activate - fi - - # Back to original dir - cd "$WORKING_DIR" -} - -install_wp -install_test_suite -install_db -install_deps diff --git a/unit-tests/bin/phpcs.sh b/unit-tests/bin/phpcs.sh deleted file mode 100755 index 5a2c8b48a05..00000000000 --- a/unit-tests/bin/phpcs.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -if [[ ${RUN_PHPCS} == 1 ]]; then - CHANGED_FILES=`git diff --name-only --diff-filter=ACMR $TRAVIS_COMMIT_RANGE | grep \\\\.php | awk '{print}' ORS=' '` - IGNORE="" - - if [ "$CHANGED_FILES" != "" ]; then - echo "Running Code Sniffer." - ./vendor/bin/phpcs --ignore=$IGNORE --encoding=utf-8 -s -n -p $CHANGED_FILES - fi -fi diff --git a/unit-tests/bin/phpunit.sh b/unit-tests/bin/phpunit.sh deleted file mode 100755 index 12e95676881..00000000000 --- a/unit-tests/bin/phpunit.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -$HOME/.composer/vendor/bin/phpunit -c phpunit.xml $@ \ No newline at end of file diff --git a/unit-tests/data/Dr1Bczxq4q.png b/unit-tests/data/Dr1Bczxq4q.png deleted file mode 100644 index 4a2bb205fe40d4d8c5125399ffc585bc65595323..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10325 zcmZX31yEeg()Qx+A&{U!6Wm<_Z14a90t5*T!4_NGArKZPxRb@*-Q5Dq;!c17i@V#$ zd++_f?^gX&HK+SbcRzjlnVP9H=Rnj{yHJOz26`m=0)?lG9?&({uN$6o*d zE~%A_jGBUs46T}zy@i#nIRGFJNzlg7j2n8H*^x^~tV@fmE^Qxp&eGur)gf^@kEvC*y`z4Z>&s%79HOI@!>{BK*u+KrO*Vz5p=2)9syJ!=y zB|6}PjTQ(bP>lK>U(%3}3elsitZ4Dm)1Pu2plO6dsbgzg?xv|p?$0yxWDsJH1Y9y~ zcrkE0d-B9GOj#a-2OvgsWRV*j3%JGvG>V97#}EL1QSIVw{oM{bq3tb3mL~+zarEz~ zmvZzMsf#I?kWd`pRFMJ9Si%|QG2To4PW#fS^26~(FJ;*cB{j|Z>rnBzS8Vvb1hkp) zal8~JA9#B6i&py-p7efCog}kq-3ldc(GgYCs3xb4re67R3_K;K+rsB4Z!16XqDsNn z)7P4(%}4P`O<8&eZi0~WSuN!#ryF-Ql$#>pt?uu6!gV*RK>u$=c=?(1lp{Db zCN&JsUAmpEr@SUXx$Qc1+R5Ys{Q*4}XGu<-Li)bx5ftbpBh0#6dOy>s7;6UVooY~W z^7bOAUcBs$xN+U?L5?d&xnzhVC1y;s5fYSS(Hh2+lOjJx^YzC9R^|oH(~=yEpr>N| z;oOl27$G6aW9S>bn~d;ake9tara-~&$|7_Oa9D!L@eHG(sXdwNvp(ns@(q0p=%vRI z3lhSZ?G<+r6vOpxGpgy!a7^Ns%wL}?1^Pj0xI@X`^HFSfg_PD9lK@sa;KALQI5i~B zYtfs>?9^+oeuW=@cZeI8X~bFY(olGjGR^ii_7BFEG9kXFQ7zz$YY~^lQ!*Y1_lxKs ziAK@C1Wg;b`XoB*ms}+FOC(!cfVx%Q7m?0)^@);W%oYzm50HrUBB%yZkw`>?>x>TOu(+u!z8CydBu``4?Pka6UyGdA z5!AWT^LsP~CEEI)cw(J3IiK~Vb-B47iXm}|(`W7AshV=|Cd2Aedu!|J9Z}zV*DFOw zHQ)}VL~@mTPi|(Qcjmodne5onK?hKJp#yxb)5iYbv0c>x(h+9isA%dL*Fxy1?~%eB zw7&tUi~!2U67`)#jYyn-2&CULgrX@JG3lS+#-IqpkZ?NH)sTlfbt{Q91MG~L3sLU6 z-i+f$1@ZntZp0Sp`shG2^MS@43%!erT#E4f_i;iIXaIsvHWbYyT!@}JRFXIZNUtD| z{WI#Ah^QLyB_#gMraWmiN|BuJhp0D}F(dM1PGlYt=k)e5s&7NoKYiAu;Fo3287mZg z9o7%!9S8Ffumi*4)880%!w+TB#(5E+&zTm2+JQf~{D(|&l?iHk)42`Vh?V*$xRB~G zS^HQjbxVnCf}hS@N--!pCDwuIQM`^yI%!hwlwbw|9%rs$b#8|C5N@W*1kiJO9BC+!@na?ugrgJDTg0tC0&*r`bXIl3A)$&xjEdH{|U^)D+m74dY2F{JM1xxGOXv} z;o;*!c2jgJcEfm@aEh_XIV73*B>(wWs)kR|WD(u2^)B_U)vm#=-s?yU-MiXIiG=9^?J45X%{exy-~Rl_O?H7sr52+;ehyqcX6 zLxzo^NsR4>?!;O#N8>Bavy5hRKC#sA(@!`I5!B z@=`ogw^C+OSGed?h11Ma?6~*%WK&~w(S zx2rqA6HPVnUp8rZ*)n_i@>2heYJz;Z zumRU-YE^O7M9Z>m5>6D(s98|O_KL+y%F11<;f>B6rgzkB>y^ue0m5s6;0))S^ z`y~3T;?(a&HcbrmI3X7~f>22E7)M%*-6ht*N;wy-L;!OpF7}M=I2* zTatDgwe36jlS=uksm45}hY=&Z{FW9lF>WQtmo_tNFQgTvhgafZrSe+rHgEZb>X=+& z4n|gbeTPogZU3A*FE?#2ZCf2$ZCY_oEKklBTv@tXXqw?3dwYCtolTKSS>#!@{9th~ z^m208-7gS?O<;k}5Q6AS4a_RaZeBz7``f$v#^L{s%Lif*DE{jDJ8a@wS%i3&SkE4H*d1~Le6S=xOu(ztUU2^ny%-*LJdMk20Q1Px~ zMdXEN;X&ouT0gz4oORShbfUnUk7udqX}qakx<7TBqk<`IY+P)_Z_}pjy`uK0DkOfn znv5z853R@L6kx03WsHf7J1{*c+b@>Z-&vBtR)hpE^apOn&yqM$^@Y6Pck4w;he=U} zu5I4?VP^?jB~jXG3seiykB7&1aQuO&d>fTnT@eEjy_S4%#{T8Lg!A&zZ7@ZbVEIZ! z+LDK(;N9V#7uuEVA*aWCcePu!9pgUwGP$}ZuDgK%>VZs>=m+Ws zNr;D2N7C}$Y0>e{cKf|?YECGkJ@R$X%>HlvLV&Y z$X>-|S8rGQY~XB;y;j?_d&_plLreXy!e4Sd!aejyN|N8a3-1v3C+h{@Rbg^l-b_B_ z_a>Kl7dD7lj2z*doF+CTB`4BOBbmtwfO`!FK$o~x6pZ}-Q%rjsL!kU>I5FxYNn$&U z0ok6zs}&Hchy0$rHODr16w`!dzfb!}htq#yK2k6Rb8_D{ud47EP3D?Q~ zM9s;e*OQg&*bg*2LUs^Qz1vCtx|qe{lu? zUNZjEkrdP!jsXCq3@c3?u+B$i5mS3R4r4QW6LSuCJBMd)06@%Ld2OHD6+u4Gg zMcl>d{^cR^tp792Nk{uH7qE>uoz6!!S{ZvMb6S25J`OHA32a(gS}`Xx3lVjo?0>?a z@5Jf8fx!+UoSbfMZX9mB9QIC@oZP~~!kk<@oIE`2&mQc~9w4x>J3Gjk{@)<~4+m)O zZ0cm?0JgFR(f)&LY+~;M7N?{8C(-}5e?O+B^I0PQGd0gm{<**Xk9^i~!e8K)hCfSf z1)!9sJJPZCCwJ_U)vRqc9gRH*y0qQ+STS8;843$>)X3NmGrRf(c8$970cBi;NA9zHQRz zzU$1a_xj#Idj*at!oeeZLaJ}>U!}lgif&NL%;Ck;%>Ayvy)8C^hU*FKHYqih#_eJd?;$r*2s)<^(JW-AG=IBi;{h+AO-UEff!1r0Lwuk+dwW zSNZ>T%NIz2yL%`9Zoc?nc5ae^e{H6AHA~HwRX5`?mW+5iB<9zJ#Q?)acN*=zL#<7? zuh++wI!A9Vn?x1~`#`|A|HX1-wc%qKL)bH7A}Qd7DT|J^05%-0?zrk}z5F?+w>o4=@l9y68&Mk^;fHdRz==+ut5w1}w+ ziv~DJ`gKinvUiB<Qd1Q7Ey#EOKARlpW7D&q$jFW{xB=&MX%c_jF^g#KS$TF+8<6<=>z-w+^~(`?Xj z3I_(AO;Wh-*&@tyT)SB1E4i7=HT4p>z0*8Wi5eRIFgS`0=l7>R)v@+cW>d%#OG6xY z&FM`N{zF9mFYcCdnXBb zK~6ZLOs4&3`6*Vac#UZ8$2ZO2Ip;8U7(WR#En?M_UDiE*_B}K$>W#?E*0qRg*V6J# z({hbpd3h=lx*~Las?jv~jvKoWg^YtRvH1t0bmPP-@*>G8DrLa#B!2bOQjJWDwaz@v zO~!bXF5M=}Gq;r?wvbW0c5xuwnt0$9YGSW#^3tiLvS55O%=!FQIaOl5?U7kt$RbK^ zqe5GzpLdck&3|^CSwkoMVqL{{__AOI3(C72CE!nOCrp`75e*Zg2L4dU0iNh}$iA4fpqX>84wb zG|_(Zo!_gvaw^b=jwQD&@WYSfIZ*S`ex(!GI)|xb?L#YqYTAbv z=C^T^~z56lI3xziK!l(Xx8}-S3|XhC9^NWxj>y`DbUxLy@Tn;Cd9- zEWTw9*MTPpJ>N(5G48WQ-V>B*8#^r8n=R2Z_W$Tti)M)p1_7W_i`n5Zp+@iw!U z*GlZxJmRYEnRyeYM}3J#Xo2MKRSp~;UBZk{ekOVfFi7oBaZ$EA6 z^reX_g)9OKrd1)J`CT0;@P}>>w#B#=quM>A2b^|4A@*h{=v$;4|6o48C1x z&f7PvnNFIDd)%?&Yel!m(E^^EXY9qy?Lml$<{Udl+MZN4 zG5Ueuj&I=!l}-91X^96P#6KT>xAb!6bfpz8CoT*;plw3zHA#>OO6yVsx{Y%GjTK898;RO3PQ-b&D}B2$&KQ|(K+tiF2_PriQO?;gK7M)J)vWK~&ZFBX^hXdlP$9hU){st>L*S+dL=++^|35 z^||AR0W!L1!?t!!_m78jySNjt8xCIC5gCa2AMRu_)pH;Z@UDtu)qsUOU=cf*?QF`W zbFWI+|5G#j_}W5F5O8;rv}))mft{J6P0rVYYwhM_sloP{`K7o8+}nK(G7nkW095!a z2{F)cV0*KTAATn;h-^fKAG-OxGV<-CLo@B)2iV^toq9%ut!y;t@p!V$`C<;aa;Rzx zd5lxp8Q9WTBGw9&#b}oMt8fnj9{(JQhpwz&c6xjSYub4)lxu>^XCAnuz(pN_deN#r z@TA97L{lL1pSquEPjyO;gk@h)b)h|(tYAVPD!7YxZ{o=dg=cj-qfH*&o>>+oWSmZ( zc;&hgwz8M;Nj=WRE+nv^jE2+)uMN^Jtz`qlwDi|Ayqx)vHHc93r#B?uU0agtQskOj zs7GA(&EP;KA?(43vs^R1?>VeNgB>-{hGfKt)qJHY>&*iX!nO})+rrHKdOmVPrh1o6 zyrn&F<6It9Y44e zg6yBv$l}xk^h9~2^u)u*6ZH>-(Ls8q9^k2~*eEehUJz2v(bvTJLWDTqmv!VMTlQ0_ zJf_;IjFG&DNg>C6UmdVX%1r2IX2ryfNBj4E+;?l_jiVxzQF1>nqNnTYxp894I;46T&OkhEpWcj96j!V^ z|NaSJi2Gc11qW)#Js5C+?rX{ zw6_-6uJ2Ic%*I|X;pTI`Dfm!TrrsiIpc`_Ybq#Qv@vf9X%XTIzq9=8w4^RW~{hZ7|B$%S%gP(AU;+dHg&4AsutSUw92lSrAD3kBI3=sbd? zmAlup{H|I95r>+Pbust|pjrGKvE7Mlz8`UpuAIa_7;RsmG`60cID(;%Jl_mAghJa1 zW@&FFmR2nImCjvTx;rv_7a3N#90(uqvL$)`iorde%4m9owk5prwExVEy&in8MPIvR z?q|3Z@p|qHX=qjqd459URZj;Vm85kkCFTD2ZJg5cs&|i*)r+LgNu1gV?Z6Y)AuqUh z5CXk2y;AqXo~mA!HM{U+>gTJI%gyLheT?I7-jp;W`c*3w+~Wae2;xTWHXb2(ZwS%g zBsgsAq4kVbNSp)832K}7NGTr9%iE6DCgDh&vYQ8@98b|8$e=JHH*roM1{N$REAgl! zXLe-Tp=Od3*x_RD1pzxD^lT_H(*K+X^8ImQr zEXCmd)`Z`T`sFKONF!nS(eRg+rv%J#lEb;<&(k1k|rVa?_wZJqa_D&h;mF#l*m z-MO#gRzq~n*sX*Pq$djuZO@pAA51*V^0D|LYILYe*2oy=iW0Fc=F^WHa|x-O2Wa9A zPu==9_9Ty+x5AC05KU0#MRn_H*4f1;Bmm&)i2)M$007`u|MQA{V6fx4CxUNt`$!-< z(spLE1xD?z%pO&mU~nb&E0~u3#DED8i`&wFyvXYCYnRXt>V&D%B#vyJ_WgQne8E@+ zmU`(VIhn3mV-=rb>78JAkyVoJ81&>f(ean-w!MS%#JS1)hYTXkoaWE^rp&p-@QBo4 z?*UBqs4vv!RO%dZFlmvEpG5O~_#T91^@45~c?x){?q$w%FklBZg8s2{XaypNfD3bl zjPyb@{3*}_6$M7e-?CkCL#jCO+X2>!Xm6fd5!r3LCXUMKS=XY4$A9paK8c)MM>^Pf-G z-l1P*efiaMI^B=6f%85L9nIq?sF~(zrWbE1KuotN>yERGm&oEjul{)WF!*T~fHd1@ zx7r>L6FT4-$&Z)7BO00h@hA{Lq}YKeic_rn{yukmn7KufCMimAlN%2NnrEPaWS8ol*8sNc+IV(P4h}HcIdOZi(?G^~;ZbLgvn6YH@|hIn2@w4)Vk#$=EAcNtYzB^pR(ly3qTr2XpN;9XH_mDX;!x}PF5ajO&UX3hqZ zpVtG&+1LdyiTHZ|pVNp;lp^sMuQBzs`*&aaX6vsoGXz~zOmiz{0_r=cSs;G|zwVs1 zXV#luB|I*JY`EA0So0qk+BkK z_u4xs-A=B|1|2+T`aU7)bkXYYU`7HcsIwa}Qc8f-In{EE{!#!#5EHqO7RouW#?RwP z5MXl~Y7_Zx;XadWmu+BAI2KOQ`7p&-9VW6}z(HSCbB+_A+6d|}YpqB;8fp}ij}%V5 zdefX!qqV)|_HHe-J)MgQ^5>g^?+8P=MV+rMbQS=~Ufl_Iiiw0XIpA~fa%@+x_%8}G0CmAN2rvjzCUj?<|p5#N5&kb zA-sPL8jU;-}UiDm-NvGGBH* zp{&Oz2?2&lYI7FVUL-#Df0i@Zofk)&qU>%KdbHM!EC2uf% zX`IG8OP=ORe)(-pE8mPj;Zvehh01{0NORf!sl^J^`Ah$Wq`hf+BI1E9hnY@f>@V9v z7h#IS{gB@TgjW75qXh&}lvrGYDSLna7iUQmwr8iYQO^Ox9FiP@F@$`+wumH&J*zu0 z(EF{>A^ii-Oq{Ys-eYi_?1w`0r(1mukEC4)L}i_*TtXnFakG(R%DnaKSaM*phLMm;OQ_qzTDW0ZbCj;=lygNHM!rzbIW? z;FJLaFbb)bh#U<<{PMDbM&}4UcW}ky9_9B)w#v8bxx_478!H14;!D8wapNuYF6L^* zEg3M%H=6`A6ZAq9TJ@hX<2uAt2V(i6fWJ=oj!-2-YB_}O#7TZuz@Zd)0YK4UaJae< zLHlmZy5_EQ$|lNXhHo~krhDqmE5>M7w!I&v(MqdFNu058AC#%T^o6LBB*G|Ph^ew! z-^aY^l3~)!HS7=bEGxaZUHF=Dc$fG&oO3seX(6a*K;6R@A=zB)qo{~GXXSu#>op*)G}J76)5&2u;&GFo(unKYdiy9P=KUUBCcYUo=N&b1iNz>B?$e z`R<4s-p~PIUB?l1vf%G~e&)3>vM#)rta~Vo@THMDBQo zAK*D9XG}6scD03wN`F+xY-SpDlxJ>1Ea-0Ws6rlGiJT=Jd0P5v8D;0IecjB*HW>6S)CQ2AB`Rq-#Uch1LDi z_^hgQUUBn&c|j8dB-%X^k*04s8U^_6Pquyni{m_ zekDNzNrr~_Rd*6El|j3J7`DFW?gY-{4P@o4SiCu2eG=X$5+3YhKuyCcXdl4*1u`#!vS4B<73cAW`$5s}&$^9Fv$I(6#*+Ib}o(X9#Az}hDi zxDUPl)OJF4@d;AllC!|9`a`=%Fye9nJ@6+2^&131dxW?p%owZ{sts*Y7QNjeLUv=k zZN+?5Ve#p<{}{=RSke~}LEYt(mJ^=i)X}`LU(z}(d+P!v$@MM=dSR9RL=2ybIEQ$g zIU*iHzp9N!0(U!$v`{^MF z6=jqq2ldUnT9+WgS%`4*bX~ch=g5hZs=WhV&5Zu&C8%6+~q* z7S<(7;zQ#SuQOvQ{K#Q2&^<7w+mV8}*J110bju~g?qHwkg!IPfFEfZjzWOP;;?v&{rao0Wn$Ie-;Ip|sROylv<5A|k~{z87b{E*c;t zr4%eyeqBa#p}qnOr{=OgZ7TP2j`5x-nIZ{+UK8UJwTBudt|Cj7k+6WRmRr*%24g41 zhM3Mqc!WvP>X~jQ(%<>ShpFQ@Q~t06MkAD)6;CZGXmbdE9}Dhvn8@`Lu3!ZbZ<8y? z@IUGu7ec$w!jj~YRFI5~2RB6ev4 zrqv{>e<|ZmIhZBiIo=EyrXT=45T*BrGUvFiGX!M2f7(dk0Sexq{Lqr>v3z!C&MM#jm%MB%eC!=C+LbBg9`#0w={e%}aFoIh$?fqTPKYP8e z#mpmCx0X{YQ1_)T+BZH%>SJseQ5JKt6zig|NHW85aFCdxfgw!i8TK#@E2s Tmze$k{5ewipaLwHHVXV7`I0Rd diff --git a/unit-tests/data/file.txt b/unit-tests/data/file.txt deleted file mode 100644 index 078595600bd..00000000000 --- a/unit-tests/data/file.txt +++ /dev/null @@ -1 +0,0 @@ -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi porta purus dolor, malesuada consequat sem blandit eu. Pellentesque tempor elementum maximus. Phasellus efficitur turpis ante, ac egestas nisl efficitur sit amet. Vestibulum tortor erat, efficitur id nulla eget, malesuada lobortis augue. Ut eleifend ante at pharetra gravida. Quisque suscipit efficitur mauris, quis bibendum massa efficitur id. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vel luctus nisl, ac bibendum nulla. Sed faucibus nibh consectetur urna hendrerit sagittis. Sed bibendum felis in tortor elementum, a porttitor lacus volutpat. Etiam facilisis congue lacinia. Quisque vitae ultricies mauris, non ornare orci. diff --git a/woocommerce-rest-api.php b/woocommerce-rest-api.php deleted file mode 100644 index 075a160c555..00000000000 --- a/woocommerce-rest-api.php +++ /dev/null @@ -1,68 +0,0 @@ - -
-

- composer install', - '' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '' - ); - ?> -

-
-