Version Description
- Fix: Eliminate most usage of number-based inputs in product UI.
- Fix: Fall back to product ID if SKU is not set for Google Analytics reporting.
- Fix: Restored inadvertently removed filter,
wpsc_add_advanced_options
. - Fix: Ensure price entered for "Free Shipping" threshold is locale-aware.
- Fix: Generally improved metadata saving routines for quick/bulk edit areas.
- Fix: Ensure "Combination of product variants is not available" message is hidden from Grid View.
- Fix: Don't require a shipping method to be selected if you qualify for free shipping.
- Fix: When "Buy Now" button is used, it is now disabled if item is out of stock.
- New: Introduced
wpsc_get_countries
andwpsc_get_countries_array
filters. - New: Introduced
wpsc_google_analytics_pushed_product
filter. - New: Introduced
wpsc_get_downloadable_links
filter. - New: Added screen option for number of purchase logs to show on a page.
- New: Introduced WPSC_Logging class. Based on WP_Logging.
- New: Customers may now checkout with carts that have a value of $0.
- New: Introduces
wpsc_is_free_cart
filter. - New: Added 2.0 theme engine component. Defaults off until the 4.0 release, but can be enabled via filter for testing.
- New: Added marketplace component.
- New: Added 3.0 payment gateway API component.
- New: PayPal Digital Goods gateway, updated PayPal Express Checkout, PayPal Pro and Manual Payment gateways.
- New: Product Tags now have proper body classes.
- New: Meta updates, kind of a big deal: We're now using X.X.Y versioning (like WordPress) and we now have unit tests.
- New: Introduce attachments method and filter for WPSC_Purchase_Log_Notification class.
- New: Single Product pages now have ID-based body classes.
- New: Supports Universal Analytics in Google Analytics.
- New: Added
wpsc_checkout_fields
filter for filtering checkout form fields. - Change: Dates are now optional on coupons. Expiration, specifically, is no longer required. Validation is filterable via
wpsc_coupons_validate_coupon
. - Change: Refactored purchase log action links, introduced new API for adding links.
- Change: Product page shortcodes, e.g. [productspage], are now stripped from the_excerpt(). Helpful for cleaner looking search results.
- Change: Limit Google Product ID to 50 characters in Google Product Feed. Introduced
wpsc_google_product_feed_product_id
. - Change: When only one shipping rate is available, it will automatically be selected as the default rate.
Download this release
Release Info
Developer | JustinSainton |
Plugin | WP eCommerce |
Version | 3.9 |
Comparing to | |
See all releases |
Code changes from version 3.8.14.4 to 3.9
- readme.md +0 -39
- readme.txt +55 -26
- wp-shopping-cart.php +42 -38
- wpsc-admin/admin-form-functions.php +7 -0
- wpsc-admin/admin.php +179 -45
- wpsc-admin/ajax-and-init.php +0 -3
- wpsc-admin/ajax.php +82 -0
- wpsc-admin/css/admin.css +59 -6
- wpsc-admin/css/settingspage.css +3 -0
- wpsc-admin/db-upgrades/routines/10.php +0 -1
- wpsc-admin/db-upgrades/routines/11.php +2 -1
- wpsc-admin/db-upgrades/routines/12.php +1 -1
- wpsc-admin/db-upgrades/routines/13.php +2 -2
- wpsc-admin/db-upgrades/routines/14.php +28 -0
- wpsc-admin/db-upgrades/upgrade.php +10 -9
- wpsc-admin/db-upgrades/views/main.php +1 -1
- wpsc-admin/display-coupon-add.php +2 -1
- wpsc-admin/display-coupon-edit.php +6 -3
- wpsc-admin/display-coupons.php +8 -3
- wpsc-admin/display-items.page.php +0 -1
- wpsc-admin/display-sales-logs.php +9 -4
- wpsc-admin/display-update.page.php +6 -6
- wpsc-admin/display-upgrades.page.php +11 -16
- wpsc-admin/includes/display-items-functions.php +1259 -1236
- wpsc-admin/includes/product-functions.php +88 -48
- wpsc-admin/includes/product-variation-list-table.class.php +6 -1
- wpsc-admin/includes/product-variations-page.class.php +7 -1
- wpsc-admin/includes/purchase-log-action-links.php +482 -0
- wpsc-admin/includes/purchase-log-list-table-class.php +11 -0
- wpsc-admin/includes/purchase-logs-page/item-details.php +10 -25
- wpsc-admin/includes/purchase-logs-page/list-table.php +2 -2
- wpsc-admin/includes/purchase-logs-page/upgrade.php +1 -1
- wpsc-admin/includes/save-data.functions.php +20 -17
- wpsc-admin/includes/settings-tabs/admin.php +8 -2
- wpsc-admin/includes/settings-tabs/checkout.php +1 -1
- wpsc-admin/includes/settings-tabs/gateway.php +19 -2
- wpsc-admin/includes/settings-tabs/marketing.php +11 -0
- wpsc-admin/includes/settings-tabs/shipping.php +8 -4
- wpsc-admin/includes/tax_and_shipping.php +7 -1
- wpsc-admin/includes/updating-functions.php +9 -5
- wpsc-admin/init.php +202 -98
- wpsc-admin/js/admin.js +5 -0
- wpsc-admin/js/purchase-log-action-links.js +124 -0
- wpsc-admin/js/variations.js +6 -0
- wpsc-admin/settings-page.php +7 -1
- wpsc-admin/users.php +6 -7
- wpsc-components/marketplace-core-v1/library/Sputnik.php +4 -4
- wpsc-components/marketplace-core-v1/library/Sputnik/API.php +31 -21
- wpsc-components/marketplace-core-v1/library/Sputnik/API/Auth.php +2 -4
- wpsc-components/marketplace-core-v1/library/Sputnik/Admin.php +119 -115
- wpsc-components/marketplace-core-v1/library/Sputnik/List/Install.php +38 -33
- wpsc-components/marketplace-core-v1/library/Sputnik/Pointers.php +7 -7
- wpsc-components/marketplace-core-v1/library/Sputnik/ThemeUpgrader.php +2 -1
- wpsc-components/marketplace-core-v1/library/Sputnik/Theme_Upgrader.php +2 -1
- wpsc-components/marketplace-core-v1/library/Sputnik/Updater.php +4 -2
- wpsc-components/marketplace-core-v1/library/Sputnik/Upgrader.php +5 -4
- wpsc-components/marketplace-core-v1/library/Sputnik/View.php +3 -3
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Account.php +13 -13
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Auth.php +1 -1
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser.php +8 -8
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/Grid.php +54 -45
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/List.php +15 -15
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Info.php +24 -24
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Install.php +4 -4
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Install/Skin.php +6 -6
- wpsc-components/marketplace-core-v1/library/Sputnik/View/Upgrade.php +4 -4
- wpsc-components/marketplace-core-v1/marketplace-core-v1.php +2 -11
- wpsc-components/marketplace-core-v1/static/admin.css +395 -406
- wpsc-components/marketplace-core-v1/static/admin.js +5 -3
- wpsc-components/marketplace-core-v1/static/jquery.masonry.js +0 -10
- wpsc-components/marketplace-core-v1/static/sputnik.css +15 -17
- wpsc-components/marketplace-core-v1/static/sputnik.js +0 -1
- wpsc-components/merchant-core-v2/helpers/admin.php +30 -0
- wpsc-components/merchant-core-v3/classes/http.php +35 -0
- wpsc-components/merchant-core-v3/classes/payment-gateway.php +638 -0
- wpsc-components/merchant-core-v3/gateways/dg.css +72 -0
- wpsc-components/merchant-core-v3/gateways/dg.js +28 -0
- wpsc-components/merchant-core-v3/gateways/manual.php +46 -0
- wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php +638 -0
- wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php +713 -0
- wpsc-components/merchant-core-v3/gateways/paypal-pro.php +633 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/README.md +0 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/exception.php +37 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/helpers.php +15 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/http-curl.php +62 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/http.php +11 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/php-merchant.php +157 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/response.php +39 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-digital-goods.php +80 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout-response.php +124 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php +324 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-ipn.php +140 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-pro-response.php +68 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-pro.php +358 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-response.php +104 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal.php +86 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/http-curl.php +31 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/php-merchant.php +180 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/test-accounts.php +22 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-express-checkout.php +552 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-ipn.php +90 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal.php +126 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/index.php +60 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/http-curl.php +29 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x1.php +317 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x2.php +116 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x3.php +127 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x4.php +163 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x1.php +403 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x2.php +186 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x3.php +97 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x4.php +115 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x5.php +109 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x6.php +93 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-express-checkout.php +146 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-pro-cert-x1.php +140 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-pro-cert-x2.php +81 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE +399 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/LICENSE +502 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/README +102 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/VERSION +1 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/authentication.php +237 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/autorun.php +99 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/browser.php +1144 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/collector.php +122 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/compatibility.php +166 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/cookies.php +380 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/default_reporter.php +163 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/detached.php +96 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/authentication_documentation.html +378 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/browser_documentation.html +501 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/docs.css +121 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/expectation_documentation.html +476 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/form_testing_documentation.html +351 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/group_test_documentation.html +252 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/index.html +542 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/mock_objects_documentation.html +870 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/overview.html +487 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/partial_mocks_documentation.html +457 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/reporter_documentation.html +616 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/unit_test_documentation.html +442 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/web_tester_documentation.html +588 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/authentication_documentation.html +292 -0
readme.md
DELETED
@@ -1,39 +0,0 @@
|
|
1 |
-
WP eCommerce [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/wp-e-commerce/WP-e-Commerce/badges/quality-score.png?s=155ede743c82bcf5116904bf155dcf215da820b0)](https://scrutinizer-ci.com/g/wp-e-commerce/WP-e-Commerce/)
|
2 |
-
============
|
3 |
-
|
4 |
-
About
|
5 |
-
-----
|
6 |
-
|
7 |
-
WP eCommerce is a free open-source WordPress Shopping Cart Plugin that lets customers buy your products, services and digital downloads online.
|
8 |
-
|
9 |
-
More details about this plugin features can be found on our website at [getshopped.org](http://getshopped.org/features/).
|
10 |
-
|
11 |
-
User documentation can be found at [docs.getshopped.org](http://docs.getshopped.org).
|
12 |
-
|
13 |
-
If you're looking for general user support, please submit your support request on [our community support forums](http://getshopped.org/forums/).
|
14 |
-
|
15 |
-
Development status
|
16 |
-
-------------------------
|
17 |
-
|
18 |
-
* The latest stable version is [3.8.14.2](http://wordpress.org/extend/plugins/wp-e-commerce).
|
19 |
-
* Active development version: 3.9-dev (branch [master](https://github.com/wp-e-commerce/WP-e-Commerce))
|
20 |
-
* [Roadmap for 3.9](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Roadmap)
|
21 |
-
* [3.9 tickets](https://github.com/wp-e-commerce/WP-e-Commerce/issues?milestone=5&page=1&state=open)
|
22 |
-
|
23 |
-
How to contribute code
|
24 |
-
-----------------------------
|
25 |
-
* [Coding standards and code quality](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Coding-Standards-and-Code-Quality)
|
26 |
-
* [Submitting code](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Submitting-Code)
|
27 |
-
* [Code review](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Code-Review)
|
28 |
-
* [Merging pull requests](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Merging-Pull-Requests)
|
29 |
-
|
30 |
-
How to report issues
|
31 |
-
--------------------
|
32 |
-
* [Reporting a security issue](wiki/Reporting-a-security-issue)
|
33 |
-
* [What makes a perfect issue ticket?](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Creating-issue-tickets)
|
34 |
-
* [Issue labels and workflow](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Issue-Labels-and-Workflow)
|
35 |
-
|
36 |
-
Translating WPEC
|
37 |
-
----------------
|
38 |
-
* [How to get involved](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Getting-involved-with-translation)
|
39 |
-
* [Current status](https://github.com/wp-e-commerce/wp-e-commerce/wiki/i18n-Status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== WP eCommerce ===
|
2 |
-
Contributors: JustinSainton, mufasa
|
3 |
-
Donate link:
|
4 |
Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
|
5 |
-
Requires at least: 3.
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 3.
|
8 |
|
9 |
WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily.
|
10 |
|
@@ -13,14 +13,14 @@ WP eCommerce is a free, powerful plugin that empowers you to sell anything onlin
|
|
13 |
Since 2006, we've been helping entrepreneurs just like you realize their goal of selling online. Whether you're hoping to sell digital downloads, physical inventory, or subscriptions and memberships - with WP eCommerce, you're only minutes away from your next sale.
|
14 |
|
15 |
* Make the plugin your own with CSS and HTML customizations
|
16 |
-
* Learn quickly with our [video tutorials](http://docs.
|
17 |
-
* Integration with [dozens of different payment gateways](http://
|
18 |
* Integrate with many popular WordPress plugins
|
19 |
* Use built-in marketing tools to sell more
|
20 |
* Shipping is easy with built in shipping tools and integration with popular couriers
|
21 |
* Secure check-out with SSL
|
22 |
* Manage your orders and catalogues with powerful built-in tools
|
23 |
-
* Extend your eCommerce site with [additional modules](http://
|
24 |
* Integrate with WordPress multisite
|
25 |
* With hundreds of available hooks, developers can make WP eCommerce do anything you can imagine
|
26 |
|
@@ -36,16 +36,47 @@ After upgrading from earlier versions look for link "Update Store". This will up
|
|
36 |
|
37 |
== Changelog ==
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
= 3.8.14.4 =
|
40 |
|
41 |
-
* Fix:
|
42 |
-
* Fix:
|
43 |
-
* Fix: Ensure shipping is always properly calculated when using table rate and it is the only available rate.
|
44 |
|
45 |
= 3.8.14.3 =
|
46 |
|
47 |
-
* Fix:
|
48 |
-
* Fix: Fixed stats class notices.
|
49 |
|
50 |
= 3.8.14.2 =
|
51 |
|
@@ -140,7 +171,7 @@ After upgrading from earlier versions look for link "Update Store". This will up
|
|
140 |
* Change: Improved security for our customer cookie hash.
|
141 |
* Change: Don't default to base country of store in checkout fields.
|
142 |
* Change: Taxes class previously regarded regions as unique, when they are not. We now check both region and country where applicable.
|
143 |
-
* Change: By default, quantity boxes will be shown
|
144 |
|
145 |
= 3.8.13.3 =
|
146 |
* Fix: Users disappear in Network Admin -> Users page (for multisite).
|
@@ -724,38 +755,36 @@ After upgrading from earlier versions look for link "Update Store". This will up
|
|
724 |
|
725 |
First of all, you should check out the Presentation settings which are in the Settings -> Store page.
|
726 |
|
727 |
-
For advanced users, all of our eCommerce templates and CSS can be moved into your active theme folder for customization. Less advanced users have [several fantastic WP eCommerce consultants](
|
728 |
|
729 |
= What payment gateways does WP eCommerce integrate with? =
|
730 |
|
731 |
-
Our [Gold Cart plugin](
|
732 |
|
733 |
= I want to integrate a payment gateway that you don't support. Can you help with that? =
|
734 |
|
735 |
-
Absolutely! We have a [growing list of trusted consultants](
|
736 |
|
737 |
= Which couriers does the plugin integrate with? =
|
738 |
|
739 |
We have table rate, weight rate and flat rate shipping calculators.
|
740 |
|
741 |
-
We also currently integrate with UPS, USPS, Australia Post and Shipwire for real-time shipping rates. We have a premium plugin for [FedEx](
|
742 |
|
743 |
= Which multi-lingual plugins is WP eCommerce compatible with? =
|
744 |
|
745 |
We currently provide basic support for WPML and qTranslate. We're excited about an up-and-coming multi-lingual project called [Babble](https://github.com/cftp/babble). We intend to fully and canonically support Babble as our primary multi-lingual partner in releases to come.
|
746 |
|
747 |
-
= Which additional modules are available for use with WP
|
748 |
|
749 |
-
* [Gold Cart](
|
750 |
-
* [
|
751 |
-
* [
|
752 |
-
* [
|
753 |
-
* [Product Slider](http://getshopped.org/premium-upgrades/premium-plugin/product-slider-image-carousel-wordpress/) - Display your products in a new and fancy way
|
754 |
-
* [Members Plugin](http://getshopped.org/premium-upgrades/premium-plugin/product-slider-image-carousel-wordpress/) - Integrates with PayPal Standard and Authorize.Net, allows you to create a Subscription-Based Product, as well as a "Members-Only" website with paid access to restricted content.
|
755 |
|
756 |
= How do you provide support? =
|
757 |
|
758 |
-
For users who have purchased a premium plugin from us (or a have purchased a [premium support token](
|
759 |
|
760 |
For the rest of our users, we do our best to monitor the WordPress.org support forums and respond in as timely a manner as we are able. We appreciate the countless helpful volunteers who also take time to respond to forum posts here.
|
761 |
|
1 |
=== WP eCommerce ===
|
2 |
+
Contributors: JustinSainton, mufasa
|
3 |
+
Donate link: https://wpecommerce.org
|
4 |
Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
|
5 |
+
Requires at least: 3.9
|
6 |
+
Tested up to: 4.1
|
7 |
+
Stable tag: 3.9
|
8 |
|
9 |
WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily.
|
10 |
|
13 |
Since 2006, we've been helping entrepreneurs just like you realize their goal of selling online. Whether you're hoping to sell digital downloads, physical inventory, or subscriptions and memberships - with WP eCommerce, you're only minutes away from your next sale.
|
14 |
|
15 |
* Make the plugin your own with CSS and HTML customizations
|
16 |
+
* Learn quickly with our [video tutorials](http://docs.wpecommerce.org/category/resources/videos/)
|
17 |
+
* Integration with [dozens of different payment gateways](http://wpecommerce.org/store/premium-plugins/)
|
18 |
* Integrate with many popular WordPress plugins
|
19 |
* Use built-in marketing tools to sell more
|
20 |
* Shipping is easy with built in shipping tools and integration with popular couriers
|
21 |
* Secure check-out with SSL
|
22 |
* Manage your orders and catalogues with powerful built-in tools
|
23 |
+
* Extend your eCommerce site with [additional modules](http://wpecommerce.org/store/premium-plugins/)
|
24 |
* Integrate with WordPress multisite
|
25 |
* With hundreds of available hooks, developers can make WP eCommerce do anything you can imagine
|
26 |
|
36 |
|
37 |
== Changelog ==
|
38 |
|
39 |
+
= 3.9 =
|
40 |
+
|
41 |
+
* Fix: Eliminate most usage of number-based inputs in product UI.
|
42 |
+
* Fix: Fall back to product ID if SKU is not set for Google Analytics reporting.
|
43 |
+
* Fix: Restored inadvertently removed filter, `wpsc_add_advanced_options`.
|
44 |
+
* Fix: Ensure price entered for "Free Shipping" threshold is locale-aware.
|
45 |
+
* Fix: Generally improved metadata saving routines for quick/bulk edit areas.
|
46 |
+
* Fix: Ensure "Combination of product variants is not available" message is hidden from Grid View.
|
47 |
+
* Fix: Don't require a shipping method to be selected if you qualify for free shipping.
|
48 |
+
* Fix: When "Buy Now" button is used, it is now disabled if item is out of stock.
|
49 |
+
* New: Introduced `wpsc_get_countries` and `wpsc_get_countries_array` filters.
|
50 |
+
* New: Introduced `wpsc_google_analytics_pushed_product` filter.
|
51 |
+
* New: Introduced `wpsc_get_downloadable_links` filter.
|
52 |
+
* New: Added screen option for number of purchase logs to show on a page.
|
53 |
+
* New: Introduced WPSC_Logging class. Based on WP_Logging.
|
54 |
+
* New: Customers may now checkout with carts that have a value of $0.
|
55 |
+
* New: Introduces `wpsc_is_free_cart` filter.
|
56 |
+
* New: Added 2.0 theme engine component. Defaults off until the 4.0 release, but can be enabled via filter for testing.
|
57 |
+
* New: Added marketplace component.
|
58 |
+
* New: Added 3.0 payment gateway API component.
|
59 |
+
* New: PayPal Digital Goods gateway, updated PayPal Express Checkout, PayPal Pro and Manual Payment gateways.
|
60 |
+
* New: Product Tags now have proper body classes.
|
61 |
+
* New: Meta updates, kind of a big deal: We're now using X.X.Y versioning (like WordPress) and we now have unit tests.
|
62 |
+
* New: Introduce attachments method and filter for WPSC_Purchase_Log_Notification class.
|
63 |
+
* New: Single Product pages now have ID-based body classes.
|
64 |
+
* New: Supports Universal Analytics in Google Analytics.
|
65 |
+
* New: Added `wpsc_checkout_fields` filter for filtering checkout form fields.
|
66 |
+
* Change: Dates are now optional on coupons. Expiration, specifically, is no longer required. Validation is filterable via `wpsc_coupons_validate_coupon`.
|
67 |
+
* Change: Refactored purchase log action links, introduced new API for adding links.
|
68 |
+
* Change: Product page shortcodes, e.g. [productspage], are now stripped from the_excerpt(). Helpful for cleaner looking search results.
|
69 |
+
* Change: Limit Google Product ID to 50 characters in Google Product Feed. Introduced `wpsc_google_product_feed_product_id`.
|
70 |
+
* Change: When only one shipping rate is available, it will automatically be selected as the default rate.
|
71 |
+
|
72 |
= 3.8.14.4 =
|
73 |
|
74 |
+
* Fix: Significant security vulnerability whereby some admin actions were exploitable by unauthorized users. Props to Sucuri for the responsible disclosure.
|
75 |
+
* Fix: Other less significant security hardening and minor code maintenance.
|
|
|
76 |
|
77 |
= 3.8.14.3 =
|
78 |
|
79 |
+
* Fix: Resolve PHP warning in stats logging class.
|
|
|
80 |
|
81 |
= 3.8.14.2 =
|
82 |
|
171 |
* Change: Improved security for our customer cookie hash.
|
172 |
* Change: Don't default to base country of store in checkout fields.
|
173 |
* Change: Taxes class previously regarded regions as unique, when they are not. We now check both region and country where applicable.
|
174 |
+
* Change: By default, quantity boxes will be shown on new installs.
|
175 |
|
176 |
= 3.8.13.3 =
|
177 |
* Fix: Users disappear in Network Admin -> Users page (for multisite).
|
755 |
|
756 |
First of all, you should check out the Presentation settings which are in the Settings -> Store page.
|
757 |
|
758 |
+
For advanced users, all of our eCommerce templates and CSS can be moved into your active theme folder for customization. Less advanced users have [several fantastic WP eCommerce consultants](https://wpecommerce.org/hire-an-expert/) to get help from.
|
759 |
|
760 |
= What payment gateways does WP eCommerce integrate with? =
|
761 |
|
762 |
+
Our [Gold Cart plugin](https://wpecommerce.org/store/premium-plugins/gold-cart/) contains nearly a dozen payment gateway options, including Authorize.net, LinkPoint and DPS. Our [Mirijeh integration plugin](https://wpecommerce.org/store/premium-plugins/mijireh-99-payment-gateways-pack/) provides access to nearly one hundred different gateway options. Beyond that, we have individual integration plugins for [Braintree](https://wpecommerce.org/store/premium-plugins/braintree-payment-gateway/), [Stripe](https://wpecommerce.org/store/premium-plugins/stripe/), [Authorize.net SIM](https://wpecommerce.org/store/premium-plugins/authorize-net-sim-payment-gateway-for-wordpress/) and more.
|
763 |
|
764 |
= I want to integrate a payment gateway that you don't support. Can you help with that? =
|
765 |
|
766 |
+
Absolutely! We have a [growing list of trusted consultants](https://wpecommerce.org/hire-an-expert/) who would be happy to partner with you to build a custom gateway. Alternatively, you're more than welcome to request that we build it as a plugin or part of our core plugin. The more requests we get, the more likely we are to build it. If you happen to be a talented developer, we have a great documentation site with helpful information on building payment gateways
|
767 |
|
768 |
= Which couriers does the plugin integrate with? =
|
769 |
|
770 |
We have table rate, weight rate and flat rate shipping calculators.
|
771 |
|
772 |
+
We also currently integrate with UPS, USPS, Australia Post and Shipwire for real-time shipping rates. We have a premium plugin for [FedEx](https://wpecommerce.org/store/premium-plugins/fedex-shipping-module/) as well.
|
773 |
|
774 |
= Which multi-lingual plugins is WP eCommerce compatible with? =
|
775 |
|
776 |
We currently provide basic support for WPML and qTranslate. We're excited about an up-and-coming multi-lingual project called [Babble](https://github.com/cftp/babble). We intend to fully and canonically support Babble as our primary multi-lingual partner in releases to come.
|
777 |
|
778 |
+
= Which additional modules are available for use with WP eCommerce? =
|
779 |
|
780 |
+
* [Gold Cart](https://wpecommerce.org/store/premium-plugins/gold-cart/) - adds more options, gateways and functionality to your store
|
781 |
+
* [MP3 Audio Player](https://wpecommerce.org/store/premium-plugins/mp3-player-plugin/) - Preview audio clips on your website
|
782 |
+
* [NextGen Gallery Buy Now Buttons](https://wpecommerce.org/store/premium-plugins/nextgen-gallery-buy-now-buttons/) - turns your NextGen gallery into an eCommerce solution
|
783 |
+
* [Members Plugin](https://wpecommerce.org/store/premium-plugins/membership-subscriptions/) - Integrates with PayPal Standard and Authorize.Net, allows you to create a Subscription-Based Product, as well as a "Members-Only" website with paid access to restricted content.
|
|
|
|
|
784 |
|
785 |
= How do you provide support? =
|
786 |
|
787 |
+
For users who have purchased a premium plugin from us (or a have purchased a [premium support token](https://wpecommerce.org/store/premium-plugins/premium-support-token/)), we offer high-touch, 1-on-1 support from our trained support staff. If you submit a support request here, you'll get a helpful response within 24 hours or less (during business hours).
|
788 |
|
789 |
For the rest of our users, we do our best to monitor the WordPress.org support forums and respond in as timely a manner as we are able. We appreciate the countless helpful volunteers who also take time to respond to forum posts here.
|
790 |
|
wp-shopping-cart.php
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Plugin Name: WP
|
4 |
-
* Plugin URI: http://
|
5 |
-
* Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://
|
6 |
-
* Version: 3.
|
7 |
-
* Author:
|
8 |
-
* Author URI: http://
|
9 |
**/
|
10 |
|
11 |
/**
|
@@ -17,8 +17,9 @@
|
|
17 |
*/
|
18 |
class WP_eCommerce {
|
19 |
private $components = array(
|
20 |
-
'merchant'
|
21 |
-
'marketplace'
|
|
|
22 |
);
|
23 |
|
24 |
/**
|
@@ -27,7 +28,7 @@ class WP_eCommerce {
|
|
27 |
* @uses add_action() Attaches to 'plugins_loaded' hook
|
28 |
* @uses add_action() Attaches to 'wpsc_components' hook
|
29 |
*/
|
30 |
-
function __construct() {
|
31 |
add_action( 'plugins_loaded' , array( $this, 'init' ), 8 );
|
32 |
add_filter( 'wpsc_components', array( $this, '_register_core_components' ) );
|
33 |
}
|
@@ -42,7 +43,7 @@ class WP_eCommerce {
|
|
42 |
* @uses do_action() Calls 'wpsc_pre_init' which runs before WPEC initializes
|
43 |
* @uses do_action() Calls 'wpsc_init' runs just after WPEC initializes
|
44 |
*/
|
45 |
-
function init() {
|
46 |
// Previous to initializing
|
47 |
do_action( 'wpsc_pre_init' );
|
48 |
|
@@ -69,19 +70,19 @@ class WP_eCommerce {
|
|
69 |
*/
|
70 |
public function _register_core_components( $components ) {
|
71 |
$components['merchant']['core-v2'] = array(
|
72 |
-
'title' => __( 'WP
|
73 |
'includes' =>
|
74 |
WPSC_FILE_PATH . '/wpsc-components/merchant-core-v2/merchant-core-v2.php'
|
75 |
);
|
76 |
|
77 |
-
$components['
|
78 |
-
'title' => __( 'WP
|
79 |
'includes' =>
|
80 |
-
WPSC_FILE_PATH . '/wpsc-components/
|
81 |
);
|
82 |
|
83 |
$components['marketplace']['core-v1'] = array(
|
84 |
-
'title' => __( 'WP
|
85 |
'includes' =>
|
86 |
WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/marketplace-core-v1.php'
|
87 |
);
|
@@ -90,33 +91,35 @@ class WP_eCommerce {
|
|
90 |
}
|
91 |
|
92 |
/**
|
93 |
-
* Initialize the basic
|
94 |
*
|
95 |
* @uses plugins_url() Retrieves url to plugins directory
|
96 |
* @uses load_plugin_textdomain() Loads plugin transations strings
|
97 |
* @uses plugin_basename() Gets the basename of a plugin (extracts the name of a plugin from its filename)
|
98 |
* @uses do_action() Calls 'wpsc_started' which runs after WPEC has started
|
99 |
*/
|
100 |
-
function start() {
|
101 |
// Set the core file path
|
102 |
define( 'WPSC_FILE_PATH', dirname( __FILE__ ) );
|
103 |
|
104 |
// Define the path to the plugin folder
|
105 |
define( 'WPSC_DIR_NAME', basename( WPSC_FILE_PATH ) );
|
|
|
106 |
|
107 |
// Define the URL to the plugin folder
|
108 |
-
define( 'WPSC_FOLDER', dirname(
|
109 |
define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
|
110 |
|
111 |
//load text domain
|
112 |
-
if ( ! load_plugin_textdomain( 'wpsc', false, '../languages/' ) )
|
113 |
-
load_plugin_textdomain( 'wpsc', false, dirname(
|
|
|
114 |
|
115 |
// Finished starting
|
116 |
do_action( 'wpsc_started' );
|
117 |
}
|
118 |
|
119 |
-
function setup_table_names() {
|
120 |
global $wpdb;
|
121 |
$wpdb->wpsc_meta = WPSC_TABLE_META;
|
122 |
$wpdb->wpsc_also_bought = WPSC_TABLE_ALSO_BOUGHT;
|
@@ -147,7 +150,7 @@ class WP_eCommerce {
|
|
147 |
* @uses wpsc_core_constants_uploads() Set the upload related constants
|
148 |
* @uses do_action() Calls 'wpsc_constants' which runs after the WPEC constants are defined
|
149 |
*/
|
150 |
-
function constants() {
|
151 |
// Define globals and constants used by wp-e-commerce
|
152 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-constants.php' );
|
153 |
|
@@ -182,22 +185,25 @@ class WP_eCommerce {
|
|
182 |
* @uses apply_filters() Calls 'wpsc_components' private merchant components
|
183 |
* @uses do_action() Calls 'wpsc_includes' which runs after WPEC files have been included
|
184 |
*/
|
185 |
-
function includes() {
|
186 |
-
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-util.php'
|
187 |
-
require_once( WPSC_FILE_PATH . '/wpsc-includes/customer.php'
|
188 |
-
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-customer.php'
|
189 |
-
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-visitor.php'
|
190 |
-
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-cart-item.php'
|
191 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-functions.php' );
|
192 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
|
193 |
-
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-includes.php'
|
194 |
|
195 |
$this->components = apply_filters( 'wpsc_components', $this->components );
|
196 |
|
197 |
foreach ( $this->components as $type => $registered ) {
|
198 |
foreach ( $registered as $component ) {
|
199 |
-
|
|
|
200 |
$component['includes'] = array( $component['includes' ] );
|
|
|
|
|
201 |
foreach ( $component['includes'] as $include ) {
|
202 |
require_once( $include );
|
203 |
}
|
@@ -224,7 +230,7 @@ class WP_eCommerce {
|
|
224 |
* @uses wpsc_core_load_page_titles() Loads the core WPEC pagetitles
|
225 |
* @uses do_action() Calls 'wpsc_loaded' which runs after WPEC is fully loaded
|
226 |
*/
|
227 |
-
function load() {
|
228 |
// Before setup
|
229 |
do_action( 'wpsc_pre_load' );
|
230 |
|
@@ -255,7 +261,7 @@ class WP_eCommerce {
|
|
255 |
do_action( 'wpsc_loaded' );
|
256 |
}
|
257 |
|
258 |
-
function _wpsc_fire_ready_action() {
|
259 |
// WPEC is ready to use as soon as WordPress and customer is setup and loaded
|
260 |
do_action( 'wpsc_ready' );
|
261 |
}
|
@@ -267,7 +273,7 @@ class WP_eCommerce {
|
|
267 |
* @uses wp_die() Kills loading and returns the HTML
|
268 |
* @uses wpsc_install() Performs checks to see if this is a clean install or not
|
269 |
*/
|
270 |
-
function install() {
|
271 |
|
272 |
if ( ! defined( 'WPSC_FILE_PATH' ) ) {
|
273 |
define( 'WPSC_FILE_PATH', dirname( __FILE__ ) );
|
@@ -276,15 +282,13 @@ class WP_eCommerce {
|
|
276 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
|
277 |
$this->constants();
|
278 |
wpsc_install();
|
279 |
-
|
280 |
}
|
281 |
|
282 |
/**
|
283 |
-
* Runs the WPEC deactivation routines
|
284 |
-
* jobs that WPEC has set.
|
285 |
*
|
286 |
-
* @uses wp_get_schedules() Retrieves all filtered
|
287 |
-
* @uses wp_clear_scheduled_hook() Removes any hooks on
|
288 |
*/
|
289 |
public function deactivate() {
|
290 |
foreach ( wp_get_schedules() as $cron => $schedule ) {
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Plugin Name: WP eCommerce
|
4 |
+
* Plugin URI: http://wpecommerce.org/
|
5 |
+
* Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://wpecommerce.org" target="_blank">WPeCommerce.org</a> | <a href="https://wordpress.org/support/plugin/wp-e-commerce/" target="_blank">Support Forum</a> | <a href="http://docs.wpecommerce.org/" target="_blank">Documentation</a>
|
6 |
+
* Version: 3.9
|
7 |
+
* Author: WP eCommerce
|
8 |
+
* Author URI: http://wpecommerce.org/
|
9 |
**/
|
10 |
|
11 |
/**
|
17 |
*/
|
18 |
class WP_eCommerce {
|
19 |
private $components = array(
|
20 |
+
'merchant' => array(),
|
21 |
+
'marketplace' => array(),
|
22 |
+
'theme-engine' => array(),
|
23 |
);
|
24 |
|
25 |
/**
|
28 |
* @uses add_action() Attaches to 'plugins_loaded' hook
|
29 |
* @uses add_action() Attaches to 'wpsc_components' hook
|
30 |
*/
|
31 |
+
public function __construct() {
|
32 |
add_action( 'plugins_loaded' , array( $this, 'init' ), 8 );
|
33 |
add_filter( 'wpsc_components', array( $this, '_register_core_components' ) );
|
34 |
}
|
43 |
* @uses do_action() Calls 'wpsc_pre_init' which runs before WPEC initializes
|
44 |
* @uses do_action() Calls 'wpsc_init' runs just after WPEC initializes
|
45 |
*/
|
46 |
+
public function init() {
|
47 |
// Previous to initializing
|
48 |
do_action( 'wpsc_pre_init' );
|
49 |
|
70 |
*/
|
71 |
public function _register_core_components( $components ) {
|
72 |
$components['merchant']['core-v2'] = array(
|
73 |
+
'title' => __( 'WP eCommerce Merchant API v2', 'wpsc' ),
|
74 |
'includes' =>
|
75 |
WPSC_FILE_PATH . '/wpsc-components/merchant-core-v2/merchant-core-v2.php'
|
76 |
);
|
77 |
|
78 |
+
$components['merchant']['core-v3'] = array(
|
79 |
+
'title' => __( 'WP eCommerce Merchant API v3', 'wpsc' ),
|
80 |
'includes' =>
|
81 |
+
WPSC_FILE_PATH . '/wpsc-components/merchant-core-v3/merchant-core-v3.php'
|
82 |
);
|
83 |
|
84 |
$components['marketplace']['core-v1'] = array(
|
85 |
+
'title' => __( 'WP eCommerce Marketplace API v1', 'wpsc' ),
|
86 |
'includes' =>
|
87 |
WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/marketplace-core-v1.php'
|
88 |
);
|
91 |
}
|
92 |
|
93 |
/**
|
94 |
+
* Initialize the basic WP eCommerce constants
|
95 |
*
|
96 |
* @uses plugins_url() Retrieves url to plugins directory
|
97 |
* @uses load_plugin_textdomain() Loads plugin transations strings
|
98 |
* @uses plugin_basename() Gets the basename of a plugin (extracts the name of a plugin from its filename)
|
99 |
* @uses do_action() Calls 'wpsc_started' which runs after WPEC has started
|
100 |
*/
|
101 |
+
public function start() {
|
102 |
// Set the core file path
|
103 |
define( 'WPSC_FILE_PATH', dirname( __FILE__ ) );
|
104 |
|
105 |
// Define the path to the plugin folder
|
106 |
define( 'WPSC_DIR_NAME', basename( WPSC_FILE_PATH ) );
|
107 |
+
define( 'WPSC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
108 |
|
109 |
// Define the URL to the plugin folder
|
110 |
+
define( 'WPSC_FOLDER', dirname( WPSC_PLUGIN_BASENAME ) );
|
111 |
define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
|
112 |
|
113 |
//load text domain
|
114 |
+
if ( ! load_plugin_textdomain( 'wpsc', false, '../languages/' ) ) {
|
115 |
+
load_plugin_textdomain( 'wpsc', false, dirname( WPSC_PLUGIN_BASENAME ) . '/wpsc-languages/' );
|
116 |
+
}
|
117 |
|
118 |
// Finished starting
|
119 |
do_action( 'wpsc_started' );
|
120 |
}
|
121 |
|
122 |
+
public function setup_table_names() {
|
123 |
global $wpdb;
|
124 |
$wpdb->wpsc_meta = WPSC_TABLE_META;
|
125 |
$wpdb->wpsc_also_bought = WPSC_TABLE_ALSO_BOUGHT;
|
150 |
* @uses wpsc_core_constants_uploads() Set the upload related constants
|
151 |
* @uses do_action() Calls 'wpsc_constants' which runs after the WPEC constants are defined
|
152 |
*/
|
153 |
+
public function constants() {
|
154 |
// Define globals and constants used by wp-e-commerce
|
155 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-constants.php' );
|
156 |
|
185 |
* @uses apply_filters() Calls 'wpsc_components' private merchant components
|
186 |
* @uses do_action() Calls 'wpsc_includes' which runs after WPEC files have been included
|
187 |
*/
|
188 |
+
public function includes() {
|
189 |
+
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-util.php' );
|
190 |
+
require_once( WPSC_FILE_PATH . '/wpsc-includes/customer.php' );
|
191 |
+
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-customer.php' );
|
192 |
+
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-visitor.php' );
|
193 |
+
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-cart-item.php' );
|
194 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-functions.php' );
|
195 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
|
196 |
+
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-includes.php' );
|
197 |
|
198 |
$this->components = apply_filters( 'wpsc_components', $this->components );
|
199 |
|
200 |
foreach ( $this->components as $type => $registered ) {
|
201 |
foreach ( $registered as $component ) {
|
202 |
+
|
203 |
+
if ( ! is_array( $component['includes'] ) ) {
|
204 |
$component['includes'] = array( $component['includes' ] );
|
205 |
+
}
|
206 |
+
|
207 |
foreach ( $component['includes'] as $include ) {
|
208 |
require_once( $include );
|
209 |
}
|
230 |
* @uses wpsc_core_load_page_titles() Loads the core WPEC pagetitles
|
231 |
* @uses do_action() Calls 'wpsc_loaded' which runs after WPEC is fully loaded
|
232 |
*/
|
233 |
+
public function load() {
|
234 |
// Before setup
|
235 |
do_action( 'wpsc_pre_load' );
|
236 |
|
261 |
do_action( 'wpsc_loaded' );
|
262 |
}
|
263 |
|
264 |
+
public function _wpsc_fire_ready_action() {
|
265 |
// WPEC is ready to use as soon as WordPress and customer is setup and loaded
|
266 |
do_action( 'wpsc_ready' );
|
267 |
}
|
273 |
* @uses wp_die() Kills loading and returns the HTML
|
274 |
* @uses wpsc_install() Performs checks to see if this is a clean install or not
|
275 |
*/
|
276 |
+
public function install() {
|
277 |
|
278 |
if ( ! defined( 'WPSC_FILE_PATH' ) ) {
|
279 |
define( 'WPSC_FILE_PATH', dirname( __FILE__ ) );
|
282 |
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
|
283 |
$this->constants();
|
284 |
wpsc_install();
|
|
|
285 |
}
|
286 |
|
287 |
/**
|
288 |
+
* Runs the WPEC deactivation routines.
|
|
|
289 |
*
|
290 |
+
* @uses wp_get_schedules() Retrieves all filtered WP_Cron recurrences
|
291 |
+
* @uses wp_clear_scheduled_hook() Removes any hooks on WP_Cron
|
292 |
*/
|
293 |
public function deactivate() {
|
294 |
foreach ( wp_get_schedules() as $cron => $schedule ) {
|
wpsc-admin/admin-form-functions.php
CHANGED
@@ -1,4 +1,11 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
function coupon_edit_form($coupon) {
|
3 |
|
4 |
$conditions = maybe_unserialize($coupon['condition']);
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The Admin Form Functions
|
4 |
+
*
|
5 |
+
* These are the functions that power administrative forms in the WordPress admin
|
6 |
+
*
|
7 |
+
* @package wp-e-commerce
|
8 |
+
*/
|
9 |
function coupon_edit_form($coupon) {
|
10 |
|
11 |
$conditions = maybe_unserialize($coupon['condition']);
|
wpsc-admin/admin.php
CHANGED
@@ -25,7 +25,6 @@ require_once( WPSC_FILE_PATH . '/wpsc-admin/ajax-and-init.php' );
|
|
25 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/display-options-settings.page.php' );
|
26 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/db-upgrades/upgrade.php' );
|
27 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/media.php' );
|
28 |
-
require_once( WPSC_FILE_PATH . '/wpsc-admin/users.php' );
|
29 |
|
30 |
if ( ( isset( $_SESSION['wpsc_activate_debug_page'] ) && ( $_SESSION['wpsc_activate_debug_page'] == true ) ) || ( defined( 'WPSC_ADD_DEBUG_PAGE' ) && ( constant( 'WPSC_ADD_DEBUG_PAGE' ) == true ) ) )
|
31 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/display-debug.page.php' );
|
@@ -89,7 +88,7 @@ function wpsc_admin_edit_posts_orderby( $orderby_sql ) {
|
|
89 |
add_filter( 'posts_orderby', 'wpsc_admin_edit_posts_orderby' );
|
90 |
|
91 |
/**
|
92 |
-
* setting the screen option to between 1 and 999
|
93 |
*
|
94 |
* @since 3.8
|
95 |
* @access public
|
@@ -102,7 +101,7 @@ add_filter( 'posts_orderby', 'wpsc_admin_edit_posts_orderby' );
|
|
102 |
* @return $value after changes...
|
103 |
*/
|
104 |
function wpsc_set_screen_option($status, $option, $value){
|
105 |
-
if( in_array($option, array ("edit_wpsc_variation_per_page","edit_wpsc_product_per_page" )) ){
|
106 |
if ( "edit_wpsc_variation_per_page" == $option ){
|
107 |
global $user_ID;
|
108 |
update_user_option($user_ID,'edit_wpsc-variation_per_page',$value);
|
@@ -132,7 +131,7 @@ function wpsc_drag_and_drop_ordering($per_page, $post_type){
|
|
132 |
return $per_page;
|
133 |
}
|
134 |
add_filter( 'request', 'wpsc_query_vars_product_list' );
|
135 |
-
add_filter('edit_posts_per_page' , 'wpsc_drag_and_drop_ordering', 10, 2 );
|
136 |
|
137 |
/**
|
138 |
* Checks whether to display or hide the update wp-e-commerce link
|
@@ -264,6 +263,8 @@ function wpsc_admin_pages() {
|
|
264 |
add_action( 'load-post-new.php' , 'wpsc_add_help_tabs' );
|
265 |
add_action( 'load-edit-tags.php' , 'wpsc_add_help_tabs' );
|
266 |
|
|
|
|
|
267 |
}
|
268 |
|
269 |
/**
|
@@ -353,7 +354,7 @@ function wpsc_add_help_tabs() {
|
|
353 |
$content = '<p><strong>' . __( 'For More Information', 'wpsc' ) . '</strong></p>';
|
354 |
$links = array();
|
355 |
foreach( $tab['links'] as $link => $link_title ) {
|
356 |
-
$link = 'http://docs.
|
357 |
$links[] = '<a target="_blank" href="' . esc_url( $link ) . '">' . esc_html( $link_title ) . '</a>';
|
358 |
}
|
359 |
$content .= '<p>' . implode( '<br />', $links ) . '</p>';
|
@@ -367,6 +368,24 @@ function wpsc_add_help_tabs() {
|
|
367 |
}
|
368 |
}
|
369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
/**
|
371 |
* Includes purchase logs CSS and JS
|
372 |
*
|
@@ -389,8 +408,16 @@ function wpsc_admin_include_purchase_logs_css_and_js() {
|
|
389 |
'sent_message' => _x( 'Email Sent!', 'sending tracking email for purchase log', 'wpsc' ),
|
390 |
'current_view' => empty( $_REQUEST['status'] ) ? 'all' : $_REQUEST['status'],
|
391 |
'current_filter' => empty( $_REQUEST['m'] ) ? '' : $_REQUEST['m'],
|
392 |
-
'current_page' => empty( $_REQUEST['paged']) ? '' : $_REQUEST['paged'],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
) );
|
|
|
394 |
}
|
395 |
|
396 |
/**
|
@@ -432,7 +459,7 @@ function wpsc_display_purchase_logs_page() {
|
|
432 |
* @uses admin_url() Retrieves URL to the WordPress admin
|
433 |
*/
|
434 |
function wpsc_product_log_rss_feed() {
|
435 |
-
echo "<link type='application/rss+xml' href='" . add_query_arg( array( 'rss' => 'true', 'rss_key' => 'key', 'action' => 'purchase_log', 'type' => 'rss' ), admin_url( 'index.php' ) ) . "' title='" .
|
436 |
}
|
437 |
|
438 |
/**
|
@@ -583,24 +610,32 @@ function wpsc_admin_include_css_and_js_refac( $pagehook ) {
|
|
583 |
}
|
584 |
wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
|
585 |
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
'
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
}
|
605 |
if ( $pagehook == 'wpsc-product-variations-iframe' ) {
|
606 |
_wpsc_enqueue_wp_e_commerce_admin();
|
@@ -821,7 +856,7 @@ function wpsc_dashboard_widget_setup() {
|
|
821 |
|
822 |
// Add the dashboard widgets
|
823 |
if ( current_user_can( $news_cap ) )
|
824 |
-
wp_add_dashboard_widget( 'wpsc_dashboard_news', __( 'WP
|
825 |
if ( current_user_can( $sales_cap ) )
|
826 |
wp_add_dashboard_widget( 'wpsc_dashboard_widget', __( 'Sales Summary', 'wpsc' ), 'wpsc_dashboard_widget' );
|
827 |
if ( current_user_can( $quarterly_sales_cap ) )
|
@@ -876,7 +911,7 @@ add_action( 'wp_dashboard_setup', 'wpsc_dashboard_widget_setup' );
|
|
876 |
* @uses wp_widget_rss_output() Display the RSS entries in a list
|
877 |
*/
|
878 |
function wpsc_dashboard_news() {
|
879 |
-
$rss = fetch_feed( '
|
880 |
$args = array( 'show_author' => 1, 'show_date' => 1, 'show_summary' => 1, 'items' => 3 );
|
881 |
wp_widget_rss_output( $rss, $args );
|
882 |
|
@@ -891,11 +926,11 @@ function wpsc_dashboard_news() {
|
|
891 |
* @return array The array of prices
|
892 |
*/
|
893 |
function wpsc_get_quarterly_summary() {
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
|
900 |
$results[] = admin_display_total_price( $thirdquarter + 1, $fourthquarter );
|
901 |
$results[] = admin_display_total_price( $secondquarter + 1, $thirdquarter );
|
@@ -1246,12 +1281,12 @@ function _wpsc_action_admin_notices_deprecated_countries_notice() {
|
|
1246 |
$message = __( 'Yugoslavia is no longer a valid official country name according to <a href="%1$s">ISO 3166</a> while both Serbia and Montenegro have been added to the country list.<br /> As a result, we highly recommend changing your <em>Base Country</em> to reflect this change on the <a href="%2$s">General Settings</a> page.', 'wpsc' );
|
1247 |
break;
|
1248 |
case 'UK':
|
1249 |
-
$message = __( 'Prior to WP
|
1250 |
break;
|
1251 |
case 'AN':
|
1252 |
$message = __( 'Netherlands Antilles is no longer a valid official country name according to <a href="%1$s">ISO 3166</a>.<br />Please consider changing your <em>Base Country</em> to reflect this change on the <a href="%2$s">General Settings</a> page.', 'wpsc' );
|
1253 |
case 'TP':
|
1254 |
-
$message = __( 'Prior to WP
|
1255 |
break;
|
1256 |
}
|
1257 |
|
@@ -1349,6 +1384,8 @@ function wpsc_duplicate_product_process( $post, $new_parent_id = false ) {
|
|
1349 |
// Copy the meta information
|
1350 |
wpsc_duplicate_product_meta( $post->ID, $new_post_id );
|
1351 |
|
|
|
|
|
1352 |
// Finds children (Which includes product files AND product images), their meta values, and duplicates them.
|
1353 |
wpsc_duplicate_children( $post->ID, $new_post_id );
|
1354 |
|
@@ -1408,7 +1445,9 @@ function wpsc_duplicate_product_meta( $id, $new_id ) {
|
|
1408 |
$sql_query.= implode( ",", $sql_query_sel );
|
1409 |
$sql_query = $wpdb->prepare( $sql_query, $values );
|
1410 |
$wpdb->query( $sql_query );
|
|
|
1411 |
}
|
|
|
1412 |
}
|
1413 |
|
1414 |
/**
|
@@ -1422,7 +1461,7 @@ function wpsc_duplicate_product_meta( $id, $new_id ) {
|
|
1422 |
*/
|
1423 |
function wpsc_duplicate_children( $old_parent_id, $new_parent_id ) {
|
1424 |
|
1425 |
-
//Get children products and duplicate them
|
1426 |
$child_posts = get_posts( array(
|
1427 |
'post_parent' => $old_parent_id,
|
1428 |
'post_type' => 'any',
|
@@ -1432,7 +1471,95 @@ function wpsc_duplicate_children( $old_parent_id, $new_parent_id ) {
|
|
1432 |
) );
|
1433 |
|
1434 |
foreach ( $child_posts as $child_post ) {
|
1435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1436 |
}
|
1437 |
|
1438 |
}
|
@@ -1446,11 +1573,11 @@ function wpsc_duplicate_children( $old_parent_id, $new_parent_id ) {
|
|
1446 |
* @uses get_option() Gets option from the database given string
|
1447 |
*/
|
1448 |
function _wpsc_admin_notices_3dot8dot9() {
|
1449 |
-
$message = '<p>' . __( 'You are currently using WP
|
1450 |
$message .= "\n<p>" . __( '<a href="%2$s">Hide this warning</a>', 'wpsc' ) . '</p>';
|
1451 |
$message = sprintf(
|
1452 |
$message,
|
1453 |
-
'
|
1454 |
add_query_arg( 'dismiss_389_upgrade_notice', 1 )
|
1455 |
);
|
1456 |
|
@@ -1524,7 +1651,7 @@ function _wpsc_admin_notices_3dot8dot11() {
|
|
1524 |
$message,
|
1525 |
WPSC_VERSION,
|
1526 |
'https://github.com/wp-e-commerce/WP-e-Commerce/issues/359',
|
1527 |
-
'http://docs.
|
1528 |
add_query_arg( 'dismiss_3811_upgrade_notice', 1 )
|
1529 |
);
|
1530 |
|
@@ -1560,11 +1687,18 @@ if ( in_array( 'google', get_option( 'custom_gateway_options', array() ) ) ) {
|
|
1560 |
}
|
1561 |
|
1562 |
/**
|
1563 |
-
*
|
|
|
|
|
1564 |
*
|
1565 |
-
* @
|
1566 |
-
* @return
|
1567 |
*/
|
1568 |
-
function
|
1569 |
-
|
1570 |
-
|
|
|
|
|
|
|
|
|
|
25 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/display-options-settings.page.php' );
|
26 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/db-upgrades/upgrade.php' );
|
27 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/media.php' );
|
|
|
28 |
|
29 |
if ( ( isset( $_SESSION['wpsc_activate_debug_page'] ) && ( $_SESSION['wpsc_activate_debug_page'] == true ) ) || ( defined( 'WPSC_ADD_DEBUG_PAGE' ) && ( constant( 'WPSC_ADD_DEBUG_PAGE' ) == true ) ) )
|
30 |
require_once( WPSC_FILE_PATH . '/wpsc-admin/display-debug.page.php' );
|
88 |
add_filter( 'posts_orderby', 'wpsc_admin_edit_posts_orderby' );
|
89 |
|
90 |
/**
|
91 |
+
* setting the product & variations per page screen option to between 1 and 999
|
92 |
*
|
93 |
* @since 3.8
|
94 |
* @access public
|
101 |
* @return $value after changes...
|
102 |
*/
|
103 |
function wpsc_set_screen_option($status, $option, $value){
|
104 |
+
if( in_array($option, array ("edit_wpsc_variation_per_page","edit_wpsc_product_per_page", "wpsc_purchases_per_page" )) ){
|
105 |
if ( "edit_wpsc_variation_per_page" == $option ){
|
106 |
global $user_ID;
|
107 |
update_user_option($user_ID,'edit_wpsc-variation_per_page',$value);
|
131 |
return $per_page;
|
132 |
}
|
133 |
add_filter( 'request', 'wpsc_query_vars_product_list' );
|
134 |
+
add_filter( 'edit_posts_per_page' , 'wpsc_drag_and_drop_ordering', 10, 2 );
|
135 |
|
136 |
/**
|
137 |
* Checks whether to display or hide the update wp-e-commerce link
|
263 |
add_action( 'load-post-new.php' , 'wpsc_add_help_tabs' );
|
264 |
add_action( 'load-edit-tags.php' , 'wpsc_add_help_tabs' );
|
265 |
|
266 |
+
// screen options on Sales Log
|
267 |
+
add_action( 'load-' . $purchase_logs_page , 'wpsc_add_purchase_logs_screen_option' );
|
268 |
}
|
269 |
|
270 |
/**
|
354 |
$content = '<p><strong>' . __( 'For More Information', 'wpsc' ) . '</strong></p>';
|
355 |
$links = array();
|
356 |
foreach( $tab['links'] as $link => $link_title ) {
|
357 |
+
$link = 'http://docs.wpecommerce.org/' . $link;
|
358 |
$links[] = '<a target="_blank" href="' . esc_url( $link ) . '">' . esc_html( $link_title ) . '</a>';
|
359 |
}
|
360 |
$content .= '<p>' . implode( '<br />', $links ) . '</p>';
|
368 |
}
|
369 |
}
|
370 |
|
371 |
+
/**
|
372 |
+
* This function allows change in number of purchase logs shown on Sales Log (Screen Options).
|
373 |
+
*
|
374 |
+
* @since 3.9
|
375 |
+
* @access public
|
376 |
+
*
|
377 |
+
* @uses add_screen_option()
|
378 |
+
*/
|
379 |
+
function wpsc_add_purchase_logs_screen_option(){
|
380 |
+
|
381 |
+
// setup Screen Option for purchase logs per page
|
382 |
+
add_screen_option( 'per_page', array(
|
383 |
+
'label' => __("Sales Orders", 'wpsc'),
|
384 |
+
'default' => 20,
|
385 |
+
'option' => 'wpsc_purchases_per_page'
|
386 |
+
) );
|
387 |
+
}
|
388 |
+
|
389 |
/**
|
390 |
* Includes purchase logs CSS and JS
|
391 |
*
|
408 |
'sent_message' => _x( 'Email Sent!', 'sending tracking email for purchase log', 'wpsc' ),
|
409 |
'current_view' => empty( $_REQUEST['status'] ) ? 'all' : $_REQUEST['status'],
|
410 |
'current_filter' => empty( $_REQUEST['m'] ) ? '' : $_REQUEST['m'],
|
411 |
+
'current_page' => empty( $_REQUEST['paged'] ) ? '' : $_REQUEST['paged'],
|
412 |
+
) );
|
413 |
+
|
414 |
+
// Purchase Log Action Links
|
415 |
+
wp_enqueue_script( 'wpsc-purchase-log-action-links', WPSC_URL . '/wpsc-admin/js/purchase-log-action-links.js', array( 'jquery' ), WPSC_VERSION . '.' . WPSC_MINOR_VERSION );
|
416 |
+
wp_localize_script( 'wpsc-purchase-log-action-links', 'WPSC_Purchase_Log_Action_Links', array(
|
417 |
+
'purchase_log_action_link_nonce' => _wpsc_create_ajax_nonce( 'purchase_log_action_link' ),
|
418 |
+
'log_id' => empty( $_REQUEST['id'] ) ? '' : absint( $_REQUEST['id'] )
|
419 |
) );
|
420 |
+
|
421 |
}
|
422 |
|
423 |
/**
|
459 |
* @uses admin_url() Retrieves URL to the WordPress admin
|
460 |
*/
|
461 |
function wpsc_product_log_rss_feed() {
|
462 |
+
echo "<link type='application/rss+xml' href='" . add_query_arg( array( 'rss' => 'true', 'rss_key' => 'key', 'action' => 'purchase_log', 'type' => 'rss' ), admin_url( 'index.php' ) ) . "' title='" . esc_attr__( 'WP eCommerce Purchase Log RSS', 'wpsc' ) . "' rel='alternate' />";
|
463 |
}
|
464 |
|
465 |
/**
|
610 |
}
|
611 |
wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
|
612 |
|
613 |
+
static $_wpsc_admin_l10n_loaded;
|
614 |
+
|
615 |
+
if ( ! $_wpsc_admin_l10n_loaded ) {
|
616 |
+
// Localize scripts
|
617 |
+
wp_localize_script( 'wp-e-commerce-admin', 'wpsc_adminL10n', array(
|
618 |
+
'dragndrop_set' => ( get_option( 'wpsc_sort_by' ) == 'dragndrop' ? 'true' : 'false' ),
|
619 |
+
'save_product_order_nonce' => _wpsc_create_ajax_nonce( 'save_product_order' ),
|
620 |
+
'l10n_print_after' => 'try{convertEntities(wpsc_adminL10n);}catch(e){};',
|
621 |
+
'empty_coupon' => esc_html__( 'Please enter a coupon code.', 'wpsc' ),
|
622 |
+
'bulk_edit_no_vars' => esc_html__( 'Quick Edit options are limited when editing products that have variations. You will need to edit the variations themselves.', 'wpsc' ),
|
623 |
+
'wpsc_core_images_url' => WPSC_CORE_IMAGES_URL,
|
624 |
+
'variation_parent_swap' => esc_html_x( 'New Variation Set', 'Variation taxonomy parent', 'wpsc' ),
|
625 |
+
/* translators : This string is prepended to the 'New Variation Set' string */
|
626 |
+
'variation_helper_text' => esc_html_x( 'Choose the Variation Set you want to add variants to. If you\'re creating a new variation set then select', 'Variation helper text', 'wpsc' ),
|
627 |
+
'variations_tutorial' => esc_html__( 'Variations allow you to create options for your products. For example, if you\'re selling T-Shirts, they will generally have a "Size" option. Size will be the Variation Set name, and it will be a "New Variant Set". You will then create variants (small, medium, large) which will have the "Variation Set" of Size. Once you have made your set you can use the table on the right to manage them (edit, delete). You will be able to order your variants by dragging and dropping them within their Variation Set.', 'wpsc' ),
|
628 |
+
/* translators : These strings are dynamically inserted as a drop-down for the Coupon comparison conditions */
|
629 |
+
'coupons_compare_or' => esc_html_x( 'OR' , 'Coupon comparison logic', 'wpsc' ),
|
630 |
+
'coupons_compare_and' => esc_html_x( 'AND' , 'Coupon comparison logic', 'wpsc' ),
|
631 |
+
'meta_downloads_plural' => __( ' downloads', 'live preview for downloads metabox', 'wpsc' ),
|
632 |
+
'meta_downloads_singular' => __( ' download' , 'live preview for downloads metabox', 'wpsc' ),
|
633 |
+
'wpsc_inline_css_error' => __( 'It is not possible to enable the inline CSS without also enabling the common CSS.' )
|
634 |
+
) );
|
635 |
+
|
636 |
+
$_wpsc_admin_l10n_loaded = true;
|
637 |
+
}
|
638 |
+
|
639 |
}
|
640 |
if ( $pagehook == 'wpsc-product-variations-iframe' ) {
|
641 |
_wpsc_enqueue_wp_e_commerce_admin();
|
856 |
|
857 |
// Add the dashboard widgets
|
858 |
if ( current_user_can( $news_cap ) )
|
859 |
+
wp_add_dashboard_widget( 'wpsc_dashboard_news', __( 'WP eCommerce News' , 'wpsc' ), 'wpsc_dashboard_news' );
|
860 |
if ( current_user_can( $sales_cap ) )
|
861 |
wp_add_dashboard_widget( 'wpsc_dashboard_widget', __( 'Sales Summary', 'wpsc' ), 'wpsc_dashboard_widget' );
|
862 |
if ( current_user_can( $quarterly_sales_cap ) )
|
911 |
* @uses wp_widget_rss_output() Display the RSS entries in a list
|
912 |
*/
|
913 |
function wpsc_dashboard_news() {
|
914 |
+
$rss = fetch_feed( 'https://wpecommerce.org/feed/?category_name=news' );
|
915 |
$args = array( 'show_author' => 1, 'show_date' => 1, 'show_summary' => 1, 'items' => 3 );
|
916 |
wp_widget_rss_output( $rss, $args );
|
917 |
|
926 |
* @return array The array of prices
|
927 |
*/
|
928 |
function wpsc_get_quarterly_summary() {
|
929 |
+
$firstquarter = (int)get_option( 'wpsc_first_quart' );
|
930 |
+
$secondquarter = (int)get_option( 'wpsc_second_quart' );
|
931 |
+
$thirdquarter = (int)get_option( 'wpsc_third_quart' );
|
932 |
+
$fourthquarter = (int)get_option( 'wpsc_fourth_quart' );
|
933 |
+
$finalquarter = (int)get_option( 'wpsc_final_quart' );
|
934 |
|
935 |
$results[] = admin_display_total_price( $thirdquarter + 1, $fourthquarter );
|
936 |
$results[] = admin_display_total_price( $secondquarter + 1, $thirdquarter );
|
1281 |
$message = __( 'Yugoslavia is no longer a valid official country name according to <a href="%1$s">ISO 3166</a> while both Serbia and Montenegro have been added to the country list.<br /> As a result, we highly recommend changing your <em>Base Country</em> to reflect this change on the <a href="%2$s">General Settings</a> page.', 'wpsc' );
|
1282 |
break;
|
1283 |
case 'UK':
|
1284 |
+
$message = __( 'Prior to WP eCommerce 3.8.9, in your database, United Kingdom\'s country code is UK and you have already selected that country code as the base country. However, now that you\'re using WP eCommerce version %3$s, it is recommended that you change your base country to the official "GB" country code, according to <a href="%1$s">ISO 3166</a>.<br /> Please go to <a href="%2$s">General Settings</a> page to make this change.<br />The legacy "UK" item will be marked as "U.K. (legacy)" on the country drop down list. Simply switch to the official "United Kingdom (ISO 3166)" to use the "GB" country code.' , 'wpsc' );
|
1285 |
break;
|
1286 |
case 'AN':
|
1287 |
$message = __( 'Netherlands Antilles is no longer a valid official country name according to <a href="%1$s">ISO 3166</a>.<br />Please consider changing your <em>Base Country</em> to reflect this change on the <a href="%2$s">General Settings</a> page.', 'wpsc' );
|
1288 |
case 'TP':
|
1289 |
+
$message = __( 'Prior to WP eCommerce 3.8.9, in your database, East Timor\'s country code is TP and you have already selected that country code as the base country. However, now that you\'re using WP eCommerce version %3$s, it is recommended that you change your base country to the official "TL" country code, according to <a href="%1$s">ISO 3166</a>.<br /> Please go to <a href="%2$s">General Settings</a> page to make this change.<br />The legacy "TP" item will be marked as "East Timor (legacy)" on the country drop down list. Simply switch to the official "Timor-Leste (ISO 3166)" to use the "TL" country code.' , 'wpsc' );
|
1290 |
break;
|
1291 |
}
|
1292 |
|
1384 |
// Copy the meta information
|
1385 |
wpsc_duplicate_product_meta( $post->ID, $new_post_id );
|
1386 |
|
1387 |
+
do_action( 'wpsc_duplicate_product', $post, $new_post_id );
|
1388 |
+
|
1389 |
// Finds children (Which includes product files AND product images), their meta values, and duplicates them.
|
1390 |
wpsc_duplicate_children( $post->ID, $new_post_id );
|
1391 |
|
1445 |
$sql_query.= implode( ",", $sql_query_sel );
|
1446 |
$sql_query = $wpdb->prepare( $sql_query, $values );
|
1447 |
$wpdb->query( $sql_query );
|
1448 |
+
clean_post_cache( $new_id );
|
1449 |
}
|
1450 |
+
|
1451 |
}
|
1452 |
|
1453 |
/**
|
1461 |
*/
|
1462 |
function wpsc_duplicate_children( $old_parent_id, $new_parent_id ) {
|
1463 |
|
1464 |
+
// Get children products and duplicate them
|
1465 |
$child_posts = get_posts( array(
|
1466 |
'post_parent' => $old_parent_id,
|
1467 |
'post_type' => 'any',
|
1471 |
) );
|
1472 |
|
1473 |
foreach ( $child_posts as $child_post ) {
|
1474 |
+
|
1475 |
+
// Duplicate product images and child posts
|
1476 |
+
if ( 'attachment' == get_post_type( $child_post ) ) {
|
1477 |
+
wpsc_duplicate_product_image_process( $child_post, $new_parent_id );
|
1478 |
+
} else {
|
1479 |
+
wpsc_duplicate_product_process( $child_post, $new_parent_id );
|
1480 |
+
}
|
1481 |
+
|
1482 |
+
do_action( 'wpsc_duplicate_product_child', $child_post, $new_parent_id );
|
1483 |
+
|
1484 |
+
}
|
1485 |
+
|
1486 |
+
}
|
1487 |
+
|
1488 |
+
/**
|
1489 |
+
* Duplicates a product image.
|
1490 |
+
*
|
1491 |
+
* Uses a portion of code from media_sideload_image() in `wp-admin/includes/media.php`
|
1492 |
+
* to check file before downloading from URL.
|
1493 |
+
*
|
1494 |
+
* @since 3.9.0
|
1495 |
+
*
|
1496 |
+
* @uses get_post_type() Gets post type.
|
1497 |
+
* @uses wp_get_attachment_url() Gets attachment URL.
|
1498 |
+
* @uses download_url() Download file from URl to temp location.
|
1499 |
+
* @uses is_wp_error() Is WP error?
|
1500 |
+
* @uses media_handle_sideload() Handle creation of new attachment and attach to post.
|
1501 |
+
*
|
1502 |
+
* @param object $post The post object.
|
1503 |
+
* @param bool $new_parent_id Optional. The parent post id.
|
1504 |
+
* @return int Attachment ID.
|
1505 |
+
*/
|
1506 |
+
function wpsc_duplicate_product_image_process( $child_post, $new_parent_id ) {
|
1507 |
+
|
1508 |
+
if ( 'attachment' == get_post_type( $child_post ) && apply_filters( 'wpsc_duplicate_product_attachment', true, $child_post ) ) {
|
1509 |
+
|
1510 |
+
$file = wp_get_attachment_url( $child_post->ID );
|
1511 |
+
|
1512 |
+
if ( ! empty( $file ) ) {
|
1513 |
+
|
1514 |
+
// Set variables for storage, fix file filename for query strings.
|
1515 |
+
preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
|
1516 |
+
$file_array = array();
|
1517 |
+
$file_array['name'] = basename( $matches[0] );
|
1518 |
+
|
1519 |
+
// Download file to temp location.
|
1520 |
+
$file_array['tmp_name'] = download_url( $file );
|
1521 |
+
|
1522 |
+
// If error storing temporarily, return the error.
|
1523 |
+
if ( is_wp_error( $file_array['tmp_name'] ) ) {
|
1524 |
+
return $file_array['tmp_name'];
|
1525 |
+
}
|
1526 |
+
|
1527 |
+
// Do the validation and storage stuff.
|
1528 |
+
$id = media_handle_sideload( $file_array, $new_parent_id );
|
1529 |
+
|
1530 |
+
// If error storing permanently, unlink.
|
1531 |
+
if ( is_wp_error( $id ) ) {
|
1532 |
+
@unlink( $file_array['tmp_name'] );
|
1533 |
+
}
|
1534 |
+
|
1535 |
+
// Re-attribute featured image
|
1536 |
+
if ( has_post_thumbnail( $new_parent_id ) && $child_post->ID == get_post_thumbnail_id( $new_parent_id ) ) {
|
1537 |
+
set_post_thumbnail( $new_parent_id, $id );
|
1538 |
+
}
|
1539 |
+
|
1540 |
+
// Copy attachment data
|
1541 |
+
$post_data = array(
|
1542 |
+
'ID' => $id,
|
1543 |
+
'post_content' => $child_post->post_content,
|
1544 |
+
'post_title' => $child_post->post_title,
|
1545 |
+
'post_excerpt' => $child_post->post_excerpt,
|
1546 |
+
'post_status' => $child_post->post_status,
|
1547 |
+
'comment_status' => $child_post->comment_status,
|
1548 |
+
'ping_status' => $child_post->ping_status,
|
1549 |
+
'post_password' => $child_post->post_password,
|
1550 |
+
'post_content_filtered' => $child_post->post_content_filtered,
|
1551 |
+
'menu_order' => $child_post->menu_order
|
1552 |
+
);
|
1553 |
+
|
1554 |
+
wp_update_post( $post_data );
|
1555 |
+
|
1556 |
+
// Copy alt text
|
1557 |
+
update_post_meta( $id, '_wp_attachment_image_alt', get_post_meta( $child_post->ID, '_wp_attachment_image_alt', true ) );
|
1558 |
+
|
1559 |
+
return $id;
|
1560 |
+
|
1561 |
+
}
|
1562 |
+
|
1563 |
}
|
1564 |
|
1565 |
}
|
1573 |
* @uses get_option() Gets option from the database given string
|
1574 |
*/
|
1575 |
function _wpsc_admin_notices_3dot8dot9() {
|
1576 |
+
$message = '<p>' . __( 'You are currently using WP eCommerce 3.8.9. There have been major changes in WP eCommerce 3.8.9, so backward-compatibility with existing plugins might not always be guaranteed. If you are unsure, please roll back to 3.8.8.5, and set up a test site with 3.8.9 to make sure WP eCommerce 3.8.9 is compatible with your existing themes and plugins.<br />If you find any incompatibility issues, please <a href="%1$s">report them to us</a> as well as the other plugins or themes\' developers.' , 'wpsc' ) . '</p>';
|
1577 |
$message .= "\n<p>" . __( '<a href="%2$s">Hide this warning</a>', 'wpsc' ) . '</p>';
|
1578 |
$message = sprintf(
|
1579 |
$message,
|
1580 |
+
'https://wpecommerce.org/wp-e-commerce-3-8-9-compatibility-issues/',
|
1581 |
add_query_arg( 'dismiss_389_upgrade_notice', 1 )
|
1582 |
);
|
1583 |
|
1651 |
$message,
|
1652 |
WPSC_VERSION,
|
1653 |
'https://github.com/wp-e-commerce/WP-e-Commerce/issues/359',
|
1654 |
+
'http://docs.wpecommerce.org/documentation/3-8-11-user-logs',
|
1655 |
add_query_arg( 'dismiss_3811_upgrade_notice', 1 )
|
1656 |
);
|
1657 |
|
1687 |
}
|
1688 |
|
1689 |
/**
|
1690 |
+
* Adds links to premium support and documentation on WPeCommerce.org
|
1691 |
+
*
|
1692 |
+
* @since 3.9.0
|
1693 |
*
|
1694 |
+
* @param array $links Original links
|
1695 |
+
* @return array $links Updated links
|
1696 |
*/
|
1697 |
+
function wpsc_support_links( $links ) {
|
1698 |
+
$links[] = sprintf( '<a href="%s">%s</a>', _x( 'https://wpecommerce.org/premium-support/', 'Premium Support URL', 'wpsc' ), __( 'Premium Support', 'wpsc' ) );
|
1699 |
+
$links[] = sprintf( '<a href="%s">%s</a>', _x( 'http://docs.wpecommerce.org/', 'Documentation URL', 'wpsc' ), __( 'Documentation', 'wpsc' ) );
|
1700 |
+
|
1701 |
+
return $links;
|
1702 |
+
}
|
1703 |
+
|
1704 |
+
add_filter( 'plugin_action_links_' . WPSC_PLUGIN_BASENAME, 'wpsc_support_links' );
|
wpsc-admin/ajax-and-init.php
CHANGED
@@ -202,8 +202,6 @@ function wpsc_clean_categories() {
|
|
202 |
'%d'
|
203 |
);
|
204 |
|
205 |
-
$updated;
|
206 |
-
|
207 |
} else if ( $datarow['active'] == 0 ) {
|
208 |
$wpdb->update(
|
209 |
WPSC_TABLE_PRODUCT_CATEGORIES,
|
@@ -216,7 +214,6 @@ function wpsc_clean_categories() {
|
|
216 |
'%s',
|
217 |
'%d'
|
218 |
);
|
219 |
-
$updated;
|
220 |
}
|
221 |
}
|
222 |
$wp_rewrite->flush_rules();
|
202 |
'%d'
|
203 |
);
|
204 |
|
|
|
|
|
205 |
} else if ( $datarow['active'] == 0 ) {
|
206 |
$wpdb->update(
|
207 |
WPSC_TABLE_PRODUCT_CATEGORIES,
|
214 |
'%s',
|
215 |
'%d'
|
216 |
);
|
|
|
217 |
}
|
218 |
}
|
219 |
$wp_rewrite->flush_rules();
|
wpsc-admin/ajax.php
CHANGED
@@ -411,6 +411,88 @@ function _wpsc_ajax_purchase_log_send_tracking_email() {
|
|
411 |
return $return;
|
412 |
}
|
413 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
/**
|
415 |
* Delete an attached downloadable file via AJAX.
|
416 |
*
|
411 |
return $return;
|
412 |
}
|
413 |
|
414 |
+
/**
|
415 |
+
* Do purchase log action link via AJAX
|
416 |
+
*
|
417 |
+
* @since 3.9.0
|
418 |
+
* @access private
|
419 |
+
*
|
420 |
+
* @return array|WP_Error $return Response args if successful, WP_Error if otherwise
|
421 |
+
*/
|
422 |
+
function _wpsc_ajax_purchase_log_action_link() {
|
423 |
+
|
424 |
+
if ( isset( $_POST['log_id'] ) && isset( $_POST['purchase_log_action_link'] ) && isset( $_POST['purchase_log_action_nonce'] ) ) {
|
425 |
+
|
426 |
+
$log_id = absint( $_POST['log_id'] );
|
427 |
+
$purchase_log_action_link = sanitize_key( $_POST['purchase_log_action_link'] );
|
428 |
+
|
429 |
+
// Verify action nonce
|
430 |
+
if ( wp_verify_nonce( $_POST['purchase_log_action_nonce'], 'wpsc_purchase_log_action_ajax_' . $purchase_log_action_link ) ) {
|
431 |
+
|
432 |
+
// Expected to receive success = true by default, or false on error.
|
433 |
+
$return = apply_filters( 'wpsc_purchase_log_action_ajax-' . $purchase_log_action_link, array( 'success' => null ), $log_id );
|
434 |
+
|
435 |
+
} else {
|
436 |
+
$return = _wpsc_error_invalid_nonce();
|
437 |
+
}
|
438 |
+
|
439 |
+
if ( ! is_wp_error( $return ) ) {
|
440 |
+
$return['log_id'] = $log_id;
|
441 |
+
$return['purchase_log_action_link'] = $purchase_log_action_link;
|
442 |
+
$return['success'] = isset( $return['success'] ) ? (bool) $return['success'] : null;
|
443 |
+
}
|
444 |
+
|
445 |
+
return $return;
|
446 |
+
|
447 |
+
}
|
448 |
+
|
449 |
+
return new WP_Error( 'wpsc_ajax_invalid_purchase_log_action', __( 'Purchase log action failed.', 'wpsc' ) );
|
450 |
+
|
451 |
+
}
|
452 |
+
|
453 |
+
/**
|
454 |
+
* Handle AJAX clear downloads lock purchase log action
|
455 |
+
*
|
456 |
+
* The _wpsc_ajax_purchase_log_action_link() function which triggers this function is nonce
|
457 |
+
* and capability checked in _wpsc_ajax_handler().
|
458 |
+
*
|
459 |
+
* @since 3.9.0
|
460 |
+
* @access private
|
461 |
+
*
|
462 |
+
* @param array $response AJAX response.
|
463 |
+
* @param int $log_id Purchase log ID.
|
464 |
+
*/
|
465 |
+
function wpsc_purchase_log_action_ajax_downloads_lock( $response, $log_id ) {
|
466 |
+
|
467 |
+
$response['success'] = wpsc_purchlog_clear_download_items( $log_id );
|
468 |
+
|
469 |
+
return $response;
|
470 |
+
|
471 |
+
}
|
472 |
+
add_action( 'wpsc_purchase_log_action_ajax-downloads_lock', 'wpsc_purchase_log_action_ajax_downloads_lock', 10, 2 );
|
473 |
+
|
474 |
+
|
475 |
+
/**
|
476 |
+
* Handle AJAX email receipt purchase log action
|
477 |
+
*
|
478 |
+
* The _wpsc_ajax_purchase_log_action_link() function which triggers this function is nonce
|
479 |
+
* and capability checked in _wpsc_ajax_handler().
|
480 |
+
*
|
481 |
+
* @since 3.9.0
|
482 |
+
* @access private
|
483 |
+
*
|
484 |
+
* @param array $response AJAX response.
|
485 |
+
* @param int $log_id Purchase log ID.
|
486 |
+
*/
|
487 |
+
function wpsc_purchase_log_action_ajax_email_receipt( $response, $log_id ) {
|
488 |
+
|
489 |
+
$response['success'] = wpsc_purchlog_resend_email( $log_id );
|
490 |
+
|
491 |
+
return $response;
|
492 |
+
|
493 |
+
}
|
494 |
+
add_action( 'wpsc_purchase_log_action_ajax-email_receipt', 'wpsc_purchase_log_action_ajax_email_receipt', 10, 2 );
|
495 |
+
|
496 |
/**
|
497 |
* Delete an attached downloadable file via AJAX.
|
498 |
*
|
wpsc-admin/css/admin.css
CHANGED
@@ -230,6 +230,8 @@ th#status {
|
|
230 |
margin-top: -.2em;
|
231 |
}
|
232 |
|
|
|
|
|
233 |
#wpsc_purchlogitems_links a {
|
234 |
text-decoration: none;
|
235 |
line-height: 14pt;
|
@@ -240,6 +242,57 @@ th#status {
|
|
240 |
float: left;
|
241 |
}
|
242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
#wpsc_shipping_details_box {
|
244 |
width: 45%;
|
245 |
float: left;
|
@@ -2137,11 +2190,11 @@ table.purchase-logs tr:hover .column-id .delete {
|
|
2137 |
|
2138 |
.wpsc-button-round {
|
2139 |
padding: 0 0 1px !important;
|
2140 |
-
height:
|
2141 |
text-align: center;
|
2142 |
-
width:
|
2143 |
-
-webkit-border-radius:
|
2144 |
-
border-radius:
|
2145 |
outline: 0 !important;
|
2146 |
}
|
2147 |
|
@@ -2257,9 +2310,9 @@ body.edit-tags-php img.wpsc_category_image {
|
|
2257 |
#wpsc_product_gallery li {
|
2258 |
float: left;
|
2259 |
margin-right: 10px;
|
|
|
2260 |
}
|
2261 |
|
2262 |
-
|
2263 |
/**
|
2264 |
* Digital download table style
|
2265 |
*/
|
@@ -2364,7 +2417,7 @@ a.wpsc_remove_meta {
|
|
2364 |
.wpsc-product-variation-iframe.wp-core-ui .button.button-large,
|
2365 |
.wpsc-product-variation-iframe.wp-core-ui .button.button-small {
|
2366 |
padding: 0px 10px 1px;
|
2367 |
-
line-height:
|
2368 |
font-size: 13px;
|
2369 |
vertical-align: top;
|
2370 |
height: 28px;
|
230 |
margin-top: -.2em;
|
231 |
}
|
232 |
|
233 |
+
/* Purchase Log Action Links */
|
234 |
+
|
235 |
#wpsc_purchlogitems_links a {
|
236 |
text-decoration: none;
|
237 |
line-height: 14pt;
|
242 |
float: left;
|
243 |
}
|
244 |
|
245 |
+
#wpsc_purchlogitems_links li .dashicons {
|
246 |
+
margin-right: 10px;
|
247 |
+
}
|
248 |
+
|
249 |
+
#wpsc_purchlogitems_links li a {
|
250 |
+
position: relative;
|
251 |
+
}
|
252 |
+
|
253 |
+
#wpsc_purchlogitems_links li a .spinner {
|
254 |
+
display: none;
|
255 |
+
float: none;
|
256 |
+
margin: 0px;
|
257 |
+
position: absolute;
|
258 |
+
top: 0px;
|
259 |
+
left: 0px;
|
260 |
+
}
|
261 |
+
|
262 |
+
#wpsc_purchlogitems_links li a .dashicons {
|
263 |
+
color: #888;
|
264 |
+
}
|
265 |
+
|
266 |
+
#wpsc_purchlogitems_links li a .dashicons-yes {
|
267 |
+
color: #7ad03a;
|
268 |
+
}
|
269 |
+
|
270 |
+
#wpsc_purchlogitems_links li a.wpsc-purchlog-action-link-delete .dashicons,
|
271 |
+
#wpsc_purchlogitems_links li a.wpsc-purchlog-action-link-back .dashicons {
|
272 |
+
color: #bbb;
|
273 |
+
}
|
274 |
+
|
275 |
+
#wpsc_purchlogitems_links li a.wpsc-purchlog-action-link-delete:hover .dashicons,
|
276 |
+
#wpsc_purchlogitems_links li a .dashicons-no {
|
277 |
+
color: #c00;
|
278 |
+
}
|
279 |
+
|
280 |
+
#wpsc_purchlogitems_links li a.wpsc-purchlog-action-link-back:hover .dashicons {
|
281 |
+
color: #888;
|
282 |
+
}
|
283 |
+
|
284 |
+
#wpsc_purchlogitems_links li a.doing {
|
285 |
+
padding-left: 30px;
|
286 |
+
}
|
287 |
+
|
288 |
+
#wpsc_purchlogitems_links li a.doing .spinner {
|
289 |
+
display: block;
|
290 |
+
}
|
291 |
+
|
292 |
+
#wpsc_purchlogitems_links li a.doing .dashicons {
|
293 |
+
display: none;
|
294 |
+
}
|
295 |
+
|
296 |
#wpsc_shipping_details_box {
|
297 |
width: 45%;
|
298 |
float: left;
|
2190 |
|
2191 |
.wpsc-button-round {
|
2192 |
padding: 0 0 1px !important;
|
2193 |
+
height: 28px !important;
|
2194 |
text-align: center;
|
2195 |
+
width: 28px !important;
|
2196 |
+
-webkit-border-radius: 14px !important;
|
2197 |
+
border-radius: 14px !important;
|
2198 |
outline: 0 !important;
|
2199 |
}
|
2200 |
|
2310 |
#wpsc_product_gallery li {
|
2311 |
float: left;
|
2312 |
margin-right: 10px;
|
2313 |
+
cursor: move;
|
2314 |
}
|
2315 |
|
|
|
2316 |
/**
|
2317 |
* Digital download table style
|
2318 |
*/
|
2417 |
.wpsc-product-variation-iframe.wp-core-ui .button.button-large,
|
2418 |
.wpsc-product-variation-iframe.wp-core-ui .button.button-small {
|
2419 |
padding: 0px 10px 1px;
|
2420 |
+
line-height: 2;
|
2421 |
font-size: 13px;
|
2422 |
vertical-align: top;
|
2423 |
height: 28px;
|
wpsc-admin/css/settingspage.css
CHANGED
@@ -133,6 +133,9 @@ table.wpsc-edit-module-options tr td {
|
|
133 |
border: none;
|
134 |
overflow: initial;
|
135 |
}
|
|
|
|
|
|
|
136 |
.widefat .shipping-module-settings-form th {
|
137 |
font-family: inherit;
|
138 |
font-size: 12px;
|
133 |
border: none;
|
134 |
overflow: initial;
|
135 |
}
|
136 |
+
.widefat .shipping-module-settings-form td input {
|
137 |
+
margin-top: -5px;
|
138 |
+
}
|
139 |
.widefat .shipping-module-settings-form th {
|
140 |
font-family: inherit;
|
141 |
font-size: 12px;
|
wpsc-admin/db-upgrades/routines/10.php
CHANGED
@@ -63,7 +63,6 @@ function _wpsc_meta_migrate_anonymous_users() {
|
|
63 |
|
64 |
wp_suspend_cache_addition( true );
|
65 |
|
66 |
-
|
67 |
$role = get_role( 'wpsc_anonymous' );
|
68 |
|
69 |
if ( $role ) {
|
63 |
|
64 |
wp_suspend_cache_addition( true );
|
65 |
|
|
|
66 |
$role = get_role( 'wpsc_anonymous' );
|
67 |
|
68 |
if ( $role ) {
|
wpsc-admin/db-upgrades/routines/11.php
CHANGED
@@ -19,6 +19,8 @@ function _wpsc_db_upgrade_11() {
|
|
19 |
*/
|
20 |
function _wpsc_fix_united_kingdom() {
|
21 |
|
|
|
|
|
22 |
if ( $wpsc_country = WPSC_Countries::get_country( 'UK' ) ) {
|
23 |
|
24 |
$legacy_ok_country_was_visible = $wpsc_country->is_visible();
|
@@ -60,7 +62,6 @@ function _wpsc_fix_united_kingdom() {
|
|
60 |
|
61 |
}
|
62 |
|
63 |
-
|
64 |
/**
|
65 |
* Sets meta for countries that no longer exist in their former notation to be considered legacy.
|
66 |
*
|
19 |
*/
|
20 |
function _wpsc_fix_united_kingdom() {
|
21 |
|
22 |
+
$legacy_ok_country_was_visible = true;
|
23 |
+
|
24 |
if ( $wpsc_country = WPSC_Countries::get_country( 'UK' ) ) {
|
25 |
|
26 |
$legacy_ok_country_was_visible = $wpsc_country->is_visible();
|
62 |
|
63 |
}
|
64 |
|
|
|
65 |
/**
|
66 |
* Sets meta for countries that no longer exist in their former notation to be considered legacy.
|
67 |
*
|
wpsc-admin/db-upgrades/routines/12.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Control database upgrade to version
|
4 |
*
|
5 |
* @access private
|
6 |
* @since 3.8.14
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Control database upgrade to version 12
|
4 |
*
|
5 |
* @access private
|
6 |
* @since 3.8.14
|
wpsc-admin/db-upgrades/routines/13.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Control database upgrade to version
|
4 |
*
|
5 |
* @access private
|
6 |
* @since 3.8.14
|
@@ -12,7 +12,7 @@ function _wpsc_db_upgrade_13() {
|
|
12 |
}
|
13 |
|
14 |
/**
|
15 |
-
*
|
16 |
*
|
17 |
* @access private
|
18 |
* @since 3.8.14.1
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Control database upgrade to version 13
|
4 |
*
|
5 |
* @access private
|
6 |
* @since 3.8.14
|
12 |
}
|
13 |
|
14 |
/**
|
15 |
+
* Add the county region label to the uk
|
16 |
*
|
17 |
* @access private
|
18 |
* @since 3.8.14.1
|
wpsc-admin/db-upgrades/routines/14.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Control database upgrade to version 14
|
4 |
+
*
|
5 |
+
* @access private
|
6 |
+
* @since 3.9.0
|
7 |
+
*
|
8 |
+
*/
|
9 |
+
function _wpsc_db_upgrade_14() {
|
10 |
+
_wpsc_fix_latvia_currency();
|
11 |
+
}
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Change Latvian currency to Euro.
|
15 |
+
*
|
16 |
+
* @access private
|
17 |
+
* @since 3.9.0
|
18 |
+
*/
|
19 |
+
function _wpsc_fix_latvia_currency() {
|
20 |
+
$country = new WPSC_Country( array(
|
21 |
+
'isocode' => 'LV',
|
22 |
+
'currency' => __( 'Euro', 'wpsc' ),
|
23 |
+
'symbol' => __( '€', 'wpsc' ),
|
24 |
+
'symbol_html' => __( '€', 'wpsc' ),
|
25 |
+
'code' => __( 'EUR', 'wpsc' )
|
26 |
+
) );
|
27 |
+
|
28 |
+
}
|
wpsc-admin/db-upgrades/upgrade.php
CHANGED
@@ -40,12 +40,12 @@ function _wpsc_maybe_upgrade() {
|
|
40 |
}
|
41 |
|
42 |
function _wpsc_upgrade_display_backup_warning() {
|
43 |
-
$message = __( '<strong>Important:</strong> Before proceeding with the database upgrade, <a href="%1$s">please backup your database and files</a>.<br>We recommend using <a href="%2$s">VaultPress</a> or <a href="%3$s">
|
44 |
$message = sprintf(
|
45 |
$message,
|
46 |
'http://codex.wordpress.org/WordPress_Backups',
|
47 |
'http://vaultpress.com/',
|
48 |
-
'http://ithemes.com/
|
49 |
);
|
50 |
?>
|
51 |
<div id="wpsc-upgrade-warning" class="updated">
|
@@ -55,7 +55,7 @@ function _wpsc_upgrade_display_backup_warning() {
|
|
55 |
}
|
56 |
|
57 |
function _wpsc_upgrade_display_prompt() {
|
58 |
-
$message = __( '<strong>WP
|
59 |
$message = sprintf( $message, WPSC_VERSION, admin_url( '?page=wpsc-db-upgrade' ) );
|
60 |
?>
|
61 |
<div id="wpsc-upgrade-warning" class="error">
|
@@ -65,7 +65,7 @@ function _wpsc_upgrade_display_prompt() {
|
|
65 |
}
|
66 |
|
67 |
function _wpsc_upgrade_display_successful() {
|
68 |
-
$message = __( 'WP
|
69 |
$message = sprintf( $message, WPSC_VERSION );
|
70 |
?>
|
71 |
<div id="wpsc-upgrade-warning" class="updated">
|
@@ -75,12 +75,13 @@ function _wpsc_upgrade_display_successful() {
|
|
75 |
}
|
76 |
|
77 |
function _wpsc_action_admin_notices_db_upgrade() {
|
78 |
-
if ( ! empty( $_GET['wpsc_db_upgrade_successful'] ) )
|
79 |
_wpsc_upgrade_display_successful();
|
80 |
-
elseif ( _wpsc_is_db_upgrade_page() )
|
81 |
_wpsc_upgrade_display_backup_warning();
|
82 |
-
elseif ( _wpsc_needs_upgrade() )
|
83 |
_wpsc_upgrade_display_prompt();
|
|
|
84 |
}
|
85 |
add_action( 'admin_notices', '_wpsc_action_admin_notices_db_upgrade' );
|
86 |
|
@@ -149,6 +150,6 @@ function _wpsc_action_load_db_upgrade() {
|
|
149 |
}
|
150 |
|
151 |
function _wpsc_callback_display_db_upgrade_page() {
|
152 |
-
$update_title = sprintf( __( 'Your database needs to be upgraded before you can use WP
|
153 |
include( 'views/main.php' );
|
154 |
-
}
|
40 |
}
|
41 |
|
42 |
function _wpsc_upgrade_display_backup_warning() {
|
43 |
+
$message = __( '<strong>Important:</strong> Before proceeding with the database upgrade, <a href="%1$s">please backup your database and files</a>.<br>We recommend using <a href="%2$s">VaultPress</a> or <a href="%3$s">BackupBuddy</a> to regularly backup your WordPress installation.', 'wpsc' );
|
44 |
$message = sprintf(
|
45 |
$message,
|
46 |
'http://codex.wordpress.org/WordPress_Backups',
|
47 |
'http://vaultpress.com/',
|
48 |
+
'http://ithemes.com/member/go.php?r=45982&i=l44'
|
49 |
);
|
50 |
?>
|
51 |
<div id="wpsc-upgrade-warning" class="updated">
|
55 |
}
|
56 |
|
57 |
function _wpsc_upgrade_display_prompt() {
|
58 |
+
$message = __( '<strong>WP eCommerce %1$s is almost ready.</strong> Some database routines need to be run before the upgrade is complete. <a href="%2$s">Click here to start!</a>');
|
59 |
$message = sprintf( $message, WPSC_VERSION, admin_url( '?page=wpsc-db-upgrade' ) );
|
60 |
?>
|
61 |
<div id="wpsc-upgrade-warning" class="error">
|
65 |
}
|
66 |
|
67 |
function _wpsc_upgrade_display_successful() {
|
68 |
+
$message = __( 'WP eCommerce has been successfully updated to %s. Enjoy!', 'wpsc' );
|
69 |
$message = sprintf( $message, WPSC_VERSION );
|
70 |
?>
|
71 |
<div id="wpsc-upgrade-warning" class="updated">
|
75 |
}
|
76 |
|
77 |
function _wpsc_action_admin_notices_db_upgrade() {
|
78 |
+
if ( ! empty( $_GET['wpsc_db_upgrade_successful'] ) ) {
|
79 |
_wpsc_upgrade_display_successful();
|
80 |
+
} elseif ( _wpsc_is_db_upgrade_page() ) {
|
81 |
_wpsc_upgrade_display_backup_warning();
|
82 |
+
} elseif ( _wpsc_needs_upgrade() ) {
|
83 |
_wpsc_upgrade_display_prompt();
|
84 |
+
}
|
85 |
}
|
86 |
add_action( 'admin_notices', '_wpsc_action_admin_notices_db_upgrade' );
|
87 |
|
150 |
}
|
151 |
|
152 |
function _wpsc_callback_display_db_upgrade_page() {
|
153 |
+
$update_title = sprintf( __( 'Your database needs to be upgraded before you can use WP eCommerce %s', 'wpsc' ), WPSC_VERSION );
|
154 |
include( 'views/main.php' );
|
155 |
+
}
|
wpsc-admin/db-upgrades/views/main.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<div class="wrap">
|
2 |
<div id="icon-tools" class="icon32"><br></div>
|
3 |
-
<h2><?php esc_html_e( 'WP
|
4 |
<form class="wpsc-db-upgrade" action="" method="post">
|
5 |
<h3><?php echo esc_html( $update_title ); ?></h3>
|
6 |
<p><?php esc_html_e( 'Click "Start Database Upgrade" when you are ready.', 'wpsc' ); ?></p>
|
1 |
<div class="wrap">
|
2 |
<div id="icon-tools" class="icon32"><br></div>
|
3 |
+
<h2><?php esc_html_e( 'WP eCommerce Database Upgrade', 'wpsc' ); ?></h2>
|
4 |
<form class="wpsc-db-upgrade" action="" method="post">
|
5 |
<h3><?php echo esc_html( $update_title ); ?></h3>
|
6 |
<p><?php esc_html_e( 'Click "Start Database Upgrade" when you are ready.', 'wpsc' ); ?></p>
|
wpsc-admin/display-coupon-add.php
CHANGED
@@ -50,6 +50,7 @@
|
|
50 |
<input name="add_start" id="add_start" type="text" class="regular-text pickdate" style="width: 100px"/>
|
51 |
<span class="description"><?php _e( 'End: ', 'wpsc' ); ?></span>
|
52 |
<input name="add_end" id="add_end" type="text" class="regular-text pickdate" style="width: 100px"/>
|
|
|
53 |
</td>
|
54 |
</tr>
|
55 |
|
@@ -124,7 +125,7 @@
|
|
124 |
|
125 |
</tbody>
|
126 |
</table>
|
127 |
-
|
128 |
<?php submit_button( __( 'Add Coupon', 'wpsc' ), 'primary', 'add_coupon' ); ?>
|
129 |
|
130 |
</form>
|
50 |
<input name="add_start" id="add_start" type="text" class="regular-text pickdate" style="width: 100px"/>
|
51 |
<span class="description"><?php _e( 'End: ', 'wpsc' ); ?></span>
|
52 |
<input name="add_end" id="add_end" type="text" class="regular-text pickdate" style="width: 100px"/>
|
53 |
+
<p class="description"><?php _e( 'If date fields are left empty, there will be no expiration on this coupon.', 'wpsc' ); ?></p>
|
54 |
</td>
|
55 |
</tr>
|
56 |
|
125 |
|
126 |
</tbody>
|
127 |
</table>
|
128 |
+
<?php wp_nonce_field( 'wpsc_coupon', 'wpsc-coupon-add' ); ?>
|
129 |
<?php submit_button( __( 'Add Coupon', 'wpsc' ), 'primary', 'add_coupon' ); ?>
|
130 |
|
131 |
</form>
|
wpsc-admin/display-coupon-edit.php
CHANGED
@@ -67,13 +67,14 @@ $coupon = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_COUP
|
|
67 |
</th>
|
68 |
<td>
|
69 |
<?php
|
70 |
-
|
71 |
-
|
72 |
?>
|
73 |
<span class="description"><?php _e( 'Start: ', 'wpsc' ); ?></span>
|
74 |
<input name="edit_coupon_start" id="edit_coupon_start" type="text" value="<?php esc_attr_e( $start ); ?>" class="regular-text pickdate" style="width: 100px"/>
|
75 |
<span class="description"><?php _e( 'End: ', 'wpsc' ); ?></span>
|
76 |
<input name="edit_coupon_end" id="edit_coupon_end" type="text" value="<?php esc_attr_e( $end ); ?>" class="regular-text pickdate" style="width: 100px"/>
|
|
|
77 |
</td>
|
78 |
</tr>
|
79 |
|
@@ -171,7 +172,9 @@ $coupon = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_COUP
|
|
171 |
</table>
|
172 |
<input type="hidden" name="coupon_id" value="<?php echo esc_attr( $coupon_id ); ?>"/>
|
173 |
<input type="hidden" name="edit_coupon_is_used" value="<?php echo esc_attr( $coupon['is-used'] ); ?>"/>
|
174 |
-
<input type="hidden" name="is_edit_coupon" value="true"/>
|
|
|
|
|
175 |
<?php submit_button( __( 'Update Coupon', 'wpsc' ), 'primary' ); ?>
|
176 |
|
177 |
</form>
|
67 |
</th>
|
68 |
<td>
|
69 |
<?php
|
70 |
+
$start = $coupon['start'] == '0000-00-00 00:00:00' ? '' : get_date_from_gmt( $coupon['start'], 'Y-m-d' );
|
71 |
+
$end = $coupon['expiry'] == '0000-00-00 00:00:00' ? '' : get_date_from_gmt( $coupon['expiry'], 'Y-m-d' );
|
72 |
?>
|
73 |
<span class="description"><?php _e( 'Start: ', 'wpsc' ); ?></span>
|
74 |
<input name="edit_coupon_start" id="edit_coupon_start" type="text" value="<?php esc_attr_e( $start ); ?>" class="regular-text pickdate" style="width: 100px"/>
|
75 |
<span class="description"><?php _e( 'End: ', 'wpsc' ); ?></span>
|
76 |
<input name="edit_coupon_end" id="edit_coupon_end" type="text" value="<?php esc_attr_e( $end ); ?>" class="regular-text pickdate" style="width: 100px"/>
|
77 |
+
<p class="description"><?php _e( 'If date fields are left empty, there will be no expiration on this coupon.', 'wpsc' ); ?></p>
|
78 |
</td>
|
79 |
</tr>
|
80 |
|
172 |
</table>
|
173 |
<input type="hidden" name="coupon_id" value="<?php echo esc_attr( $coupon_id ); ?>"/>
|
174 |
<input type="hidden" name="edit_coupon_is_used" value="<?php echo esc_attr( $coupon['is-used'] ); ?>"/>
|
175 |
+
<input type="hidden" name="is_edit_coupon" value="true" />
|
176 |
+
|
177 |
+
<?php wp_nonce_field( 'wpsc_coupon', 'wpsc-coupon-edit' ); ?>
|
178 |
<?php submit_button( __( 'Update Coupon', 'wpsc' ), 'primary' ); ?>
|
179 |
|
180 |
</form>
|
wpsc-admin/display-coupons.php
CHANGED
@@ -8,10 +8,12 @@ function wpsc_display_coupons_page() {
|
|
8 |
* Update / create code that will be abstracted to its own class at some point
|
9 |
*/
|
10 |
|
11 |
-
if ( isset( $_POST ) && is_array( $_POST ) && !empty( $_POST ) ) {
|
12 |
|
13 |
if ( isset( $_POST['add_coupon'] ) && (!isset( $_POST['is_edit_coupon'] ) || !($_POST['is_edit_coupon'] == 'true')) ) {
|
14 |
|
|
|
|
|
15 |
$coupon_code = $_POST['add_coupon_code'];
|
16 |
$discount = (double)$_POST['add_discount'];
|
17 |
$discount_type = (int)$_POST['add_discount_type'];
|
@@ -69,6 +71,8 @@ function wpsc_display_coupons_page() {
|
|
69 |
// update an existing coupon
|
70 |
if ( isset( $_POST['is_edit_coupon'] ) && ($_POST['is_edit_coupon'] == 'true') && !(isset( $_POST['delete_condition'] )) && !(isset( $_POST['submit_condition'] )) ) {
|
71 |
|
|
|
|
|
72 |
$rules = isset( $_POST['rules'] ) ? $_POST['rules'] : array();
|
73 |
$new_rules = array();
|
74 |
|
@@ -113,8 +117,9 @@ function wpsc_display_coupons_page() {
|
|
113 |
array( '%d' )
|
114 |
);
|
115 |
|
116 |
-
if ( $update )
|
117 |
-
|
|
|
118 |
}
|
119 |
}
|
120 |
|
8 |
* Update / create code that will be abstracted to its own class at some point
|
9 |
*/
|
10 |
|
11 |
+
if ( isset( $_POST ) && is_array( $_POST ) && ! empty( $_POST ) ) {
|
12 |
|
13 |
if ( isset( $_POST['add_coupon'] ) && (!isset( $_POST['is_edit_coupon'] ) || !($_POST['is_edit_coupon'] == 'true')) ) {
|
14 |
|
15 |
+
check_admin_referer( 'wpsc_coupon', 'wpsc-coupon-add' );
|
16 |
+
|
17 |
$coupon_code = $_POST['add_coupon_code'];
|
18 |
$discount = (double)$_POST['add_discount'];
|
19 |
$discount_type = (int)$_POST['add_discount_type'];
|
71 |
// update an existing coupon
|
72 |
if ( isset( $_POST['is_edit_coupon'] ) && ($_POST['is_edit_coupon'] == 'true') && !(isset( $_POST['delete_condition'] )) && !(isset( $_POST['submit_condition'] )) ) {
|
73 |
|
74 |
+
check_admin_referer( 'wpsc_coupon', 'wpsc-coupon-edit' );
|
75 |
+
|
76 |
$rules = isset( $_POST['rules'] ) ? $_POST['rules'] : array();
|
77 |
$new_rules = array();
|
78 |
|
117 |
array( '%d' )
|
118 |
);
|
119 |
|
120 |
+
if ( $update ) {
|
121 |
+
echo "<div class='updated'><p>" . __( 'The coupon has been updated.', 'wpsc' ) . "</p></div>";
|
122 |
+
}
|
123 |
}
|
124 |
}
|
125 |
|
wpsc-admin/display-items.page.php
CHANGED
@@ -11,7 +11,6 @@
|
|
11 |
|
12 |
require_once(WPSC_FILE_PATH . '/wpsc-admin/includes/products.php');
|
13 |
|
14 |
-
|
15 |
/**
|
16 |
* wpsc_additional_column_names function.
|
17 |
*
|
11 |
|
12 |
require_once(WPSC_FILE_PATH . '/wpsc-admin/includes/products.php');
|
13 |
|
|
|
14 |
/**
|
15 |
* wpsc_additional_column_names function.
|
16 |
*
|
wpsc-admin/display-sales-logs.php
CHANGED
@@ -11,14 +11,23 @@
|
|
11 |
class WPSC_Purchase_Log_Page {
|
12 |
private $list_table;
|
13 |
private $output;
|
|
|
14 |
|
15 |
public function __construct() {
|
16 |
$controller = 'default';
|
17 |
$controller_method = 'controller_default';
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
if ( isset( $_REQUEST['c'] ) && method_exists( $this, 'controller_' . $_REQUEST['c'] ) ) {
|
20 |
$controller = $_REQUEST['c'];
|
21 |
$controller_method = 'controller_' . $controller;
|
|
|
|
|
|
|
22 |
}
|
23 |
|
24 |
$this->$controller_method();
|
@@ -250,8 +259,6 @@ class WPSC_Purchase_Log_Page {
|
|
250 |
|
251 |
global $purchlogitem;
|
252 |
|
253 |
-
$this->log_id = (int) $_REQUEST['id'];
|
254 |
-
|
255 |
// TODO: seriously get rid of all these badly coded purchaselogs.class.php functions in 4.0
|
256 |
$purchlogitem = new wpsc_purchaselogs_items( $this->log_id );
|
257 |
|
@@ -282,8 +289,6 @@ class WPSC_Purchase_Log_Page {
|
|
282 |
|
283 |
global $purchlogitem;
|
284 |
|
285 |
-
$this->log_id = (int) $_REQUEST['id'];
|
286 |
-
|
287 |
$purchlogitem = new wpsc_purchaselogs_items( $this->log_id );
|
288 |
|
289 |
$columns = array(
|
11 |
class WPSC_Purchase_Log_Page {
|
12 |
private $list_table;
|
13 |
private $output;
|
14 |
+
public $log_id = 0;
|
15 |
|
16 |
public function __construct() {
|
17 |
$controller = 'default';
|
18 |
$controller_method = 'controller_default';
|
19 |
|
20 |
+
// If individual purchase log, setup ID and action links.
|
21 |
+
if ( isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ) {
|
22 |
+
$this->log_id = (int) $_REQUEST['id'];
|
23 |
+
}
|
24 |
+
|
25 |
if ( isset( $_REQUEST['c'] ) && method_exists( $this, 'controller_' . $_REQUEST['c'] ) ) {
|
26 |
$controller = $_REQUEST['c'];
|
27 |
$controller_method = 'controller_' . $controller;
|
28 |
+
} elseif ( isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ) {
|
29 |
+
$controller = 'item_details';
|
30 |
+
$controller_method = 'controller_item_details';
|
31 |
}
|
32 |
|
33 |
$this->$controller_method();
|
259 |
|
260 |
global $purchlogitem;
|
261 |
|
|
|
|
|
262 |
// TODO: seriously get rid of all these badly coded purchaselogs.class.php functions in 4.0
|
263 |
$purchlogitem = new wpsc_purchaselogs_items( $this->log_id );
|
264 |
|
289 |
|
290 |
global $purchlogitem;
|
291 |
|
|
|
|
|
292 |
$purchlogitem = new wpsc_purchaselogs_items( $this->log_id );
|
293 |
|
294 |
$columns = array(
|
wpsc-admin/display-update.page.php
CHANGED
@@ -36,7 +36,7 @@ if ( ! get_option( 'wpsc_needs_update', false ) ) {
|
|
36 |
if ( $product_count > 0 ) {
|
37 |
|
38 |
function wpsc_display_update_notice() {
|
39 |
-
echo "<div id='wpsc-warning' class='error fade'><p><strong>" . __( 'WP
|
40 |
}
|
41 |
|
42 |
if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'wpsc-update' )
|
@@ -50,7 +50,7 @@ if ( ! get_option( 'wpsc_needs_update', false ) ) {
|
|
50 |
|
51 |
function wpsc_display_php_version_notice() {
|
52 |
?>
|
53 |
-
<div id='wpsc-warning' class='error fade'><p><?php printf( __( 'You are using PHP %s. WP
|
54 |
<?php
|
55 |
}
|
56 |
|
@@ -60,7 +60,7 @@ function wpsc_display_update_page() {
|
|
60 |
?>
|
61 |
|
62 |
<div class="wrap">
|
63 |
-
<h2><?php esc_html_e( 'Update WP
|
64 |
<br />
|
65 |
<?php
|
66 |
if ( isset( $_REQUEST['run_updates'] ) ) :
|
@@ -81,7 +81,7 @@ function wpsc_display_update_page() {
|
|
81 |
$wpsc_update->run( $function, $message );
|
82 |
}
|
83 |
|
84 |
-
echo '<br /><br /><strong>' . esc_html__( 'WP
|
85 |
if( '' != get_option('permalink_structure')){ ?>
|
86 |
<em><?php echo esc_html( sprintf( __( 'Note: It looks like you have custom permalinks, you will need to refresh your permalinks <a href="%s">here</a>', 'wpsc' ) , admin_url( 'options-permalink.php' ) ) ); ?></em>
|
87 |
<?php
|
@@ -94,7 +94,7 @@ function wpsc_display_update_page() {
|
|
94 |
else:
|
95 |
|
96 |
|
97 |
-
esc_html_e( 'Your WP
|
98 |
?> <br />
|
99 |
<br />
|
100 |
<em><?php esc_html_e( 'Note: If the server times out or runs out of memory, just reload this page, the server will pick up where it left off.', 'wpsc' ); ?></em>
|
@@ -102,7 +102,7 @@ function wpsc_display_update_page() {
|
|
102 |
|
103 |
<form action="" method="post" id="setup">
|
104 |
<input type="hidden" name="run_updates" value="true" id="run_updates">
|
105 |
-
<p class="step"><input type="submit" class="button" value="<?php esc_attr_e( 'Update WP
|
106 |
</form>
|
107 |
<?php
|
108 |
endif;
|
36 |
if ( $product_count > 0 ) {
|
37 |
|
38 |
function wpsc_display_update_notice() {
|
39 |
+
echo "<div id='wpsc-warning' class='error fade'><p><strong>" . __( 'WP eCommerce is almost ready.', 'wpsc' ) . "</strong> " . sprintf( __( 'You must <a href="%1$s">update your database</a> to import all of your products.', 'wpsc' ), "admin.php?page=wpsc-update") . "</p></div>";
|
40 |
}
|
41 |
|
42 |
if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'wpsc-update' )
|
50 |
|
51 |
function wpsc_display_php_version_notice() {
|
52 |
?>
|
53 |
+
<div id='wpsc-warning' class='error fade'><p><?php printf( __( 'You are using PHP %s. WP eCommerce %s requires PHP 5.0 or above. Please contact your hosting provider for further assistance.', 'wpsc' ), PHP_VERSION, WPSC_VERSION ); ?></p></div>
|
54 |
<?php
|
55 |
}
|
56 |
|
60 |
?>
|
61 |
|
62 |
<div class="wrap">
|
63 |
+
<h2><?php esc_html_e( 'Update WP eCommerce', 'wpsc' ); ?> </h2>
|
64 |
<br />
|
65 |
<?php
|
66 |
if ( isset( $_REQUEST['run_updates'] ) ) :
|
81 |
$wpsc_update->run( $function, $message );
|
82 |
}
|
83 |
|
84 |
+
echo '<br /><br /><strong>' . esc_html__( 'WP eCommerce updated successfully!', 'wpsc' ) . '</strong><br />';
|
85 |
if( '' != get_option('permalink_structure')){ ?>
|
86 |
<em><?php echo esc_html( sprintf( __( 'Note: It looks like you have custom permalinks, you will need to refresh your permalinks <a href="%s">here</a>', 'wpsc' ) , admin_url( 'options-permalink.php' ) ) ); ?></em>
|
87 |
<?php
|
94 |
else:
|
95 |
|
96 |
|
97 |
+
esc_html_e( 'Your WP eCommerce database needs to be updated for WP eCommerce 3.8. To perform this update, press the button below. It is highly recommended that you back up your database before performing this update.', 'wpsc' );
|
98 |
?> <br />
|
99 |
<br />
|
100 |
<em><?php esc_html_e( 'Note: If the server times out or runs out of memory, just reload this page, the server will pick up where it left off.', 'wpsc' ); ?></em>
|
102 |
|
103 |
<form action="" method="post" id="setup">
|
104 |
<input type="hidden" name="run_updates" value="true" id="run_updates">
|
105 |
+
<p class="step"><input type="submit" class="button" value="<?php esc_attr_e( 'Update WP eCommerce', 'wpsc' ); ?>" name="Submit"></p>
|
106 |
</form>
|
107 |
<?php
|
108 |
endif;
|
wpsc-admin/display-upgrades.page.php
CHANGED
@@ -6,12 +6,12 @@ function wpsc_display_upgrades_page() {
|
|
6 |
|
7 |
<div class='wrap'>
|
8 |
<div class='metabox-holder wpsc_gold_side'>
|
9 |
-
|
10 |
<h2><?php esc_html_e( 'Upgrades', 'wpsc' ); ?></h2>
|
11 |
<div>
|
12 |
<?php if ( defined( 'WPSC_GOLD_MODULE_PRESENT' ) && ( true == WPSC_GOLD_MODULE_PRESENT ) ) {?>
|
13 |
<p><?php esc_html_e( 'Enter your API Username and API Key below.', 'wpsc' ); ?></p>
|
14 |
-
<p><a href="http://docs.
|
15 |
<?php } ?>
|
16 |
<div class='metabox-holder'>
|
17 |
<form method='post' id='gold_cart_form' action=''>
|
@@ -35,42 +35,37 @@ function wpsc_display_upgrades_page() {
|
|
35 |
</div>
|
36 |
</div>
|
37 |
|
38 |
-
<strong><?php esc_html_e( 'WP
|
39 |
-
|
|
|
40 |
|
41 |
<br />
|
42 |
<div class='wpsc_gold_module'>
|
43 |
<br />
|
44 |
-
<a href="
|
45 |
<p class='wpsc_gold_text'><?php esc_html_e( 'Add product search, multiple image upload, gallery view, Grid View and multiple payment gateway options to your shop', 'wpsc' ); ?></p>
|
46 |
</div>
|
47 |
|
48 |
<div class='wpsc_gold_module'>
|
49 |
<br />
|
50 |
-
<a href="
|
51 |
<p class='wpsc_gold_text'><?php esc_html_e( 'Create product memberships and sell them in your store. Use these memberships to restrict premium content on your posts and pages creating a "members only" area perfect for: Forums, Images and Movies and Podcasts', 'wpsc' ); ?></p>
|
52 |
</div>
|
53 |
|
54 |
<div class='wpsc_gold_module'>
|
55 |
<br />
|
56 |
-
<a href="
|
57 |
-
<p class='wpsc_gold_text'><?php esc_html_e( '
|
58 |
-
</div>
|
59 |
-
|
60 |
-
<div class='wpsc_gold_module'>
|
61 |
-
<br />
|
62 |
-
<a href="http://getshopped.org/premium-upgrades/premium-plugin/nextgen-gallery-buy-now-buttons-wordpress-stores/" target="_blank"><strong><?php esc_html_e( 'NextGen Gallery Buy Now Buttons', 'wpsc' ); ?> </strong></a>
|
63 |
-
<p class='wpsc_gold_text'><?php esc_html_e( 'Make your Online photo gallery into an e-Commerce solution.', 'wpsc' ); ?></p>
|
64 |
</div>
|
65 |
|
66 |
<div class='wpsc_gold_module'>
|
67 |
<br />
|
68 |
-
<a href="
|
69 |
<p class='wpsc_gold_text'><?php esc_html_e( 'MP3 Player Plugin for WordPress', 'wpsc' ); ?></p>
|
70 |
</div>
|
71 |
<div class='wpsc_gold_module'>
|
72 |
<br />
|
73 |
-
<a href="
|
74 |
<p class='wpsc_gold_text'><?php esc_html_e( 'This plugin offers shop owners the ability to provide Fedex Shipping Quotes for products with weights.', 'wpsc' ); ?></p>
|
75 |
</div>
|
76 |
</div>
|
6 |
|
7 |
<div class='wrap'>
|
8 |
<div class='metabox-holder wpsc_gold_side'>
|
9 |
+
|
10 |
<h2><?php esc_html_e( 'Upgrades', 'wpsc' ); ?></h2>
|
11 |
<div>
|
12 |
<?php if ( defined( 'WPSC_GOLD_MODULE_PRESENT' ) && ( true == WPSC_GOLD_MODULE_PRESENT ) ) {?>
|
13 |
<p><?php esc_html_e( 'Enter your API Username and API Key below.', 'wpsc' ); ?></p>
|
14 |
+
<p><a href="http://docs.wpecommerce.org/category/extending-your-store/premium-plugins/gold-cart/"><?php esc_html_e( 'For more information visit our documentation page.', 'wpsc' ); ?></a></p>
|
15 |
<?php } ?>
|
16 |
<div class='metabox-holder'>
|
17 |
<form method='post' id='gold_cart_form' action=''>
|
35 |
</div>
|
36 |
</div>
|
37 |
|
38 |
+
<strong><?php esc_html_e( 'WP eCommerce Upgrades', 'wpsc' ); ?></strong><br />
|
39 |
+
|
40 |
+
<span><?php esc_html_e( 'Add more functionality to your eCommerce site. Prices may be subject to change.', 'wpsc' ); ?><input type='button' class='button-primary' onclick='window.open ("http://wpecommerce.org/store/premium-plugins/","mywindow");' value='<?php esc_html_e( 'Buy Now', 'wpsc' ); ?>' id='visitInstinct' name='visitInstinct' /></span>
|
41 |
|
42 |
<br />
|
43 |
<div class='wpsc_gold_module'>
|
44 |
<br />
|
45 |
+
<a href="https://wpecommerce.org/store/premium-plugins/gold-cart/" target="_blank"><strong><?php esc_html_e( 'Gold Cart', 'wpsc' ); ?></strong></a>
|
46 |
<p class='wpsc_gold_text'><?php esc_html_e( 'Add product search, multiple image upload, gallery view, Grid View and multiple payment gateway options to your shop', 'wpsc' ); ?></p>
|
47 |
</div>
|
48 |
|
49 |
<div class='wpsc_gold_module'>
|
50 |
<br />
|
51 |
+
<a href="https://wpecommerce.org/store/premium-plugins/membership-subscriptions/" target="_blank"><strong><?php esc_html_e( 'Members Access Plugin', 'wpsc' ); ?></strong></a>
|
52 |
<p class='wpsc_gold_text'><?php esc_html_e( 'Create product memberships and sell them in your store. Use these memberships to restrict premium content on your posts and pages creating a "members only" area perfect for: Forums, Images and Movies and Podcasts', 'wpsc' ); ?></p>
|
53 |
</div>
|
54 |
|
55 |
<div class='wpsc_gold_module'>
|
56 |
<br />
|
57 |
+
<a href="https://wpecommerce.org/store/premium-plugins/nextgen-gallery-buy-now-buttons/" target="_blank"><strong><?php esc_html_e( 'NextGen Gallery Buy Now Buttons', 'wpsc' ); ?> </strong></a>
|
58 |
+
<p class='wpsc_gold_text'><?php esc_html_e( 'Make your Online photo gallery into an eCommerce solution.', 'wpsc' ); ?></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
</div>
|
60 |
|
61 |
<div class='wpsc_gold_module'>
|
62 |
<br />
|
63 |
+
<a href="https://wpecommerce.org/store/premium-plugins/mp3-player-plugin/" target="_blank"><strong><?php esc_html_e( 'JPlayer - MP3 Plugin', 'wpsc' ); ?> </strong></a>
|
64 |
<p class='wpsc_gold_text'><?php esc_html_e( 'MP3 Player Plugin for WordPress', 'wpsc' ); ?></p>
|
65 |
</div>
|
66 |
<div class='wpsc_gold_module'>
|
67 |
<br />
|
68 |
+
<a href="https://wpecommerce.org/store/premium-plugins/fedex-shipping-module/" target="_blank"><strong><?php esc_html_e( 'FedEx Plugin', 'wpsc' ); ?> </strong></a>
|
69 |
<p class='wpsc_gold_text'><?php esc_html_e( 'This plugin offers shop owners the ability to provide Fedex Shipping Quotes for products with weights.', 'wpsc' ); ?></p>
|
70 |
</div>
|
71 |
</div>
|
wpsc-admin/includes/display-items-functions.php
CHANGED
@@ -9,483 +9,487 @@
|
|
9 |
global $wpsc_product_defaults;
|
10 |
|
11 |
$wpsc_product_defaults = array(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
);
|
55 |
|
56 |
function wpsc_redirect_variation_update( $location, $post_id ) {
|
57 |
-
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
}
|
65 |
|
66 |
add_filter( 'redirect_post_location', 'wpsc_redirect_variation_update', 10, 2 );
|
67 |
|
68 |
function wpsc_price_control_forms() {
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
|
78 |
-
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
|
123 |
-
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
|
129 |
-
|
130 |
|
131 |
-
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
|
137 |
-
|
138 |
-
|
139 |
|
140 |
-
|
141 |
-
|
142 |
|
143 |
-
|
144 |
|
145 |
-
|
146 |
-
|
147 |
?>
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
|
|
279 |
|
280 |
<?php endif;
|
281 |
|
282 |
}
|
283 |
function wpsc_stock_control_forms() {
|
284 |
-
|
285 |
|
286 |
-
|
287 |
-
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
|
293 |
-
|
294 |
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
|
320 |
-
|
321 |
-
|
322 |
|
323 |
-
|
324 |
-
?>
|
325 |
-
<label for="wpsc_sku"><abbr title="<?php esc_attr_e( 'Stock Keeping Unit', 'wpsc' ); ?>"><?php esc_html_e( 'SKU:', 'wpsc' ); ?></abbr></label>
|
326 |
-
<?php
|
327 |
-
if ( !isset( $product_data['meta']['_wpsc_sku'] ) )
|
328 |
-
$product_data['meta']['_wpsc_sku'] = $wpsc_product_defaults['meta']['sku']; ?><br />
|
329 |
-
<input size='32' type='text' class='text' id="wpsc_sku" name='meta[_wpsc_sku]' value='<?php echo esc_html( $product_data['meta']['_wpsc_sku'] ); ?>' />
|
330 |
-
<br style="clear:both" />
|
331 |
-
<?php
|
332 |
-
if ( !isset( $product_data['meta']['_wpsc_stock'] ) )
|
333 |
-
$product_data['meta']['_wpsc_stock'] = ''; ?>
|
334 |
-
<br /><input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' <?php if ( is_numeric( $product_data['meta']['_wpsc_stock'] ) ) echo 'checked="checked"'; else echo ''; ?> name='meta[_wpsc_limited_stock]' />
|
335 |
-
<label for='add_form_quantity_limited' class='small'><?php esc_html_e( 'Product has limited stock', 'wpsc' ); ?></label>
|
336 |
-
<?php
|
337 |
-
if ( $post->ID > 0 ) {
|
338 |
-
if ( is_numeric( $product_data['meta']['_wpsc_stock'] ) ) {?>
|
339 |
-
<div class='edit_stock' style='display: block;'> <?php
|
340 |
-
} else { ?>
|
341 |
-
<div class='edit_stock' style='display: none;'><?php
|
342 |
-
} ?>
|
343 |
-
<?php if ( wpsc_product_has_children( $post->ID ) ) : ?>
|
344 |
-
<?php $stock = wpsc_variations_stock_remaining( $post->ID ); ?>
|
345 |
-
<p><?php echo sprintf( __( 'This product has variations. To edit the quantity, please use the <a href="%s">Variation Controls</a> below.' , 'wpsc' ), '#wpsc_product_variation_forms' ); ?></p>
|
346 |
-
<p><?php printf( _n( "%s variant item in stock.", "%s variant items in stock.", $stock, 'wpsc' ), $stock ); ?></p>
|
347 |
-
<?php else: ?>
|
348 |
-
<div style="margin-bottom:20px;">
|
349 |
-
<label for="stock_limit_quantity"><?php esc_html_e( 'Quantity in stock', 'wpsc' ); ?></label>
|
350 |
-
<input type='number' min="0" step="1" style="width:80px; margin-left:50px;"
|
351 |
-
id="stock_limit_quantity" name='meta[_wpsc_stock]'
|
352 |
-
size='3' value='<?php echo absint( $product_data['meta']['_wpsc_stock'] ); ?>'
|
353 |
-
class='stock_limit_quantity' />
|
354 |
-
</div>
|
355 |
-
|
356 |
-
<?php
|
357 |
-
$remaining_quantity = wpsc_get_remaining_quantity( $post->ID );
|
358 |
-
$reserved_quantity = $product_data['meta']['_wpsc_stock'] - $remaining_quantity;
|
359 |
-
if ( $reserved_quantity ) {
|
360 |
-
echo '<p><em>';
|
361 |
-
printf( _n('%s of them is reserved for pending or recently completed orders.',
|
362 |
-
'%s of them are reserved for pending or recently completed orders.',
|
363 |
-
$reserved_quantity, 'wpsc'), $reserved_quantity );
|
364 |
-
|
365 |
-
echo '</em></p>';
|
366 |
-
}
|
367 |
-
?>
|
368 |
-
<?php endif; ?>
|
369 |
-
|
370 |
-
<p><?php esc_html_e( 'When stock reduces to zero:', 'wpsc' ); ?></p>
|
371 |
-
<div class='notify_when_none_left'>
|
372 |
-
<input type='checkbox' id="notify_when_oos"
|
373 |
-
name='meta[_wpsc_product_metadata][notify_when_none_left]'
|
374 |
-
class='notify_when_oos'<?php checked( $product_meta['notify_when_none_left'] ); ?> />
|
375 |
-
<label for="notify_when_oos"><?php esc_html_e( 'Notify site owner via email', 'wpsc' ); ?></label>
|
376 |
-
</div>
|
377 |
-
<div class='unpublish_when_none_left'>
|
378 |
-
<input type='checkbox' id="unpublish_when_oos"
|
379 |
-
name='meta[_wpsc_product_metadata][unpublish_when_none_left]'
|
380 |
-
class='unpublish_when_oos'<?php checked( $product_meta['unpublish_when_none_left'] ); ?> />
|
381 |
-
<label for="unpublish_when_oos"><?php esc_html_e( 'Unpublish product from website', 'wpsc' ); ?></label>
|
382 |
-
|
383 |
-
</div>
|
384 |
-
</div> <?php
|
385 |
-
} else { ?>
|
386 |
-
<div style='display: none;' class='edit_stock'>
|
387 |
-
<?php esc_html_e( 'Stock Qty', 'wpsc' ); ?><input type='text' name='meta[_wpsc_stock]' value='0' size='10' />
|
388 |
-
<div style='font-size:9px; padding:5px;'>
|
389 |
-
<input type='checkbox' class='notify_when_oos' name='meta[_wpsc_product_metadata][notify_when_none_left]' /> <?php esc_html_e( 'Email site owner if this Product runs out of stock', 'wpsc' ); ?>
|
390 |
-
<input type='checkbox' class='unpublish_when_oos' name='meta[_wpsc_product_metadata][unpublish_when_none_left]' /> <?php esc_html_e( 'Set status to Unpublished if this Product runs out of stock', 'wpsc' ); ?>
|
391 |
-
</div>
|
392 |
-
</div><?php
|
393 |
-
}
|
394 |
?>
|
|
|
395 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
}
|
|
|
397 |
function wpsc_product_taxes_forms() {
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
}
|
472 |
|
473 |
function wpsc_product_variation_forms() {
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
}
|
478 |
|
479 |
function _wpsc_get_product_variation_form_url( $id = false ) {
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
|
484 |
-
|
485 |
}
|
486 |
|
487 |
function wpsc_product_shipping_forms_metabox() {
|
488 |
-
|
489 |
}
|
490 |
|
491 |
/**
|
@@ -496,11 +500,11 @@ function wpsc_product_shipping_forms_metabox() {
|
|
496 |
* @return array List of valid dimension units.
|
497 |
*/
|
498 |
function wpsc_dimension_units() {
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
}
|
505 |
|
506 |
/**
|
@@ -511,12 +515,12 @@ function wpsc_dimension_units() {
|
|
511 |
* @return array List of valid weight units.
|
512 |
*/
|
513 |
function wpsc_weight_units() {
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
}
|
521 |
|
522 |
/**
|
@@ -530,18 +534,18 @@ function wpsc_weight_units() {
|
|
530 |
* @return string Weight unit string.
|
531 |
*/
|
532 |
function wpsc_weight_unit_display( $unit ) {
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
}
|
546 |
|
547 |
/**
|
@@ -560,13 +564,13 @@ function wpsc_weight_unit_display( $unit ) {
|
|
560 |
*/
|
561 |
function wpsc_validate_dimension_unit( $unit = '' ) {
|
562 |
|
563 |
-
|
564 |
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
|
569 |
-
|
570 |
}
|
571 |
|
572 |
/**
|
@@ -585,13 +589,13 @@ function wpsc_validate_dimension_unit( $unit = '' ) {
|
|
585 |
*/
|
586 |
function wpsc_validate_weight_unit( $unit = '' ) {
|
587 |
|
588 |
-
|
589 |
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
|
594 |
-
|
595 |
}
|
596 |
|
597 |
/**
|
@@ -601,270 +605,277 @@ function wpsc_validate_weight_unit( $unit = '' ) {
|
|
601 |
* @uses wpsc_validate_dimension_unit()
|
602 |
*/
|
603 |
function wpsc_product_shipping_forms( $product = false, $field_name_prefix = 'meta[_wpsc_product_metadata]', $bulk = false ) {
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
|
652 |
?>
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
<?php
|
|
|
|
|
|
|
732 |
}
|
733 |
|
734 |
-
|
|
|
|
|
|
|
|
|
|
|
735 |
function wpsc_product_advanced_forms() {
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
$output .= '<td><input type="text" name="new_custom_meta[name][]" value=""></input></td>';
|
804 |
-
$output .= '<td><input type="text" name="new_custom_meta[value][]" value=""></input></td>';
|
805 |
-
$output .= '<td><a href="#" class="wpsc_remove_meta" onclick="wpsc_remove_empty_meta(this)">'.esc_html( 'Delete', 'wpsc' ).'</a></td>';
|
806 |
-
$output .= '</tr>';
|
807 |
-
|
808 |
-
$output .= '</tbody>';
|
809 |
-
$output .= '</table>';
|
810 |
-
|
811 |
-
$output .= '<a href="#" class="add_more_meta button button-small" id="wpsc_add_custom_meta">'.esc_html( '+ Add Custom Meta', 'wpsc' ).'</a>';
|
812 |
-
|
813 |
-
|
814 |
-
echo $output;
|
815 |
-
return;
|
816 |
}
|
817 |
|
818 |
/**
|
819 |
* Display Product External Link Meta Box Form Fields.
|
|
|
|
|
820 |
*/
|
821 |
function wpsc_product_external_link_forms() {
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
862 |
}
|
863 |
|
864 |
function wpsc_additional_desc() {
|
865 |
?>
|
866 |
-
|
867 |
-
|
868 |
<?php
|
869 |
|
870 |
}
|
@@ -877,190 +888,202 @@ function wpsc_additional_desc() {
|
|
877 |
* @return void
|
878 |
*/
|
879 |
function wpsc_product_gallery( $post ) {
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
}
|
916 |
|
917 |
|
918 |
function wpsc_product_download_forms() {
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
|
924 |
-
|
925 |
-
|
926 |
|
927 |
-
|
928 |
?>
|
929 |
-
|
930 |
|
931 |
-
|
932 |
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
|
939 |
<?php
|
940 |
-
|
941 |
?>
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
|
946 |
-
|
947 |
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
|
956 |
-
|
957 |
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
|
967 |
-
|
968 |
}
|
969 |
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
990 |
}
|
991 |
|
992 |
function wpsc_product_delivery_forms(){
|
993 |
-
|
994 |
|
995 |
-
|
996 |
?>
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
<?php
|
1027 |
}
|
1028 |
|
1029 |
function wpsc_product_details_forms(){
|
1030 |
?>
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
<?php
|
1060 |
}
|
1061 |
|
1062 |
function wpsc_form_multipart_encoding() {
|
1063 |
-
|
1064 |
}
|
1065 |
|
1066 |
add_action( 'post_edit_form_tag', 'wpsc_form_multipart_encoding' );
|
@@ -1084,131 +1107,131 @@ add_filter( 'gettext_with_context', 'wpsc_filter_gettex_with_context', 12, 4);
|
|
1084 |
*/
|
1085 |
function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
|
1086 |
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
}
|
1095 |
|
1096 |
function wpsc_attachment_fields( $form_fields, $post ) {
|
1097 |
-
|
1098 |
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
|
1104 |
-
|
1105 |
-
|
1106 |
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
<script type="text/javascript">
|
1111 |
|
1112 |
-
|
1113 |
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
|
1121 |
-
|
1122 |
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
|
1127 |
|
1128 |
-
|
1129 |
|
1130 |
</script>';
|
1131 |
-
|
1132 |
|
1133 |
-
|
1134 |
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
|
1156 |
-
|
1157 |
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
|
1163 |
-
|
1164 |
|
1165 |
-
|
1166 |
-
|
1167 |
|
1168 |
-
|
1169 |
-
|
1170 |
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
|
1178 |
-
|
1179 |
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
|
1184 |
-
|
1185 |
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
|
1196 |
}
|
1197 |
function wpsc_save_attachment_fields( $post, $attachment ) {
|
1198 |
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
|
1211 |
-
|
1212 |
}
|
1213 |
|
1214 |
/**
|
@@ -1222,79 +1245,79 @@ function wpsc_save_attachment_fields( $post, $attachment ) {
|
|
1222 |
*/
|
1223 |
|
1224 |
function wpsc_save_quickedit_box( $post_id ) {
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
}
|
1299 |
|
1300 |
/**
|
@@ -1307,67 +1330,67 @@ function wpsc_save_quickedit_box( $post_id ) {
|
|
1307 |
*/
|
1308 |
|
1309 |
function wpsc_quick_edit_boxes( $col_name, $_screen_post_type = null ) {
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
?>
|
1315 |
|
1316 |
<fieldset class="inline-edit-col-left wpsc-cols">
|
1317 |
-
|
1318 |
-
|
1319 |
<?php
|
1320 |
-
|
1321 |
-
|
1322 |
?>
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
case 'weight' :
|
1332 |
?>
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
case 'stock' :
|
1341 |
?>
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
case 'price' :
|
1350 |
?>
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
case 'sale_price' :
|
1359 |
?>
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
?>
|
1369 |
-
|
1370 |
-
|
1371 |
</fieldset>
|
1372 |
<?php
|
1373 |
}
|
@@ -1383,54 +1406,54 @@ add_action( 'save_post', 'wpsc_save_quickedit_box' );
|
|
1383 |
* @param <type> $variation
|
1384 |
*/
|
1385 |
function variation_price_field( $variation ) {
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
}
|
1435 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field' );
|
1436 |
add_action( 'wpsc-variation_add_form_fields', 'variation_price_field' );
|
@@ -1441,17 +1464,17 @@ Use Jquery to move the set variation (parent) field to the top and add a descrip
|
|
1441 |
*/
|
1442 |
function variation_set_field(){
|
1443 |
?>
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
<?php
|
1456 |
}
|
1457 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_set_field' );
|
@@ -1460,27 +1483,27 @@ add_action( 'wpsc-variation_add_form_fields', 'variation_set_field' );
|
|
1460 |
|
1461 |
function category_edit_form(){
|
1462 |
?>
|
1463 |
-
|
1464 |
|
1465 |
-
|
1466 |
<?php
|
1467 |
}
|
1468 |
|
1469 |
function variation_price_field_check( $variation ) {
|
1470 |
|
1471 |
-
|
1472 |
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
<?php
|
1485 |
}
|
1486 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field_check' );
|
@@ -1494,79 +1517,79 @@ add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field_check' );
|
|
1494 |
* @param <type> $term_id
|
1495 |
*/
|
1496 |
function save_term_prices( $term_id ) {
|
1497 |
-
|
1498 |
-
|
1499 |
|
1500 |
-
|
1501 |
|
1502 |
-
|
1503 |
-
|
1504 |
|
1505 |
-
|
1506 |
-
|
1507 |
|
1508 |
-
|
1509 |
-
|
1510 |
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
|
1515 |
-
|
1516 |
|
1517 |
-
|
1518 |
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
|
1523 |
-
|
1524 |
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
1531 |
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
|
1539 |
-
|
1540 |
|
1541 |
-
|
1542 |
|
1543 |
-
|
1544 |
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
}
|
1552 |
add_action( 'edited_wpsc-variation', 'save_term_prices' );
|
1553 |
add_action( 'created_wpsc-variation', 'save_term_prices' );
|
1554 |
|
1555 |
function wpsc_delete_variations( $postid ) {
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
}
|
1571 |
add_action( 'before_delete_post', 'wpsc_delete_variations' );
|
1572 |
|
@@ -1584,34 +1607,34 @@ add_action( 'before_delete_post', 'wpsc_delete_variations' );
|
|
1584 |
*/
|
1585 |
function wpsc_get_admin_product_gallery( $product_id = 0 ) {
|
1586 |
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
|
1616 |
}
|
1617 |
|
@@ -1624,35 +1647,35 @@ function wpsc_get_admin_product_gallery( $product_id = 0 ) {
|
|
1624 |
*/
|
1625 |
function wpsc_new_gallery_save( $product_id = 0 ) {
|
1626 |
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
|
1657 |
}
|
1658 |
add_action( 'wpsc_edit_product', 'wpsc_new_gallery_save' );
|
9 |
global $wpsc_product_defaults;
|
10 |
|
11 |
$wpsc_product_defaults = array(
|
12 |
+
'id' => '0',
|
13 |
+
'name' => '',
|
14 |
+
'description' => '',
|
15 |
+
'additional_description' => '',
|
16 |
+
'price' => '0.00',
|
17 |
+
'weight' => '0',
|
18 |
+
'weight_unit' => 'pound',
|
19 |
+
'pnp' => '0.00',
|
20 |
+
'international_pnp' => '0.00',
|
21 |
+
'file' => '0',
|
22 |
+
'image' => '',
|
23 |
+
'category' => '0',
|
24 |
+
'brand' => '0',
|
25 |
+
'quantity_limited' => '0',
|
26 |
+
'quantity' => '0',
|
27 |
+
'special' => '0',
|
28 |
+
'special_price' => 0.00,
|
29 |
+
'display_frontpage' => '0',
|
30 |
+
'notax' => '0',
|
31 |
+
'publish' => '1',
|
32 |
+
'active' => '1',
|
33 |
+
'donation' => '0',
|
34 |
+
'no_shipping' => '0',
|
35 |
+
'thumbnail_image' => '',
|
36 |
+
'thumbnail_state' => '1',
|
37 |
+
'meta' => array(
|
38 |
+
'external_link' => NULL,
|
39 |
+
'external_link_text' => NULL,
|
40 |
+
'external_link_target' => NULL,
|
41 |
+
'merchant_notes' => NULL,
|
42 |
+
'sku' => NULL,
|
43 |
+
'engraved' => '0',
|
44 |
+
'can_have_uploaded_image' => '0',
|
45 |
+
'table_rate_price' => array(
|
46 |
+
'quantity' => array(
|
47 |
+
0 => '',
|
48 |
+
),
|
49 |
+
'table_price' => array(
|
50 |
+
0 => '',
|
51 |
+
),
|
52 |
+
),
|
53 |
+
),
|
54 |
);
|
55 |
|
56 |
function wpsc_redirect_variation_update( $location, $post_id ) {
|
57 |
+
global $post;
|
58 |
|
59 |
+
if ( $post->post_parent > 0 && 'wpsc-product' == $post->post_type )
|
60 |
+
wp_redirect( admin_url( 'post.php?post='.$post->post_parent.'&action=edit' ) );
|
61 |
+
else
|
62 |
+
return $location;
|
63 |
|
64 |
}
|
65 |
|
66 |
add_filter( 'redirect_post_location', 'wpsc_redirect_variation_update', 10, 2 );
|
67 |
|
68 |
function wpsc_price_control_forms() {
|
69 |
+
global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
|
70 |
|
71 |
+
$product_data = get_post_custom( $post->ID );
|
72 |
+
$product_data['meta'] = maybe_unserialize( $product_data );
|
73 |
|
74 |
+
foreach ( $product_data['meta'] as $meta_key => $meta_value ) {
|
75 |
+
$product_data['meta'][$meta_key] = $meta_value[0];
|
76 |
+
}
|
77 |
|
78 |
+
$product_meta = array();
|
79 |
|
80 |
+
if ( ! empty( $product_data['_wpsc_product_metadata'] ) ) {
|
81 |
+
$product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
|
82 |
+
}
|
83 |
|
84 |
+
if ( isset( $product_data['meta']['_wpsc_currency'] ) ) {
|
85 |
+
$product_alt_currency = maybe_unserialize( $product_data['meta']['_wpsc_currency'] );
|
86 |
+
}
|
87 |
|
88 |
+
if ( ! isset( $product_data['meta']['_wpsc_table_rate_price'] ) ) {
|
89 |
+
$product_data['meta']['_wpsc_table_rate_price'] = $wpsc_product_defaults['meta']['table_rate_price'];
|
90 |
+
}
|
91 |
|
92 |
+
if ( isset( $product_meta['_wpsc_table_rate_price'] ) ) {
|
93 |
+
$product_meta['table_rate_price']['state'] = 1;
|
94 |
+
$product_meta['table_rate_price'] += $product_meta['_wpsc_table_rate_price'];
|
95 |
+
$product_data['meta']['_wpsc_table_rate_price'] = $product_meta['_wpsc_table_rate_price'];
|
96 |
+
}
|
97 |
|
98 |
|
99 |
+
if ( ! isset( $product_data['meta']['_wpsc_is_donation'] ) ) {
|
100 |
+
$product_data['meta']['_wpsc_is_donation'] = $wpsc_product_defaults['donation'];
|
101 |
+
}
|
102 |
|
103 |
+
if ( ! isset( $product_meta['table_rate_price']['state'] ) ) {
|
104 |
+
$product_meta['table_rate_price']['state'] = null;
|
105 |
+
}
|
106 |
|
107 |
+
if ( ! isset( $product_meta['table_rate_price']['quantity'] ) ) {
|
108 |
+
$product_meta['table_rate_price']['quantity'] = $wpsc_product_defaults['meta']['table_rate_price']['quantity'][0];
|
109 |
+
}
|
110 |
|
111 |
+
if ( ! isset( $product_data['meta']['_wpsc_price'] ) ) {
|
112 |
+
$product_data['meta']['_wpsc_price'] = $wpsc_product_defaults['price'];
|
113 |
+
}
|
114 |
|
115 |
+
if ( ! isset( $product_data['special'] ) ) {
|
116 |
+
$product_data['special'] = $wpsc_product_defaults['special'];
|
117 |
+
}
|
118 |
|
119 |
+
if ( ! isset( $product_data['meta']['_wpsc_special_price'] ) ) {
|
120 |
+
$product_data['meta']['_wpsc_special_price'] = $wpsc_product_defaults['special_price'];
|
121 |
+
}
|
122 |
|
123 |
+
$product_data['meta']['_wpsc_special_price'] = wpsc_format_number( $product_data['meta']['_wpsc_special_price'] );
|
124 |
|
125 |
+
if ( ! isset( $product_data['meta']['_wpsc_price'] ) ) {
|
126 |
+
$product_data['meta']['_wpsc_price'] = 0;
|
127 |
+
}
|
128 |
|
129 |
+
$product_data['meta']['_wpsc_price'] = wpsc_format_number( $product_data['meta']['_wpsc_price'] );
|
130 |
|
131 |
+
$currency_data = $wpdb->get_results( "SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A );
|
132 |
|
133 |
+
/* Get country name and symbol */
|
134 |
+
$currency_type = get_option( 'currency_type' );
|
135 |
+
$country = new WPSC_Country( $currency_type );
|
136 |
|
137 |
+
$ct_code = $country->get_currency_code(); // Country currency code
|
138 |
+
$ct_symb = $country->get_currency_symbol(); // Country symbol
|
139 |
|
140 |
+
$price = $product_data['meta']['_wpsc_price'];
|
141 |
+
$sale_price = $product_data['meta']['_wpsc_special_price'];
|
142 |
|
143 |
+
$wp_38 = version_compare( $GLOBALS['wp_version'], '3.8', '>=' );
|
144 |
|
145 |
+
$currency_delete_class = $wp_38 ? ' dashicons dashicons-dismiss' : '';
|
146 |
+
$currency_delete_text = $wp_38 ? '' : 'x';
|
147 |
?>
|
148 |
+
<em id="wpsc_product_price_metabox_live_title" class="wpsc_metabox_live_title">
|
149 |
+
<p> <?php echo esc_html( $ct_symb ); ?><span><?php echo esc_html( $sale_price ); ?></span></p>
|
150 |
+
<del><?php esc_html_e($ct_symb); ?><span><?php esc_html_e($price) ?></span></del>
|
151 |
+
</em>
|
152 |
+
<input type="hidden" id="parent_post" name="parent_post" value="<?php echo $post->post_parent; ?>" />
|
153 |
+
<?php /* Lots of tedious work is avoided with this little line. */ ?>
|
154 |
+
<input type="hidden" id="product_id" name="product_id" value="<?php echo $post->ID; ?>" />
|
155 |
+
|
156 |
+
<?php /* Check product if a product has variations */ ?>
|
157 |
+
<?php if ( wpsc_product_has_children( $post->ID ) ) : ?>
|
158 |
+
<?php $price = wpsc_product_variation_price_from( $post->ID ); ?>
|
159 |
+
<p style="margin-top: 6px;"><?php echo sprintf( __( 'This product has variations. To edit the price, please use the <a href="%s">Variation Controls</a>.' , 'wpsc' ), '#wpsc_product_variation_forms' ); ?></p>
|
160 |
+
<p><?php printf( __( 'Price: %s and above.' , 'wpsc' ), $price ); ?></p>
|
161 |
+
<?php else: ?>
|
162 |
+
|
163 |
+
<div class='wpsc_floatleft' style="width:100px;">
|
164 |
+
<label for="wpsc_price"><?php _e( 'Price', 'wpsc' ); ?></label>
|
165 |
+
<?php echo esc_html( $ct_symb ); ?> <input id="wpsc_price"
|
166 |
+
type="text"
|
167 |
+
style="width: 70px;"
|
168 |
+
name="meta[_wpsc_price]"
|
169 |
+
value="<?php echo esc_attr( $price ); ?>" />
|
170 |
+
</div>
|
171 |
+
|
172 |
+
<div class='wpsc_floatleft' style='width:95px; margin-left:30px;'>
|
173 |
+
<label for='wpsc_sale_price'><?php _e( 'Sale Price', 'wpsc' ); ?></label>
|
174 |
+
<?php echo esc_html( $ct_symb ); ?> <input id = "wpsc_sale_price"
|
175 |
+
type="text"
|
176 |
+
style="width: 70px;"
|
177 |
+
value="<?php echo esc_attr( $sale_price ); ?>"
|
178 |
+
name='meta[_wpsc_special_price]' />
|
179 |
+
</div>
|
180 |
+
|
181 |
+
<div class="wpsc-currency-layers">
|
182 |
+
<table>
|
183 |
+
<thead>
|
184 |
+
<tr>
|
185 |
+
<th class="type" colspan="2"><?php esc_html_e( 'Alternative Currencies:', 'wpsc' ); ?></th>
|
186 |
+
<th class="price"><?php esc_html_e( 'Price:', 'wpsc' ); ?></th>
|
187 |
+
<tr>
|
188 |
+
</thead>
|
189 |
+
<tbody>
|
190 |
+
<?php
|
191 |
+
if ( isset( $product_alt_currency ) && is_array( $product_alt_currency ) ) :
|
192 |
+
$i = 0;
|
193 |
+
foreach ( $product_alt_currency as $iso => $alt_price ) :
|
194 |
+
$i++;
|
195 |
+
?>
|
196 |
+
<tr class="wpsc_additional_currency">
|
197 |
+
<td class="remove"><a href="#" class="wpsc_delete_currency_layer<?php echo $currency_delete_class; ?>" rel="<?php echo $iso; ?>"><?php echo $currency_delete_text; ?></a></td>
|
198 |
+
<td>
|
199 |
+
<select name="newCurrency[]" class="newCurrency">
|
200 |
+
<?php foreach ( $currency_data as $currency ) : ?>
|
201 |
+
<option value="<?php echo absint( $currency['id'] ); ?>" <?php selected( $iso, $currency['isocode'] ); ?>>
|
202 |
+
<?php echo esc_html( $currency['country'] ); ?> (<?php echo esc_html( $currency['currency'] ); ?>)
|
203 |
+
</option>
|
204 |
+
<?php endforeach; ?>
|
205 |
+
</select>
|
206 |
+
</td>
|
207 |
+
<td><input class="newCurrPrice text" size="8" name="newCurrPrice[]" value="<?php echo esc_attr( $alt_price ); ?>" /></td>
|
208 |
+
</tr>
|
209 |
+
<?php
|
210 |
+
endforeach;
|
211 |
+
endif;
|
212 |
+
?>
|
213 |
+
<tr id="wpsc_currency_row_template" class="template hidden">
|
214 |
+
<td class="remove"><a href="#" class="wpsc_delete_currency_layer<?php echo $currency_delete_class; ?>"><?php echo $currency_delete_text; ?></a></td>
|
215 |
+
<td>
|
216 |
+
<select name="newCurrency[]" class="newCurrency">
|
217 |
+
<?php foreach ( (array) $currency_data as $currency ) { ?>
|
218 |
+
<option value="<?php echo absint( $currency['id'] ); ?>">
|
219 |
+
<?php echo esc_html( $currency['country'] ); ?>
|
220 |
+
</option>
|
221 |
+
<?php } ?>
|
222 |
+
</select>
|
223 |
+
</td>
|
224 |
+
<td><input class="newCurrPrice text" size="8" name="newCurrPrice[]" value="0.00" /></td>
|
225 |
+
</tr>
|
226 |
+
</tbody>
|
227 |
+
</table>
|
228 |
+
<a href="#wpsc_currency_row_template" class="button button-small wpsc_add_new_currency"><?php esc_html_e( 'Add a Currency Option', 'wpsc' ); ?></a>
|
229 |
+
<?php wp_nonce_field( 'update-options', 'wpsc-update-currency-layers', false ); ?>
|
230 |
+
</div>
|
231 |
+
|
232 |
+
<div class="wpsc-quantity-discounts">
|
233 |
+
<table>
|
234 |
+
<thead>
|
235 |
+
<tr>
|
236 |
+
<th class="qty" colspan="2"><?php esc_html_e( 'Quantity:', 'wpsc' ); ?></th>
|
237 |
+
<th class="curr"><span class="hidden"><?php esc_html_e( 'Currency:', 'wpsc' ); ?><span></th>
|
238 |
+
<th class="price"><?php esc_html_e( 'Price:', 'wpsc' ); ?></th>
|
239 |
+
</tr>
|
240 |
+
</thead>
|
241 |
+
<tbody>
|
242 |
+
<?php
|
243 |
+
if ( count( $product_meta['table_rate_price']['quantity'] ) > 0 ) {
|
244 |
+
foreach ( (array) $product_meta['table_rate_price']['quantity'] as $key => $quantity ) {
|
245 |
+
if ( $quantity != '' ) {
|
246 |
+
$table_price = number_format( $product_meta['table_rate_price']['table_price'][ $key ], 2, '.', '' );
|
247 |
+
?>
|
248 |
+
<tr>
|
249 |
+
<td class="remove"><a href="#" class="remove_line<?php echo $currency_delete_class; ?>"><?php echo $currency_delete_text; ?></a></td>
|
250 |
+
<td class="qty">
|
251 |
+
<input type="text" size="5" value="<?php echo absint( $quantity ); ?>" name="table_rate_price[quantity][]" />
|
252 |
+
<?php esc_html_e( '+', 'wpsc' ); ?>
|
253 |
+
</td>
|
254 |
+
<td class="curr"><?php echo $ct_code . ' ' . $ct_symb; ?></td>
|
255 |
+
<td><input class="newCurrPrice text" value="<?php echo $table_price; ?>" name="table_rate_price[table_price][]" /></td>
|
256 |
+
</tr>
|
257 |
+
<?php
|
258 |
+
}
|
259 |
+
}
|
260 |
+
}
|
261 |
+
?>
|
262 |
+
<tr id="wpsc_quantity_discount_row_template" class="template hidden">
|
263 |
+
<td class="remove"><a href="#" class="remove_line<?php echo $currency_delete_class; ?>"><?php echo $currency_delete_text; ?></a></td>
|
264 |
+
<td class="qty">
|
265 |
+
<input size="5" value="0" name="table_rate_price[quantity][]" />
|
266 |
+
<?php esc_html_e( '+', 'wpsc' ); ?>
|
267 |
+
</td>
|
268 |
+
<td class="curr"><?php echo $ct_code . ' ' . $ct_symb; ?></td>
|
269 |
+
<td><input size="10"class="newCurrPrice text" value="0" name="table_rate_price[table_price][]" /></td>
|
270 |
+
</tr>
|
271 |
+
</tbody>
|
272 |
+
</table>
|
273 |
+
<a href="#wpsc_quantity_discount_row_template" class="add_level button button-small"><?php esc_html_e( 'Add a Quantity Discount', 'wpsc' ); ?></a>
|
274 |
+
<?php wp_nonce_field( 'update-options', 'wpsc-update-quantity-discounts', false ); ?>
|
275 |
+
</div>
|
276 |
+
|
277 |
+
<input id="add_form_donation" type="checkbox" name="meta[_wpsc_is_donation]" value="yes" <?php checked( $product_data['meta']['_wpsc_is_donation'], 1 ); ?> />
|
278 |
+
<label for="add_form_donation"><?php _e( 'Purchase is a donation.', 'wpsc' ) ?></label>
|
279 |
+
<?php wp_nonce_field( 'update', 'wpsc_product_pricing_nonce' ); ?>
|
280 |
|
281 |
<?php endif;
|
282 |
|
283 |
}
|
284 |
function wpsc_stock_control_forms() {
|
285 |
+
global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
|
286 |
|
287 |
+
$product_data = get_post_custom( $post->ID );
|
288 |
+
$product_data['meta'] = maybe_unserialize( $product_data );
|
289 |
|
290 |
+
foreach ( $product_data['meta'] as $meta_key => $meta_value ) {
|
291 |
+
$product_data['meta'][$meta_key] = $meta_value[0];
|
292 |
+
}
|
293 |
|
294 |
+
$product_meta = array();
|
295 |
|
296 |
+
if ( ! empty( $product_data['_wpsc_product_metadata'] ) ) {
|
297 |
+
$product_meta = maybe_unserialize( $product_data["_wpsc_product_metadata"][0] );
|
298 |
+
}
|
299 |
|
300 |
+
// this is to make sure after upgrading to 3.8.9, products will have
|
301 |
+
// "notify_when_none_left" enabled by default if "unpublish_when_none_left"
|
302 |
+
// is enabled.
|
303 |
+
if ( ! isset( $product_meta['notify_when_none_left'] ) ) {
|
304 |
+
$product_meta['notify_when_none_left'] = 0;
|
305 |
|
306 |
+
if ( ! empty( $product_meta['unpublish_when_none_left'] ) ) {
|
307 |
+
$product_meta['notify_when_none_left'] = 1;
|
308 |
+
}
|
309 |
+
}
|
310 |
|
311 |
+
if ( ! isset( $product_meta['unpublish_when_none_left'] ) ) {
|
312 |
+
$product_meta['unpublish_when_none_left'] = '';
|
313 |
+
}
|
314 |
|
315 |
+
// Display live title if stock is set
|
316 |
+
if ( isset( $product_data['meta']['_wpsc_stock'] ) && is_numeric( $product_data['meta']['_wpsc_stock'] ) ) {
|
317 |
+
$live_title = '<em id="wpsc_product_stock_metabox_live_title" class="wpsc_metabox_live_title">';
|
318 |
+
$live_title .= sprintf( '<p><span>%s</span> %s</p>', wpsc_format_number( $product_data['meta']['_wpsc_stock'], 0 ), _x( 'left in stock', 'live preview of stock remaining in admin', 'wpsc' ) );
|
319 |
+
$live_title .= '</em>';
|
320 |
|
321 |
+
echo $live_title;
|
322 |
+
}
|
323 |
|
324 |
+
if ( ! empty( $product_meta['unpublish_when_none_left'] ) && ! isset( $product_meta['notify_when_none_left'] ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
?>
|
326 |
+
<label for="wpsc_sku"><abbr title="<?php esc_attr_e( 'Stock Keeping Unit', 'wpsc' ); ?>"><?php esc_html_e( 'SKU:', 'wpsc' ); ?></abbr></label>
|
327 |
<?php
|
328 |
+
if ( !isset( $product_data['meta']['_wpsc_sku'] ) )
|
329 |
+
$product_data['meta']['_wpsc_sku'] = $wpsc_product_defaults['meta']['sku']; ?><br />
|
330 |
+
<input size='32' type='text' class='text' id="wpsc_sku" name='meta[_wpsc_sku]' value='<?php echo esc_html( $product_data['meta']['_wpsc_sku'] ); ?>' />
|
331 |
+
<br style="clear:both" />
|
332 |
+
<?php
|
333 |
+
if ( !isset( $product_data['meta']['_wpsc_stock'] ) )
|
334 |
+
$product_data['meta']['_wpsc_stock'] = ''; ?>
|
335 |
+
<br /><input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' <?php if ( is_numeric( $product_data['meta']['_wpsc_stock'] ) ) echo 'checked="checked"'; else echo ''; ?> name='meta[_wpsc_limited_stock]' />
|
336 |
+
<label for='add_form_quantity_limited' class='small'><?php esc_html_e( 'Product has limited stock', 'wpsc' ); ?></label>
|
337 |
+
<?php
|
338 |
+
if ( $post->ID > 0 ) {
|
339 |
+
if ( is_numeric( $product_data['meta']['_wpsc_stock'] ) ) {?>
|
340 |
+
<div class='edit_stock' style='display: block;'> <?php
|
341 |
+
} else { ?>
|
342 |
+
<div class='edit_stock' style='display: none;'><?php
|
343 |
+
} ?>
|
344 |
+
<?php if ( wpsc_product_has_children( $post->ID ) ) : ?>
|
345 |
+
<?php $stock = wpsc_variations_stock_remaining( $post->ID ); ?>
|
346 |
+
<p><?php echo sprintf( __( 'This product has variations. To edit the quantity, please use the <a href="%s">Variation Controls</a> below.' , 'wpsc' ), '#wpsc_product_variation_forms' ); ?></p>
|
347 |
+
<p><?php printf( _n( "%s variant item in stock.", "%s variant items in stock.", $stock, 'wpsc' ), $stock ); ?></p>
|
348 |
+
<?php else: ?>
|
349 |
+
<div style="margin-bottom:20px;">
|
350 |
+
<label for="stock_limit_quantity"><?php esc_html_e( 'Quantity in stock', 'wpsc' ); ?></label>
|
351 |
+
<input type='number' min="0" step="1" style="width:80px; margin-left:50px;"
|
352 |
+
id="stock_limit_quantity" name='meta[_wpsc_stock]'
|
353 |
+
size='3' value='<?php echo absint( $product_data['meta']['_wpsc_stock'] ); ?>'
|
354 |
+
class='stock_limit_quantity' />
|
355 |
+
</div>
|
356 |
+
|
357 |
+
<?php
|
358 |
+
$remaining_quantity = wpsc_get_remaining_quantity( $post->ID );
|
359 |
+
$reserved_quantity = $product_data['meta']['_wpsc_stock'] - $remaining_quantity;
|
360 |
+
if ( $reserved_quantity ) {
|
361 |
+
echo '<p><em>';
|
362 |
+
printf( _n('%s of them is reserved for pending or recently completed orders.',
|
363 |
+
'%s of them are reserved for pending or recently completed orders.',
|
364 |
+
$reserved_quantity, 'wpsc'), $reserved_quantity );
|
365 |
+
|
366 |
+
echo '</em></p>';
|
367 |
+
}
|
368 |
+
?>
|
369 |
+
<?php endif; ?>
|
370 |
+
|
371 |
+
<p><?php esc_html_e( 'When stock reduces to zero:', 'wpsc' ); ?></p>
|
372 |
+
<div class='notify_when_none_left'>
|
373 |
+
<input type='checkbox' id="notify_when_oos"
|
374 |
+
name='meta[_wpsc_product_metadata][notify_when_none_left]'
|
375 |
+
class='notify_when_oos'<?php checked( $product_meta['notify_when_none_left'] ); ?> />
|
376 |
+
<label for="notify_when_oos"><?php esc_html_e( 'Notify site owner via email', 'wpsc' ); ?></label>
|
377 |
+
</div>
|
378 |
+
<div class='unpublish_when_none_left'>
|
379 |
+
<input type='checkbox' id="unpublish_when_oos"
|
380 |
+
name='meta[_wpsc_product_metadata][unpublish_when_none_left]'
|
381 |
+
class='unpublish_when_oos'<?php checked( $product_meta['unpublish_when_none_left'] ); ?> />
|
382 |
+
<label for="unpublish_when_oos"><?php esc_html_e( 'Unpublish product from website', 'wpsc' ); ?></label>
|
383 |
+
|
384 |
+
</div>
|
385 |
+
</div> <?php
|
386 |
+
} else { ?>
|
387 |
+
<div style='display: none;' class='edit_stock'>
|
388 |
+
<?php esc_html_e( 'Stock Qty', 'wpsc' ); ?><input type='text' name='meta[_wpsc_stock]' value='0' size='10' />
|
389 |
+
<div style='font-size:9px; padding:5px;'>
|
390 |
+
<input type='checkbox' class='notify_when_oos' name='meta[_wpsc_product_metadata][notify_when_none_left]' /> <?php esc_html_e( 'Email site owner if this Product runs out of stock', 'wpsc' ); ?>
|
391 |
+
<input type='checkbox' class='unpublish_when_oos' name='meta[_wpsc_product_metadata][unpublish_when_none_left]' /> <?php esc_html_e( 'Set status to Unpublished if this Product runs out of stock', 'wpsc' ); ?>
|
392 |
+
</div>
|
393 |
+
</div>
|
394 |
+
<?php
|
395 |
+
}
|
396 |
+
|
397 |
+
wp_nonce_field( 'update', 'wpsc_product_stock_nonce' );
|
398 |
+
|
399 |
}
|
400 |
+
|
401 |
function wpsc_product_taxes_forms() {
|
402 |
+
global $post, $wpdb, $wpsc_product_defaults;
|
403 |
+
$product_data = get_post_custom( $post->ID );
|
404 |
+
|
405 |
+
$product_data['meta'] = $product_meta = array();
|
406 |
+
if ( !empty( $product_data['_wpsc_product_metadata'] ) )
|
407 |
+
$product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
|
408 |
+
|
409 |
+
if ( !isset( $product_data['meta']['_wpsc_custom_tax'] ) )
|
410 |
+
$product_data['meta']['_wpsc_custom_tax'] = '';
|
411 |
+
$custom_tax = $product_data['meta']['_wpsc_custom_tax'];
|
412 |
+
|
413 |
+
|
414 |
+
if ( !isset( $product_meta['custom_tax'] ) ) {
|
415 |
+
$product_meta['custom_tax'] = 0.00;
|
416 |
+
}
|
417 |
+
|
418 |
+
//Add New WPEC-Taxes Bands Here
|
419 |
+
$wpec_taxes_controller = new wpec_taxes_controller();
|
420 |
+
|
421 |
+
//display tax bands
|
422 |
+
$band_select_settings = array(
|
423 |
+
'id' => 'wpec_taxes_band',
|
424 |
+
'name' => 'meta[_wpsc_product_metadata][wpec_taxes_band]',
|
425 |
+
'label' => __( 'Custom Tax Band', 'wpsc' )
|
426 |
+
);
|
427 |
+
$wpec_taxes_band = '';
|
428 |
+
if ( isset( $product_meta['wpec_taxes_band'] ) ) {
|
429 |
+
$band = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_band_from_index( $product_meta['wpec_taxes_band'] );
|
430 |
+
$wpec_taxes_band = array( 'index'=>$band['index'], 'name'=>$band['name'] );
|
431 |
+
}
|
432 |
+
|
433 |
+
$taxable_checkbox_settings = array(
|
434 |
+
'type' => 'checkbox',
|
435 |
+
'id' => 'wpec_taxes_taxable',
|
436 |
+
'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable]',
|
437 |
+
'label' => __( 'Product is exempt from taxation.', 'wpsc' )
|
438 |
+
);
|
439 |
+
|
440 |
+
if ( isset( $product_meta['wpec_taxes_taxable'] ) && 'on' == $product_meta['wpec_taxes_taxable'] ) {
|
441 |
+
$taxable_checkbox_settings['checked'] = 'checked';
|
442 |
+
}
|
443 |
+
|
444 |
+
//add taxable amount only for exclusive tax
|
445 |
+
if ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) {
|
446 |
+
$taxable_amount_input_settings = array(
|
447 |
+
'id' => 'wpec_taxes_taxable_amount',
|
448 |
+
'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable_amount]',
|
449 |
+
'label' => __( 'Taxable Amount', 'wpsc' ),
|
450 |
+
'description' => __( 'Taxable amount in your currency, not percentage of price.', 'wpsc' ),
|
451 |
+
);
|
452 |
+
|
453 |
+
if ( isset( $product_meta['wpec_taxes_taxable_amount'] ) ) {
|
454 |
+
$taxable_amount_input_settings['value'] = $product_meta['wpec_taxes_taxable_amount'];
|
455 |
+
|
456 |
+
if ( ! empty( $product_meta['wpec_taxes_taxable_amount'] ) )
|
457 |
+
$taxable_amount_input_settings['value'] = wpsc_format_number(
|
458 |
+
$taxable_amount_input_settings['value']
|
459 |
+
);
|
460 |
+
}
|
461 |
+
}// if
|
462 |
+
|
463 |
+
$output = '<a name="wpsc_tax"></a>';
|
464 |
+
$output .= '<p>'.$wpec_taxes_controller->wpec_taxes_build_input( $taxable_checkbox_settings ).'</p>';
|
465 |
+
$output .= '<p>'.$wpec_taxes_controller->wpec_taxes_display_tax_bands( $band_select_settings, $wpec_taxes_band ).'</p>';
|
466 |
+
$output .= '<p>';
|
467 |
+
$output .= ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) ? $wpec_taxes_controller->wpec_taxes_build_input( $taxable_amount_input_settings ) : '';
|
468 |
+
$output .= '</p>';
|
469 |
+
|
470 |
+
if ( ! $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_enabled() ) {
|
471 |
+
$output = '<p>' . sprintf( __( 'Taxes are not enabled. See <a href="%s">Settings > Taxes</a>', 'wpsc' ), admin_url( 'options-general.php?page=wpsc-settings&tab=taxes' ) ) . '</p>';
|
472 |
+
}
|
473 |
+
|
474 |
+
echo $output;
|
475 |
}
|
476 |
|
477 |
function wpsc_product_variation_forms() {
|
478 |
+
?>
|
479 |
+
<iframe src="<?php echo _wpsc_get_product_variation_form_url(); ?>"></iframe>
|
480 |
+
<?php
|
481 |
}
|
482 |
|
483 |
function _wpsc_get_product_variation_form_url( $id = false ) {
|
484 |
+
if ( ! $id ) {
|
485 |
+
$id = get_the_ID();
|
486 |
+
}
|
487 |
|
488 |
+
return admin_url( 'admin-ajax.php?action=wpsc_product_variations_table&product_id=' . $id . '&_wpnonce=' . wp_create_nonce( 'wpsc_product_variations_table' ) );
|
489 |
}
|
490 |
|
491 |
function wpsc_product_shipping_forms_metabox() {
|
492 |
+
wpsc_product_shipping_forms();
|
493 |
}
|
494 |
|
495 |
/**
|
500 |
* @return array List of valid dimension units.
|
501 |
*/
|
502 |
function wpsc_dimension_units() {
|
503 |
+
return array(
|
504 |
+
'in' => __( 'inches', 'wpsc' ),
|
505 |
+
'cm' => __( 'cm', 'wpsc' ),
|
506 |
+
'meter' => __( 'meters', 'wpsc' )
|
507 |
+
);
|
508 |
}
|
509 |
|
510 |
/**
|
515 |
* @return array List of valid weight units.
|
516 |
*/
|
517 |
function wpsc_weight_units() {
|
518 |
+
return array(
|
519 |
+
'pound' => __( 'pounds', 'wpsc' ),
|
520 |
+
'ounce' => __( 'ounces', 'wpsc' ),
|
521 |
+
'gram' => __( 'grams', 'wpsc' ),
|
522 |
+
'kilogram' => __( 'kilograms', 'wpsc' )
|
523 |
+
);
|
524 |
}
|
525 |
|
526 |
/**
|
534 |
* @return string Weight unit string.
|
535 |
*/
|
536 |
function wpsc_weight_unit_display( $unit ) {
|
537 |
+
switch ( $unit ) {
|
538 |
+
case 'pound' :
|
539 |
+
return __( ' lbs.', 'wpsc' );
|
540 |
+
case 'ounce' :
|
541 |
+
return __( ' oz.', 'wpsc' );
|
542 |
+
case 'gram' :
|
543 |
+
return __( ' g', 'wpsc' );
|
544 |
+
case 'kilograms' :
|
545 |
+
case 'kilogram' :
|
546 |
+
return __( ' kgs.', 'wpsc' );
|
547 |
+
}
|
548 |
+
return '';
|
549 |
}
|
550 |
|
551 |
/**
|
564 |
*/
|
565 |
function wpsc_validate_dimension_unit( $unit = '' ) {
|
566 |
|
567 |
+
$default_unit = apply_filters( 'wpsc_default_dimension_unit', $unit );
|
568 |
|
569 |
+
if ( empty( $unit ) && array_key_exists( $default_unit, wpsc_dimension_units() ) ) {
|
570 |
+
$unit = $default_unit;
|
571 |
+
}
|
572 |
|
573 |
+
return $unit;
|
574 |
}
|
575 |
|
576 |
/**
|
589 |
*/
|
590 |
function wpsc_validate_weight_unit( $unit = '' ) {
|
591 |
|
592 |
+
$default_unit = apply_filters( 'wpsc_default_weight_unit', $unit );
|
593 |
|
594 |
+
if ( empty( $unit ) && array_key_exists( $default_unit, wpsc_weight_units() ) ) {
|
595 |
+
$unit = $default_unit;
|
596 |
+
}
|
597 |
|
598 |
+
return $unit;
|
599 |
}
|
600 |
|
601 |
/**
|
605 |
* @uses wpsc_validate_dimension_unit()
|
606 |
*/
|
607 |
function wpsc_product_shipping_forms( $product = false, $field_name_prefix = 'meta[_wpsc_product_metadata]', $bulk = false ) {
|
608 |
+
if ( ! $product )
|
609 |
+
$product_id = get_the_ID();
|
610 |
+
else
|
611 |
+
$product_id = $product->ID;
|
612 |
+
|
613 |
+
$meta = get_post_meta( $product_id, '_wpsc_product_metadata', true );
|
614 |
+
if ( ! is_array( $meta ) )
|
615 |
+
$meta = array();
|
616 |
+
|
617 |
+
$defaults = array(
|
618 |
+
'weight' => '',
|
619 |
+
'weight_unit' => wpsc_validate_weight_unit(),
|
620 |
+
'demension_unit' => wpsc_validate_dimension_unit(),
|
621 |
+
'dimensions' => array(),
|
622 |
+
'shipping' => array(),
|
623 |
+
'no_shipping' => '',
|
624 |
+
'display_weight_as' => '',
|
625 |
+
);
|
626 |
+
$dimensions_defaults = array(
|
627 |
+
'height' => 0,
|
628 |
+
'width' => 0,
|
629 |
+
'length' => 0,
|
630 |
+
);
|
631 |
+
$shipping_defaults = array(
|
632 |
+
'local' => '',
|
633 |
+
'international' => '',
|
634 |
+
);
|
635 |
+
$meta = array_merge( $defaults, $meta );
|
636 |
+
$meta['dimensions'] = array_merge( $dimensions_defaults, $meta['dimensions'] );
|
637 |
+
$meta['shipping'] = array_merge( $shipping_defaults, $meta['shipping'] );
|
638 |
+
|
639 |
+
extract( $meta, EXTR_SKIP );
|
640 |
+
|
641 |
+
foreach ( $shipping as $key => &$val ) {
|
642 |
+
$val = wpsc_format_number( $val );
|
643 |
+
}
|
644 |
+
|
645 |
+
$weight = wpsc_convert_weight( $weight, 'pound', $weight_unit );
|
646 |
+
|
647 |
+
$dimension_units = wpsc_dimension_units();
|
648 |
+
$weight_units = wpsc_weight_units();
|
649 |
+
|
650 |
+
// Why we need this????
|
651 |
+
$measurements = $dimensions;
|
652 |
+
$measurements['weight'] = $weight;
|
653 |
+
$measurements['weight_unit'] = $weight_unit;
|
654 |
+
// End why
|
655 |
|
656 |
?>
|
657 |
+
<div class="wpsc-stock-editor<?php if ( $bulk ) echo ' wpsc-bulk-edit' ?>">
|
658 |
+
<p class="wpsc-form-field">
|
659 |
+
<input type="checkbox" id="wpsc-product-no-shipping" name="<?php echo esc_attr( $field_name_prefix ); ?>[no_shipping]" value="1" <?php checked( $no_shipping && ! $bulk ); ?>>
|
660 |
+
<label for="wpsc-product-no-shipping"><?php _e( 'Product will <em>not</em> be shipped to customer', 'wpsc' ); ?></label>
|
661 |
+
</p>
|
662 |
+
|
663 |
+
<div class="wpsc-product-shipping-section wpsc-product-shipping-weight-dimensions">
|
664 |
+
<p><strong><?php esc_html_e( 'Calculate Shipping Costs based on measurements', 'wpsc' ); ?></strong></p>
|
665 |
+
|
666 |
+
<!-- WEIGHT INPUT -->
|
667 |
+
<p class="wpsc-form-field">
|
668 |
+
<?php if ( $bulk ) : ?>
|
669 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][measurements][weight]" value="1" />
|
670 |
+
<?php endif; ?>
|
671 |
+
<label for="wpsc-product-shipping-weight"><?php echo esc_html_e( 'Weight', 'wpsc' ); ?></label>
|
672 |
+
<span class="wpsc-product-shipping-input">
|
673 |
+
<input type="text" id="wpsc-product-shipping-weight" name="<?php echo esc_attr( $field_name_prefix ); ?>[weight]" value="<?php if ( ! $bulk ) echo esc_attr( wpsc_format_number( $weight ) ); ?>" />
|
674 |
+
<select id="wpsc-product-shipping-weight-unit" name="<?php echo $field_name_prefix; ?>[weight_unit]">
|
675 |
+
<?php foreach ( $weight_units as $unit => $unit_label ): ?>
|
676 |
+
<option value="<?php echo esc_attr( $unit ); ?>" <?php if ( ! $bulk ) selected( $unit, $measurements['weight_unit'] ); ?>><?php echo esc_html( $unit_label ); ?></option>
|
677 |
+
<?php endforeach; ?>
|
678 |
+
</select>
|
679 |
+
</span>
|
680 |
+
</p>
|
681 |
+
<!-- END WEIGHT INPUT -->
|
682 |
+
|
683 |
+
<!-- DIMENSIONS INPUT -->
|
684 |
+
<p class="wpsc-form-field">
|
685 |
+
<?php if ( $bulk ) : ?>
|
686 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][measurements][dimensions]" value="1" />
|
687 |
+
<?php endif; ?>
|
688 |
+
<label for="wpsc-product-shipping-weight"><?php echo esc_html_e( 'Dimensions', 'wpsc' ); ?></label>
|
689 |
+
<span class="wpsc-product-shipping-input">
|
690 |
+
<input placeholder="L" type="text" id="wpsc-product-shipping-length" name="<?php echo esc_attr( $field_name_prefix ); ?>[dimensions][length]" value="<?php if ( !$bulk && $dimensions['length']>0 ) echo esc_attr( wpsc_format_number( $dimensions['length'] ) ); ?>" /> ×
|
691 |
+
<input placeholder="W" type="text" id="wpsc-product-shipping-width" name="<?php echo esc_attr( $field_name_prefix ); ?>[dimensions][width]" value="<?php if ( !$bulk && $dimensions['width']>0 ) echo esc_attr( wpsc_format_number( $dimensions['width'] ) ); ?>" /> ×
|
692 |
+
<input placeholder="H" type="text" id="wpsc-product-shipping-height" name="<?php echo esc_attr( $field_name_prefix ); ?>[dimensions][height]" value="<?php if ( !$bulk && $dimensions['height']>0 ) echo esc_attr( wpsc_format_number( $dimensions['height'] ) ); ?>" />
|
693 |
+
<select id="wpsc-product-shipping-dimensions-unit" name="<?php echo $field_name_prefix; ?>[dimension_unit]">
|
694 |
+
<?php foreach ( $dimension_units as $unit => $unit_label ): ?>
|
695 |
+
<option value="<?php echo esc_attr( $unit ); ?>" <?php if ( ! $bulk && isset( $meta['dimension_unit'] ) ) selected( $unit, $meta['dimension_unit'] ); // Dirty code ?>><?php echo esc_html( $unit_label ); ?></option>
|
696 |
+
<?php endforeach; ?>
|
697 |
+
</select>
|
698 |
+
</span>
|
699 |
+
</p>
|
700 |
+
<!-- END DEMENSION INPUT -->
|
701 |
+
|
702 |
+
</div>
|
703 |
+
|
704 |
+
<?php
|
705 |
+
$currency_type = get_option( 'currency_type' );
|
706 |
+
$country = new WPSC_Country( $currency_type );
|
707 |
+
|
708 |
+
$ct_symb = $country->get_currency_symbol_html();
|
709 |
+
?>
|
710 |
+
|
711 |
+
<div class="wpsc-product-shipping-section wpsc-product-shipping-flat-rate">
|
712 |
+
<p><strong><?php esc_html_e( 'Flat Rate Settings', 'wpsc' ); ?></strong></p>
|
713 |
+
<p class="wpsc-form-field">
|
714 |
+
<?php if ( $bulk ): ?>
|
715 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][shipping][local]" value="1" />
|
716 |
+
<?php endif; ?>
|
717 |
+
<label for="wpsc-product-shipping-flatrate-local"><?php esc_html_e( 'Local Shipping Fee', 'wpsc' ); ?></label>
|
718 |
+
<span>
|
719 |
+
<?php echo esc_html( $ct_symb ); ?>
|
720 |
+
<input type="text" id="wpsc-product-shipping-flatrate-local" name="<?php echo esc_html( $field_name_prefix ); ?>[shipping][local]" value="<?php if ( ! $bulk ) echo $shipping['local']; ?>" />
|
721 |
+
</span>
|
722 |
+
</p>
|
723 |
+
<p class="wpsc-form-field">
|
724 |
+
<?php if ( $bulk ): ?>
|
725 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][shipping][international]" value="1" />
|
726 |
+
<?php endif; ?>
|
727 |
+
<label for="wpsc-product-shipping-flatrate-international"><?php esc_html_e( 'International Shipping Fee', 'wpsc' ); ?></label>
|
728 |
+
<span>
|
729 |
+
<?php echo esc_html( $ct_symb ); ?>
|
730 |
+
<input type="text" id="wpsc-product-shipping-flatrate-international" name="<?php echo esc_html( $field_name_prefix ); ?>[shipping][international]" value="<?php if ( ! $bulk ) echo $shipping['international']; ?>" />
|
731 |
+
</span>
|
732 |
+
</p>
|
733 |
+
</div>
|
734 |
+
</div>
|
735 |
+
<?php
|
736 |
+
|
737 |
+
wp_nonce_field( 'update', 'wpsc_product_shipping_nonce' );
|
738 |
+
|
739 |
}
|
740 |
|
741 |
+
/**
|
742 |
+
* Product Custom Metadata Form
|
743 |
+
*
|
744 |
+
* @global $post Instance of WP_Post.
|
745 |
+
* @global $wpdb Instance of wpdb.
|
746 |
+
*/
|
747 |
function wpsc_product_advanced_forms() {
|
748 |
+
|
749 |
+
global $post, $wpdb;
|
750 |
+
|
751 |
+
$delete_nonce = _wpsc_create_ajax_nonce( 'remove_product_meta' );
|
752 |
+
|
753 |
+
$custom_fields = $wpdb->get_results( "
|
754 |
+
SELECT
|
755 |
+
`meta_id`, `meta_key`, `meta_value`
|
756 |
+
FROM
|
757 |
+
`{$wpdb->postmeta}`
|
758 |
+
WHERE
|
759 |
+
`post_id` = {$post->ID}
|
760 |
+
AND
|
761 |
+
`meta_key` NOT LIKE '\_%'
|
762 |
+
ORDER BY
|
763 |
+
LOWER(meta_key)", ARRAY_A
|
764 |
+
);
|
765 |
+
|
766 |
+
$output = '<table id="wpsc_product_meta_table" class="wp-list-table widefat posts">';
|
767 |
+
$output .= '<thead>';
|
768 |
+
$output .= '<tr>';
|
769 |
+
$output .= '<th id="wpsc_custom_meta_name_th">' . _x( 'Name', 'Product meta UI', 'wpsc' ) . '</th>';
|
770 |
+
$output .= '<th id="wpsc_custom_meta_value_th">' . _x( 'Value', 'Product meta UI', 'wpsc' ) . '</th>';
|
771 |
+
$output .= '<th id="wpsc_custom_meta_action_th">' . _x( 'Action', 'Product meta UI', 'wpsc' ) . '</th>';
|
772 |
+
$output .= '</tr>';
|
773 |
+
$output .= '</thead>';
|
774 |
+
$output .= '<tfoot>';
|
775 |
+
$output .= '<tr>';
|
776 |
+
$output .= '<th>' . _x( 'Name', 'Product meta UI', 'wpsc' ) . '</th>';
|
777 |
+
$output .= '<th>' . _x( 'Value', 'Product meta UI', 'wpsc' ) . '</th>';
|
778 |
+
$output .= '<th>' . _x( 'Action', 'Product meta UI', 'wpsc' ) . '</th>';
|
779 |
+
$output .= '</tr>';
|
780 |
+
$output .= '</tfood>';
|
781 |
+
|
782 |
+
$output .= '<tbody>';
|
783 |
+
|
784 |
+
if ( empty( $custom_fields ) ) {
|
785 |
+
$output .= '<tr class="no-meta"><td colspan="3"><p>' . sprintf( __( 'You have no custom metadata. You can set any arbitrary meta you like and access it programatically via the <a href="">Post Meta API</a>.', 'wpsc' ), esc_url( 'https://codex.wordpress.org/Function_Reference/get_post_meta' ) ) . '</p></td></tr>';
|
786 |
+
} else {
|
787 |
+
// Display all available metadata
|
788 |
+
$alternate = false;
|
789 |
+
foreach ( (array) $custom_fields as $custom_field ) {
|
790 |
+
$i = $custom_field['meta_id'];
|
791 |
+
$alternate = ! $alternate;
|
792 |
+
|
793 |
+
$output .= '<tr'. ($alternate ? ' class="alternate"' : '') .'>';
|
794 |
+
$output .= '<td><input type="text" value="'.esc_attr( $custom_field['meta_key'] ).'" name="custom_meta['.$i.'][name]" id="custom_meta_name_'.$i.'"></input></td>';
|
795 |
+
$output .= '<td><input type="text" value="'.esc_attr( $custom_field['meta_value'] ).'" name="custom_meta['.$i.'][value]" id="custom_meta_value_'.$i.'"></input></td>';
|
796 |
+
$output .= '<td><a href="#" data-nonce="'.esc_attr( $delete_nonce ).'" class="wpsc_remove_meta" onclick="wpsc_remove_custom_meta(this,'.$i.')">'.esc_html( 'Delete', 'wpsc' ).'</a></td>';
|
797 |
+
$output .= '</tr>';
|
798 |
+
}
|
799 |
+
}
|
800 |
+
|
801 |
+
// Template for new metadata input
|
802 |
+
$output .= '<tr id="wpsc_new_meta_template">';
|
803 |
+
$output .= '<td><input type="text" name="new_custom_meta[name][]" value=""></input></td>';
|
804 |
+
$output .= '<td><input type="text" name="new_custom_meta[value][]" value=""></input></td>';
|
805 |
+
$output .= '<td><a href="#" class="wpsc_remove_meta" onclick="wpsc_remove_empty_meta(this)">'.esc_html( 'Delete', 'wpsc' ).'</a></td>';
|
806 |
+
$output .= '</tr>';
|
807 |
+
|
808 |
+
$output .= '</tbody>';
|
809 |
+
$output .= '</table>';
|
810 |
+
|
811 |
+
$output .= '<a href="#" class="add_more_meta button button-small" id="wpsc_add_custom_meta">'.esc_html( '+ Add Custom Meta', 'wpsc' ).'</a>';
|
812 |
+
|
813 |
+
echo $output;
|
814 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
815 |
}
|
816 |
|
817 |
/**
|
818 |
* Display Product External Link Meta Box Form Fields.
|
819 |
+
*
|
820 |
+
* @global $post Instance of WP_Post.
|
821 |
*/
|
822 |
function wpsc_product_external_link_forms() {
|
823 |
+
|
824 |
+
global $post;
|
825 |
+
|
826 |
+
// Get External Link Values
|
827 |
+
$product_meta = get_post_meta( $post->ID, '_wpsc_product_metadata', true );
|
828 |
+
$product_meta = wp_parse_args( $product_meta, array(
|
829 |
+
'external_link' => '',
|
830 |
+
'external_link_text' => '',
|
831 |
+
'external_link_target' => ''
|
832 |
+
) );
|
833 |
+
|
834 |
+
?>
|
835 |
+
<table class="form-table" style="width: 100%;" cellspacing="2" cellpadding="5">
|
836 |
+
<tbody>
|
837 |
+
<tr class="form-field">
|
838 |
+
<th valign="top" scope="row"><label for="external_link"><?php esc_html_e( 'URL', 'wpsc' ); ?></label></th>
|
839 |
+
<td><input type="text" name="meta[_wpsc_product_metadata][external_link]" id="external_link" value="<?php echo esc_url( $product_meta['external_link'] ); ?>" size="50" style="width: 95%" placeholder="http://" /></td>
|
840 |
+
</tr>
|
841 |
+
<tr class="form-field">
|
842 |
+
<th valign="top" scope="row"><label for="external_link_text"><?php esc_html_e( 'Label', 'wpsc' ); ?></label></th>
|
843 |
+
<td><input type="text" name="meta[_wpsc_product_metadata][external_link_text]" id="external_link_text" value="<?php echo esc_attr( $product_meta['external_link_text'] ); ?>" size="50" style="width: 95%" placeholder="<?php _e( 'Buy Now', 'wpsc' ); ?>" /></td>
|
844 |
+
</tr>
|
845 |
+
<tr class="form-field">
|
846 |
+
<th valign="top" scope="row"><label for="external_link_target"><?php esc_html_e( 'Target', 'wpsc' ); ?></label></th>
|
847 |
+
<td id="external_link_target">
|
848 |
+
|
849 |
+
<label>
|
850 |
+
<input type="radio" name="meta[_wpsc_product_metadata][external_link_target]" value=""<?php checked( '', $product_meta['external_link_target'] ); ?> />
|
851 |
+
<?php _ex( 'Default (set by theme)', 'External product link target', 'wpsc' ); ?>
|
852 |
+
</label>
|
853 |
+
|
854 |
+
<label>
|
855 |
+
<input type="radio" name="meta[_wpsc_product_metadata][external_link_target]" value="_self"<?php checked( '_self', $product_meta['external_link_target'] ); ?> />
|
856 |
+
<?php esc_html_e( 'Force open in same window', 'wpsc' ); ?>
|
857 |
+
</label>
|
858 |
+
|
859 |
+
<label>
|
860 |
+
<input type="radio" name="meta[_wpsc_product_metadata][external_link_target]" value="_blank"<?php checked( '_blank', $product_meta['external_link_target'] ); ?> />
|
861 |
+
<?php esc_html_e( 'Force open in new window', 'wpsc' ); ?>
|
862 |
+
</label>
|
863 |
+
|
864 |
+
</td>
|
865 |
+
</tr>
|
866 |
+
</tbody>
|
867 |
+
</table>
|
868 |
+
<em><?php esc_html_e( 'This option overrides the "Buy Now" and "Add to Cart" buttons, replacing them with the link you describe here.', 'wpsc' ); ?></em>
|
869 |
+
<?php
|
870 |
+
|
871 |
+
wp_nonce_field( 'update', 'wpsc_product_external_link_nonce' );
|
872 |
+
|
873 |
}
|
874 |
|
875 |
function wpsc_additional_desc() {
|
876 |
?>
|
877 |
+
<textarea name='additional_description' id='additional_description' cols='40' rows='5' ><?php echo esc_textarea( get_post_field( 'post_excerpt', get_the_ID() ) ); ?></textarea>
|
878 |
+
<em><?php _e( 'Short Descriptions are optional hand-crafted summaries of your content that can be used in your theme.', 'wpsc' ); ?></em>
|
879 |
<?php
|
880 |
|
881 |
}
|
888 |
* @return void
|
889 |
*/
|
890 |
function wpsc_product_gallery( $post ) {
|
891 |
+
// pull the old iframe source for non JS users
|
892 |
+
$upload_iframe_src = esc_url( get_upload_iframe_src( 'image', $post->ID ) );
|
893 |
+
// get our gallery image IDs if present
|
894 |
+
$images = wpsc_get_admin_product_gallery( $post->ID );
|
895 |
+
// begin HTML output
|
896 |
+
$output = '<div id="wpsc_product_gallery">';
|
897 |
+
$output .= '<ul>';
|
898 |
+
// check for images before beginngin loop
|
899 |
+
if ( $images ) {
|
900 |
+
// now loop images
|
901 |
+
foreach ( $images as $image_id ) {
|
902 |
+
// get the thumbnail URL
|
903 |
+
$thumb_url = wp_get_attachment_thumb_url( absint( $image_id ) );
|
904 |
+
// output each item
|
905 |
+
$output .= '<li>';
|
906 |
+
$output .= '<img src="' . esc_url( $thumb_url ) . '">';
|
907 |
+
$output .= '<input type="hidden" name="wpsc-product-gallery-imgs[]" value="' . absint( $image_id ) . '">';
|
908 |
+
$output .= '</li>';
|
909 |
+
}
|
910 |
+
}
|
911 |
+
$output .= '</ul>';
|
912 |
+
$output .= '<div class="clear"></div>';
|
913 |
+
$output .= '</div>';
|
914 |
+
// button for old iframe for non JS people
|
915 |
+
$output .= '<p class="hide-if-no-js">';
|
916 |
+
$output .= '<a class="button button-small thickbox" title="' . esc_attr__( 'Manage Product Image Gallery...', 'wpsc' ).'" href="' . $upload_iframe_src . '" id="wpsc-manage-product-gallery">';
|
917 |
+
$output .= esc_html__( 'Manage Product Image Gallery...', 'wpsc' );
|
918 |
+
$output .= '</a>';
|
919 |
+
$output .= '</p>';
|
920 |
+
|
921 |
+
// include a nonce for verification
|
922 |
+
$output .= wp_nonce_field( 'wpec_product_gallery_nonce', 'wpec_product_gallery_nonce', false, false );
|
923 |
+
|
924 |
+
// echo the gallery output
|
925 |
+
echo $output;
|
926 |
}
|
927 |
|
928 |
|
929 |
function wpsc_product_download_forms() {
|
930 |
+
global $post, $wpdb, $wpsc_product_defaults;
|
931 |
+
$product_data = get_post_custom( $post->ID );
|
932 |
+
$output = '';
|
933 |
+
$product_data['meta'] = array();
|
934 |
|
935 |
+
if ( !empty( $product_data['_wpsc_product_metadata'] ) )
|
936 |
+
$product_data['meta'] = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
|
937 |
|
938 |
+
$upload_max = wpsc_get_max_upload_size();
|
939 |
?>
|
940 |
+
<?php echo wpsc_select_product_file( $post->ID ); ?>
|
941 |
|
942 |
+
<a href="admin.php?wpsc_admin_action=product_files_existing&product_id=<?php echo absint( $post->ID ); ?>" class="thickbox button button-small" title="<?php echo esc_attr( sprintf( __( 'Select all downloadable files for %s', 'wpsc' ), $post->post_title ) ); ?>"><?php esc_html_e( 'Add existing files...', 'wpsc' ); ?></a>
|
943 |
|
944 |
+
<div class="wpsc_fileUpload button button-small">
|
945 |
+
<span><?php esc_html_e('Upload new file...','wpsc'); ?></span>
|
946 |
+
<input type='file' name='file' class="button button-small" value='' onchange="wpsc_push_v2t(this, '#wpsc_fileupload_path')" />
|
947 |
+
</div>
|
948 |
+
<em id="wpsc_fileupload_path"></em>
|
949 |
|
950 |
<?php
|
951 |
+
if ( function_exists( "make_mp3_preview" ) || function_exists( "wpsc_media_player" ) ) {
|
952 |
?>
|
953 |
+
<br />
|
954 |
+
<h4><?php esc_html_e( 'Select an MP3 file to upload as a preview', 'wpsc' ) ?></h4>
|
955 |
+
<input type='file' name='preview_file' value='' /><br />
|
956 |
|
957 |
+
<h4><?php esc_html_e( 'Your preview for this product', 'wpsc' ) ?>:</h4>
|
958 |
|
959 |
+
<?php
|
960 |
+
$args = array(
|
961 |
+
'post_type' => 'wpsc-preview-file',
|
962 |
+
'post_parent' => $post->ID,
|
963 |
+
'numberposts' => -1,
|
964 |
+
'post_status' => 'all'
|
965 |
+
);
|
966 |
|
967 |
+
$preview_files = (array) get_posts( $args );
|
968 |
|
969 |
+
foreach ( $preview_files as $preview ) {
|
970 |
+
echo $preview->post_title . '<br />';
|
971 |
+
}
|
972 |
|
973 |
+
?>
|
974 |
+
<br />
|
975 |
+
<?php
|
976 |
+
}
|
977 |
|
978 |
+
$output = apply_filters( 'wpsc_downloads_metabox', $output );
|
979 |
}
|
980 |
|
981 |
+
/**
|
982 |
+
* Product Personalization Form
|
983 |
+
*
|
984 |
+
* @global $post Instance of WP_Post.
|
985 |
+
*/
|
986 |
+
function wpsc_product_personalization_forms() {
|
987 |
+
|
988 |
+
global $post;
|
989 |
+
|
990 |
+
$product_meta = get_post_meta( $post->ID, '_wpsc_product_metadata', true );
|
991 |
+
$product_meta = wp_parse_args( $product_meta, array(
|
992 |
+
'engraved' => 0,
|
993 |
+
'can_have_uploaded_image' => 0
|
994 |
+
) );
|
995 |
+
|
996 |
+
?>
|
997 |
+
<ul id="wpsc_product_personalization_option">
|
998 |
+
<li>
|
999 |
+
<input type="checkbox" name="meta[_wpsc_product_metadata][engraved]" <?php checked( $product_meta['engraved'], '1' ); ?> id="add_engrave_text" />
|
1000 |
+
<label for="add_engrave_text"><?php esc_html_e( 'Users can personalize this product by leaving a message on single product page', 'wpsc' ); ?></label>
|
1001 |
+
</li>
|
1002 |
+
<li>
|
1003 |
+
<input type="checkbox" name="meta[_wpsc_product_metadata][can_have_uploaded_image]" <?php checked( $product_meta['can_have_uploaded_image'], '1' ); ?> id="can_have_uploaded_image" />
|
1004 |
+
<label for="can_have_uploaded_image"> <?php esc_html_e( 'Users can upload images on single product page to purchase logs.', 'wpsc' ); ?></label>
|
1005 |
+
</li>
|
1006 |
+
<?php do_action( 'wpsc_add_advanced_options', $post->ID ); ?>
|
1007 |
+
</ul>
|
1008 |
+
<em><?php _e( "Form fields for the customer to personalize this product will be shown on it's single product page.", 'wpsc' ); ?></em>
|
1009 |
+
<?php
|
1010 |
+
|
1011 |
+
wp_nonce_field( 'update', 'wpsc_product_personalization_nonce' );
|
1012 |
+
|
1013 |
}
|
1014 |
|
1015 |
function wpsc_product_delivery_forms(){
|
1016 |
+
$has_variations = wpsc_product_has_variations( get_post()->ID );
|
1017 |
|
1018 |
+
$show_if_variation = $has_variations ? 'display: block;' : 'display:none;';
|
1019 |
?>
|
1020 |
+
<em id="wpsc_product_delivery_metabox_live_title" class="wpsc_metabox_live_title">
|
1021 |
+
<p></p>
|
1022 |
+
</em>
|
1023 |
+
|
1024 |
+
<div id="wpsc_product_delivery_forms" class="categorydiv wpsc-categorydiv">
|
1025 |
+
<ul id="wpsc_product_delivery_tabs" class="category-tabs">
|
1026 |
+
<li class="tabs"><a href="#wpsc_product_delivery-shipping"><?php _e( 'Shipping', 'wpsc' ); ?></a></li>
|
1027 |
+
<li><a href="#wpsc_product_delivery-download"><?php _e( 'Download', 'wpsc' ); ?></a></li>
|
1028 |
+
<li><a href="#wpsc_product_delivery-external_link"><?php _e( 'External Link', 'wpsc' ); ?></a></li>
|
1029 |
+
</ul>
|
1030 |
+
|
1031 |
+
<div id="wpsc_product_delivery-shipping" class="tabs-panel" style="display:block;">
|
1032 |
+
<?php
|
1033 |
+
if ( ! $has_variations ) {
|
1034 |
+
wpsc_product_shipping_forms();
|
1035 |
+
} else {
|
1036 |
+
echo '<p>' . sprintf( __( 'This product has variations. To edit the shipping, please use the <a href="%s">Variation Controls</a>.', 'wpsc' ), '#wpsc_product_variation_forms' ) . '</p>';
|
1037 |
+
}
|
1038 |
+
?>
|
1039 |
+
</div>
|
1040 |
+
|
1041 |
+
<div id="wpsc_product_delivery-download" class="tabs-panel" style="display:none;">
|
1042 |
+
<?php wpsc_product_download_forms(); ?>
|
1043 |
+
</div>
|
1044 |
+
|
1045 |
+
<div id="wpsc_product_delivery-external_link" class="tabs-panel" style="display: none;">
|
1046 |
+
<?php wpsc_product_external_link_forms(); ?>
|
1047 |
+
</div>
|
1048 |
+
</div>
|
1049 |
<?php
|
1050 |
}
|
1051 |
|
1052 |
function wpsc_product_details_forms(){
|
1053 |
?>
|
1054 |
+
<em id="wpsc_product_details_metabox_live_title" class="wpsc_metabox_live_title">
|
1055 |
+
<p></p>
|
1056 |
+
</em>
|
1057 |
+
|
1058 |
+
<div id="wpsc_product_details_forms" class="categorydiv wpsc-categorydiv">
|
1059 |
+
<ul id="wpsc_product_details_tabs" class="category-tabs">
|
1060 |
+
<li class="tabs"><a href="#wpsc_product_details-image"><?php _e( 'Image Gallery', 'wpsc' ); ?></a></li>
|
1061 |
+
<li><a href="#wpsc_product_details-desc"><?php _e( 'Short Description', 'wpsc' ); ?></a></li>
|
1062 |
+
<li><a href="#wpsc_product_details-personalization"><?php _e( 'Personalization', 'wpsc' ); ?></a></li>
|
1063 |
+
<li><a href="#wpsc_product_details-meta"><?php _e( 'Metadata', 'wpsc' ); ?></a></li>
|
1064 |
+
</ul>
|
1065 |
+
|
1066 |
+
<div id="wpsc_product_details-image" class="tabs-panel" style="display: block;">
|
1067 |
+
<?php wpsc_product_gallery( get_post() ); ?>
|
1068 |
+
</div>
|
1069 |
+
|
1070 |
+
<div id="wpsc_product_details-desc" class="tabs-panel" style="display: none;">
|
1071 |
+
<?php wpsc_additional_desc(); ?>
|
1072 |
+
</div>
|
1073 |
+
|
1074 |
+
<div id="wpsc_product_details-personalization" class="tabs-panel" style="display: none;">
|
1075 |
+
<?php wpsc_product_personalization_forms(); ?>
|
1076 |
+
</div>
|
1077 |
+
|
1078 |
+
<div id="wpsc_product_details-meta" class="tabs-panel" style="display: none;">
|
1079 |
+
<?php wpsc_product_advanced_forms(); ?>
|
1080 |
+
</div>
|
1081 |
+
</div>
|
1082 |
<?php
|
1083 |
}
|
1084 |
|
1085 |
function wpsc_form_multipart_encoding() {
|
1086 |
+
echo ' enctype="multipart/form-data"';
|
1087 |
}
|
1088 |
|
1089 |
add_action( 'post_edit_form_tag', 'wpsc_form_multipart_encoding' );
|
1107 |
*/
|
1108 |
function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
|
1109 |
|
1110 |
+
if ( 'Taxonomy Parent' == $context && 'Parent' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ) {
|
1111 |
+
$translations = get_translations_for_domain( $domain );
|
1112 |
+
return $translations->translate( 'Variation Set', 'wpsc' );
|
1113 |
+
//this will never happen, this is here only for gettext to pick up the translation
|
1114 |
+
return __( 'Variation Set', 'wpsc' );
|
1115 |
+
}
|
1116 |
+
return $translation;
|
1117 |
}
|
1118 |
|
1119 |
function wpsc_attachment_fields( $form_fields, $post ) {
|
1120 |
+
$out = '';
|
1121 |
|
1122 |
+
if( isset( $_REQUEST["post_id"] ) )
|
1123 |
+
$parent_post = get_post( absint( $_REQUEST["post_id"] ) );
|
1124 |
+
else
|
1125 |
+
$parent_post = get_post( $post->post_parent );
|
1126 |
|
1127 |
+
// check if post is set before accessing
|
1128 |
+
if ( isset( $parent_post ) && $parent_post->post_type == "wpsc-product" ) {
|
1129 |
|
1130 |
+
//Unfortunate hack, as I'm not sure why the From Computer tab doesn't process filters the same way the Gallery does
|
1131 |
+
ob_start();
|
1132 |
+
echo '
|
1133 |
<script type="text/javascript">
|
1134 |
|
1135 |
+
jQuery(function(){
|
1136 |
|
1137 |
+
jQuery("a.wp-post-thumbnail").each(function(){
|
1138 |
+
var product_image = jQuery(this).text();
|
1139 |
+
if (product_image == "' . esc_js( __( 'Use as featured image' ) ) . '") {
|
1140 |
+
jQuery(this).text("' . esc_js( __('Use as Product Thumbnail', 'wpsc') ) . '");
|
1141 |
+
}
|
1142 |
+
});
|
1143 |
|
1144 |
+
var trash = jQuery("#media-upload a.del-link").text();
|
1145 |
|
1146 |
+
if (trash == "' . esc_js( __( 'Delete' ) ) . '") {
|
1147 |
+
jQuery("#media-upload a.del-link").text("' . esc_js( __( 'Trash' ) ) . '");
|
1148 |
+
}
|
1149 |
|
1150 |
|
1151 |
+
});
|
1152 |
|
1153 |
</script>';
|
1154 |
+
$out .= ob_get_clean();
|
1155 |
|
1156 |
+
$size_names = array( 'small-product-thumbnail' => __( 'Default Product Thumbnail Size', 'wpsc' ), 'medium-single-product' => __( 'Single Product Image Size', 'wpsc' ), 'full' => __( 'Full Size', 'wpsc' ) );
|
1157 |
|
1158 |
+
$check = get_post_meta( $post->ID, '_wpsc_selected_image_size', true );
|
1159 |
+
if ( !$check )
|
1160 |
+
$check = 'medium-single-product';
|
1161 |
|
1162 |
+
$current_size = image_get_intermediate_size( $post->ID, $check );
|
1163 |
+
$settings_width = get_option( 'single_view_image_width' );
|
1164 |
+
$settings_height = get_option( 'single_view_image_height' );
|
1165 |
|
1166 |
+
// regenerate size metadata in case it's missing
|
1167 |
+
if ( ! $check || ( $current_size['width'] != $settings_width && $current_size['height'] != $settings_height ) ) {
|
1168 |
+
_wpsc_regenerate_thumbnail_size( $post->ID, $check );
|
1169 |
+
}
|
1170 |
|
1171 |
+
//This loop attaches the custom thumbnail/single image sizes to this page
|
1172 |
+
foreach ( $size_names as $size => $name ) {
|
1173 |
+
$downsize = image_downsize( $post->ID, $size );
|
1174 |
+
// is this size selectable?
|
1175 |
+
$enabled = ( $downsize[3] || 'full' == $size );
|
1176 |
+
$css_id = "image-size-{$size}-{$post->ID}";
|
1177 |
+
// if this size is the default but that's not available, don't select it
|
1178 |
|
1179 |
+
$html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][wpsc_image_size]' id='{$css_id}' value='{$size}' " . checked( $size, $check, false ) . " />";
|
1180 |
|
1181 |
+
$html .= "<label for='{$css_id}'>$name</label>";
|
1182 |
+
// only show the dimensions if that choice is available
|
1183 |
+
if ( $enabled )
|
1184 |
+
$html .= " <label for='{$css_id}' class='help'>" . sprintf( __( "(%d × %d)", 'wpsc' ), $downsize[1], $downsize[2] ). "</label>";
|
1185 |
|
1186 |
+
$html .= '</div>';
|
1187 |
|
1188 |
+
$out .= $html;
|
1189 |
+
}
|
1190 |
|
1191 |
+
unset( $form_fields['post_excerpt'], $form_fields['image_url'], $form_fields['post_content'], $form_fields['post_title'], $form_fields['url'], $form_fields['align'], $form_fields['image_alt']['helps'], $form_fields["image-size"] );
|
1192 |
+
$form_fields['image_alt']['helps'] = __( 'Alt text for the product image, e.g. “Rockstar T-Shirt”', 'wpsc' );
|
1193 |
|
1194 |
+
$form_fields["wpsc_image_size"] = array(
|
1195 |
+
'label' => __( 'Single Product Page Thumbnail:', 'wpsc' ),
|
1196 |
+
'input' => 'html',
|
1197 |
+
'html' => $out,
|
1198 |
+
'helps' => "<span style='text-align:left; clear:both; display:block; padding-top:3px;'>" . __( 'This is the Thumbnail size that will be displayed on the Single Product page. You can change the default sizes under your store settings', 'wpsc' ) . "</span>"
|
1199 |
+
);
|
1200 |
|
1201 |
+
//This is for the custom thumbnail size.
|
1202 |
|
1203 |
+
$custom_thumb_size_w = get_post_meta( $post->ID, "_wpsc_custom_thumb_w", true );
|
1204 |
+
$custom_thumb_size_h = get_post_meta( $post->ID, "_wpsc_custom_thumb_h", true );
|
1205 |
+
$custom_thumb_html = "
|
1206 |
|
1207 |
+
<input style='width:50px; text-align:center' type='text' name='attachments[{$post->ID}][wpsc_custom_thumb_w]' value='{$custom_thumb_size_w}' /> X <input style='width:50px; text-align:center' type='text' name='attachments[{$post->ID}][wpsc_custom_thumb_h]' value='{$custom_thumb_size_h}' />
|
1208 |
|
1209 |
+
";
|
1210 |
+
$form_fields["wpsc_custom_thumb"] = array(
|
1211 |
+
"label" => __( 'Products Page Thumbnail Size:', 'wpsc' ),
|
1212 |
+
"input" => "html", // this is default if "input" is omitted
|
1213 |
+
"helps" => "<span style='text-align:left; clear:both; display:block; padding-top:3px;'>" . __( 'Custom thumbnail size for this image on the main Product Page', 'wpsc') . "</span>",
|
1214 |
+
"html" => $custom_thumb_html
|
1215 |
+
);
|
1216 |
+
}
|
1217 |
+
return $form_fields;
|
1218 |
|
1219 |
}
|
1220 |
function wpsc_save_attachment_fields( $post, $attachment ) {
|
1221 |
|
1222 |
+
if ( isset( $attachment['wpsc_custom_thumb_w'] ) ) {
|
1223 |
+
update_post_meta( $post['ID'], '_wpsc_custom_thumb_w', $attachment['wpsc_custom_thumb_w'] );
|
1224 |
+
}
|
1225 |
|
1226 |
+
if ( isset( $attachment['wpsc_custom_thumb_h'] ) ) {
|
1227 |
+
update_post_meta( $post['ID'], '_wpsc_custom_thumb_h', $attachment['wpsc_custom_thumb_h'] );
|
1228 |
+
}
|
1229 |
|
1230 |
+
if ( isset( $attachment['wpsc_image_size'] ) ) {
|
1231 |
+
update_post_meta( $post['ID'], '_wpsc_selected_image_size', $attachment['wpsc_image_size'] );
|
1232 |
+
}
|
1233 |
|
1234 |
+
return $post;
|
1235 |
}
|
1236 |
|
1237 |
/**
|
1245 |
*/
|
1246 |
|
1247 |
function wpsc_save_quickedit_box( $post_id ) {
|
1248 |
+
global $doaction;
|
1249 |
+
|
1250 |
+
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || get_post_type( $post_id ) != 'wpsc-product' )
|
1251 |
+
return;
|
1252 |
+
|
1253 |
+
$bulk = isset( $doaction ) && $doaction =='edit';
|
1254 |
+
|
1255 |
+
$custom_fields = array(
|
1256 |
+
'weight' => 'product_metadata',
|
1257 |
+
'stock' => 'stock',
|
1258 |
+
'price' => 'price',
|
1259 |
+
'sale_price' => 'special_price',
|
1260 |
+
'sku' => 'sku',
|
1261 |
+
);
|
1262 |
+
|
1263 |
+
$args = array(
|
1264 |
+
'post_parent' => $post_id,
|
1265 |
+
'post_type' => 'wpsc-product',
|
1266 |
+
'post_status' => 'inherit'
|
1267 |
+
);
|
1268 |
+
$children = get_children($args);
|
1269 |
+
$is_parent = (bool)$children;
|
1270 |
+
foreach ( $custom_fields as $post_key => $meta_key ) {
|
1271 |
+
$overideVariant = isset($_REQUEST[$post_key.'_variant']) && $_REQUEST[$post_key.'_variant'] == 'on';
|
1272 |
+
// don't update if we're bulk updating and the field is left blank, or if the product has children and the field is one of those fields defined below (unles overridden)
|
1273 |
+
if ( ! isset( $_REQUEST[$post_key] ) || ( $bulk && empty( $_REQUEST[$post_key] ) ) ||
|
1274 |
+
( $is_parent && in_array( $post_key, array( 'weight', 'stock', 'price', 'special_price' )) && !$overideVariant ) ){
|
1275 |
+
continue;
|
1276 |
+
}
|
1277 |
+
|
1278 |
+
if($is_parent && count($children) >0){
|
1279 |
+
$products = $children;
|
1280 |
+
}else{
|
1281 |
+
$products = array($post_id);
|
1282 |
+
}
|
1283 |
+
|
1284 |
+
foreach($products as $product){
|
1285 |
+
$value = $_REQUEST[$post_key];
|
1286 |
+
if($is_parent) $post_id = $product->ID;
|
1287 |
+
else $post_id = $product;
|
1288 |
+
switch ( $post_key ) {
|
1289 |
+
case 'weight':
|
1290 |
+
$product_meta = get_post_meta( $post_id, '_wpsc_product_metadata', true );
|
1291 |
+
if ( ! is_array( $product_meta ) )
|
1292 |
+
$product_meta = array();
|
1293 |
+
// draft products don't have product metadata set yet
|
1294 |
+
$weight_unit = isset( $product_meta["weight_unit"] ) ? $product_meta["weight_unit"] : 'pound';
|
1295 |
+
$weight = wpsc_convert_weight( $value, $weight_unit, "pound", true );
|
1296 |
+
|
1297 |
+
if ( isset( $product_meta["weight"] ) )
|
1298 |
+
unset( $product_meta["weight"] );
|
1299 |
+
|
1300 |
+
$product_meta["weight"] = $weight;
|
1301 |
+
|
1302 |
+
$value = $product_meta;
|
1303 |
+
break;
|
1304 |
+
|
1305 |
+
case 'stock':
|
1306 |
+
if ( ! is_numeric( $value ) )
|
1307 |
+
$value = '';
|
1308 |
+
break;
|
1309 |
+
|
1310 |
+
case 'sku':
|
1311 |
+
if ( $value == __( 'N/A', 'wpsc' ) )
|
1312 |
+
$value = '';
|
1313 |
+
break;
|
1314 |
+
}
|
1315 |
+
|
1316 |
+
update_post_meta( $post_id, "_wpsc_{$meta_key}", $value );
|
1317 |
+
}
|
1318 |
+
}
|
1319 |
+
|
1320 |
+
return $post_id;
|
1321 |
}
|
1322 |
|
1323 |
/**
|
1330 |
*/
|
1331 |
|
1332 |
function wpsc_quick_edit_boxes( $col_name, $_screen_post_type = null ) {
|
1333 |
+
// Avoid outputting this on term edit screens.
|
1334 |
+
// See http://core.trac.wordpress.org/ticket/16392#comment:9
|
1335 |
+
if ( current_filter() == 'quick_edit_custom_box' && $_screen_post_type == 'edit-tags' )
|
1336 |
+
return;
|
1337 |
?>
|
1338 |
|
1339 |
<fieldset class="inline-edit-col-left wpsc-cols">
|
1340 |
+
<div class="inline-edit-col">
|
1341 |
+
<div class="inline-edit-group">
|
1342 |
<?php
|
1343 |
+
switch ( $col_name ) :
|
1344 |
+
case 'SKU' :
|
1345 |
?>
|
1346 |
+
<label style="max-width: 85%" class="alignleft">
|
1347 |
+
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'SKU:', 'wpsc' ); ?> </span>
|
1348 |
+
<input type="text" name="sku" class="wpsc_ie_sku" />
|
1349 |
+
<input type="checkbox" name="sku_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1350 |
+
|
1351 |
+
</label>
|
1352 |
+
<?php
|
1353 |
+
break;
|
1354 |
case 'weight' :
|
1355 |
?>
|
1356 |
+
<label style="max-width: 85%" class="alignleft">
|
1357 |
+
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Weight:', 'wpsc' ); ?> </span>
|
1358 |
+
<input type="text" name="weight" class="wpsc_ie_weight" />
|
1359 |
+
<input type="checkbox" name="weight_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1360 |
+
</label>
|
1361 |
+
<?php
|
1362 |
+
break;
|
1363 |
case 'stock' :
|
1364 |
?>
|
1365 |
+
<label style="max-width: 85%" class="alignleft">
|
1366 |
+
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Stock:', 'wpsc' ); ?> </span>
|
1367 |
+
<input type="text" name="stock" class="wpsc_ie_stock" />
|
1368 |
+
<input type="checkbox" name="stock_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1369 |
+
</label>
|
1370 |
+
<?php
|
1371 |
+
break;
|
1372 |
case 'price' :
|
1373 |
?>
|
1374 |
+
<label style="max-width: 85%" class="alignleft">
|
1375 |
+
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Price:', 'wpsc' ); ?> </span>
|
1376 |
+
<input type="text" name="price" class="wpsc_ie_price" />
|
1377 |
+
<input type="checkbox" name="price_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1378 |
+
</label>
|
1379 |
+
<?php
|
1380 |
+
break;
|
1381 |
case 'sale_price' :
|
1382 |
?>
|
1383 |
+
<label style="max-width: 85%" class="alignleft">
|
1384 |
+
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Sale Price:', 'wpsc' ); ?> </span>
|
1385 |
+
<input type="text" name="sale_price" class="wpsc_ie_sale_price" />
|
1386 |
+
<input type="checkbox" name="sale_price_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1387 |
+
</label>
|
1388 |
+
<?php
|
1389 |
+
break;
|
1390 |
+
endswitch;
|
1391 |
?>
|
1392 |
+
</div>
|
1393 |
+
</div>
|
1394 |
</fieldset>
|
1395 |
<?php
|
1396 |
}
|
1406 |
* @param <type> $variation
|
1407 |
*/
|
1408 |
function variation_price_field( $variation ) {
|
1409 |
+
$term_prices = get_option( 'term_prices' );
|
1410 |
+
|
1411 |
+
if ( is_object( $variation ) )
|
1412 |
+
$term_id = $variation->term_id;
|
1413 |
+
|
1414 |
+
if ( empty( $term_prices ) || !is_array( $term_prices ) ) {
|
1415 |
+
|
1416 |
+
$term_prices = array( );
|
1417 |
+
if ( isset( $term_id ) ) {
|
1418 |
+
$term_prices[$term_id] = array( );
|
1419 |
+
$term_prices[$term_id]["price"] = '';
|
1420 |
+
$term_prices[$term_id]["checked"] = '';
|
1421 |
+
}
|
1422 |
+
add_option( 'term_prices', $term_prices );
|
1423 |
+
}
|
1424 |
+
|
1425 |
+
if ( isset( $term_id ) && is_array( $term_prices ) && array_key_exists( $term_id, $term_prices ) )
|
1426 |
+
$price = esc_attr( $term_prices[$term_id]["price"] );
|
1427 |
+
else
|
1428 |
+
$price = '';
|
1429 |
+
|
1430 |
+
if( !isset( $_GET['action'] ) ) {
|
1431 |
+
?>
|
1432 |
+
<div class="form-field">
|
1433 |
+
<label for="variation_price"><?php esc_html_e( 'Variation Price', 'wpsc' ); ?></label>
|
1434 |
+
<input type="text" name="variation_price" id="variation_price" style="width:50px;" value="<?php echo $price; ?>"><br />
|
1435 |
+
<span class="description"><?php esc_html_e( 'You can list a default price here for this variation. You can list a regular price (18.99), differential price (+1.99 / -2) or even a percentage-based price (+50% / -25%).', 'wpsc' ); ?></span>
|
1436 |
+
</div>
|
1437 |
+
<script type="text/javascript">
|
1438 |
+
jQuery('#parent option:contains(" ")').remove();
|
1439 |
+
jQuery('#parent').mousedown(function(){
|
1440 |
+
jQuery('#parent option:contains(" ")').remove();
|
1441 |
+
});
|
1442 |
+
</script>
|
1443 |
+
<?php
|
1444 |
+
} else{
|
1445 |
+
?>
|
1446 |
+
<tr class="form-field">
|
1447 |
+
<th scope="row" valign="top">
|
1448 |
+
<label for="variation_price"><?php esc_html_e( 'Variation Price', 'wpsc' ); ?></label>
|
1449 |
+
</th>
|
1450 |
+
<td>
|
1451 |
+
<input type="text" name="variation_price" id="variation_price" style="width:50px;" value="<?php echo $price; ?>"><br />
|
1452 |
+
<span class="description"><?php esc_html_e( 'You can list a default price here for this variation. You can list a regular price (18.99), differential price (+1.99 / -2) or even a percentage-based price (+50% / -25%).', 'wpsc' ); ?></span>
|
1453 |
+
</td>
|
1454 |
+
</tr>
|
1455 |
+
<?php
|
1456 |
+
}
|
1457 |
}
|
1458 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field' );
|
1459 |
add_action( 'wpsc-variation_add_form_fields', 'variation_price_field' );
|
1464 |
*/
|
1465 |
function variation_set_field(){
|
1466 |
?>
|
1467 |
+
<script>
|
1468 |
+
/* change the text on the variation set from (none) to new variation set*/
|
1469 |
+
jQuery("#parent option[value='-1']").text("New Variation Set");
|
1470 |
+
/* Move to the top of the form and add a description */
|
1471 |
+
jQuery("#tag-name").parent().before( jQuery("#parent").parent().append('<p>Choose the Variation Set you want to add variants to. If your\'e creating a new variation set then select "New Variation Set"</p>') );
|
1472 |
+
/*
|
1473 |
+
create a small description about variations below the add variation / set title
|
1474 |
+
we can then get rid of the big red danger warning
|
1475 |
+
*/
|
1476 |
+
( jQuery("div#ajax-response").after('<p>Variations allow you to create options for your products, for example if you\'re selling T-Shirts they will have a size option you can create this as a variation. Size will be the Variation Set name, and it will be a "New Variant Set". You will then create variants (small, medium, large) which will have the "Variation Set" of Size. Once you have made your set you can use the table on the right to manage them (edit, delete). You will be able to order your variants by draging and droping them within their Variation Set.</p>') );
|
1477 |
+
</script>
|
1478 |
<?php
|
1479 |
}
|
1480 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_set_field' );
|
1483 |
|
1484 |
function category_edit_form(){
|
1485 |
?>
|
1486 |
+
<script type="text/javascript">
|
1487 |
|
1488 |
+
</script>
|
1489 |
<?php
|
1490 |
}
|
1491 |
|
1492 |
function variation_price_field_check( $variation ) {
|
1493 |
|
1494 |
+
$term_prices = get_option( 'term_prices' );
|
1495 |
|
1496 |
+
if ( is_array( $term_prices ) && array_key_exists( $variation->term_id, $term_prices ) )
|
1497 |
+
$checked = ($term_prices[$variation->term_id]["checked"] == 'checked') ? 'checked' : '';
|
1498 |
+
else
|
1499 |
+
$checked = ''; ?>
|
1500 |
|
1501 |
+
<tr class="form-field">
|
1502 |
+
<th scope="row" valign="top"><label for="apply_to_current"><?php esc_html_e( 'Apply to current variations?', 'wpsc' ) ?></label></th>
|
1503 |
+
<td>
|
1504 |
+
<span class="description"><input type="checkbox" name="apply_to_current" id="apply_to_current" style="width:2%;" <?php echo $checked; ?> /><?php _e( 'By checking this box, the price rule you implement above will be applied to all variations that currently exist. If you leave it unchecked, it will only apply to products that use this variation created or edited from now on. Take note, this will apply this rule to <strong>every</strong> product using this variation. If you need to override it for any reason on a specific product, simply go to that product and change the price.', 'wpsc' ); ?></span>
|
1505 |
+
</td>
|
1506 |
+
</tr>
|
1507 |
<?php
|
1508 |
}
|
1509 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field_check' );
|
1517 |
* @param <type> $term_id
|
1518 |
*/
|
1519 |
function save_term_prices( $term_id ) {
|
1520 |
+
// First - Saves options from input
|
1521 |
+
if ( isset( $_POST['variation_price'] ) || isset( $_POST["apply_to_current"] ) ) {
|
1522 |
|
1523 |
+
$term_prices = get_option( 'term_prices' );
|
1524 |
|
1525 |
+
$term_prices[$term_id]["price"] = $_POST["variation_price"];
|
1526 |
+
$term_prices[$term_id]["checked"] = (isset( $_POST["apply_to_current"] )) ? "checked" : "unchecked";
|
1527 |
|
1528 |
+
update_option( 'term_prices', $term_prices );
|
1529 |
+
}
|
1530 |
|
1531 |
+
// Second - If box was checked, let's then check whether or not it was flat, differential, or percentile, then let's apply the pricing to every product appropriately
|
1532 |
+
if ( isset( $_POST["apply_to_current"] ) ) {
|
1533 |
|
1534 |
+
//Now, find all products with this term_id, update their pricing structure (terms returned include only parents at this point, we'll grab relevent children soon)
|
1535 |
+
$products_to_mod = get_objects_in_term( $term_id, "wpsc-variation" );
|
1536 |
+
$product_parents = array( );
|
1537 |
|
1538 |
+
foreach ( (array)$products_to_mod as $get_parent ) {
|
1539 |
|
1540 |
+
$post = get_post( $get_parent );
|
1541 |
|
1542 |
+
if ( !$post->post_parent )
|
1543 |
+
$product_parents[] = $post->ID;
|
1544 |
+
}
|
1545 |
|
1546 |
+
//Now that we have all parent IDs with this term, we can get the children (only the ones that are also in $products_to_mod, we don't want to apply pricing to ALL kids)
|
1547 |
|
1548 |
+
foreach ( $product_parents as $parent ) {
|
1549 |
+
$args = array(
|
1550 |
+
'post_parent' => $parent,
|
1551 |
+
'post_type' => 'wpsc-product'
|
1552 |
+
);
|
1553 |
+
$children = get_children( $args, ARRAY_A );
|
1554 |
|
1555 |
+
foreach ( $children as $childrens ) {
|
1556 |
+
$parent = $childrens["post_parent"];
|
1557 |
+
$children_ids[$parent][] = $childrens["ID"];
|
1558 |
+
$children_ids[$parent] = array_intersect( $children_ids[$parent], $products_to_mod );
|
1559 |
+
}
|
1560 |
+
}
|
1561 |
|
1562 |
+
//Got the right kids, let's grab their parent pricing and modify their pricing based on var_price_type
|
1563 |
|
1564 |
+
foreach ( (array)$children_ids as $parents => $kids ) {
|
1565 |
|
1566 |
+
$kids = array_values( $kids );
|
1567 |
|
1568 |
+
foreach ( $kids as $kiddos ) {
|
1569 |
+
$price = wpsc_determine_variation_price( $kiddos );
|
1570 |
+
update_product_meta( $kiddos, 'price', $price );
|
1571 |
+
}
|
1572 |
+
}
|
1573 |
+
}
|
1574 |
}
|
1575 |
add_action( 'edited_wpsc-variation', 'save_term_prices' );
|
1576 |
add_action( 'created_wpsc-variation', 'save_term_prices' );
|
1577 |
|
1578 |
function wpsc_delete_variations( $postid ) {
|
1579 |
+
$post = get_post( $postid );
|
1580 |
+
if ( $post->post_type != 'wpsc-product' || $post->post_parent != 0 )
|
1581 |
+
return;
|
1582 |
+
$variations = get_posts( array(
|
1583 |
+
'post_type' => 'wpsc-product',
|
1584 |
+
'post_parent' => $postid,
|
1585 |
+
'post_status' => 'any',
|
1586 |
+
'numberposts' => -1,
|
1587 |
+
) );
|
1588 |
+
|
1589 |
+
if ( ! empty( $variations ) )
|
1590 |
+
foreach ( $variations as $variation ) {
|
1591 |
+
wp_delete_post( $variation->ID, true );
|
1592 |
+
}
|
1593 |
}
|
1594 |
add_action( 'before_delete_post', 'wpsc_delete_variations' );
|
1595 |
|
1607 |
*/
|
1608 |
function wpsc_get_admin_product_gallery( $product_id = 0 ) {
|
1609 |
|
1610 |
+
// grab our meta from the DB
|
1611 |
+
$gallery = get_post_meta( $product_id, '_wpsc_product_gallery', true );
|
1612 |
+
|
1613 |
+
// no custom gallery was created, so return nothing
|
1614 |
+
if ( ! $gallery ) {
|
1615 |
+
return;
|
1616 |
+
}
|
1617 |
+
|
1618 |
+
// now make sure the IDs present are actual attachments
|
1619 |
+
// by looping and unsetting them
|
1620 |
+
//
|
1621 |
+
// may want to add a MIME type check here, but not sure
|
1622 |
+
// if that would cause issues if people use non-images
|
1623 |
+
// in their galleries
|
1624 |
+
foreach( $gallery as $key => $image_id ) {
|
1625 |
+
if ( get_post_type( $image_id ) !== 'attachment' ) {
|
1626 |
+
unset( $gallery[$key] );
|
1627 |
+
}
|
1628 |
+
}
|
1629 |
+
|
1630 |
+
// somehow everything in the gallery
|
1631 |
+
// was not an attachment, so bail
|
1632 |
+
if ( empty( $gallery ) ) {
|
1633 |
+
return;
|
1634 |
+
}
|
1635 |
+
|
1636 |
+
// send it back
|
1637 |
+
return $gallery;
|
1638 |
|
1639 |
}
|
1640 |
|
1647 |
*/
|
1648 |
function wpsc_new_gallery_save( $product_id = 0 ) {
|
1649 |
|
1650 |
+
// do our nonce check. ALWAYS A NONCE CHECK
|
1651 |
+
if ( ! isset( $_POST['wpsc_product_gallery_nonce'] ) || ! wp_verify_nonce( $_POST['wpsc_product_gallery_nonce'], 'wpsc_product_gallery_nonce' ) ) {
|
1652 |
+
return $product_id;
|
1653 |
+
}
|
1654 |
+
|
1655 |
+
// set an empty array for the image IDs
|
1656 |
+
$image_ids = array();
|
1657 |
+
|
1658 |
+
// ok. we have image IDs to work with. do some filtering
|
1659 |
+
if ( ! empty( $_POST['wpsc-product-gallery-imgs'] ) ) {
|
1660 |
+
// make sure our IDs are set to an array
|
1661 |
+
$image_ids = (array) $_POST['wpsc-product-gallery-imgs'];
|
1662 |
+
// ensure nothing non-numeric got added in
|
1663 |
+
$image_ids = wp_parse_id_list( $image_ids );
|
1664 |
+
// filter out any empty items
|
1665 |
+
$image_ids = array_filter( $image_ids );
|
1666 |
+
}
|
1667 |
+
|
1668 |
+
// now if we have image IDs left after filtering, save them
|
1669 |
+
// if not, delete the meta key
|
1670 |
+
if ( ! empty( $image_ids ) ) {
|
1671 |
+
update_post_meta( $product_id, '_wpsc_product_gallery', $image_ids );
|
1672 |
+
} else {
|
1673 |
+
delete_post_meta( $product_id, '_wpsc_product_gallery' );
|
1674 |
+
}
|
1675 |
+
|
1676 |
+
// add an action for after the gallery being saved
|
1677 |
+
// passing the post ID and the image IDs
|
1678 |
+
do_action( 'wpsc_after_gallery_save', $product_id, $image_ids );
|
1679 |
|
1680 |
}
|
1681 |
add_action( 'wpsc_edit_product', 'wpsc_new_gallery_save' );
|
wpsc-admin/includes/product-functions.php
CHANGED
@@ -46,10 +46,10 @@ function wpsc_admin_submit_product( $post_ID, $post ) {
|
|
46 |
$post_data['meta']['_wpsc_sku'] = '';
|
47 |
}
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
if ( ! isset( $post_data['meta']['_wpsc_limited_stock'] ) ){
|
55 |
$post_data['meta']['_wpsc_stock'] = false;
|
@@ -58,17 +58,33 @@ function wpsc_admin_submit_product( $post_ID, $post ) {
|
|
58 |
}
|
59 |
|
60 |
unset($post_data['meta']['_wpsc_limited_stock']);
|
61 |
-
if(!isset($post_data['
|
62 |
-
if(!isset($post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'])) $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] = '';
|
63 |
-
if(!isset($post_data['quantity_limited'])) $post_data['quantity_limited'] = '';
|
64 |
if(!isset($post_data['special'])) $post_data['special'] = '';
|
65 |
-
if(!isset($post_data['meta']['_wpsc_product_metadata']['no_shipping'])) $post_data['meta']['_wpsc_product_metadata']['no_shipping'] = '';
|
66 |
|
67 |
-
$post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'] = (int)(bool)$post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'];
|
68 |
-
$post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] = (int)(bool)$post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'];
|
69 |
$post_data['meta']['_wpsc_product_metadata']['quantity_limited'] = (int)(bool)$post_data['quantity_limited'];
|
70 |
$post_data['meta']['_wpsc_product_metadata']['special'] = (int)(bool)$post_data['special'];
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
// Product Weight
|
74 |
if(!isset($post_data['meta']['_wpsc_product_metadata']['display_weight_as'])) $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = '';
|
@@ -127,22 +143,53 @@ function wpsc_admin_submit_product( $post_ID, $post ) {
|
|
127 |
$post_data['meta']['_wpsc_product_metadata']['wpec_taxes_taxable_amount']
|
128 |
);
|
129 |
|
130 |
-
//
|
131 |
-
if ( isset( $
|
132 |
-
|
133 |
-
|
134 |
-
$post_data['meta']['_wpsc_product_metadata']['
|
|
|
|
|
|
|
|
|
|
|
135 |
}
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
}
|
142 |
|
143 |
if ( ! isset($post_data['meta']['_wpsc_product_metadata']['google_prohibited'])) $post_data['meta']['_wpsc_product_metadata']['google_prohibited'] = '';
|
144 |
$post_data['meta']['_wpsc_product_metadata']['google_prohibited'] = (int)(bool)$post_data['meta']['_wpsc_product_metadata']['google_prohibited'];
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
$post_data['files'] = $_FILES;
|
147 |
|
148 |
if(isset($post_data['post_title']) && $post_data['post_title'] != '') {
|
@@ -172,16 +219,12 @@ function wpsc_admin_submit_product( $post_ID, $post ) {
|
|
172 |
'thumbnail_state' => null
|
173 |
);
|
174 |
|
175 |
-
foreach($product_columns as $column => $default)
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
if($post_data[$column] !== null) {
|
180 |
-
$update_values[$column] = $post_data[$column];
|
181 |
-
} else if(($update != true) && ($default !== null)) {
|
182 |
-
$update_values[$column] = ($default);
|
183 |
}
|
184 |
}
|
|
|
185 |
// if we succeed, we can do further editing (todo - if_wp_error)
|
186 |
|
187 |
// if we have no categories selected, assign one.
|
@@ -318,7 +361,6 @@ function wpsc_sanitise_product_forms($post_data = null) {
|
|
318 |
|
319 |
$post_data['meta']['_wpsc_price'] = wpsc_string_to_float( $post_data['meta']['_wpsc_price'] );
|
320 |
$post_data['meta']['_wpsc_special_price'] = wpsc_string_to_float( $post_data['meta']['_wpsc_special_price'] );
|
321 |
-
$post_data['meta']['_wpsc_sku'] = $post_data['meta']['_wpsc_sku'];
|
322 |
if (!isset($post_data['meta']['_wpsc_is_donation'])) $post_data['meta']['_wpsc_is_donation'] = '';
|
323 |
$post_data['meta']['_wpsc_is_donation'] = (int)(bool)$post_data['meta']['_wpsc_is_donation'];
|
324 |
$post_data['meta']['_wpsc_stock'] = (int)$post_data['meta']['_wpsc_stock'];
|
@@ -390,14 +432,9 @@ function wpsc_insert_product($post_data, $wpsc_error = false) {
|
|
390 |
);
|
391 |
|
392 |
|
393 |
-
foreach($product_columns as $column => $default)
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
if($post_data[$column] !== null) {
|
398 |
-
$update_values[$column] = $post_data[$column];
|
399 |
-
} else if(($update != true) && ($default !== null)) {
|
400 |
-
$update_values[$column] = $default;
|
401 |
}
|
402 |
}
|
403 |
|
@@ -424,13 +461,7 @@ function wpsc_insert_product($post_data, $wpsc_error = false) {
|
|
424 |
}else {
|
425 |
unstick_post($product_id);
|
426 |
}
|
427 |
-
|
428 |
-
if ( $wp_error ) {
|
429 |
-
return new WP_Error('db_insert_error', __( 'Could not insert product into the database', 'wpsc' ), $wpdb->last_error);
|
430 |
-
} else {
|
431 |
-
return 0;
|
432 |
-
}
|
433 |
-
}
|
434 |
$adding = true;
|
435 |
|
436 |
// if we succeed, we can do further editing
|
@@ -472,7 +503,7 @@ function term_id_price($term_id, $parent_price) {
|
|
472 |
}
|
473 |
|
474 |
if (strchr($price, '-') ) {
|
475 |
-
$
|
476 |
} else {
|
477 |
$positive = true;
|
478 |
}
|
@@ -677,6 +708,8 @@ function wpsc_edit_product_variations($product_id, $post_data) {
|
|
677 |
$currently_associated_vars[] = $current->term_id;
|
678 |
}
|
679 |
|
|
|
|
|
680 |
foreach ($posted_term as $term=>$val) {
|
681 |
$posted_terms[] = $term;
|
682 |
if(is_array($val)) {
|
@@ -685,14 +718,20 @@ function wpsc_edit_product_variations($product_id, $post_data) {
|
|
685 |
}
|
686 |
}
|
687 |
}
|
|
|
688 |
if(!empty($currently_associated_vars)){
|
689 |
$term_ids_to_delete = array();
|
690 |
$term_ids_to_delete = array_diff($currently_associated_vars, $posted_terms);
|
691 |
}
|
692 |
-
|
|
|
693 |
$post_id = $_REQUEST["post_ID"];
|
694 |
-
elseif(isset($_REQUEST["product_id"]))
|
695 |
$post_id = $_REQUEST["product_id"];
|
|
|
|
|
|
|
|
|
696 |
if(!empty($term_ids_to_delete) && (isset($_REQUEST["product_id"]) || isset($post_id))) {
|
697 |
$post_ids_to_delete = array();
|
698 |
|
@@ -883,7 +922,8 @@ function wpsc_item_reassign_file($product_id, $selected_files) {
|
|
883 |
'post_status' => 'any'
|
884 |
);
|
885 |
|
886 |
-
$attached_files = (array)get_posts($args);
|
|
|
887 |
|
888 |
foreach($attached_files as $key => $attached_file) {
|
889 |
$attached_files_by_file[$attached_file->post_title] = $attached_files[$key];
|
46 |
$post_data['meta']['_wpsc_sku'] = '';
|
47 |
}
|
48 |
|
49 |
+
// Update donation setting
|
50 |
+
if ( isset( $post_data['wpsc_product_pricing_nonce'] ) && wp_verify_nonce( $post_data['wpsc_product_pricing_nonce'], 'update' ) ) {
|
51 |
+
$post_data['meta']['_wpsc_is_donation'] = isset( $post_data['meta']['_wpsc_is_donation'] ) ? 1 : 0;
|
52 |
+
}
|
53 |
|
54 |
if ( ! isset( $post_data['meta']['_wpsc_limited_stock'] ) ){
|
55 |
$post_data['meta']['_wpsc_stock'] = false;
|
58 |
}
|
59 |
|
60 |
unset($post_data['meta']['_wpsc_limited_stock']);
|
61 |
+
if(!isset($post_data['quantity_limited'])) $post_data['quantity_limited'] = '';
|
|
|
|
|
62 |
if(!isset($post_data['special'])) $post_data['special'] = '';
|
|
|
63 |
|
|
|
|
|
64 |
$post_data['meta']['_wpsc_product_metadata']['quantity_limited'] = (int)(bool)$post_data['quantity_limited'];
|
65 |
$post_data['meta']['_wpsc_product_metadata']['special'] = (int)(bool)$post_data['special'];
|
66 |
+
|
67 |
+
// Update Stock Options
|
68 |
+
if ( isset( $_POST['wpsc_product_stock_nonce'] ) && wp_verify_nonce( $_POST['wpsc_product_stock_nonce'], 'update' ) ) {
|
69 |
+
|
70 |
+
$post_data['meta']['_wpsc_product_metadata'] = wp_parse_args( $post_data['meta']['_wpsc_product_metadata'], array(
|
71 |
+
'notify_when_none_left' => 0,
|
72 |
+
'unpublish_when_none_left' => 0
|
73 |
+
) );
|
74 |
+
$post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'] = absint( (bool) $post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'] );
|
75 |
+
$post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] = absint( (bool) $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] );
|
76 |
+
|
77 |
+
}
|
78 |
+
|
79 |
+
// Update shipping setting
|
80 |
+
if ( isset( $_POST['wpsc_product_shipping_nonce'] ) && wp_verify_nonce( $_POST['wpsc_product_shipping_nonce'], 'update' ) ) {
|
81 |
+
|
82 |
+
$post_data['meta']['_wpsc_product_metadata'] = wp_parse_args( $post_data['meta']['_wpsc_product_metadata'], array(
|
83 |
+
'no_shipping' => 0
|
84 |
+
) );
|
85 |
+
$post_data['meta']['_wpsc_product_metadata']['no_shipping'] = absint( (bool) $post_data['meta']['_wpsc_product_metadata']['no_shipping'] );
|
86 |
+
|
87 |
+
}
|
88 |
|
89 |
// Product Weight
|
90 |
if(!isset($post_data['meta']['_wpsc_product_metadata']['display_weight_as'])) $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = '';
|
143 |
$post_data['meta']['_wpsc_product_metadata']['wpec_taxes_taxable_amount']
|
144 |
);
|
145 |
|
146 |
+
// External Link Options
|
147 |
+
if ( isset( $_POST['wpsc_product_external_link_nonce'] ) && wp_verify_nonce( $_POST['wpsc_product_external_link_nonce'], 'update' ) ) {
|
148 |
+
|
149 |
+
// Parse post meta to ensure default values
|
150 |
+
$post_data['meta']['_wpsc_product_metadata'] = wp_parse_args( $post_data['meta']['_wpsc_product_metadata'], array(
|
151 |
+
'external_link' => '',
|
152 |
+
'external_link_text' => '',
|
153 |
+
'external_link_target' => ''
|
154 |
+
) );
|
155 |
+
|
156 |
}
|
157 |
|
158 |
+
// Advanced Options
|
159 |
+
if ( isset( $_POST['wpsc_product_personalization_nonce'] ) && wp_verify_nonce( $_POST['wpsc_product_personalization_nonce'], 'update' ) ) {
|
160 |
+
|
161 |
+
// Parse post meta to ensure default values (especially checkboxes)
|
162 |
+
$post_data['meta']['_wpsc_product_metadata'] = wp_parse_args( $post_data['meta']['_wpsc_product_metadata'], array(
|
163 |
+
'engraved' => 0,
|
164 |
+
'can_have_uploaded_image' => 0
|
165 |
+
) );
|
166 |
+
|
167 |
+
$post_data['meta']['_wpsc_product_metadata']['engraved'] = absint( (bool) $post_data['meta']['_wpsc_product_metadata']['engraved'] );
|
168 |
+
$post_data['meta']['_wpsc_product_metadata']['can_have_uploaded_image'] = absint( (bool) $post_data['meta']['_wpsc_product_metadata']['can_have_uploaded_image'] );
|
169 |
+
|
170 |
}
|
171 |
|
172 |
if ( ! isset($post_data['meta']['_wpsc_product_metadata']['google_prohibited'])) $post_data['meta']['_wpsc_product_metadata']['google_prohibited'] = '';
|
173 |
$post_data['meta']['_wpsc_product_metadata']['google_prohibited'] = (int)(bool)$post_data['meta']['_wpsc_product_metadata']['google_prohibited'];
|
174 |
|
175 |
+
// Fill in any missing meta values with existing values.
|
176 |
+
$post_data['meta'] = wp_parse_args( $post_data['meta'], array(
|
177 |
+
'_wpsc_is_donation' => get_product_meta( $product_id, 'is_donation', true )
|
178 |
+
) );
|
179 |
+
|
180 |
+
// Fill in any missing product meta values with existing values.
|
181 |
+
$default_meta_values = wp_parse_args( get_product_meta( $product_id, 'product_metadata', true ), array(
|
182 |
+
'notify_when_none_left' => 0,
|
183 |
+
'unpublish_when_none_left' => 0,
|
184 |
+
'no_shipping' => 0,
|
185 |
+
'external_link' => '',
|
186 |
+
'external_link_text' => '',
|
187 |
+
'external_link_target' => '',
|
188 |
+
'engraved' => 0,
|
189 |
+
'can_have_uploaded_image' => 0
|
190 |
+
) );
|
191 |
+
$post_data['meta']['_wpsc_product_metadata'] = wp_parse_args( $post_data['meta']['_wpsc_product_metadata'], $default_meta_values );
|
192 |
+
|
193 |
$post_data['files'] = $_FILES;
|
194 |
|
195 |
if(isset($post_data['post_title']) && $post_data['post_title'] != '') {
|
219 |
'thumbnail_state' => null
|
220 |
);
|
221 |
|
222 |
+
foreach ( $product_columns as $column => $default ) {
|
223 |
+
if ( ! isset( $post_data[ $column ] ) ) {
|
224 |
+
$post_data[ $column ] = '';
|
|
|
|
|
|
|
|
|
|
|
225 |
}
|
226 |
}
|
227 |
+
|
228 |
// if we succeed, we can do further editing (todo - if_wp_error)
|
229 |
|
230 |
// if we have no categories selected, assign one.
|
361 |
|
362 |
$post_data['meta']['_wpsc_price'] = wpsc_string_to_float( $post_data['meta']['_wpsc_price'] );
|
363 |
$post_data['meta']['_wpsc_special_price'] = wpsc_string_to_float( $post_data['meta']['_wpsc_special_price'] );
|
|
|
364 |
if (!isset($post_data['meta']['_wpsc_is_donation'])) $post_data['meta']['_wpsc_is_donation'] = '';
|
365 |
$post_data['meta']['_wpsc_is_donation'] = (int)(bool)$post_data['meta']['_wpsc_is_donation'];
|
366 |
$post_data['meta']['_wpsc_stock'] = (int)$post_data['meta']['_wpsc_stock'];
|
432 |
);
|
433 |
|
434 |
|
435 |
+
foreach ( $product_columns as $column => $default ) {
|
436 |
+
if ( ! isset( $post_data[ $column ] ) ) {
|
437 |
+
$post_data[ $column ] = '';
|
|
|
|
|
|
|
|
|
|
|
438 |
}
|
439 |
}
|
440 |
|
461 |
}else {
|
462 |
unstick_post($product_id);
|
463 |
}
|
464 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
$adding = true;
|
466 |
|
467 |
// if we succeed, we can do further editing
|
503 |
}
|
504 |
|
505 |
if (strchr($price, '-') ) {
|
506 |
+
$positive = false;
|
507 |
} else {
|
508 |
$positive = true;
|
509 |
}
|
708 |
$currently_associated_vars[] = $current->term_id;
|
709 |
}
|
710 |
|
711 |
+
$posted_terms = array();
|
712 |
+
|
713 |
foreach ($posted_term as $term=>$val) {
|
714 |
$posted_terms[] = $term;
|
715 |
if(is_array($val)) {
|
718 |
}
|
719 |
}
|
720 |
}
|
721 |
+
|
722 |
if(!empty($currently_associated_vars)){
|
723 |
$term_ids_to_delete = array();
|
724 |
$term_ids_to_delete = array_diff($currently_associated_vars, $posted_terms);
|
725 |
}
|
726 |
+
|
727 |
+
if(isset($_REQUEST["post_ID"])) {
|
728 |
$post_id = $_REQUEST["post_ID"];
|
729 |
+
} elseif(isset($_REQUEST["product_id"])) {
|
730 |
$post_id = $_REQUEST["product_id"];
|
731 |
+
} else {
|
732 |
+
return;
|
733 |
+
}
|
734 |
+
|
735 |
if(!empty($term_ids_to_delete) && (isset($_REQUEST["product_id"]) || isset($post_id))) {
|
736 |
$post_ids_to_delete = array();
|
737 |
|
922 |
'post_status' => 'any'
|
923 |
);
|
924 |
|
925 |
+
$attached_files = (array) get_posts( $args );
|
926 |
+
$attached_files_by_file = array();
|
927 |
|
928 |
foreach($attached_files as $key => $attached_file) {
|
929 |
$attached_files_by_file[$attached_file->post_title] = $attached_files[$key];
|
wpsc-admin/includes/product-variation-list-table.class.php
CHANGED
@@ -3,6 +3,11 @@
|
|
3 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
4 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php' );
|
5 |
|
|
|
|
|
|
|
|
|
|
|
6 |
class WPSC_Product_Variation_List_Table extends WP_List_Table {
|
7 |
private $product_id;
|
8 |
private $object_terms_cache = array();
|
@@ -438,7 +443,7 @@ class WPSC_Product_Variation_List_Table extends WP_List_Table {
|
|
438 |
return $actions;
|
439 |
}
|
440 |
|
441 |
-
public function bulk_actions() {
|
442 |
$screen = get_current_screen();
|
443 |
|
444 |
if ( is_null( $this->_actions ) ) {
|
3 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
4 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php' );
|
5 |
|
6 |
+
/**
|
7 |
+
* Product Variation List Table class
|
8 |
+
*
|
9 |
+
* @package wp-e-commerce
|
10 |
+
*/
|
11 |
class WPSC_Product_Variation_List_Table extends WP_List_Table {
|
12 |
private $product_id;
|
13 |
private $object_terms_cache = array();
|
443 |
return $actions;
|
444 |
}
|
445 |
|
446 |
+
public function bulk_actions( $which = '' ) {
|
447 |
$screen = get_current_screen();
|
448 |
|
449 |
if ( is_null( $this->_actions ) ) {
|
wpsc-admin/includes/product-variations-page.class.php
CHANGED
@@ -1,5 +1,11 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
class WPSC_Product_Variations_Page {
|
4 |
private $list_table;
|
5 |
private $parent_id;
|
@@ -414,4 +420,4 @@ function _wpsc_admin_html_begin() {
|
|
414 |
<head>
|
415 |
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
|
416 |
<?php
|
417 |
-
}
|
1 |
<?php
|
2 |
|
3 |
+
/**
|
4 |
+
* The Product Variations page class in the WordPress admin
|
5 |
+
*
|
6 |
+
* @package wp-e-commerce
|
7 |
+
*/
|
8 |
+
|
9 |
class WPSC_Product_Variations_Page {
|
10 |
private $list_table;
|
11 |
private $parent_id;
|
420 |
<head>
|
421 |
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
|
422 |
<?php
|
423 |
+
}
|
wpsc-admin/includes/purchase-log-action-links.php
ADDED
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Purchase Log Action Links Class
|
5 |
+
*
|
6 |
+
* Manages and displays a links of action links when editing a puchase log.
|
7 |
+
*
|
8 |
+
* @package wp-e-commerce
|
9 |
+
* @since 3.9.0
|
10 |
+
*
|
11 |
+
* @link https://github.com/wp-e-commerce/WP-e-Commerce/pull/1562
|
12 |
+
*/
|
13 |
+
class WPSC_Purchase_Log_Action_Links {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Purchase Log ID.
|
17 |
+
*
|
18 |
+
* @since 3.9.0
|
19 |
+
* @access private
|
20 |
+
* @var int
|
21 |
+
*/
|
22 |
+
protected $log_id;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* An array of WPSC_Purchase_Log_Action_Link objects.
|
26 |
+
*
|
27 |
+
* @since 3.9.0
|
28 |
+
* @access private
|
29 |
+
* @var array
|
30 |
+
*/
|
31 |
+
protected $links;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Setup all action links.
|
35 |
+
*
|
36 |
+
* @since 3.9.0
|
37 |
+
*
|
38 |
+
* @param int $log_id Purchase log ID.
|
39 |
+
*/
|
40 |
+
public function __construct( $log_id ) {
|
41 |
+
|
42 |
+
$this->log_id = absint( $log_id );
|
43 |
+
|
44 |
+
// Create and validate links.
|
45 |
+
$this->_create_links();
|
46 |
+
$this->_validate_links();
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Create Action Links
|
52 |
+
*
|
53 |
+
* Packing slip and email receipt links are available by default.
|
54 |
+
* Action links are filterable via the 'wpsc_purchlogitem_links' filter which passes the purchase log ID.
|
55 |
+
* Delete and back links are always required and added after the filter.
|
56 |
+
*
|
57 |
+
* @since 3.9.0
|
58 |
+
* @access private
|
59 |
+
*/
|
60 |
+
private function _create_links() {
|
61 |
+
|
62 |
+
// Add default links.
|
63 |
+
if ( wpsc_purchlogs_have_downloads_locked() != false ) {
|
64 |
+
$this->links[] = $this->get_downloads_lock_link();
|
65 |
+
}
|
66 |
+
$this->links[] = $this->get_packing_slip_link();
|
67 |
+
$this->links[] = $this->get_email_receipt_link();
|
68 |
+
|
69 |
+
// Filter action links.
|
70 |
+
$this->links = apply_filters( 'wpsc_purchlogitem_links', $this->links, $this->log_id );
|
71 |
+
|
72 |
+
// Add delete and back links.
|
73 |
+
$this->links[] = $this->_get_delete_link();
|
74 |
+
$this->links[] = $this->_get_back_link();
|
75 |
+
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Validate Links
|
80 |
+
*
|
81 |
+
* Validates all links are WPSC_Purchase_Log_Action_Link objects.
|
82 |
+
*
|
83 |
+
* @since 3.9.0
|
84 |
+
* @access private
|
85 |
+
*/
|
86 |
+
private function _validate_links() {
|
87 |
+
|
88 |
+
$this->links = array_map( array( $this, '_validate_link' ), $this->links );
|
89 |
+
$this->links = array_filter( $this->links );
|
90 |
+
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Validate Link
|
95 |
+
*
|
96 |
+
* Validates a WPSC_Purchase_Log_Action_Link object.
|
97 |
+
*
|
98 |
+
* @since 3.9.0
|
99 |
+
* @access private
|
100 |
+
*
|
101 |
+
* @todo Check that the WPSC_Purchase_Log_Action_Link ID is unique and reject if not - maybe not here.
|
102 |
+
*
|
103 |
+
* @param WPSC_Purchase_Log_Action_Link $action_link Action link object.
|
104 |
+
* @return WPSC_Purchase_Log_Action_Link|boolean If valid, the action link object, otherwise false.
|
105 |
+
*/
|
106 |
+
private function _validate_link( $action_link ) {
|
107 |
+
|
108 |
+
if ( is_a( $action_link, 'WPSC_Purchase_Log_Action_Link' ) ) {
|
109 |
+
return $action_link;
|
110 |
+
}
|
111 |
+
|
112 |
+
return false;
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Downloads Lock Action Link
|
118 |
+
*
|
119 |
+
* @since 3.9.0
|
120 |
+
* @access private
|
121 |
+
*
|
122 |
+
* @return WPSC_Purchase_Log_Action_Link Instance of an action link object.
|
123 |
+
*/
|
124 |
+
private function get_downloads_lock_link() {
|
125 |
+
|
126 |
+
return new WPSC_Purchase_Log_Action_Link( 'downloads_lock', wpsc_purchlogs_have_downloads_locked(), $this->log_id, array(
|
127 |
+
'ajax' => true,
|
128 |
+
'dashicon' => 'dashicons-lock'
|
129 |
+
) );
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* View Packing Slip Action Link
|
135 |
+
*
|
136 |
+
* @since 3.9.0
|
137 |
+
* @access private
|
138 |
+
*
|
139 |
+
* @return WPSC_Purchase_Log_Action_Link Instance of an action link object.
|
140 |
+
*/
|
141 |
+
private function get_packing_slip_link() {
|
142 |
+
|
143 |
+
return new WPSC_Purchase_Log_Action_Link( 'packing_slip', __( 'View Packing Slip', 'wpsc' ), $this->log_id, array(
|
144 |
+
'url' => esc_url( add_query_arg( array(
|
145 |
+
'c' => 'packing_slip',
|
146 |
+
'id' => $this->log_id
|
147 |
+
) ) ),
|
148 |
+
'dashicon' => 'dashicons-format-aside',
|
149 |
+
'attributes' => array(
|
150 |
+
'target' => 'wpsc_packing_slip'
|
151 |
+
)
|
152 |
+
) );
|
153 |
+
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Resend Email Receipt Action Link
|
158 |
+
*
|
159 |
+
* @since 3.9.0
|
160 |
+
* @access private
|
161 |
+
*
|
162 |
+
* @return WPSC_Purchase_Log_Action_Link Instance of an action link object.
|
163 |
+
*/
|
164 |
+
private function get_email_receipt_link() {
|
165 |
+
|
166 |
+
return new WPSC_Purchase_Log_Action_Link( 'email_receipt', __( 'Resend Receipt to Buyer', 'wpsc' ), $this->log_id, array(
|
167 |
+
'ajax' => true,
|
168 |
+
'dashicon' => 'dashicons-migrate dashicons-email-alt'
|
169 |
+
) );
|
170 |
+
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Delete Action Link
|
175 |
+
*
|
176 |
+
* @since 3.9.0
|
177 |
+
* @access private
|
178 |
+
*
|
179 |
+
* @return WPSC_Purchase_Log_Action_Link Instance of an action link object.
|
180 |
+
*/
|
181 |
+
private function _get_delete_link() {
|
182 |
+
|
183 |
+
return new WPSC_Purchase_Log_Action_Link( 'delete', _x( 'Remove this record', 'purchase log action link', 'wpsc' ), $this->log_id, array(
|
184 |
+
'dashicon' => 'dashicons-dismiss',
|
185 |
+
'attributes' => array(
|
186 |
+
'onclick' => "if ( confirm('" . esc_js( sprintf( __( "You are about to delete this log '%s'\n 'Cancel' to stop, 'OK' to delete.", 'wpsc' ), wpsc_purchaselog_details_date() ) ) . "') ) { return true; } return false;"
|
187 |
+
)
|
188 |
+
) );
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Back Action Link
|
194 |
+
*
|
195 |
+
* @since 3.9.0
|
196 |
+
* @access private
|
197 |
+
*
|
198 |
+
* @return WPSC_Purchase_Log_Action_Link Instance of an action link object.
|
199 |
+
*/
|
200 |
+
private function _get_back_link() {
|
201 |
+
|
202 |
+
return new WPSC_Purchase_Log_Action_Link( 'back', _x( 'Go Back', 'purchase log action link', 'wpsc' ), $this->log_id, array(
|
203 |
+
'url' => wp_get_referer(),
|
204 |
+
'dashicon' => 'dashicons-arrow-left-alt'
|
205 |
+
) );
|
206 |
+
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Display Link List Items
|
211 |
+
*
|
212 |
+
* @since 3.9.0
|
213 |
+
*
|
214 |
+
* Outputs action links as a series of list item tags to be included in an HTML list.
|
215 |
+
*/
|
216 |
+
public function display_link_list_items() {
|
217 |
+
|
218 |
+
foreach ( $this->links as $link ) {
|
219 |
+
echo '<li>' . $link->get_link_display() . '</li>';
|
220 |
+
}
|
221 |
+
|
222 |
+
}
|
223 |
+
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Purchase Log Action Link Class
|
228 |
+
*
|
229 |
+
* Creates, styles and handles a purchase log action link.
|
230 |
+
*
|
231 |
+
* @since 3.9.0
|
232 |
+
*/
|
233 |
+
class WPSC_Purchase_Log_Action_Link {
|
234 |
+
|
235 |
+
/**
|
236 |
+
* Action Link ID.
|
237 |
+
*
|
238 |
+
* @since 3.9.0
|
239 |
+
* @access private
|
240 |
+
* @var string
|
241 |
+
*/
|
242 |
+
private $id;
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Action Link Title Text.
|
246 |
+
*
|
247 |
+
* @since 3.9.0
|
248 |
+
* @access private
|
249 |
+
* @var string
|
250 |
+
*/
|
251 |
+
private $title;
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Purchase Log ID.
|
255 |
+
*
|
256 |
+
* @since 3.9.0
|
257 |
+
* @access private
|
258 |
+
* @var int
|
259 |
+
*/
|
260 |
+
private $log_id;
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Action Link Settings.
|
264 |
+
*
|
265 |
+
* @since 3.9.0
|
266 |
+
* @access private
|
267 |
+
* @var array
|
268 |
+
*/
|
269 |
+
private $args;
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Define the action link.
|
273 |
+
*
|
274 |
+
* @since 3.9.0
|
275 |
+
*
|
276 |
+
* @param string $id Action link ID (will be sanitized).
|
277 |
+
* @param string $title Link text.
|
278 |
+
* @param array $args Action link settings.
|
279 |
+
*/
|
280 |
+
public function __construct( $id, $title, $log_id, $args = array() ) {
|
281 |
+
|
282 |
+
$this->id = sanitize_key( $id );
|
283 |
+
$this->title = $title;
|
284 |
+
$this->log_id = absint( $log_id );
|
285 |
+
$this->args = $this->_validate_settings( $args );
|
286 |
+
|
287 |
+
}
|
288 |
+
|
289 |
+
/**
|
290 |
+
* Validate Settings
|
291 |
+
*
|
292 |
+
* Checks settings and adds defaults where required.
|
293 |
+
*
|
294 |
+
* The 'attributes' setting allows additional attributes to be added to the link tag if required.
|
295 |
+
* 'title' and 'href' attributes are removed as these are created via the 'url' and 'description' settings.
|
296 |
+
*
|
297 |
+
* Any class attributes are added to the 'wpsc-purchlog-action-{$id}' class we generate.
|
298 |
+
*
|
299 |
+
* @since 3.9.0
|
300 |
+
* @access private
|
301 |
+
*
|
302 |
+
* @param array $args Supplied settings.
|
303 |
+
* @return array Validated settings.
|
304 |
+
*/
|
305 |
+
private function _validate_settings( $args ) {
|
306 |
+
|
307 |
+
$args = wp_parse_args( $args, array(
|
308 |
+
'url' => '',
|
309 |
+
'description' => '',
|
310 |
+
'dashicon' => '',
|
311 |
+
'attributes' => array(),
|
312 |
+
'ajax' => false
|
313 |
+
) );
|
314 |
+
|
315 |
+
// Use title if no description.
|
316 |
+
if ( empty( $args['description'] ) ) {
|
317 |
+
$args['description'] = $this->title;
|
318 |
+
}
|
319 |
+
|
320 |
+
// Use default arrow dashicon if none specified.
|
321 |
+
if ( empty( $args['dashicon'] ) ) {
|
322 |
+
$args['dashicon'] = 'dashicons-arrow-right-alt';
|
323 |
+
}
|
324 |
+
|
325 |
+
// Remove href and title attributes.
|
326 |
+
if ( is_array( $args['attributes'] ) ) {
|
327 |
+
if ( array_key_exists( 'title', $args['attributes'] ) ) {
|
328 |
+
unset( $args['attributes']['title'] );
|
329 |
+
}
|
330 |
+
if ( array_key_exists( 'href', $args['attributes'] ) ) {
|
331 |
+
unset( $args['attributes']['href'] );
|
332 |
+
}
|
333 |
+
} else {
|
334 |
+
$args['attributes'] = array();
|
335 |
+
}
|
336 |
+
|
337 |
+
// Add class and append any extra classes.
|
338 |
+
if ( ! array_key_exists( 'class', $args['attributes'] ) ) {
|
339 |
+
$args['attributes']['class'] = '';
|
340 |
+
}
|
341 |
+
$args['attributes']['class'] = 'wpsc-purchlog-action-link ' . trim( $this->get_html_class() . ' ' . $args['attributes']['class'] );
|
342 |
+
|
343 |
+
// Add AJAX class
|
344 |
+
if ( $args['ajax'] ) {
|
345 |
+
$args['attributes']['class'] .= ' is-ajax';
|
346 |
+
}
|
347 |
+
|
348 |
+
return $args;
|
349 |
+
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* Get HTML Class
|
354 |
+
*
|
355 |
+
* @since 3.9.0
|
356 |
+
*
|
357 |
+
* @return string Action link class.
|
358 |
+
*/
|
359 |
+
public function get_html_class() {
|
360 |
+
|
361 |
+
return 'wpsc-purchlog-action-link-' . sanitize_html_class( $this->id );
|
362 |
+
|
363 |
+
}
|
364 |
+
|
365 |
+
/**
|
366 |
+
* Get Link Display
|
367 |
+
*
|
368 |
+
* @since 3.9.0
|
369 |
+
*
|
370 |
+
* @return string HTML action link.
|
371 |
+
*/
|
372 |
+
public function get_link_display() {
|
373 |
+
|
374 |
+
return sprintf( '<a href="%s" title="%s" %s>%s%s</a>',
|
375 |
+
esc_attr( $this->get_link_url() ),
|
376 |
+
esc_attr( $this->args['description'] ),
|
377 |
+
$this->_get_link_attributes_string(),
|
378 |
+
$this->_get_dashicon_display(),
|
379 |
+
esc_html( $this->title )
|
380 |
+
);
|
381 |
+
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Get Link URL
|
386 |
+
*
|
387 |
+
* Returns the custom URL if specified.
|
388 |
+
* Otherwise returns a callback URL.
|
389 |
+
*
|
390 |
+
* @since 3.9.0
|
391 |
+
*
|
392 |
+
* @return string URL.
|
393 |
+
*/
|
394 |
+
public function get_link_url() {
|
395 |
+
|
396 |
+
// Custom URL
|
397 |
+
if ( ! empty( $this->args['url'] ) ) {
|
398 |
+
return $this->args['url'];
|
399 |
+
}
|
400 |
+
|
401 |
+
// Callback URL
|
402 |
+
$url = add_query_arg( array( 'wpsc_purchase_log_action' => $this->id, 'id' => $this->log_id ) );
|
403 |
+
$url = wp_nonce_url( $url, 'wpsc_purchase_log_action_' . $this->id );
|
404 |
+
|
405 |
+
return $url;
|
406 |
+
|
407 |
+
}
|
408 |
+
|
409 |
+
/**
|
410 |
+
* Get Link Attributes String
|
411 |
+
*
|
412 |
+
* @since 3.9.0
|
413 |
+
* @access private
|
414 |
+
*
|
415 |
+
* @return string Link attributes HTML.
|
416 |
+
*/
|
417 |
+
private function _get_link_attributes_string() {
|
418 |
+
|
419 |
+
$atts = array();
|
420 |
+
foreach ( $this->args['attributes'] as $att => $val ) {
|
421 |
+
$att_key = sanitize_html_class( $att );
|
422 |
+
|
423 |
+
// Don't override attributes that we set elsewhere
|
424 |
+
if ( in_array( $att_key, array( 'href', 'title' ) ) ) {
|
425 |
+
continue;
|
426 |
+
}
|
427 |
+
|
428 |
+
$atts[] = $att_key . '="' . esc_attr( $val ) . '"';
|
429 |
+
}
|
430 |
+
|
431 |
+
// Data attributes for JS/AJAX
|
432 |
+
$atts[] = 'data-purchase-log-action="' . esc_attr( $this->id ) . '"';
|
433 |
+
$atts[] = 'data-nonce="' . esc_attr( wp_create_nonce( 'wpsc_purchase_log_action_ajax_' . $this->id ) ) . '"';
|
434 |
+
|
435 |
+
return implode( ' ', $atts );
|
436 |
+
|
437 |
+
}
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Get Dashicon Display
|
441 |
+
*
|
442 |
+
* @since 3.9.0
|
443 |
+
* @access private
|
444 |
+
*
|
445 |
+
* @return string Dashicon HTML element.
|
446 |
+
*/
|
447 |
+
private function _get_dashicon_display() {
|
448 |
+
|
449 |
+
return '<span class="dashicons ' . $this->_sanitize_html_classes( $this->args['dashicon'] ) . '"></span>';
|
450 |
+
|
451 |
+
}
|
452 |
+
|
453 |
+
/**
|
454 |
+
* Sanitize HTML Classes
|
455 |
+
*
|
456 |
+
* Handles sanitizing multiple classes provided as a string.
|
457 |
+
*
|
458 |
+
* @since 3.9.0
|
459 |
+
* @access private
|
460 |
+
*
|
461 |
+
* @param string|array $classes Classes.
|
462 |
+
* @return string Santized classes.
|
463 |
+
*/
|
464 |
+
private function _sanitize_html_classes( $classes ) {
|
465 |
+
|
466 |
+
// Convert multiple classes string to an array.
|
467 |
+
if ( ! is_array( $classes ) && strpos( $classes, ' ' ) !== false ) {
|
468 |
+
$classes = explode( ' ', $classes );
|
469 |
+
}
|
470 |
+
|
471 |
+
// Sanitize and return multiple classes.
|
472 |
+
if ( is_array( $classes ) ) {
|
473 |
+
$classes = array_map( 'sanitize_html_class', $classes );
|
474 |
+
return implode( ' ', $classes );
|
475 |
+
}
|
476 |
+
|
477 |
+
// Sanitize single class.
|
478 |
+
return sanitize_html_class( $classes );
|
479 |
+
|
480 |
+
}
|
481 |
+
|
482 |
+
}
|
wpsc-admin/includes/purchase-log-list-table-class.php
CHANGED
@@ -20,6 +20,9 @@ class WPSC_Purchase_Log_List_Table extends WP_List_Table {
|
|
20 |
|
21 |
public function __construct( $args = array() ) {
|
22 |
$args['plural'] = 'purchase-logs';
|
|
|
|
|
|
|
23 |
parent::__construct( $args );
|
24 |
|
25 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
|
@@ -46,6 +49,14 @@ class WPSC_Purchase_Log_List_Table extends WP_List_Table {
|
|
46 |
$this->views = false;
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
public function set_per_page( $per_page ) {
|
50 |
$this->per_page = (int) $per_page;
|
51 |
}
|
20 |
|
21 |
public function __construct( $args = array() ) {
|
22 |
$args['plural'] = 'purchase-logs';
|
23 |
+
|
24 |
+
$this->set_per_page( $this->set_purchase_logs_per_page_by_user() );
|
25 |
+
|
26 |
parent::__construct( $args );
|
27 |
|
28 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
|
49 |
$this->views = false;
|
50 |
}
|
51 |
|
52 |
+
private function set_purchase_logs_per_page_by_user() {
|
53 |
+
|
54 |
+
$per_page = get_user_meta( get_current_user_id(), 'wpsc_purchases_per_page', true );
|
55 |
+
|
56 |
+
return empty( $per_page ) || $per_page < 1 ? 20 : $per_page;
|
57 |
+
}
|
58 |
+
|
59 |
+
// Override the default Purchase Logs Per Page
|
60 |
public function set_per_page( $per_page ) {
|
61 |
$this->per_page = (int) $per_page;
|
62 |
}
|
wpsc-admin/includes/purchase-logs-page/item-details.php
CHANGED
@@ -137,21 +137,12 @@
|
|
137 |
<input type='hidden' name='wpsc_admin_action' value='purchlogs_update_notes' />
|
138 |
<input type="hidden" name="wpsc_purchlogs_update_notes_nonce" id="wpsc_purchlogs_update_notes_nonce" value="<?php echo wp_create_nonce( 'wpsc_purchlogs_update_notes' ); ?>" />
|
139 |
<input type='hidden' name='purchlog_id' value='<?php echo $this->log_id; ?>' />
|
140 |
-
<p>
|
141 |
-
|
142 |
-
if ( isset( $_POST['purchlog_notes'] ) ) {
|
143 |
-
echo esc_textarea( stripslashes( $_POST['purchlog_notes'] ) );
|
144 |
-
} else {
|
145 |
-
echo wpsc_display_purchlog_notes();
|
146 |
-
}
|
147 |
-
?></textarea>
|
148 |
-
</p>
|
149 |
-
<p><input class="button" type="submit" name="button" id="button" value="<?php _e( 'Update Notes', 'wpsc' ); ?>" /></p>
|
150 |
</form>
|
151 |
</div>
|
152 |
</div>
|
153 |
</div>
|
154 |
-
<!-- End Order Notes (by Ben) -->
|
155 |
|
156 |
<?php $this->purchase_logs_checkout_fields(); ?>
|
157 |
<?php do_action( 'wpsc_purchlogitem_metabox_end', $this->log_id ); ?>
|
@@ -159,22 +150,16 @@
|
|
159 |
</div>
|
160 |
</div>
|
161 |
|
162 |
-
<div id=
|
163 |
<h3><?php esc_html_e( 'Actions', 'wpsc' ); ?></h3>
|
164 |
<?php do_action( 'wpsc_purchlogitem_links_start' ); ?>
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
<br /><br class='small' />
|
173 |
-
<a class='submitdelete' title='<?php echo esc_attr(__( 'Remove this log', 'wpsc' )); ?>' href='<?php echo wp_nonce_url("admin.php?wpsc_admin_action=delete_purchlog&purchlog_id=".$this->log_id, 'delete_purchlog_' .$this->log_id); ?>' onclick="if ( confirm(' <?php echo esc_js(sprintf( __("You are about to delete this log '%s'\n 'Cancel' to stop, 'OK' to delete.",'wpsc'), wpsc_purchaselog_details_date() )) ?>') ) { return true;}return false;"><img src='<?php echo WPSC_CORE_IMAGES_URL . "/cross.png"; ?>' alt='<?php _e( 'delete icon', 'wpsc' ); ?>' /> <?php _e('Remove this record', 'wpsc') ?></a>
|
174 |
-
|
175 |
-
<br /><br class='small' />   <a href='<?php echo esc_attr( wp_get_referer() ); ?>'><?php _e('Go Back', 'wpsc'); ?></a>
|
176 |
-
<br /><br />
|
177 |
</div>
|
178 |
-
<br />
|
179 |
|
180 |
</div>
|
137 |
<input type='hidden' name='wpsc_admin_action' value='purchlogs_update_notes' />
|
138 |
<input type="hidden" name="wpsc_purchlogs_update_notes_nonce" id="wpsc_purchlogs_update_notes_nonce" value="<?php echo wp_create_nonce( 'wpsc_purchlogs_update_notes' ); ?>" />
|
139 |
<input type='hidden' name='purchlog_id' value='<?php echo $this->log_id; ?>' />
|
140 |
+
<p><textarea name="purchlog_notes" rows="3" wrap="virtual" id="purchlog_notes" style="width:100%;"><?php echo esc_textarea( wpsc_display_purchlog_notes() ); ?></textarea></p>
|
141 |
+
<div><input class="button" type="submit" name="button" id="button" value="<?php _e( 'Update Notes', 'wpsc' ); ?>" /></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
</form>
|
143 |
</div>
|
144 |
</div>
|
145 |
</div>
|
|
|
146 |
|
147 |
<?php $this->purchase_logs_checkout_fields(); ?>
|
148 |
<?php do_action( 'wpsc_purchlogitem_metabox_end', $this->log_id ); ?>
|
150 |
</div>
|
151 |
</div>
|
152 |
|
153 |
+
<div id="wpsc_purchlogitems_links">
|
154 |
<h3><?php esc_html_e( 'Actions', 'wpsc' ); ?></h3>
|
155 |
<?php do_action( 'wpsc_purchlogitem_links_start' ); ?>
|
156 |
+
<ul>
|
157 |
+
<?php
|
158 |
+
require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/purchase-log-action-links.php' );
|
159 |
+
$action_links = new WPSC_Purchase_Log_Action_Links( $this->log_id );
|
160 |
+
$action_links->display_link_list_items();
|
161 |
+
?>
|
162 |
+
</ul>
|
|
|
|
|
|
|
|
|
|
|
163 |
</div>
|
|
|
164 |
|
165 |
</div>
|
wpsc-admin/includes/purchase-logs-page/list-table.php
CHANGED
@@ -24,11 +24,11 @@
|
|
24 |
<?php endif ?>
|
25 |
|
26 |
<?php if( get_option( 'wpsc_purchaselogs_fixed' ) == false || ( wpsc_check_uniquenames() ) ): ?>
|
27 |
-
<div class='error' style='padding:8px;line-spacing:8px;'><span ><?php printf( __( 'When upgrading the WP
|
28 |
<?php endif; ?>
|
29 |
|
30 |
<?php if ( $this->needs_update() ): ?>
|
31 |
-
<div class='error' style='padding:8px;line-spacing:8px;'><span ><?php printf( __( 'It has been detected that some of your purchase logs were not updated properly when you upgrade to WP
|
32 |
<?php endif; ?>
|
33 |
|
34 |
<form id="purchase-logs-search" method-"get" action="">
|
24 |
<?php endif ?>
|
25 |
|
26 |
<?php if( get_option( 'wpsc_purchaselogs_fixed' ) == false || ( wpsc_check_uniquenames() ) ): ?>
|
27 |
+
<div class='error' style='padding:8px;line-spacing:8px;'><span ><?php printf( __( 'When upgrading the WP eCommerce Plugin from 3.6.* to 3.7, it is required that you associate your checkout form fields with the new Purchase Logs system. To do so please <a href="%s">click here</a>', 'wpsc' ), add_query_arg( 'c', 'upgrade_purchase_logs_3_7' ) ); ?></span></div>
|
28 |
<?php endif; ?>
|
29 |
|
30 |
<?php if ( $this->needs_update() ): ?>
|
31 |
+
<div class='error' style='padding:8px;line-spacing:8px;'><span ><?php printf( __( 'It has been detected that some of your purchase logs were not updated properly when you upgrade to WP eCommerce %s. Please <a href="%s">click here</a> to fix this problem.', 'wpsc' ), WPSC_VERSION, add_query_arg( 'c', 'upgrade_purchase_logs_3_8' ) ); ?></span></div>
|
32 |
<?php endif; ?>
|
33 |
|
34 |
<form id="purchase-logs-search" method-"get" action="">
|
wpsc-admin/includes/purchase-logs-page/upgrade.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
<p><?php printf( __( 'Your purchase logs have been updated! <a href="%s">Click here</a> to return.' , 'wpsc' ), remove_query_arg( 'c' ) ); ?></p>
|
8 |
</div>
|
9 |
<?php else: ?>
|
10 |
-
<p><?php _e( 'Upgrading to WP
|
11 |
|
12 |
<div class="metabox-holder" style="width:700px">
|
13 |
<form action='' method='post'>
|
7 |
<p><?php printf( __( 'Your purchase logs have been updated! <a href="%s">Click here</a> to return.' , 'wpsc' ), remove_query_arg( 'c' ) ); ?></p>
|
8 |
</div>
|
9 |
<?php else: ?>
|
10 |
+
<p><?php _e( 'Upgrading to WP eCommerce 3.7 and later requires you to run this fix once. The following boxes correspond to the form fields in your current checkout page. All you have to do is select from the drop-down menu box what each of the following fields represent. Sorry for any inconvenience caused, but we\'re sure you\'ll agree that the new purchase logs are worth this minor hassle.', 'wpsc' ); ?> </p>
|
11 |
|
12 |
<div class="metabox-holder" style="width:700px">
|
13 |
<form action='' method='post'>
|
wpsc-admin/includes/save-data.functions.php
CHANGED
@@ -80,27 +80,30 @@ function wpsc_custom_category_columns( $columns ) {
|
|
80 |
|
81 |
return $columns;
|
82 |
}
|
|
|
83 |
/**
|
84 |
-
*
|
85 |
-
*
|
86 |
-
*
|
87 |
-
*
|
|
|
|
|
|
|
|
|
88 |
*/
|
89 |
-
|
90 |
function wpsc_custom_category_column_data( $string, $column_name, $term_id ) {
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
$name = get_term_by( 'id', $term_id, 'wpsc_product_category' );
|
95 |
-
$name = $name->name;
|
96 |
-
|
97 |
-
if ( ! empty( $image ) )
|
98 |
-
$image = "<img src='" . WPSC_CATEGORY_URL . $image . "' title='" . esc_attr( $name ) . "' alt='" . esc_attr( $name ) . "' width='30' height='30' />";
|
99 |
-
else
|
100 |
-
$image = "<img src='" . WPSC_CORE_IMAGES_URL . "/no-image-uploaded.gif' title='" . esc_attr( $name ) . "' alt='" . esc_attr( $name ) . "' width='30' height='30' />";
|
101 |
-
|
102 |
-
return $image;
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
/**
|
80 |
|
81 |
return $columns;
|
82 |
}
|
83 |
+
|
84 |
/**
|
85 |
+
* Custom Category Column Data
|
86 |
+
*
|
87 |
+
* Adds images to the custom category column.
|
88 |
+
*
|
89 |
+
* @param string $string Column output.
|
90 |
+
* @param string $column_name Column name.
|
91 |
+
* @param string $term_id Term ID.
|
92 |
+
* @return string Updated column output.
|
93 |
*/
|
|
|
94 |
function wpsc_custom_category_column_data( $string, $column_name, $term_id ) {
|
95 |
+
if ( 'image' == $column_name ) {
|
96 |
+
$term = get_term_by( 'id', $term_id, 'wpsc_product_category' );
|
97 |
+
$image = wpsc_get_categorymeta( $term_id, 'image' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
$format = '<img src="%s" title="%s" alt="%2$s" width="30" height="30" />';
|
100 |
+
if ( ! empty( $image ) ) {
|
101 |
+
$string = sprintf( $format, WPSC_CORE_IMAGES_URL . $image, esc_attr( $term->name ) );
|
102 |
+
} else {
|
103 |
+
$string = sprintf( $format, WPSC_CORE_IMAGES_URL . '/no-image-uploaded.gif', esc_attr( $term->name ) );
|
104 |
+
}
|
105 |
+
}
|
106 |
+
return $string;
|
107 |
}
|
108 |
|
109 |
/**
|
wpsc-admin/includes/settings-tabs/admin.php
CHANGED
@@ -1,5 +1,11 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
class WPSC_Settings_Tab_Admin extends WPSC_Settings_Tab {
|
4 |
public function display() {
|
5 |
?>
|
@@ -8,7 +14,7 @@ class WPSC_Settings_Tab_Admin extends WPSC_Settings_Tab {
|
|
8 |
<tr>
|
9 |
<th scope="row"><?php esc_html_e( 'Max downloads per file', 'wpsc' ); ?>: </th>
|
10 |
<td>
|
11 |
-
<input type="number" size="10" value="<?php echo esc_attr( get_option('max_downloads') ); ?>" name="wpsc_options[max_downloads]" />
|
12 |
</td>
|
13 |
</tr>
|
14 |
<?php
|
@@ -144,4 +150,4 @@ class WPSC_Settings_Tab_Admin extends WPSC_Settings_Tab {
|
|
144 |
</table>
|
145 |
<?php
|
146 |
}
|
147 |
-
}
|
1 |
<?php
|
2 |
|
3 |
+
/**
|
4 |
+
* The Admin Settings Tab class
|
5 |
+
*
|
6 |
+
* @package wp-e-commerce
|
7 |
+
*/
|
8 |
+
|
9 |
class WPSC_Settings_Tab_Admin extends WPSC_Settings_Tab {
|
10 |
public function display() {
|
11 |
?>
|
14 |
<tr>
|
15 |
<th scope="row"><?php esc_html_e( 'Max downloads per file', 'wpsc' ); ?>: </th>
|
16 |
<td>
|
17 |
+
<input type="number" min="0" size="10" value="<?php echo esc_attr( get_option('max_downloads') ); ?>" name="wpsc_options[max_downloads]" />
|
18 |
</td>
|
19 |
</tr>
|
20 |
<?php
|
150 |
</table>
|
151 |
<?php
|
152 |
}
|
153 |
+
}
|
wpsc-admin/includes/settings-tabs/checkout.php
CHANGED
@@ -367,7 +367,7 @@ class WPSC_Settings_Tab_Checkout extends WPSC_Settings_Tab {
|
|
367 |
<label for='require_register2'><?php _e( 'Users can checkout without a user account', 'wpsc' );?></label><br />
|
368 |
<input type='radio' value='1' name='wpsc_options[require_register]' id='require_register1' <?php checked( $this->require_register, 1 ); ?> />
|
369 |
<label for='require_register1'><?php _e( 'Users must register before checking out', 'wpsc' );?></label>
|
370 |
-
<p class='description'><?php esc_attr_e( '
|
371 |
</td>
|
372 |
</tr>
|
373 |
|
367 |
<label for='require_register2'><?php _e( 'Users can checkout without a user account', 'wpsc' );?></label><br />
|
368 |
<input type='radio' value='1' name='wpsc_options[require_register]' id='require_register1' <?php checked( $this->require_register, 1 ); ?> />
|
369 |
<label for='require_register1'><?php _e( 'Users must register before checking out', 'wpsc' );?></label>
|
370 |
+
<p class='description'><?php esc_attr_e( 'Enabling this will also turn on "Membership: Anyone can register" from within WordPress Settings > General if it\'s not already enabled', 'wpsc' ); ?></p>
|
371 |
</td>
|
372 |
</tr>
|
373 |
|
wpsc-admin/includes/settings-tabs/gateway.php
CHANGED
@@ -91,7 +91,7 @@ class WPSC_Settings_Tab_Gateway extends WPSC_Settings_Tab {
|
|
91 |
</tbody>
|
92 |
</table>
|
93 |
<?php submit_button( __( 'Save Changes' ) ); ?>
|
94 |
-
<h4><?php _e( 'WP
|
95 |
<a style="border-bottom:none;" href="https://www.paypal.com/nz/mrb/pal=LENKCHY6CU2VY" target="_blank"><img src="<?php echo WPSC_CORE_IMAGES_URL; ?>/paypal-referal.gif" border="0" alt="<?php esc_attr_e( 'Sign up for PayPal and start accepting credit card payments instantly.', 'wpsc' ); ?>" /></a>
|
96 |
<?php
|
97 |
}
|
@@ -138,8 +138,11 @@ class WPSC_Settings_Tab_Gateway extends WPSC_Settings_Tab {
|
|
138 |
}
|
139 |
|
140 |
private function gateway_list() {
|
|
|
141 |
$gateways = apply_filters( 'wpsc_settings_get_gateways', array() );
|
142 |
|
|
|
|
|
143 |
$selected_gateway = (string) get_user_option( 'wpsc_settings_selected_payment_gateway', get_current_user_id() );
|
144 |
|
145 |
foreach ( $gateways as $gateway ) {
|
@@ -147,7 +150,21 @@ class WPSC_Settings_Tab_Gateway extends WPSC_Settings_Tab {
|
|
147 |
}
|
148 |
}
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
public function callback_submit_options() {
|
151 |
do_action( 'wpsc_submit_gateway_options' );
|
152 |
}
|
153 |
-
}
|
91 |
</tbody>
|
92 |
</table>
|
93 |
<?php submit_button( __( 'Save Changes' ) ); ?>
|
94 |
+
<h4><?php _e( 'WP eCommerce Recommends', 'wpsc' ); ?></h4>
|
95 |
<a style="border-bottom:none;" href="https://www.paypal.com/nz/mrb/pal=LENKCHY6CU2VY" target="_blank"><img src="<?php echo WPSC_CORE_IMAGES_URL; ?>/paypal-referal.gif" border="0" alt="<?php esc_attr_e( 'Sign up for PayPal and start accepting credit card payments instantly.', 'wpsc' ); ?>" /></a>
|
96 |
<?php
|
97 |
}
|
138 |
}
|
139 |
|
140 |
private function gateway_list() {
|
141 |
+
|
142 |
$gateways = apply_filters( 'wpsc_settings_get_gateways', array() );
|
143 |
|
144 |
+
usort( $gateways, apply_filters( 'wpsc_settings_get_gateways_sort_callback', array( $this, 'gateway_usort_callback' ), $gateways, $this ) );
|
145 |
+
|
146 |
$selected_gateway = (string) get_user_option( 'wpsc_settings_selected_payment_gateway', get_current_user_id() );
|
147 |
|
148 |
foreach ( $gateways as $gateway ) {
|
150 |
}
|
151 |
}
|
152 |
|
153 |
+
/**
|
154 |
+
* Usort callback used to order gateways by their name.
|
155 |
+
*
|
156 |
+
* @param array $a A gateway array.
|
157 |
+
* @param array $b A different gateway array.
|
158 |
+
*
|
159 |
+
* @since 3.9.0
|
160 |
+
*
|
161 |
+
* @return bool True if $b should be ordered after $a based on its name.
|
162 |
+
*/
|
163 |
+
private function gateway_usort_callback( $a, $b ) {
|
164 |
+
return $a['name'] > $b['name'];
|
165 |
+
}
|
166 |
+
|
167 |
public function callback_submit_options() {
|
168 |
do_action( 'wpsc_submit_gateway_options' );
|
169 |
}
|
170 |
+
}
|
wpsc-admin/includes/settings-tabs/marketing.php
CHANGED
@@ -168,6 +168,17 @@ class WPSC_Settings_Tab_Marketing extends WPSC_Settings_Tab {
|
|
168 |
<span class='description'><?php _e( 'e.g. <code>UA-XXXXX-Y</code>', 'wpsc' ); ?></span>
|
169 |
</td>
|
170 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
<tr>
|
172 |
<th>
|
173 |
<?php _e( 'Tracking Code Present', 'wpsc' ); ?>
|
168 |
<span class='description'><?php _e( 'e.g. <code>UA-XXXXX-Y</code>', 'wpsc' ); ?></span>
|
169 |
</td>
|
170 |
</tr>
|
171 |
+
<tr>
|
172 |
+
<th>
|
173 |
+
<?php _e( 'Universal Analytics', 'wpsc' ); ?>
|
174 |
+
</th>
|
175 |
+
<td>
|
176 |
+
<label>
|
177 |
+
<input value="1" <?php checked( '1', get_option( 'wpsc_ga_use_universal' ) ); ?> type="checkbox" name="wpsc_ga_use_universal" />
|
178 |
+
<?php printf( __( 'Use <a%s>Universal Analytics</a> tracking code', 'wpsc' ), ' href="https://support.google.com/analytics/answer/2790010?hl=en-GB&ref_topic=6010376" target="universal_analytics"' ); ?>
|
179 |
+
</label>
|
180 |
+
</td>
|
181 |
+
</tr>
|
182 |
<tr>
|
183 |
<th>
|
184 |
<?php _e( 'Tracking Code Present', 'wpsc' ); ?>
|
wpsc-admin/includes/settings-tabs/shipping.php
CHANGED
@@ -53,6 +53,10 @@ class WPSC_Settings_Tab_Shipping extends WPSC_Settings_Tab {
|
|
53 |
}
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
56 |
if ( ! get_option( 'do_not_use_shipping' ) && ! get_option( 'custom_shipping_options' ) && ! ( bool ) get_option( 'shipwire' ) ) {
|
57 |
update_option( 'do_not_use_shipping', '1' );
|
58 |
return array( 'shipping_disabled' => 1 );
|
@@ -164,7 +168,7 @@ class WPSC_Settings_Tab_Shipping extends WPSC_Settings_Tab {
|
|
164 |
<input type='hidden' value='0' name='wpsc_options[shipwire]' />
|
165 |
<input type='checkbox' onclick='jQuery("#wpsc_shipwire_setting").toggle( jQuery(this).prop("checked") );' value='1' name='wpsc_options[shipwire]' id='shipwire' <?php checked( '1', get_option( 'shipwire' ) ); ?> />
|
166 |
<label for='shipwire'><?php _e( 'Enable Shipwire Integration', 'wpsc' ); ?></label>
|
167 |
-
<p class='description'><?php printf( __( '<a href="%1$s" target="_blank">Shipwire</a> provide e-commerce fulfillment warehouses. WP
|
168 |
</td>
|
169 |
</tr>
|
170 |
<?php
|
@@ -233,11 +237,11 @@ class WPSC_Settings_Tab_Shipping extends WPSC_Settings_Tab {
|
|
233 |
<td> </td>
|
234 |
<td colspan="2">
|
235 |
<?php
|
236 |
-
$value =
|
237 |
?>
|
238 |
<div <?php echo $shipping_discount_settings; ?> id='shipping_discount_value'>
|
239 |
|
240 |
-
<?php printf( __( 'Sales over or equal to %1$s<input type="text" size="6" name="wpsc_options[shipping_discount_value]" value="%2$s" id="shipping_discount_value" /> will receive free shipping.', 'wpsc' ), $currency_sign, $value ); ?>
|
241 |
</div>
|
242 |
</td>
|
243 |
</tr>
|
@@ -246,7 +250,7 @@ class WPSC_Settings_Tab_Shipping extends WPSC_Settings_Tab {
|
|
246 |
<?php submit_button( __( 'Save Changes' ) ); ?>
|
247 |
|
248 |
<h3><?php _e( 'Shipping Modules', 'wpsc' ) ?></h3>
|
249 |
-
<p class='description'><?php _e( 'To enable shipping in WP
|
250 |
<p class='description'>
|
251 |
<strong><?php _e( 'Tip', 'wpsc' ); ?></strong>:
|
252 |
<?php printf( __( 'For fixed-price shipping options such as "Pickup - $0, Overnight - $10, Same day - $20, etc.", install our free <a href="%1$s">Fixed Rate Shipping</a> plugin.', 'wpsc' ), 'http://wordpress.org/extend/plugins/wp-e-commerce-fixed-rate-shipping/' ); ?>
|
53 |
}
|
54 |
}
|
55 |
|
56 |
+
if ( isset( $_POST['wpsc_options']['shipping_discount_value'] ) ) {
|
57 |
+
update_option( 'shipping_discount_value', wpsc_string_to_float( $_POST['wpsc_options']['shipping_discount_value'] ) );
|
58 |
+
}
|
59 |
+
|
60 |
if ( ! get_option( 'do_not_use_shipping' ) && ! get_option( 'custom_shipping_options' ) && ! ( bool ) get_option( 'shipwire' ) ) {
|
61 |
update_option( 'do_not_use_shipping', '1' );
|
62 |
return array( 'shipping_disabled' => 1 );
|
168 |
<input type='hidden' value='0' name='wpsc_options[shipwire]' />
|
169 |
<input type='checkbox' onclick='jQuery("#wpsc_shipwire_setting").toggle( jQuery(this).prop("checked") );' value='1' name='wpsc_options[shipwire]' id='shipwire' <?php checked( '1', get_option( 'shipwire' ) ); ?> />
|
170 |
<label for='shipwire'><?php _e( 'Enable Shipwire Integration', 'wpsc' ); ?></label>
|
171 |
+
<p class='description'><?php printf( __( '<a href="%1$s" target="_blank">Shipwire</a> provide e-commerce fulfillment warehouses. WP eCommerce can integrate stock inventory and shipping tracking with their service.', 'wpsc' ), 'http://www.shipwire.com/' ); ?></p>
|
172 |
</td>
|
173 |
</tr>
|
174 |
<?php
|
237 |
<td> </td>
|
238 |
<td colspan="2">
|
239 |
<?php
|
240 |
+
$value = wpsc_format_number( get_option( 'shipping_discount_value' ) );
|
241 |
?>
|
242 |
<div <?php echo $shipping_discount_settings; ?> id='shipping_discount_value'>
|
243 |
|
244 |
+
<?php printf( __( 'Sales over or equal to %1$s<input type="text" size="6" name="wpsc_options[shipping_discount_value]" value="%2$s" id="shipping_discount_value" /> will receive free shipping.', 'wpsc' ), $currency_sign, esc_attr( $value ) ); ?>
|
245 |
</div>
|
246 |
</td>
|
247 |
</tr>
|
250 |
<?php submit_button( __( 'Save Changes' ) ); ?>
|
251 |
|
252 |
<h3><?php _e( 'Shipping Modules', 'wpsc' ) ?></h3>
|
253 |
+
<p class='description'><?php _e( 'To enable shipping in WP eCommerce you must select which shipping methods you want to enable on your site.', 'wpsc' ); ?></p>
|
254 |
<p class='description'>
|
255 |
<strong><?php _e( 'Tip', 'wpsc' ); ?></strong>:
|
256 |
<?php printf( __( 'For fixed-price shipping options such as "Pickup - $0, Overnight - $10, Same day - $20, etc.", install our free <a href="%1$s">Fixed Rate Shipping</a> plugin.', 'wpsc' ), 'http://wordpress.org/extend/plugins/wp-e-commerce-fixed-rate-shipping/' ); ?>
|
wpsc-admin/includes/tax_and_shipping.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
global $wpdb;
|
3 |
$changes_made = false;
|
4 |
$country_isocode = preg_match( "/[a-zA-Z]{2,4}/", $_GET['isocode'] ) ? $_GET['isocode'] : get_option( 'base_country' );
|
@@ -57,4 +63,4 @@ $base_region = get_option('base_region');
|
|
57 |
<input type='hidden' name='wpsc_admin_action' value='change_region_tax' />
|
58 |
<input class='button-secondary' type='submit' name='submit' value='<?php esc_attr_e( 'Save Changes', 'wpsc' );?>' />
|
59 |
</form>
|
60 |
-
</div>
|
1 |
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The HTML outputting the tax and shipping form
|
5 |
+
*
|
6 |
+
* @package wp-e-commerce
|
7 |
+
*/
|
8 |
global $wpdb;
|
9 |
$changes_made = false;
|
10 |
$country_isocode = preg_match( "/[a-zA-Z]{2,4}/", $_GET['isocode'] ) ? $_GET['isocode'] : get_option( 'base_country' );
|
63 |
<input type='hidden' name='wpsc_admin_action' value='change_region_tax' />
|
64 |
<input class='button-secondary' type='submit' name='submit' value='<?php esc_attr_e( 'Save Changes', 'wpsc' );?>' />
|
65 |
</form>
|
66 |
+
</div>
|
wpsc-admin/includes/updating-functions.php
CHANGED
@@ -57,13 +57,15 @@ class WPSC_Update {
|
|
57 |
}
|
58 |
|
59 |
public function run( $function, $message = '' ) {
|
60 |
-
|
|
|
61 |
echo "<p>{$message}</p>";
|
|
|
62 |
|
63 |
if ( empty( $this->stages[$function] ) ) {
|
64 |
call_user_func( 'wpsc_' . $function );
|
65 |
-
$this->stages[$function] = true;
|
66 |
-
set_transient( 'wpsc_update_progress', $this->stages,
|
67 |
}
|
68 |
}
|
69 |
}
|
@@ -116,7 +118,8 @@ class WPSC_Update_Progress {
|
|
116 |
|
117 |
private function print_eta() {
|
118 |
echo '<div class="eta">';
|
119 |
-
_e( 'Estimated time left:', 'wpsc' )
|
|
|
120 |
if ( $this->eta == 0 )
|
121 |
_e( 'Under a minute', 'wpsc' );
|
122 |
else
|
@@ -180,7 +183,8 @@ function wpsc_update_step( $i, $total ) {
|
|
180 |
$processed = $i - $count + 1;
|
181 |
$eta = floor( ( $total - $i ) * ( $now - $start ) / ( $processed * 60 ) );
|
182 |
echo '<div class="eta">';
|
183 |
-
_e( 'Estimated time left:', 'wpsc' )
|
|
|
184 |
if ( $eta == 0 )
|
185 |
_e( 'Under a minute', 'wpsc' );
|
186 |
else
|
57 |
}
|
58 |
|
59 |
public function run( $function, $message = '' ) {
|
60 |
+
|
61 |
+
if ( $message ) {
|
62 |
echo "<p>{$message}</p>";
|
63 |
+
}
|
64 |
|
65 |
if ( empty( $this->stages[$function] ) ) {
|
66 |
call_user_func( 'wpsc_' . $function );
|
67 |
+
$this->stages[ $function ] = true;
|
68 |
+
set_transient( 'wpsc_update_progress', $this->stages, WEEK_IN_SECONDS );
|
69 |
}
|
70 |
}
|
71 |
}
|
118 |
|
119 |
private function print_eta() {
|
120 |
echo '<div class="eta">';
|
121 |
+
_e( 'Estimated time left:', 'wpsc' );
|
122 |
+
echo ' ';
|
123 |
if ( $this->eta == 0 )
|
124 |
_e( 'Under a minute', 'wpsc' );
|
125 |
else
|
183 |
$processed = $i - $count + 1;
|
184 |
$eta = floor( ( $total - $i ) * ( $now - $start ) / ( $processed * 60 ) );
|
185 |
echo '<div class="eta">';
|
186 |
+
_e( 'Estimated time left:', 'wpsc' );
|
187 |
+
echo ' ';
|
188 |
if ( $eta == 0 )
|
189 |
_e( 'Under a minute', 'wpsc' );
|
190 |
else
|
wpsc-admin/init.php
CHANGED
@@ -264,10 +264,10 @@ function wpsc_admin_sale_rss() {
|
|
264 |
$output .= "<?xml version='1.0'?>\n\r";
|
265 |
$output .= "<rss version='2.0'>\n\r";
|
266 |
$output .= " <channel>\n\r";
|
267 |
-
$output .= " <title>" . _x( 'WP
|
268 |
$output .= " <link>" . admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "</link>\n\r";
|
269 |
-
$output .= " <description>" . _x( 'This is the WP
|
270 |
-
$output .= " <generator>" . _x( 'WP
|
271 |
|
272 |
foreach ( (array)$purchase_log as $purchase ) {
|
273 |
$purchase_link = admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "&purchaseid=" . $purchase['id'];
|
@@ -288,40 +288,115 @@ function wpsc_admin_sale_rss() {
|
|
288 |
}
|
289 |
}
|
290 |
|
291 |
-
if ( isset( $_GET['action'] ) && ( 'purchase_log' == $_GET['action'] ) )
|
292 |
add_action( 'admin_init', 'wpsc_admin_sale_rss' );
|
|
|
293 |
|
294 |
/**
|
295 |
-
* Purchase
|
|
|
|
|
|
|
|
|
|
|
296 |
*/
|
297 |
-
function
|
298 |
|
299 |
if ( ! wpsc_is_store_admin() ) {
|
300 |
return;
|
301 |
}
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
|
|
|
|
309 |
}
|
310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
$sendback = wp_get_referer();
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
|
|
|
|
|
|
|
|
|
316 |
wp_redirect( $sendback );
|
317 |
exit();
|
|
|
318 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
|
320 |
-
if ( isset( $_REQUEST['email_buyer_id'] ) && is_numeric( $_REQUEST['email_buyer_id'] ) ) {
|
321 |
-
add_action( 'admin_init', 'wpsc_purchlog_resend_email' );
|
322 |
}
|
|
|
323 |
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
|
326 |
if ( ! wpsc_is_store_admin() ) {
|
327 |
return;
|
@@ -329,40 +404,87 @@ function wpsc_purchlog_clear_download_items() {
|
|
329 |
|
330 |
global $wpdb;
|
331 |
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
|
336 |
-
|
337 |
-
$
|
|
|
|
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
|
|
|
|
348 |
}
|
349 |
|
|
|
350 |
|
351 |
-
|
352 |
|
353 |
-
|
354 |
|
355 |
-
|
356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
}
|
358 |
|
359 |
-
|
360 |
-
|
|
|
|
|
361 |
}
|
|
|
|
|
|
|
362 |
}
|
363 |
|
|
|
364 |
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'clear_locks') ) {
|
365 |
-
|
366 |
}
|
367 |
|
368 |
//bulk actions for purchase log
|
@@ -381,8 +503,12 @@ function wpsc_purchlog_bulk_modify() {
|
|
381 |
} elseif ( $_POST['purchlog_multiple_status_change'] == 'delete' ) {
|
382 |
foreach ( (array)$_POST['purchlogids'] as $purchlogid ) {
|
383 |
|
384 |
-
|
385 |
-
$
|
|
|
|
|
|
|
|
|
386 |
}
|
387 |
}
|
388 |
}
|
@@ -407,79 +533,57 @@ if ( isset( $_REQUEST['wpsc_admin_action2'] ) && ($_REQUEST['wpsc_admin_action2'
|
|
407 |
add_action( 'admin_init', 'wpsc_purchlog_bulk_modify' );
|
408 |
}
|
409 |
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
|
|
|
|
|
|
|
|
415 |
$purchlog_id = absint( $_POST['purchlog_id'] );
|
416 |
$purchlog_notes = stripslashes( $_POST['purchlog_notes'] );
|
417 |
}
|
418 |
-
$wpdb->update(
|
419 |
-
WPSC_TABLE_PURCHASE_LOGS,
|
420 |
-
array(
|
421 |
-
'notes' => $purchlog_notes
|
422 |
-
),
|
423 |
-
array(
|
424 |
-
'id' => $purchlog_id
|
425 |
-
),
|
426 |
-
array(
|
427 |
-
'%s'
|
428 |
-
),
|
429 |
-
array(
|
430 |
-
'%d'
|
431 |
-
)
|
432 |
-
);
|
433 |
-
}
|
434 |
-
}
|
435 |
-
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'purchlogs_update_notes' ) )
|
436 |
-
add_action( 'admin_init', 'wpsc_purchlogs_update_notes' );
|
437 |
|
438 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
|
440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
function wpsc_delete_purchlog( $purchlog_id = '' ) {
|
442 |
|
443 |
-
if ( ! wpsc_is_store_admin() ) {
|
444 |
-
return;
|
445 |
-
}
|
446 |
-
|
447 |
global $wpdb;
|
448 |
-
$deleted = 0;
|
449 |
|
|
|
450 |
if ( $purchlog_id == '' ) {
|
451 |
-
|
452 |
-
|
453 |
}
|
454 |
|
455 |
-
$
|
456 |
-
if ( $purchlog_status == 5 || $purchlog_status == 1 ) {
|
457 |
-
$claimed_query = new WPSC_Claimed_Stock( array(
|
458 |
-
'cart_id' => $purchlog_id,
|
459 |
-
'cart_submitted' => 1
|
460 |
-
) );
|
461 |
-
$claimed_query->clear_claimed_stock( 0 );
|
462 |
-
}
|
463 |
|
464 |
-
|
465 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` IN (%d)", $purchlog_id ) );
|
466 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id` = %d LIMIT 1", $purchlog_id ) );
|
467 |
|
468 |
-
$deleted = 1;
|
469 |
-
|
470 |
-
if ( is_numeric( $_GET['purchlog_id'] ) ) {
|
471 |
-
$sendback = wp_get_referer();
|
472 |
-
$sendback = remove_query_arg( array( 'c', 'id' ), $sendback );
|
473 |
-
if ( isset( $deleted ) ) {
|
474 |
-
$sendback = add_query_arg( 'deleted', $deleted, $sendback );
|
475 |
-
}
|
476 |
-
wp_redirect( $sendback );
|
477 |
-
exit();
|
478 |
-
}
|
479 |
}
|
480 |
|
481 |
-
|
482 |
-
|
|
|
483 |
}
|
484 |
|
485 |
function wpsc_update_option_product_category_hierarchical_url() {
|
@@ -509,7 +613,7 @@ add_filter( 'sanitize_option_grid_number_per_row', '_wpsc_action_sanitize_option
|
|
509 |
function _wpsc_action_update_option_require_register( $old_value, $new_value ) {
|
510 |
if ( $new_value == 1 && ! get_option( 'users_can_register' ) ) {
|
511 |
update_option( 'users_can_register', 1 );
|
512 |
-
$message = __( 'You wanted to require your customers to log in before checking out. However, the WordPress setting <a href="%s">"Anyone can register"</a> was disabled. WP
|
513 |
$message = sprintf( $message, admin_url( 'options-general.php' ) );
|
514 |
add_settings_error( 'require_register', 'users_can_register_turned_on', $message, 'updated' );
|
515 |
}
|
264 |
$output .= "<?xml version='1.0'?>\n\r";
|
265 |
$output .= "<rss version='2.0'>\n\r";
|
266 |
$output .= " <channel>\n\r";
|
267 |
+
$output .= " <title>" . _x( 'WP eCommerce Product Log', 'admin rss product feed', 'wpsc' ) . "</title>\n\r";
|
268 |
$output .= " <link>" . admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "</link>\n\r";
|
269 |
+
$output .= " <description>" . _x( 'This is the WP eCommerce Product Log RSS feed', 'admin rss product feed', 'wpsc' ) . "</description>\n\r";
|
270 |
+
$output .= " <generator>" . _x( 'WP eCommerce Plugin', 'admin rss product feed', 'wpsc' ) . "</generator>\n\r";
|
271 |
|
272 |
foreach ( (array)$purchase_log as $purchase ) {
|
273 |
$purchase_link = admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "&purchaseid=" . $purchase['id'];
|
288 |
}
|
289 |
}
|
290 |
|
291 |
+
if ( isset( $_GET['action'] ) && ( 'purchase_log' == $_GET['action'] ) ) {
|
292 |
add_action( 'admin_init', 'wpsc_admin_sale_rss' );
|
293 |
+
}
|
294 |
|
295 |
/**
|
296 |
+
* Do Purchase Log Actions
|
297 |
+
*
|
298 |
+
* All purchase log actions are capability and nonce checked before calling
|
299 |
+
* the relevent 'wpsc_purchase_log_action-{wpsc_purchase_log_action}' hook.
|
300 |
+
*
|
301 |
+
* @since 3.9.0
|
302 |
*/
|
303 |
+
function wpsc_do_purchase_log_actions() {
|
304 |
|
305 |
if ( ! wpsc_is_store_admin() ) {
|
306 |
return;
|
307 |
}
|
308 |
|
309 |
+
if ( isset( $_GET['wpsc_purchase_log_action'] ) && isset( $_GET['id'] ) && isset( $_GET['_wpnonce'] ) ) {
|
310 |
+
$wpsc_purchase_log_action = sanitize_key( $_GET['wpsc_purchase_log_action'] );
|
311 |
+
|
312 |
+
if ( wp_verify_nonce( $_GET['_wpnonce'], 'wpsc_purchase_log_action_' . $wpsc_purchase_log_action ) ) {
|
313 |
+
|
314 |
+
do_action( 'wpsc_purchase_log_action-' . $wpsc_purchase_log_action, absint( $_GET['id'] ) );
|
315 |
+
|
316 |
+
}
|
317 |
}
|
318 |
|
319 |
+
}
|
320 |
+
add_action( 'admin_init', 'wpsc_do_purchase_log_actions' );
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Handle clear downloads lock purchase log action
|
324 |
+
*
|
325 |
+
* The 'wpsc_purchase_log_action-downloads_lock' action hook which calls this function is nonce and capability checked
|
326 |
+
* in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-downloads_lock' ).
|
327 |
+
*
|
328 |
+
* @since 3.9.0
|
329 |
+
*
|
330 |
+
* @param int $log_id Purchase log ID.
|
331 |
+
*/
|
332 |
+
function wpsc_purchase_log_action_downloads_lock( $log_id ) {
|
333 |
+
|
334 |
+
wpsc_purchlog_clear_download_items( $log_id );
|
335 |
+
|
336 |
+
// Redirect back to purchase logs list
|
337 |
$sendback = wp_get_referer();
|
338 |
+
$sendback = add_query_arg( 'cleared', 1, $sendback );
|
339 |
+
wp_redirect( $sendback );
|
340 |
+
exit();
|
341 |
+
|
342 |
+
}
|
343 |
+
add_action( 'wpsc_purchase_log_action-downloads_lock', 'wpsc_purchase_log_action_downloads_lock' );
|
344 |
|
345 |
+
/**
|
346 |
+
* Handle delete purchase log action
|
347 |
+
*
|
348 |
+
* The 'wpsc_purchase_log_action-delete' action hook which calls this function is nonce and capability checked
|
349 |
+
* in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-delete' ).
|
350 |
+
*
|
351 |
+
* @since 3.9.0
|
352 |
+
*
|
353 |
+
* @param int $log_id Purchase log ID.
|
354 |
+
*/
|
355 |
+
function wpsc_purchase_log_action_delete( $log_id ) {
|
356 |
+
|
357 |
+
$log = new WPSC_Purchase_Log( $log_id );
|
358 |
+
$deleted = $log->delete();
|
359 |
|
360 |
+
// Redirect back to purchase logs list
|
361 |
+
$sendback = wp_get_referer();
|
362 |
+
$sendback = remove_query_arg( array( 'c', 'id' ), $sendback );
|
363 |
+
$sendback = add_query_arg( 'deleted', absint( $deleted ), $sendback );
|
364 |
wp_redirect( $sendback );
|
365 |
exit();
|
366 |
+
|
367 |
}
|
368 |
+
add_action( 'wpsc_purchase_log_action-delete', 'wpsc_purchase_log_action_delete' );
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Handle email receipt purchase log action
|
372 |
+
*
|
373 |
+
* The 'wpsc_purchase_log_action-email_receipt' action hook which calls this function is nonce and capability checked
|
374 |
+
* in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-email_receipt' ).
|
375 |
+
*
|
376 |
+
* @since 3.9.0
|
377 |
+
*
|
378 |
+
* @param int $log_id Purchase log ID.
|
379 |
+
*/
|
380 |
+
function wpsc_purchase_log_action_email_receipt( $log_id ) {
|
381 |
+
|
382 |
+
$sent = wpsc_purchlog_resend_email( $log_id );
|
383 |
+
|
384 |
+
// Redirect back to purchase logs list
|
385 |
+
$sendback = wp_get_referer();
|
386 |
+
$sendback = add_query_arg( 'sent', absint( $sent ), $sendback );
|
387 |
+
wp_redirect( $sendback );
|
388 |
+
exit();
|
389 |
|
|
|
|
|
390 |
}
|
391 |
+
add_action( 'wpsc_purchase_log_action-email_receipt', 'wpsc_purchase_log_action_email_receipt' );
|
392 |
|
393 |
+
/**
|
394 |
+
* Resend Purchase Log Email
|
395 |
+
*
|
396 |
+
* @param int|string $log_id Required. Purchase log ID (empty string is deprecated).
|
397 |
+
* @return boolean Sent successfully.
|
398 |
+
*/
|
399 |
+
function wpsc_purchlog_resend_email( $log_id = '' ) {
|
400 |
|
401 |
if ( ! wpsc_is_store_admin() ) {
|
402 |
return;
|
404 |
|
405 |
global $wpdb;
|
406 |
|
407 |
+
// Deprecate empty purchase log ID parameter.
|
408 |
+
if ( $log_id == '' ) {
|
409 |
+
_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( '$log_id parameter requires a numeric purchase log ID.', 'wpsc' ), '3.9.0' );
|
410 |
|
411 |
+
// Support redirect for legacy purposes for the moment
|
412 |
+
$sendback = add_query_arg( 'sent', 0, wp_get_referer() );
|
413 |
+
wp_redirect( $sendback );
|
414 |
+
exit();
|
415 |
|
416 |
+
}
|
417 |
+
|
418 |
+
$log_id = absint( $log_id );
|
419 |
+
|
420 |
+
if ( $log_id > 0 ) {
|
421 |
+
|
422 |
+
$wpec_taxes_controller = new wpec_taxes_controller();
|
423 |
+
|
424 |
+
if ( is_numeric( $log_id ) ) {
|
425 |
+
$purchase_log = new WPSC_Purchase_Log( $log_id );
|
426 |
+
return wpsc_send_customer_email( $purchase_log );
|
427 |
}
|
428 |
|
429 |
+
}
|
430 |
|
431 |
+
return false;
|
432 |
|
433 |
+
}
|
434 |
|
435 |
+
// Deprecate resending purchase log email receipt via URL query
|
436 |
+
if ( isset( $_REQUEST['email_buyer_id'] ) && is_numeric( $_REQUEST['email_buyer_id'] ) ) {
|
437 |
+
_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( 'Do not trigger resend purchase log email action via email_buyer_id URL query. Instead use the Purchase Log Action Links API.', 'wpsc' ), '3.9.0' );
|
438 |
+
}
|
439 |
+
|
440 |
+
/**
|
441 |
+
* Clear Purchase Log Download Locks
|
442 |
+
*
|
443 |
+
* @param string $log_id Required. Purchase log ID (empty string is deprecated).
|
444 |
+
* @return boolean
|
445 |
+
*/
|
446 |
+
function wpsc_purchlog_clear_download_items( $log_id = '' ) {
|
447 |
+
|
448 |
+
if ( ! wpsc_is_store_admin() ) {
|
449 |
+
return;
|
450 |
+
}
|
451 |
+
|
452 |
+
global $wpdb;
|
453 |
+
|
454 |
+
// Deprecate empty purchase log ID parameter.
|
455 |
+
if ( $log_id == '' ) {
|
456 |
+
_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( '$log_id parameter requires a numeric purchase log ID.', 'wpsc' ), '3.9.0' );
|
457 |
+
return false;
|
458 |
+
}
|
459 |
+
|
460 |
+
$log_id = absint( $log_id );
|
461 |
+
|
462 |
+
if ( $log_id > 0 ) {
|
463 |
+
|
464 |
+
$downloadable_items = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid` = %d", $log_id ), ARRAY_A );
|
465 |
+
|
466 |
+
$wpdb->update( WPSC_TABLE_DOWNLOAD_STATUS, array( 'ip_number' => '' ), array( 'purchid' => $log_id ), '%s', '%d' );
|
467 |
+
|
468 |
+
$email_form_field = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `checkout_order` ASC LIMIT 1" );
|
469 |
+
$email_address = $wpdb->get_var( $wpdb->prepare( "SELECT `value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = '{$email_form_field}' LIMIT 1", $log_id ) );
|
470 |
+
|
471 |
+
foreach ( $downloadable_items as $downloadable_item ) {
|
472 |
+
$download_links .= add_query_arg( 'downloadid', $downloadable_item['uniqueid'], home_url() ) . "\n";
|
473 |
}
|
474 |
|
475 |
+
wp_mail( $email_address, __( 'The administrator has unlocked your file', 'wpsc' ), str_replace( "[download_links]", $download_links, __( 'Dear CustomerWe are pleased to advise you that your order has been updated and your downloads are now active.Please download your purchase using the links provided below.[download_links]Thank you for your custom.', 'wpsc' ) ), "From: " . get_option( 'return_email' ) );
|
476 |
+
|
477 |
+
return true;
|
478 |
+
|
479 |
}
|
480 |
+
|
481 |
+
return false;
|
482 |
+
|
483 |
}
|
484 |
|
485 |
+
// Deprecate clearing purchase log download locks via URL query
|
486 |
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'clear_locks') ) {
|
487 |
+
_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( 'Do not trigger clear purchase log download locks action via wpsc_admin_action = clear_locks URL query. Instead use the Purchase Log Action Links API.', 'wpsc' ), '3.9.0' );
|
488 |
}
|
489 |
|
490 |
//bulk actions for purchase log
|
503 |
} elseif ( $_POST['purchlog_multiple_status_change'] == 'delete' ) {
|
504 |
foreach ( (array)$_POST['purchlogids'] as $purchlogid ) {
|
505 |
|
506 |
+
$log = new WPSC_Purchase_Log( $purchlogid );
|
507 |
+
$deleted_log = $log->delete();
|
508 |
+
if ( $deleted_log ) {
|
509 |
+
$deleted++;
|
510 |
+
}
|
511 |
+
|
512 |
}
|
513 |
}
|
514 |
}
|
533 |
add_action( 'admin_init', 'wpsc_purchlog_bulk_modify' );
|
534 |
}
|
535 |
|
536 |
+
/**
|
537 |
+
* Update Purchase Log Notes
|
538 |
+
*
|
539 |
+
* @param int $purchlog_id Purchase log ID.
|
540 |
+
* @param string $purchlog_notes Notes.
|
541 |
+
*/
|
542 |
+
function wpsc_purchlogs_update_notes( $purchlog_id = 0, $purchlog_notes = '' ) {
|
543 |
+
if ( isset( $_POST['wpsc_purchlogs_update_notes_nonce'] ) && wp_verify_nonce( $_POST['wpsc_purchlogs_update_notes_nonce'], 'wpsc_purchlogs_update_notes' ) ) {
|
544 |
+
if ( 0 == $purchlog_id && isset( $_POST['purchlog_id'] ) && '' == $purchlog_notes ) {
|
545 |
$purchlog_id = absint( $_POST['purchlog_id'] );
|
546 |
$purchlog_notes = stripslashes( $_POST['purchlog_notes'] );
|
547 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
548 |
|
549 |
+
if ( $purchlog_id > 0 ) {
|
550 |
+
$purchase_log = new WPSC_Purchase_Log( $purchlog_id );
|
551 |
+
$purchase_log->set( 'notes', $purchlog_notes );
|
552 |
+
$purchase_log->save();
|
553 |
+
}
|
554 |
+
}
|
555 |
+
}
|
556 |
+
if ( isset( $_REQUEST['wpsc_admin_action'] ) && $_REQUEST['wpsc_admin_action'] == 'purchlogs_update_notes' ) {
|
557 |
+
add_action( 'admin_init', 'wpsc_purchlogs_update_notes' );
|
558 |
+
}
|
559 |
|
560 |
+
/**
|
561 |
+
* Delete a purchase log
|
562 |
+
*
|
563 |
+
* @deprecated Use WPSC_Purchase_Log->delete() instead.
|
564 |
+
*
|
565 |
+
* @param int|string $purchlog_id Required. Purchase log ID (empty string is deprecated).
|
566 |
+
* @return boolean Deleted successfully.
|
567 |
+
*/
|
568 |
function wpsc_delete_purchlog( $purchlog_id = '' ) {
|
569 |
|
|
|
|
|
|
|
|
|
570 |
global $wpdb;
|
|
|
571 |
|
572 |
+
// Deprecate empty purchase log ID parameter.
|
573 |
if ( $purchlog_id == '' ) {
|
574 |
+
_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( '$purchlog_id parameter requires a numeric purchase log ID.', 'wpsc' ), '3.9.0' );
|
575 |
+
return false;
|
576 |
}
|
577 |
|
578 |
+
$log = new WPSC_Purchase_Log( $purchlog_id );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
579 |
|
580 |
+
return $log->delete();
|
|
|
|
|
581 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
}
|
583 |
|
584 |
+
// Deprecate deleting purchase log via URL query
|
585 |
+
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'delete_purchlog' ) ) {
|
586 |
+
_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( 'Do not trigger delete purchase log action via wpsc_admin_action = delete_purchlog URL query. Instead use the Purchase Log Action Links API.', 'wpsc' ), '3.9.0' );
|
587 |
}
|
588 |
|
589 |
function wpsc_update_option_product_category_hierarchical_url() {
|
613 |
function _wpsc_action_update_option_require_register( $old_value, $new_value ) {
|
614 |
if ( $new_value == 1 && ! get_option( 'users_can_register' ) ) {
|
615 |
update_option( 'users_can_register', 1 );
|
616 |
+
$message = __( 'You wanted to require your customers to log in before checking out. However, the WordPress setting <a href="%s">"Anyone can register"</a> was disabled. WP eCommerce has enabled that setting for you automatically.', 'wpsc' );
|
617 |
$message = sprintf( $message, admin_url( 'options-general.php' ) );
|
618 |
add_settings_error( 'require_register', 'users_can_register_turned_on', $message, 'updated' );
|
619 |
}
|
wpsc-admin/js/admin.js
CHANGED
@@ -63,6 +63,10 @@
|
|
63 |
};
|
64 |
|
65 |
$(function(){
|
|
|
|
|
|
|
|
|
66 |
var table = $('body.edit-tags-php .wp-list-table');
|
67 |
table.find('tbody tr').each(function(){
|
68 |
var t = $(this),
|
@@ -579,6 +583,7 @@ function wpsc_update_product_gallery_tab(obj){
|
|
579 |
output += '<li>';
|
580 |
output += '<img src="' + url + '">';
|
581 |
output += '<input type="hidden" name="wpsc-product-gallery-imgs[]" value="' + obj[i].id + '">';
|
|
|
582 |
output += '</li>';
|
583 |
}
|
584 |
|
63 |
};
|
64 |
|
65 |
$(function(){
|
66 |
+
if ( 'undefined' === typeof WPSC_Term_List_Levels ) {
|
67 |
+
return;
|
68 |
+
}
|
69 |
+
|
70 |
var table = $('body.edit-tags-php .wp-list-table');
|
71 |
table.find('tbody tr').each(function(){
|
72 |
var t = $(this),
|
583 |
output += '<li>';
|
584 |
output += '<img src="' + url + '">';
|
585 |
output += '<input type="hidden" name="wpsc-product-gallery-imgs[]" value="' + obj[i].id + '">';
|
586 |
+
|
587 |
output += '</li>';
|
588 |
}
|
589 |
|
wpsc-admin/js/purchase-log-action-links.js
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
( function( $ ) {
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Purchase Log Action Links
|
6 |
+
*/
|
7 |
+
$.extend( WPSC_Purchase_Log_Action_Links, {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Setup purchase log action links and event handlers.
|
11 |
+
*
|
12 |
+
* @since 3.9.0
|
13 |
+
*/
|
14 |
+
init : function() {
|
15 |
+
|
16 |
+
$( function() {
|
17 |
+
var wrapper = $( '#wpsc_purchlogitems_links ul' );
|
18 |
+
|
19 |
+
// Add spinners to AJAX links
|
20 |
+
wrapper.find( 'a.wpsc-purchlog-action-link.is-ajax' ).each( function() {
|
21 |
+
$( this ).prepend( $( '<span class="spinner" />' ) );
|
22 |
+
} );
|
23 |
+
|
24 |
+
wrapper.on( 'click', 'a.wpsc-purchlog-action-link.is-ajax', WPSC_Purchase_Log_Action_Links.event_ajax_link_clicked );
|
25 |
+
} );
|
26 |
+
|
27 |
+
},
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Handle purchase log action link click.
|
31 |
+
*
|
32 |
+
* @since 3.9.0
|
33 |
+
*/
|
34 |
+
event_ajax_link_clicked : function( e ) {
|
35 |
+
|
36 |
+
var action = $( this ).data( 'purchase-log-action' );
|
37 |
+
var nonce = $( this ).data( 'nonce' );
|
38 |
+
|
39 |
+
if ( action ) {
|
40 |
+
|
41 |
+
// Only do AJAX request if not already doing it.
|
42 |
+
if ( ! $( this ).hasClass( 'doing' ) ) {
|
43 |
+
|
44 |
+
var post_data = {
|
45 |
+
'action' : 'purchase_log_action_link',
|
46 |
+
'purchase_log_action_link' : action,
|
47 |
+
'purchase_log_action_nonce' : nonce,
|
48 |
+
'log_id' : WPSC_Purchase_Log_Action_Links.log_id,
|
49 |
+
'nonce' : WPSC_Purchase_Log_Action_Links.purchase_log_action_link_nonce
|
50 |
+
};
|
51 |
+
|
52 |
+
$( this ).addClass( 'doing' );
|
53 |
+
$.wpsc_post( post_data, WPSC_Purchase_Log_Action_Links.ajax_callback );
|
54 |
+
|
55 |
+
}
|
56 |
+
|
57 |
+
e.preventDefault();
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
},
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Handle purchase log action AJAX response.
|
65 |
+
*
|
66 |
+
* @since 3.9.0
|
67 |
+
*/
|
68 |
+
ajax_callback : function( response ) {
|
69 |
+
|
70 |
+
// If AJAX successful and purchase log action successful.
|
71 |
+
if ( response.is_successful && response.obj.success ) {
|
72 |
+
|
73 |
+
var dashicon = $( '#wpsc_purchlogitems_links ul a.wpsc-purchlog-action-link-' + response.obj.purchase_log_action_link + ' .dashicons' );
|
74 |
+
var dashicon_class = dashicon.attr( 'class' );
|
75 |
+
|
76 |
+
// Successful notification.
|
77 |
+
dashicon.removeClass().addClass( 'dashicons dashicons-yes' );
|
78 |
+
setTimeout( function() {
|
79 |
+
dashicon.removeClass().addClass( dashicon_class );
|
80 |
+
}, 3000 );
|
81 |
+
|
82 |
+
// Remove spinner
|
83 |
+
$( '#wpsc_purchlogitems_links ul a.wpsc-purchlog-action-link.doing' ).removeClass( 'doing' );
|
84 |
+
|
85 |
+
} else {
|
86 |
+
|
87 |
+
// Ideally we'd always like to know which link was clicked, but we don't
|
88 |
+
// so just clear all spinners and only clear specific spinner if AJAX response was processed.
|
89 |
+
|
90 |
+
var dashicon = $( '#wpsc_purchlogitems_links ul a.wpsc-purchlog-action-link.doing .dashicons' );
|
91 |
+
if ( response.is_successful ) {
|
92 |
+
dashicon = $( '#wpsc_purchlogitems_links ul a.wpsc-purchlog-action-link-' + response.obj.purchase_log_action_link + ' .dashicons' );
|
93 |
+
}
|
94 |
+
var dashicon_class = dashicon.attr( 'class' );
|
95 |
+
|
96 |
+
if ( response.obj.success != null ) {
|
97 |
+
|
98 |
+
// Failure notification.
|
99 |
+
dashicon.removeClass().addClass( 'dashicons dashicons-no' );
|
100 |
+
setTimeout( function() {
|
101 |
+
dashicon.removeClass().addClass( dashicon_class );
|
102 |
+
}, 3000 );
|
103 |
+
|
104 |
+
} else {
|
105 |
+
dashicon.removeClass().addClass( dashicon_class );
|
106 |
+
}
|
107 |
+
|
108 |
+
// Remove spinner.
|
109 |
+
$( '#wpsc_purchlogitems_links ul a.wpsc-purchlog-action-link.doing' ).removeClass( 'doing' );
|
110 |
+
|
111 |
+
// Show error message.
|
112 |
+
if ( typeof response.error !== 'undefined' ) {
|
113 |
+
alert( response.error.messages.join( "\n" ) );
|
114 |
+
}
|
115 |
+
|
116 |
+
}
|
117 |
+
|
118 |
+
}
|
119 |
+
|
120 |
+
} );
|
121 |
+
|
122 |
+
} )( jQuery );
|
123 |
+
|
124 |
+
WPSC_Purchase_Log_Action_Links.init();
|
wpsc-admin/js/variations.js
CHANGED
@@ -58,7 +58,13 @@ var wpsc_refresh_variation_iframe = function() {
|
|
58 |
};
|
59 |
|
60 |
(function($) {
|
|
|
61 |
$(function(){
|
|
|
|
|
|
|
|
|
|
|
62 |
var table = $('body.edit-tags-php .wp-list-table');
|
63 |
table.find('tbody tr').each(function(){
|
64 |
var t = $(this);
|
58 |
};
|
59 |
|
60 |
(function($) {
|
61 |
+
|
62 |
$(function(){
|
63 |
+
|
64 |
+
if ( 'undefined' === typeof WPSC_Term_List_Levels ) {
|
65 |
+
return;
|
66 |
+
}
|
67 |
+
|
68 |
var table = $('body.edit-tags-php .wp-list-table');
|
69 |
table.find('tbody tr').each(function(){
|
70 |
var t = $(this);
|
wpsc-admin/settings-page.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* WP
|
4 |
*
|
5 |
* Third-party plugin / theme developers can add their own tabs to WPEC store settings page.
|
6 |
*
|
@@ -579,6 +579,12 @@ final class WPSC_Settings_Page {
|
|
579 |
else
|
580 |
update_option( 'wpsc_ga_tracking_id', '' );
|
581 |
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
}
|
583 |
|
584 |
if (empty($_POST['countrylist2']) && !empty($_POST['wpsc_options']['currency_sign_location']))
|
1 |
<?php
|
2 |
/**
|
3 |
+
* WP eCommerce Settings Page API.
|
4 |
*
|
5 |
* Third-party plugin / theme developers can add their own tabs to WPEC store settings page.
|
6 |
*
|
579 |
else
|
580 |
update_option( 'wpsc_ga_tracking_id', '' );
|
581 |
|
582 |
+
if ( isset( $_POST['wpsc_ga_use_universal'] ) && $_POST['wpsc_ga_use_universal'] == '1' ) {
|
583 |
+
update_option( 'wpsc_ga_use_universal', 1 );
|
584 |
+
} else {
|
585 |
+
update_option( 'wpsc_ga_use_universal', 0 );
|
586 |
+
}
|
587 |
+
|
588 |
}
|
589 |
|
590 |
if (empty($_POST['countrylist2']) && !empty($_POST['wpsc_options']['currency_sign_location']))
|
wpsc-admin/users.php
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
}
|
1 |
<?php
|
2 |
+
_wpsc_deprecated_file(
|
3 |
+
__FILE__,
|
4 |
+
'3.9',
|
5 |
+
'',
|
6 |
+
__( 'The sole function that existed in users.php has now been deprecated.', 'wpsc' )
|
7 |
+
);
|
|
wpsc-components/marketplace-core-v1/library/Sputnik.php
CHANGED
@@ -16,17 +16,17 @@ class Sputnik {
|
|
16 |
/**
|
17 |
* Minimum version of WordPress that Sputnik requires
|
18 |
*/
|
19 |
-
const MINVERSION = '3.
|
20 |
|
21 |
/**
|
22 |
* Base URI for store URLs
|
23 |
*/
|
24 |
-
const SITE_BASE = '
|
25 |
|
26 |
/**
|
27 |
* Base URI for API URLs
|
28 |
*/
|
29 |
-
const API_BASE = '
|
30 |
|
31 |
/**
|
32 |
* OAuth client key
|
@@ -339,7 +339,7 @@ class Sputnik {
|
|
339 |
$cart_contents = json_decode( stripslashes( $_POST['cart_contents'] ) );
|
340 |
|
341 |
//Unset purchase log ID, since we're inserting a new one.
|
342 |
-
$data = (
|
343 |
|
344 |
unset( $data['id'] );
|
345 |
|
16 |
/**
|
17 |
* Minimum version of WordPress that Sputnik requires
|
18 |
*/
|
19 |
+
const MINVERSION = '3.9';
|
20 |
|
21 |
/**
|
22 |
* Base URI for store URLs
|
23 |
*/
|
24 |
+
const SITE_BASE = 'https://wpecommerce.org';
|
25 |
|
26 |
/**
|
27 |
* Base URI for API URLs
|
28 |
*/
|
29 |
+
const API_BASE = 'https://wpecommerce.org/wpec';
|
30 |
|
31 |
/**
|
32 |
* OAuth client key
|
339 |
$cart_contents = json_decode( stripslashes( $_POST['cart_contents'] ) );
|
340 |
|
341 |
//Unset purchase log ID, since we're inserting a new one.
|
342 |
+
$data = (array) $data;
|
343 |
|
344 |
unset( $data['id'] );
|
345 |
|
wpsc-components/marketplace-core-v1/library/Sputnik/API.php
CHANGED
@@ -7,11 +7,11 @@ class Sputnik_API {
|
|
7 |
protected static $auth = null;
|
8 |
|
9 |
/**
|
10 |
-
* For sites like
|
11 |
* we override the domain. This is because we need to ensure Baikonur receives the Saas domain,
|
12 |
* not the end-user domain. Only relevant where Sputnik is available to an end-user, not a Saas.
|
13 |
*/
|
14 |
-
protected static $domain_override = '
|
15 |
|
16 |
public static function get_all($page = 1, $params = null) {
|
17 |
$url = '/';
|
@@ -22,17 +22,22 @@ class Sputnik_API {
|
|
22 |
return self::request($url, $params);
|
23 |
}
|
24 |
|
25 |
-
|
26 |
-
$url = '/
|
27 |
-
|
28 |
-
|
|
|
29 |
}
|
30 |
-
|
31 |
-
|
|
|
32 |
);
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
|
37 |
public static function get_single($name, $user = 0) {
|
38 |
$params = array(
|
@@ -118,7 +123,7 @@ class Sputnik_API {
|
|
118 |
<head>
|
119 |
<title><?php _e( 'Redirecting ...', 'wpsc' ); ?></title>
|
120 |
<script type="text/javascript">
|
121 |
-
parent.location = '<?php echo
|
122 |
window.close();
|
123 |
</script>
|
124 |
</head>
|
@@ -186,39 +191,44 @@ class Sputnik_API {
|
|
186 |
return $response;
|
187 |
}
|
188 |
|
189 |
-
|
190 |
/* Helper Methods */
|
191 |
public static function request($url, $params = null, $args = array()) {
|
192 |
-
|
|
|
193 |
$url = add_query_arg( $params, $url );
|
|
|
|
|
|
|
194 |
|
195 |
-
$
|
196 |
-
$args = wp_parse_args($args, $defaults);
|
197 |
|
198 |
-
if (strpos($url, 'http') !== 0) {
|
199 |
$url = Sputnik::API_BASE . $url;
|
200 |
}
|
201 |
|
202 |
-
$args['timeout']
|
203 |
-
|
204 |
$args['headers']['X-WP-Domain'] = self::domain();
|
205 |
|
206 |
$request = wp_remote_request( $url, $args );
|
207 |
|
208 |
-
if (is_wp_error($request)) {
|
209 |
-
throw new Exception($request->get_error_message());
|
210 |
}
|
211 |
|
212 |
-
if ($request['response']['code'] != 200) {
|
213 |
throw new Exception($request['body'], $request['response']['code']);
|
214 |
}
|
|
|
215 |
$result = json_decode($request['body']);
|
216 |
|
217 |
if ($result === null) {
|
218 |
throw new Exception($request['body'], $request['response']['code']);
|
219 |
}
|
|
|
220 |
$request['body'] = $result;
|
221 |
|
|
|
222 |
return $request;
|
223 |
}
|
224 |
|
7 |
protected static $auth = null;
|
8 |
|
9 |
/**
|
10 |
+
* For sites like WPeCommerce.org that will distribute Sputnik with a plugin to sell WP plugins,
|
11 |
* we override the domain. This is because we need to ensure Baikonur receives the Saas domain,
|
12 |
* not the end-user domain. Only relevant where Sputnik is available to an end-user, not a Saas.
|
13 |
*/
|
14 |
+
protected static $domain_override = 'https://wpecommerce.org';
|
15 |
|
16 |
public static function get_all($page = 1, $params = null) {
|
17 |
$url = '/';
|
22 |
return self::request($url, $params);
|
23 |
}
|
24 |
|
25 |
+
public static function search( $query, $params = null, $page = 1 ) {
|
26 |
+
$url = '/';
|
27 |
+
|
28 |
+
if ( $page !== 1 ) {
|
29 |
+
$url = sprintf( '/page/%d', $page );
|
30 |
}
|
31 |
+
|
32 |
+
$extra = array(
|
33 |
+
'query' => $query
|
34 |
);
|
35 |
|
36 |
+
$params = array_merge( $params, $extra );
|
37 |
+
|
38 |
+
return self::request( $url, $params );
|
39 |
+
}
|
40 |
+
|
41 |
|
42 |
public static function get_single($name, $user = 0) {
|
43 |
$params = array(
|
123 |
<head>
|
124 |
<title><?php _e( 'Redirecting ...', 'wpsc' ); ?></title>
|
125 |
<script type="text/javascript">
|
126 |
+
parent.location = '<?php echo wp_validate_redirect( $return_url ); ?>';
|
127 |
window.close();
|
128 |
</script>
|
129 |
</head>
|
191 |
return $response;
|
192 |
}
|
193 |
|
|
|
194 |
/* Helper Methods */
|
195 |
public static function request($url, $params = null, $args = array()) {
|
196 |
+
|
197 |
+
if ( ! empty( $params ) ) {
|
198 |
$url = add_query_arg( $params, $url );
|
199 |
+
}
|
200 |
+
|
201 |
+
$defaults = array( 'method' => 'GET' );
|
202 |
|
203 |
+
$args = wp_parse_args( $args, $defaults );
|
|
|
204 |
|
205 |
+
if ( strpos( $url, 'http' ) !== 0 ) {
|
206 |
$url = Sputnik::API_BASE . $url;
|
207 |
}
|
208 |
|
209 |
+
$args['timeout'] = 25;
|
210 |
+
$args['headers']['user-agent'] = 'WP eCommerce Marketplace: ' . WPSC_VERSION;
|
211 |
$args['headers']['X-WP-Domain'] = self::domain();
|
212 |
|
213 |
$request = wp_remote_request( $url, $args );
|
214 |
|
215 |
+
if ( is_wp_error( $request ) ) {
|
216 |
+
throw new Exception( $request->get_error_message() );
|
217 |
}
|
218 |
|
219 |
+
if ( $request['response']['code'] != 200 ) {
|
220 |
throw new Exception($request['body'], $request['response']['code']);
|
221 |
}
|
222 |
+
|
223 |
$result = json_decode($request['body']);
|
224 |
|
225 |
if ($result === null) {
|
226 |
throw new Exception($request['body'], $request['response']['code']);
|
227 |
}
|
228 |
+
|
229 |
$request['body'] = $result;
|
230 |
|
231 |
+
|
232 |
return $request;
|
233 |
}
|
234 |
|
wpsc-components/marketplace-core-v1/library/Sputnik/API/Auth.php
CHANGED
@@ -109,7 +109,8 @@ class Sputnik_API_Auth {
|
|
109 |
|
110 |
protected function http($url, $method, $postfields = NULL) {
|
111 |
$args = array(
|
112 |
-
'method'
|
|
|
113 |
);
|
114 |
|
115 |
switch ($method) {
|
@@ -123,9 +124,6 @@ class Sputnik_API_Auth {
|
|
123 |
$args['headers'] = array( 'X-WP-Domain' => Sputnik_API::domain() );
|
124 |
|
125 |
$response = wp_remote_request($url, $args);
|
126 |
-
//echo '<pre />' . debug_print_backtrace();
|
127 |
-
//echo '<pre />' . print_r( $url, 1 );
|
128 |
-
//echo '<pre />' . print_r( $response, 1 );
|
129 |
|
130 |
if (is_wp_error($response)) {
|
131 |
throw new Exception($response->get_error_message());
|
109 |
|
110 |
protected function http($url, $method, $postfields = NULL) {
|
111 |
$args = array(
|
112 |
+
'method' => $method,
|
113 |
+
'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION
|
114 |
);
|
115 |
|
116 |
switch ($method) {
|
124 |
$args['headers'] = array( 'X-WP-Domain' => Sputnik_API::domain() );
|
125 |
|
126 |
$response = wp_remote_request($url, $args);
|
|
|
|
|
|
|
127 |
|
128 |
if (is_wp_error($response)) {
|
129 |
throw new Exception($response->get_error_message());
|
wpsc-components/marketplace-core-v1/library/Sputnik/Admin.php
CHANGED
@@ -95,7 +95,7 @@ class Sputnik_Admin {
|
|
95 |
return;
|
96 |
}
|
97 |
?>
|
98 |
-
<div class="error"><p><?php _e('The following plugins are disabled:', '
|
99 |
<ul>
|
100 |
<?php
|
101 |
foreach ($invalid as $plugin) {
|
@@ -104,10 +104,10 @@ class Sputnik_Admin {
|
|
104 |
}
|
105 |
switch ($plugin['sputnik_error']) {
|
106 |
case 'not_purchased':
|
107 |
-
$error = __('Not purchased', '
|
108 |
break;
|
109 |
default:
|
110 |
-
$error = __('Unknown error', '
|
111 |
break;
|
112 |
}
|
113 |
?>
|
@@ -127,7 +127,7 @@ class Sputnik_Admin {
|
|
127 |
if (empty($data['Sputnik ID'])) {
|
128 |
return $meta;
|
129 |
}
|
130 |
-
echo '<a class="sputnik-plugin-row-note" href="' . self::build_url() . '"><span class="powered">' . __('Powered by WPEConomy', '
|
131 |
return $meta;
|
132 |
}
|
133 |
|
@@ -137,6 +137,8 @@ class Sputnik_Admin {
|
|
137 |
return;
|
138 |
}
|
139 |
|
|
|
|
|
140 |
if (self::$page === 'dash') {
|
141 |
self::$list_table = new Sputnik_List_Install();
|
142 |
$pagenum = self::$list_table->get_pagenum();
|
@@ -151,16 +153,28 @@ class Sputnik_Admin {
|
|
151 |
add_action('sputnik_messages', array(__CLASS__, 'admin_notices'));
|
152 |
}
|
153 |
|
|
|
|
|
|
|
|
|
154 |
public static function load_page() {
|
155 |
//Sputnik_API::auth_or_redirect();
|
156 |
}
|
157 |
|
158 |
public static function styles() {
|
159 |
-
wp_enqueue_style('sputnik', plugins_url( 'static/sputnik.css', Sputnik::$path . '/wpsc-marketplace' ), false, '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
}
|
161 |
|
162 |
public static function scripts() {
|
163 |
-
wp_enqueue_script('sputnik_js', plugins_url( 'static/sputnik.js', Sputnik::$path . '/wpsc-marketplace' ), array('jquery', 'common'), '
|
164 |
}
|
165 |
|
166 |
public static function connect_notice() {
|
@@ -179,14 +193,14 @@ class Sputnik_Admin {
|
|
179 |
<?php _e( '<strong>WPEConomy is now installed!</strong> – Get started by linking with your account!', 'wpsc' ); ?> <br />
|
180 |
<?php _e( "If you haven't created an account yet, don't worry, you will be prompted to do so.", 'wpsc') ?>
|
181 |
</p>
|
182 |
-
<a href="<?php echo esc_html( $oauth_url ); ?>" class="thickbox button button-primary thickbox`"><?php _e( 'Link your account now', '
|
183 |
</div>
|
184 |
<?php
|
185 |
}
|
186 |
|
187 |
public static function admin_notices() {
|
188 |
if ( isset( $_GET['payment_cancelled'] ) ) {
|
189 |
-
self::print_message( __( 'Payment cancelled.', '
|
190 |
}
|
191 |
}
|
192 |
|
@@ -213,11 +227,12 @@ class Sputnik_Admin {
|
|
213 |
}
|
214 |
|
215 |
public static function menu() {
|
216 |
-
$hooks[] = add_submenu_page( 'edit.php?post_type=wpsc-product', _x('
|
217 |
$hooks[] = 'plugin-install.php';
|
218 |
-
|
219 |
-
|
220 |
-
add_action("
|
|
|
221 |
}
|
222 |
}
|
223 |
|
@@ -240,34 +255,45 @@ class Sputnik_Admin {
|
|
240 |
|
241 |
public static function page_styles() {
|
242 |
self::$page_is_current = true;
|
243 |
-
wp_enqueue_style('
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
}
|
249 |
-
</style>
|
250 |
-
<?php
|
251 |
}
|
252 |
|
253 |
public static function page_scripts() {
|
254 |
-
wp_enqueue_script('jquery-masonry'
|
255 |
wp_enqueue_script( 'paypal', 'https://www.paypalobjects.com/js/external/dg.js' );
|
256 |
-
wp_enqueue_script('
|
257 |
|
258 |
$l10n = array(
|
259 |
-
'plugin_information' => __('Plugin Information:', '
|
260 |
-
'ays'
|
261 |
);
|
262 |
|
263 |
if ( ! empty( $_REQUEST['oauth_buy'] ) ) {
|
264 |
-
$plugin
|
265 |
-
$status
|
266 |
-
$l10n['buy_id']
|
267 |
$l10n['buy_href'] = $status['url'];
|
268 |
}
|
269 |
|
270 |
-
wp_localize_script('
|
271 |
}
|
272 |
|
273 |
public static function page() {
|
@@ -318,7 +344,7 @@ class Sputnik_Admin {
|
|
318 |
}
|
319 |
} catch (Exception $e) {
|
320 |
status_header(500);
|
321 |
-
iframe_header( __('Plugin Install', '
|
322 |
echo $e->getMessage();
|
323 |
iframe_footer();
|
324 |
die();
|
@@ -332,12 +358,12 @@ class Sputnik_Admin {
|
|
332 |
'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
|
333 |
|
334 |
$plugins_section_titles = array(
|
335 |
-
'description' => _x('Description', 'Plugin installer section title', '
|
336 |
-
'installation' => _x('Installation', 'Plugin installer section title', '
|
337 |
-
'faq' => _x('FAQ', 'Plugin installer section title', '
|
338 |
-
'screenshots' => _x('Screenshots', 'Plugin installer section title', '
|
339 |
-
'changelog' => _x('Changelog', 'Plugin installer section title', '
|
340 |
-
'other_notes' => _x('Other Notes', 'Plugin installer section title', '
|
341 |
);
|
342 |
|
343 |
//Sanitize HTML
|
@@ -368,7 +394,7 @@ class Sputnik_Admin {
|
|
368 |
|
369 |
global $body_id;
|
370 |
$body_id = 'sputnik-plugin-information';
|
371 |
-
iframe_header( __('Plugin Install', '
|
372 |
?>
|
373 |
<div class="alignleft fyi">
|
374 |
<h1><?php echo $api->name ?></h1>
|
@@ -380,21 +406,21 @@ class Sputnik_Admin {
|
|
380 |
case 'purchase':
|
381 |
default:
|
382 |
if ( $status['url'] )
|
383 |
-
echo '<a href="' . $status['url'] . '" target="_parent" id="' . $plugin . '" class="button-primary buy">' . sprintf(__('<span>$%.2f</span> Buy & Install', '
|
384 |
break;
|
385 |
case 'install':
|
386 |
if ( $status['url'] )
|
387 |
-
echo '<a href="' . $status['url'] . '" class="button-primary install" title="' . __('You have already purchased, install now', '
|
388 |
break;
|
389 |
case 'update_available':
|
390 |
if ( $status['url'] )
|
391 |
-
echo '<a href="' . $status['url'] . '" class="button-primary install">' . __('Install Update Now', '
|
392 |
break;
|
393 |
case 'newer_installed':
|
394 |
-
echo '<a>' . sprintf(__('Newer Version (%s) Installed', '
|
395 |
break;
|
396 |
case 'latest_installed':
|
397 |
-
echo '<a>' . __('Latest Version Installed', '
|
398 |
break;
|
399 |
}
|
400 |
?>
|
@@ -426,43 +452,43 @@ class Sputnik_Admin {
|
|
426 |
echo "</ul>\n";
|
427 |
echo "</div>\n";
|
428 |
?>
|
429 |
-
<h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI', '
|
430 |
<ul>
|
431 |
<?php if ( ! empty($api->version) ) : ?>
|
432 |
-
<li><strong><?php _e('Version:', '
|
433 |
<?php endif; if ( ! empty($api->author) ) : ?>
|
434 |
-
<li><strong><?php _e('Author:', '
|
435 |
<?php endif; if ( ! empty($api->last_updated) ) : ?>
|
436 |
-
<li><strong><?php _e('Last Updated:', '
|
437 |
-
printf( __('%s ago', '
|
438 |
<?php endif; if ( ! empty($api->requires) ) : ?>
|
439 |
-
<li><strong><?php _e('Requires WordPress Version:', '
|
440 |
<?php endif; if ( ! empty($api->tested) ) : ?>
|
441 |
-
<li><strong><?php _e('Compatible up to:', '
|
442 |
<?php endif; if ( ! empty($api->requires_wpec) ) : ?>
|
443 |
-
<li><strong><?php _e('Requires WPeC Version:', '
|
444 |
<?php endif; if ( ! empty($api->tested_wpec) ) : ?>
|
445 |
-
<li><strong><?php _e('Compatible up to WPEC Version:', '
|
446 |
<?php endif; if ( ! empty($api->downloaded) ) : ?>
|
447 |
-
<li><strong><?php _e('Downloaded:', '
|
448 |
<?php endif; if ( ! empty($api->homepage) ) : ?>
|
449 |
-
<li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage »', '
|
450 |
<?php endif; ?>
|
451 |
</ul>
|
452 |
</div>
|
453 |
<div id="section-holder" class="wrap">
|
454 |
<?php
|
455 |
if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
|
456 |
-
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.', '
|
457 |
|
458 |
else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
|
459 |
-
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.', '
|
460 |
|
461 |
else if ( !empty($api->requires_wpec) && version_compare( substr( WPSC_VERSION, 0, strlen($api->requires_wpec)), $api->requires_wpec, '<') )
|
462 |
-
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WP
|
463 |
|
464 |
else if ( !empty($api->tested_wpec) && version_compare( substr( WPSC_VERSION, 0, strlen($api->tested_wpec)), $api->tested_wpec, '<') )
|
465 |
-
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your version of WP
|
466 |
|
467 |
foreach ( $api->sections as $section_name => $content ) {
|
468 |
if ( isset( $plugins_section_titles[ $section_name ] ) )
|
@@ -588,9 +614,8 @@ class Sputnik_Admin {
|
|
588 |
'oauth' => 'request',
|
589 |
'oauth_buy' => $api->slug,
|
590 |
'TB_iframe' => true,
|
591 |
-
'height' =>
|
592 |
-
'width' =>
|
593 |
-
'modal' => 'true'
|
594 |
) );
|
595 |
|
596 |
return compact('status', 'url', 'version');
|
@@ -599,8 +624,8 @@ class Sputnik_Admin {
|
|
599 |
protected static function header( $account ) {
|
600 |
if ($account !== false) {
|
601 |
$tabs = array(
|
602 |
-
'dash' => __('Store', '
|
603 |
-
'account' => __('Your Account', '
|
604 |
);
|
605 |
$hrefs = array(
|
606 |
'dash' => self::build_url(),
|
@@ -611,27 +636,11 @@ class Sputnik_Admin {
|
|
611 |
}
|
612 |
?>
|
613 |
<div class="wrap" id="sputnik-page">
|
614 |
-
|
615 |
-
<h2>Marketplace <?php self::account_link(); ?>
|
616 |
-
</h2>
|
617 |
<?php
|
618 |
do_action('sputnik_messages');
|
619 |
}
|
620 |
|
621 |
-
protected static function footer() {?>
|
622 |
-
<div id="sputnik-footer">
|
623 |
-
<p class="logo-holder"><a href="http://wpeconomy.org/" class="renku-logo-no-img">Marketplace Powered by WPEconomy</a></p>
|
624 |
-
<nav><p><a href="http://www.wpeconomy.org/documentation/developers/">Developer Tools</a> | <a href="http://twitter.com/WPEconomy">@WPEconomy</a> | <a href="http://www.wpeconomy.org/documentation/marketplace/faqs/">FAQ</a></p></nav>
|
625 |
-
</div>
|
626 |
-
</div>
|
627 |
-
<?php
|
628 |
-
}
|
629 |
-
|
630 |
-
protected static function account_link() {
|
631 |
-
if ( Sputnik::account_is_linked() && 'dash' == self::$page )
|
632 |
-
echo '<a href="edit.php?post_type=wpsc-product&page=sputnik-account" class="add-new-h2">Your Account</a>';
|
633 |
-
}
|
634 |
-
|
635 |
protected static function other_pages() {
|
636 |
global $tab;
|
637 |
|
@@ -645,7 +654,7 @@ class Sputnik_Admin {
|
|
645 |
delete_option('sputnik_oauth_request');
|
646 |
}
|
647 |
elseif ( $e->getCode() !== 1 ) {
|
648 |
-
echo '<p>' . sprintf(__('Problem: %s', '
|
649 |
}
|
650 |
}
|
651 |
|
@@ -659,35 +668,34 @@ class Sputnik_Admin {
|
|
659 |
<?php echo get_avatar($account->email) ?>
|
660 |
<p class="lead-in">Logged in as</p>
|
661 |
<h3><?php echo esc_html($account->name) ?></h3>
|
662 |
-
<p><?php printf(__('<a href="%s">Log out</a> of your account', '
|
663 |
</div>
|
664 |
<div class="block">
|
665 |
<p>Email: <code><?php echo $account->email ?></code></p>
|
666 |
<?php if ( $tab != 'purchased' ): ?>
|
667 |
-
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', '
|
668 |
<?php endif; ?>
|
669 |
-
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', '
|
670 |
</div>
|
671 |
</div>
|
672 |
<?php
|
673 |
}
|
674 |
self::$list_table->views();
|
675 |
self::$list_table->display();
|
676 |
-
self::footer();
|
677 |
}
|
678 |
|
679 |
/**
|
680 |
* Output the main landing page for the Sputnik administration screen.
|
681 |
*/
|
682 |
protected static function dashboard() { ?>
|
683 |
-
<p><?php _e('Some text about WPEconomy goes here! This will eventually be replaced with a dashboard-like interface, including latest news, etc.', '
|
684 |
|
685 |
-
<h4><?php _e('Search', '
|
686 |
-
<p class="install-help"><?php _e('Search for plugins by keyword.', '
|
687 |
<?php Sputnik_Admin::search_form(); ?>
|
688 |
|
689 |
<h4><?php _e('Popular tags') ?></h4>
|
690 |
-
<p class="install-help"><?php _e('You may also browse based on the most popular tags on the store:', '
|
691 |
<?php
|
692 |
echo '<p class="popular-tags">';
|
693 |
|
@@ -704,7 +712,7 @@ class Sputnik_Admin {
|
|
704 |
'count' => $tag->count
|
705 |
);
|
706 |
}
|
707 |
-
echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin', '
|
708 |
}
|
709 |
catch (Exception $e) {
|
710 |
echo $e->getMessage();
|
@@ -732,8 +740,7 @@ class Sputnik_Admin {
|
|
732 |
}
|
733 |
else {
|
734 |
self::header('Account', $account);
|
735 |
-
echo '<p>' . sprintf(__('Problem: %s', '
|
736 |
-
self::footer();
|
737 |
|
738 |
return;
|
739 |
}
|
@@ -746,26 +753,25 @@ class Sputnik_Admin {
|
|
746 |
<?php echo get_avatar($account->email) ?>
|
747 |
<p class="lead-in">Logged in as</p>
|
748 |
<h3><?php echo esc_html($account->name) ?></h3>
|
749 |
-
<p><?php printf(__('<a href="%s">Log out</a> of your account', '
|
750 |
</div>
|
751 |
<div class="block">
|
752 |
<p>Email: <code><?php echo $account->email ?></code></p>
|
753 |
-
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', '
|
754 |
-
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', '
|
755 |
</div>
|
756 |
</div>
|
757 |
|
758 |
<?php
|
759 |
self::$list_table->views();
|
760 |
self::$list_table->display();
|
761 |
-
self::footer();
|
762 |
}
|
763 |
|
764 |
protected static function auth() {
|
765 |
$oauth_url = self::build_url(array('oauth' => 'request', 'TB_iframe' => true));
|
766 |
|
767 |
if ( isset( $_GET['auth'] ) && $_GET['auth'] == 'denied' ) {
|
768 |
-
self::print_message( __( 'Authorization cancelled.', '
|
769 |
}
|
770 |
}
|
771 |
|
@@ -809,7 +815,7 @@ class Sputnik_Admin {
|
|
809 |
$install_url = add_query_arg('_wpnonce', wp_create_nonce('sputnik_install-plugin_' . $product_slug), $install_url);
|
810 |
$install_url = add_query_arg(array('TB_iframe' => true), $install_url);
|
811 |
|
812 |
-
self::iframe_closer( self::build_url(array('run-installer' => urlencode($install_url))), __( 'Installing ... ', '
|
813 |
}
|
814 |
|
815 |
/**
|
@@ -822,19 +828,19 @@ class Sputnik_Admin {
|
|
822 |
|
823 |
$cancelled_url = self::build_url( array( 'payment_cancelled' => true ) );
|
824 |
|
825 |
-
self::iframe_closer( $cancelled_url, __( 'Payment Cancelled', '
|
826 |
}
|
827 |
|
828 |
protected static function install($id) {
|
829 |
|
830 |
-
|
831 |
|
832 |
try {
|
833 |
$api = Sputnik::get_plugin($id);
|
834 |
}
|
835 |
catch (Exception $e) {
|
836 |
status_header(500);
|
837 |
-
iframe_header( __('Plugin Install', '
|
838 |
echo $e->getMessage();
|
839 |
iframe_footer();
|
840 |
die();
|
@@ -846,7 +852,7 @@ class Sputnik_Admin {
|
|
846 |
}
|
847 |
|
848 |
if ( ! current_user_can('install_plugins') )
|
849 |
-
wp_die(__('You do not have sufficient permissions to install plugins for this site.', '
|
850 |
|
851 |
include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
|
852 |
|
@@ -854,44 +860,42 @@ class Sputnik_Admin {
|
|
854 |
|
855 |
global $body_id;
|
856 |
$body_id = 'sputnik-install';
|
857 |
-
iframe_header( __('Plugin Install', '
|
858 |
|
859 |
-
$title = sprintf( __('Installing Plugin: %s', '
|
860 |
$nonce = 'sputnik_install-plugin_' . $id;
|
861 |
$url = 'update.php?action=install-plugin&plugin=' . $id;
|
862 |
if ( isset($_GET['from']) )
|
863 |
$url .= '&from=' . urlencode(stripslashes($_GET['from']));
|
864 |
|
865 |
-
$type = 'web'; //Install plugin type, From Web or an Upload.
|
866 |
-
|
867 |
-
ini_set( 'display_errors', '1' );
|
868 |
-
error_reporting( E_ALL );
|
869 |
|
870 |
-
if ( in_array( 'theme', $api->categories ) )
|
871 |
$upgrader = new Sputnik_ThemeUpgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
|
872 |
-
else
|
873 |
$upgrader = new Sputnik_Upgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
|
|
|
874 |
|
875 |
-
$upgrader->install($api->download_link);
|
876 |
|
877 |
iframe_footer();
|
878 |
die();
|
879 |
}
|
880 |
|
881 |
protected static function upgrade($file) {
|
882 |
-
|
883 |
|
884 |
try {
|
885 |
$data = Sputnik::get_from_file($file);
|
886 |
if ($data === null) {
|
887 |
-
throw new Exception(__('Plugin not found', '
|
888 |
}
|
889 |
$id = $data['Sputnik ID'];
|
890 |
$api = Sputnik::get_plugin($id);
|
891 |
}
|
892 |
catch (Exception $e) {
|
893 |
status_header(500);
|
894 |
-
iframe_header( __('Update Plugin', '
|
895 |
echo $e->getMessage();
|
896 |
iframe_footer();
|
897 |
die();
|
@@ -903,7 +907,7 @@ class Sputnik_Admin {
|
|
903 |
}
|
904 |
|
905 |
if ( ! current_user_can('install_plugins') )
|
906 |
-
wp_die(__('You do not have sufficient permissions to install plugins for this site.', '
|
907 |
|
908 |
include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
|
909 |
|
@@ -911,9 +915,9 @@ class Sputnik_Admin {
|
|
911 |
|
912 |
global $body_id;
|
913 |
$body_id = 'sputnik-upgrade';
|
914 |
-
iframe_header( __('Update Plugin', '
|
915 |
|
916 |
-
$title = sprintf( __('Updating Plugin: %s', '
|
917 |
$nonce = 'sputnik_upgrade-plugin_' . $id;
|
918 |
$url = 'update.php?action=upgrade-plugin&plugin=' . $id;
|
919 |
if ( isset($_GET['from']) )
|
@@ -955,7 +959,7 @@ class Sputnik_Admin {
|
|
955 |
*/
|
956 |
public static function iframe_closer( $redirect_url, $title = null ) {
|
957 |
if (empty($title)) {
|
958 |
-
$title = __('Redirecting...', '
|
959 |
}
|
960 |
?>
|
961 |
<!DOCTYPE html><html>
|
95 |
return;
|
96 |
}
|
97 |
?>
|
98 |
+
<div class="error"><p><?php _e('The following plugins are disabled:', 'wpsc') ?></p>
|
99 |
<ul>
|
100 |
<?php
|
101 |
foreach ($invalid as $plugin) {
|
104 |
}
|
105 |
switch ($plugin['sputnik_error']) {
|
106 |
case 'not_purchased':
|
107 |
+
$error = __('Not purchased', 'wpsc');
|
108 |
break;
|
109 |
default:
|
110 |
+
$error = __('Unknown error', 'wpsc');
|
111 |
break;
|
112 |
}
|
113 |
?>
|
127 |
if (empty($data['Sputnik ID'])) {
|
128 |
return $meta;
|
129 |
}
|
130 |
+
echo '<a class="sputnik-plugin-row-note" href="' . self::build_url() . '"><span class="powered">' . __( 'Powered by WPEConomy', 'wpsc' ) . '</span><span class="corner"></span></a>';
|
131 |
return $meta;
|
132 |
}
|
133 |
|
137 |
return;
|
138 |
}
|
139 |
|
140 |
+
add_filter( 'admin_body_class', array( __CLASS__, 'admin_body_class' ) );
|
141 |
+
|
142 |
if (self::$page === 'dash') {
|
143 |
self::$list_table = new Sputnik_List_Install();
|
144 |
$pagenum = self::$list_table->get_pagenum();
|
153 |
add_action('sputnik_messages', array(__CLASS__, 'admin_notices'));
|
154 |
}
|
155 |
|
156 |
+
public static function admin_body_class( $classes ) {
|
157 |
+
return $classes . 'plugin-install-php';
|
158 |
+
}
|
159 |
+
|
160 |
public static function load_page() {
|
161 |
//Sputnik_API::auth_or_redirect();
|
162 |
}
|
163 |
|
164 |
public static function styles() {
|
165 |
+
wp_enqueue_style('sputnik', plugins_url( 'static/sputnik.css', Sputnik::$path . '/wpsc-marketplace' ), false, '20141202');
|
166 |
+
?>
|
167 |
+
<style type="text/css">
|
168 |
+
span#wpsc-extensions-menu-link {
|
169 |
+
font-weight: bold;
|
170 |
+
color: <?php self::get_marketplace_link_color(); ?>;
|
171 |
+
}
|
172 |
+
</style>
|
173 |
+
<?php
|
174 |
}
|
175 |
|
176 |
public static function scripts() {
|
177 |
+
wp_enqueue_script('sputnik_js', plugins_url( 'static/sputnik.js', Sputnik::$path . '/wpsc-marketplace' ), array('jquery', 'common'), '20141202' );
|
178 |
}
|
179 |
|
180 |
public static function connect_notice() {
|
193 |
<?php _e( '<strong>WPEConomy is now installed!</strong> – Get started by linking with your account!', 'wpsc' ); ?> <br />
|
194 |
<?php _e( "If you haven't created an account yet, don't worry, you will be prompted to do so.", 'wpsc') ?>
|
195 |
</p>
|
196 |
+
<a href="<?php echo esc_html( $oauth_url ); ?>" class="thickbox button button-primary thickbox`"><?php _e( 'Link your account now', 'wpsc' ); ?></a>
|
197 |
</div>
|
198 |
<?php
|
199 |
}
|
200 |
|
201 |
public static function admin_notices() {
|
202 |
if ( isset( $_GET['payment_cancelled'] ) ) {
|
203 |
+
self::print_message( __( 'Payment cancelled.', 'wpsc' ) );
|
204 |
}
|
205 |
}
|
206 |
|
227 |
}
|
228 |
|
229 |
public static function menu() {
|
230 |
+
$hooks[] = add_submenu_page( 'edit.php?post_type=wpsc-product', _x( 'Extensions', 'page title', 'wpsc' ), _x( '<span id="wpsc-extensions-menu-link">Extensions</span>', 'menu title', 'wpsc' ), 'install_plugins', 'sputnik', array( __CLASS__, 'page' ) );
|
231 |
$hooks[] = 'plugin-install.php';
|
232 |
+
|
233 |
+
foreach ( $hooks as $hook ) {
|
234 |
+
add_action( "admin_print_styles-$hook" , array( __CLASS__, 'page_styles' ) );
|
235 |
+
add_action( "admin_print_scripts-$hook", array( __CLASS__, 'page_scripts' ) );
|
236 |
}
|
237 |
}
|
238 |
|
255 |
|
256 |
public static function page_styles() {
|
257 |
self::$page_is_current = true;
|
258 |
+
wp_enqueue_style('wpsc-marketplace-page', plugins_url( 'static/admin.css', Sputnik::$path . '/wpsc-marketplace' ), array( 'thickbox' ), '20141109' );
|
259 |
+
}
|
260 |
+
|
261 |
+
public static function get_marketplace_link_color() {
|
262 |
+
global $_wp_admin_css_colors;
|
263 |
+
|
264 |
+
$_color = get_user_option( 'admin_color' );
|
265 |
+
|
266 |
+
if ( empty( $_color ) || ! isset( $_wp_admin_css_colors[ $_color ] ) ) {
|
267 |
+
$_color = 'fresh';
|
268 |
+
}
|
269 |
+
|
270 |
+
$color = $_wp_admin_css_colors[ $_color ];
|
271 |
+
|
272 |
+
if ( in_array( $_color, array( 'blue', 'coffee', 'ectoplasm', 'ocean', 'sunrise' ) ) ) {
|
273 |
+
echo isset( $color->icon_colors['focus'] ) ? $color->icon_colors['focus'] : '';
|
274 |
+
} else {
|
275 |
+
echo isset( $color->colors[ 3 ] ) ? $color->colors[ 3 ] : '';
|
276 |
}
|
|
|
|
|
277 |
}
|
278 |
|
279 |
public static function page_scripts() {
|
280 |
+
wp_enqueue_script( 'jquery-masonry' );
|
281 |
wp_enqueue_script( 'paypal', 'https://www.paypalobjects.com/js/external/dg.js' );
|
282 |
+
wp_enqueue_script( 'wpsc-marketplace-js', plugins_url( 'static/admin.js', Sputnik::$path . '/wpsc-marketplace' ), array( 'jquery', 'jquery-masonry', 'thickbox', 'paypal' ), '20141109' );
|
283 |
|
284 |
$l10n = array(
|
285 |
+
'plugin_information' => __( 'Plugin Information:', 'wpsc' ),
|
286 |
+
'ays' => __( 'Are you sure you want to install this plugin?', 'wpsc' )
|
287 |
);
|
288 |
|
289 |
if ( ! empty( $_REQUEST['oauth_buy'] ) ) {
|
290 |
+
$plugin = Sputnik::get_plugin( $_REQUEST['oauth_buy'] );
|
291 |
+
$status = self::install_status( $plugin );
|
292 |
+
$l10n['buy_id'] = $plugin->slug;
|
293 |
$l10n['buy_href'] = $status['url'];
|
294 |
}
|
295 |
|
296 |
+
wp_localize_script( 'wpsc-marketplace-js', 'sputnikL10n', $l10n );
|
297 |
}
|
298 |
|
299 |
public static function page() {
|
344 |
}
|
345 |
} catch (Exception $e) {
|
346 |
status_header(500);
|
347 |
+
iframe_header( __('Plugin Install', 'wpsc') );
|
348 |
echo $e->getMessage();
|
349 |
iframe_footer();
|
350 |
die();
|
358 |
'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
|
359 |
|
360 |
$plugins_section_titles = array(
|
361 |
+
'description' => _x('Description', 'Plugin installer section title', 'wpsc'),
|
362 |
+
'installation' => _x('Installation', 'Plugin installer section title', 'wpsc'),
|
363 |
+
'faq' => _x('FAQ', 'Plugin installer section title', 'wpsc'),
|
364 |
+
'screenshots' => _x('Screenshots', 'Plugin installer section title', 'wpsc'),
|
365 |
+
'changelog' => _x('Changelog', 'Plugin installer section title', 'wpsc'),
|
366 |
+
'other_notes' => _x('Other Notes', 'Plugin installer section title', 'wpsc')
|
367 |
);
|
368 |
|
369 |
//Sanitize HTML
|
394 |
|
395 |
global $body_id;
|
396 |
$body_id = 'sputnik-plugin-information';
|
397 |
+
iframe_header( __('Plugin Install', 'wpsc') );
|
398 |
?>
|
399 |
<div class="alignleft fyi">
|
400 |
<h1><?php echo $api->name ?></h1>
|
406 |
case 'purchase':
|
407 |
default:
|
408 |
if ( $status['url'] )
|
409 |
+
echo '<a href="' . $status['url'] . '" target="_parent" id="' . $plugin . '" class="button-primary buy">' . sprintf(__('<span>$%.2f</span> Buy & Install', 'wpsc'), $api->price) . '</a>';
|
410 |
break;
|
411 |
case 'install':
|
412 |
if ( $status['url'] )
|
413 |
+
echo '<a href="' . $status['url'] . '" class="button-primary install" title="' . __('You have already purchased, install now', 'wpsc') . '">' . __('Install Now', 'wpsc') . '</a>';
|
414 |
break;
|
415 |
case 'update_available':
|
416 |
if ( $status['url'] )
|
417 |
+
echo '<a href="' . $status['url'] . '" class="button-primary install">' . __('Install Update Now', 'wpsc') .'</a>';
|
418 |
break;
|
419 |
case 'newer_installed':
|
420 |
+
echo '<a>' . sprintf(__('Newer Version (%s) Installed', 'wpsc'), $status['version']) . '</a>';
|
421 |
break;
|
422 |
case 'latest_installed':
|
423 |
+
echo '<a>' . __('Latest Version Installed', 'wpsc') . '</a>';
|
424 |
break;
|
425 |
}
|
426 |
?>
|
452 |
echo "</ul>\n";
|
453 |
echo "</div>\n";
|
454 |
?>
|
455 |
+
<h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI', 'wpsc') ?></h2>
|
456 |
<ul>
|
457 |
<?php if ( ! empty($api->version) ) : ?>
|
458 |
+
<li><strong><?php _e('Version:', 'wpsc') ?></strong> <?php echo $api->version ?></li>
|
459 |
<?php endif; if ( ! empty($api->author) ) : ?>
|
460 |
+
<li><strong><?php _e('Author:', 'wpsc') ?></strong> <?php echo $api->author ?></li>
|
461 |
<?php endif; if ( ! empty($api->last_updated) ) : ?>
|
462 |
+
<li><strong><?php _e('Last Updated:', 'wpsc') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
|
463 |
+
printf( __('%s ago', 'wpsc'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
|
464 |
<?php endif; if ( ! empty($api->requires) ) : ?>
|
465 |
+
<li><strong><?php _e('Requires WordPress Version:', 'wpsc') ?></strong> <?php printf(__('%s or higher', 'wpsc'), $api->requires) ?></li>
|
466 |
<?php endif; if ( ! empty($api->tested) ) : ?>
|
467 |
+
<li><strong><?php _e('Compatible up to:', 'wpsc') ?></strong> <?php echo $api->tested ?></li>
|
468 |
<?php endif; if ( ! empty($api->requires_wpec) ) : ?>
|
469 |
+
<li><strong><?php _e('Requires WPeC Version:', 'wpsc') ?></strong> <?php printf(__('%s or higher', 'wpsc'), $api->requires_wpec) ?></li>
|
470 |
<?php endif; if ( ! empty($api->tested_wpec) ) : ?>
|
471 |
+
<li><strong><?php _e('Compatible up to WPEC Version:', 'wpsc') ?></strong> <?php echo $api->tested_wpec ?></li>
|
472 |
<?php endif; if ( ! empty($api->downloaded) ) : ?>
|
473 |
+
<li><strong><?php _e('Downloaded:', 'wpsc') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded, 'wpsc'), number_format_i18n($api->downloaded)) ?></li>
|
474 |
<?php endif; if ( ! empty($api->homepage) ) : ?>
|
475 |
+
<li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage »', 'wpsc') ?></a></li>
|
476 |
<?php endif; ?>
|
477 |
</ul>
|
478 |
</div>
|
479 |
<div id="section-holder" class="wrap">
|
480 |
<?php
|
481 |
if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
|
482 |
+
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.', 'wpsc') . '</p></div>';
|
483 |
|
484 |
else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
|
485 |
+
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.', 'wpsc') . '</p></div>';
|
486 |
|
487 |
else if ( !empty($api->requires_wpec) && version_compare( substr( WPSC_VERSION, 0, strlen($api->requires_wpec)), $api->requires_wpec, '<') )
|
488 |
+
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WP eCommerce.', 'wpsc') . '</p></div>';
|
489 |
|
490 |
else if ( !empty($api->tested_wpec) && version_compare( substr( WPSC_VERSION, 0, strlen($api->tested_wpec)), $api->tested_wpec, '<') )
|
491 |
+
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your version of WP eCommerce.', 'wpsc') . '</p></div>';
|
492 |
|
493 |
foreach ( $api->sections as $section_name => $content ) {
|
494 |
if ( isset( $plugins_section_titles[ $section_name ] ) )
|
614 |
'oauth' => 'request',
|
615 |
'oauth_buy' => $api->slug,
|
616 |
'TB_iframe' => true,
|
617 |
+
'height' => 600,
|
618 |
+
'width' => 800
|
|
|
619 |
) );
|
620 |
|
621 |
return compact('status', 'url', 'version');
|
624 |
protected static function header( $account ) {
|
625 |
if ($account !== false) {
|
626 |
$tabs = array(
|
627 |
+
'dash' => __('Store', 'wpsc'),
|
628 |
+
'account' => __('Your Account', 'wpsc'),
|
629 |
);
|
630 |
$hrefs = array(
|
631 |
'dash' => self::build_url(),
|
636 |
}
|
637 |
?>
|
638 |
<div class="wrap" id="sputnik-page">
|
639 |
+
<h2><?php _e( 'Marketplace', 'wpsc' ); ?></h2>
|
|
|
|
|
640 |
<?php
|
641 |
do_action('sputnik_messages');
|
642 |
}
|
643 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
644 |
protected static function other_pages() {
|
645 |
global $tab;
|
646 |
|
654 |
delete_option('sputnik_oauth_request');
|
655 |
}
|
656 |
elseif ( $e->getCode() !== 1 ) {
|
657 |
+
echo '<p>' . sprintf(__('Problem: %s', 'wpsc'), $e->getMessage() ). '</p>';
|
658 |
}
|
659 |
}
|
660 |
|
668 |
<?php echo get_avatar($account->email) ?>
|
669 |
<p class="lead-in">Logged in as</p>
|
670 |
<h3><?php echo esc_html($account->name) ?></h3>
|
671 |
+
<p><?php printf(__('<a href="%s">Log out</a> of your account', 'wpsc'), self::build_url(array('oauth' => 'reset'))) ?></p>
|
672 |
</div>
|
673 |
<div class="block">
|
674 |
<p>Email: <code><?php echo $account->email ?></code></p>
|
675 |
<?php if ( $tab != 'purchased' ): ?>
|
676 |
+
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', 'wpsc'), count( self::$list_table->items )) ?></p>
|
677 |
<?php endif; ?>
|
678 |
+
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', 'wpsc'), count( $account->purchased ) ) ?></p>
|
679 |
</div>
|
680 |
</div>
|
681 |
<?php
|
682 |
}
|
683 |
self::$list_table->views();
|
684 |
self::$list_table->display();
|
|
|
685 |
}
|
686 |
|
687 |
/**
|
688 |
* Output the main landing page for the Sputnik administration screen.
|
689 |
*/
|
690 |
protected static function dashboard() { ?>
|
691 |
+
<p><?php _e('Some text about WPEconomy goes here! This will eventually be replaced with a dashboard-like interface, including latest news, etc.', 'wpsc'); ?></p>
|
692 |
|
693 |
+
<h4><?php _e('Search', 'wpsc') ?></h4>
|
694 |
+
<p class="install-help"><?php _e('Search for plugins by keyword.', 'wpsc') ?></p>
|
695 |
<?php Sputnik_Admin::search_form(); ?>
|
696 |
|
697 |
<h4><?php _e('Popular tags') ?></h4>
|
698 |
+
<p class="install-help"><?php _e('You may also browse based on the most popular tags on the store:', 'wpsc') ?></p>
|
699 |
<?php
|
700 |
echo '<p class="popular-tags">';
|
701 |
|
712 |
'count' => $tag->count
|
713 |
);
|
714 |
}
|
715 |
+
echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin', 'wpsc'), 'multiple_text' => __('%s plugins', 'wpsc') ) );
|
716 |
}
|
717 |
catch (Exception $e) {
|
718 |
echo $e->getMessage();
|
740 |
}
|
741 |
else {
|
742 |
self::header('Account', $account);
|
743 |
+
echo '<p>' . sprintf(__('Problem: %s', 'wpsc'), $e->getMessage()) . '</p>';
|
|
|
744 |
|
745 |
return;
|
746 |
}
|
753 |
<?php echo get_avatar($account->email) ?>
|
754 |
<p class="lead-in">Logged in as</p>
|
755 |
<h3><?php echo esc_html($account->name) ?></h3>
|
756 |
+
<p><?php printf(__('<a href="%s">Log out</a> of your account', 'wpsc'), self::build_url(array('oauth' => 'reset'))) ?></p>
|
757 |
</div>
|
758 |
<div class="block">
|
759 |
<p>Email: <code><?php echo $account->email ?></code></p>
|
760 |
+
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', 'wpsc'), count($account->purchased)) ?></p>
|
761 |
+
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', 'wpsc'), count(self::$list_table->items)) ?></p>
|
762 |
</div>
|
763 |
</div>
|
764 |
|
765 |
<?php
|
766 |
self::$list_table->views();
|
767 |
self::$list_table->display();
|
|
|
768 |
}
|
769 |
|
770 |
protected static function auth() {
|
771 |
$oauth_url = self::build_url(array('oauth' => 'request', 'TB_iframe' => true));
|
772 |
|
773 |
if ( isset( $_GET['auth'] ) && $_GET['auth'] == 'denied' ) {
|
774 |
+
self::print_message( __( 'Authorization cancelled.', 'wpsc' ) );
|
775 |
}
|
776 |
}
|
777 |
|
815 |
$install_url = add_query_arg('_wpnonce', wp_create_nonce('sputnik_install-plugin_' . $product_slug), $install_url);
|
816 |
$install_url = add_query_arg(array('TB_iframe' => true), $install_url);
|
817 |
|
818 |
+
self::iframe_closer( self::build_url( array('run-installer' => urlencode( $install_url ) ) ), __( 'Installing ... ', 'wpsc' ) );
|
819 |
}
|
820 |
|
821 |
/**
|
828 |
|
829 |
$cancelled_url = self::build_url( array( 'payment_cancelled' => true ) );
|
830 |
|
831 |
+
self::iframe_closer( $cancelled_url, __( 'Payment Cancelled', 'wpsc' ) );
|
832 |
}
|
833 |
|
834 |
protected static function install($id) {
|
835 |
|
836 |
+
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
837 |
|
838 |
try {
|
839 |
$api = Sputnik::get_plugin($id);
|
840 |
}
|
841 |
catch (Exception $e) {
|
842 |
status_header(500);
|
843 |
+
iframe_header( __('Plugin Install', 'wpsc') );
|
844 |
echo $e->getMessage();
|
845 |
iframe_footer();
|
846 |
die();
|
852 |
}
|
853 |
|
854 |
if ( ! current_user_can('install_plugins') )
|
855 |
+
wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'wpsc'));
|
856 |
|
857 |
include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
|
858 |
|
860 |
|
861 |
global $body_id;
|
862 |
$body_id = 'sputnik-install';
|
863 |
+
iframe_header( __('Plugin Install', 'wpsc') );
|
864 |
|
865 |
+
$title = sprintf( __('Installing Plugin: %s', 'wpsc'), $api->name . ' ' . $api->version );
|
866 |
$nonce = 'sputnik_install-plugin_' . $id;
|
867 |
$url = 'update.php?action=install-plugin&plugin=' . $id;
|
868 |
if ( isset($_GET['from']) )
|
869 |
$url .= '&from=' . urlencode(stripslashes($_GET['from']));
|
870 |
|
871 |
+
$type = 'web'; //Install plugin type, From Web or an Upload.
|
|
|
|
|
|
|
872 |
|
873 |
+
if ( in_array( 'theme', $api->categories ) ) {
|
874 |
$upgrader = new Sputnik_ThemeUpgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
|
875 |
+
} else {
|
876 |
$upgrader = new Sputnik_Upgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
|
877 |
+
}
|
878 |
|
879 |
+
$upgrader->install( $api->download_link );
|
880 |
|
881 |
iframe_footer();
|
882 |
die();
|
883 |
}
|
884 |
|
885 |
protected static function upgrade($file) {
|
886 |
+
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
887 |
|
888 |
try {
|
889 |
$data = Sputnik::get_from_file($file);
|
890 |
if ($data === null) {
|
891 |
+
throw new Exception(__('Plugin not found', 'wpsc'));
|
892 |
}
|
893 |
$id = $data['Sputnik ID'];
|
894 |
$api = Sputnik::get_plugin($id);
|
895 |
}
|
896 |
catch (Exception $e) {
|
897 |
status_header(500);
|
898 |
+
iframe_header( __('Update Plugin', 'wpsc') );
|
899 |
echo $e->getMessage();
|
900 |
iframe_footer();
|
901 |
die();
|
907 |
}
|
908 |
|
909 |
if ( ! current_user_can('install_plugins') )
|
910 |
+
wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'wpsc'));
|
911 |
|
912 |
include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
|
913 |
|
915 |
|
916 |
global $body_id;
|
917 |
$body_id = 'sputnik-upgrade';
|
918 |
+
iframe_header( __('Update Plugin', 'wpsc') );
|
919 |
|
920 |
+
$title = sprintf( __('Updating Plugin: %s', 'wpsc'), $api->name . ' ' . $api->version );
|
921 |
$nonce = 'sputnik_upgrade-plugin_' . $id;
|
922 |
$url = 'update.php?action=upgrade-plugin&plugin=' . $id;
|
923 |
if ( isset($_GET['from']) )
|
959 |
*/
|
960 |
public static function iframe_closer( $redirect_url, $title = null ) {
|
961 |
if (empty($title)) {
|
962 |
+
$title = __('Redirecting...', 'wpsc');
|
963 |
}
|
964 |
?>
|
965 |
<!DOCTYPE html><html>
|
wpsc-components/marketplace-core-v1/library/Sputnik/List/Install.php
CHANGED
@@ -55,7 +55,7 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
55 |
|
56 |
case 'search':
|
57 |
$term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
|
58 |
-
$api = Sputnik_API::search($term);
|
59 |
break;
|
60 |
|
61 |
case 'account':
|
@@ -106,7 +106,7 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
106 |
|
107 |
echo '<p>';
|
108 |
if ( $tab == 'purchased' )
|
109 |
-
printf( __( "You haven't purchased any
|
110 |
else
|
111 |
_e( 'No plugins match your request.', 'wpsc' );
|
112 |
echo '</p>';
|
@@ -151,7 +151,6 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
151 |
}
|
152 |
|
153 |
public function display_grid() {
|
154 |
-
extract( $this->_args );
|
155 |
|
156 |
$this->display_tablenav( 'top' );
|
157 |
?>
|
@@ -246,10 +245,14 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
246 |
|
247 |
foreach ( (array) $this->items as $plugin ) {
|
248 |
$plugin->title = wp_kses( $plugin->name, $plugins_allowedtags );
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
252 |
$plugin->description = mb_substr( $plugin->description, 0, 400 ) . '…';
|
|
|
|
|
253 |
//remove any trailing entities
|
254 |
$plugin->description = preg_replace( '/&[^;\s]{0,6}$/', '', $plugin->description );
|
255 |
//strip leading/trailing & multiple consecutive lines
|
@@ -260,16 +263,16 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
260 |
$plugin->version = wp_kses( $plugin->version, $plugins_allowedtags );
|
261 |
$plugin->price = sprintf('$%.2f', $plugin->price);
|
262 |
if ($plugin->price === '$0.00') {
|
263 |
-
$plugin->price = _x('Free', 'plugin price', 'wpsc' );
|
264 |
}
|
265 |
|
266 |
-
$plugin->author
|
267 |
-
if (!empty($plugin->author))
|
268 |
$plugin->author = ' <cite>' . sprintf( __( 'By %s', 'wpsc' ), $plugin->author ) . '.</cite>';
|
|
|
269 |
|
270 |
$plugin->author = wp_kses( $plugin->author, $plugins_allowedtags );
|
271 |
|
272 |
-
switch ($this->view) {
|
273 |
case 'list':
|
274 |
self::display_row($plugin, $style);
|
275 |
break;
|
@@ -301,7 +304,7 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
301 |
break;
|
302 |
case 'install':
|
303 |
if ( $status['url'] ) {
|
304 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
305 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
306 |
. esc_attr(sprintf(__( 'Install %s', 'wpsc' ), $name)) . '">' . __('Install', 'wpsc' ) . '</a>';
|
307 |
}
|
@@ -312,7 +315,7 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
312 |
break;
|
313 |
case 'update_available':
|
314 |
if ( $status['url'] ) {
|
315 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
316 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
317 |
. esc_attr(sprintf(__( 'Update to version %s', 'wpsc' ), $status['version'])) . '">' . __('Update', 'wpsc' ) . '</a>';
|
318 |
}
|
@@ -361,7 +364,7 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
361 |
|
362 |
protected static function display_as_grid($plugin, $style) {
|
363 |
|
364 |
-
$name = strip_tags( $plugin->name
|
365 |
$action_links = array();
|
366 |
$action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
|
367 |
. '" class="thickbox button info" title="' .
|
@@ -381,7 +384,7 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
381 |
break;
|
382 |
case 'install':
|
383 |
if ( $status['url'] ) {
|
384 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
385 |
$purchase_link = '<a class="button install status" href="' . $status['url'] . '" title="'
|
386 |
. esc_attr(sprintf(__( 'Install %s', 'wpsc' ), $name)) . '">' . __('Install', 'wpsc' ) . '</a>';
|
387 |
}
|
@@ -392,7 +395,7 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
392 |
break;
|
393 |
case 'update_available':
|
394 |
if ( $status['url'] ) {
|
395 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
396 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
397 |
. esc_attr(sprintf(__( 'Update to version %s', 'wpsc' ), $status['version'])) . '">' . __('Update', 'wpsc' ) . '</a>';
|
398 |
}
|
@@ -411,28 +414,30 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
411 |
|
412 |
$action_links = apply_filters( 'sputnik_install_grid_action_links', $action_links, $plugin );
|
413 |
|
414 |
-
$thumb =
|
415 |
-
|
416 |
-
|
417 |
-
else
|
418 |
$thumb = $plugin->thumb;
|
|
|
|
|
|
|
419 |
?>
|
420 |
<div>
|
421 |
<div class="sputnik-plugin<?php if ( ! empty( $plugin->thumb ) ) echo ' has-thumb'; ?>">
|
422 |
<div class="sputnik-card">
|
423 |
-
|
424 |
-
|
425 |
-
|
|
|
|
|
426 |
<div class="sputnik-plugin-thumb">
|
427 |
-
<img src="<?php echo esc_url($thumb) ?>" alt="<?php echo esc_attr($name) ?> Thumbnail">
|
428 |
</div>
|
429 |
-
<?php
|
430 |
-
|
431 |
-
?>
|
432 |
<div class="sputnik-plugin-details">
|
433 |
-
<
|
434 |
-
<span class="price"><?php echo $plugin->price ?></span>
|
435 |
-
<p><?php echo $plugin->description ?></p>
|
436 |
<?php if ( isset( $plugin->rating ) && isset( $plugin->rating->count ) ): ?>
|
437 |
<div class="footer" style="display:none">
|
438 |
<div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'wpsc' ), number_format_i18n( $plugin->rating->count ) ) ?>">
|
@@ -454,10 +459,10 @@ class Sputnik_List_Install extends WP_List_Table {
|
|
454 |
<?php endif; ?>
|
455 |
</div>
|
456 |
</div>
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
</div>
|
462 |
</div>
|
463 |
<?php
|
55 |
|
56 |
case 'search':
|
57 |
$term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
|
58 |
+
$api = Sputnik_API::search( urlencode( $term ), array( 'browse' => $tab ), $paged );
|
59 |
break;
|
60 |
|
61 |
case 'account':
|
106 |
|
107 |
echo '<p>';
|
108 |
if ( $tab == 'purchased' )
|
109 |
+
printf( __( "You haven't purchased any extensions yet. <a href='%s'>Browse our extensions marketplace.</a>", 'wpsc' ), Sputnik_Admin::build_url() );
|
110 |
else
|
111 |
_e( 'No plugins match your request.', 'wpsc' );
|
112 |
echo '</p>';
|
151 |
}
|
152 |
|
153 |
public function display_grid() {
|
|
|
154 |
|
155 |
$this->display_tablenav( 'top' );
|
156 |
?>
|
245 |
|
246 |
foreach ( (array) $this->items as $plugin ) {
|
247 |
$plugin->title = wp_kses( $plugin->name, $plugins_allowedtags );
|
248 |
+
|
249 |
+
//Limit description to 400char, and sanitize.
|
250 |
+
$plugin->description = wp_kses( $plugin->description, $plugins_allowedtags );
|
251 |
+
|
252 |
+
if ( strlen( $plugin->description ) > 400 ) {
|
253 |
$plugin->description = mb_substr( $plugin->description, 0, 400 ) . '…';
|
254 |
+
}
|
255 |
+
|
256 |
//remove any trailing entities
|
257 |
$plugin->description = preg_replace( '/&[^;\s]{0,6}$/', '', $plugin->description );
|
258 |
//strip leading/trailing & multiple consecutive lines
|
263 |
$plugin->version = wp_kses( $plugin->version, $plugins_allowedtags );
|
264 |
$plugin->price = sprintf('$%.2f', $plugin->price);
|
265 |
if ($plugin->price === '$0.00') {
|
266 |
+
$plugin->price = _x( 'Free', 'plugin price', 'wpsc' );
|
267 |
}
|
268 |
|
269 |
+
if ( ! empty( $plugin->author ) ) {
|
|
|
270 |
$plugin->author = ' <cite>' . sprintf( __( 'By %s', 'wpsc' ), $plugin->author ) . '.</cite>';
|
271 |
+
}
|
272 |
|
273 |
$plugin->author = wp_kses( $plugin->author, $plugins_allowedtags );
|
274 |
|
275 |
+
switch ( $this->view ) {
|
276 |
case 'list':
|
277 |
self::display_row($plugin, $style);
|
278 |
break;
|
304 |
break;
|
305 |
case 'install':
|
306 |
if ( $status['url'] ) {
|
307 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600), $status['url']);
|
308 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
309 |
. esc_attr(sprintf(__( 'Install %s', 'wpsc' ), $name)) . '">' . __('Install', 'wpsc' ) . '</a>';
|
310 |
}
|
315 |
break;
|
316 |
case 'update_available':
|
317 |
if ( $status['url'] ) {
|
318 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600), $status['url']);
|
319 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
320 |
. esc_attr(sprintf(__( 'Update to version %s', 'wpsc' ), $status['version'])) . '">' . __('Update', 'wpsc' ) . '</a>';
|
321 |
}
|
364 |
|
365 |
protected static function display_as_grid($plugin, $style) {
|
366 |
|
367 |
+
$name = strip_tags( $plugin->name );
|
368 |
$action_links = array();
|
369 |
$action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
|
370 |
. '" class="thickbox button info" title="' .
|
384 |
break;
|
385 |
case 'install':
|
386 |
if ( $status['url'] ) {
|
387 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600), $status['url']);
|
388 |
$purchase_link = '<a class="button install status" href="' . $status['url'] . '" title="'
|
389 |
. esc_attr(sprintf(__( 'Install %s', 'wpsc' ), $name)) . '">' . __('Install', 'wpsc' ) . '</a>';
|
390 |
}
|
395 |
break;
|
396 |
case 'update_available':
|
397 |
if ( $status['url'] ) {
|
398 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600), $status['url']);
|
399 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
400 |
. esc_attr(sprintf(__( 'Update to version %s', 'wpsc' ), $status['version'])) . '">' . __('Update', 'wpsc' ) . '</a>';
|
401 |
}
|
414 |
|
415 |
$action_links = apply_filters( 'sputnik_install_grid_action_links', $action_links, $plugin );
|
416 |
|
417 |
+
$thumb = '';
|
418 |
+
|
419 |
+
if ( ! empty( $plugin->thumb ) ) {
|
|
|
420 |
$thumb = $plugin->thumb;
|
421 |
+
}
|
422 |
+
|
423 |
+
$thumb = apply_filters( 'wpsc_marketplace_plugin_thumbnail_img_src', $thumb, $plugin );
|
424 |
?>
|
425 |
<div>
|
426 |
<div class="sputnik-plugin<?php if ( ! empty( $plugin->thumb ) ) echo ' has-thumb'; ?>">
|
427 |
<div class="sputnik-card">
|
428 |
+
<h4><?php echo $name ?><span class="price"><?php echo $plugin->price ?></span></h4>
|
429 |
+
|
430 |
+
<?php
|
431 |
+
if ( ! empty( $thumb ) ) :
|
432 |
+
?>
|
433 |
<div class="sputnik-plugin-thumb">
|
434 |
+
<img src="<?php echo esc_url( $thumb ) ?>" alt="<?php echo esc_attr( $name ) ?> Thumbnail">
|
435 |
</div>
|
436 |
+
<?php
|
437 |
+
endif;
|
438 |
+
?>
|
439 |
<div class="sputnik-plugin-details">
|
440 |
+
<p><?php echo $plugin->description; ?></p>
|
|
|
|
|
441 |
<?php if ( isset( $plugin->rating ) && isset( $plugin->rating->count ) ): ?>
|
442 |
<div class="footer" style="display:none">
|
443 |
<div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'wpsc' ), number_format_i18n( $plugin->rating->count ) ) ?>">
|
459 |
<?php endif; ?>
|
460 |
</div>
|
461 |
</div>
|
462 |
+
<div class="sputnik-plugin-actions">
|
463 |
+
<?php if ( !empty( $action_links ) ) echo implode( ' ', $action_links ); ?>
|
464 |
+
<?php echo $purchase_link; ?>
|
465 |
+
</div>
|
466 |
</div>
|
467 |
</div>
|
468 |
<?php
|
wpsc-components/marketplace-core-v1/library/Sputnik/Pointers.php
CHANGED
@@ -12,10 +12,10 @@ class Sputnik_Pointers {
|
|
12 |
|
13 |
$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
if ( $enqueue ) {
|
21 |
// Enqueue pointers
|
@@ -25,9 +25,9 @@ class Sputnik_Pointers {
|
|
25 |
}
|
26 |
|
27 |
public static function print_footer_scripts() {
|
28 |
-
$content = '<h3>' . __( 'New Feature: WPeC
|
29 |
-
$content .= '<p>' . __( 'Ever wanted to be able to find an extension for your
|
30 |
-
$content .= '<p>' . __( 'Find the latest and greatest free and premium plugins from the WP
|
31 |
?>
|
32 |
<script type="text/javascript">// <![CDATA[
|
33 |
jQuery(document).ready(function($) {
|
12 |
|
13 |
$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
|
14 |
|
15 |
+
if ( ! in_array( 'wpsc_marketplace_pointer', $dismissed ) && current_user_can( 'install_plugins' ) ) {
|
16 |
+
$enqueue = true;
|
17 |
+
add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_footer_scripts' ) );
|
18 |
+
}
|
19 |
|
20 |
if ( $enqueue ) {
|
21 |
// Enqueue pointers
|
25 |
}
|
26 |
|
27 |
public static function print_footer_scripts() {
|
28 |
+
$content = '<h3>' . __( 'New Feature: WPeC Extensions' ) . '</h3>';
|
29 |
+
$content .= '<p>' . __( 'Ever wanted to be able to find an extension for your WP eCommerce store and purchase, install and activate it right from WordPress? Now you can!', 'wpsc' ) . '</p>';
|
30 |
+
$content .= '<p>' . __( 'Find the latest and greatest free and premium plugins from the WP eCommerce community in our <a href="' . Sputnik_Admin::build_url() . '">Extensions Marketplace</a>.', 'wpsc' ) . '</p>';
|
31 |
?>
|
32 |
<script type="text/javascript">// <![CDATA[
|
33 |
jQuery(document).ready(function($) {
|
wpsc-components/marketplace-core-v1/library/Sputnik/ThemeUpgrader.php
CHANGED
@@ -33,7 +33,8 @@ class Sputnik_ThemeUpgrader extends Theme_Upgrader {
|
|
33 |
'timeout' => $timeout,
|
34 |
'stream' => true,
|
35 |
'filename' => $tmpfname,
|
36 |
-
'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() )
|
|
|
37 |
);
|
38 |
|
39 |
Sputnik_API::sign_download($url, $args);
|
33 |
'timeout' => $timeout,
|
34 |
'stream' => true,
|
35 |
'filename' => $tmpfname,
|
36 |
+
'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() ),
|
37 |
+
'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION
|
38 |
);
|
39 |
|
40 |
Sputnik_API::sign_download($url, $args);
|
wpsc-components/marketplace-core-v1/library/Sputnik/Theme_Upgrader.php
CHANGED
@@ -33,7 +33,8 @@ class Sputnik_ThemeUpgrader extends Theme_Upgrader {
|
|
33 |
'timeout' => $timeout,
|
34 |
'stream' => true,
|
35 |
'filename' => $tmpfname,
|
36 |
-
'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() )
|
|
|
37 |
);
|
38 |
|
39 |
Sputnik_API::sign_download($url, $args);
|
33 |
'timeout' => $timeout,
|
34 |
'stream' => true,
|
35 |
'filename' => $tmpfname,
|
36 |
+
'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() ),
|
37 |
+
'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION
|
38 |
);
|
39 |
|
40 |
Sputnik_API::sign_download($url, $args);
|
wpsc-components/marketplace-core-v1/library/Sputnik/Updater.php
CHANGED
@@ -41,7 +41,8 @@ class Sputnik_Updater {
|
|
41 |
$options = array(
|
42 |
'headers' => array(
|
43 |
'X-WP-Domain' => self::domain(),
|
44 |
-
)
|
|
|
45 |
);
|
46 |
$url = add_query_arg('plugins', urlencode(json_encode($data)), $url);
|
47 |
$req = wp_remote_get($url, $options);
|
@@ -114,7 +115,8 @@ class Sputnik_Updater {
|
|
114 |
$options = array(
|
115 |
'headers' => array(
|
116 |
'X-WP-Domain' => self::domain(),
|
117 |
-
)
|
|
|
118 |
);
|
119 |
$url = add_query_arg( 'themes', urlencode( json_encode( $data ) ), $url );
|
120 |
$req = wp_remote_get( $url, $options );
|
41 |
$options = array(
|
42 |
'headers' => array(
|
43 |
'X-WP-Domain' => self::domain(),
|
44 |
+
),
|
45 |
+
'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION
|
46 |
);
|
47 |
$url = add_query_arg('plugins', urlencode(json_encode($data)), $url);
|
48 |
$req = wp_remote_get($url, $options);
|
115 |
$options = array(
|
116 |
'headers' => array(
|
117 |
'X-WP-Domain' => self::domain(),
|
118 |
+
),
|
119 |
+
'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION
|
120 |
);
|
121 |
$url = add_query_arg( 'themes', urlencode( json_encode( $data ) ), $url );
|
122 |
$req = wp_remote_get( $url, $options );
|
wpsc-components/marketplace-core-v1/library/Sputnik/Upgrader.php
CHANGED
@@ -30,10 +30,11 @@ class Sputnik_Upgrader extends Plugin_Upgrader {
|
|
30 |
return new WP_Error('http_no_file', __('Could not create Temporary file.'));
|
31 |
|
32 |
$args = array(
|
33 |
-
'timeout'
|
34 |
-
'stream'
|
35 |
-
'filename'
|
36 |
-
'headers'
|
|
|
37 |
);
|
38 |
|
39 |
Sputnik_API::sign_download($url, $args);
|
30 |
return new WP_Error('http_no_file', __('Could not create Temporary file.'));
|
31 |
|
32 |
$args = array(
|
33 |
+
'timeout' => $timeout,
|
34 |
+
'stream' => true,
|
35 |
+
'filename' => $tmpfname,
|
36 |
+
'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() ),
|
37 |
+
'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION
|
38 |
);
|
39 |
|
40 |
Sputnik_API::sign_download($url, $args);
|
wpsc-components/marketplace-core-v1/library/Sputnik/View.php
CHANGED
@@ -30,8 +30,8 @@ abstract class Sputnik_View {
|
|
30 |
}
|
31 |
if ($account !== false) {
|
32 |
$tabs = array(
|
33 |
-
'dash' => __('Store', '
|
34 |
-
'account' => __('Your Account', '
|
35 |
);
|
36 |
$hrefs = array(
|
37 |
'dash' => Sputnik_Admin::build_url(),
|
@@ -72,7 +72,7 @@ abstract class Sputnik_View {
|
|
72 |
protected function footer() {?>
|
73 |
<div id="sputnik-footer">
|
74 |
<p class="logo-holder"><a href="http://wpeconomy.org/" class="renku-logo">WPEconomy</a></p>
|
75 |
-
<nav><p><a href="http://www.wpeconomy.org/documentation/developers/"><?php _e('Developer Tools', '
|
76 |
</div>
|
77 |
</div>
|
78 |
<?php
|
30 |
}
|
31 |
if ($account !== false) {
|
32 |
$tabs = array(
|
33 |
+
'dash' => __('Store', 'wpsc'),
|
34 |
+
'account' => __('Your Account', 'wpsc'),
|
35 |
);
|
36 |
$hrefs = array(
|
37 |
'dash' => Sputnik_Admin::build_url(),
|
72 |
protected function footer() {?>
|
73 |
<div id="sputnik-footer">
|
74 |
<p class="logo-holder"><a href="http://wpeconomy.org/" class="renku-logo">WPEconomy</a></p>
|
75 |
+
<nav><p><a href="http://www.wpeconomy.org/documentation/developers/"><?php _e('Developer Tools', 'wpsc') ?></a> | <a href="http://twitter.com/WPEconomy">@WPEconomy</a> | <a href="http://www.wpeconomy.org/documentation/marketplace/faqs/"><?php _e('FAQ', 'wpsc') ?></a></p></nav>
|
76 |
</div>
|
77 |
</div>
|
78 |
<?php
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Account.php
CHANGED
@@ -22,14 +22,14 @@ class Sputnik_View_Account extends Sputnik_View_Browser {
|
|
22 |
<div class="account-card">
|
23 |
<div class="block">
|
24 |
<?php echo get_avatar($account->email) ?>
|
25 |
-
<p class="lead-in"><?php _e('Logged in as', '
|
26 |
<h3><?php echo esc_html($account->name) ?></h3>
|
27 |
-
<p><?php printf(__('<a href="%s">Log out</a> of your account', '
|
28 |
</div>
|
29 |
<div class="block">
|
30 |
-
<p><?php printf(__('Email: %s', '
|
31 |
-
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', '
|
32 |
-
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', '
|
33 |
</div>
|
34 |
</div>
|
35 |
|
@@ -46,8 +46,8 @@ class Sputnik_View_Account extends Sputnik_View_Browser {
|
|
46 |
|
47 |
public function get_tabs() {
|
48 |
$tabs = array();
|
49 |
-
$tabs['purchased'] = __( 'Purchased Plugins', '
|
50 |
-
$tabs['yours'] = __( 'Your Plugins', '
|
51 |
return $tabs;
|
52 |
}
|
53 |
|
@@ -76,8 +76,8 @@ class Sputnik_View_Account extends Sputnik_View_Browser {
|
|
76 |
if ($tab === 'yours') {
|
77 |
$api['body'][] = (object) array(
|
78 |
'slug' => '__add_new',
|
79 |
-
'name' => __('Add Your Plugin', '
|
80 |
-
'description' => __('List your plugin on the WPEconomy store. Read our developer documentation and get started!', '
|
81 |
'rating' => (object) array('average' => 0, 'count' => 0),
|
82 |
'price' => 0,
|
83 |
'version' => '',
|
@@ -116,10 +116,10 @@ class Sputnik_View_Account extends Sputnik_View_Browser {
|
|
116 |
global $tab;
|
117 |
echo '<p>';
|
118 |
if ($tab === 'yours') {
|
119 |
-
_e( "You haven't created any plugins yet. Check out our <a href='http://developer.renku.me/'>developer documentation</a> to find out how!", '
|
120 |
}
|
121 |
else {
|
122 |
-
printf(__( "You haven't purchased any plugins yet. Why not <a href='%s'>buy some</a>?", '
|
123 |
}
|
124 |
echo '</p>';
|
125 |
}
|
@@ -132,8 +132,8 @@ class Sputnik_View_Account extends Sputnik_View_Browser {
|
|
132 |
$actions[] = sprintf(
|
133 |
'<a href="%s" class="button edit" title="%s">%s</a>',
|
134 |
sprintf(Sputnik::SITE_BASE . '/plugins/%d/edit/', $plugin->product_id),
|
135 |
-
esc_attr(sprintf(_x('Edit %s', 'Edit button title', '
|
136 |
-
_x('Edit', 'Edit button text', '
|
137 |
);
|
138 |
return $actions;
|
139 |
}
|
22 |
<div class="account-card">
|
23 |
<div class="block">
|
24 |
<?php echo get_avatar($account->email) ?>
|
25 |
+
<p class="lead-in"><?php _e('Logged in as', 'wpsc') ?></p>
|
26 |
<h3><?php echo esc_html($account->name) ?></h3>
|
27 |
+
<p><?php printf(__('<a href="%s">Log out</a> of your account', 'wpsc'), Sputnik_Admin::build_url(array('oauth' => 'reset'))) ?></p>
|
28 |
</div>
|
29 |
<div class="block">
|
30 |
+
<p><?php printf(__('Email: %s', 'wpsc'), '<code>' . $account->email . '</code>') ?></p>
|
31 |
+
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', 'wpsc'), count($account->purchased)) ?></p>
|
32 |
+
<p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', 'wpsc'), $this->count) ?></p>
|
33 |
</div>
|
34 |
</div>
|
35 |
|
46 |
|
47 |
public function get_tabs() {
|
48 |
$tabs = array();
|
49 |
+
$tabs['purchased'] = __( 'Purchased Plugins', 'wpsc' );
|
50 |
+
$tabs['yours'] = __( 'Your Plugins', 'wpsc' );
|
51 |
return $tabs;
|
52 |
}
|
53 |
|
76 |
if ($tab === 'yours') {
|
77 |
$api['body'][] = (object) array(
|
78 |
'slug' => '__add_new',
|
79 |
+
'name' => __('Add Your Plugin', 'wpsc'),
|
80 |
+
'description' => __('List your plugin on the WPEconomy store. Read our developer documentation and get started!', 'wpsc'),
|
81 |
'rating' => (object) array('average' => 0, 'count' => 0),
|
82 |
'price' => 0,
|
83 |
'version' => '',
|
116 |
global $tab;
|
117 |
echo '<p>';
|
118 |
if ($tab === 'yours') {
|
119 |
+
_e( "You haven't created any plugins yet. Check out our <a href='http://developer.renku.me/'>developer documentation</a> to find out how!", 'wpsc' );
|
120 |
}
|
121 |
else {
|
122 |
+
printf(__( "You haven't purchased any plugins yet. Why not <a href='%s'>buy some</a>?", 'wpsc' ), Sputnik_Admin::build_url());
|
123 |
}
|
124 |
echo '</p>';
|
125 |
}
|
132 |
$actions[] = sprintf(
|
133 |
'<a href="%s" class="button edit" title="%s">%s</a>',
|
134 |
sprintf(Sputnik::SITE_BASE . '/plugins/%d/edit/', $plugin->product_id),
|
135 |
+
esc_attr(sprintf(_x('Edit %s', 'Edit button title', 'wpsc'), $plugin->name)),
|
136 |
+
_x('Edit', 'Edit button text', 'wpsc')
|
137 |
);
|
138 |
return $actions;
|
139 |
}
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Auth.php
CHANGED
@@ -18,7 +18,7 @@ class Sputnik_View_Auth extends Sputnik_View {
|
|
18 |
}
|
19 |
public function render() {
|
20 |
if ( isset( $_GET['auth'] ) && $_GET['auth'] == 'denied' ) {
|
21 |
-
Sputnik_Admin::add_message( __( 'Account linking cancelled. Please note that you need to link your account in order to access the store.', '
|
22 |
}
|
23 |
|
24 |
$this->header();
|
18 |
}
|
19 |
public function render() {
|
20 |
if ( isset( $_GET['auth'] ) && $_GET['auth'] == 'denied' ) {
|
21 |
+
Sputnik_Admin::add_message( __( 'Account linking cancelled. Please note that you need to link your account in order to access the store.', 'wpsc' ) );
|
22 |
}
|
23 |
|
24 |
$this->header();
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser.php
CHANGED
@@ -56,14 +56,14 @@ class Sputnik_View_Browser extends Sputnik_View {
|
|
56 |
|
57 |
global $tab;
|
58 |
$tabs = array();
|
59 |
-
$tabs['dashboard'] = __( 'Search', '
|
60 |
if ( 'search' == $tab )
|
61 |
-
$tabs['search'] = __( 'Search Results', '
|
62 |
-
$tabs['featured'] = _x( 'Featured', 'Plugin Installer', '
|
63 |
-
$tabs['popular'] = _x( 'Popular', 'Plugin Installer', '
|
64 |
-
$tabs['new'] = _x( 'Newest', 'Plugin Installer', '
|
65 |
-
$tabs['updated'] = _x( 'Recently Updated', 'Plugin Installer', '
|
66 |
-
$tabs['price'] = _x( 'Lowest Priced', 'Plugin Installer', '
|
67 |
return $tabs;
|
68 |
}
|
69 |
|
@@ -99,7 +99,7 @@ class Sputnik_View_Browser extends Sputnik_View {
|
|
99 |
}
|
100 |
|
101 |
public function no_items() {
|
102 |
-
echo '<p>' . __( 'No plugins match your request.', '
|
103 |
}
|
104 |
|
105 |
public function footer() {
|
56 |
|
57 |
global $tab;
|
58 |
$tabs = array();
|
59 |
+
$tabs['dashboard'] = __( 'Search', 'wpsc' );
|
60 |
if ( 'search' == $tab )
|
61 |
+
$tabs['search'] = __( 'Search Results', 'wpsc' );
|
62 |
+
$tabs['featured'] = _x( 'Featured', 'Plugin Installer', 'wpsc' );
|
63 |
+
$tabs['popular'] = _x( 'Popular', 'Plugin Installer', 'wpsc' );
|
64 |
+
$tabs['new'] = _x( 'Newest', 'Plugin Installer', 'wpsc' );
|
65 |
+
$tabs['updated'] = _x( 'Recently Updated', 'Plugin Installer', 'wpsc' );
|
66 |
+
$tabs['price'] = _x( 'Lowest Priced', 'Plugin Installer', 'wpsc' );
|
67 |
return $tabs;
|
68 |
}
|
69 |
|
99 |
}
|
100 |
|
101 |
public function no_items() {
|
102 |
+
echo '<p>' . __( 'No plugins match your request.', 'wpsc' ) . '</p>';
|
103 |
}
|
104 |
|
105 |
public function footer() {
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/Grid.php
CHANGED
@@ -70,8 +70,8 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
70 |
|
71 |
public function view_switcher() {
|
72 |
$modes = array(
|
73 |
-
'list' => __('List View', '
|
74 |
-
'grid' => __('Grid View', '
|
75 |
);
|
76 |
$current_mode = $this->parent->view_type;
|
77 |
?>
|
@@ -135,7 +135,7 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
135 |
if ( 'top' == $which ) { ?>
|
136 |
<div class="tablenav top">
|
137 |
<div class="alignright account">
|
138 |
-
<?php printf(__('Logged in as %s', '
|
139 |
<?php
|
140 |
if ($tab === 'search') {
|
141 |
?>
|
@@ -168,11 +168,11 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
168 |
|
169 |
public function get_columns() {
|
170 |
return array(
|
171 |
-
'name' => _x( 'Name', 'plugin name', '
|
172 |
-
'version' => __( 'Version', '
|
173 |
-
'price' => __( 'Action', '
|
174 |
-
'rating' => __( 'Rating', '
|
175 |
-
'description' => __( 'Description', '
|
176 |
);
|
177 |
}
|
178 |
|
@@ -208,12 +208,11 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
208 |
$plugin->version = wp_kses( $plugin->version, $plugins_allowedtags );
|
209 |
$plugin->price = sprintf('$%.2f', $plugin->price);
|
210 |
if ($plugin->price === '$0.00') {
|
211 |
-
$plugin->price = _x('Free', 'plugin price', '
|
212 |
}
|
213 |
|
214 |
-
$plugin->author = $plugin->author;
|
215 |
if (!empty($plugin->author))
|
216 |
-
$plugin->author = ' <cite>' . sprintf( __( 'By %s', '
|
217 |
|
218 |
$plugin->author = wp_kses( $plugin->author, $plugins_allowedtags );
|
219 |
|
@@ -222,11 +221,11 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
222 |
}
|
223 |
|
224 |
protected function display_row($plugin, $style) {
|
225 |
-
$name = strip_tags( $plugin->name
|
226 |
$action_links = array();
|
227 |
$action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
|
228 |
. '" class="thickbox button info" title="' .
|
229 |
-
esc_attr( sprintf( __( 'More information about %s', '
|
230 |
|
231 |
$purchase_link = $plugin->price;
|
232 |
|
@@ -234,8 +233,8 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
234 |
$status = 'addown';
|
235 |
$name = $plugin->name;
|
236 |
$action_links = array();
|
237 |
-
$action_links[] = '<a href="http://developer.renku.me/" class="thickbox button info">' . __( 'Documentation', '
|
238 |
-
$purchase_link = '<a class="button-primary addown status" href="' . Sputnik::SITE_BASE . '/plugins/add/">' . esc_html__('Add Now', '
|
239 |
}
|
240 |
elseif ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
|
241 |
$status = Sputnik_Admin::install_status( $plugin );
|
@@ -244,35 +243,35 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
244 |
case 'purchase':
|
245 |
if ( $status['url'] ) {
|
246 |
$purchase_link = '<a id="' . $plugin->slug .'" class="button-primary buy status" href="' . $status['url'] . '" title="'
|
247 |
-
. esc_attr(sprintf(__( 'Buy %s', '
|
248 |
}
|
249 |
break;
|
250 |
case 'install':
|
251 |
if ( $status['url'] ) {
|
252 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
253 |
$purchase_link = '<a class="button install status" href="' . $status['url'] . '" title="'
|
254 |
-
. esc_attr(sprintf(__( 'Install %s', '
|
255 |
}
|
256 |
else {
|
257 |
-
$purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', '
|
258 |
-
. __('Install', '
|
259 |
}
|
260 |
break;
|
261 |
case 'update_available':
|
262 |
if ( $status['url'] ) {
|
263 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
264 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
265 |
-
. esc_attr(sprintf(__( 'Update to version %s', '
|
266 |
}
|
267 |
else {
|
268 |
-
$purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', '
|
269 |
-
. __('Update', '
|
270 |
}
|
271 |
break;
|
272 |
case 'latest_installed':
|
273 |
case 'newer_installed':
|
274 |
-
$purchase_link = '<span class="status" title="' . esc_attr__('This plugin is already installed and is up to date', '
|
275 |
-
. __('Installed', '
|
276 |
break;
|
277 |
}
|
278 |
}
|
@@ -285,32 +284,42 @@ class Sputnik_View_Browser_Grid extends WP_List_Table {
|
|
285 |
}
|
286 |
?>
|
287 |
<div>
|
288 |
-
<div class="sputnik-plugin<?php if ($thumb
|
289 |
<div class="sputnik-card">
|
290 |
-
|
291 |
-
|
292 |
-
|
|
|
|
|
293 |
<div class="sputnik-plugin-thumb">
|
294 |
-
<img src="<?php echo esc_url($thumb) ?>" alt="<?php echo esc_attr($name) ?> Thumbnail">
|
295 |
</div>
|
296 |
-
<?php
|
297 |
-
|
298 |
-
?>
|
299 |
<div class="sputnik-plugin-details">
|
300 |
-
<
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
</div>
|
307 |
-
|
308 |
</div>
|
309 |
</div>
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
</div>
|
315 |
</div>
|
316 |
<?php
|
70 |
|
71 |
public function view_switcher() {
|
72 |
$modes = array(
|
73 |
+
'list' => __('List View', 'wpsc'),
|
74 |
+
'grid' => __('Grid View', 'wpsc')
|
75 |
);
|
76 |
$current_mode = $this->parent->view_type;
|
77 |
?>
|
135 |
if ( 'top' == $which ) { ?>
|
136 |
<div class="tablenav top">
|
137 |
<div class="alignright account">
|
138 |
+
<?php printf(__('Logged in as %s', 'wpsc'), '<a href="' . menu_page_url( 'sputnik-account', false ) . '" class="account-link">' . $account->name . '</a>') ?>
|
139 |
<?php
|
140 |
if ($tab === 'search') {
|
141 |
?>
|
168 |
|
169 |
public function get_columns() {
|
170 |
return array(
|
171 |
+
'name' => _x( 'Name', 'plugin name', 'wpsc' ),
|
172 |
+
'version' => __( 'Version', 'wpsc' ),
|
173 |
+
'price' => __( 'Action', 'wpsc' ),
|
174 |
+
'rating' => __( 'Rating', 'wpsc' ),
|
175 |
+
'description' => __( 'Description', 'wpsc' ),
|
176 |
);
|
177 |
}
|
178 |
|
208 |
$plugin->version = wp_kses( $plugin->version, $plugins_allowedtags );
|
209 |
$plugin->price = sprintf('$%.2f', $plugin->price);
|
210 |
if ($plugin->price === '$0.00') {
|
211 |
+
$plugin->price = _x('Free', 'plugin price', 'wpsc');
|
212 |
}
|
213 |
|
|
|
214 |
if (!empty($plugin->author))
|
215 |
+
$plugin->author = ' <cite>' . sprintf( __( 'By %s', 'wpsc' ), $plugin->author ) . '.</cite>';
|
216 |
|
217 |
$plugin->author = wp_kses( $plugin->author, $plugins_allowedtags );
|
218 |
|
221 |
}
|
222 |
|
223 |
protected function display_row($plugin, $style) {
|
224 |
+
$name = strip_tags( $plugin->name );
|
225 |
$action_links = array();
|
226 |
$action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
|
227 |
. '" class="thickbox button info" title="' .
|
228 |
+
esc_attr( sprintf( __( 'More information about %s', 'wpsc' ), $name ) ) . '">' . __( 'Details', 'wpsc' ) . '</a>';
|
229 |
|
230 |
$purchase_link = $plugin->price;
|
231 |
|
233 |
$status = 'addown';
|
234 |
$name = $plugin->name;
|
235 |
$action_links = array();
|
236 |
+
$action_links[] = '<a href="http://developer.renku.me/" class="thickbox button info">' . __( 'Documentation', 'wpsc' ) . '</a>';
|
237 |
+
$purchase_link = '<a class="button-primary addown status" href="' . Sputnik::SITE_BASE . '/plugins/add/">' . esc_html__('Add Now', 'wpsc') . '</a>';
|
238 |
}
|
239 |
elseif ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
|
240 |
$status = Sputnik_Admin::install_status( $plugin );
|
243 |
case 'purchase':
|
244 |
if ( $status['url'] ) {
|
245 |
$purchase_link = '<a id="' . $plugin->slug .'" class="button-primary buy status" href="' . $status['url'] . '" title="'
|
246 |
+
. esc_attr(sprintf(__( 'Buy %s', 'wpsc'), $name)) . '">' . __('Buy Now', 'wpsc') . '</a>';
|
247 |
}
|
248 |
break;
|
249 |
case 'install':
|
250 |
if ( $status['url'] ) {
|
251 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600 ), $status['url']);
|
252 |
$purchase_link = '<a class="button install status" href="' . $status['url'] . '" title="'
|
253 |
+
. esc_attr(sprintf(__( 'Install %s', 'wpsc'), $name)) . '">' . __('Install', 'wpsc') . '</a>';
|
254 |
}
|
255 |
else {
|
256 |
+
$purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc') . '">'
|
257 |
+
. __('Install', 'wpsc') . '</span>';
|
258 |
}
|
259 |
break;
|
260 |
case 'update_available':
|
261 |
if ( $status['url'] ) {
|
262 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600), $status['url']);
|
263 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
264 |
+
. esc_attr(sprintf(__( 'Update to version %s', 'wpsc'), $status['version'])) . '">' . __('Update', 'wpsc') . '</a>';
|
265 |
}
|
266 |
else {
|
267 |
+
$purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc') . '">'
|
268 |
+
. __('Update', 'wpsc') . '</span>';
|
269 |
}
|
270 |
break;
|
271 |
case 'latest_installed':
|
272 |
case 'newer_installed':
|
273 |
+
$purchase_link = '<span class="status" title="' . esc_attr__('This plugin is already installed and is up to date', 'wpsc') . ' ">'
|
274 |
+
. __('Installed', 'wpsc') . '</span>';
|
275 |
break;
|
276 |
}
|
277 |
}
|
284 |
}
|
285 |
?>
|
286 |
<div>
|
287 |
+
<div class="sputnik-plugin<?php if ( ! empty( $plugin->thumb ) ) echo ' has-thumb'; ?>">
|
288 |
<div class="sputnik-card">
|
289 |
+
<h4><?php echo $name ?><span class="price"><?php echo $plugin->price ?></span></h4>
|
290 |
+
|
291 |
+
<?php
|
292 |
+
if ( ! empty( $thumb ) ) :
|
293 |
+
?>
|
294 |
<div class="sputnik-plugin-thumb">
|
295 |
+
<img src="<?php echo esc_url( $thumb ) ?>" alt="<?php echo esc_attr( $name ) ?> Thumbnail">
|
296 |
</div>
|
297 |
+
<?php
|
298 |
+
endif;
|
299 |
+
?>
|
300 |
<div class="sputnik-plugin-details">
|
301 |
+
<p><?php echo $plugin->description; ?></p>
|
302 |
+
<?php if ( isset( $plugin->rating ) && isset( $plugin->rating->count ) ): ?>
|
303 |
+
<div class="footer" style="display:none">
|
304 |
+
<div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'wpsc' ), number_format_i18n( $plugin->rating->count ) ) ?>">
|
305 |
+
<div class="star star-rating" style="width: <?php echo (int) (20 * $plugin->rating->average) ?>px"></div>
|
306 |
+
<?php
|
307 |
+
$star_url = admin_url( 'images/stars.png?v=20110615' );
|
308 |
+
?>
|
309 |
+
<div class="star star5"><img src="<?php echo $star_url; ?>" alt="" /></div>
|
310 |
+
<div class="star star4"><img src="<?php echo $star_url; ?>" alt="" /></div>
|
311 |
+
<div class="star star3"><img src="<?php echo $star_url; ?>" alt="" /></div>
|
312 |
+
<div class="star star2"><img src="<?php echo $star_url; ?>" alt="" /></div>
|
313 |
+
<div class="star star1"><img src="<?php echo $star_url; ?>" alt="" /></div>
|
314 |
+
</div>
|
315 |
</div>
|
316 |
+
<?php endif; ?>
|
317 |
</div>
|
318 |
</div>
|
319 |
+
<div class="sputnik-plugin-actions">
|
320 |
+
<?php if ( !empty( $action_links ) ) echo implode( ' ', $action_links ); ?>
|
321 |
+
<?php echo $purchase_link; ?>
|
322 |
+
</div>
|
323 |
</div>
|
324 |
</div>
|
325 |
<?php
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/List.php
CHANGED
@@ -11,7 +11,7 @@ class Sputnik_View_Browser_List extends Sputnik_View_Browser_Grid {
|
|
11 |
$action_links = array();
|
12 |
$action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
|
13 |
. '" class="button thickbox info" title="' .
|
14 |
-
esc_attr( sprintf( __( 'More information about %s', '
|
15 |
|
16 |
$purchase_link = $plugin->price;
|
17 |
|
@@ -19,8 +19,8 @@ class Sputnik_View_Browser_List extends Sputnik_View_Browser_Grid {
|
|
19 |
$status = 'addown';
|
20 |
$style['name'] .= ' class="addown"';
|
21 |
$action_links = array();
|
22 |
-
$action_links[] = '<a href="http://developer.renku.me/" class="thickbox button info">' . __( 'Documentation', '
|
23 |
-
$purchase_link = '<a class="button-primary addown" href="' . Sputnik::SITE_BASE . '/plugins/add/" title="Add New Plugin">' . esc_html__('Add Now', '
|
24 |
}
|
25 |
elseif ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
|
26 |
$status = Sputnik_Admin::install_status( $plugin );
|
@@ -29,35 +29,35 @@ class Sputnik_View_Browser_List extends Sputnik_View_Browser_Grid {
|
|
29 |
case 'purchase':
|
30 |
if ( $status['url'] ) {
|
31 |
$purchase_link = '<a id="' . $plugin->slug . '" class="button-primary buy" href="' . $status['url'] . '" title="'
|
32 |
-
. esc_attr(sprintf(__( 'Buy %s', '
|
33 |
}
|
34 |
break;
|
35 |
case 'install':
|
36 |
if ( $status['url'] ) {
|
37 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
38 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
39 |
-
. esc_attr(sprintf(__( 'Install %s', '
|
40 |
}
|
41 |
else {
|
42 |
-
$purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', '
|
43 |
-
. __('Install', '
|
44 |
}
|
45 |
break;
|
46 |
case 'update_available':
|
47 |
if ( $status['url'] ) {
|
48 |
-
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' =>
|
49 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
50 |
-
. esc_attr(sprintf(__( 'Update to version %s', '
|
51 |
}
|
52 |
else {
|
53 |
-
$purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', '
|
54 |
-
. __('Update', '
|
55 |
}
|
56 |
break;
|
57 |
case 'latest_installed':
|
58 |
case 'newer_installed':
|
59 |
-
$purchase_link = '<span title="' . esc_attr__('This plugin is already installed and is up to date', '
|
60 |
-
. __('Installed', '
|
61 |
break;
|
62 |
}
|
63 |
}
|
@@ -71,7 +71,7 @@ class Sputnik_View_Browser_List extends Sputnik_View_Browser_Grid {
|
|
71 |
<td class="vers column-version"<?php echo $style['version']; ?>><?php echo $plugin->version; ?></td>
|
72 |
<td class="vers column-price"<?php echo $style['price']; ?>><?php echo $purchase_link; ?></td>
|
73 |
<td class="vers column-rating"<?php echo $style['rating']; ?>>
|
74 |
-
<div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, '
|
75 |
<div class="star star-rating" style="width: <?php echo (int) (20 * $plugin->rating->average) ?>px"></div>
|
76 |
</div>
|
77 |
</td>
|
11 |
$action_links = array();
|
12 |
$action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
|
13 |
. '" class="button thickbox info" title="' .
|
14 |
+
esc_attr( sprintf( __( 'More information about %s', 'wpsc' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
|
15 |
|
16 |
$purchase_link = $plugin->price;
|
17 |
|
19 |
$status = 'addown';
|
20 |
$style['name'] .= ' class="addown"';
|
21 |
$action_links = array();
|
22 |
+
$action_links[] = '<a href="http://developer.renku.me/" class="thickbox button info">' . __( 'Documentation', 'wpsc' ) . '</a>';
|
23 |
+
$purchase_link = '<a class="button-primary addown" href="' . Sputnik::SITE_BASE . '/plugins/add/" title="Add New Plugin">' . esc_html__('Add Now', 'wpsc') . '</a>';
|
24 |
}
|
25 |
elseif ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
|
26 |
$status = Sputnik_Admin::install_status( $plugin );
|
29 |
case 'purchase':
|
30 |
if ( $status['url'] ) {
|
31 |
$purchase_link = '<a id="' . $plugin->slug . '" class="button-primary buy" href="' . $status['url'] . '" title="'
|
32 |
+
. esc_attr(sprintf(__( 'Buy %s', 'wpsc'), $name)) . '">' . sprintf(__('<span>%s</span> Buy Now</a>', 'wpsc'), $plugin->price);
|
33 |
}
|
34 |
break;
|
35 |
case 'install':
|
36 |
if ( $status['url'] ) {
|
37 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600 ), $status['url']);
|
38 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
39 |
+
. esc_attr(sprintf(__( 'Install %s', 'wpsc'), $name)) . '">' . __('Install', 'wpsc') . '</a>';
|
40 |
}
|
41 |
else {
|
42 |
+
$purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc') . '">'
|
43 |
+
. __('Install', 'wpsc') . '</span>';
|
44 |
}
|
45 |
break;
|
46 |
case 'update_available':
|
47 |
if ( $status['url'] ) {
|
48 |
+
$status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 800, 'height' => 600 ), $status['url']);
|
49 |
$purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
|
50 |
+
. esc_attr(sprintf(__( 'Update to version %s', 'wpsc'), $status['version'])) . '">' . __('Update', 'wpsc') . '</a>';
|
51 |
}
|
52 |
else {
|
53 |
+
$purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc') . '">'
|
54 |
+
. __('Update', 'wpsc') . '</span>';
|
55 |
}
|
56 |
break;
|
57 |
case 'latest_installed':
|
58 |
case 'newer_installed':
|
59 |
+
$purchase_link = '<span title="' . esc_attr__('This plugin is already installed and is up to date', 'wpsc') . ' ">'
|
60 |
+
. __('Installed', 'wpsc') . '</span>';
|
61 |
break;
|
62 |
}
|
63 |
}
|
71 |
<td class="vers column-version"<?php echo $style['version']; ?>><?php echo $plugin->version; ?></td>
|
72 |
<td class="vers column-price"<?php echo $style['price']; ?>><?php echo $purchase_link; ?></td>
|
73 |
<td class="vers column-rating"<?php echo $style['rating']; ?>>
|
74 |
+
<div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'wpsc' ), number_format_i18n( $plugin->rating->count ) ) ?>">
|
75 |
<div class="star star-rating" style="width: <?php echo (int) (20 * $plugin->rating->average) ?>px"></div>
|
76 |
</div>
|
77 |
</td>
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Info.php
CHANGED
@@ -19,7 +19,7 @@ class Sputnik_View_Info extends Sputnik_View_Mini {
|
|
19 |
protected $api;
|
20 |
|
21 |
public function __construct() {
|
22 |
-
parent::__construct( __('Plugin Information', '
|
23 |
$this->plugin = $_GET['info'];
|
24 |
|
25 |
try {
|
@@ -28,7 +28,7 @@ class Sputnik_View_Info extends Sputnik_View_Mini {
|
|
28 |
}
|
29 |
catch (Exception $e) {
|
30 |
status_header(500);
|
31 |
-
iframe_header( __('', '
|
32 |
echo $e->getMessage();
|
33 |
iframe_footer();
|
34 |
die();
|
@@ -48,12 +48,12 @@ class Sputnik_View_Info extends Sputnik_View_Mini {
|
|
48 |
'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
|
49 |
|
50 |
$plugins_section_titles = array(
|
51 |
-
'description' => _x('Description', 'Plugin installer section title', '
|
52 |
-
'installation' => _x('Installation', 'Plugin installer section title', '
|
53 |
-
'faq' => _x('FAQ', 'Plugin installer section title', '
|
54 |
-
'screenshots' => _x('Screenshots', 'Plugin installer section title', '
|
55 |
-
'changelog' => _x('Changelog', 'Plugin installer section title', '
|
56 |
-
'other_notes' => _x('Other Notes', 'Plugin installer section title', '
|
57 |
);
|
58 |
//Sanitize HTML
|
59 |
$api->sections = (array) $api->sections;
|
@@ -92,21 +92,21 @@ class Sputnik_View_Info extends Sputnik_View_Mini {
|
|
92 |
case 'purchase':
|
93 |
default:
|
94 |
if ( $status['url'] )
|
95 |
-
echo '<a href="' . $status['url'] . '" target="_parent" class="button-primary buy">' . sprintf(__('<span>$%.2f</span> Buy & Install', '
|
96 |
break;
|
97 |
case 'install':
|
98 |
if ( $status['url'] )
|
99 |
-
echo '<a href="' . $status['url'] . '" class="button-primary install" title="' . __('You have already purchased, install now', '
|
100 |
break;
|
101 |
case 'update_available':
|
102 |
if ( $status['url'] )
|
103 |
-
echo '<a href="' . $status['url'] . '" class="button-primary install">' . __('Install Update Now', '
|
104 |
break;
|
105 |
case 'newer_installed':
|
106 |
-
echo '<a>' . sprintf(__('Newer Version (%s) Installed', '
|
107 |
break;
|
108 |
case 'latest_installed':
|
109 |
-
echo '<a>' . __('Latest Version Installed', '
|
110 |
break;
|
111 |
}
|
112 |
?>
|
@@ -137,23 +137,23 @@ class Sputnik_View_Info extends Sputnik_View_Mini {
|
|
137 |
echo "</ul>\n";
|
138 |
echo "</div>\n";
|
139 |
?>
|
140 |
-
<h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI', '
|
141 |
<ul>
|
142 |
<?php if ( ! empty($api->version) ) : ?>
|
143 |
-
<li><strong><?php _e('Version:', '
|
144 |
<?php endif; if ( ! empty($api->author) ) : ?>
|
145 |
-
<li><strong><?php _e('Author:', '
|
146 |
<?php endif; if ( ! empty($api->last_updated) ) : ?>
|
147 |
-
<li><strong><?php _e('Last Updated:', '
|
148 |
-
printf( __('%s ago', '
|
149 |
<?php endif; if ( ! empty($api->requires) ) : ?>
|
150 |
-
<li><strong><?php _e('Requires WordPress Version:', '
|
151 |
<?php endif; if ( ! empty($api->tested) ) : ?>
|
152 |
-
<li><strong><?php _e('Compatible up to:', '
|
153 |
<?php endif; if ( ! empty($api->downloaded) ) : ?>
|
154 |
-
<li><strong><?php _e('Downloaded:', '
|
155 |
<?php endif; if ( ! empty($api->homepage) ) : ?>
|
156 |
-
<li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage »', '
|
157 |
<?php endif; ?>
|
158 |
</ul>
|
159 |
|
@@ -161,10 +161,10 @@ class Sputnik_View_Info extends Sputnik_View_Mini {
|
|
161 |
<div id="section-holder" class="wrap">
|
162 |
<?php
|
163 |
if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
|
164 |
-
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.', '
|
165 |
|
166 |
else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
|
167 |
-
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.', '
|
168 |
|
169 |
foreach ( $api->sections as $section_name => $content ) {
|
170 |
if ( isset( $plugins_section_titles[ $section_name ] ) )
|
19 |
protected $api;
|
20 |
|
21 |
public function __construct() {
|
22 |
+
parent::__construct( __('Plugin Information', 'wpsc') );
|
23 |
$this->plugin = $_GET['info'];
|
24 |
|
25 |
try {
|
28 |
}
|
29 |
catch (Exception $e) {
|
30 |
status_header(500);
|
31 |
+
iframe_header( __('', 'wpsc') );
|
32 |
echo $e->getMessage();
|
33 |
iframe_footer();
|
34 |
die();
|
48 |
'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
|
49 |
|
50 |
$plugins_section_titles = array(
|
51 |
+
'description' => _x('Description', 'Plugin installer section title', 'wpsc'),
|
52 |
+
'installation' => _x('Installation', 'Plugin installer section title', 'wpsc'),
|
53 |
+
'faq' => _x('FAQ', 'Plugin installer section title', 'wpsc'),
|
54 |
+
'screenshots' => _x('Screenshots', 'Plugin installer section title', 'wpsc'),
|
55 |
+
'changelog' => _x('Changelog', 'Plugin installer section title', 'wpsc'),
|
56 |
+
'other_notes' => _x('Other Notes', 'Plugin installer section title', 'wpsc')
|
57 |
);
|
58 |
//Sanitize HTML
|
59 |
$api->sections = (array) $api->sections;
|
92 |
case 'purchase':
|
93 |
default:
|
94 |
if ( $status['url'] )
|
95 |
+
echo '<a href="' . $status['url'] . '" target="_parent" class="button-primary buy">' . sprintf(__('<span>$%.2f</span> Buy & Install', 'wpsc'), $api->price) . '</a>';
|
96 |
break;
|
97 |
case 'install':
|
98 |
if ( $status['url'] )
|
99 |
+
echo '<a href="' . $status['url'] . '" class="button-primary install" title="' . __('You have already purchased, install now', 'wpsc') . '">' . __('Install Now', 'wpsc') . '</a>';
|
100 |
break;
|
101 |
case 'update_available':
|
102 |
if ( $status['url'] )
|
103 |
+
echo '<a href="' . $status['url'] . '" class="button-primary install">' . __('Install Update Now', 'wpsc') .'</a>';
|
104 |
break;
|
105 |
case 'newer_installed':
|
106 |
+
echo '<a>' . sprintf(__('Newer Version (%s) Installed', 'wpsc'), $status['version']) . '</a>';
|
107 |
break;
|
108 |
case 'latest_installed':
|
109 |
+
echo '<a>' . __('Latest Version Installed', 'wpsc') . '</a>';
|
110 |
break;
|
111 |
}
|
112 |
?>
|
137 |
echo "</ul>\n";
|
138 |
echo "</div>\n";
|
139 |
?>
|
140 |
+
<h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI', 'wpsc') ?></h2>
|
141 |
<ul>
|
142 |
<?php if ( ! empty($api->version) ) : ?>
|
143 |
+
<li><strong><?php _e('Version:', 'wpsc') ?></strong> <?php echo $api->version ?></li>
|
144 |
<?php endif; if ( ! empty($api->author) ) : ?>
|
145 |
+
<li><strong><?php _e('Author:', 'wpsc') ?></strong> <?php echo $api->author ?></li>
|
146 |
<?php endif; if ( ! empty($api->last_updated) ) : ?>
|
147 |
+
<li><strong><?php _e('Last Updated:', 'wpsc') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
|
148 |
+
printf( __('%s ago', 'wpsc'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
|
149 |
<?php endif; if ( ! empty($api->requires) ) : ?>
|
150 |
+
<li><strong><?php _e('Requires WordPress Version:', 'wpsc') ?></strong> <?php printf(__('%s or higher', 'wpsc'), $api->requires) ?></li>
|
151 |
<?php endif; if ( ! empty($api->tested) ) : ?>
|
152 |
+
<li><strong><?php _e('Compatible up to:', 'wpsc') ?></strong> <?php echo $api->tested ?></li>
|
153 |
<?php endif; if ( ! empty($api->downloaded) ) : ?>
|
154 |
+
<li><strong><?php _e('Downloaded:', 'wpsc') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded, 'wpsc'), number_format_i18n($api->downloaded)) ?></li>
|
155 |
<?php endif; if ( ! empty($api->homepage) ) : ?>
|
156 |
+
<li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage »', 'wpsc') ?></a></li>
|
157 |
<?php endif; ?>
|
158 |
</ul>
|
159 |
|
161 |
<div id="section-holder" class="wrap">
|
162 |
<?php
|
163 |
if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
|
164 |
+
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.', 'wpsc') . '</p></div>';
|
165 |
|
166 |
else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
|
167 |
+
echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.', 'wpsc') . '</p></div>';
|
168 |
|
169 |
foreach ( $api->sections as $section_name => $content ) {
|
170 |
if ( isset( $plugins_section_titles[ $section_name ] ) )
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Install.php
CHANGED
@@ -22,13 +22,13 @@ class Sputnik_View_Install extends Sputnik_View_Mini {
|
|
22 |
protected $api = null;
|
23 |
|
24 |
public function __construct() {
|
25 |
-
parent::__construct(__('Plugin Install', '
|
26 |
$this->id = $_GET['install'];
|
27 |
-
$this->title = __('Installing Plugin: %s', '
|
28 |
}
|
29 |
|
30 |
protected function prepare() {
|
31 |
-
|
32 |
|
33 |
try {
|
34 |
$this->api = $api = Sputnik::get_plugin($this->id);
|
@@ -48,7 +48,7 @@ class Sputnik_View_Install extends Sputnik_View_Mini {
|
|
48 |
}
|
49 |
|
50 |
if ( ! current_user_can('install_plugins') )
|
51 |
-
wp_die(__('You do not have sufficient permissions to install plugins for this site.', '
|
52 |
|
53 |
check_admin_referer($this->nonce_prefix . $this->api->slug);
|
54 |
|
22 |
protected $api = null;
|
23 |
|
24 |
public function __construct() {
|
25 |
+
parent::__construct(__('Plugin Install', 'wpsc'));
|
26 |
$this->id = $_GET['install'];
|
27 |
+
$this->title = __('Installing Plugin: %s', 'wpsc');
|
28 |
}
|
29 |
|
30 |
protected function prepare() {
|
31 |
+
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
32 |
|
33 |
try {
|
34 |
$this->api = $api = Sputnik::get_plugin($this->id);
|
48 |
}
|
49 |
|
50 |
if ( ! current_user_can('install_plugins') )
|
51 |
+
wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'wpsc'));
|
52 |
|
53 |
check_admin_referer($this->nonce_prefix . $this->api->slug);
|
54 |
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Install/Skin.php
CHANGED
@@ -16,7 +16,7 @@ class Sputnik_View_Install_Skin extends WP_Upgrader_Skin {
|
|
16 |
|
17 |
function before() {
|
18 |
if ( ! empty( $this->api ) ) {
|
19 |
-
$asset_type = $this->api->is_theme ? 'theme' : 'plugin';
|
20 |
$this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the %s <strong>%s %s</strong>.'), $asset_type, $this->api->name, $this->api->version);
|
21 |
}
|
22 |
|
@@ -34,23 +34,23 @@ class Sputnik_View_Install_Skin extends WP_Upgrader_Skin {
|
|
34 |
// One-Click flow
|
35 |
if (!empty($_GET['also']) && $_GET['also'] == 'activate') {
|
36 |
if (!$this->result || is_wp_error($this->result)) {
|
37 |
-
show_message(__('Cannot activate plugin.', '
|
38 |
}
|
39 |
else {
|
40 |
-
show_message(__('Activating the plugin…', '
|
41 |
echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=0&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) .'"></iframe>';
|
42 |
}
|
43 |
}
|
44 |
else {
|
45 |
-
$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin', '
|
46 |
|
47 |
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
|
48 |
-
$install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network', '
|
49 |
unset( $install_actions['activate_plugin'] );
|
50 |
}
|
51 |
}
|
52 |
|
53 |
-
$install_actions['store'] = '<a href="' . Sputnik_Admin::build_url() . '" title="' . esc_attr__('Return to Store', '
|
54 |
|
55 |
|
56 |
if (!$this->result || is_wp_error($this->result)) {
|
16 |
|
17 |
function before() {
|
18 |
if ( ! empty( $this->api ) ) {
|
19 |
+
$asset_type = $this->api->is_theme ? 'theme' : 'plugin';
|
20 |
$this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the %s <strong>%s %s</strong>.'), $asset_type, $this->api->name, $this->api->version);
|
21 |
}
|
22 |
|
34 |
// One-Click flow
|
35 |
if (!empty($_GET['also']) && $_GET['also'] == 'activate') {
|
36 |
if (!$this->result || is_wp_error($this->result)) {
|
37 |
+
show_message(__('Cannot activate plugin.', 'wpsc'));
|
38 |
}
|
39 |
else {
|
40 |
+
show_message(__('Activating the plugin…', 'wpsc'));
|
41 |
echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=0&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) .'"></iframe>';
|
42 |
}
|
43 |
}
|
44 |
else {
|
45 |
+
$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin', 'wpsc') . '" target="_parent">' . __('Activate Plugin', 'wpsc') . '</a>';
|
46 |
|
47 |
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
|
48 |
+
$install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network', 'wpsc') . '" target="_parent">' . __('Network Activate', 'wpsc') . '</a>';
|
49 |
unset( $install_actions['activate_plugin'] );
|
50 |
}
|
51 |
}
|
52 |
|
53 |
+
$install_actions['store'] = '<a href="' . Sputnik_Admin::build_url() . '" title="' . esc_attr__('Return to Store', 'wpsc') . '" target="_parent" class="close">' . __('Return to Store', 'wpsc') . '</a>';
|
54 |
|
55 |
|
56 |
if (!$this->result || is_wp_error($this->result)) {
|
wpsc-components/marketplace-core-v1/library/Sputnik/View/Upgrade.php
CHANGED
@@ -17,11 +17,11 @@ class Sputnik_View_Upgrade extends Sputnik_View_Install {
|
|
17 |
|
18 |
public function __construct() {
|
19 |
parent::__construct();
|
20 |
-
$this->title = __('Update Plugin', '
|
21 |
|
22 |
$this->body_id = 'sputnik-upgrade';
|
23 |
$this->nonce_prefix = 'sputnik_upgrade-plugin_';
|
24 |
-
$this->title_format = __('Updating Plugin: %s', '
|
25 |
}
|
26 |
|
27 |
protected function prepare() {
|
@@ -29,13 +29,13 @@ class Sputnik_View_Upgrade extends Sputnik_View_Install {
|
|
29 |
$this->file = $_GET['upgrade'];
|
30 |
$data = Sputnik::get_from_file($file);
|
31 |
if ($data === null) {
|
32 |
-
throw new Exception(__('Plugin not found', '
|
33 |
}
|
34 |
$this->id = $data['Sputnik ID'];
|
35 |
}
|
36 |
catch (Exception $e) {
|
37 |
status_header(500);
|
38 |
-
iframe_header( __('Update Plugin', '
|
39 |
echo $e->getMessage();
|
40 |
iframe_footer();
|
41 |
die();
|
17 |
|
18 |
public function __construct() {
|
19 |
parent::__construct();
|
20 |
+
$this->title = __('Update Plugin', 'wpsc');
|
21 |
|
22 |
$this->body_id = 'sputnik-upgrade';
|
23 |
$this->nonce_prefix = 'sputnik_upgrade-plugin_';
|
24 |
+
$this->title_format = __('Updating Plugin: %s', 'wpsc');
|
25 |
}
|
26 |
|
27 |
protected function prepare() {
|
29 |
$this->file = $_GET['upgrade'];
|
30 |
$data = Sputnik::get_from_file($file);
|
31 |
if ($data === null) {
|
32 |
+
throw new Exception(__('Plugin not found', 'wpsc'));
|
33 |
}
|
34 |
$this->id = $data['Sputnik ID'];
|
35 |
}
|
36 |
catch (Exception $e) {
|
37 |
status_header(500);
|
38 |
+
iframe_header( __('Update Plugin', 'wpsc') );
|
39 |
echo $e->getMessage();
|
40 |
iframe_footer();
|
41 |
die();
|
wpsc-components/marketplace-core-v1/marketplace-core-v1.php
CHANGED
@@ -1,17 +1,8 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
-
update_option( '_wpsc_enable_marketplace', true );
|
5 |
-
|
6 |
-
if ( ! empty( $_GET['wpsc_disable_marketplace'] ) )
|
7 |
-
update_option( '_wpsc_enable_marketplace', false );
|
8 |
-
|
9 |
-
add_action( 'wpsc_includes', 'wpec_beta_marketplace_bootstrap', 12 );
|
10 |
-
|
11 |
-
function wpec_beta_marketplace_bootstrap() {
|
12 |
-
if ( ! get_option( '_wpsc_enable_marketplace', false ) )
|
13 |
-
return;
|
14 |
|
|
|
15 |
if ( ! class_exists( 'Sputnik' ) ) {
|
16 |
require_once( dirname( __FILE__ ) . '/library/Sputnik.php' );
|
17 |
Sputnik::$path = dirname( __FILE__ );
|
1 |
<?php
|
2 |
|
3 |
+
add_action( 'wpsc_includes', 'wpsc_beta_marketplace_bootstrap', 12 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
function wpsc_beta_marketplace_bootstrap() {
|
6 |
if ( ! class_exists( 'Sputnik' ) ) {
|
7 |
require_once( dirname( __FILE__ ) . '/library/Sputnik.php' );
|
8 |
Sputnik::$path = dirname( __FILE__ );
|
wpsc-components/marketplace-core-v1/static/admin.css
CHANGED
@@ -1,108 +1,95 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
-
|
21 |
-
}
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
background: radial-gradient(top, #F0F0F0, #FFFFFF 80%);
|
74 |
-
}
|
75 |
-
#sputnik-footer .logo-holder {
|
76 |
-
float: left;
|
77 |
-
}
|
78 |
-
#sputnik-footer .renku-logo {
|
79 |
-
background: url("logo.png") no-repeat scroll center center transparent;
|
80 |
-
text-indent: -9999px;
|
81 |
-
width: 47px;
|
82 |
-
height: 22px;
|
83 |
-
display: block;
|
84 |
-
}
|
85 |
-
#sputnik-footer nav {
|
86 |
-
float: right;
|
87 |
-
}
|
88 |
|
89 |
#sputnik-auth, #sputnik-page .connect-error {
|
90 |
font-size: 20px;
|
91 |
-
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
|
92 |
line-height: 1.6em;
|
93 |
color: #777;
|
94 |
max-width: 500px;
|
95 |
}
|
96 |
-
#sputnik-auth .buttons {
|
97 |
-
text-align: right;
|
98 |
-
}
|
99 |
-
#sputnik-auth .button {
|
100 |
-
font-size: 15px !important;
|
101 |
-
}
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
#sputnik-page a.view-as-list,
|
107 |
#sputnik-page a.view-as-grid {
|
108 |
background-image: url('icons.png'), linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
|
@@ -112,26 +99,30 @@
|
|
112 |
background-image: url('icons.png'), -ms-linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
|
113 |
background-repeat: no-repeat, repeat-x, repeat-x, repeat-x, repeat-x;
|
114 |
}
|
|
|
115 |
#sputnik-page a.view-as-list {
|
116 |
background-position: right 2px, left top;
|
117 |
padding: 6px 32px 6px 6px;
|
118 |
}
|
|
|
119 |
#sputnik-page a.view-as-grid {
|
120 |
background-position: 31px -69px, left top;
|
121 |
padding: 7px 32px 6px 7px;
|
122 |
}
|
|
|
123 |
#sputnik-page .tablenav-pages {
|
124 |
display: none;
|
125 |
}
|
|
|
126 |
#sputnik-page .tablenav {
|
127 |
margin-top: 0;
|
128 |
height: auto;
|
129 |
position: relative;
|
130 |
}
|
|
|
131 |
.grid-view {
|
132 |
margin: 0 0 15px;
|
133 |
clear: both;
|
134 |
-
overflow: auto;
|
135 |
}
|
136 |
|
137 |
/* Buy buttons */
|
@@ -151,146 +142,138 @@
|
|
151 |
}
|
152 |
|
153 |
.sputnik-plugin {
|
154 |
-
width: 200px;
|
155 |
padding: 0;
|
156 |
-
margin:
|
157 |
float: left;
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
}
|
288 |
-
.sputnik-button span {
|
289 |
-
border-right: 1px solid rgba(255, 255, 255, 0.3);
|
290 |
-
padding-right: 6px;
|
291 |
-
margin-right: 5px;
|
292 |
-
display: inline-block;
|
293 |
-
}
|
294 |
|
295 |
/* iframed windows */
|
296 |
.toplevel_page_sputnik #TB_iframeContent {
|
@@ -301,160 +284,166 @@
|
|
301 |
}
|
302 |
|
303 |
#sputnik-plugin-information {
|
304 |
-
background: url('fyi-back.png') repeat-y #fff;
|
305 |
min-height: 100%;
|
306 |
margin: 0;
|
307 |
padding: 0;
|
308 |
}
|
309 |
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
#
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
/* Account page */
|
460 |
#sputnik-page .account-card {
|
@@ -465,27 +454,27 @@
|
|
465 |
padding: 10px;
|
466 |
margin-top: 20px;
|
467 |
}
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
#sputnik-page table.widefat tr td {
|
490 |
vertical-align: middle;
|
491 |
}
|
1 |
+
body.wpsc-product_page_sputnik #TB_iframeContent {
|
2 |
+
margin: -1px 0 -4px 0
|
3 |
+
}
|
4 |
+
|
5 |
+
#sputnik-page .sep {
|
6 |
+
margin: 0 12px 0 0;
|
7 |
+
font-size: 23px;
|
8 |
+
}
|
9 |
+
|
10 |
+
#sputnik-page h3 {
|
11 |
+
color: #999;
|
12 |
+
font-size: 23px;
|
13 |
+
line-height: 29px;
|
14 |
+
font-weight: normal;
|
15 |
+
margin: 0 0 0 40px;
|
16 |
+
padding: 9px 15px 4px 0;
|
17 |
+
}
|
18 |
+
|
19 |
+
#sputnik-page .account-link {
|
20 |
+
margin-right: 8px;
|
21 |
+
}
|
22 |
+
|
23 |
+
#sputnik-page .aux-links {
|
24 |
+
float: right;
|
25 |
+
clear: both;
|
26 |
+
margin: 10px;
|
27 |
+
}
|
28 |
+
|
29 |
+
#sputnik-header p {
|
30 |
+
margin-top: 0;
|
31 |
+
margin-bottom: 0;
|
32 |
+
}
|
33 |
+
|
34 |
+
#sputnik-header a, #sputnik-footer a {
|
35 |
+
text-decoration: none;
|
36 |
+
}
|
37 |
+
|
38 |
+
#sputnik-header a:hover, #sputnik-footer a:hover {
|
39 |
+
color: #f00;
|
40 |
+
}
|
41 |
+
|
42 |
+
#sputnik-footer {
|
43 |
+
margin-top: 10px;
|
44 |
+
text-align: center;
|
45 |
+
border-top: 1px solid #DFDFDF;
|
46 |
+
|
47 |
+
overflow: auto;
|
48 |
+
padding: 10px 20px;
|
49 |
+
|
50 |
+
background: #fcfcfc;
|
51 |
+
background: -moz-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
|
52 |
+
background: -webkit-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
|
53 |
+
background: -ms-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
|
54 |
+
background: -o-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
|
55 |
+
background: radial-gradient(top, #F0F0F0, #FFFFFF 80%);
|
56 |
+
}
|
57 |
+
|
58 |
+
#sputnik-footer .logo-holder {
|
59 |
+
float: left;
|
60 |
+
}
|
61 |
+
|
62 |
+
#sputnik-footer .renku-logo {
|
63 |
+
background: url("logo.png") no-repeat scroll center center transparent;
|
64 |
+
text-indent: -9999px;
|
65 |
+
width: 47px;
|
66 |
+
height: 22px;
|
67 |
+
display: block;
|
68 |
+
}
|
69 |
+
|
70 |
+
#sputnik-footer nav {
|
71 |
+
float: right;
|
72 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
#sputnik-auth, #sputnik-page .connect-error {
|
75 |
font-size: 20px;
|
|
|
76 |
line-height: 1.6em;
|
77 |
color: #777;
|
78 |
max-width: 500px;
|
79 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
+
#sputnik-auth .buttons {
|
82 |
+
text-align: right;
|
83 |
+
}
|
84 |
+
|
85 |
+
#sputnik-auth .button {
|
86 |
+
font-size: 15px !important;
|
87 |
+
}
|
88 |
+
|
89 |
+
#sputnik-page .connect-error {
|
90 |
+
clear: both;
|
91 |
+
}
|
92 |
+
|
93 |
#sputnik-page a.view-as-list,
|
94 |
#sputnik-page a.view-as-grid {
|
95 |
background-image: url('icons.png'), linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
|
99 |
background-image: url('icons.png'), -ms-linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
|
100 |
background-repeat: no-repeat, repeat-x, repeat-x, repeat-x, repeat-x;
|
101 |
}
|
102 |
+
|
103 |
#sputnik-page a.view-as-list {
|
104 |
background-position: right 2px, left top;
|
105 |
padding: 6px 32px 6px 6px;
|
106 |
}
|
107 |
+
|
108 |
#sputnik-page a.view-as-grid {
|
109 |
background-position: 31px -69px, left top;
|
110 |
padding: 7px 32px 6px 7px;
|
111 |
}
|
112 |
+
|
113 |
#sputnik-page .tablenav-pages {
|
114 |
display: none;
|
115 |
}
|
116 |
+
|
117 |
#sputnik-page .tablenav {
|
118 |
margin-top: 0;
|
119 |
height: auto;
|
120 |
position: relative;
|
121 |
}
|
122 |
+
|
123 |
.grid-view {
|
124 |
margin: 0 0 15px;
|
125 |
clear: both;
|
|
|
126 |
}
|
127 |
|
128 |
/* Buy buttons */
|
142 |
}
|
143 |
|
144 |
.sputnik-plugin {
|
|
|
145 |
padding: 0;
|
146 |
+
margin: 15px 25px 5px 0;
|
147 |
float: left;
|
148 |
+
max-width: 100%;
|
149 |
+
height: 375px;
|
150 |
+
width: 283px;
|
151 |
+
}
|
152 |
+
|
153 |
+
.sputnik-card {}
|
154 |
+
|
155 |
+
.sputnik-plugin-details {
|
156 |
+
height: 60px;
|
157 |
+
}
|
158 |
+
|
159 |
+
.sputnik-card h4 {
|
160 |
+
font-size: 1.25em;
|
161 |
+
margin: 1.33em .2em .5em;
|
162 |
+
color: #444;
|
163 |
+
font-weight: normal;
|
164 |
+
}
|
165 |
+
|
166 |
+
.sputnik-card h4 span {
|
167 |
+
font-size: .8em;
|
168 |
+
float: right;
|
169 |
+
font-style: italic;
|
170 |
+
}
|
171 |
+
|
172 |
+
.sputnik-plugin-details .footer {
|
173 |
+
position: absolute;
|
174 |
+
width: 176px;
|
175 |
+
bottom: 0;
|
176 |
+
right: 12px;
|
177 |
+
height: 20px;
|
178 |
+
padding: 8px 0;
|
179 |
+
background: #F9F9F9;
|
180 |
+
line-height: 19px;
|
181 |
+
}
|
182 |
+
|
183 |
+
.sputnik-plugin-details .price {
|
184 |
+
position: absolute;
|
185 |
+
right: 12px;
|
186 |
+
top: 10px;
|
187 |
+
}
|
188 |
+
|
189 |
+
.sputnik-plugin-details .footer .star-holder {
|
190 |
+
position: absolute;
|
191 |
+
right: 0;
|
192 |
+
}
|
193 |
+
|
194 |
+
.sputnik-plugin-actions {
|
195 |
+
margin: 10px 2px;
|
196 |
+
line-height: 22px;
|
197 |
+
}
|
198 |
+
|
199 |
+
.sputnik-plugin-actions .button {
|
200 |
+
display: inline-block;
|
201 |
+
}
|
202 |
+
|
203 |
+
.sputnik-plugin-actions .status {
|
204 |
+
float: right;
|
205 |
+
}
|
206 |
+
|
207 |
+
.sputnik-plugin .sputnik-card {
|
208 |
+
-o-transition: 0.4s;
|
209 |
+
-moz-transition: 0.4s;
|
210 |
+
-webkit-transition: 0.4s;
|
211 |
+
}
|
212 |
+
|
213 |
+
.sputnik-plugin .sputnik-plugin-thumb img {
|
214 |
+
display: table-cell;
|
215 |
+
border: 1px solid #cfcfcf;
|
216 |
+
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.22);
|
217 |
+
}
|
218 |
+
|
219 |
+
.sputnik-plugin.has-thumb .sputnik-plugin-thumb {
|
220 |
+
margin-top: 0;
|
221 |
+
}
|
222 |
+
|
223 |
+
.sputnik-button {
|
224 |
+
background: rgb(215, 215, 215);
|
225 |
+
background: rgba(255, 255, 255, 0.5);
|
226 |
+
background: -moz-linear-gradient(
|
227 |
+
center top, rgba(255, 255, 255, 0.5) 0pt,
|
228 |
+
rgba(235, 235, 235, 0.5) 50%,
|
229 |
+
rgba(215, 215, 215, 0.5) 52%,
|
230 |
+
rgba(240, 240, 240, 0.5) 100%)
|
231 |
+
repeat scroll 0 0 transparent;
|
232 |
+
background: -webkit-gradient(
|
233 |
+
linear, left top, left bottom,
|
234 |
+
color-stop(0, rgba(255, 255, 255, 0.5)),
|
235 |
+
color-stop(0.5, rgba(235, 235, 235, 0.5)),
|
236 |
+
color-stop(0.52, rgba(215, 215, 215, 0.5)),
|
237 |
+
color-stop(1, rgba(240, 240, 240, 0.5)))
|
238 |
+
repeat scroll 0 0 transparent;
|
239 |
+
|
240 |
+
border: 1px solid rgba(165, 175, 185, 0.75);
|
241 |
+
box-shadow: 0 0 2px rgba(255, 255, 255, 0.65) inset;
|
242 |
+
color: #000;
|
243 |
+
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
|
244 |
+
padding: 4px 12px;
|
245 |
+
border-radius: 3px;
|
246 |
+
margin-bottom: 1.3em;
|
247 |
+
cursor: pointer;
|
248 |
+
display: inline-block;
|
249 |
+
text-decoration: none;
|
250 |
+
}
|
251 |
+
|
252 |
+
.sputnik-button:hover {
|
253 |
+
color: #000;
|
254 |
+
}
|
255 |
+
|
256 |
+
.sputnik-button.buy, .sputnik-button.install {
|
257 |
+
background: #55a802 55%;
|
258 |
+
background: -moz-linear-gradient(center top, #93c85e 30%, #55a802 55%) repeat scroll 0 0 transparent;
|
259 |
+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.3, #93c85e), color-stop(0.55, #55a802)) repeat scroll 0 0 transparent;
|
260 |
+
border-color: #3A7404;
|
261 |
+
color: #fff;
|
262 |
+
text-shadow: 0 -1px 0 #3a7404;
|
263 |
+
}
|
264 |
+
|
265 |
+
.sputnik-button.disabled {
|
266 |
+
border: 1px solid rgba(165, 175, 185, 0.5);
|
267 |
+
cursor: default;
|
268 |
+
color: #888;
|
269 |
+
}
|
270 |
+
|
271 |
+
.sputnik-button span {
|
272 |
+
border-right: 1px solid rgba(255, 255, 255, 0.3);
|
273 |
+
padding-right: 6px;
|
274 |
+
margin-right: 5px;
|
275 |
+
display: inline-block;
|
276 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
/* iframed windows */
|
279 |
.toplevel_page_sputnik #TB_iframeContent {
|
284 |
}
|
285 |
|
286 |
#sputnik-plugin-information {
|
|
|
287 |
min-height: 100%;
|
288 |
margin: 0;
|
289 |
padding: 0;
|
290 |
}
|
291 |
|
292 |
+
#sputnik-plugin-information #plugin-information-header {
|
293 |
+
margin: 0;
|
294 |
+
padding: 0 5px;
|
295 |
+
font-weight: bold;
|
296 |
+
position: relative;
|
297 |
+
height: auto;
|
298 |
+
border: 0;
|
299 |
+
background: transparent;
|
300 |
+
}
|
301 |
+
|
302 |
+
#sputnik-plugin-information ul#sidemenu {
|
303 |
+
font-weight: normal;
|
304 |
+
margin: 0;
|
305 |
+
padding: 0;
|
306 |
+
float: none;
|
307 |
+
}
|
308 |
+
|
309 |
+
#sputnik-plugin-information #sidemenu li {
|
310 |
+
display: block;
|
311 |
+
text-align: left;
|
312 |
+
}
|
313 |
+
|
314 |
+
#sputnik-plugin-information #sidemenu a {
|
315 |
+
color: #ddd;
|
316 |
+
background: transparent;
|
317 |
+
border: none;
|
318 |
+
float: none;
|
319 |
+
padding: 0;
|
320 |
+
}
|
321 |
+
|
322 |
+
#sputnik-plugin-information #sidemenu a.current {
|
323 |
+
color: #fff;
|
324 |
+
font-weight: bold;
|
325 |
+
}
|
326 |
+
|
327 |
+
#sputnik-plugin-information .mainheader {
|
328 |
+
}
|
329 |
+
|
330 |
+
/* Install sidemenu */
|
331 |
+
#sputnik-plugin-information p.action-button {
|
332 |
+
width: 100%;
|
333 |
+
padding-bottom: 0;
|
334 |
+
margin-bottom: 10px;
|
335 |
+
margin-top: 10px;
|
336 |
+
-webkit-border-top-left-radius: 3px;
|
337 |
+
-webkit-border-bottom-left-radius: 3px;
|
338 |
+
border-top-left-radius: 3px;
|
339 |
+
border-bottom-left-radius: 3px;
|
340 |
+
}
|
341 |
+
|
342 |
+
#sputnik-plugin-information .action-button a {
|
343 |
+
text-align: center;
|
344 |
+
font-weight: bold;
|
345 |
+
text-decoration: none;
|
346 |
+
display: block;
|
347 |
+
line-height: 2em;
|
348 |
+
}
|
349 |
+
|
350 |
+
#sputnik-plugin-information #section-header h2 {
|
351 |
+
clear: none !important;
|
352 |
+
margin-right: 200px;
|
353 |
+
}
|
354 |
+
|
355 |
+
#sputnik-plugin-information .fyi {
|
356 |
+
position: fixed;
|
357 |
+
margin: 0;
|
358 |
+
padding: 0 10px;
|
359 |
+
width: 225px;
|
360 |
+
height: 100%;
|
361 |
+
background-color: #333;
|
362 |
+
color: #aaa;
|
363 |
+
}
|
364 |
+
|
365 |
+
#sputnik-plugin-information .fyi a {
|
366 |
+
color: #fff;
|
367 |
+
}
|
368 |
+
|
369 |
+
#sputnik-plugin-information .fyi h1 {
|
370 |
+
font-size: 1.6em;
|
371 |
+
margin-bottom: 0;
|
372 |
+
margin-right: 0;
|
373 |
+
padding: 10px 0;
|
374 |
+
}
|
375 |
+
|
376 |
+
#sputnik-plugin-information .fyi h2.mainheader {
|
377 |
+
display: none;
|
378 |
+
}
|
379 |
+
|
380 |
+
#sputnik-plugin-information .fyi ul {
|
381 |
+
padding: 10px 5px 10px 7px;
|
382 |
+
margin: 0;
|
383 |
+
list-style: none;
|
384 |
+
-webkit-border-bottom-left-radius: 3px;
|
385 |
+
border-bottom-left-radius: 3px;
|
386 |
+
}
|
387 |
+
|
388 |
+
#sputnik-plugin-information .fyi li {
|
389 |
+
margin-right: 0;
|
390 |
+
}
|
391 |
+
|
392 |
+
#sputnik-plugin-information .fyi strong {
|
393 |
+
color: #bbb;
|
394 |
+
}
|
395 |
+
|
396 |
+
#sputnik-plugin-information #section-holder {
|
397 |
+
padding: 10px;
|
398 |
+
margin: 0 0 0 255px;
|
399 |
+
}
|
400 |
+
|
401 |
+
#sputnik-plugin-information #section-holder img {
|
402 |
+
max-width: 100%;
|
403 |
+
}
|
404 |
+
|
405 |
+
#sputnik-plugin-information .section ul,
|
406 |
+
#sputnik-plugin-information .section ol {
|
407 |
+
margin-left: 16px;
|
408 |
+
list-style-type: square;
|
409 |
+
list-style-image: none;
|
410 |
+
}
|
411 |
+
|
412 |
+
#sputnik-plugin-information #section-screenshots ol {
|
413 |
+
list-style: none;
|
414 |
+
margin: 0;
|
415 |
+
text-align: center;
|
416 |
+
}
|
417 |
+
|
418 |
+
#sputnik-plugin-information #section-screenshots li {
|
419 |
+
margin-bottom: 18px;
|
420 |
+
}
|
421 |
+
|
422 |
+
#sputnik-plugin-information #section-screenshots li img {
|
423 |
+
vertical-align: text-top;
|
424 |
+
max-width: 100%;
|
425 |
+
width: auto;
|
426 |
+
height: auto;
|
427 |
+
border: 1px solid #ccc;
|
428 |
+
padding: 7px;
|
429 |
+
}
|
430 |
+
|
431 |
+
#sputnik-plugin-information #section-screenshots li p {
|
432 |
+
font-style: italic;
|
433 |
+
padding-left: 20px;
|
434 |
+
padding-bottom: 2em;
|
435 |
+
}
|
436 |
+
|
437 |
+
#sputnik-plugin-information #section-screenshots ol,
|
438 |
+
#sputnik-plugin-information .updated,
|
439 |
+
#sputnik-plugin-information pre {
|
440 |
+
margin-right: 0;
|
441 |
+
}
|
442 |
+
|
443 |
+
#sputnik-plugin-information pre {
|
444 |
+
padding: 7px;
|
445 |
+
overflow: auto;
|
446 |
+
}
|
447 |
|
448 |
/* Account page */
|
449 |
#sputnik-page .account-card {
|
454 |
padding: 10px;
|
455 |
margin-top: 20px;
|
456 |
}
|
457 |
+
#sputnik-page .account-card .block {
|
458 |
+
width: 50%;
|
459 |
+
max-width: 400px;
|
460 |
+
float: left;
|
461 |
+
}
|
462 |
+
#sputnik-page .account-card img {
|
463 |
+
float: left;
|
464 |
+
background: #fff;
|
465 |
+
padding: 5px;
|
466 |
+
border: 1px solid #ddd;
|
467 |
+
}
|
468 |
+
#sputnik-page .account-card h3, #sputnik-page .account-card p {
|
469 |
+
margin-left: 130px;
|
470 |
+
}
|
471 |
+
#sputnik-page .account-card .lead-in {
|
472 |
+
margin-top: 0.5em;
|
473 |
+
margin-bottom: 0;
|
474 |
+
}
|
475 |
+
#sputnik-page .account-card .stat strong {
|
476 |
+
font-size: 16px;
|
477 |
+
}
|
478 |
#sputnik-page table.widefat tr td {
|
479 |
vertical-align: middle;
|
480 |
}
|
wpsc-components/marketplace-core-v1/static/admin.js
CHANGED
@@ -10,8 +10,10 @@ jQuery(document).ready(function($) {
|
|
10 |
dg.startFlow(sputnikL10n.buy_href);
|
11 |
}
|
12 |
$('#menu-posts-wpsc-product div ul li a[href$="page=sputnik-account"]').parent('li').remove();
|
|
|
13 |
$('.grid-view').masonry({
|
14 |
-
selector: '.plugin'
|
|
|
15 |
});
|
16 |
|
17 |
$('#rateme').mousemove(function (event) {
|
@@ -36,8 +38,8 @@ jQuery(document).ready(function($) {
|
|
36 |
|
37 |
var href = $(this).attr('href');
|
38 |
var dim = Sputnik.window_dimensions();
|
39 |
-
href += '&width=' + Math.min(Math.max(dim[0] - 50, 300),
|
40 |
-
+ '&height=' + Math.min(Math.max(dim[1] - 100, 250),
|
41 |
tb_show('', href);
|
42 |
this.blur();
|
43 |
|
10 |
dg.startFlow(sputnikL10n.buy_href);
|
11 |
}
|
12 |
$('#menu-posts-wpsc-product div ul li a[href$="page=sputnik-account"]').parent('li').remove();
|
13 |
+
|
14 |
$('.grid-view').masonry({
|
15 |
+
selector: '.plugin',
|
16 |
+
gutter: 15
|
17 |
});
|
18 |
|
19 |
$('#rateme').mousemove(function (event) {
|
38 |
|
39 |
var href = $(this).attr('href');
|
40 |
var dim = Sputnik.window_dimensions();
|
41 |
+
href += '&width=' + Math.min(Math.max(dim[0] - 50, 300), 800)
|
42 |
+
+ '&height=' + Math.min(Math.max(dim[1] - 100, 250), 600);
|
43 |
tb_show('', href);
|
44 |
this.blur();
|
45 |
|
wpsc-components/marketplace-core-v1/static/jquery.masonry.js
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
/**
|
2 |
-
* jQuery Masonry v2.0.110901
|
3 |
-
* A dynamic layout plugin for jQuery
|
4 |
-
* The flip-side of CSS Floats
|
5 |
-
* http://masonry.desandro.com
|
6 |
-
*
|
7 |
-
* Licensed under the MIT license.
|
8 |
-
* Copyright 2011 David DeSandro
|
9 |
-
*/
|
10 |
-
(function(a,b,c){var d=b.event,e;d.special.smartresize={setup:function(){b(this).bind("resize",d.special.smartresize.handler)},teardown:function(){b(this).unbind("resize",d.special.smartresize.handler)},handler:function(a,b){var c=this,d=arguments;a.type="smartresize",e&&clearTimeout(e),e=setTimeout(function(){jQuery.event.handle.apply(c,d)},b==="execAsap"?0:100)}},b.fn.smartresize=function(a){return a?this.bind("smartresize",a):this.trigger("smartresize",["execAsap"])},b.Mason=function(a,c){this.element=b(c),this._create(a),this._init()};var f=["position","height"];b.Mason.settings={isResizable:!0,isAnimated:!1,animationOptions:{queue:!1,duration:500},gutterWidth:0,isRTL:!1,isFitWidth:!1},b.Mason.prototype={_filterFindBricks:function(a){var b=this.options.itemSelector;return b?a.filter(b).add(a.find(b)):a},_getBricks:function(a){var b=this._filterFindBricks(a).css({position:"absolute"}).addClass("masonry-brick");return b},_create:function(c){this.options=b.extend(!0,{},b.Mason.settings,c),this.styleQueue=[],this.reloadItems();var d=this.element[0].style;this.originalStyle={};for(var e=0,g=f.length;e<g;e++){var h=f[e];this.originalStyle[h]=d[h]||""}this.element.css({position:"relative"}),this.horizontalDirection=this.options.isRTL?"right":"left",this.offset={};var i=b(document.createElement("div"));this.element.prepend(i),this.offset.y=Math.round(i.position().top),this.options.isRTL?(i.css({"float":"right",display:"inline-block"}),this.offset.x=Math.round(this.element.outerWidth()-i.position().left)):this.offset.x=Math.round(i.position().left),i.remove();var j=this;setTimeout(function(){j.element.addClass("masonry")},0),this.options.isResizable&&b(a).bind("smartresize.masonry",function(){j.resize()})},_init:function(a){this._getColumns("masonry"),this._reLayout(a)},option:function(a,c){b.isPlainObject(a)&&(this.options=b.extend(!0,this.options,a))},layout:function(a,c){var d,e,f,g,h,i;for(var j=0,k=a.length;j<k;j++){d=b(a[j]),e=Math.ceil(d.outerWidth(!0)/this.columnWidth),e=Math.min(e,this.cols);if(e===1)this._placeBrick(d,this.colYs);else{f=this.cols+1-e,g=[];for(i=0;i<f;i++)h=this.colYs.slice(i,i+e),g[i]=Math.max.apply(Math,h);this._placeBrick(d,g)}}var l={};l.height=Math.max.apply(Math,this.colYs)-this.offset.y,this.options.isFitWidth&&(l.width=this.cols*this.columnWidth-this.options.gutterWidth),this.styleQueue.push({$el:this.element,style:l});var m=this.isLaidOut?this.options.isAnimated?"animate":"css":"css",n=this.options.animationOptions,o;for(j=0,k=this.styleQueue.length;j<k;j++)o=this.styleQueue[j],o.$el[m](o.style,n);this.styleQueue=[],c&&c.call(a),this.isLaidOut=!0},_getColumns:function(){var a=this.options.isFitWidth?this.element.parent():this.element,b=a.width();this.columnWidth=this.options.columnWidth||this.$bricks.outerWidth(!0)||b,this.columnWidth+=this.options.gutterWidth,this.cols=Math.floor((b+this.options.gutterWidth)/this.columnWidth),this.cols=Math.max(this.cols,1)},_placeBrick:function(a,b){var c=Math.min.apply(Math,b),d=0;for(var e=0,f=b.length;e<f;e++)if(b[e]===c){d=e;break}var g={top:c};g[this.horizontalDirection]=this.columnWidth*d+this.offset.x,this.styleQueue.push({$el:a,style:g});var h=c+a.outerHeight(!0),i=this.cols+1-f;for(e=0;e<i;e++)this.colYs[d+e]=h},resize:function(){var a=this.cols;this._getColumns("masonry"),this.cols!==a&&this._reLayout()},_reLayout:function(a){var b=this.cols;this.colYs=[];while(b--)this.colYs.push(this.offset.y);this.layout(this.$bricks,a)},reloadItems:function(){this.$bricks=this._getBricks(this.element.children())},reload:function(a){this.reloadItems(),this._init(a)},appended:function(a,b,c){if(b){this._filterFindBricks(a).css({top:this.element.height()});var d=this;setTimeout(function(){d._appended(a,c)},1)}else this._appended(a,c)},_appended:function(a,b){var c=this._getBricks(a);this.$bricks=this.$bricks.add(c),this.layout(c,b)},remove:function(a){this.$bricks=this.$bricks.not(a),a.remove()},destroy:function(){this.$bricks.removeClass("masonry-brick").each(function(){this.style.position="",this.style.top="",this.style.left=""});var c=this.element[0].style;for(var d=0,e=f.length;d<e;d++){var g=f[d];c[g]=this.originalStyle[g]}this.element.unbind(".masonry").removeClass("masonry").removeData("masonry"),b(a).unbind(".masonry")}},b.fn.imagesLoaded=function(a){function h(){--e<=0&&this.src!==f&&(setTimeout(g),d.unbind("load error",h))}function g(){a.call(b,d)}var b=this,d=b.find("img").add(b.filter("img")),e=d.length,f="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";e||g(),d.bind("load error",h).each(function(){if(this.complete||this.complete===c){var a=this.src;this.src=f,this.src=a}});return b};var g=function(a){this.console&&console.error(a)};b.fn.masonry=function(a){if(typeof a=="string"){var c=Array.prototype.slice.call(arguments,1);this.each(function(){var d=b.data(this,"masonry");if(!d)g("cannot call methods on masonry prior to initialization; attempted to call method '"+a+"'");else{if(!b.isFunction(d[a])||a.charAt(0)==="_"){g("no such method '"+a+"' for masonry instance");return}d[a].apply(d,c)}})}else this.each(function(){var c=b.data(this,"masonry");c?(c.option(a||{}),c._init()):b.data(this,"masonry",new b.Mason(a,this))});return this}})(window,jQuery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/marketplace-core-v1/static/sputnik.css
CHANGED
@@ -8,23 +8,21 @@ div.sputnik-message {
|
|
8 |
padding: 1px 12px;
|
9 |
position: relative;
|
10 |
}
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
.sputnik-plugin-row-note {
|
29 |
display: block;
|
30 |
float: right;
|
8 |
padding: 1px 12px;
|
9 |
position: relative;
|
10 |
}
|
11 |
+
div.sputnik-message p {
|
12 |
+
padding: 2px;
|
13 |
+
margin: 0.5em 0px;
|
14 |
+
font-size: 14px;
|
15 |
+
line-height: 1.5em;
|
16 |
+
}
|
17 |
+
div.sputnik-message .button {
|
18 |
+
position: absolute;
|
19 |
+
right: 12px;
|
20 |
+
top: 10px;
|
21 |
+
font-size: 20px;
|
22 |
+
padding: 0px 15px 2px;
|
23 |
+
line-height: 41px;
|
24 |
+
height: 43px;
|
25 |
+
}
|
|
|
|
|
26 |
.sputnik-plugin-row-note {
|
27 |
display: block;
|
28 |
float: right;
|
wpsc-components/marketplace-core-v1/static/sputnik.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
jQuery(document).ready(function($) {
|
2 |
$('.sputnik-message').insertAfter( $('div.wrap h2:first') );
|
3 |
-
//$('#menu-posts-wpsc-product').before('<li class="wp-not-current-submenu wp-menu-separator"><div class="separator"></div></li>');
|
4 |
$('#menu-posts-wpsc-product div ul li a[href$="page=sputnik-account"]').parent('li').remove();
|
5 |
});
|
1 |
jQuery(document).ready(function($) {
|
2 |
$('.sputnik-message').insertAfter( $('div.wrap h2:first') );
|
|
|
3 |
$('#menu-posts-wpsc-product div ul li a[href$="page=sputnik-account"]').parent('li').remove();
|
4 |
});
|
wpsc-components/merchant-core-v2/helpers/admin.php
CHANGED
@@ -26,6 +26,36 @@ add_filter(
|
|
26 |
2
|
27 |
);
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
function _wpsc_filter_merchant_v2_gateway_form( $form, $selected_gateway ) {
|
30 |
global $nzshpcrt_gateways;
|
31 |
|
26 |
2
|
27 |
);
|
28 |
|
29 |
+
/**
|
30 |
+
* Filters deprecated gateways out of available gateways list.
|
31 |
+
*
|
32 |
+
* Only occurs if there is a 3.0 API replacement for the gateway and it is not currently active.
|
33 |
+
*
|
34 |
+
* @since 3.9.0
|
35 |
+
*
|
36 |
+
* @param array $gateways Original list of gateways.
|
37 |
+
* @return array Modified list of gateways.
|
38 |
+
*/
|
39 |
+
function wpsc_filter_deprecated_v2_gateways( $gateways ) {
|
40 |
+
|
41 |
+
$deprecated_gateways = array(
|
42 |
+
'wpsc_merchant_paypal_express',
|
43 |
+
'wpsc_merchant_paypal_pro',
|
44 |
+
'wpsc_merchant_testmode'
|
45 |
+
);
|
46 |
+
|
47 |
+
// Loops through available gateways, checks if available gateway is both inactive and deprecated, and removes it.
|
48 |
+
foreach ( $gateways as $index => $gateway ) {
|
49 |
+
if ( in_array( $gateway['id'], $deprecated_gateways ) && ! in_array( $gateway['id'], get_option( 'custom_gateway_options', array() ) ) ) {
|
50 |
+
unset( $gateways[ $index ] );
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
return $gateways;
|
55 |
+
}
|
56 |
+
|
57 |
+
add_filter( 'wpsc_settings_get_gateways', 'wpsc_filter_deprecated_v2_gateways', 25 );
|
58 |
+
|
59 |
function _wpsc_filter_merchant_v2_gateway_form( $form, $selected_gateway ) {
|
60 |
global $nzshpcrt_gateways;
|
61 |
|
wpsc-components/merchant-core-v3/classes/http.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( WPSC_MERCHANT_V3_PATH . '/gateways/php-merchant/common/http.php' );
|
4 |
+
|
5 |
+
class WPSC_Payment_Gateway_HTTP extends PHP_Merchant_HTTP {
|
6 |
+
protected function request( $url, $fields = '', $args = array() ) {
|
7 |
+
$defaults = array(
|
8 |
+
'follow' => true,
|
9 |
+
'method' => 'GET',
|
10 |
+
'ssl_verify' => false,
|
11 |
+
'body' => '',
|
12 |
+
'httpversion' => '1.1',
|
13 |
+
'timeout' => 60,
|
14 |
+
);
|
15 |
+
|
16 |
+
$args = array_merge( $defaults, $args );
|
17 |
+
$args['body'] = $fields;
|
18 |
+
|
19 |
+
$response = wp_remote_request( $url, $args );
|
20 |
+
|
21 |
+
if ( is_wp_error( $response ) )
|
22 |
+
throw new PHP_Merchant_Exception( PHPME_HTTP_REQUEST_FAILED, $response->get_error_message() );
|
23 |
+
|
24 |
+
return $response['body'];
|
25 |
+
}
|
26 |
+
|
27 |
+
public function post( $url, $fields = '', $args = array() ) {
|
28 |
+
$args['method'] = 'POST';
|
29 |
+
return $this->request( esc_url_raw( $url ), $fields, $args );
|
30 |
+
}
|
31 |
+
|
32 |
+
public function get( $url, $fields = '', $args = array() ) {
|
33 |
+
return $this->request( esc_url_raw( $url ), $fields, $args );
|
34 |
+
}
|
35 |
+
}
|
wpsc-components/merchant-core-v3/classes/payment-gateway.php
ADDED
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
final class WPSC_Payment_Gateways {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Contain a key-value array of gateway names and gateway class names
|
7 |
+
*
|
8 |
+
* @access private
|
9 |
+
* @static
|
10 |
+
* @var array
|
11 |
+
* @since 3.9
|
12 |
+
*/
|
13 |
+
private static $gateways = array();
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Contain an array of payment gateway objects
|
17 |
+
*
|
18 |
+
* @access private
|
19 |
+
* @static
|
20 |
+
* @var array
|
21 |
+
* @since 3.9
|
22 |
+
*/
|
23 |
+
private static $instances = array();
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Contains the cached metadata of the registered payment gateways, so that the
|
27 |
+
* plugin doesn't have to load the gateway's files to determine its metadata
|
28 |
+
*
|
29 |
+
* @access private
|
30 |
+
* @static
|
31 |
+
*
|
32 |
+
* @since 3.9
|
33 |
+
*
|
34 |
+
* @var array
|
35 |
+
*/
|
36 |
+
private static $payment_gateway_cache = array();
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Contains the names of active gateways that use this API
|
40 |
+
*
|
41 |
+
* @access private
|
42 |
+
* @static
|
43 |
+
* @since 3.9
|
44 |
+
*
|
45 |
+
* @var array
|
46 |
+
*/
|
47 |
+
private static $active_gateways = array();
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Return a particular payment gateway object
|
51 |
+
*
|
52 |
+
* @access public
|
53 |
+
* @param string $gateway Name of the payment gateway you want to get
|
54 |
+
* @return object
|
55 |
+
* @since 3.9
|
56 |
+
*/
|
57 |
+
public static function &get( $gateway, $meta = false ) {
|
58 |
+
if ( empty( self::$instances[$gateway] ) ) {
|
59 |
+
if ( ! $meta )
|
60 |
+
$meta = self::$gateways[$gateway];
|
61 |
+
require_once( $meta['path'] );
|
62 |
+
$class_name = $meta['class'];
|
63 |
+
$options = array(
|
64 |
+
'http_client' => new WPSC_Payment_Gateway_HTTP(),
|
65 |
+
);
|
66 |
+
if ( ! class_exists( $class_name ) ) {
|
67 |
+
$error = new WP_Error( 'wpsc_invalid_payment_gateway', sprintf( __( 'Invalid payment gateway: Class %s does not exist.', 'wpsc' ), $class_name ) );
|
68 |
+
return $error;
|
69 |
+
}
|
70 |
+
|
71 |
+
self::$instances[$gateway] = new $class_name( $options );
|
72 |
+
}
|
73 |
+
|
74 |
+
return self::$instances[$gateway];
|
75 |
+
}
|
76 |
+
|
77 |
+
public static function init() {
|
78 |
+
add_action( 'wpsc_submit_gateway_options', array( 'WPSC_Payment_Gateway_Setting', 'action_update_payment_gateway_settings' ) );
|
79 |
+
|
80 |
+
if ( ! defined( 'WPSC_PAYMENT_GATEWAY_DEBUG' ) || WPSC_PAYMENT_GATEWAY_DEBUG == false )
|
81 |
+
add_action( 'wp_loaded', array( 'WPSC_Payment_Gateways', 'action_save_payment_gateway_cache' ), 99 );
|
82 |
+
else
|
83 |
+
WPSC_Payment_Gateways::flush_cache();
|
84 |
+
|
85 |
+
WPSC_Payment_Gateways::register_dir( WPSC_MERCHANT_V3_PATH . '/gateways' );
|
86 |
+
|
87 |
+
if ( isset( $_REQUEST['payment_gateway'] ) && isset( $_REQUEST['payment_gateway_callback'] ) && self::is_registered( $_REQUEST['payment_gateway'] ) )
|
88 |
+
add_action( 'init', array( 'WPSC_Payment_Gateways', 'action_process_callbacks' ) );
|
89 |
+
}
|
90 |
+
|
91 |
+
public static function action_process_callbacks() {
|
92 |
+
$gateway = self::get( $_REQUEST['payment_gateway'] );
|
93 |
+
$function_name = "callback_{$_REQUEST['payment_gateway_callback']}";
|
94 |
+
$callback = array( $gateway, $function_name );
|
95 |
+
|
96 |
+
if ( is_callable( $callback ) )
|
97 |
+
$gateway->$function_name();
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Check to see whether a gateway is registered using this new API
|
102 |
+
*
|
103 |
+
* @access public
|
104 |
+
* @since 3.9
|
105 |
+
*
|
106 |
+
* @param string $gateway Gateway name (derived from the filename without .php extension)
|
107 |
+
* @return bool True if it's already registered.
|
108 |
+
*/
|
109 |
+
public static function is_registered( $gateway ) {
|
110 |
+
return ! empty( self::$gateways[$gateway] );
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Automatically scan a directory for payment gateways and load the classes.
|
115 |
+
*
|
116 |
+
* The structure of this directory should follow the same rules of the wp-content/plugins
|
117 |
+
* structure.
|
118 |
+
*
|
119 |
+
* All of the files inside the directory will be assumed as payment gateway modules.
|
120 |
+
* Files with the same name as those sub-folders will be included as payment
|
121 |
+
* gateway modules.
|
122 |
+
*
|
123 |
+
* For example, if we have the following directory structure:
|
124 |
+
* payment-gateways/
|
125 |
+
* |-- test-gateway-1.php
|
126 |
+
* |-- test-gateway-2.php
|
127 |
+
* |-- some-folder/
|
128 |
+
* |-- class.php
|
129 |
+
* |-- functions.php
|
130 |
+
*
|
131 |
+
* The following files will be loaded as payment gateway modules: test-gateway-1.php,
|
132 |
+
* test-gateway-2.php
|
133 |
+
* See WPSC_Payment_Gateways::register_file() for file and class naming convention
|
134 |
+
*
|
135 |
+
* @access public
|
136 |
+
* @since 3.9
|
137 |
+
* @uses WPSC_Payment_Gateways::register_file()
|
138 |
+
*
|
139 |
+
* @param string $dir Path to the directory
|
140 |
+
* @param string $main_file File name of the class to load
|
141 |
+
* @return mixed Return true if successfully loaded all the payment gateway in
|
142 |
+
* the directory.
|
143 |
+
* Otherwise return a WP_Error object.
|
144 |
+
*/
|
145 |
+
public static function register_dir( $dir, $main_file = '' ) {
|
146 |
+
$dir = trailingslashit( $dir );
|
147 |
+
$main_file = basename( $dir ) . '.php';
|
148 |
+
|
149 |
+
// scan files in dir
|
150 |
+
$files = scandir( $dir );
|
151 |
+
|
152 |
+
if ( in_array( $main_file, $files ) )
|
153 |
+
return self::register_file( $dir . $main_file );
|
154 |
+
|
155 |
+
foreach ( $files as $file ) {
|
156 |
+
$path = $dir . $file;
|
157 |
+
|
158 |
+
if ( pathinfo( $path, PATHINFO_EXTENSION ) != 'php' || in_array( $file, array( '.', '..' ) ) || is_dir( $path ) )
|
159 |
+
continue;
|
160 |
+
|
161 |
+
$return = self::register_file( $path );
|
162 |
+
|
163 |
+
if ( is_wp_error( $return ) )
|
164 |
+
return $return;
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Register a file as a payment gateway module.
|
170 |
+
*
|
171 |
+
* The payment gateway inside the file must be defined as a subclass of WPSC_Payment_Gateway.
|
172 |
+
*
|
173 |
+
* The file name should be lowercase, using hyphens or underscores between words
|
174 |
+
* instead of spaces. The class name must have "WPSC_Payment_Gateway_" as the
|
175 |
+
* prefix, followed by the file name, in which words are capitalized and connected
|
176 |
+
* by underscore.
|
177 |
+
*
|
178 |
+
* For example, if the file name is "paypal-pro.php", then the class name inside
|
179 |
+
* the file must be WPSC_Payment_Gateway_Paypal_Pro.
|
180 |
+
*
|
181 |
+
* @access public
|
182 |
+
* @since 3.9
|
183 |
+
* @see WPSC_Payment_Gateways::register_dir()
|
184 |
+
*
|
185 |
+
* @param string $file Absolute path to the file containing the payment gateway
|
186 |
+
* class
|
187 |
+
* @return mixed Return true if the file is successfully included and contains
|
188 |
+
* a valid class. Otherwise, a WP_Error object is returned.
|
189 |
+
*/
|
190 |
+
public static function register_file( $file ) {
|
191 |
+
if ( empty( self::$payment_gateway_cache ) )
|
192 |
+
self::$payment_gateway_cache = get_option( 'wpsc_payment_gateway_cache', array() );
|
193 |
+
$filename = basename( $file, '.php' );
|
194 |
+
|
195 |
+
// payment gateway already exists in cache
|
196 |
+
if ( isset( self::$payment_gateway_cache[$filename] ) ) {
|
197 |
+
self::$gateways[$filename] = self::$payment_gateway_cache[$filename];
|
198 |
+
return true;
|
199 |
+
}
|
200 |
+
|
201 |
+
// if payment gateway is not in cache, load metadata
|
202 |
+
$classname = ucwords( str_replace( '-', ' ', $filename ) );
|
203 |
+
$classname = 'WPSC_Payment_Gateway_' . str_replace( ' ', '_', $classname );
|
204 |
+
|
205 |
+
$meta = array(
|
206 |
+
'class' => $classname,
|
207 |
+
'path' => $file,
|
208 |
+
'internalname' => $filename, // compat with older API
|
209 |
+
);
|
210 |
+
|
211 |
+
$gateway = self::get( $filename, $meta );
|
212 |
+
|
213 |
+
if ( is_wp_error( $gateway ) )
|
214 |
+
return $gateway;
|
215 |
+
|
216 |
+
$meta['name'] = $gateway->get_title();
|
217 |
+
$meta['image'] = $gateway->get_image_url();
|
218 |
+
$meta['mark'] = $gateway->get_mark_html();
|
219 |
+
self::$gateways[$filename] = $meta;
|
220 |
+
|
221 |
+
return true;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Updates the payment gateway cache when it's changed. This function is hooked
|
226 |
+
* into WordPress' wp_loaded action
|
227 |
+
*
|
228 |
+
* @access public
|
229 |
+
* @static
|
230 |
+
* @since 3.9
|
231 |
+
*
|
232 |
+
* @return void
|
233 |
+
*/
|
234 |
+
public static function action_save_payment_gateway_cache() {
|
235 |
+
if ( self::$payment_gateway_cache != self::$gateways )
|
236 |
+
update_option( 'wpsc_payment_gateway_cache', self::$gateways );
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Flush the payment gateways cache.
|
241 |
+
*
|
242 |
+
* @access public
|
243 |
+
* @static
|
244 |
+
* @since 3.9
|
245 |
+
* @return void
|
246 |
+
*/
|
247 |
+
public static function flush_cache() {
|
248 |
+
delete_option( 'wpsc_payment_gateway_cache' );
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* Gets metadata of a certain payment gateway. This is better than calling WPSC_Payment_Gateways->get( $gateway_name )->get_title()
|
253 |
+
* and the likes of it, since it doesn't require the gateway itself to be loaded.
|
254 |
+
*
|
255 |
+
* @access public
|
256 |
+
* @static
|
257 |
+
* @since 3.9
|
258 |
+
*
|
259 |
+
* @param string $gateway
|
260 |
+
* @return mixed Array containing the metadata. If the gateway is not registered,
|
261 |
+
* returns false.
|
262 |
+
*/
|
263 |
+
public static function get_meta( $gateway ) {
|
264 |
+
return isset( self::$gateways[$gateway] ) ? self::$gateways[$gateway] : false;
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
*
|
269 |
+
* Return an array containing registered gateway names.
|
270 |
+
*
|
271 |
+
* @access public
|
272 |
+
* @since 3.9
|
273 |
+
*
|
274 |
+
* @return array
|
275 |
+
*/
|
276 |
+
public static function get_gateways() {
|
277 |
+
return array_keys( self::$gateways );
|
278 |
+
}
|
279 |
+
|
280 |
+
public static function get_active_gateways() {
|
281 |
+
if ( empty( self::$active_gateways ) ) {
|
282 |
+
$selected_gateways = get_option( 'custom_gateway_options', array() );
|
283 |
+
$registered_gateways = self::get_gateways();
|
284 |
+
self::$active_gateways = array_intersect( $selected_gateways, $registered_gateways );
|
285 |
+
}
|
286 |
+
|
287 |
+
return apply_filters( 'wpsc_get_active_gateways', array_values( self::$active_gateways ) );
|
288 |
+
}
|
289 |
+
|
290 |
+
/**
|
291 |
+
* No instantiation for this class
|
292 |
+
*
|
293 |
+
* @access private
|
294 |
+
* @since 3.9
|
295 |
+
*
|
296 |
+
*/
|
297 |
+
private function __construct() {}
|
298 |
+
}
|
299 |
+
|
300 |
+
abstract class WPSC_Payment_Gateway {
|
301 |
+
|
302 |
+
/**
|
303 |
+
* Object that allows manipulation of payment gateway settings in a consistent
|
304 |
+
* manner
|
305 |
+
*
|
306 |
+
* @access public
|
307 |
+
* @var WPSC_Payment_Gateway_Setting
|
308 |
+
*/
|
309 |
+
public $setting;
|
310 |
+
|
311 |
+
public $purchase_log;
|
312 |
+
|
313 |
+
public $checkout_data;
|
314 |
+
|
315 |
+
public $currency_code;
|
316 |
+
|
317 |
+
public $title;
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Return the title of the payment gateway. For this to work, $this->title must
|
321 |
+
* be set already.
|
322 |
+
*
|
323 |
+
* It is recommended that the payment gateway title be properly localized using __()
|
324 |
+
*
|
325 |
+
* @access public
|
326 |
+
* @since 3.9
|
327 |
+
* @see __()
|
328 |
+
*
|
329 |
+
* @return string
|
330 |
+
*/
|
331 |
+
public function get_title() {
|
332 |
+
$title = empty( $this->title ) ? '' : $this->title;
|
333 |
+
return apply_filters( 'wpsc_payment_gateway_title', $title );
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* Display the payment gateway settings form as seen in WP eCommerce Settings area.
|
338 |
+
* This method must be overridden by subclasses.
|
339 |
+
*
|
340 |
+
* @abstract
|
341 |
+
* @access public
|
342 |
+
* @since 3.9
|
343 |
+
*
|
344 |
+
* @return void
|
345 |
+
*/
|
346 |
+
public function setup_form() {
|
347 |
+
$checkout_field_types = array(
|
348 |
+
'billing' => __( 'Billing Fields', 'wpsc' ),
|
349 |
+
'shipping' => __( 'Shipping Fields', 'wpsc' ),
|
350 |
+
);
|
351 |
+
|
352 |
+
$fields = array(
|
353 |
+
'firstname' => __( 'First Name', 'wpsc' ),
|
354 |
+
'lastname' => __( 'Last Name', 'wpsc' ),
|
355 |
+
'address' => __( 'Address', 'wpsc' ),
|
356 |
+
'city' => __( 'City', 'wpsc' ),
|
357 |
+
'state' => __( 'State', 'wpsc' ),
|
358 |
+
'country' => __( 'Country', 'wpsc' ),
|
359 |
+
'postcode' => __( 'Postal Code', 'wpsc' ),
|
360 |
+
);
|
361 |
+
$checkout_form = WPSC_Checkout_Form::get();
|
362 |
+
foreach ( $checkout_field_types as $field_type => $title ): ?>
|
363 |
+
<tr>
|
364 |
+
<td colspan="2">
|
365 |
+
<h4><?php echo esc_html( $title ); ?></h4>
|
366 |
+
</td>
|
367 |
+
</tr>
|
368 |
+
<?php foreach ( $fields as $field_name => $field_title ):
|
369 |
+
$unique_name = $field_type . $field_name;
|
370 |
+
$selected_id = $this->setting->get( "checkout_field_{$unique_name}", $checkout_form->get_field_id_by_unique_name( $unique_name ) );
|
371 |
+
?>
|
372 |
+
<tr>
|
373 |
+
<td>
|
374 |
+
<label for="manual-form-<?php echo esc_attr( $unique_name ); ?>"><?php echo esc_html( $field_title ); ?></label>
|
375 |
+
</td>
|
376 |
+
<td>
|
377 |
+
<select name="<?php echo $this->setting->get_field_name( "checkout_field_{$unique_name}" ); ?>" id="manual-form-<?php echo esc_attr( $unique_name ); ?>">
|
378 |
+
<?php $checkout_form->field_drop_down_options( $selected_id ); ?>
|
379 |
+
</select>
|
380 |
+
</td>
|
381 |
+
</tr>
|
382 |
+
<?php endforeach;
|
383 |
+
endforeach;
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Process and send payment details to payment gateways
|
388 |
+
*
|
389 |
+
* @abstract
|
390 |
+
* @access public
|
391 |
+
* @since 3.9
|
392 |
+
*
|
393 |
+
* @return void
|
394 |
+
*/
|
395 |
+
abstract public function process();
|
396 |
+
|
397 |
+
/**
|
398 |
+
* Returns the URL to the logo of the payment gateway (or any representative image).
|
399 |
+
*
|
400 |
+
* @access public
|
401 |
+
* @since 3.9
|
402 |
+
*
|
403 |
+
* @return mixed False if there's no image defined.
|
404 |
+
*/
|
405 |
+
public function get_image_url() {
|
406 |
+
return false;
|
407 |
+
}
|
408 |
+
|
409 |
+
/**
|
410 |
+
* Returns the HTML of the logo of the payment gateway.
|
411 |
+
*
|
412 |
+
* @access public
|
413 |
+
* @since 3.9
|
414 |
+
*
|
415 |
+
* @return mixed False if there's no html defined.
|
416 |
+
*/
|
417 |
+
public function get_mark_html() {
|
418 |
+
return false;
|
419 |
+
}
|
420 |
+
|
421 |
+
public function set_purchase_log( &$purchase_log ) {
|
422 |
+
$this->purchase_log = &$purchase_log;
|
423 |
+
$this->checkout_data = new WPSC_Checkout_Form_Data( $purchase_log->get( 'id' ) );
|
424 |
+
}
|
425 |
+
|
426 |
+
public function get_currency_code() {
|
427 |
+
if ( ! $this->currency_code ) {
|
428 |
+
$country = new WPSC_Country( get_option( 'currency_type' ) );
|
429 |
+
$currency = $country->get( 'currency_code' );
|
430 |
+
} else {
|
431 |
+
$currency = $this->currency_code;
|
432 |
+
}
|
433 |
+
|
434 |
+
return $currency;
|
435 |
+
}
|
436 |
+
|
437 |
+
public function get_notification_url() {
|
438 |
+
return add_query_arg( 'wpsc_action', 'gateway_notification', (get_option( 'siteurl' ) . "/index.php" ) );
|
439 |
+
}
|
440 |
+
|
441 |
+
public function get_transaction_results_url() {
|
442 |
+
return get_option( 'transact_url' );
|
443 |
+
}
|
444 |
+
|
445 |
+
public function get_shopping_cart_url() {
|
446 |
+
return get_option( 'shopping_cart_url' );
|
447 |
+
}
|
448 |
+
|
449 |
+
public function get_shopping_cart_payment_url() {
|
450 |
+
return _wpsc_maybe_activate_theme_engine_v2() ? wpsc_get_checkout_url( 'payment' ) : get_option( 'shopping_cart_url' );
|
451 |
+
}
|
452 |
+
|
453 |
+
public function get_products_page_url() {
|
454 |
+
return get_option( 'product_list_url' );
|
455 |
+
}
|
456 |
+
|
457 |
+
public function go_to_transaction_results() {
|
458 |
+
//Now to do actions once the payment has been attempted
|
459 |
+
switch ( $this->purchase_log->get( 'processed' ) ) {
|
460 |
+
case 3:
|
461 |
+
// payment worked
|
462 |
+
do_action('wpsc_payment_successful');
|
463 |
+
break;
|
464 |
+
case 1:
|
465 |
+
// payment declined
|
466 |
+
do_action('wpsc_payment_failed');
|
467 |
+
break;
|
468 |
+
case 2:
|
469 |
+
// something happened with the payment
|
470 |
+
do_action('wpsc_payment_incomplete');
|
471 |
+
break;
|
472 |
+
}
|
473 |
+
|
474 |
+
$transaction_url_with_sessionid = add_query_arg( 'sessionid', $this->purchase_log->get( 'sessionid' ), get_option( 'transact_url' ) );
|
475 |
+
wp_redirect( $transaction_url_with_sessionid );
|
476 |
+
|
477 |
+
exit();
|
478 |
+
}
|
479 |
+
|
480 |
+
/**
|
481 |
+
* Payment gateway constructor. Should use WPSC_Payment_Gateways::get( $gateway_name ) instead.
|
482 |
+
*
|
483 |
+
* @access public
|
484 |
+
* @return WPSC_Payment_Gateway
|
485 |
+
*/
|
486 |
+
public function __construct() {
|
487 |
+
$this->setting = new WPSC_Payment_Gateway_Setting( get_class( $this ) );
|
488 |
+
}
|
489 |
+
}
|
490 |
+
|
491 |
+
class WPSC_Payment_Gateway_Setting {
|
492 |
+
/**
|
493 |
+
* Contain settings of the payment gateway
|
494 |
+
*
|
495 |
+
* @access private
|
496 |
+
* @var array
|
497 |
+
*/
|
498 |
+
private $settings;
|
499 |
+
|
500 |
+
/**
|
501 |
+
* Contain unsaved settings of the payment gateway. This is useful when the saving of the settings
|
502 |
+
* are deferred.
|
503 |
+
*
|
504 |
+
* @access private
|
505 |
+
* @var array
|
506 |
+
*/
|
507 |
+
private $unsaved_settings = array();
|
508 |
+
|
509 |
+
/**
|
510 |
+
* Name of the gateway
|
511 |
+
*
|
512 |
+
* @access private
|
513 |
+
* @var string
|
514 |
+
*/
|
515 |
+
private $gateway_name = '';
|
516 |
+
|
517 |
+
/**
|
518 |
+
* Name of the option containing all the settings in WP DB
|
519 |
+
*
|
520 |
+
* @access private
|
521 |
+
* @var string
|
522 |
+
*/
|
523 |
+
private $option_name = '';
|
524 |
+
|
525 |
+
/**
|
526 |
+
* Save settings when the payment gateway setup form is updated
|
527 |
+
*
|
528 |
+
* @access public
|
529 |
+
* @static
|
530 |
+
* @return void
|
531 |
+
*
|
532 |
+
* @since 3.9
|
533 |
+
*/
|
534 |
+
public static function action_update_payment_gateway_settings() {
|
535 |
+
if ( ! empty( $_POST['wpsc_payment_gateway_settings'] ) )
|
536 |
+
foreach ( $_POST['wpsc_payment_gateway_settings'] as $gateway_name => $new_settings ) {
|
537 |
+
$settings = new WPSC_Payment_Gateway_Setting( $gateway_name );
|
538 |
+
$settings->merge( $new_settings );
|
539 |
+
}
|
540 |
+
}
|
541 |
+
|
542 |
+
/**
|
543 |
+
* Constructor
|
544 |
+
*
|
545 |
+
* @access public
|
546 |
+
*
|
547 |
+
* @param string $gateway_name Name of the gateway
|
548 |
+
* @return WPSC_Payment_Gateway
|
549 |
+
*/
|
550 |
+
public function __construct( $gateway_name_or_class ) {
|
551 |
+
$name = str_replace( 'wpsc_payment_gateway_', '', strtolower( $gateway_name_or_class ) );
|
552 |
+
$name = str_replace( array( ' ', '-' ), '_', $name );
|
553 |
+
$this->gateway_name = $name;
|
554 |
+
$this->option_name = 'wpsc_payment_gateway_' . $this->gateway_name;
|
555 |
+
}
|
556 |
+
|
557 |
+
/**
|
558 |
+
* Lazy load the settings from the DB when necessary
|
559 |
+
*
|
560 |
+
* @access private
|
561 |
+
* @return void
|
562 |
+
*/
|
563 |
+
private function lazy_load() {
|
564 |
+
if ( is_null( $this->settings ) )
|
565 |
+
$this->settings = get_option( $this->option_name, array() );
|
566 |
+
}
|
567 |
+
|
568 |
+
/**
|
569 |
+
* Get the value of a setting
|
570 |
+
*
|
571 |
+
* @param string $setting
|
572 |
+
* @return mixed
|
573 |
+
* @since 3.9
|
574 |
+
*/
|
575 |
+
public function get( $setting, $default = false ) {
|
576 |
+
$this->lazy_load();
|
577 |
+
return isset( $this->settings[$setting] ) ? $this->settings[$setting] : $default;
|
578 |
+
}
|
579 |
+
|
580 |
+
/**
|
581 |
+
* Set the value of a setting
|
582 |
+
*
|
583 |
+
* @param string $setting
|
584 |
+
* @param mixed $value
|
585 |
+
* @param bool $defer True if you want to defer saving the settings array to the database
|
586 |
+
* @return void
|
587 |
+
* @since 3.9
|
588 |
+
*/
|
589 |
+
public function set( $setting, $value, $defer = false ) {
|
590 |
+
$this->lazy_load();
|
591 |
+
$this->unsaved_settings[$setting] = $value;
|
592 |
+
if ( ! $defer )
|
593 |
+
$this->save();
|
594 |
+
}
|
595 |
+
|
596 |
+
/**
|
597 |
+
* Overwrite current settings with an array of settings
|
598 |
+
*
|
599 |
+
* @access public
|
600 |
+
* @param string $settings Settings that you want to overwrite upon current settings
|
601 |
+
* @param string $defer Optional. Defaults to false. True if you want to defer
|
602 |
+
* saving the settings array to the database.
|
603 |
+
* @return void
|
604 |
+
* @since 3.9
|
605 |
+
*/
|
606 |
+
public function merge( $settings, $defer = false ) {
|
607 |
+
$this->lazy_load();
|
608 |
+
$this->unsaved_settings = array_merge( $this->unsaved_settings, $settings );
|
609 |
+
if ( ! $defer )
|
610 |
+
$this->save();
|
611 |
+
}
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Returns the field name of the setting on payment gateway setup form
|
615 |
+
*
|
616 |
+
* @access public
|
617 |
+
* @param string $setting Setting names
|
618 |
+
* @return string
|
619 |
+
* @since 3.9
|
620 |
+
*/
|
621 |
+
public function get_field_name( $setting ) {
|
622 |
+
return "wpsc_payment_gateway_settings[{$this->gateway_name}][{$setting}]";
|
623 |
+
}
|
624 |
+
|
625 |
+
/**
|
626 |
+
* Save the settings into the database
|
627 |
+
*
|
628 |
+
* @return void
|
629 |
+
* @since 3.9
|
630 |
+
*/
|
631 |
+
public function save() {
|
632 |
+
$this->settings = array_merge( $this->settings, $this->unsaved_settings );
|
633 |
+
$this->unsaved_settings = array();
|
634 |
+
update_option( $this->option_name, $this->settings );
|
635 |
+
}
|
636 |
+
}
|
637 |
+
|
638 |
+
WPSC_Payment_Gateways::init();
|
wpsc-components/merchant-core-v3/gateways/dg.css
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Digital Goods Lightbox CSS code
|
3 |
+
*/
|
4 |
+
p {
|
5 |
+
display: block;
|
6 |
+
position: relative;
|
7 |
+
top: 33%;
|
8 |
+
text-transform:
|
9 |
+
uppercase;
|
10 |
+
color: #084482;
|
11 |
+
text-align: center;
|
12 |
+
font-style: italic;
|
13 |
+
font-weight: bold;
|
14 |
+
font-size: 12px;
|
15 |
+
font-family: arial, helvetica, sans-serif;
|
16 |
+
}
|
17 |
+
img {
|
18 |
+
display: block;
|
19 |
+
position: absolute;
|
20 |
+
left: 46%;
|
21 |
+
top: 46%;
|
22 |
+
}
|
23 |
+
#left_frame {
|
24 |
+
margin-top: 15px;
|
25 |
+
position: relative;
|
26 |
+
width: 370px;
|
27 |
+
height: 330px;
|
28 |
+
background: top left;
|
29 |
+
}
|
30 |
+
#right_frame {
|
31 |
+
margin: 0 15px 15px 15px;
|
32 |
+
padding: 10px 10px 0 0;
|
33 |
+
width: 350px;
|
34 |
+
height: 325px;
|
35 |
+
background: top right;
|
36 |
+
}
|
37 |
+
#right_bottom {
|
38 |
+
bottom: -12px;
|
39 |
+
left: 0px;
|
40 |
+
margin: 0 0 0 10px;
|
41 |
+
padding: 0px 5px 10px 10px;
|
42 |
+
position: absolute;
|
43 |
+
width: 350px;
|
44 |
+
background: bottom right;
|
45 |
+
}
|
46 |
+
#left_bottom {
|
47 |
+
bottom: -10px;
|
48 |
+
left: 0px;
|
49 |
+
margin: 0 0 0 -20px;
|
50 |
+
padding: 0;
|
51 |
+
position: relative;
|
52 |
+
height: 12px;
|
53 |
+
width: 100px;
|
54 |
+
background: bottom left;
|
55 |
+
}
|
56 |
+
#left_frame, #right_frame, #right_bottom, #left_bottom {
|
57 |
+
background-image: url(https://www.paypal.com/en_US/i/scr/scr_dg_sliding_door_bdr_wf.png);
|
58 |
+
background-color: transparent;
|
59 |
+
background-repeat: no-repeat;
|
60 |
+
}
|
61 |
+
|
62 |
+
@media only screen and (max-device-width : 568px) {
|
63 |
+
#left_frame,
|
64 |
+
#right_frame,
|
65 |
+
#right_bottom {
|
66 |
+
width: 96%;
|
67 |
+
}
|
68 |
+
#left_frame,
|
69 |
+
#right_frame {
|
70 |
+
height: 96%;
|
71 |
+
}
|
72 |
+
}
|
wpsc-components/merchant-core-v3/gateways/dg.js
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* PayPal for Digital Goods script
|
3 |
+
*/
|
4 |
+
(function($) {
|
5 |
+
$(window).load(function() {
|
6 |
+
// Declare variables/doom elements
|
7 |
+
var $checkout_btn = $( '.wpsc-checkout-form-button' ),
|
8 |
+
$rd_btn = $( 'input[value="paypal-digital-goods"]' ),
|
9 |
+
$inputs = $( 'input[type="radio"]' ),
|
10 |
+
$form = $( '#wpsc-checkout-form' );
|
11 |
+
|
12 |
+
// Change the id of the checkout button
|
13 |
+
$checkout_btn.attr( 'id', 'submitBtn' );
|
14 |
+
|
15 |
+
// Gateway selection changed
|
16 |
+
$inputs.on( 'change', function() {
|
17 |
+
if ( $rd_btn.is( ':checked' ) ) {
|
18 |
+
// Starts the DG Flow
|
19 |
+
var dg = new PAYPAL.apps.DGFlow( {
|
20 |
+
trigger: 'submitBtn'
|
21 |
+
} );
|
22 |
+
} else {
|
23 |
+
$form.attr( 'target', '' );
|
24 |
+
}
|
25 |
+
} );
|
26 |
+
} );
|
27 |
+
|
28 |
+
} )( jQuery );
|
wpsc-components/merchant-core-v3/gateways/manual.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPSC_Payment_Gateway_Manual extends WPSC_Payment_Gateway {
|
4 |
+
/**
|
5 |
+
* Constructor of Manual Payment Gateway
|
6 |
+
*
|
7 |
+
* @access public
|
8 |
+
* @since 3.9
|
9 |
+
*/
|
10 |
+
public function __construct() {
|
11 |
+
parent::__construct();
|
12 |
+
$this->title = __( 'Manual Payment Gateway 3.0', 'wpsc' );
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Displays the setup form
|
17 |
+
*
|
18 |
+
* @access public
|
19 |
+
* @since 3.9
|
20 |
+
* @uses WPSC_Checkout_Form::get()
|
21 |
+
* @uses WPSC_Checkout_Form::field_drop_down_options()
|
22 |
+
* @uses WPSC_Checkout_Form::get_field_id_by_unique_name()
|
23 |
+
* @uses WPSC_Payment_Gateway_Setting::get()
|
24 |
+
*
|
25 |
+
* @return void
|
26 |
+
*/
|
27 |
+
public function setup_form() {
|
28 |
+
?>
|
29 |
+
<tr>
|
30 |
+
<td colspan="2">
|
31 |
+
<p>
|
32 |
+
<label for="wpsc-manual-gateway-setup"><?php _e( 'Instructions', 'wpsc' ); ?></label><br />
|
33 |
+
<textarea id="wpsc-manual-gateway-setup" cols='' rows='10' name='<?php echo esc_attr( $this->setting->get_field_name( 'payment_instructions' ) ); ?>'><?php echo esc_textarea( wp_unslash( $this->setting->get( 'payment_instructions' ) ) ); ?></textarea><br />
|
34 |
+
<small><?php _e('Enter the payment instructions that you wish to display to your customers when they make a purchase.', 'wpsc'); ?></small><br />
|
35 |
+
<small><?php _e('For example, this is where you the Shop Owner might enter your bank account details or address so that your customer can make their manual payment.', 'wpsc'); ?></small>
|
36 |
+
</p>
|
37 |
+
</td>
|
38 |
+
</tr>
|
39 |
+
<?php
|
40 |
+
}
|
41 |
+
|
42 |
+
public function process() {
|
43 |
+
$this->purchase_log->set( 'processed', WPSC_PAYMENT_STATUS_RECEIVED )->save();
|
44 |
+
$this->go_to_transaction_results();
|
45 |
+
}
|
46 |
+
}
|
wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php
ADDED
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( 'paypal-express-checkout.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* The PayPal Express Checkout Gateway class
|
6 |
+
*
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WPSC_Payment_Gateway_Paypal_Digital_Goods extends WPSC_Payment_Gateway_Paypal_Express_Checkout
|
10 |
+
{
|
11 |
+
const SANDBOX_URL = 'https://www.sandbox.paypal.com/incontext?token=';
|
12 |
+
const LIVE_URL = 'https://www.paypal.com/incontext?token=';
|
13 |
+
public $gateway;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Constructor of PayPal Express Checkout Gateway
|
17 |
+
*
|
18 |
+
* @param array $options
|
19 |
+
* @return void
|
20 |
+
*
|
21 |
+
* @since 3.9
|
22 |
+
*/
|
23 |
+
public function __construct( $options ) {
|
24 |
+
|
25 |
+
require_once( 'php-merchant/gateways/paypal-digital-goods.php' );
|
26 |
+
$this->gateway = new PHP_Merchant_Paypal_Digital_Goods( $options );
|
27 |
+
|
28 |
+
// Now that the gateway is created, call parent constructor
|
29 |
+
parent::__construct( $options );
|
30 |
+
|
31 |
+
$this->title = __( 'PayPal ExpressCheckout for Digital Goods', 'wpsc' );
|
32 |
+
|
33 |
+
$this->gateway->set_options( array(
|
34 |
+
'api_username' => $this->setting->get( 'api_username' ),
|
35 |
+
'api_password' => $this->setting->get( 'api_password' ),
|
36 |
+
'api_signature' => $this->setting->get( 'api_signature' ),
|
37 |
+
'cancel_url' => $this->get_cancel_url(),
|
38 |
+
'currency' => $this->get_currency_code(),
|
39 |
+
'test' => (bool) $this->setting->get( 'sandbox_mode' ),
|
40 |
+
'address_override' => 1,
|
41 |
+
'solution_type' => 'mark',
|
42 |
+
'cart_logo' => $this->setting->get( 'cart_logo' ),
|
43 |
+
'cart_border' => $this->setting->get( 'cart_border' ),
|
44 |
+
) );
|
45 |
+
|
46 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'dg_script' ) );
|
47 |
+
|
48 |
+
add_filter( 'wpsc_purchase_log_gateway_data', array( get_parent_class( $this ), 'filter_purchase_log_gateway_data' ), 10, 2 );
|
49 |
+
|
50 |
+
add_filter(
|
51 |
+
'wpsc_payment_method_form_fields',
|
52 |
+
array( $this, 'filter_unselect_default' ), 100 , 1
|
53 |
+
);
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* WordPress Enqueue for the Dgital Goods Script and CSS file
|
58 |
+
*
|
59 |
+
* @return void
|
60 |
+
*
|
61 |
+
* @since 3.9
|
62 |
+
*/
|
63 |
+
public function dg_script() {
|
64 |
+
if ( wpsc_is_checkout() ) {
|
65 |
+
wp_enqueue_script( 'dg-script', 'https://www.paypalobjects.com/js/external/dg.js' );
|
66 |
+
wp_enqueue_script( 'dg-script-internal', WPSC_URL . '/wpsc-components/merchant-core-v3/gateways/dg.js', array( 'jquery' ) );
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
/**
|
72 |
+
* No payment gateway is selected by default
|
73 |
+
*
|
74 |
+
* @access public
|
75 |
+
* @since 3.9
|
76 |
+
*
|
77 |
+
* @param array $fields
|
78 |
+
*
|
79 |
+
* @return array
|
80 |
+
*/
|
81 |
+
public function filter_unselect_default( $fields ) {
|
82 |
+
foreach ( $fields as $i=>$field ) {
|
83 |
+
$fields[ $i ][ 'checked' ] = false;
|
84 |
+
}
|
85 |
+
|
86 |
+
return $fields;
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Return the PayPal return URL
|
91 |
+
*
|
92 |
+
* @return string
|
93 |
+
*
|
94 |
+
* @since 3.9
|
95 |
+
*/
|
96 |
+
protected function get_return_url() {
|
97 |
+
$redirect = add_query_arg( array(
|
98 |
+
'sessionid' => $this->purchase_log->get( 'sessionid' ),
|
99 |
+
'payment_gateway' => 'paypal-digital-goods',
|
100 |
+
'payment_gateway_callback' => 'return_url_redirect',
|
101 |
+
),
|
102 |
+
get_option( 'transact_url' )
|
103 |
+
);
|
104 |
+
return apply_filters( 'wpsc_paypal_digital_goods_return_url_redirect', $redirect, $this );
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* PayPal Lightbox Form redirection for the Return URL
|
109 |
+
*
|
110 |
+
* @return void
|
111 |
+
*
|
112 |
+
* @since 3.9
|
113 |
+
*/
|
114 |
+
public function callback_return_url_redirect() {
|
115 |
+
// Session id
|
116 |
+
if ( ! isset( $_GET['sessionid'] ) ) {
|
117 |
+
return;
|
118 |
+
} else {
|
119 |
+
$sessionid = $_GET['sessionid'];
|
120 |
+
}
|
121 |
+
|
122 |
+
// Page Styles
|
123 |
+
wp_register_style( 'ppdg-iframe', plugins_url( 'dg.css', __FILE__ ) );
|
124 |
+
|
125 |
+
// Return a redirection page
|
126 |
+
?>
|
127 |
+
<html>
|
128 |
+
<head>
|
129 |
+
<title><?php _e( 'Processing...', 'wpsc' ); ?></title>
|
130 |
+
<?php wp_print_styles( 'ppdg-iframe' ); ?>
|
131 |
+
</head>
|
132 |
+
<body>
|
133 |
+
<div id="left_frame">
|
134 |
+
<div id="right_frame">
|
135 |
+
<p id="message">
|
136 |
+
<?php _e( 'Processing Order', 'wpsc'); ?>
|
137 |
+
<?php $location = esc_js( $this->get_original_return_url( $sessionid ) ); ?>
|
138 |
+
</p>
|
139 |
+
<img src="https://www.paypal.com/en_US/i/icon/icon_animated_prog_42wx42h.gif" alt="Processing..." />
|
140 |
+
<div id="right_bottom">
|
141 |
+
<div id="left_bottom">
|
142 |
+
</div>
|
143 |
+
</div>
|
144 |
+
</div>
|
145 |
+
</div>
|
146 |
+
<script type="text/javascript">
|
147 |
+
setTimeout('if (window!=top) {top.location.replace("<?php echo $location; ?>");}else{location.replace("<?php echo $location; ?>");}', 1500);
|
148 |
+
</script>
|
149 |
+
</body>
|
150 |
+
</html>
|
151 |
+
<?php
|
152 |
+
exit();
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Return the original (real) Return URL
|
157 |
+
*
|
158 |
+
* @param integer $session_id
|
159 |
+
*
|
160 |
+
* @return string
|
161 |
+
*
|
162 |
+
* @since 3.9
|
163 |
+
*/
|
164 |
+
protected function get_original_return_url( $session_id ) {
|
165 |
+
$location = add_query_arg( array(
|
166 |
+
'sessionid' => $session_id,
|
167 |
+
'token' => $_REQUEST['token'],
|
168 |
+
'PayerID' => $_REQUEST['PayerID'],
|
169 |
+
'payment_gateway' => 'paypal-digital-goods',
|
170 |
+
'payment_gateway_callback' => 'confirm_transaction',
|
171 |
+
),
|
172 |
+
get_option( 'transact_url' )
|
173 |
+
);
|
174 |
+
return apply_filters( 'wpsc_paypal_digital_goods_return_url', $location );
|
175 |
+
}
|
176 |
+
|
177 |
+
/**
|
178 |
+
* Return the Cancel URL
|
179 |
+
*
|
180 |
+
* @return string
|
181 |
+
*
|
182 |
+
* @since 3.9
|
183 |
+
*/
|
184 |
+
protected function get_cancel_url() {
|
185 |
+
$redirect = add_query_arg( array(
|
186 |
+
'payment_gateway' => 'paypal-digital-goods',
|
187 |
+
'payment_gateway_callback' => 'cancel_url_redirect',
|
188 |
+
),
|
189 |
+
get_option( 'transact_url' )
|
190 |
+
);
|
191 |
+
return apply_filters( 'wpsc_paypal_digital_goods_cancel_url_redirect', $redirect );
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* PayPal Lightbox Form redirection for the Cancel URL
|
196 |
+
*
|
197 |
+
* @return void
|
198 |
+
*
|
199 |
+
* @since 3.9
|
200 |
+
*/
|
201 |
+
public function callback_cancel_url_redirect() {
|
202 |
+
// Page Styles
|
203 |
+
wp_register_style( 'ppdg-iframe', plugins_url( 'dg.css', __FILE__ ) );
|
204 |
+
|
205 |
+
// Return a redirection page
|
206 |
+
?>
|
207 |
+
<html>
|
208 |
+
<head>
|
209 |
+
<title><?php _e( 'Processing...', 'wpsc' ); ?></title>
|
210 |
+
<?php wp_print_styles( 'ppdg-iframe' ); ?>
|
211 |
+
</head>
|
212 |
+
<body>
|
213 |
+
<div id="left_frame">
|
214 |
+
<div id="right_frame">
|
215 |
+
<p id="message">
|
216 |
+
<?php _e( 'Cancelling Order', 'ppdg'); ?>
|
217 |
+
<?php $location = html_entity_decode( $this->get_original_cancel_url() ); ?>
|
218 |
+
</p>
|
219 |
+
<img src="https://www.paypal.com/en_US/i/icon/icon_animated_prog_42wx42h.gif" alt="Processing..." />
|
220 |
+
<div id="right_bottom">
|
221 |
+
<div id="left_bottom">
|
222 |
+
</div>
|
223 |
+
</div>
|
224 |
+
</div>
|
225 |
+
</div>
|
226 |
+
<script type="text/javascript">
|
227 |
+
setTimeout('if (window!=top) {top.location.replace("<?php echo $location; ?>");}else{location.replace("<?php echo $location; ?>");}', 1500);
|
228 |
+
</script>
|
229 |
+
</body>
|
230 |
+
</html>
|
231 |
+
<?php
|
232 |
+
exit();
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* Return the original (real) Cancel URL
|
237 |
+
*
|
238 |
+
* @param integer $session_id
|
239 |
+
*
|
240 |
+
* @return string
|
241 |
+
*
|
242 |
+
* @since 3.9
|
243 |
+
*/
|
244 |
+
protected function get_original_cancel_url() {
|
245 |
+
return apply_filters( 'wpsc_paypal_digital_goods_cancel_url', $this->get_shopping_cart_payment_url() );
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Return the notify URL
|
250 |
+
*
|
251 |
+
* @return string
|
252 |
+
*
|
253 |
+
* @since 3.9
|
254 |
+
*/
|
255 |
+
protected function get_notify_url() {
|
256 |
+
$location = add_query_arg( array(
|
257 |
+
'payment_gateway' => 'paypal-digital-goods',
|
258 |
+
'payment_gateway_callback' => 'ipn',
|
259 |
+
), home_url( 'index.php' ) );
|
260 |
+
|
261 |
+
return apply_filters( 'wpsc_paypal_express_checkout_notify_url', $location );
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* IPN Callback function
|
266 |
+
*
|
267 |
+
* @return void
|
268 |
+
*
|
269 |
+
* @since 3.9
|
270 |
+
*/
|
271 |
+
public function callback_ipn() {
|
272 |
+
$ipn = new PHP_Merchant_Paypal_IPN( false, (bool) $this->setting->get( 'sandbox_mode', false ) );
|
273 |
+
|
274 |
+
if ( $ipn->is_verified() ) {
|
275 |
+
$sessionid = $ipn->get( 'message_id' );
|
276 |
+
$this->set_purchase_log_for_callbacks( $sessionid );
|
277 |
+
|
278 |
+
if ( $ipn->is_payment_denied() ) {
|
279 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::PAYMENT_DECLINED );
|
280 |
+
} elseif ( $ipn->is_payment_refunded() ) {
|
281 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUNDED );
|
282 |
+
} elseif ( $ipn->is_payment_completed() ) {
|
283 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
284 |
+
} elseif ( $ipn->is_payment_pending() ) {
|
285 |
+
if ( $ipn->is_payment_refund_pending() )
|
286 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUND_PENDING );
|
287 |
+
else
|
288 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
289 |
+
}
|
290 |
+
|
291 |
+
$this->purchase_log->save();
|
292 |
+
transaction_results( $sessionid, false );
|
293 |
+
}
|
294 |
+
|
295 |
+
exit;
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Confirm Transaction Callback
|
300 |
+
*
|
301 |
+
* @return null
|
302 |
+
*
|
303 |
+
* @since 3.9
|
304 |
+
*/
|
305 |
+
public function callback_confirm_transaction() {
|
306 |
+
|
307 |
+
if ( ! isset( $_GET['sessionid'] ) || ! isset( $_GET['token'] ) || ! isset( $_GET['PayerID'] ) ) {
|
308 |
+
return;
|
309 |
+
}
|
310 |
+
|
311 |
+
$this->set_purchase_log_for_callbacks();
|
312 |
+
|
313 |
+
$this->callback_process_confirmed_payment();
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Process the transaction through the PayPal APIs
|
318 |
+
*
|
319 |
+
* @since 3.9
|
320 |
+
*/
|
321 |
+
public function callback_process_confirmed_payment() {
|
322 |
+
$args = array_map( 'urldecode', $_GET );
|
323 |
+
extract( $args, EXTR_SKIP );
|
324 |
+
|
325 |
+
if ( ! isset( $sessionid ) || ! isset( $token ) || ! isset( $PayerID ) ) {
|
326 |
+
return;
|
327 |
+
}
|
328 |
+
|
329 |
+
$this->set_purchase_log_for_callbacks();
|
330 |
+
|
331 |
+
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
332 |
+
$options = array(
|
333 |
+
'token' => $token,
|
334 |
+
'payer_id' => $PayerID,
|
335 |
+
'message_id' => $this->purchase_log->get( 'sessionid' ),
|
336 |
+
'invoice' => $this->purchase_log->get( 'sessionid' ) . '-' . $this->purchase_log->get( 'id' ),
|
337 |
+
);
|
338 |
+
$options += $this->checkout_data->get_gateway_data();
|
339 |
+
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
340 |
+
|
341 |
+
if ( $this->setting->get( 'ipn', false ) ) {
|
342 |
+
$options['notify_url'] = $this->get_notify_url();
|
343 |
+
}
|
344 |
+
|
345 |
+
// GetExpressCheckoutDetails
|
346 |
+
$details = $this->gateway->get_details_for( $token );
|
347 |
+
$this->log_payer_details( $details );
|
348 |
+
|
349 |
+
$response = $this->gateway->purchase( $options );
|
350 |
+
$this->log_protection_status( $response );
|
351 |
+
$location = remove_query_arg( 'payment_gateway_callback' );
|
352 |
+
|
353 |
+
if ( $response->has_errors() ) {
|
354 |
+
wpsc_update_customer_meta( 'paypal_express_checkout_errors', $response->get_errors() );
|
355 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_paypal_error' ) );
|
356 |
+
} elseif ( $response->is_payment_completed() || $response->is_payment_pending() ) {
|
357 |
+
$location = remove_query_arg( 'payment_gateway' );
|
358 |
+
|
359 |
+
if ( $response->is_payment_completed() ) {
|
360 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
361 |
+
} else {
|
362 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
363 |
+
}
|
364 |
+
|
365 |
+
$this->purchase_log->set( 'transactid', $response->get( 'transaction_id' ) )
|
366 |
+
->set( 'date', time() )
|
367 |
+
->save();
|
368 |
+
} else {
|
369 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_generic_error' ) );
|
370 |
+
}
|
371 |
+
|
372 |
+
wp_redirect( $location );
|
373 |
+
exit;
|
374 |
+
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* PayPal Lightbox Form redirection for the Error Page
|
379 |
+
*
|
380 |
+
* @return void
|
381 |
+
*
|
382 |
+
* @since 3.9
|
383 |
+
*/
|
384 |
+
public function callback_display_paypal_error_redirect() {
|
385 |
+
// Redirect Location
|
386 |
+
$location = add_query_arg( array(
|
387 |
+
'payment_gateway' => 'paypal-digital-goods',
|
388 |
+
'payment_gateway_callback' => 'display_paypal_error',
|
389 |
+
), base64_decode( $_GET['return_url'] ) );
|
390 |
+
|
391 |
+
// Page Styles
|
392 |
+
wp_register_style( 'ppdg-iframe', plugins_url( 'dg.css', __FILE__ ) );
|
393 |
+
|
394 |
+
// Return a redirection page
|
395 |
+
?>
|
396 |
+
<html>
|
397 |
+
<head>
|
398 |
+
<title><?php __( 'Processing...', 'wpsc' ); ?></title>
|
399 |
+
<?php wp_print_styles( 'ppdg-iframe' ); ?>
|
400 |
+
</head>
|
401 |
+
<body>
|
402 |
+
<div id="left_frame">
|
403 |
+
<div id="right_frame">
|
404 |
+
<p id="message">
|
405 |
+
<?php _e( 'Processing Order', 'wpsc'); ?>
|
406 |
+
</p>
|
407 |
+
<img src="https://www.paypal.com/en_US/i/icon/icon_animated_prog_42wx42h.gif" alt="Processing..." />
|
408 |
+
<div id="right_bottom">
|
409 |
+
<div id="left_bottom">
|
410 |
+
</div>
|
411 |
+
</div>
|
412 |
+
</div>
|
413 |
+
</div>
|
414 |
+
<script type="text/javascript">
|
415 |
+
setTimeout('if (window!=top) {top.location.replace("<?php echo $location; ?>");}else{location.replace("<?php echo $location; ?>");}', 1500);
|
416 |
+
</script>
|
417 |
+
</body>
|
418 |
+
</html>
|
419 |
+
<?php
|
420 |
+
exit();
|
421 |
+
|
422 |
+
|
423 |
+
}
|
424 |
+
|
425 |
+
public function callback_display_paypal_error() {
|
426 |
+
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_paypal_error_page' ) );
|
427 |
+
}
|
428 |
+
|
429 |
+
public function callback_display_generic_error() {
|
430 |
+
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_generic_error_page' ) );
|
431 |
+
}
|
432 |
+
|
433 |
+
/**
|
434 |
+
* Error Page Template
|
435 |
+
*
|
436 |
+
* @since 3.9
|
437 |
+
*/
|
438 |
+
public function filter_paypal_error_page() {
|
439 |
+
$errors = wpsc_get_customer_meta( 'paypal_express_checkout_errors' );
|
440 |
+
ob_start();
|
441 |
+
?>
|
442 |
+
<p>
|
443 |
+
<?php _e( 'Sorry, your transaction could not be processed by PayPal. Please contact the site administrator. The following errors are returned:', 'wpsc' ); ?>
|
444 |
+
</p>
|
445 |
+
<ul>
|
446 |
+
<?php foreach ( $errors as $error ): ?>
|
447 |
+
<li><?php echo esc_html( $error['details'] ) ?> (<?php echo esc_html( $error['code'] ); ?>)</li>
|
448 |
+
<?php endforeach; ?>
|
449 |
+
</ul>
|
450 |
+
<p><a href="<?php echo esc_url( $this->get_shopping_cart_payment_url() ); ?>"><?php _e( 'Click here to go back to the checkout page.', 'wpsc' ) ?></a></p>
|
451 |
+
<?php
|
452 |
+
$output = apply_filters( 'wpsc_paypal_express_checkout_gateway_error_message', ob_get_clean(), $errors );
|
453 |
+
return $output;
|
454 |
+
}
|
455 |
+
|
456 |
+
/**
|
457 |
+
* Generic Error Page Template
|
458 |
+
*
|
459 |
+
* @since 3.9
|
460 |
+
*/
|
461 |
+
public function filter_generic_error_page() {
|
462 |
+
ob_start();
|
463 |
+
?>
|
464 |
+
<p><?php _e( 'Sorry, but your transaction could not be processed by PayPal for some reason. Please contact the site administrator.', 'wpsc' ); ?></p>
|
465 |
+
<p><a href="<?php echo esc_attr( $this->get_shopping_cart_payment_url() ); ?>"><?php _e( 'Click here to go back to the checkout page.', 'wpsc' ) ?></a></p>
|
466 |
+
<?php
|
467 |
+
$output = apply_filters( 'wpsc_paypal_express_checkout_generic_error_message', ob_get_clean() );
|
468 |
+
return $output;
|
469 |
+
}
|
470 |
+
|
471 |
+
/**
|
472 |
+
* Settings Form Template
|
473 |
+
*
|
474 |
+
* @since 3.9
|
475 |
+
*/
|
476 |
+
public function setup_form() {
|
477 |
+
$paypal_currency = $this->get_currency_code();
|
478 |
+
?>
|
479 |
+
<!-- Account Credentials -->
|
480 |
+
<tr>
|
481 |
+
<td colspan="2">
|
482 |
+
<h4><?php _e( 'Account Credentials', 'wpsc' ); ?></h4>
|
483 |
+
</td>
|
484 |
+
</tr>
|
485 |
+
<tr>
|
486 |
+
<td>
|
487 |
+
<label for="wpsc-paypal-express-api-username"><?php _e( 'API Username', 'wpsc' ); ?></label>
|
488 |
+
</td>
|
489 |
+
<td>
|
490 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_username' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_username' ) ); ?>" id="wpsc-paypal-express-api-username" />
|
491 |
+
</td>
|
492 |
+
</tr>
|
493 |
+
<tr>
|
494 |
+
<td>
|
495 |
+
<label for="wpsc-paypal-express-api-password"><?php _e( 'API Password', 'wpsc' ); ?></label>
|
496 |
+
</td>
|
497 |
+
<td>
|
498 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_password' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_password' ) ); ?>" id="wpsc-paypal-express-api-password" />
|
499 |
+
</td>
|
500 |
+
</tr>
|
501 |
+
<tr>
|
502 |
+
<td>
|
503 |
+
<label for="wpsc-paypal-express-api-signature"><?php _e( 'API Signature', 'wpsc' ); ?></label>
|
504 |
+
</td>
|
505 |
+
<td>
|
506 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_signature' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_signature' ) ); ?>" id="wpsc-paypal-express-api-signature" />
|
507 |
+
</td>
|
508 |
+
</tr>
|
509 |
+
<tr>
|
510 |
+
<td>
|
511 |
+
<label><?php _e( 'Sandbox Mode', 'wpsc' ); ?></label>
|
512 |
+
</td>
|
513 |
+
<td>
|
514 |
+
<label><input <?php checked( $this->setting->get( 'sandbox_mode' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox_mode' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
515 |
+
<label><input <?php checked( (bool) $this->setting->get( 'sandbox_mode' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox_mode' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
516 |
+
</td>
|
517 |
+
</tr>
|
518 |
+
<tr>
|
519 |
+
<td>
|
520 |
+
<label><?php _e( 'IPN', 'wpsc' ); ?></label>
|
521 |
+
</td>
|
522 |
+
<td>
|
523 |
+
<label><input <?php checked( $this->setting->get( 'ipn' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'ipn' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
524 |
+
<label><input <?php checked( (bool) $this->setting->get( 'ipn' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'ipn' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
525 |
+
</td>
|
526 |
+
</tr>
|
527 |
+
|
528 |
+
<!-- Cart Customization -->
|
529 |
+
<tr>
|
530 |
+
<td colspan="2">
|
531 |
+
<label><h4><?php _e( 'Cart Customization', 'wpsc'); ?></h4></label>
|
532 |
+
</td>
|
533 |
+
</tr>
|
534 |
+
<tr>
|
535 |
+
<td>
|
536 |
+
<label for="wpsc-paypal-express-cart-logo"><?php _e( 'Merchant Logo', 'wpsc' ); ?></label>
|
537 |
+
</td>
|
538 |
+
<td>
|
539 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'cart_logo' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'cart_logo' ) ); ?>" id="wpsc-paypal-express-cart-logo" />
|
540 |
+
</td>
|
541 |
+
</tr>
|
542 |
+
<tr>
|
543 |
+
<td>
|
544 |
+
<label for="wpsc-paypal-express-cart-border"><?php _e( 'Cart Border Color', 'wpsc' ); ?></label>
|
545 |
+
</td>
|
546 |
+
<td>
|
547 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'cart_border' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'cart_border' ) ); ?>" id="wpsc-paypal-express-cart-border" />
|
548 |
+
</td>
|
549 |
+
</tr>
|
550 |
+
|
551 |
+
<!-- Currency Conversion -->
|
552 |
+
<?php if ( ! $this->is_currency_supported() ): ?>
|
553 |
+
<tr>
|
554 |
+
<td colspan="2">
|
555 |
+
<h4><?php _e( 'Currency Conversion', 'wpsc' ); ?></h4>
|
556 |
+
</td>
|
557 |
+
</tr>
|
558 |
+
<tr>
|
559 |
+
<td colspan="2">
|
560 |
+
<p><?php _e( 'Your base currency is currently not accepted by PayPal. As a result, before a payment request is sent to Paypal, WP eCommerce has to convert the amounts into one of Paypal supported currencies. Please select your preferred currency below.', 'wpsc' ); ?></p>
|
561 |
+
</td>
|
562 |
+
</tr>
|
563 |
+
<tr>
|
564 |
+
<td>
|
565 |
+
<label for "wpsc-paypal-express-currency"><?php _e( 'Paypal Currency', 'wpsc' ); ?></label>
|
566 |
+
</td>
|
567 |
+
<td>
|
568 |
+
<select name="<?php echo esc_attr( $this->setting->get_field_name( 'currency' ) ); ?>" id="wpsc-paypal-express-currency">
|
569 |
+
<?php foreach ($this->gateway->get_supported_currencies() as $currency): ?>
|
570 |
+
<option <?php selected( $currency, $paypal_currency ); ?> value="<?php echo esc_attr( $currency ); ?>"><?php echo esc_html( $currency ); ?></option>
|
571 |
+
<?php endforeach ?>
|
572 |
+
</select>
|
573 |
+
</td>
|
574 |
+
</tr>
|
575 |
+
<?php endif ?>
|
576 |
+
|
577 |
+
<!-- Error Logging -->
|
578 |
+
<tr>
|
579 |
+
<td colspan="2">
|
580 |
+
<h4><?php _e( 'Error Logging', 'wpsc' ); ?></h4>
|
581 |
+
</td>
|
582 |
+
</tr>
|
583 |
+
<tr>
|
584 |
+
<td>
|
585 |
+
<label><?php _e( 'Enable Debugging', 'wpsc' ); ?></label>
|
586 |
+
</td>
|
587 |
+
<td>
|
588 |
+
<label><input <?php checked( $this->setting->get( 'debugging' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
589 |
+
<label><input <?php checked( (bool) $this->setting->get( 'debugging' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
590 |
+
</td>
|
591 |
+
</tr>
|
592 |
+
<?php
|
593 |
+
}
|
594 |
+
|
595 |
+
/**
|
596 |
+
* Process the SetExpressCheckout API Call
|
597 |
+
*
|
598 |
+
* @param array $args
|
599 |
+
* @return void
|
600 |
+
*
|
601 |
+
* @since 3.9
|
602 |
+
*/
|
603 |
+
public function process( $args = array() ) {
|
604 |
+
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
605 |
+
$options = array(
|
606 |
+
'return_url' => $this->get_return_url(),
|
607 |
+
'message_id' => $this->purchase_log->get( 'sessionid' ),
|
608 |
+
'invoice' => $this->purchase_log->get( 'sessionid' ) . '-' . $this->purchase_log->get( 'id' ),
|
609 |
+
'address_override' => 1,
|
610 |
+
);
|
611 |
+
$options += $this->checkout_data->get_gateway_data();
|
612 |
+
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
613 |
+
|
614 |
+
if ( $this->setting->get( 'ipn', false ) ) {
|
615 |
+
$options['notify_url'] = $this->get_notify_url();
|
616 |
+
}
|
617 |
+
|
618 |
+
$response = $this->gateway->setup_purchase( $options );
|
619 |
+
|
620 |
+
if ( $response->is_successful() ) {
|
621 |
+
$url = ( $this->setting->get( 'sandbox_mode' ) ? self::SANDBOX_URL : self::LIVE_URL ) . $response->get( 'token' );
|
622 |
+
} else {
|
623 |
+
$this->log_error( $response );
|
624 |
+
$url = add_query_arg( array(
|
625 |
+
'payment_gateway' => 'paypal-digital-goods',
|
626 |
+
'payment_gateway_callback' => 'display_paypal_error_redirect',
|
627 |
+
'return_url' => base64_encode( $this->get_return_url() ),
|
628 |
+
), $this->get_return_url() );
|
629 |
+
}
|
630 |
+
|
631 |
+
if( ! isset( $args['return_only'] ) || $args['return_only'] !== true ) {
|
632 |
+
wp_redirect( $url );
|
633 |
+
exit;
|
634 |
+
}
|
635 |
+
|
636 |
+
return $url;
|
637 |
+
}
|
638 |
+
}
|
wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php
ADDED
@@ -0,0 +1,713 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PayPal Express Checkout Gateway class
|
4 |
+
*
|
5 |
+
*/
|
6 |
+
|
7 |
+
class WPSC_Payment_Gateway_Paypal_Express_Checkout extends WPSC_Payment_Gateway {
|
8 |
+
public $sandbox_url = 'https://www.sandbox.paypal.com/webscr';
|
9 |
+
public $live_url = 'https://www.paypal.com/cgi-bin/webscr';
|
10 |
+
private $gateway;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Constructor of PayPal Express Checkout Gateway
|
14 |
+
*
|
15 |
+
* @param array $options
|
16 |
+
* @return void
|
17 |
+
*
|
18 |
+
* @since 3.9
|
19 |
+
*/
|
20 |
+
public function __construct( $options ) {
|
21 |
+
parent::__construct();
|
22 |
+
$this->title = __( 'PayPal Express Checkout 3.0', 'wpsc' );
|
23 |
+
|
24 |
+
require_once( 'php-merchant/gateways/paypal-express-checkout.php' );
|
25 |
+
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $options );
|
26 |
+
$this->gateway->set_options( array(
|
27 |
+
'api_username' => $this->setting->get( 'api_username' ),
|
28 |
+
'api_password' => $this->setting->get( 'api_password' ),
|
29 |
+
'api_signature' => $this->setting->get( 'api_signature' ),
|
30 |
+
'cancel_url' => $this->get_shopping_cart_payment_url(),
|
31 |
+
'currency' => $this->get_currency_code(),
|
32 |
+
'test' => (bool) $this->setting->get( 'sandbox_mode' ),
|
33 |
+
'address_override' => 1,
|
34 |
+
'solution_type' => 'mark',
|
35 |
+
'cart_logo' => $this->setting->get( 'cart_logo' ),
|
36 |
+
'cart_border' => $this->setting->get( 'cart_border' ),
|
37 |
+
) );
|
38 |
+
|
39 |
+
add_filter( 'wpsc_purchase_log_gateway_data', array( $this, 'filter_purchase_log_gateway_data' ), 10, 2 );
|
40 |
+
add_filter(
|
41 |
+
'wpsc_payment_method_form_fields',
|
42 |
+
array( $this, 'filter_unselect_default' ), 100 , 1
|
43 |
+
);
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Returns the HTML of the logo of the payment gateway.
|
48 |
+
*
|
49 |
+
* @access public
|
50 |
+
* @return string
|
51 |
+
*
|
52 |
+
* @since 3.9
|
53 |
+
*/
|
54 |
+
public function get_mark_html() {
|
55 |
+
$html = '<a href="https://www.paypal.com/webapps/mpp/paypal-popup" title="' . esc_attr__( 'How PayPal Works' ) . '" onclick="javascript:window.open(\'https://www.paypal.com/webapps/mpp/paypal-popup\',\'WIPaypal\',\'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1060, height=700\'); return false;"><img src="https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_37x23.jpg" border="0" alt="PayPal Logo"></a>';
|
56 |
+
|
57 |
+
return apply_filters( 'wpsc_paypal-ec_mark_html', $html );
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* No payment gateway is selected by default
|
62 |
+
*
|
63 |
+
* @access public
|
64 |
+
* @param array $fields
|
65 |
+
* @return array
|
66 |
+
*
|
67 |
+
* @since 3.9
|
68 |
+
*/
|
69 |
+
public function filter_unselect_default( $fields ) {
|
70 |
+
foreach ( $fields as $i=>$field ) {
|
71 |
+
$fields[ $i ][ 'checked' ] = false;
|
72 |
+
}
|
73 |
+
|
74 |
+
return $fields;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Returns the PayPal redirect URL
|
79 |
+
*
|
80 |
+
* @param array $data Arguments to encode with the URL
|
81 |
+
* @return string
|
82 |
+
*
|
83 |
+
* @since 3.9
|
84 |
+
*/
|
85 |
+
public function get_redirect_url( $data = array() ) {
|
86 |
+
|
87 |
+
// Select either the Sandbox or the Live URL
|
88 |
+
if ( $this->setting->get( 'sandbox_mode' ) ) {
|
89 |
+
$url = $this->sandbox_url;
|
90 |
+
} else {
|
91 |
+
$url = $this->live_url;
|
92 |
+
}
|
93 |
+
|
94 |
+
// Common Vars
|
95 |
+
$common = array(
|
96 |
+
'cmd' => '_express-checkout',
|
97 |
+
'useraction' => 'commit',
|
98 |
+
);
|
99 |
+
|
100 |
+
if ( wp_is_mobile() ) {
|
101 |
+
$common['cmd'] = '_express-checkout-mobile';
|
102 |
+
}
|
103 |
+
|
104 |
+
// Merge the two arrays
|
105 |
+
$data = array_merge( $data, $common );
|
106 |
+
|
107 |
+
// Build the URL
|
108 |
+
$url = add_query_arg( $data, $url );
|
109 |
+
|
110 |
+
return $url;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Purchase Log Filter for Gateway Data
|
115 |
+
*
|
116 |
+
* @param array $gateway_data
|
117 |
+
* @param array $data
|
118 |
+
* @return array
|
119 |
+
*
|
120 |
+
* @since 3.9
|
121 |
+
*/
|
122 |
+
public static function filter_purchase_log_gateway_data( $gateway_data, $data ) {
|
123 |
+
// Because paypal express checkout API doesn't have full support for discount, we have to manually add an item here
|
124 |
+
if ( isset( $gateway_data['discount'] ) && (float) $gateway_data['discount'] != 0 ) {
|
125 |
+
$i =& $gateway_data['items'];
|
126 |
+
$d =& $gateway_data['discount'];
|
127 |
+
$s =& $gateway_data['subtotal'];
|
128 |
+
|
129 |
+
// If discount amount is larger than or equal to the item total, we need to set item total to 0.01
|
130 |
+
// because Paypal does not accept 0 item total.
|
131 |
+
if ( $d >= $gateway_data['subtotal'] ) {
|
132 |
+
$d = $s - 0.01;
|
133 |
+
|
134 |
+
// if there's shipping, we'll take 0.01 from there
|
135 |
+
if ( ! empty( $gateway_data['shipping'] ) ) {
|
136 |
+
$gateway_data['shipping'] -= 0.01;
|
137 |
+
} else {
|
138 |
+
$gateway_data['amount'] = 0.01;
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
$s -= $d;
|
143 |
+
|
144 |
+
$i[] = array(
|
145 |
+
'name' => __( 'Discount', 'wpsc' ),
|
146 |
+
'amount' => - $d,
|
147 |
+
'quantity' => 1,
|
148 |
+
);
|
149 |
+
}
|
150 |
+
return $gateway_data;
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Returns the URL of the Return Page after the PayPal Checkout
|
155 |
+
*
|
156 |
+
* @return string
|
157 |
+
*/
|
158 |
+
protected function get_return_url() {
|
159 |
+
$location = add_query_arg( array(
|
160 |
+
'sessionid' => $this->purchase_log->get( 'sessionid' ),
|
161 |
+
'payment_gateway' => 'paypal-express-checkout',
|
162 |
+
'payment_gateway_callback' => 'confirm_transaction',
|
163 |
+
),
|
164 |
+
get_option( 'transact_url' )
|
165 |
+
);
|
166 |
+
return apply_filters( 'wpsc_paypal_express_checkout_return_url', $location, $this );
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Returns the URL of the IPN Page
|
171 |
+
*
|
172 |
+
* @return string
|
173 |
+
*/
|
174 |
+
protected function get_notify_url() {
|
175 |
+
$location = add_query_arg( array(
|
176 |
+
'payment_gateway' => 'paypal-express-checkout',
|
177 |
+
'payment_gateway_callback' => 'ipn',
|
178 |
+
), home_url( 'index.php' ) );
|
179 |
+
|
180 |
+
return apply_filters( 'wpsc_paypal_express_checkout_notify_url', $location );
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Creates a new Purchase Log entry and set it to the current object
|
185 |
+
*
|
186 |
+
* @return null
|
187 |
+
*/
|
188 |
+
protected function set_purchase_log_for_callbacks( $sessionid = false ) {
|
189 |
+
// Define the sessionid if it's not passed
|
190 |
+
if ( $sessionid === false ) {
|
191 |
+
$sessionid = $_REQUEST['sessionid'];
|
192 |
+
}
|
193 |
+
|
194 |
+
// Create a new Purchase Log entry
|
195 |
+
$purchase_log = new WPSC_Purchase_Log( $sessionid, 'sessionid' );
|
196 |
+
|
197 |
+
if ( ! $purchase_log->exists() ) {
|
198 |
+
return null;
|
199 |
+
}
|
200 |
+
|
201 |
+
// Set the Purchase Log for the gateway object
|
202 |
+
$this->set_purchase_log( $purchase_log );
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* IPN Callback function
|
207 |
+
*
|
208 |
+
* @return void
|
209 |
+
*/
|
210 |
+
public function callback_ipn() {
|
211 |
+
$ipn = new PHP_Merchant_Paypal_IPN( false, (bool) $this->setting->get( 'sandbox_mode', false ) );
|
212 |
+
|
213 |
+
if ( $ipn->is_verified() ) {
|
214 |
+
$sessionid = $ipn->get( 'invoice' );
|
215 |
+
$this->set_purchase_log_for_callbacks( $sessionid );
|
216 |
+
|
217 |
+
if ( $ipn->is_payment_denied() ) {
|
218 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::PAYMENT_DECLINED );
|
219 |
+
} elseif ( $ipn->is_payment_refunded() ) {
|
220 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUNDED );
|
221 |
+
} elseif ( $ipn->is_payment_completed() ) {
|
222 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
223 |
+
} elseif ( $ipn->is_payment_pending() ) {
|
224 |
+
if ( $ipn->is_payment_refund_pending() ) {
|
225 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUND_PENDING );
|
226 |
+
} else {
|
227 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
$this->purchase_log->save();
|
232 |
+
transaction_results( $sessionid, false );
|
233 |
+
}
|
234 |
+
|
235 |
+
exit;
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Confirm Transaction Callback
|
240 |
+
*
|
241 |
+
* @return bool
|
242 |
+
*
|
243 |
+
* @since 3.9
|
244 |
+
*/
|
245 |
+
public function callback_confirm_transaction() {
|
246 |
+
if ( ! isset( $_REQUEST['sessionid'] ) || ! isset( $_REQUEST['token'] ) || ! isset( $_REQUEST['PayerID'] ) ) {
|
247 |
+
return false;
|
248 |
+
}
|
249 |
+
|
250 |
+
// Set the Purchase Log
|
251 |
+
$this->set_purchase_log_for_callbacks();
|
252 |
+
|
253 |
+
// Display the Confirmation Page
|
254 |
+
$this->do_transaction();
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Process the transaction through the PayPal APIs
|
259 |
+
*
|
260 |
+
* @since 3.9
|
261 |
+
*/
|
262 |
+
public function do_transaction() {
|
263 |
+
$args = array_map( 'urldecode', $_GET );
|
264 |
+
extract( $args, EXTR_SKIP );
|
265 |
+
|
266 |
+
if ( ! isset( $sessionid ) || ! isset( $token ) || ! isset( $PayerID ) ) {
|
267 |
+
return;
|
268 |
+
}
|
269 |
+
|
270 |
+
$this->set_purchase_log_for_callbacks();
|
271 |
+
|
272 |
+
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
273 |
+
$options = array(
|
274 |
+
'token' => $token,
|
275 |
+
'payer_id' => $PayerID,
|
276 |
+
'message_id' => $this->purchase_log->get( 'sessionid' ),
|
277 |
+
'invoice' => $this->purchase_log->get( 'id' ),
|
278 |
+
);
|
279 |
+
$options += $this->checkout_data->get_gateway_data();
|
280 |
+
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
281 |
+
|
282 |
+
if ( $this->setting->get( 'ipn', false ) ) {
|
283 |
+
$options['notify_url'] = $this->get_notify_url();
|
284 |
+
}
|
285 |
+
|
286 |
+
// GetExpressCheckoutDetails
|
287 |
+
$details = $this->gateway->get_details_for( $token );
|
288 |
+
$this->log_payer_details( $details );
|
289 |
+
|
290 |
+
$response = $this->gateway->purchase( $options );
|
291 |
+
$this->log_protection_status( $response );
|
292 |
+
$location = remove_query_arg( 'payment_gateway_callback' );
|
293 |
+
|
294 |
+
if ( $response->has_errors() ) {
|
295 |
+
$errors = $response->get_params();
|
296 |
+
|
297 |
+
if ( isset( $errors['L_ERRORCODE0'] ) && '10486' == $errors['L_ERRORCODE0'] ) {
|
298 |
+
wp_redirect( $this->get_redirect_url( array( 'token' => $token ) ) );
|
299 |
+
exit;
|
300 |
+
}
|
301 |
+
|
302 |
+
wpsc_update_customer_meta( 'paypal_express_checkout_errors', $response->get_errors() );
|
303 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_paypal_error' ) );
|
304 |
+
|
305 |
+
} elseif ( $response->is_payment_completed() || $response->is_payment_pending() ) {
|
306 |
+
$location = remove_query_arg( 'payment_gateway' );
|
307 |
+
|
308 |
+
if ( $response->is_payment_completed() ) {
|
309 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
310 |
+
} else {
|
311 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
312 |
+
}
|
313 |
+
|
314 |
+
$this->purchase_log->set( 'transactid', $response->get( 'transaction_id' ) )
|
315 |
+
->set( 'date', time() )
|
316 |
+
->save();
|
317 |
+
} else {
|
318 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_generic_error' ) );
|
319 |
+
}
|
320 |
+
|
321 |
+
wp_redirect( $location );
|
322 |
+
exit;
|
323 |
+
}
|
324 |
+
|
325 |
+
public function callback_display_paypal_error() {
|
326 |
+
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_paypal_error_page' ) );
|
327 |
+
}
|
328 |
+
|
329 |
+
public function callback_display_generic_error() {
|
330 |
+
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_generic_error_page' ) );
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* Records the Payer ID, Payer Status and Shipping Status to the Purchase
|
335 |
+
* Log on GetExpressCheckout Call
|
336 |
+
*
|
337 |
+
* @return void
|
338 |
+
*/
|
339 |
+
public function log_payer_details( $details ) {
|
340 |
+
if ( isset( $details->get( 'payer' )->id ) && !empty( $details->get( 'payer' )->id ) ) {
|
341 |
+
$payer_id = $details->get( 'payer' )->id;
|
342 |
+
} else {
|
343 |
+
$payer_id = 'not set';
|
344 |
+
}
|
345 |
+
if ( isset( $details->get( 'payer' )->status ) && !empty( $details->get( 'payer' )->status ) ) {
|
346 |
+
$payer_status = $details->get( 'payer' )->status;
|
347 |
+
} else {
|
348 |
+
$payer_status = 'not set';
|
349 |
+
}
|
350 |
+
if ( isset( $details->get( 'payer' )->shipping_status ) && !empty( $details->get( 'payer' )->shipping_status ) ) {
|
351 |
+
$payer_shipping_status = $details->get( 'payer' )->shipping_status;
|
352 |
+
} else {
|
353 |
+
$payer_shipping_status = 'not set';
|
354 |
+
}
|
355 |
+
$paypal_log = array(
|
356 |
+
'payer_id' => $payer_id,
|
357 |
+
'payer_status' => $payer_status,
|
358 |
+
'shipping_status' => $payer_shipping_status,
|
359 |
+
'protection' => null,
|
360 |
+
);
|
361 |
+
|
362 |
+
wpsc_update_purchase_meta( $this->purchase_log->get( 'id' ), 'paypal_ec_details' , $paypal_log );
|
363 |
+
}
|
364 |
+
|
365 |
+
/**
|
366 |
+
* Records the Protection Eligibility status to the Purchase Log on
|
367 |
+
* DoExpressCheckout Call
|
368 |
+
*
|
369 |
+
* @return void
|
370 |
+
*/
|
371 |
+
public function log_protection_status( $response ) {
|
372 |
+
$params = $response->get_params();
|
373 |
+
|
374 |
+
$elg = $params['PAYMENTINFO_0_PROTECTIONELIGIBILITY'];
|
375 |
+
$paypal_log = wpsc_get_purchase_meta( $this->purchase_log->get( 'id' ), 'paypal_ec_details', true );
|
376 |
+
$paypal_log['protection'] = $elg;
|
377 |
+
wpsc_update_purchase_meta( $this->purchase_log->get( 'id' ), 'paypal_ec_details' , $paypal_log );
|
378 |
+
}
|
379 |
+
|
380 |
+
public function callback_process_confirmed_payment() {
|
381 |
+
$args = array_map( 'urldecode', $_GET );
|
382 |
+
extract( $args, EXTR_SKIP );
|
383 |
+
|
384 |
+
if ( ! isset( $sessionid ) || ! isset( $token ) || ! isset( $PayerID ) ) {
|
385 |
+
return;
|
386 |
+
}
|
387 |
+
|
388 |
+
$this->set_purchase_log_for_callbacks();
|
389 |
+
|
390 |
+
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
391 |
+
$options = array(
|
392 |
+
'token' => $token,
|
393 |
+
'payer_id' => $PayerID,
|
394 |
+
'message_id' => $this->purchase_log->get( 'sessionid' ),
|
395 |
+
'invoice' => $this->purchase_log->get( 'id' ),
|
396 |
+
);
|
397 |
+
$options += $this->checkout_data->get_gateway_data();
|
398 |
+
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
399 |
+
|
400 |
+
if ( $this->setting->get( 'ipn', false ) ) {
|
401 |
+
$options['notify_url'] = $this->get_notify_url();
|
402 |
+
}
|
403 |
+
|
404 |
+
// GetExpressCheckoutDetails
|
405 |
+
$details = $this->gateway->get_details_for( $token );
|
406 |
+
$this->log_payer_details( $details );
|
407 |
+
|
408 |
+
$response = $this->gateway->purchase( $options );
|
409 |
+
$this->log_protection_status( $response );
|
410 |
+
$location = remove_query_arg( 'payment_gateway_callback' );
|
411 |
+
|
412 |
+
if ( $response->has_errors() ) {
|
413 |
+
wpsc_update_customer_meta( 'paypal_express_checkout_errors', $response->get_errors() );
|
414 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_paypal_error' ) );
|
415 |
+
} elseif ( $response->is_payment_completed() || $response->is_payment_pending() ) {
|
416 |
+
$location = remove_query_arg( 'payment_gateway' );
|
417 |
+
|
418 |
+
if ( $response->is_payment_completed() ) {
|
419 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
420 |
+
} else {
|
421 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
422 |
+
}
|
423 |
+
|
424 |
+
$this->purchase_log->set( 'transactid', $response->get( 'transaction_id' ) )
|
425 |
+
->set( 'date', time() )
|
426 |
+
->save();
|
427 |
+
} else {
|
428 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_generic_error' ) );
|
429 |
+
}
|
430 |
+
|
431 |
+
wp_redirect( $location );
|
432 |
+
exit;
|
433 |
+
}
|
434 |
+
|
435 |
+
/**
|
436 |
+
* Error Page Template
|
437 |
+
*
|
438 |
+
* @since 3.9
|
439 |
+
*/
|
440 |
+
public function filter_paypal_error_page() {
|
441 |
+
$errors = wpsc_get_customer_meta( 'paypal_express_checkout_errors' );
|
442 |
+
ob_start();
|
443 |
+
?>
|
444 |
+
<p>
|
445 |
+
<?php _e( 'Sorry, your transaction could not be processed by PayPal. Please contact the site administrator. The following errors are returned:' , 'wpsc' ); ?>
|
446 |
+
</p>
|
447 |
+
<ul>
|
448 |
+
<?php foreach ( $errors as $error ): ?>
|
449 |
+
<li><?php echo esc_html( $error['details'] ) ?> (<?php echo esc_html( $error['code'] ); ?>)</li>
|
450 |
+
<?php endforeach; ?>
|
451 |
+
</ul>
|
452 |
+
<p><a href="<?php echo esc_url( $this->get_shopping_cart_payment_url() ); ?>"><?php ( 'Click here to go back to the checkout page.') ?></a></p>
|
453 |
+
<?php
|
454 |
+
$output = apply_filters( 'wpsc_paypal_express_checkout_gateway_error_message', ob_get_clean(), $errors );
|
455 |
+
return $output;
|
456 |
+
}
|
457 |
+
|
458 |
+
/**
|
459 |
+
* Generic Error Page Template
|
460 |
+
*
|
461 |
+
* @since 3.9
|
462 |
+
*/
|
463 |
+
public function filter_generic_error_page() {
|
464 |
+
ob_start();
|
465 |
+
?>
|
466 |
+
<p><?php _e( 'Sorry, but your transaction could not be processed by PayPal for some reason. Please contact the site administrator.' , 'wpsc' ); ?></p>
|
467 |
+
<p><a href="<?php echo esc_attr( $this->get_shopping_cart_payment_url() ); ?>"><?php _e( 'Click here to go back to the checkout page.', 'wpsc' ) ?></a></p>
|
468 |
+
<?php
|
469 |
+
$output = apply_filters( 'wpsc_paypal_express_checkout_generic_error_message', ob_get_clean() );
|
470 |
+
return $output;
|
471 |
+
}
|
472 |
+
|
473 |
+
/**
|
474 |
+
* Settings Form Template
|
475 |
+
*
|
476 |
+
* @since 3.9
|
477 |
+
*/
|
478 |
+
public function setup_form() {
|
479 |
+
$paypal_currency = $this->get_currency_code();
|
480 |
+
?>
|
481 |
+
|
482 |
+
<!-- Account Credentials -->
|
483 |
+
<tr>
|
484 |
+
<td colspan="2">
|
485 |
+
<h4><?php _e( 'Account Credentials', 'wpsc' ); ?></h4>
|
486 |
+
</td>
|
487 |
+
</tr>
|
488 |
+
<tr>
|
489 |
+
<td>
|
490 |
+
<label for="wpsc-paypal-express-api-username"><?php _e( 'API Username', 'wpsc' ); ?></label>
|
491 |
+
</td>
|
492 |
+
<td>
|
493 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_username' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_username' ) ); ?>" id="wpsc-paypal-express-api-username" />
|
494 |
+
</td>
|
495 |
+
</tr>
|
496 |
+
<tr>
|
497 |
+
<td>
|
498 |
+
<label for="wpsc-paypal-express-api-password"><?php _e( 'API Password', 'wpsc' ); ?></label>
|
499 |
+
</td>
|
500 |
+
<td>
|
501 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_password' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_password' ) ); ?>" id="wpsc-paypal-express-api-password" />
|
502 |
+
</td>
|
503 |
+
</tr>
|
504 |
+
<tr>
|
505 |
+
<td>
|
506 |
+
<label for="wpsc-paypal-express-api-signature"><?php _e( 'API Signature', 'wpsc' ); ?></label>
|
507 |
+
</td>
|
508 |
+
<td>
|
509 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_signature' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_signature' ) ); ?>" id="wpsc-paypal-express-api-signature" />
|
510 |
+
</td>
|
511 |
+
</tr>
|
512 |
+
<tr>
|
513 |
+
<td>
|
514 |
+
<label><?php _e( 'Sandbox Mode', 'wpsc' ); ?></label>
|
515 |
+
</td>
|
516 |
+
<td>
|
517 |
+
<label><input <?php checked( $this->setting->get( 'sandbox_mode' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox_mode' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
518 |
+
<label><input <?php checked( (bool) $this->setting->get( 'sandbox_mode' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox_mode' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
519 |
+
</td>
|
520 |
+
</tr>
|
521 |
+
<tr>
|
522 |
+
<td>
|
523 |
+
<label><?php _e( 'IPN', 'wpsc' ); ?></label>
|
524 |
+
</td>
|
525 |
+
<td>
|
526 |
+
<label><input <?php checked( $this->setting->get( 'ipn' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'ipn' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
527 |
+
<label><input <?php checked( (bool) $this->setting->get( 'ipn' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'ipn' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
528 |
+
</td>
|
529 |
+
</tr>
|
530 |
+
|
531 |
+
<!-- Cart Customization -->
|
532 |
+
<tr>
|
533 |
+
<td colspan="2">
|
534 |
+
<label><h4><?php _e( 'Cart Customization', 'wpsc'); ?></h4></label>
|
535 |
+
</td>
|
536 |
+
</tr>
|
537 |
+
<tr>
|
538 |
+
<td>
|
539 |
+
<label for="wpsc-paypal-express-cart-logo"><?php _e( 'Merchant Logo', 'wpsc' ); ?></label>
|
540 |
+
</td>
|
541 |
+
<td>
|
542 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'cart_logo' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'cart_logo' ) ); ?>" id="wpsc-paypal-express-cart-logo" />
|
543 |
+
</td>
|
544 |
+
</tr>
|
545 |
+
<tr>
|
546 |
+
<td>
|
547 |
+
<label for="wpsc-paypal-express-cart-border"><?php _e( 'Cart Border Color', 'wpsc' ); ?></label>
|
548 |
+
</td>
|
549 |
+
<td>
|
550 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'cart_border' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'cart_border' ) ); ?>" id="wpsc-paypal-express-cart-border" />
|
551 |
+
</td>
|
552 |
+
</tr>
|
553 |
+
|
554 |
+
<!-- Currency Conversion -->
|
555 |
+
<?php if ( ! $this->is_currency_supported() ): ?>
|
556 |
+
<tr>
|
557 |
+
<td colspan="2">
|
558 |
+
<h4><?php _e( 'Currency Conversion', 'wpsc' ); ?></h4>
|
559 |
+
</td>
|
560 |
+
</tr>
|
561 |
+
<tr>
|
562 |
+
<td colspan="2">
|
563 |
+
<p><?php _e( 'Your base currency is currently not accepted by PayPal. As a result, before a payment request is sent to PayPal, WP eCommerce has to convert the amounts into one of PayPal supported currencies. Please select your preferred currency below.', 'wpsc' ); ?></p>
|
564 |
+
</td>
|
565 |
+
</tr>
|
566 |
+
<tr>
|
567 |
+
<td>
|
568 |
+
<label for "wpsc-paypal-express-currency"><?php _e( 'PayPal Currency', 'wpsc' ); ?></label>
|
569 |
+
</td>
|
570 |
+
<td>
|
571 |
+
<select name="<?php echo esc_attr( $this->setting->get_field_name( 'currency' ) ); ?>" id="wpsc-paypal-express-currency">
|
572 |
+
<?php foreach ( $this->gateway->get_supported_currencies() as $currency ) : ?>
|
573 |
+
<option <?php selected( $currency, $paypal_currency ); ?> value="<?php echo esc_attr( $currency ); ?>"><?php echo esc_html( $currency ); ?></option>
|
574 |
+
<?php endforeach ?>
|
575 |
+
</select>
|
576 |
+
</td>
|
577 |
+
</tr>
|
578 |
+
<?php endif ?>
|
579 |
+
|
580 |
+
<!-- Error Logging -->
|
581 |
+
<tr>
|
582 |
+
<td colspan="2">
|
583 |
+
<h4><?php _e( 'Error Logging', 'wpsc' ); ?></h4>
|
584 |
+
</td>
|
585 |
+
</tr>
|
586 |
+
<tr>
|
587 |
+
<td>
|
588 |
+
<label><?php _e( 'Enable Debugging', 'wpsc' ); ?></label>
|
589 |
+
</td>
|
590 |
+
<td>
|
591 |
+
<label><input <?php checked( $this->setting->get( 'debugging' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
592 |
+
<label><input <?php checked( (bool) $this->setting->get( 'debugging' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
593 |
+
</td>
|
594 |
+
</tr>
|
595 |
+
<?php
|
596 |
+
}
|
597 |
+
|
598 |
+
/**
|
599 |
+
* Check if the selected currency is supported by the gateway
|
600 |
+
*
|
601 |
+
* @return bool
|
602 |
+
*
|
603 |
+
* @since 3.9
|
604 |
+
*/
|
605 |
+
protected function is_currency_supported() {
|
606 |
+
return in_array( parent::get_currency_code(), $this->gateway->get_supported_currencies() );
|
607 |
+
}
|
608 |
+
|
609 |
+
/**
|
610 |
+
* Return the Currency ISO code
|
611 |
+
*
|
612 |
+
* @return string
|
613 |
+
*
|
614 |
+
* @since 3.9
|
615 |
+
*/
|
616 |
+
public function get_currency_code() {
|
617 |
+
$code = parent::get_currency_code();
|
618 |
+
|
619 |
+
if ( ! in_array( $code, $this->gateway->get_supported_currencies() ) ) {
|
620 |
+
$code = $this->setting->get( 'currency', 'USD' );
|
621 |
+
}
|
622 |
+
|
623 |
+
return $code;
|
624 |
+
}
|
625 |
+
|
626 |
+
/**
|
627 |
+
* Convert an amount (integer) to the supported currency
|
628 |
+
* @param integer $amt
|
629 |
+
*
|
630 |
+
* @return integer
|
631 |
+
*
|
632 |
+
* @since 3.9
|
633 |
+
*/
|
634 |
+
protected function convert( $amt ) {
|
635 |
+
if ( $this->is_currency_supported() ) {
|
636 |
+
return $amt;
|
637 |
+
}
|
638 |
+
|
639 |
+
return wpsc_convert_currency( $amt, parent::get_currency_code(), $this->get_currency_code() );
|
640 |
+
}
|
641 |
+
|
642 |
+
/**
|
643 |
+
* Process the SetExpressCheckout API Call
|
644 |
+
*
|
645 |
+
* @return void
|
646 |
+
*
|
647 |
+
* @since 3.9
|
648 |
+
*/
|
649 |
+
public function process() {
|
650 |
+
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
651 |
+
$options = array(
|
652 |
+
'return_url' => $this->get_return_url(),
|
653 |
+
'message_id' => $this->purchase_log->get( 'sessionid' ),
|
654 |
+
'invoice' => $this->purchase_log->get( 'id' ),
|
655 |
+
'address_override' => 1,
|
656 |
+
);
|
657 |
+
|
658 |
+
$options += $this->checkout_data->get_gateway_data();
|
659 |
+
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
660 |
+
|
661 |
+
if ( $this->setting->get( 'ipn', false ) ) {
|
662 |
+
$options['notify_url'] = $this->get_notify_url();
|
663 |
+
}
|
664 |
+
|
665 |
+
// SetExpressCheckout
|
666 |
+
$response = $this->gateway->setup_purchase( $options );
|
667 |
+
|
668 |
+
if ( $response->is_successful() ) {
|
669 |
+
$params = $response->get_params();
|
670 |
+
if ( $params['ACK'] == 'SuccessWithWarning' ) {
|
671 |
+
$this->log_error( $response );
|
672 |
+
}
|
673 |
+
// Successful redirect
|
674 |
+
$url = $this->get_redirect_url( array( 'token' => $response->get( 'token' ) ) );
|
675 |
+
} else {
|
676 |
+
// SetExpressCheckout Failure
|
677 |
+
$this->log_error( $response );
|
678 |
+
$url = add_query_arg( array(
|
679 |
+
'payment_gateway' => 'paypal-express-checkout',
|
680 |
+
'payment_gateway_callback' => 'display_paypal_error',
|
681 |
+
), $this->get_return_url() );
|
682 |
+
}
|
683 |
+
|
684 |
+
wp_redirect( $url );
|
685 |
+
exit;
|
686 |
+
}
|
687 |
+
|
688 |
+
/**
|
689 |
+
* Log an error message
|
690 |
+
*
|
691 |
+
* @param PHP_Merchant_Paypal_Express_Checkout_Response $response
|
692 |
+
* @return void
|
693 |
+
*
|
694 |
+
* @since 3.9
|
695 |
+
*/
|
696 |
+
public function log_error( $response ) {
|
697 |
+
if ( $this->setting->get( 'debugging' ) ) {
|
698 |
+
$log_data = array(
|
699 |
+
'post_title' => 'PayPal ExpressCheckout Operation Failure',
|
700 |
+
'post_content' => 'There was an error processing the payment. Find details in the log entry meta fields.',
|
701 |
+
'log_type' => 'error'
|
702 |
+
);
|
703 |
+
|
704 |
+
$log_meta = array(
|
705 |
+
'correlation_id' => $response->get( 'correlation_id' ),
|
706 |
+
'time' => $response->get( 'datetime' ),
|
707 |
+
'errors' => $response->get_errors(),
|
708 |
+
);
|
709 |
+
|
710 |
+
$log_entry = WPSC_Logging::insert_log( $log_data, $log_meta );
|
711 |
+
}
|
712 |
+
}
|
713 |
+
}
|
wpsc-components/merchant-core-v3/gateways/paypal-pro.php
ADDED
@@ -0,0 +1,633 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PayPal Pro Gateway class
|
4 |
+
*
|
5 |
+
*/
|
6 |
+
|
7 |
+
class WPSC_Payment_Gateway_Paypal_Pro extends WPSC_Payment_Gateway {
|
8 |
+
private $gateway;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Constructor of PayPal Pro Gateway
|
12 |
+
*
|
13 |
+
* @param array $options
|
14 |
+
* @return void
|
15 |
+
*
|
16 |
+
* @since 3.9
|
17 |
+
*/
|
18 |
+
public function __construct( $options ) {
|
19 |
+
parent::__construct();
|
20 |
+
|
21 |
+
$this->title = __( 'PayPal Pro 3.0', 'wpsc' );
|
22 |
+
|
23 |
+
require_once( 'php-merchant/gateways/paypal-pro.php' );
|
24 |
+
|
25 |
+
$this->gateway = new PHP_Merchant_Paypal_Pro( $options );
|
26 |
+
|
27 |
+
$this->gateway->set_options( array(
|
28 |
+
'api_username' => $this->setting->get( 'api_username' ),
|
29 |
+
'api_password' => $this->setting->get( 'api_password' ),
|
30 |
+
'api_signature' => $this->setting->get( 'api_signature' ),
|
31 |
+
'cancel_url' => $this->get_shopping_cart_payment_url(),
|
32 |
+
'currency' => $this->get_currency_code(),
|
33 |
+
'test' => (bool) $this->setting->get( 'sandbox_mode' ),
|
34 |
+
) );
|
35 |
+
|
36 |
+
// Load PayPal Pro JavaScript file
|
37 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'pro_script' ) );
|
38 |
+
|
39 |
+
add_filter( 'wpsc_purchase_log_gateway_data', array( $this, 'filter_purchase_log_gateway_data' ), 10, 2 );
|
40 |
+
|
41 |
+
// Unselect Default Payment Gateway
|
42 |
+
add_filter(
|
43 |
+
'wpsc_payment_method_form_fields',
|
44 |
+
array( $this, 'filter_unselect_default' ), 101 , 1
|
45 |
+
);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* No payment gateway is selected by default
|
50 |
+
*
|
51 |
+
* @access public
|
52 |
+
* @param array $fields
|
53 |
+
* @return array
|
54 |
+
*
|
55 |
+
* @since 3.9
|
56 |
+
*/
|
57 |
+
public function filter_unselect_default( $fields ) {
|
58 |
+
foreach ( $fields as $i=>$field ) {
|
59 |
+
$fields[ $i ][ 'checked' ] = false;
|
60 |
+
}
|
61 |
+
|
62 |
+
return $fields;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Returns the HTML of the logo of the payment gateway.
|
67 |
+
*
|
68 |
+
* @access public
|
69 |
+
* @return string
|
70 |
+
*
|
71 |
+
* @since 3.9
|
72 |
+
*/
|
73 |
+
public function get_mark_html() {
|
74 |
+
$html = '<img src="' . WPSC_URL . '/images/cc.gif" border="0" alt="' . esc_attr__( 'Credit Card Icons' ) .'" />';
|
75 |
+
|
76 |
+
return apply_filters( 'wpsc_paypal-pro_mark_html', $html );
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* WordPress Enqueue for the Pro Script and CSS file
|
81 |
+
*
|
82 |
+
* @return void
|
83 |
+
*
|
84 |
+
* @since 3.9
|
85 |
+
*/
|
86 |
+
public function pro_script() {
|
87 |
+
if ( wpsc_is_checkout() ) {
|
88 |
+
wp_enqueue_script( 'pro-script-internal', WPSC_URL . '/wpsc-components/merchant-core-v3/gateways/pro.js', array( 'jquery' ) );
|
89 |
+
wp_enqueue_style( 'pro-syle-internal', WPSC_URL . '/wpsc-components/merchant-core-v3/gateways/pro.css' );
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Purchase Log Filter for Gateway Data
|
95 |
+
*
|
96 |
+
* @param array $gateway_data
|
97 |
+
* @param array $data
|
98 |
+
* @return array
|
99 |
+
*
|
100 |
+
* @since 3.9
|
101 |
+
*/
|
102 |
+
public static function filter_purchase_log_gateway_data( $gateway_data, $data ) {
|
103 |
+
// Because paypal express checkout API doesn't have full support for discount, we have to manually add an item here
|
104 |
+
if ( isset( $gateway_data['discount'] ) && (float) $gateway_data['discount'] != 0 ) {
|
105 |
+
$i =& $gateway_data['items'];
|
106 |
+
$d =& $gateway_data['discount'];
|
107 |
+
$s =& $gateway_data['subtotal'];
|
108 |
+
|
109 |
+
// If discount amount is larger than or equal to the item total, we need to set item total to 0.01
|
110 |
+
// because Paypal does not accept 0 item total.
|
111 |
+
if ( $d >= $gateway_data['subtotal'] ) {
|
112 |
+
$d = $s - 0.01;
|
113 |
+
|
114 |
+
// if there's shipping, we'll take 0.01 from there
|
115 |
+
if ( ! empty( $gateway_data['shipping'] ) ) {
|
116 |
+
$gateway_data['shipping'] -= 0.01;
|
117 |
+
} else {
|
118 |
+
$gateway_data['amount'] = 0.01;
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
$s -= $d;
|
123 |
+
|
124 |
+
$i[] = array(
|
125 |
+
'name' => __( 'Discount', 'wpsc' ),
|
126 |
+
'amount' => - $d,
|
127 |
+
'quantity' => 1,
|
128 |
+
);
|
129 |
+
}
|
130 |
+
return $gateway_data;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Returns the URL of the Return Page after the PayPal Checkout
|
135 |
+
*
|
136 |
+
* @return string
|
137 |
+
*/
|
138 |
+
protected function get_return_url() {
|
139 |
+
$location = add_query_arg( array(
|
140 |
+
'sessionid' => $this->purchase_log->get( 'sessionid' ),
|
141 |
+
'payment_gateway' => 'paypal-pro',
|
142 |
+
'payment_gateway_callback' => 'confirm_transaction',
|
143 |
+
),
|
144 |
+
get_option( 'transact_url' )
|
145 |
+
);
|
146 |
+
return apply_filters( 'wpsc_paypal_pro_return_url', $location, $this );
|
147 |
+
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Returns the URL of the IPN Page
|
152 |
+
*
|
153 |
+
* @return string
|
154 |
+
*/
|
155 |
+
protected function get_notify_url() {
|
156 |
+
$location = add_query_arg( array(
|
157 |
+
'payment_gateway' => 'paypal-pro',
|
158 |
+
'payment_gateway_callback' => 'ipn',
|
159 |
+
), home_url( 'index.php' ) );
|
160 |
+
|
161 |
+
return apply_filters( 'wpsc_paypal_pro_notify_url', $location );
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Creates a new Purchase Log entry and set it to the current object
|
166 |
+
* @param bool|int ID or session id
|
167 |
+
*
|
168 |
+
* @return null
|
169 |
+
*/
|
170 |
+
protected function set_purchase_log_for_callbacks( $id = false, $sessionid = false ) {
|
171 |
+
// Define the sessionid if it's not passed
|
172 |
+
if ( $id === false ) {
|
173 |
+
$id = $_REQUEST['sessionid'];
|
174 |
+
}
|
175 |
+
|
176 |
+
// Create a new Purchase Log entry
|
177 |
+
if ( $sessionid === 'sessionid' ) {
|
178 |
+
$purchase_log = new WPSC_Purchase_Log( $id, 'sessionid' );
|
179 |
+
} else {
|
180 |
+
$purchase_log = new WPSC_Purchase_Log( $id, 'id' );
|
181 |
+
}
|
182 |
+
|
183 |
+
if ( ! $purchase_log->exists() ) {
|
184 |
+
return null;
|
185 |
+
}
|
186 |
+
|
187 |
+
// Set the Purchase Log for the gateway object
|
188 |
+
$this->set_purchase_log( $purchase_log );
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* IPN Callback function
|
193 |
+
*
|
194 |
+
* @return void
|
195 |
+
*/
|
196 |
+
public function callback_ipn() {
|
197 |
+
$ipn = new PHP_Merchant_Paypal_IPN( false, (bool) $this->setting->get( 'sandbox_mode', false ) );
|
198 |
+
|
199 |
+
if ( $ipn->is_verified() ) {
|
200 |
+
$sessionid = $ipn->get( 'invoice' );
|
201 |
+
$this->set_purchase_log_for_callbacks( $sessionid );
|
202 |
+
|
203 |
+
if ( $ipn->is_payment_denied() ) {
|
204 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::PAYMENT_DECLINED );
|
205 |
+
} elseif ( $ipn->is_payment_refunded() ) {
|
206 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUNDED );
|
207 |
+
} elseif ( $ipn->is_payment_completed() ) {
|
208 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
209 |
+
} elseif ( $ipn->is_payment_pending() ) {
|
210 |
+
if ( $ipn->is_payment_refund_pending() ) {
|
211 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUND_PENDING );
|
212 |
+
} else {
|
213 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
$this->purchase_log->save();
|
218 |
+
transaction_results( $sessionid, false );
|
219 |
+
}
|
220 |
+
|
221 |
+
exit;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Confirm Transaction Callback
|
226 |
+
*
|
227 |
+
* @return bool
|
228 |
+
*
|
229 |
+
* @since 3.9
|
230 |
+
*/
|
231 |
+
public function callback_confirm_transaction() {
|
232 |
+
if ( ! isset( $_REQUEST['sessionid'] ) || ! isset( $_REQUEST['tx'] ) ) {
|
233 |
+
return false;
|
234 |
+
}
|
235 |
+
|
236 |
+
// Set the Purchase Log
|
237 |
+
$this->set_purchase_log_for_callbacks();
|
238 |
+
|
239 |
+
// Display the Confirmation Page
|
240 |
+
$this->do_transaction();
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Process the transaction through the PayPal APIs
|
245 |
+
*
|
246 |
+
* @since 3.9
|
247 |
+
*/
|
248 |
+
public function do_transaction() {
|
249 |
+
$args = array_map( 'urldecode', $_GET );
|
250 |
+
extract( $args, EXTR_SKIP );
|
251 |
+
|
252 |
+
if ( ! isset( $sessionid ) || ! isset( $tx ) || ! isset( $CSCMATCH ) ) {
|
253 |
+
return;
|
254 |
+
}
|
255 |
+
|
256 |
+
$this->set_purchase_log_for_callbacks( $sessionid, 'sessionid' );
|
257 |
+
|
258 |
+
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
259 |
+
|
260 |
+
$options = array(
|
261 |
+
'tx' => $tx,
|
262 |
+
'CSCMATCH' => $CSCMATCH,
|
263 |
+
'message_id' => $this->purchase_log->get( 'sessionid' ),
|
264 |
+
'invoice' => $this->purchase_log->get( 'id' ),
|
265 |
+
);
|
266 |
+
|
267 |
+
$options += $this->checkout_data->get_gateway_data();
|
268 |
+
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
269 |
+
|
270 |
+
if ( $this->setting->get( 'ipn', false ) ) {
|
271 |
+
$options['notify_url'] = $this->get_notify_url();
|
272 |
+
}
|
273 |
+
|
274 |
+
$response = $this->gateway->get_transaction_details( $tx );
|
275 |
+
|
276 |
+
$this->log_payer_details( $response );
|
277 |
+
$this->log_protection_status( $response );
|
278 |
+
$location = remove_query_arg( 'payment_gateway_callback' );
|
279 |
+
|
280 |
+
if ( $response->has_errors() ) {
|
281 |
+
wpsc_update_customer_meta( 'paypal_pro_errors', $response->get_errors() );
|
282 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_paypal_error' ) );
|
283 |
+
} elseif ( $response->is_payment_completed() || $response->is_payment_pending() ) {
|
284 |
+
$location = remove_query_arg( 'payment_gateway' );
|
285 |
+
|
286 |
+
if ( $response->is_payment_completed() ) {
|
287 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
288 |
+
} else {
|
289 |
+
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
290 |
+
}
|
291 |
+
|
292 |
+
$this->purchase_log->set( 'transactid', $response->get( 'transaction_id' ) )
|
293 |
+
->set( 'date', time() )
|
294 |
+
->save();
|
295 |
+
} else {
|
296 |
+
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_generic_error' ) );
|
297 |
+
}
|
298 |
+
|
299 |
+
wp_redirect( $location );
|
300 |
+
exit;
|
301 |
+
}
|
302 |
+
|
303 |
+
public function callback_display_paypal_error() {
|
304 |
+
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_paypal_error_page' ) );
|
305 |
+
}
|
306 |
+
|
307 |
+
public function callback_display_generic_error() {
|
308 |
+
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_generic_error_page' ) );
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Records the Payer ID, Payer Status and Shipping Status to the Purchase
|
313 |
+
* Log on GetExpressCheckout Call
|
314 |
+
*
|
315 |
+
* @return void
|
316 |
+
*/
|
317 |
+
public function log_payer_details( $details ) {
|
318 |
+
if ( isset( $details->get( 'payer' )->id ) && !empty( $details->get( 'payer' )->id ) ) {
|
319 |
+
$payer_id = $details->get( 'payer' )->id;
|
320 |
+
} else {
|
321 |
+
$payer_id = 'not set';
|
322 |
+
}
|
323 |
+
if ( isset( $details->get( 'payer' )->status ) && !empty( $details->get( 'payer' )->status ) ) {
|
324 |
+
$payer_status = $details->get( 'payer' )->status;
|
325 |
+
} else {
|
326 |
+
$payer_status = 'not set';
|
327 |
+
}
|
328 |
+
if ( isset( $details->get( 'payer' )->shipping_status ) && !empty( $details->get( 'payer' )->shipping_status ) ) {
|
329 |
+
$payer_shipping_status = $details->get( 'payer' )->shipping_status;
|
330 |
+
} else {
|
331 |
+
$payer_shipping_status = 'not set';
|
332 |
+
}
|
333 |
+
$paypal_log = array(
|
334 |
+
'payer_id' => $payer_id,
|
335 |
+
'payer_status' => $payer_status,
|
336 |
+
'shipping_status' => $payer_shipping_status,
|
337 |
+
'protection' => null,
|
338 |
+
);
|
339 |
+
|
340 |
+
wpsc_update_purchase_meta( $this->purchase_log->get( 'id' ), 'paypal_pro_details' , $paypal_log );
|
341 |
+
}
|
342 |
+
|
343 |
+
/**
|
344 |
+
* Records the Protection Eligibility status to the Purchase Log
|
345 |
+
* after the purchase process
|
346 |
+
*
|
347 |
+
* @param PHP_Merchant_Paypal_Pro_Response $response
|
348 |
+
* @return void
|
349 |
+
*/
|
350 |
+
public function log_protection_status( $response ) {
|
351 |
+
$params = $response->get_params();
|
352 |
+
|
353 |
+
$elg = $params['PROTECTIONELIGIBILITY'];
|
354 |
+
$paypal_log = wpsc_get_purchase_meta( $this->purchase_log->get( 'id' ), 'paypal_pro_details', true );
|
355 |
+
$paypal_log['protection'] = $elg;
|
356 |
+
wpsc_update_purchase_meta( $this->purchase_log->get( 'id' ), 'paypal_pro_details' , $paypal_log );
|
357 |
+
}
|
358 |
+
|
359 |
+
public function callback_process_confirmed_payment() {
|
360 |
+
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Error Page Template
|
365 |
+
*
|
366 |
+
* @since 3.9
|
367 |
+
*/
|
368 |
+
public function filter_paypal_error_page() {
|
369 |
+
$errors = wpsc_get_customer_meta( 'paypal_pro_errors' );
|
370 |
+
ob_start();
|
371 |
+
?>
|
372 |
+
<p>
|
373 |
+
<?php _e( 'Sorry, your transaction could not be processed by PayPal. Please contact the site administrator. The following errors are returned:' , 'wpsc' ); ?>
|
374 |
+
</p>
|
375 |
+
<ul>
|
376 |
+
<?php foreach ( $errors as $error ): ?>
|
377 |
+
<li><?php echo esc_html( $error['details'] ) ?> (<?php echo esc_html( $error['code'] ); ?>)</li>
|
378 |
+
<?php endforeach; ?>
|
379 |
+
</ul>
|
380 |
+
<p><a href="<?php echo esc_url( $this->get_shopping_cart_payment_url() ); ?>"><?php ( 'Click here to go back to the checkout page.') ?></a></p>
|
381 |
+
<?php
|
382 |
+
$output = apply_filters( 'wpsc_paypal_pro_gateway_error_message', ob_get_clean(), $errors );
|
383 |
+
return $output;
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Generic Error Page Template
|
388 |
+
*
|
389 |
+
* @since 3.9
|
390 |
+
*/
|
391 |
+
public function filter_generic_error_page() {
|
392 |
+
ob_start();
|
393 |
+
?>
|
394 |
+
<p><?php _e( 'Sorry, but your transaction could not be processed by PayPal for some reason. Please contact the site administrator.' , 'wpsc' ); ?></p>
|
395 |
+
<p><a href="<?php echo esc_attr( $this->get_shopping_cart_payment_url() ); ?>"><?php _e( 'Click here to go back to the checkout page.', 'wpsc' ) ?></a></p>
|
396 |
+
<?php
|
397 |
+
$output = apply_filters( 'wpsc_paypal_pro_generic_error_message', ob_get_clean() );
|
398 |
+
return $output;
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Settings Form Template
|
403 |
+
*
|
404 |
+
* @since 3.9
|
405 |
+
*/
|
406 |
+
public function setup_form() {
|
407 |
+
$paypal_currency = $this->get_currency_code();
|
408 |
+
?>
|
409 |
+
|
410 |
+
<!-- Account Credentials -->
|
411 |
+
<tr>
|
412 |
+
<td colspan="2">
|
413 |
+
<h4><?php _e( 'Account Credentials', 'wpsc' ); ?></h4>
|
414 |
+
</td>
|
415 |
+
</tr>
|
416 |
+
<tr>
|
417 |
+
<td>
|
418 |
+
<label for="wpsc-paypal-pro-vendor-id"><?php _e( 'Vendor ID', 'wpsc' ); ?></label>
|
419 |
+
</td>
|
420 |
+
<td>
|
421 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'vendor_id' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'vendor_id' ) ); ?>" id="wpsc-paypal-pro-vendor-id" />
|
422 |
+
</td>
|
423 |
+
</tr>
|
424 |
+
<tr>
|
425 |
+
<td>
|
426 |
+
<label for="wpsc-paypal-pro-api-username"><?php _e( 'API Username', 'wpsc' ); ?></label>
|
427 |
+
</td>
|
428 |
+
<td>
|
429 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_username' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_username' ) ); ?>" id="wpsc-paypal-pro-api-username" />
|
430 |
+
</td>
|
431 |
+
</tr>
|
432 |
+
<tr>
|
433 |
+
<td>
|
434 |
+
<label for="wpsc-paypal-pro-api-password"><?php _e( 'API Password', 'wpsc' ); ?></label>
|
435 |
+
</td>
|
436 |
+
<td>
|
437 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_password' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_password' ) ); ?>" id="wpsc-paypal-pro-api-password" />
|
438 |
+
</td>
|
439 |
+
</tr>
|
440 |
+
<tr>
|
441 |
+
<td>
|
442 |
+
<label for="wpsc-paypal-pro-api-signature"><?php _e( 'API Signature', 'wpsc' ); ?></label>
|
443 |
+
</td>
|
444 |
+
<td>
|
445 |
+
<input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'api_signature' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'api_signature' ) ); ?>" id="wpsc-paypal-pro-api-signature" />
|
446 |
+
</td>
|
447 |
+
</tr>
|
448 |
+
<tr>
|
449 |
+
<td>
|
450 |
+
<label><?php _e( 'Sandbox Mode', 'wpsc' ); ?></label>
|
451 |
+
</td>
|
452 |
+
<td>
|
453 |
+
<label><input <?php checked( $this->setting->get( 'sandbox_mode' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox_mode' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
454 |
+
<label><input <?php checked( (bool) $this->setting->get( 'sandbox_mode' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox_mode' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
455 |
+
</td>
|
456 |
+
</tr>
|
457 |
+
<tr>
|
458 |
+
<td>
|
459 |
+
<label><?php _e( 'IPN', 'wpsc' ); ?></label>
|
460 |
+
</td>
|
461 |
+
<td>
|
462 |
+
<label><input <?php checked( $this->setting->get( 'ipn' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'ipn' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
463 |
+
<label><input <?php checked( (bool) $this->setting->get( 'ipn' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'ipn' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
464 |
+
</td>
|
465 |
+
</tr>
|
466 |
+
|
467 |
+
<!-- Currency Conversion -->
|
468 |
+
<?php if ( ! $this->is_currency_supported() ): ?>
|
469 |
+
<tr>
|
470 |
+
<td colspan="2">
|
471 |
+
<h4><?php _e( 'Currency Conversion', 'wpsc' ); ?></h4>
|
472 |
+
</td>
|
473 |
+
</tr>
|
474 |
+
<tr>
|
475 |
+
<td colspan="2">
|
476 |
+
<p><?php _e( 'Your base currency is currently not accepted by PayPal. As a result, before a payment request is sent to PayPal, WP eCommerce has to convert the amounts into one of PayPal supported currencies. Please select your preferred currency below.', 'wpsc' ); ?></p>
|
477 |
+
</td>
|
478 |
+
</tr>
|
479 |
+
<tr>
|
480 |
+
<td>
|
481 |
+
<label for "wpsc-paypal-pro-currency"><?php _e( 'PayPal Currency', 'wpsc' ); ?></label>
|
482 |
+
</td>
|
483 |
+
<td>
|
484 |
+
<select name="<?php echo esc_attr( $this->setting->get_field_name( 'currency' ) ); ?>" id="wpsc-paypal-pro-currency">
|
485 |
+
<?php foreach ( $this->gateway->get_supported_currencies() as $currency ) : ?>
|
486 |
+
<option <?php selected( $currency, $paypal_currency ); ?> value="<?php echo esc_attr( $currency ); ?>"><?php echo esc_html( $currency ); ?></option>
|
487 |
+
<?php endforeach ?>
|
488 |
+
</select>
|
489 |
+
</td>
|
490 |
+
</tr>
|
491 |
+
<?php endif ?>
|
492 |
+
|
493 |
+
<!-- Error Logging -->
|
494 |
+
<tr>
|
495 |
+
<td colspan="2">
|
496 |
+
<h4><?php _e( 'Error Logging', 'wpsc' ); ?></h4>
|
497 |
+
</td>
|
498 |
+
</tr>
|
499 |
+
<tr>
|
500 |
+
<td>
|
501 |
+
<label><?php _e( 'Enable Debugging', 'wpsc' ); ?></label>
|
502 |
+
</td>
|
503 |
+
<td>
|
504 |
+
<label><input <?php checked( $this->setting->get( 'debugging' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wpsc' ); ?></label>
|
505 |
+
<label><input <?php checked( (bool) $this->setting->get( 'debugging' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="0" /> <?php _e( 'No', 'wpsc' ); ?></label>
|
506 |
+
</td>
|
507 |
+
</tr>
|
508 |
+
<?php
|
509 |
+
}
|
510 |
+
|
511 |
+
/**
|
512 |
+
* Check if the selected currency is supported by the gateway
|
513 |
+
*
|
514 |
+
* @return bool
|
515 |
+
*
|
516 |
+
* @since 3.9
|
517 |
+
*/
|
518 |
+
protected function is_currency_supported() {
|
519 |
+
return in_array( parent::get_currency_code(), $this->gateway->get_supported_currencies() );
|
520 |
+
}
|
521 |
+
|
522 |
+
/**
|
523 |
+
* Return the Currency ISO code
|
524 |
+
*
|
525 |
+
* @return string
|
526 |
+
*
|
527 |
+
* @since 3.9
|
528 |
+
*/
|
529 |
+
public function get_currency_code() {
|
530 |
+
$code = parent::get_currency_code();
|
531 |
+
|
532 |
+
if ( ! in_array( $code, $this->gateway->get_supported_currencies() ) ) {
|
533 |
+
$code = $this->setting->get( 'currency', 'USD' );
|
534 |
+
}
|
535 |
+
|
536 |
+
return $code;
|
537 |
+
}
|
538 |
+
|
539 |
+
/**
|
540 |
+
* Convert an amount (integer) to the supported currency
|
541 |
+
* @param integer $amt
|
542 |
+
*
|
543 |
+
* @return integer
|
544 |
+
*
|
545 |
+
* @since 3.9
|
546 |
+
*/
|
547 |
+
protected function convert( $amt ) {
|
548 |
+
if ( $this->is_currency_supported() ) {
|
549 |
+
return $amt;
|
550 |
+
}
|
551 |
+
|
552 |
+
return wpsc_convert_currency( $amt, parent::get_currency_code(), $this->get_currency_code() );
|
553 |
+
}
|
554 |
+
|
555 |
+
/**
|
556 |
+
* Call the CreateButton API
|
557 |
+
*
|
558 |
+
* @return void
|
559 |
+
*
|
560 |
+
* @since 3.9
|
561 |
+
*/
|
562 |
+
public function process() {
|
563 |
+
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
564 |
+
$options = array(
|
565 |
+
'return_url' => $this->get_return_url(),
|
566 |
+
'message_id' => $this->purchase_log->get( 'sessionid' ),
|
567 |
+
'invoice' => $this->purchase_log->get( 'id' ),
|
568 |
+
'address_override' => 1,
|
569 |
+
'paymentaction' => 'sale',
|
570 |
+
'template' => 'templateD',
|
571 |
+
'vendor' => $this->setting->get( 'vendor_id' ),
|
572 |
+
);
|
573 |
+
|
574 |
+
$options += $this->checkout_data->get_gateway_data();
|
575 |
+
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
576 |
+
|
577 |
+
if ( $this->setting->get( 'ipn', false ) ) {
|
578 |
+
$options['notify_url'] = $this->get_notify_url();
|
579 |
+
}
|
580 |
+
|
581 |
+
// BMCreateButton API call
|
582 |
+
$response = $this->gateway->createButton( $options );
|
583 |
+
$params = $response->get_params();
|
584 |
+
$website_code = $params['WEBSITECODE'];
|
585 |
+
|
586 |
+
|
587 |
+
if ( $response->is_successful() ) {
|
588 |
+
$params = $response->get_params();
|
589 |
+
// Log any warning
|
590 |
+
if ( $params['ACK'] == 'SuccessWithWarning' ) {
|
591 |
+
$this->log_error( $response );
|
592 |
+
}
|
593 |
+
} else {
|
594 |
+
// Log errors and redirect user
|
595 |
+
$this->log_error( $response );
|
596 |
+
$url = add_query_arg( array(
|
597 |
+
'payment_gateway' => 'paypal-pro-checkout',
|
598 |
+
'payment_gateway_callback' => 'display_paypal_error',
|
599 |
+
), $this->get_return_url() );
|
600 |
+
}
|
601 |
+
|
602 |
+
// Write the Button code
|
603 |
+
echo( $website_code );
|
604 |
+
|
605 |
+
exit;
|
606 |
+
}
|
607 |
+
|
608 |
+
/**
|
609 |
+
* Log an error message
|
610 |
+
*
|
611 |
+
* @param PHP_Merchant_Paypal_Pro_Response $response
|
612 |
+
* @return void
|
613 |
+
*
|
614 |
+
* @since 3.9
|
615 |
+
*/
|
616 |
+
public function log_error( $response ) {
|
617 |
+
if ( $this->setting->get( 'debugging' ) ) {
|
618 |
+
$log_data = array(
|
619 |
+
'post_title' => 'PayPal Pro Operation Failure',
|
620 |
+
'post_content' => 'There was an error processing the payment. Find details in the log entry meta fields.',
|
621 |
+
'log_type' => 'error'
|
622 |
+
);
|
623 |
+
|
624 |
+
$log_meta = array(
|
625 |
+
'correlation_id' => $response->get( 'correlation_id' ),
|
626 |
+
'time' => $response->get( 'datetime' ),
|
627 |
+
'errors' => $response->get_errors(),
|
628 |
+
);
|
629 |
+
|
630 |
+
$log_entry = WPSC_Logging::insert_log( $log_data, $log_meta );
|
631 |
+
}
|
632 |
+
}
|
633 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/README.md
ADDED
File without changes
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/exception.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
define( 'PHPME_FEATURE_NOT_SUPPORTED', 1 );
|
4 |
+
define( 'PHPME_REQUIRED_OPTION_UNDEFINED', 2 );
|
5 |
+
define( 'PHPME_HTTP_REQUEST_FAILED', 3 );
|
6 |
+
define( 'PHPME_INVALID_RESPONSE', 4 );
|
7 |
+
|
8 |
+
final class PHP_Merchant_Exception extends Exception {
|
9 |
+
private static $messages = array(
|
10 |
+
PHPME_FEATURE_NOT_SUPPORTED => 'This payment gateway does not support "%s" feature',
|
11 |
+
PHPME_REQUIRED_OPTION_UNDEFINED => 'Missing required parameter: %s',
|
12 |
+
PHPME_HTTP_REQUEST_FAILED => 'HTTP request failed: %s',
|
13 |
+
PHPME_INVALID_RESPONSE => 'Invalid response from payment gateway',
|
14 |
+
);
|
15 |
+
|
16 |
+
public static function addCodes( $codes ) {
|
17 |
+
if ( ! is_array( $codes ) )
|
18 |
+
return;
|
19 |
+
|
20 |
+
self::$message += $codes;
|
21 |
+
}
|
22 |
+
|
23 |
+
private $other_args;
|
24 |
+
|
25 |
+
public function __construct( $code, $message_args = array(), $other_args = array() ) {
|
26 |
+
$this->message_args = (array) $message_args;
|
27 |
+
$this->message = vsprintf( self::$messages[$code], $this->message_args );
|
28 |
+
$this->other_args = (array) $other_args;
|
29 |
+
$this->code = $code;
|
30 |
+
|
31 |
+
parent::__construct( $this->message, $code );
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getArguments() {
|
35 |
+
return $this->other_args;
|
36 |
+
}
|
37 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/helpers.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
function phpme_map( $from_array, $map, $return_type = 'Array' ) {
|
3 |
+
$return = array();
|
4 |
+
|
5 |
+
foreach ( $map as $to_key => $from_key ) {
|
6 |
+
if ( isset( $from_array[$from_key] ) )
|
7 |
+
$return[$to_key] = $from_array[$from_key];
|
8 |
+
}
|
9 |
+
|
10 |
+
if ( $return_type == 'Object' )
|
11 |
+
$return = (Object) $return;
|
12 |
+
|
13 |
+
return $return;
|
14 |
+
}
|
15 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/http-curl.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class PHP_Merchant_HTTP_CURL extends PHP_Merchant_HTTP
|
4 |
+
{
|
5 |
+
protected function request( $url, $fields = array(), $args = array() ) {
|
6 |
+
$defaults = array(
|
7 |
+
'follow' => true,
|
8 |
+
'method' => 'GET',
|
9 |
+
'ssl_verify' => false,
|
10 |
+
'body' => '',
|
11 |
+
);
|
12 |
+
|
13 |
+
$args = array_merge( $defaults, $args );
|
14 |
+
extract( $args, EXTR_SKIP );
|
15 |
+
|
16 |
+
$body = http_build_query( $fields );
|
17 |
+
|
18 |
+
$handle = curl_init();
|
19 |
+
curl_setopt( $handle, CURLOPT_URL, $url );
|
20 |
+
curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
|
21 |
+
curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, $ssl_verify ? 2 : false );
|
22 |
+
curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify );
|
23 |
+
curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, $follow );
|
24 |
+
|
25 |
+
switch ( $method ) {
|
26 |
+
case 'POST':
|
27 |
+
curl_setopt( $handle, CURLOPT_POST, true );
|
28 |
+
curl_setopt( $handle, CURLOPT_POSTFIELDS, $body );
|
29 |
+
break;
|
30 |
+
}
|
31 |
+
|
32 |
+
$response = curl_exec( $handle );
|
33 |
+
|
34 |
+
if ( ! $response ) {
|
35 |
+
throw new PHP_Merchant_Exception( PHPME_HTTP_REQUEST_FAILED, curl_error( $handle ) );
|
36 |
+
}
|
37 |
+
|
38 |
+
return $response;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function post( $url, $fields = array(), $args = array() ) {
|
42 |
+
$args['method'] = 'POST';
|
43 |
+
return $this->request( $url, $fields, $args );
|
44 |
+
}
|
45 |
+
|
46 |
+
public function get( $url, $fields = array(), $args = array() ) {
|
47 |
+
return $this->request( $url, $fields, $args );
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Generate URL-encoded query string
|
52 |
+
*
|
53 |
+
* @param array|object $args An Array or Object containaing properties
|
54 |
+
* @return string|bool Returns a URL-encoded string.
|
55 |
+
*/
|
56 |
+
protected function parse_args( $args ) {
|
57 |
+
if ( is_object ( $args ) || is_array( $args ) ) {
|
58 |
+
return http_build_query( $args );
|
59 |
+
}
|
60 |
+
return false;
|
61 |
+
}
|
62 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/http.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class PHP_Merchant_HTTP
|
4 |
+
{
|
5 |
+
public function __construct() {
|
6 |
+
|
7 |
+
}
|
8 |
+
|
9 |
+
abstract public function get( $url, $args = array() );
|
10 |
+
abstract public function post( $url, $args = array() );
|
11 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/php-merchant.php
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
*
|
6 |
+
* @author Instinct Entertainment
|
7 |
+
* @package PHP_Merchant
|
8 |
+
**/
|
9 |
+
|
10 |
+
require_once( 'exception.php' );
|
11 |
+
require_once( 'http.php' );
|
12 |
+
require_once( 'response.php' );
|
13 |
+
require_once( 'helpers.php' );
|
14 |
+
|
15 |
+
abstract class PHP_Merchant {
|
16 |
+
/**
|
17 |
+
* These currencies don't have decimal points. Eg: You never see JPY1000.5
|
18 |
+
*
|
19 |
+
* @var array
|
20 |
+
* @access protected
|
21 |
+
*/
|
22 |
+
protected $currencies_without_fractions = array( 'JPY', 'HUF' );
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Options are passed into the object constructor or payment action methods (purchase,
|
26 |
+
* authorize, capture void, credit, recurring). These options will eventually be used
|
27 |
+
* to generate HTTP requests to payment gateways.
|
28 |
+
*
|
29 |
+
* @var array
|
30 |
+
* @access protected
|
31 |
+
*/
|
32 |
+
protected $options = array(
|
33 |
+
'currency' => 'USD',
|
34 |
+
);
|
35 |
+
|
36 |
+
/**
|
37 |
+
* This is the object that handles sending HTTP requests. The default HTTP client is CURL,
|
38 |
+
* but you can always set a custom HTTP client object that inherits from PHP_Merchant_HTTP.
|
39 |
+
*
|
40 |
+
* @var PHP_Merchant_HTTP
|
41 |
+
* @access protected
|
42 |
+
*/
|
43 |
+
protected $http;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Constructor of the payment gateway. Accepts an array of options.
|
47 |
+
*
|
48 |
+
* @param array $options
|
49 |
+
*/
|
50 |
+
public function __construct( $options = array() ) {
|
51 |
+
if ( ! array_key_exists( 'http_client', $options ) ) {
|
52 |
+
require_once( 'http-curl.php' );
|
53 |
+
$this->http = new PHP_Merchant_HTTP_CURL();
|
54 |
+
} else {
|
55 |
+
$this->http =& $options['http_client'];
|
56 |
+
unset( $options['http_client'] );
|
57 |
+
}
|
58 |
+
|
59 |
+
$this->set_options( $options );
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Format the amount according to the currency being used.
|
64 |
+
*
|
65 |
+
* @param float $amt Amount
|
66 |
+
* @param string $currency Defaults to the currency specified in defined $options
|
67 |
+
* @return string
|
68 |
+
*/
|
69 |
+
public function format( $amt, $currency = false ) {
|
70 |
+
if ( ! $currency )
|
71 |
+
$currency = $this->options['currency'];
|
72 |
+
|
73 |
+
$dec = in_array( $currency, $this->currencies_without_fractions ) ? 0 : 2;
|
74 |
+
return number_format( $amt, $dec );
|
75 |
+
}
|
76 |
+
|
77 |
+
public function purchase( $options = array() ) {
|
78 |
+
$this->requires( 'amount' );
|
79 |
+
}
|
80 |
+
|
81 |
+
public function authorize() {
|
82 |
+
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'authorize' );
|
83 |
+
}
|
84 |
+
|
85 |
+
public function capture() {
|
86 |
+
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'capture' );
|
87 |
+
}
|
88 |
+
|
89 |
+
public function void() {
|
90 |
+
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'void' );
|
91 |
+
}
|
92 |
+
|
93 |
+
public function credit() {
|
94 |
+
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'credit' );
|
95 |
+
}
|
96 |
+
|
97 |
+
public function recurring() {
|
98 |
+
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'recurring' );
|
99 |
+
}
|
100 |
+
|
101 |
+
public function get_options() {
|
102 |
+
return $this->options;
|
103 |
+
}
|
104 |
+
|
105 |
+
public function set_options( $options ) {
|
106 |
+
$this->options = array_merge( $this->options, $options );
|
107 |
+
return $this;
|
108 |
+
}
|
109 |
+
|
110 |
+
public function get_option( $key ) {
|
111 |
+
return array_key_exists( $key, $this->options ) ? $this->options[ $key ] : null;
|
112 |
+
}
|
113 |
+
|
114 |
+
public function set_option( $key, $value ) {
|
115 |
+
$this->options[ $key ] = $value;
|
116 |
+
return $this;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Specify fields that are required for the API operation, otherwise
|
121 |
+
* throw a PHP_Merchant_Exception exception
|
122 |
+
*
|
123 |
+
* @param array $options Required fields
|
124 |
+
* @return void
|
125 |
+
* @since 3.9
|
126 |
+
*/
|
127 |
+
protected function requires( $options ) {
|
128 |
+
$missing = array();
|
129 |
+
foreach ( (array) $options as $option ) {
|
130 |
+
if ( ! isset( $this->options[ $option ] ) ) {
|
131 |
+
$missing[] = $option;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
if ( ! empty( $missing ) ) {
|
136 |
+
throw new PHP_Merchant_Exception( PHPME_REQUIRED_OPTION_UNDEFINED, implode( ', ', $missing ) );
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Specify fields that are required for the API operation, otherwise
|
142 |
+
* throw a PHP_Merchant_Exception exception
|
143 |
+
*
|
144 |
+
* @param array $options Required fields
|
145 |
+
* @return boolean|void Returns True if a specified field is found
|
146 |
+
* @since 3.9
|
147 |
+
*/
|
148 |
+
protected function conditional_requires( $options ) {
|
149 |
+
foreach ( (array) $options as $option ) {
|
150 |
+
if ( isset( $this->options[ $option ] ) ) {
|
151 |
+
return true;
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
throw new PHP_Merchant_Exception( PHPME_REQUIRED_OPTION_UNDEFINED, implode( ', ', $options ) );
|
156 |
+
}
|
157 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/response.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class PHP_Merchant_Response
|
4 |
+
{
|
5 |
+
protected $is_successful = false;
|
6 |
+
protected $options = array();
|
7 |
+
protected $errors = array();
|
8 |
+
protected $response = '';
|
9 |
+
|
10 |
+
public function __construct( $response_str ) {
|
11 |
+
$this->response = $response_str;
|
12 |
+
}
|
13 |
+
|
14 |
+
public function is_successful() {
|
15 |
+
return $this->is_successful;
|
16 |
+
}
|
17 |
+
|
18 |
+
public function get( $name ) {
|
19 |
+
if ( ! isset( $this->options[$name] ) )
|
20 |
+
return null;
|
21 |
+
return $this->options[$name];
|
22 |
+
}
|
23 |
+
|
24 |
+
public function get_response_string() {
|
25 |
+
return $this->response;
|
26 |
+
}
|
27 |
+
|
28 |
+
public function get_errors() {
|
29 |
+
return $this->errors;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function has_errors() {
|
33 |
+
return ! empty( $this->errors );
|
34 |
+
}
|
35 |
+
|
36 |
+
public function get_error() {
|
37 |
+
return empty( $this->errors ) ? false : $this->errors[0];
|
38 |
+
}
|
39 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-digital-goods.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( 'paypal-express-checkout.php' );
|
4 |
+
require_once( 'paypal-express-checkout-response.php' );
|
5 |
+
|
6 |
+
class PHP_Merchant_Paypal_Digital_Goods extends PHP_Merchant_Paypal_Express_Checkout
|
7 |
+
{
|
8 |
+
public function __construct( $options = array() ) {
|
9 |
+
parent::__construct( $options );
|
10 |
+
}
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Creates and returns the payment component of a PayPal Digital Goods NVP API request.
|
14 |
+
*
|
15 |
+
* PayPal requires the category component for all items in a digital goods purchase to be set as Digital.
|
16 |
+
* This function specifies that all goods are digital, then calls @see parent::add_payment() to create
|
17 |
+
* the rest of the API request (which is the same as a vanilla Express Checkout request).
|
18 |
+
*
|
19 |
+
* @uses parent::add_payment() to create non digital goods components of the request.
|
20 |
+
* @return Array An array of name value pairs for each element representing a payment in a PayPal Digital Goods NVP API request.
|
21 |
+
*/
|
22 |
+
protected function add_payment( $action ) {
|
23 |
+
$request = parent::add_payment( $action );
|
24 |
+
|
25 |
+
// Make sure PayPal knows all goods are digital
|
26 |
+
for( $i = 0; $i < count( $this->options['items'] ); $i++ ) {
|
27 |
+
$request += array( "L_PAYMENTREQUEST_0_ITEMCATEGORY{$i}" => 'Digital' );
|
28 |
+
}
|
29 |
+
|
30 |
+
return $request;
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* For Digital Goods purchases, PayPal requires the PAYMENTREQUEST_n_ITEMAMT. This function sets the 'items' flag to required
|
35 |
+
* then calls @see parent::setup_purchase() to initiate an Express Checkout payment.
|
36 |
+
*
|
37 |
+
* @uses self::requires() to flag 'items' as required
|
38 |
+
* @uses parent::setup_purchase() to create and make the request.
|
39 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response An object containing the details of PayPal's response to the request.
|
40 |
+
*/
|
41 |
+
public function setup_purchase( $options = array(), $action = 'Sale' ) {
|
42 |
+
return parent::setup_purchase( $options, $action );
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* For Digital Goods purchases, PayPal requires the PAYMENTREQUEST_n_ITEMAMT. This function sets the 'items' flag to required
|
47 |
+
* then calls @see parent::setup_purchase() to complete the payment.
|
48 |
+
*
|
49 |
+
* @uses self::requires() to flag 'items' as required
|
50 |
+
* @uses parent::setup_purchase() to create and make the request.
|
51 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response An object containing the details of PayPal's response to the request.
|
52 |
+
*/
|
53 |
+
public function purchase( $options = array(), $action = 'Sale' ) {
|
54 |
+
return parent::purchase( $options, $action );
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
/**
|
59 |
+
* The Javascript to invoke the digital goods in context checkout process.
|
60 |
+
*
|
61 |
+
* No need to call this function manually, required scripts are automatically printed with @see print_buy_buttion().
|
62 |
+
* If you do print this script manually, print it after the button in the DOM to ensure the
|
63 |
+
* click event is properly hooked.
|
64 |
+
*/
|
65 |
+
public function get_script( $args = array() ){
|
66 |
+
|
67 |
+
if( empty( $args['element_id'] ) )
|
68 |
+
$args['element_id'] = 'paypal-submit';
|
69 |
+
|
70 |
+
$dg_script = '<script src ="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>'
|
71 |
+
. '<script>'
|
72 |
+
. 'var dg = new PAYPAL.apps.DGFlow({'
|
73 |
+
. 'trigger: "' . $args['element_id'] . '"' // the ID of the HTML element which calls setExpressCheckout
|
74 |
+
. '}); </script>';
|
75 |
+
|
76 |
+
return $dg_script;
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout-response.php
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class PHP_Merchant_Paypal_Express_Checkout_Response extends PHP_Merchant_Paypal_Response
|
3 |
+
{
|
4 |
+
public function __construct( $response_str ) {
|
5 |
+
parent::__construct( $response_str );
|
6 |
+
$p =& $this->params;
|
7 |
+
|
8 |
+
// more readable checkout status
|
9 |
+
if ( isset( $p['CHECKOUTSTATUS'] ) )
|
10 |
+
switch ( $p['CHECKOUTSTATUS'] ) {
|
11 |
+
case 'PaymentActionNotInitiated':
|
12 |
+
$this->options['checkout_status'] = 'Not-Initiated';
|
13 |
+
break;
|
14 |
+
|
15 |
+
case 'PaymentActionFailed':
|
16 |
+
$this->options['checkout_status'] = 'Failed';
|
17 |
+
break;
|
18 |
+
|
19 |
+
case 'PaymentActionInProgress':
|
20 |
+
$this->options['checkout_status'] = 'In-Progress';
|
21 |
+
break;
|
22 |
+
|
23 |
+
case 'PaymentCompleted':
|
24 |
+
$this->options['checkout_status'] = 'Completed';
|
25 |
+
break;
|
26 |
+
|
27 |
+
default:
|
28 |
+
$this->options['checkout_status'] = $p['CHECKOUTSTATUS'];
|
29 |
+
break;
|
30 |
+
}
|
31 |
+
|
32 |
+
if ( isset( $p['PAYMENTINFO_0_PAYMENTSTATUS'] ) )
|
33 |
+
$this->options['payment_status'] = $p['PAYMENTINFO_0_PAYMENTSTATUS'];
|
34 |
+
|
35 |
+
if ( isset( $p['PAYMENTINFO_0_TRANSACTIONID'] ) )
|
36 |
+
$this->options['transaction_id'] = $p['PAYMENTINFO_0_TRANSACTIONID'];
|
37 |
+
|
38 |
+
$this->options += phpme_map( $p, array(
|
39 |
+
'currency' => 'PAYMENTREQUEST_0_CURRENCYCODE',
|
40 |
+
'total' => 'PAYMENTREQUEST_0_AMT', // alias for "amount"
|
41 |
+
'amount' => 'PAYMENTREQUEST_0_AMT',
|
42 |
+
'subtotal' => 'PAYMENTREQUEST_0_ITEMAMT',
|
43 |
+
'shipping' => 'PAYMENTREQUEST_0_SHIPPINGAMT',
|
44 |
+
'handling' => 'PAYMENTREQUEST_0_HANDLINGAMT',
|
45 |
+
'tax' => 'PAYMENTREQUEST_0_TAXAMT',
|
46 |
+
'description' => 'PAYMENTREQUEST_0_DESC',
|
47 |
+
'invoice' => 'PAYMENTREQUEST_0_INVNUM',
|
48 |
+
'notify_url' => 'PAYMENTREQUEST_0_NOTIFYURL',
|
49 |
+
'shipping_discount' => 'PAYMENTREQUEST_0_SHIPDISCAMT',
|
50 |
+
) );
|
51 |
+
|
52 |
+
$items = array();
|
53 |
+
$i = 0;
|
54 |
+
while ( isset( $p["L_PAYMENTREQUEST_0_NAME{$i}"] ) ) {
|
55 |
+
$items[] = phpme_map( $p, array(
|
56 |
+
'name' => "L_PAYMENTREQUEST_0_NAME{$i}",
|
57 |
+
'description' => "L_PAYMENTREQUEST_0_DESC{$i}",
|
58 |
+
'amount' => "L_PAYMENTREQUEST_0_AMT{$i}",
|
59 |
+
'quantity' => "L_PAYMENTREQUEST_0_QTY{$i}",
|
60 |
+
'tax' => "L_PAYMENTREQUEST_0_TAXAMT{$i}",
|
61 |
+
), 'Object' );
|
62 |
+
|
63 |
+
$i ++;
|
64 |
+
}
|
65 |
+
|
66 |
+
$this->options['items'] = $items;
|
67 |
+
|
68 |
+
if ( isset( $p['PAYERID'] ) )
|
69 |
+
$this->options['payer'] = phpme_map( $p, array(
|
70 |
+
'email' => 'EMAIL',
|
71 |
+
'id' => 'PAYERID',
|
72 |
+
'status' => 'PAYERSTATUS',
|
73 |
+
'shipping_status' => 'ADDRESSSTATUS',
|
74 |
+
'first_name' => 'FIRSTNAME',
|
75 |
+
'last_name' => 'LASTNAME',
|
76 |
+
'country' => 'COUNTRYCODE',
|
77 |
+
), 'Object' );
|
78 |
+
|
79 |
+
if ( isset( $p['SHIPTONAME'] ) )
|
80 |
+
$this->options['shipping_address'] = phpme_map( $p, array(
|
81 |
+
'name' => 'SHIPTONAME',
|
82 |
+
'street' => 'SHIPTOSTREET',
|
83 |
+
'street2' => 'SHIPTOSTREET2',
|
84 |
+
'city' => 'SHIPTOCITY',
|
85 |
+
'state' => 'SHIPTOSTATE',
|
86 |
+
'zip' => 'SHIPTOZIP',
|
87 |
+
'country_code' => 'SHIPTOCOUNTRYCODE',
|
88 |
+
'country' => 'SHIPTOCOUNTRYNAME',
|
89 |
+
'phone' => 'SHIPTOPHONENUM',
|
90 |
+
) );
|
91 |
+
}
|
92 |
+
|
93 |
+
public function is_checkout_not_initiated() {
|
94 |
+
return $this->get( 'checkout_status' ) == 'Not-Initiated';
|
95 |
+
}
|
96 |
+
|
97 |
+
public function is_checkout_failed() {
|
98 |
+
return $this->get( 'checkout_status' ) == 'Failed';
|
99 |
+
}
|
100 |
+
|
101 |
+
public function is_checkout_in_progress() {
|
102 |
+
return $this->get( 'checkout_status' ) == 'In-Progress';
|
103 |
+
}
|
104 |
+
|
105 |
+
public function is_checkout_completed() {
|
106 |
+
return $this->get( 'checkout_status' ) == 'Completed';
|
107 |
+
}
|
108 |
+
|
109 |
+
public function is_payment_completed() {
|
110 |
+
return in_array( $this->get( 'payment_status' ), array( 'Completed', 'Processed' ) );
|
111 |
+
}
|
112 |
+
|
113 |
+
public function is_payment_pending() {
|
114 |
+
return $this->get( 'payment_status' ) == 'Pending';
|
115 |
+
}
|
116 |
+
|
117 |
+
public function is_payment_refunded() {
|
118 |
+
return $this->get( 'payment_status' ) == 'Refunded';
|
119 |
+
}
|
120 |
+
|
121 |
+
public function is_payment_denied() {
|
122 |
+
return $this->get( 'payment_status' ) == 'Denied';
|
123 |
+
}
|
124 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php
ADDED
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( 'paypal.php' );
|
3 |
+
require_once( 'paypal-express-checkout-response.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout extends PHP_Merchant_Paypal
|
6 |
+
{
|
7 |
+
public function __construct( $options = array() ) {
|
8 |
+
parent::__construct( $options );
|
9 |
+
}
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Add the payment details to the PayPal request
|
13 |
+
*
|
14 |
+
* @param array $action
|
15 |
+
* @return array
|
16 |
+
* @since 3.9
|
17 |
+
*/
|
18 |
+
protected function add_payment( $action ) {
|
19 |
+
|
20 |
+
// Total Payment details
|
21 |
+
$request = array(
|
22 |
+
'PAYMENTREQUEST_0_AMT' => $this->format( $this->options['amount'] ),
|
23 |
+
'PAYMENTREQUEST_0_CURRENCYCODE' => $this->options['currency'],
|
24 |
+
'PAYMENTREQUEST_0_PAYMENTACTION' => $action,
|
25 |
+
);
|
26 |
+
|
27 |
+
if ( $action === 'Sale' ) {
|
28 |
+
$request['PAYMENTREQUEST_0_ALLOWEDPAYMENTMETHOD'] = 'InstantPaymentOnly';
|
29 |
+
}
|
30 |
+
|
31 |
+
foreach ( array( 'subtotal', 'shipping', 'handling', 'tax' ) as $key ) {
|
32 |
+
if ( isset( $this->options[$key] ) ) {
|
33 |
+
$this->options[$key] = $this->format( $this->options[$key] );
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
$request += phpme_map( $this->options, array(
|
38 |
+
'PAYMENTREQUEST_0_ITEMAMT' => 'subtotal',
|
39 |
+
'PAYMENTREQUEST_0_SHIPPINGAMT' => 'shipping',
|
40 |
+
'PAYMENTREQUEST_0_HANDLINGAMT' => 'handling',
|
41 |
+
'PAYMENTREQUEST_0_TAXAMT' => 'tax',
|
42 |
+
'PAYMENTREQUEST_0_DESC' => 'description',
|
43 |
+
'PAYMENTREQUEST_0_INVNUM' => 'invoice',
|
44 |
+
'PAYMENTREQUEST_0_NOTIFYURL' => 'notify_url',
|
45 |
+
'L_BILLINGTYPE0' => 'billing_type',
|
46 |
+
'L_BILLINGAGREEMENTDESCRIPTION0' => 'billing_description',
|
47 |
+
) );
|
48 |
+
|
49 |
+
$subtotal = 0;
|
50 |
+
|
51 |
+
// Shopping Cart details
|
52 |
+
$i = 0;
|
53 |
+
foreach ( $this->options['items'] as $item ) {
|
54 |
+
// Options Fields
|
55 |
+
$item_optionals = array(
|
56 |
+
'description' => "L_PAYMENTREQUEST_0_DESC{$i}",
|
57 |
+
'tax' => "L_PAYMENTREQUEST_0_TAXAMT{$i}",
|
58 |
+
'url' => "L_PAYMENTREQUEST_0_ITEMURL{$i}",
|
59 |
+
'number' => "L_PAYMENTREQUEST_0_NUMBER{$i}",
|
60 |
+
);
|
61 |
+
|
62 |
+
// Format Amount Field
|
63 |
+
$item['amount'] = $this->format( $item['amount'] );
|
64 |
+
|
65 |
+
// Required Fields
|
66 |
+
$request += phpme_map( $item, array(
|
67 |
+
"L_PAYMENTREQUEST_0_NAME{$i}" => 'name',
|
68 |
+
"L_PAYMENTREQUEST_0_AMT{$i}" => 'amount',
|
69 |
+
"L_PAYMENTREQUEST_0_QTY{$i}" => 'quantity',
|
70 |
+
) );
|
71 |
+
|
72 |
+
// No Shipping Field
|
73 |
+
if ( isset( $this->options['no_shipping'] ) ) {
|
74 |
+
$request["L_PAYMENTREQUEST_0_ITEMCATEGORY{$i}"] = 'DIGITAL';
|
75 |
+
}
|
76 |
+
|
77 |
+
foreach ( $item_optionals as $key => $param ) {
|
78 |
+
if ( ! empty( $this->options['items'][$i][$key] ) )
|
79 |
+
if ( $key == 'tax' ) {
|
80 |
+
$request[$param] = $this->format( $this->options['items'][$i][$key] );
|
81 |
+
} else {
|
82 |
+
$request[$param] = $this->options['items'][$i][$key];
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
$i ++;
|
87 |
+
}
|
88 |
+
|
89 |
+
return $request;
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Add a shipping address to the PayPal request
|
94 |
+
*
|
95 |
+
* @return array
|
96 |
+
* @since 3.9
|
97 |
+
*/
|
98 |
+
protected function add_address() {
|
99 |
+
$map = array(
|
100 |
+
'name' => 'PAYMENTREQUEST_0_SHIPTONAME',
|
101 |
+
'street' => 'PAYMENTREQUEST_0_SHIPTOSTREET',
|
102 |
+
'street2' => 'PAYMENTREQUEST_0_SHIPTOSTREET2',
|
103 |
+
'city' => 'PAYMENTREQUEST_0_SHIPTOCITY',
|
104 |
+
'state' => 'PAYMENTREQUEST_0_SHIPTOSTATE',
|
105 |
+
'zip' => 'PAYMENTREQUEST_0_SHIPTOZIP',
|
106 |
+
'country' => 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE',
|
107 |
+
'phone' => 'PAYMENTREQUEST_0_SHIPTOPHONENUM',
|
108 |
+
);
|
109 |
+
|
110 |
+
$request = array();
|
111 |
+
|
112 |
+
foreach ( $map as $key => $param ) {
|
113 |
+
if ( ! empty( $this->options['shipping_address'][$key] ) ) {
|
114 |
+
$request[$param] = $this->options['shipping_address'][$key];
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
return $request;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Build the request array
|
123 |
+
*
|
124 |
+
* @param string $action
|
125 |
+
* @param array $options
|
126 |
+
* @return array
|
127 |
+
* @since 3.9
|
128 |
+
*/
|
129 |
+
protected function build_checkout_request( $action, $options = array() ) {
|
130 |
+
$request = array();
|
131 |
+
|
132 |
+
if ( isset( $this->options['return_url'] ) ) {
|
133 |
+
$request['RETURNURL'] = $this->options['return_url'];
|
134 |
+
}
|
135 |
+
|
136 |
+
if ( isset( $this->options['cancel_url'] ) ) {
|
137 |
+
$request['CANCELURL'] = $this->options['cancel_url'];
|
138 |
+
}
|
139 |
+
|
140 |
+
// Common Fields
|
141 |
+
$request += phpme_map( $this->options, array(
|
142 |
+
'AMT' => 'amount',
|
143 |
+
'MAXAMT' => 'max_amount',
|
144 |
+
'SOLUTIONTYPE' => 'solution_type',
|
145 |
+
'ALLOWNOTE' => 'allow_note',
|
146 |
+
'ADDROVERRIDE' => 'address_override',
|
147 |
+
'TOKEN' => 'token',
|
148 |
+
'PAYERID' => 'payer_id',
|
149 |
+
'TRANSACTIONID'=> 'transaction_id',
|
150 |
+
'AUTHORIZATIONID'=> 'authorization_id',
|
151 |
+
'MSGSUBID' => 'message_id',
|
152 |
+
'INVOICEID' => 'invoice',
|
153 |
+
) );
|
154 |
+
|
155 |
+
// Cart Customization Fields
|
156 |
+
$request += phpme_map( $this->options, array(
|
157 |
+
'LOGOIMG' => 'cart_logo',
|
158 |
+
'CARTBORDERCOLOR' => 'cart_border',
|
159 |
+
) );
|
160 |
+
|
161 |
+
// RefundTransaction Fields
|
162 |
+
$request += phpme_map( $this->options, array(
|
163 |
+
'REFUNDTYPE' => 'refund_type',
|
164 |
+
'REFUNDSOURCE' => 'refund_source',
|
165 |
+
'REFUNDADVICE' => 'refund_advice',
|
166 |
+
) );
|
167 |
+
|
168 |
+
// DoCapture Fields
|
169 |
+
$request += phpme_map( $this->options, array(
|
170 |
+
'COMPLETETYPE' => 'complete_type',
|
171 |
+
) );
|
172 |
+
|
173 |
+
if ( ! empty( $this->options['shipping_address'] ) ) {
|
174 |
+
$request += $this->add_address();
|
175 |
+
}
|
176 |
+
|
177 |
+
if ( isset( $this->options['no_shipping'] ) ) {
|
178 |
+
$request['NOSHIPPING'] = '1';
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( $action != false ) {
|
182 |
+
$request += $this->add_payment( $action );
|
183 |
+
}
|
184 |
+
|
185 |
+
// BN Code
|
186 |
+
$request['BUTTONSOURCE'] = 'WPECOM_ECM';
|
187 |
+
|
188 |
+
return $request;
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Gateway implementation for SetExpressCheckout
|
193 |
+
*
|
194 |
+
* @param array $options
|
195 |
+
* @param string $action
|
196 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
197 |
+
* @since 3.9
|
198 |
+
*/
|
199 |
+
public function setup_purchase( $options = array(), $action = 'Sale' ) {
|
200 |
+
$this->options = array_merge( $this->options, $options );
|
201 |
+
$this->requires( array( 'amount', 'return_url', 'cancel_url' ) );
|
202 |
+
$request = $this->build_checkout_request( $action, $options );
|
203 |
+
|
204 |
+
$response_str = $this->commit( 'SetExpressCheckout', $request );
|
205 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Gateway impelementation for GetExpressCheckoutDetails
|
210 |
+
*
|
211 |
+
* @param string $token Authentication token returned by the SetExpressCheckout operation
|
212 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
213 |
+
* @since 3.9
|
214 |
+
*/
|
215 |
+
public function get_details_for( $token ) {
|
216 |
+
$request = array( 'TOKEN' => $token );
|
217 |
+
$response_str = $this->commit( 'GetExpressCheckoutDetails', $request );
|
218 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Gateway impelementation for GetTransactionDetails
|
223 |
+
*
|
224 |
+
* @param string $transaction_id Unique identifier of a transaction.
|
225 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
226 |
+
* @since 3.9
|
227 |
+
*/
|
228 |
+
public function get_transaction_details( $transaction_id ) {
|
229 |
+
$request = array( 'TRANSACTIONID' => $transaction_id );
|
230 |
+
$response_str = $this->commit( 'GetTransactionDetails', $request );
|
231 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Gateway implementation for DoExpressCheckout
|
236 |
+
*
|
237 |
+
* @param array $options
|
238 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
239 |
+
* @since 3.9
|
240 |
+
*/
|
241 |
+
public function purchase( $options = array(), $action = 'Sale' ) {
|
242 |
+
$this->options = array_merge( $this->options, $options );
|
243 |
+
$this->requires( array( 'amount', 'token', 'payer_id' ) );
|
244 |
+
$request = $this->build_checkout_request( $action, $options );
|
245 |
+
|
246 |
+
$response_str = $this->commit( 'DoExpressCheckoutPayment', $request );
|
247 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Gateway implementation for DoAuthorize
|
252 |
+
*
|
253 |
+
* @param array $options
|
254 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
255 |
+
* @since 3.9
|
256 |
+
*/
|
257 |
+
public function authorize( $options = array() ) {
|
258 |
+
$this->options = array_merge( $this->options, $options );
|
259 |
+
$this->requires( array( 'amount', 'token', 'transaction_id' ) );
|
260 |
+
$request = $this->build_checkout_request( false, $options );
|
261 |
+
|
262 |
+
$response_str = $this->commit( 'DoAuthorization', $request );
|
263 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Gateway implementation for DoCapture
|
268 |
+
*
|
269 |
+
* @param array $options
|
270 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
271 |
+
* @since 3.9
|
272 |
+
*/
|
273 |
+
public function capture( $options = array() ) {
|
274 |
+
$this->options = array_merge( $this->options, $options );
|
275 |
+
$this->requires( array( 'amount', 'complete_type', 'authorization_id' ) );
|
276 |
+
$request = $this->build_checkout_request( false, $options );
|
277 |
+
|
278 |
+
$response_str = $this->commit( 'DoCapture', $request );
|
279 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Gateway implementation for DoVoid
|
284 |
+
*
|
285 |
+
* @param array $options
|
286 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
287 |
+
* @since 3.9
|
288 |
+
*/
|
289 |
+
public function void( $options = array() ) {
|
290 |
+
$this->options = array_merge( $this->options, $options );
|
291 |
+
$this->requires( array( 'authorization_id' ) );
|
292 |
+
$request = $this->build_checkout_request( false, $options );
|
293 |
+
|
294 |
+
$response_str = $this->commit( 'DoVoid', $request );
|
295 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Gateway implementation for RefundTransaction
|
300 |
+
*
|
301 |
+
* @param array $options
|
302 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
303 |
+
* @since 3.9
|
304 |
+
*/
|
305 |
+
public function credit( $options = array() ) {
|
306 |
+
$this->options = array_merge( $this->options, $options );
|
307 |
+
|
308 |
+
// Required Fields
|
309 |
+
$this->requires( array( 'message_id', 'invoice' ) );
|
310 |
+
|
311 |
+
// Conditionally required fields (one field at least is set)
|
312 |
+
$this->conditional_requires( array( 'payer_id', 'transaction_id' ) );
|
313 |
+
|
314 |
+
// Amount is required if the refund is partial
|
315 |
+
if ( strtolower( $this->options['refund_type'] ) === 'partial' ) {
|
316 |
+
$this->requires( array( 'amount' ) );
|
317 |
+
}
|
318 |
+
|
319 |
+
$request = $this->build_checkout_request( false, $options );
|
320 |
+
|
321 |
+
$response_str = $this->commit( 'RefundTransaction', $request );
|
322 |
+
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
323 |
+
}
|
324 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-ipn.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class PHP_Merchant_Paypal_IPN
|
4 |
+
{
|
5 |
+
const SANDBOX_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
|
6 |
+
const LIVE_URL = 'https://www.paypal.com/cgi-bin/webscr';
|
7 |
+
|
8 |
+
private $verified = null;
|
9 |
+
private $params = array();
|
10 |
+
private $data = array();
|
11 |
+
private $url;
|
12 |
+
protected $http = false;
|
13 |
+
|
14 |
+
public function __construct( $data = false, $test = false, &$http = false ) {
|
15 |
+
if ( $http ) {
|
16 |
+
$this->http = $http;
|
17 |
+
} else {
|
18 |
+
require_once( dirname( __FILE__ ) . '/../common/http-curl.php' );
|
19 |
+
$this->http = new PHP_Merchant_HTTP_CURL();
|
20 |
+
}
|
21 |
+
|
22 |
+
if ( $data === false ) {
|
23 |
+
$data = $_POST;
|
24 |
+
}
|
25 |
+
|
26 |
+
$this->params = $data;
|
27 |
+
|
28 |
+
$this->url = $test ? self::SANDBOX_URL : self::LIVE_URL;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function is_verified() {
|
32 |
+
if ( is_null( $this->verified ) ) {
|
33 |
+
$verifying_data = array( 'cmd' => '_notify-validate' );
|
34 |
+
$verifying_data += $this->params;
|
35 |
+
|
36 |
+
$verifying_response = $this->http->post( $this->url, $verifying_data );
|
37 |
+
|
38 |
+
if ( $verifying_response == 'VERIFIED' ) {
|
39 |
+
$this->verified = true;
|
40 |
+
|
41 |
+
/*
|
42 |
+
|
43 |
+
There's some confusing stuff regarding payment information:
|
44 |
+
mc_gross = total amount = total tax + item subtotal + total shipping
|
45 |
+
mc_gross_$i = item amount * quantity + item shipping
|
46 |
+
|
47 |
+
See: https://www.x.com/developers/paypal/forums/ipn/pdt/mcgross-does-not-include-tax-right
|
48 |
+
|
49 |
+
IPN only returns the item gross amount, so the single item amount will need to be
|
50 |
+
calculated so that the $this->data array is consistent with other Paypal Response classes.
|
51 |
+
|
52 |
+
*/
|
53 |
+
$this->data = phpme_map( $this->params, array(
|
54 |
+
'transaction_id' => 'txn_id',
|
55 |
+
'transaction_type' => 'txn_type',
|
56 |
+
'handling' => 'mc_handling',
|
57 |
+
'shipping' => 'mc_shipping',
|
58 |
+
'exchange_rate' => 'exchange_rate',
|
59 |
+
'invoice' => 'invoice',
|
60 |
+
'currency' => 'mc_currency',
|
61 |
+
'fee' => 'mc_fee',
|
62 |
+
'total' => 'mc_gross',
|
63 |
+
'amount' => 'mc_gross',
|
64 |
+
'payment_status' => 'payment_status',
|
65 |
+
'tax' => 'tax',
|
66 |
+
) );
|
67 |
+
|
68 |
+
// Strangely, Canceled_Reversal in IPN response is actually Canceled-Reversal in normal Paypal Express responses.
|
69 |
+
// Need to change the underscore to hyphen to maintain consistency
|
70 |
+
$this->data['payment_status'] = str_replace( '_', '-', $this->data['payment_status'] );
|
71 |
+
|
72 |
+
$i = 1;
|
73 |
+
$this->data['items'] = array();
|
74 |
+
while ( isset( $this->params["item_name{$i}"] ) ) {
|
75 |
+
$item = phpme_map( $this->params, array(
|
76 |
+
'name' => "item_name{$i}",
|
77 |
+
'quantity' => "quantity{$i}",
|
78 |
+
) );
|
79 |
+
|
80 |
+
$item['shipping'] = $shipping = isset( $this->params["mc_shipping{$i}"] ) ? $this->params["mc_shipping{$i}"] : 0;
|
81 |
+
$item['handling'] = $handling = isset( $this->params["mc_handling{$i}"] ) ? $this->params["mc_handling{$i}"] : 0;
|
82 |
+
$item['amount'] = ( $this->params["mc_gross_{$i}"] - $shipping - $handling ) / $item['quantity'];
|
83 |
+
$this->data['items'][] = $item;
|
84 |
+
$i++;
|
85 |
+
}
|
86 |
+
|
87 |
+
$this->data['payer'] = phpme_map( $this->params, array(
|
88 |
+
'first_name' => 'first_name',
|
89 |
+
'last_name' => 'last_name',
|
90 |
+
'business_name' => 'payer_business_name',
|
91 |
+
'status' => 'payer_status',
|
92 |
+
'id' => 'payer_id',
|
93 |
+
'email' => 'payer_email',
|
94 |
+
) );
|
95 |
+
|
96 |
+
$this->data['address'] = phpme_map( $this->params, array(
|
97 |
+
'street' => 'address_street',
|
98 |
+
'zip' => 'address_zip',
|
99 |
+
'city' => 'address_city',
|
100 |
+
'state' => 'address_state',
|
101 |
+
'country' => 'address_country',
|
102 |
+
'country_code' => 'address_country_code',
|
103 |
+
'name' => 'address_name',
|
104 |
+
'status' => 'address_status',
|
105 |
+
'phone' => 'contact_phone',
|
106 |
+
) );
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
return $this->verified;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function get( $item ) {
|
114 |
+
return isset( $this->data[$item] ) ? $this->data[$item] : null;
|
115 |
+
}
|
116 |
+
|
117 |
+
public function get_data() {
|
118 |
+
return $this->data;
|
119 |
+
}
|
120 |
+
|
121 |
+
public function is_payment_completed() {
|
122 |
+
return in_array( $this->get( 'payment_status' ), array( 'Completed', 'Processed' ) );
|
123 |
+
}
|
124 |
+
|
125 |
+
public function is_payment_pending() {
|
126 |
+
return $this->get( 'payment_status' ) == 'Pending';
|
127 |
+
}
|
128 |
+
|
129 |
+
public function is_payment_refunded() {
|
130 |
+
return in_array( $this->get( 'payment_status' ), array( 'Refunded', 'Reversed' ) );
|
131 |
+
}
|
132 |
+
|
133 |
+
public function is_payment_refund_pending() {
|
134 |
+
return $this->is_payment_pending() && isset( $this->params['reason_code'] ) && $this->params['reason_code'] == 'refund';
|
135 |
+
}
|
136 |
+
|
137 |
+
public function is_payment_denied() {
|
138 |
+
return $this->get( 'payment_status' ) == 'Denied';
|
139 |
+
}
|
140 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-pro-response.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class PHP_Merchant_Paypal_Pro_Response extends PHP_Merchant_Paypal_Response
|
4 |
+
{
|
5 |
+
public function __construct( $response_str ) {
|
6 |
+
parent::__construct( $response_str );
|
7 |
+
$p =& $this->params;
|
8 |
+
|
9 |
+
if ( isset( $p['PAYMENTSTATUS'] ) )
|
10 |
+
$this->options['payment_status'] = $p['PAYMENTSTATUS'];
|
11 |
+
|
12 |
+
if ( isset( $p['TRANSACTIONID'] ) )
|
13 |
+
$this->options['transaction_id'] = $p['TRANSACTIONID'];
|
14 |
+
|
15 |
+
$this->options += phpme_map( $p, array(
|
16 |
+
'currency' => 'CURRENCYCODE',
|
17 |
+
'total' => 'AMT', // alias for "amount"
|
18 |
+
'amount' => 'AMT',
|
19 |
+
'subtotal' => 'ITEMAMT',
|
20 |
+
'shipping' => 'SHIPPINGAMT',
|
21 |
+
'handling' => 'HANDLINGAMT',
|
22 |
+
'tax' => 'TAXAMT',
|
23 |
+
'description' => 'DESC',
|
24 |
+
'invoice' => 'INVNUM',
|
25 |
+
'notify_url' => 'NOTIFYURL',
|
26 |
+
'shipping_discount' => 'SHIPDISCAMT',
|
27 |
+
) );
|
28 |
+
|
29 |
+
if ( isset( $p['PAYERID'] ) )
|
30 |
+
$this->options['payer'] = phpme_map( $p, array(
|
31 |
+
'email' => 'EMAIL',
|
32 |
+
'id' => 'PAYERID',
|
33 |
+
'status' => 'PAYERSTATUS',
|
34 |
+
'shipping_status' => 'ADDRESSSTATUS',
|
35 |
+
'first_name' => 'FIRSTNAME',
|
36 |
+
'last_name' => 'LASTNAME',
|
37 |
+
'country' => 'COUNTRYCODE',
|
38 |
+
), 'Object' );
|
39 |
+
|
40 |
+
if ( isset( $p['SHIPTONAME'] ) )
|
41 |
+
$this->options['shipping_address'] = phpme_map( $p, array(
|
42 |
+
'name' => 'SHIPTONAME',
|
43 |
+
'street' => 'SHIPTOSTREET',
|
44 |
+
'street2' => 'SHIPTOSTREET2',
|
45 |
+
'city' => 'SHIPTOCITY',
|
46 |
+
'state' => 'SHIPTOSTATE',
|
47 |
+
'zip' => 'SHIPTOZIP',
|
48 |
+
'country_code' => 'SHIPTOCOUNTRYCODE',
|
49 |
+
'country' => 'SHIPTOCOUNTRYNAME',
|
50 |
+
'phone' => 'SHIPTOPHONENUM',
|
51 |
+
) );
|
52 |
+
}
|
53 |
+
|
54 |
+
public function is_payment_completed() {
|
55 |
+
return in_array( $this->get( 'payment_status' ), array( 'Completed', 'Processed' ) );
|
56 |
+
}
|
57 |
+
|
58 |
+
public function is_payment_pending() {
|
59 |
+
return $this->get( 'payment_status' ) == 'Pending';
|
60 |
+
}
|
61 |
+
|
62 |
+
public function is_payment_refunded() {
|
63 |
+
return $this->get( 'payment_status' ) == 'Refunded';
|
64 |
+
}
|
65 |
+
|
66 |
+
public function is_payment_denied() {
|
67 |
+
return $this->get( 'payment_status' ) == 'Denied';
|
68 |
+
}}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-pro.php
ADDED
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( 'paypal.php' );
|
3 |
+
require_once( 'paypal-pro-response.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Pro extends PHP_Merchant_Paypal
|
6 |
+
{
|
7 |
+
const API_VERSION = '117.0';
|
8 |
+
const SANDBOX_URL = 'https://api-3t.sandbox.paypal.com/nvp';
|
9 |
+
const LIVE_URL = 'https://api-3t.paypal.com/nvp';
|
10 |
+
|
11 |
+
public function __construct( $options = array() ) {
|
12 |
+
parent::__construct( $options );
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Add the payment details to the PayPal request
|
17 |
+
*
|
18 |
+
* @param array $action
|
19 |
+
* @return array
|
20 |
+
* @since 3.9
|
21 |
+
*/
|
22 |
+
protected function add_payment( $action ) {
|
23 |
+
|
24 |
+
// Total Payment details
|
25 |
+
$request = array(
|
26 |
+
'amount' => $this->format( $this->options['amount'] ),
|
27 |
+
'currency_code' => $this->options['currency'],
|
28 |
+
'paymentaction' => $action,
|
29 |
+
);
|
30 |
+
|
31 |
+
foreach ( array( 'subtotal', 'shipping', 'handling', 'tax' ) as $key ) {
|
32 |
+
if ( isset( $this->options[$key] ) ) {
|
33 |
+
$this->options[$key] = $this->format( $this->options[$key] );
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
$request += phpme_map( $this->options, array(
|
38 |
+
'subtotal' => 'subtotal',
|
39 |
+
'shipping' => 'shipping',
|
40 |
+
'handling' => 'handling',
|
41 |
+
'tax' => 'tax',
|
42 |
+
'item_name' => 'description',
|
43 |
+
'invoice' => 'invoice',
|
44 |
+
'notify_url' => 'notify_url',
|
45 |
+
) );
|
46 |
+
|
47 |
+
$subtotal = 0;
|
48 |
+
|
49 |
+
// Shopping Cart details
|
50 |
+
$i = 0;
|
51 |
+
foreach ( $this->options['items'] as $item ) {
|
52 |
+
// Options Fields
|
53 |
+
$item_optionals = array(
|
54 |
+
'tax' => "tax{$i}",
|
55 |
+
);
|
56 |
+
|
57 |
+
// Format Amount Field
|
58 |
+
$item['amount'] = $this->format( $item['amount'] );
|
59 |
+
|
60 |
+
// Required Fields
|
61 |
+
$request += phpme_map( $item, array(
|
62 |
+
"item_name{$i}" => 'name',
|
63 |
+
"amount{$i}" => 'amount',
|
64 |
+
"quantity{$i}" => 'quantity',
|
65 |
+
) );
|
66 |
+
|
67 |
+
foreach ( $item_optionals as $key => $param ) {
|
68 |
+
if ( ! empty( $this->options['items'][$i][$key] ) )
|
69 |
+
if ( $key == 'tax' ) {
|
70 |
+
$request[$param] = $this->format( $this->options['items'][$i][$key] );
|
71 |
+
} else {
|
72 |
+
$request[$param] = $this->options['items'][$i][$key];
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
$i ++;
|
77 |
+
}
|
78 |
+
|
79 |
+
return $request;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Add a shipping address to the PayPal request
|
84 |
+
*
|
85 |
+
* @return array
|
86 |
+
* @since 3.9
|
87 |
+
*/
|
88 |
+
protected function add_address() {
|
89 |
+
$map = array(
|
90 |
+
'name' => 'first_name',
|
91 |
+
'street' => 'address1',
|
92 |
+
'street2' => 'address2',
|
93 |
+
'city' => 'city',
|
94 |
+
'state' => 'state',
|
95 |
+
'zip' => 'zip',
|
96 |
+
'country' => 'country',
|
97 |
+
'phone' => 'night_phone_1',
|
98 |
+
);
|
99 |
+
|
100 |
+
$request = array();
|
101 |
+
|
102 |
+
foreach ( $map as $key => $param ) {
|
103 |
+
if ( ! empty( $this->options['shipping_address'][$key] ) ) {
|
104 |
+
$request[$param] = $this->options['shipping_address'][$key];
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
return $request;
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Add a Billing address to the PayPal request
|
113 |
+
*
|
114 |
+
* @return array
|
115 |
+
* @since 3.9
|
116 |
+
*/
|
117 |
+
protected function add_billing_address() {
|
118 |
+
$map = array(
|
119 |
+
'name' => 'billing_first_name',
|
120 |
+
'street' => 'billing_address1',
|
121 |
+
'street2' => 'billing_address2',
|
122 |
+
'city' => 'billing_city',
|
123 |
+
'state' => 'billing_state',
|
124 |
+
'zip' => 'billing_zip',
|
125 |
+
'country' => 'billing_country',
|
126 |
+
'phone' => 'billing_night_phone_1',
|
127 |
+
);
|
128 |
+
|
129 |
+
$request = array();
|
130 |
+
|
131 |
+
foreach ( $map as $key => $param ) {
|
132 |
+
if ( ! empty( $this->options['billing_address'][$key] ) ) {
|
133 |
+
$request[$param] = $this->options['billing_address'][$key];
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
return $request;
|
138 |
+
}
|
139 |
+
/**
|
140 |
+
* Gateway implementation for BMCreateButton
|
141 |
+
*
|
142 |
+
* @param array $options
|
143 |
+
* @return PHP_Merchant_Paypal_Pro_Response
|
144 |
+
* @since 3.9
|
145 |
+
*/
|
146 |
+
public function createButton( $options = array() ) {
|
147 |
+
$this->options = array_merge( $this->options, $options );
|
148 |
+
$this->requires( array( 'amount', 'vendor', 'paymentaction', 'template' ) );
|
149 |
+
|
150 |
+
$request = $this->build_button_vars( $this->options );
|
151 |
+
$request['BUTTONCODE'] = 'TOKEN';
|
152 |
+
$request['BUTTONTYPE'] = 'PAYMENT';
|
153 |
+
$request['cmd'] = '_cart';
|
154 |
+
|
155 |
+
$response_str = $this->commit( 'BMCreateButton', $request );
|
156 |
+
return new PHP_Merchant_Paypal_Pro_Response( $response_str );
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Build the request array
|
161 |
+
*
|
162 |
+
* @param array $options
|
163 |
+
* @return array
|
164 |
+
* @since 3.9
|
165 |
+
*/
|
166 |
+
protected function build_button_vars( $options = array(), $action = 'sale' ) {
|
167 |
+
$request = array();
|
168 |
+
|
169 |
+
if ( isset( $this->options['return_url'] ) ) {
|
170 |
+
$request['return'] = $this->options['return_url'];
|
171 |
+
}
|
172 |
+
|
173 |
+
if ( isset( $this->options['cancel_url'] ) ) {
|
174 |
+
$request['cancel_return'] = $this->options['cancel_url'];
|
175 |
+
}
|
176 |
+
|
177 |
+
if ( isset( $this->options['notify_url'] ) ) {
|
178 |
+
$request['notify_url'] = $this->options['notify_url'];
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( $action != false ) {
|
182 |
+
$request += $this->add_payment( $action );
|
183 |
+
$request['display'] = '1';
|
184 |
+
}
|
185 |
+
|
186 |
+
if ( ! empty( $this->options['shipping_address'] ) ) {
|
187 |
+
$request += $this->add_address();
|
188 |
+
}
|
189 |
+
|
190 |
+
if ( ! empty( $this->options['billing_address'] ) ) {
|
191 |
+
$request += $this->add_billing_address();
|
192 |
+
}
|
193 |
+
|
194 |
+
if ( isset( $this->options['no_shipping'] ) ) {
|
195 |
+
$request['no_shipping'] = '1';
|
196 |
+
}
|
197 |
+
|
198 |
+
// Common Fields
|
199 |
+
$request += phpme_map( $this->options, array(
|
200 |
+
'amount' => 'amount',
|
201 |
+
'subtotal' => 'subtotal',
|
202 |
+
'tax' => 'tax',
|
203 |
+
'shipping' => 'shipping',
|
204 |
+
'paymentaction' => 'paymentaction',
|
205 |
+
'template' => 'template',
|
206 |
+
'address_override' => 'address_override',
|
207 |
+
'vendor' => 'merchant_email',
|
208 |
+
'invoice' => 'invoice',
|
209 |
+
'currency' => 'currency',
|
210 |
+
) );
|
211 |
+
|
212 |
+
$request = $this->add_sub( 'L_BUTTONVAR', $request );
|
213 |
+
|
214 |
+
return $request;
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Build the request array
|
219 |
+
*
|
220 |
+
* @param string $action
|
221 |
+
* @param array $options
|
222 |
+
* @return array
|
223 |
+
* @since 3.9
|
224 |
+
*/
|
225 |
+
function build_checkout_request( $action, $options = array() ) {
|
226 |
+
$request = array();
|
227 |
+
|
228 |
+
// Common Fields
|
229 |
+
$request += phpme_map( $this->options, array(
|
230 |
+
'AMT' => 'amount',
|
231 |
+
'MAXAMT' => 'max_amount',
|
232 |
+
'SOLUTIONTYPE' => 'solution_type',
|
233 |
+
'ALLOWNOTE' => 'allow_note',
|
234 |
+
'ADDROVERRIDE' => 'address_override',
|
235 |
+
'TOKEN' => 'token',
|
236 |
+
'PAYERID' => 'payer_id',
|
237 |
+
'TRANSACTIONID'=> 'transaction_id',
|
238 |
+
'AUTHORIZATIONID'=> 'authorization_id',
|
239 |
+
'MSGSUBID' => 'message_id',
|
240 |
+
'INVOICEID' => 'invoice',
|
241 |
+
) );
|
242 |
+
|
243 |
+
// RefundTransaction Fields
|
244 |
+
$request += phpme_map( $this->options, array(
|
245 |
+
'REFUNDTYPE' => 'refund_type',
|
246 |
+
'REFUNDSOURCE' => 'refund_source',
|
247 |
+
'REFUNDADVICE' => 'refund_advice',
|
248 |
+
) );
|
249 |
+
// BN Code
|
250 |
+
$request['BUTTONSOURCE'] = 'WPECOM_ECM';
|
251 |
+
|
252 |
+
return $request;
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Add a subline for the HTML variables array
|
257 |
+
*
|
258 |
+
* @param string $sub
|
259 |
+
* @param array $array
|
260 |
+
* @return array
|
261 |
+
* @since 3.9
|
262 |
+
*/
|
263 |
+
private function add_sub( $sub, $arr ) {
|
264 |
+
$request = array();
|
265 |
+
|
266 |
+
$i = 0;
|
267 |
+
foreach( $arr as $key=>$value) {
|
268 |
+
$request[$sub . $i] = $key . '=' . $value;
|
269 |
+
$i++;
|
270 |
+
}
|
271 |
+
|
272 |
+
return $request;
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Gateway implementation for "purchase" operation
|
277 |
+
*
|
278 |
+
* @param array $options
|
279 |
+
* @return PHP_Merchant_Paypal_Pro_Response
|
280 |
+
* @since 3.9
|
281 |
+
*/
|
282 |
+
public function purchase( $options = array(), $action = 'Sale' ) {
|
283 |
+
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* Gateway implementation for "authorize" operation
|
288 |
+
*
|
289 |
+
* @param array $options
|
290 |
+
* @return PHP_Merchant_Paypal_Pro_Response
|
291 |
+
* @since 3.9
|
292 |
+
*/
|
293 |
+
public function authorize( $options = array() ) {
|
294 |
+
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Gateway implementation for "capture" operation
|
299 |
+
*
|
300 |
+
* @param array $options
|
301 |
+
* @return PHP_Merchant_Paypal_Pro_Response
|
302 |
+
* @since 3.9
|
303 |
+
*/
|
304 |
+
public function capture( $options = array() ) {
|
305 |
+
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Gateway implementation for "void" operation
|
310 |
+
*
|
311 |
+
* @param array $options
|
312 |
+
* @return PHP_Merchant_Paypal_Pro_Response
|
313 |
+
* @since 3.9
|
314 |
+
*/
|
315 |
+
public function void( $options = array() ) {
|
316 |
+
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Gateway implementation for RefundTransaction
|
321 |
+
*
|
322 |
+
* @param array $options
|
323 |
+
* @return PHP_Merchant_Paypal_Pro_Response
|
324 |
+
* @since 3.9
|
325 |
+
*/
|
326 |
+
public function credit( $options = array() ) {
|
327 |
+
$this->options = array_merge( $this->options, $options );
|
328 |
+
|
329 |
+
// Required Fields
|
330 |
+
$this->requires( array( 'message_id', 'invoice' ) );
|
331 |
+
|
332 |
+
// Conditionally required fields (one field at least is set)
|
333 |
+
$this->conditional_requires( array( 'payer_id', 'transaction_id' ) );
|
334 |
+
|
335 |
+
// Amount is required if the refund is partial
|
336 |
+
if ( strtolower( $this->options['refund_type'] ) === 'partial' ) {
|
337 |
+
$this->requires( array( 'amount' ) );
|
338 |
+
}
|
339 |
+
|
340 |
+
$request = $this->build_checkout_request( $options, false );
|
341 |
+
|
342 |
+
$response_str = $this->commit( 'RefundTransaction', $request );
|
343 |
+
return new PHP_Merchant_Paypal_Pro_Response( $response_str );
|
344 |
+
}
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Gateway impelementation for GetTransactionDetails
|
348 |
+
*
|
349 |
+
* @param string $transaction_id Unique identifier of a transaction.
|
350 |
+
* @return PHP_Merchant_Paypal_Express_Checkout_Response
|
351 |
+
* @since 3.9
|
352 |
+
*/
|
353 |
+
public function get_transaction_details( $transaction_id ) {
|
354 |
+
$request = array( 'TRANSACTIONID' => $transaction_id );
|
355 |
+
$response_str = $this->commit( 'GetTransactionDetails', $request );
|
356 |
+
return new PHP_Merchant_Paypal_Pro_Response( $response_str );
|
357 |
+
}
|
358 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-response.php
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class PHP_Merchant_Paypal_Response extends PHP_Merchant_Response {
|
4 |
+
protected $params = array();
|
5 |
+
|
6 |
+
public function __construct( $response_str ) {
|
7 |
+
parent::__construct( $response_str );
|
8 |
+
|
9 |
+
parse_str( $response_str, $params );
|
10 |
+
|
11 |
+
$this->params = $params = array_map( 'urldecode', $params );
|
12 |
+
|
13 |
+
if ( empty( $params ) || ! isset( $params['ACK'] ) ) {
|
14 |
+
throw new PHP_Merchant_Exception( PHPME_INVALID_RESPONSE, array(), $response_str );
|
15 |
+
}
|
16 |
+
|
17 |
+
$this->options['datetime'] = $params['TIMESTAMP'];
|
18 |
+
|
19 |
+
$time = rtrim( $params['TIMESTAMP'], 'Z' ) . '+0000';
|
20 |
+
|
21 |
+
if ( function_exists( 'strptime' ) ) {
|
22 |
+
if ( ! $time = strptime( $time, '%FT%T%z' ) ) {
|
23 |
+
$time = strptime( $time, '%FT%T%Z' );
|
24 |
+
}
|
25 |
+
} else {
|
26 |
+
if ( ! $time = self::strptime( $time, '%FT%T%z' ) ) {
|
27 |
+
$time = self::strptime( $time, '%FT%T%Z' );
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
switch ( $params['ACK'] ) {
|
32 |
+
case 'Success':
|
33 |
+
case 'SuccessWithWarning':
|
34 |
+
$this->is_successful = true;
|
35 |
+
break;
|
36 |
+
|
37 |
+
case 'Failure':
|
38 |
+
case 'FailureWithWarning':
|
39 |
+
case 'Warning':
|
40 |
+
$this->is_successful = false;
|
41 |
+
break;
|
42 |
+
}
|
43 |
+
|
44 |
+
if ( isset( $params['TOKEN'] ) ) {
|
45 |
+
$this->options['token'] = $params['TOKEN'];
|
46 |
+
}
|
47 |
+
|
48 |
+
$this->options['correlation_id'] = $params['CORRELATIONID'];
|
49 |
+
$this->options['version'] = $params['VERSION'];
|
50 |
+
$this->options['build'] = $params['BUILD'];
|
51 |
+
|
52 |
+
$i = 0;
|
53 |
+
|
54 |
+
while ( array_key_exists( "L_ERRORCODE{$i}", $params ) ) {
|
55 |
+
$error = array(
|
56 |
+
'code' => $params["L_ERRORCODE{$i}"],
|
57 |
+
'message' => $params["L_SHORTMESSAGE{$i}"],
|
58 |
+
'details' => $params["L_LONGMESSAGE{$i}"],
|
59 |
+
);
|
60 |
+
|
61 |
+
$this->errors[] = $error;
|
62 |
+
$i++;
|
63 |
+
}
|
64 |
+
|
65 |
+
if ( is_array( $time ) ) {
|
66 |
+
extract( $time, EXTR_SKIP );
|
67 |
+
$this->options['timestamp'] = mktime( $tm_hour, $tm_min, $tm_sec, 1 + $tm_mon, $tm_mday, 1900 + $tm_year );
|
68 |
+
} else {
|
69 |
+
$this->options['timestamp'] = time();
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
public static function strptime( $date, $format ) {
|
74 |
+
$masks = array(
|
75 |
+
'%d' => '(?P<d>[0-9]{2})',
|
76 |
+
'%m' => '(?P<m>[0-9]{2})',
|
77 |
+
'%Y' => '(?P<Y>[0-9]{4})',
|
78 |
+
'%H' => '(?P<H>[0-9]{2})',
|
79 |
+
'%M' => '(?P<M>[0-9]{2})',
|
80 |
+
'%S' => '(?P<S>[0-9]{2})',
|
81 |
+
);
|
82 |
+
|
83 |
+
$rexep = '#' . strtr( preg_quote( $format ), $masks ) . '#';
|
84 |
+
|
85 |
+
if ( ! preg_match( $rexep, $date, $out ) ) {
|
86 |
+
return false;
|
87 |
+
}
|
88 |
+
|
89 |
+
$ret = array(
|
90 |
+
'tm_sec' => (int) $out['S'],
|
91 |
+
'tm_min' => (int) $out['M'],
|
92 |
+
'tm_hour' => (int) $out['H'],
|
93 |
+
'tm_mday' => (int) $out['d'],
|
94 |
+
'tm_mon' => $out['m'] ? $out['m'] - 1 : 0,
|
95 |
+
'tm_year' => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0,
|
96 |
+
);
|
97 |
+
|
98 |
+
return $ret;
|
99 |
+
}
|
100 |
+
|
101 |
+
public function get_params() {
|
102 |
+
return $this->params;
|
103 |
+
}
|
104 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal.php
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( dirname( __FILE__ ) . '/../common/php-merchant.php' );
|
3 |
+
require_once( 'paypal-response.php' );
|
4 |
+
require_once( 'paypal-ipn.php' );
|
5 |
+
|
6 |
+
abstract class PHP_Merchant_Paypal extends PHP_Merchant
|
7 |
+
{
|
8 |
+
private static $supported_currencies = array(
|
9 |
+
'AUD',
|
10 |
+
'BRL',
|
11 |
+
'CAD',
|
12 |
+
'CHF',
|
13 |
+
'CZK',
|
14 |
+
'DKK',
|
15 |
+
'EUR',
|
16 |
+
'GBP',
|
17 |
+
'HKD',
|
18 |
+
'HUF',
|
19 |
+
'ILS',
|
20 |
+
'JPY',
|
21 |
+
'MXN',
|
22 |
+
'MYR',
|
23 |
+
'NOK',
|
24 |
+
'NZD',
|
25 |
+
'PHP',
|
26 |
+
'PLN',
|
27 |
+
'SEK',
|
28 |
+
'SGD',
|
29 |
+
'THB',
|
30 |
+
'TWD',
|
31 |
+
'USD',
|
32 |
+
);
|
33 |
+
|
34 |
+
const API_VERSION = '114.0';
|
35 |
+
const SANDBOX_URL = 'https://api-3t.sandbox.paypal.com/nvp';
|
36 |
+
const LIVE_URL = 'https://api-3t.paypal.com/nvp';
|
37 |
+
|
38 |
+
protected $request = array();
|
39 |
+
protected $url;
|
40 |
+
|
41 |
+
protected function add_credentials() {
|
42 |
+
$this->requires( array( 'api_username', 'api_password', 'api_signature' ) );
|
43 |
+
$credentials = array(
|
44 |
+
'USER' => $this->options['api_username'],
|
45 |
+
'PWD' => $this->options['api_password'],
|
46 |
+
'VERSION' => self::API_VERSION,
|
47 |
+
'SIGNATURE' => $this->options['api_signature'],
|
48 |
+
);
|
49 |
+
|
50 |
+
return $credentials;
|
51 |
+
}
|
52 |
+
|
53 |
+
protected function build_request( $action = '', $request = array() ) {
|
54 |
+
$this->request += $this->add_credentials();
|
55 |
+
if ( ! empty( $action ) )
|
56 |
+
$this->request['METHOD'] = $action;
|
57 |
+
$this->request = array_merge( $this->request, $request );
|
58 |
+
foreach( $this->request as $key => $value ) {
|
59 |
+
if ( is_bool( $value ) )
|
60 |
+
$this->request[$key] = (int) $value;
|
61 |
+
}
|
62 |
+
|
63 |
+
return $this->request;
|
64 |
+
}
|
65 |
+
|
66 |
+
public static function get_supported_currencies() {
|
67 |
+
return self::$supported_currencies;
|
68 |
+
}
|
69 |
+
|
70 |
+
public function __construct( $options = array() ) {
|
71 |
+
parent::__construct( $options );
|
72 |
+
}
|
73 |
+
|
74 |
+
public function get_url() {
|
75 |
+
return empty( $this->options['test'] ) ? self::LIVE_URL : self::SANDBOX_URL;
|
76 |
+
}
|
77 |
+
|
78 |
+
public static function is_currency_supported( $currency ) {
|
79 |
+
return in_array( $currency, self::$supported_currencies );
|
80 |
+
}
|
81 |
+
|
82 |
+
protected function commit( $action, $request = array() ) {
|
83 |
+
$this->build_request( $action, $request );
|
84 |
+
return $this->http->post( $this->get_url(), $this->request );
|
85 |
+
}
|
86 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/http-curl.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/common/http.php' );
|
4 |
+
require_once( PHP_MERCHANT_PATH . '/common/http-curl.php' );
|
5 |
+
|
6 |
+
class PHP_Merchant_HTTP_CURL_Test extends UnitTestCase
|
7 |
+
{
|
8 |
+
public function __construct() {
|
9 |
+
parent::__construct( 'PHP_Merchant_HTTP_CURL unit tests' );
|
10 |
+
}
|
11 |
+
|
12 |
+
public function test_array_is_parsed_correctly_into_query_string() {
|
13 |
+
$http = new PHP_Merchant_HTTP_CURL_Bogus();
|
14 |
+
|
15 |
+
$args = array(
|
16 |
+
'key_1' => 'key 1 value',
|
17 |
+
'key_2' => 'key&2%value='
|
18 |
+
);
|
19 |
+
|
20 |
+
$query_string = 'key_1=key+1+value&key_2=key%262%25value%3D';
|
21 |
+
|
22 |
+
$this->assertEqual( $http->parse_args( $args ), $query_string );
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
class PHP_Merchant_HTTP_CURL_Bogus extends PHP_Merchant_HTTP_CURL
|
27 |
+
{
|
28 |
+
public function parse_args( $args ) {
|
29 |
+
return parent::parse_args( $args );
|
30 |
+
}
|
31 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/php-merchant.php
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/common/php-merchant.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Test extends UnitTestCase
|
6 |
+
{
|
7 |
+
public function __construct() {
|
8 |
+
parent::__construct( 'PHP_Merchant test cases' );
|
9 |
+
}
|
10 |
+
|
11 |
+
public function test_options_are_initialized_correctly() {
|
12 |
+
$options = array(
|
13 |
+
'option_1' => 'option 1',
|
14 |
+
'option_2' => 'option 2',
|
15 |
+
);
|
16 |
+
|
17 |
+
$bogus = new PHP_Merchant_Bogus( $options );
|
18 |
+
foreach ( $options as $key => $value ) {
|
19 |
+
$this->assertEqual( $value, $bogus->get_option( $key ) );
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
public function test_multiple_options_are_set_correctly() {
|
24 |
+
$options = array(
|
25 |
+
'option_1' => 'option 1',
|
26 |
+
'option_2' => 'option 2',
|
27 |
+
);
|
28 |
+
|
29 |
+
$bogus = new PHP_Merchant_Bogus();
|
30 |
+
$bogus->set_options( $options );
|
31 |
+
foreach ( $options as $key => $value ) {
|
32 |
+
$this->assertEqual( $value, $bogus->get_option( $key ) );
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
public function test_option_is_set_correctly() {
|
37 |
+
$bogus = new PHP_Merchant_Bogus();
|
38 |
+
$bogus->set_option( 'test_option', 'test_value' );
|
39 |
+
$this->assertEqual( 'test_value', $bogus->get_option( 'test_option' ) );
|
40 |
+
}
|
41 |
+
|
42 |
+
public function test_default_currency_option_is_usd() {
|
43 |
+
$bogus = new PHP_Merchant_Bogus();
|
44 |
+
$this->assertEqual( 'USD', $bogus->get_option( 'currency' ) );
|
45 |
+
}
|
46 |
+
|
47 |
+
public function test_option_is_overrided_correctly() {
|
48 |
+
$bogus = new PHP_Merchant_Bogus();
|
49 |
+
$bogus->set_option( 'currency', 'JPY' );
|
50 |
+
$this->assertEqual( 'JPY', $bogus->get_option( 'currency' ) );
|
51 |
+
}
|
52 |
+
|
53 |
+
public function test_multiple_options_are_overrided_correctly() {
|
54 |
+
$bogus = new PHP_Merchant_Bogus();
|
55 |
+
$bogus->set_option( 'option_1', 'option 1' );
|
56 |
+
$bogus->set_option( 'option_2', 'option 2' );
|
57 |
+
|
58 |
+
$bogus->set_options( array(
|
59 |
+
'currency' => 'JPY',
|
60 |
+
'option_1' => 'updated value',
|
61 |
+
) );
|
62 |
+
|
63 |
+
$this->assertEqual( 'JPY', $bogus->get_option( 'currency' ) );
|
64 |
+
$this->assertEqual( 'updated value', $bogus->get_option( 'option_1' ) );
|
65 |
+
$this->assertEqual( 'option 2', $bogus->get_option( 'option_2' ) );
|
66 |
+
}
|
67 |
+
|
68 |
+
public function test_price_is_formatted_correctly() {
|
69 |
+
$bogus = new PHP_Merchant_Bogus();
|
70 |
+
$this->assertEqual( $bogus->format( 22.59378 ), '22.59' );
|
71 |
+
$this->assertEqual( $bogus->format( 22.495 ), '22.5' );
|
72 |
+
}
|
73 |
+
|
74 |
+
public function test_price_should_not_be_fractional_in_certain_currencies() {
|
75 |
+
$bogus = new PHP_Merchant_Bogus();
|
76 |
+
$bogus->set_option( 'currency', 'JPY' );
|
77 |
+
$this->assertEqual( $bogus->format( 22.59378 ), '23' );
|
78 |
+
$this->assertEqual( $bogus->format( 22.495 ), '22' );
|
79 |
+
$this->assertEqual( $bogus->format( 22.333 ), '22' );
|
80 |
+
|
81 |
+
$bogus->set_option( 'currency', 'HUF' );
|
82 |
+
$this->assertEqual( $bogus->format( 22.59378 ), '23' );
|
83 |
+
$this->assertEqual( $bogus->format( 22.495 ), '22' );
|
84 |
+
$this->assertEqual( $bogus->format( 22.333 ), '22' );
|
85 |
+
}
|
86 |
+
|
87 |
+
public function test_no_exception_is_thrown_when_feature_is_supported() {
|
88 |
+
$bogus = new PHP_Merchant_Bogus_Full_Features();
|
89 |
+
$bogus->authorize();
|
90 |
+
$bogus->capture();
|
91 |
+
$bogus->void();
|
92 |
+
$bogus->credit();
|
93 |
+
$bogus->recurring();
|
94 |
+
}
|
95 |
+
|
96 |
+
public function test_exception_is_thrown_when_authorize_is_not_supported() {
|
97 |
+
$bogus = new PHP_Merchant_Bogus();
|
98 |
+
|
99 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'authorize' ) );
|
100 |
+
$bogus->authorize();
|
101 |
+
}
|
102 |
+
|
103 |
+
public function test_exception_is_thrown_when_capture_is_not_supported() {
|
104 |
+
$bogus = new PHP_Merchant_Bogus();
|
105 |
+
|
106 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'capture' ) );
|
107 |
+
$bogus->capture();
|
108 |
+
}
|
109 |
+
|
110 |
+
public function test_exception_is_thrown_when_void_is_not_supported() {
|
111 |
+
$bogus = new PHP_Merchant_Bogus();
|
112 |
+
|
113 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'void' ) );
|
114 |
+
$bogus->void();
|
115 |
+
}
|
116 |
+
|
117 |
+
public function test_exception_is_thrown_when_credit_is_not_supported() {
|
118 |
+
$bogus = new PHP_Merchant_Bogus();
|
119 |
+
|
120 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'credit' ) );
|
121 |
+
$bogus->credit();
|
122 |
+
}
|
123 |
+
|
124 |
+
public function test_exception_is_thrown_when_recurring_is_not_supported() {
|
125 |
+
$bogus = new PHP_Merchant_Bogus();
|
126 |
+
|
127 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'recurring' ) );
|
128 |
+
$bogus->recurring();
|
129 |
+
}
|
130 |
+
|
131 |
+
public function test_exception_is_thrown_when_a_required_option_is_missing() {
|
132 |
+
$bogus = new PHP_Merchant_Bogus();
|
133 |
+
|
134 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_REQUIRED_OPTION_UNDEFINED, array( 'missing_option' ) ) );
|
135 |
+
$bogus->requires( 'missing_option' );
|
136 |
+
}
|
137 |
+
|
138 |
+
public function test_exception_is_thrown_when_some_required_options_are_missing() {
|
139 |
+
$bogus = new PHP_Merchant_Bogus();
|
140 |
+
|
141 |
+
$bogus->set_option( 'option_1', 'option 1' );
|
142 |
+
$bogus->set_option( 'option_2', 'option 2' );
|
143 |
+
|
144 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_REQUIRED_OPTION_UNDEFINED, array( 'missing_option' ) ) );
|
145 |
+
$bogus->requires( array( 'currency', 'option_1', 'option_2', 'missing_option' ) );
|
146 |
+
}
|
147 |
+
|
148 |
+
public function test_exception_is_thrown_when_some_cond_required_options_are_missing() {
|
149 |
+
$bogus = new PHP_Merchant_Bogus();
|
150 |
+
|
151 |
+
$this->expectException( new PHP_Merchant_Exception( PHPME_REQUIRED_OPTION_UNDEFINED, 'option_1, option_2, option_3' ) );
|
152 |
+
$bogus->conditional_requires( array( 'option_1', 'option_2', 'option_3' ) );
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
class PHP_Merchant_Bogus extends PHP_Merchant {
|
157 |
+
public function requires( $options ) {
|
158 |
+
parent::requires( $options );
|
159 |
+
}
|
160 |
+
public function conditional_requires( $options ) {
|
161 |
+
parent::conditional_requires( $options );
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
class PHP_Merchant_Bogus_Full_Features extends PHP_Merchant {
|
166 |
+
public function authorize() {
|
167 |
+
}
|
168 |
+
|
169 |
+
public function capture() {
|
170 |
+
}
|
171 |
+
|
172 |
+
public function void() {
|
173 |
+
}
|
174 |
+
|
175 |
+
public function credit() {
|
176 |
+
}
|
177 |
+
|
178 |
+
public function recurring() {
|
179 |
+
}
|
180 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/test-accounts.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// @todo: Update to use canonical test accounts rather than those of individuals.
|
3 |
+
$test_accounts = array(
|
4 |
+
'paypal-express-checkout' => array(
|
5 |
+
'api_username' => 'pro_1304085877_biz_api1.garyc40.com',
|
6 |
+
'api_password' => '1304085909',
|
7 |
+
'api_signature' => 'AvoRfECzHW0KLVBSrJC70dNDVgEQA2j69L5ydKo3JhQBCJCNrZTj2zS8',
|
8 |
+
'test' => true,
|
9 |
+
),
|
10 |
+
'paypal-ec-oa' => array(
|
11 |
+
'api_username' => 'paypal-facilitator_api1.omarabid.com',
|
12 |
+
'api_password' => '1404523024',
|
13 |
+
'api_signature' => 'An5ns1Kso7MWUdW4ErQKJJJ4qi4-AnIgHxdxM4-jkGKkkOhcO0fD-Av5',
|
14 |
+
'test' => true,
|
15 |
+
),
|
16 |
+
'paypal-pro-oa' => array(
|
17 |
+
'api_username' => 'wpp_api1.omarabid.com',
|
18 |
+
'api_password' => '4WQY6WGGAGS4JPEA',
|
19 |
+
'api_signature' => 'AFcWxV21C7fd0v3bYYYRCpSSRl31AboWy-uBCAMW9aDx8JwAq7ryYemY',
|
20 |
+
'test' => true,
|
21 |
+
),
|
22 |
+
);
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-express-checkout.php
ADDED
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Test extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $bogus;
|
8 |
+
private $options;
|
9 |
+
private $amount;
|
10 |
+
private $token;
|
11 |
+
private $setup_purchase_options;
|
12 |
+
private $purchase_options;
|
13 |
+
|
14 |
+
public function __construct() {
|
15 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
16 |
+
$this->token = 'EC-6L77249383950130E';
|
17 |
+
// options to pass to the merchant class
|
18 |
+
$this->setup_purchase_options = $this->purchase_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => true,
|
23 |
+
|
24 |
+
// Shipping details
|
25 |
+
'shipping_address' => array(
|
26 |
+
'name' => 'Gary Cao',
|
27 |
+
'street' => '1 Infinite Loop',
|
28 |
+
'street2' => 'Apple Headquarter',
|
29 |
+
'city' => 'Cupertino',
|
30 |
+
'state' => 'CA',
|
31 |
+
'country' => 'USA',
|
32 |
+
'zip' => '95014',
|
33 |
+
'phone' => '(877) 412-7753',
|
34 |
+
),
|
35 |
+
|
36 |
+
// Payment info
|
37 |
+
'currency' => 'JPY',
|
38 |
+
'amount' => 15337,
|
39 |
+
'subtotal' => 13700,
|
40 |
+
'shipping' => 1500,
|
41 |
+
'tax' => 137,
|
42 |
+
'description' => 'Order for example.com',
|
43 |
+
'invoice' => 'E84A90G94',
|
44 |
+
'notify_url' => 'http://example.com/ipn',
|
45 |
+
|
46 |
+
// Items
|
47 |
+
'items' => array(
|
48 |
+
array(
|
49 |
+
'name' => 'Gold Cart Plugin',
|
50 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality, including views, galleries, store search and payment gateways.',
|
51 |
+
'amount' => 4000,
|
52 |
+
'quantity' => 1,
|
53 |
+
'tax' => 40,
|
54 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
55 |
+
),
|
56 |
+
array(
|
57 |
+
'name' => 'Member Access Plugin',
|
58 |
+
'description' => 'Create pay to view subscription sites',
|
59 |
+
'amount' => 5000,
|
60 |
+
'quantity' => 1,
|
61 |
+
'tax' => 50,
|
62 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
63 |
+
),
|
64 |
+
array(
|
65 |
+
'name' => 'Amazon S3',
|
66 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
67 |
+
'amount' => 4700,
|
68 |
+
'quantity' => 1,
|
69 |
+
'tax' => 47,
|
70 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
71 |
+
),
|
72 |
+
),
|
73 |
+
);
|
74 |
+
|
75 |
+
$this->purchase_options += array(
|
76 |
+
'token' => 'EC-2JJ0893331633543K',
|
77 |
+
'payer_id' => 'BC798KQ2QU22W',
|
78 |
+
);
|
79 |
+
}
|
80 |
+
|
81 |
+
public function setUp() {
|
82 |
+
$this->bogus = new PHP_Merchant_Paypal_Express_Checkout_Bogus( array(
|
83 |
+
'api_username' => 'sdk-three_api1.sdk.com',
|
84 |
+
'api_password' => 'QFZCWN5HZM8VBG7Q',
|
85 |
+
'api_signature' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
86 |
+
) );
|
87 |
+
}
|
88 |
+
|
89 |
+
public function tearDown() {
|
90 |
+
|
91 |
+
}
|
92 |
+
|
93 |
+
public function test_correct_parameters_are_sent_to_paypal_when_set_express_checkout() {
|
94 |
+
// set up expectations for mock objects
|
95 |
+
$url = 'https://api-3t.paypal.com/nvp';
|
96 |
+
|
97 |
+
// how the request parameters should look like
|
98 |
+
$args = array(
|
99 |
+
// API info
|
100 |
+
'USER' => 'sdk-three_api1.sdk.com',
|
101 |
+
'PWD' => 'QFZCWN5HZM8VBG7Q',
|
102 |
+
'VERSION' => '114.0',
|
103 |
+
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
104 |
+
'METHOD' => 'SetExpressCheckout',
|
105 |
+
'RETURNURL' => 'http://example.com/return',
|
106 |
+
'CANCELURL' => 'http://example.com/cancel',
|
107 |
+
'AMT' => 15337,
|
108 |
+
'ADDROVERRIDE' => 1,
|
109 |
+
'INVOICEID' => 'E84A90G94',
|
110 |
+
|
111 |
+
|
112 |
+
// Shipping details
|
113 |
+
'PAYMENTREQUEST_0_SHIPTONAME' => 'Gary Cao',
|
114 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET' => '1 Infinite Loop',
|
115 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Apple Headquarter',
|
116 |
+
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Cupertino',
|
117 |
+
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'CA',
|
118 |
+
'PAYMENTREQUEST_0_SHIPTOZIP' => '95014',
|
119 |
+
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
|
120 |
+
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '(877) 412-7753',
|
121 |
+
|
122 |
+
// Payment info
|
123 |
+
'PAYMENTREQUEST_0_AMT' => '15,337',
|
124 |
+
'PAYMENTREQUEST_0_CURRENCYCODE' => 'JPY',
|
125 |
+
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
|
126 |
+
'PAYMENTREQUEST_0_ALLOWEDPAYMENTMETHOD' => 'InstantPaymentOnly',
|
127 |
+
'PAYMENTREQUEST_0_ITEMAMT' => '13,700',
|
128 |
+
'PAYMENTREQUEST_0_SHIPPINGAMT' => '1,500',
|
129 |
+
'PAYMENTREQUEST_0_TAXAMT' => '137',
|
130 |
+
'PAYMENTREQUEST_0_DESC' => 'Order for example.com',
|
131 |
+
'PAYMENTREQUEST_0_INVNUM' => 'E84A90G94',
|
132 |
+
'PAYMENTREQUEST_0_NOTIFYURL' => 'http://example.com/ipn',
|
133 |
+
|
134 |
+
// Items
|
135 |
+
'L_PAYMENTREQUEST_0_NAME0' => 'Gold Cart Plugin',
|
136 |
+
'L_PAYMENTREQUEST_0_AMT0' => '4,000',
|
137 |
+
'L_PAYMENTREQUEST_0_QTY0' => 1,
|
138 |
+
'L_PAYMENTREQUEST_0_DESC0' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality, including views, galleries, store search and payment gateways.',
|
139 |
+
'L_PAYMENTREQUEST_0_TAXAMT0' => '40',
|
140 |
+
'L_PAYMENTREQUEST_0_ITEMURL0' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
141 |
+
|
142 |
+
'L_PAYMENTREQUEST_0_NAME1' => 'Member Access Plugin',
|
143 |
+
'L_PAYMENTREQUEST_0_AMT1' => '5,000',
|
144 |
+
'L_PAYMENTREQUEST_0_QTY1' => 1,
|
145 |
+
'L_PAYMENTREQUEST_0_DESC1' => 'Create pay to view subscription sites',
|
146 |
+
'L_PAYMENTREQUEST_0_TAXAMT1' => '50',
|
147 |
+
'L_PAYMENTREQUEST_0_ITEMURL1' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
148 |
+
|
149 |
+
'L_PAYMENTREQUEST_0_NAME2' => 'Amazon S3',
|
150 |
+
'L_PAYMENTREQUEST_0_AMT2' => '4,700',
|
151 |
+
'L_PAYMENTREQUEST_0_QTY2' => 1,
|
152 |
+
'L_PAYMENTREQUEST_0_DESC2' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
153 |
+
'L_PAYMENTREQUEST_0_TAXAMT2' => '47',
|
154 |
+
'L_PAYMENTREQUEST_0_ITEMURL2' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
155 |
+
);
|
156 |
+
|
157 |
+
$this->bogus->http->expectOnce( 'post', array( $url, $args ) );
|
158 |
+
try {
|
159 |
+
$this->bogus->setup_purchase( $this->setup_purchase_options );
|
160 |
+
} catch ( PHP_Merchant_Exception $e ) {
|
161 |
+
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
public function test_correct_parameters_are_sent_when_do_express_checkout_payment() {
|
166 |
+
// set up expectations for mock objects
|
167 |
+
$url = 'https://api-3t.paypal.com/nvp';
|
168 |
+
|
169 |
+
// how the request parameters should look like
|
170 |
+
$args = array(
|
171 |
+
// API info
|
172 |
+
'USER' => 'sdk-three_api1.sdk.com',
|
173 |
+
'PWD' => 'QFZCWN5HZM8VBG7Q',
|
174 |
+
'VERSION' => '114.0',
|
175 |
+
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
176 |
+
'METHOD' => 'DoExpressCheckoutPayment',
|
177 |
+
'RETURNURL' => 'http://example.com/return',
|
178 |
+
'CANCELURL' => 'http://example.com/cancel',
|
179 |
+
'AMT' => 15337,
|
180 |
+
'ADDROVERRIDE' => 1,
|
181 |
+
|
182 |
+
// Payer ID
|
183 |
+
'TOKEN' => 'EC-2JJ0893331633543K',
|
184 |
+
'PAYERID' => 'BC798KQ2QU22W',
|
185 |
+
|
186 |
+
'INVOICEID' => 'E84A90G94',
|
187 |
+
|
188 |
+
// Shipping details
|
189 |
+
'PAYMENTREQUEST_0_SHIPTONAME' => 'Gary Cao',
|
190 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET' => '1 Infinite Loop',
|
191 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Apple Headquarter',
|
192 |
+
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Cupertino',
|
193 |
+
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'CA',
|
194 |
+
'PAYMENTREQUEST_0_SHIPTOZIP' => '95014',
|
195 |
+
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
|
196 |
+
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '(877) 412-7753',
|
197 |
+
|
198 |
+
// Payment info
|
199 |
+
'PAYMENTREQUEST_0_AMT' => '15,337',
|
200 |
+
'PAYMENTREQUEST_0_CURRENCYCODE' => 'JPY',
|
201 |
+
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
|
202 |
+
'PAYMENTREQUEST_0_ALLOWEDPAYMENTMETHOD' => 'InstantPaymentOnly',
|
203 |
+
'PAYMENTREQUEST_0_ITEMAMT' => '13,700',
|
204 |
+
'PAYMENTREQUEST_0_SHIPPINGAMT' => '1,500',
|
205 |
+
'PAYMENTREQUEST_0_TAXAMT' => '137',
|
206 |
+
'PAYMENTREQUEST_0_DESC' => 'Order for example.com',
|
207 |
+
'PAYMENTREQUEST_0_INVNUM' => 'E84A90G94',
|
208 |
+
'PAYMENTREQUEST_0_NOTIFYURL' => 'http://example.com/ipn',
|
209 |
+
|
210 |
+
// Items
|
211 |
+
'L_PAYMENTREQUEST_0_NAME0' => 'Gold Cart Plugin',
|
212 |
+
'L_PAYMENTREQUEST_0_AMT0' => '4,000',
|
213 |
+
'L_PAYMENTREQUEST_0_QTY0' => 1,
|
214 |
+
'L_PAYMENTREQUEST_0_DESC0' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality, including views, galleries, store search and payment gateways.',
|
215 |
+
'L_PAYMENTREQUEST_0_TAXAMT0' => '40',
|
216 |
+
'L_PAYMENTREQUEST_0_ITEMURL0' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
217 |
+
|
218 |
+
'L_PAYMENTREQUEST_0_NAME1' => 'Member Access Plugin',
|
219 |
+
'L_PAYMENTREQUEST_0_AMT1' => '5,000',
|
220 |
+
'L_PAYMENTREQUEST_0_QTY1' => 1,
|
221 |
+
'L_PAYMENTREQUEST_0_DESC1' => 'Create pay to view subscription sites',
|
222 |
+
'L_PAYMENTREQUEST_0_TAXAMT1' => '50',
|
223 |
+
'L_PAYMENTREQUEST_0_ITEMURL1' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
224 |
+
|
225 |
+
'L_PAYMENTREQUEST_0_NAME2' => 'Amazon S3',
|
226 |
+
'L_PAYMENTREQUEST_0_AMT2' => '4,700',
|
227 |
+
'L_PAYMENTREQUEST_0_QTY2' => 1,
|
228 |
+
'L_PAYMENTREQUEST_0_DESC2' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
229 |
+
'L_PAYMENTREQUEST_0_TAXAMT2' => '47',
|
230 |
+
'L_PAYMENTREQUEST_0_ITEMURL2' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
231 |
+
);
|
232 |
+
|
233 |
+
$this->bogus->http->expectOnce( 'post', array( $url, $args ) );
|
234 |
+
try {
|
235 |
+
$this->bogus->purchase( $this->purchase_options );
|
236 |
+
} catch ( PHP_Merchant_Exception $e ) {
|
237 |
+
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
public function test_correct_parameters_are_sent_when_get_express_checkout_details() {
|
242 |
+
$url = 'https://api-3t.paypal.com/nvp';
|
243 |
+
$args = array(
|
244 |
+
// API info
|
245 |
+
'USER' => 'sdk-three_api1.sdk.com',
|
246 |
+
'PWD' => 'QFZCWN5HZM8VBG7Q',
|
247 |
+
'VERSION' => '114.0',
|
248 |
+
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
249 |
+
'METHOD' => 'GetExpressCheckoutDetails',
|
250 |
+
'TOKEN' => $this->token,
|
251 |
+
);
|
252 |
+
|
253 |
+
$this->bogus->http->expectOnce( 'post', array( $url, $args ) );
|
254 |
+
try {
|
255 |
+
$this->bogus->get_details_for( $this->token );
|
256 |
+
} catch ( PHP_Merchant_Exception $e ) {
|
257 |
+
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
public function test_correct_response_is_returned_when_set_express_checkout_is_successful() {
|
262 |
+
$mock_response = 'ACK=Success&CORRELATIONID=224f0e4a32d14&TIMESTAMP=2011%2d07%2d05T13%253A23%253A52Z&VERSION=2%2e30000&BUILD=1%2e0006&TOKEN=EC%2d1OIN4UJGFOK54YFV';
|
263 |
+
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
264 |
+
$response = $this->bogus->setup_purchase( $this->setup_purchase_options );
|
265 |
+
|
266 |
+
$this->assertTrue( $response->is_successful() );
|
267 |
+
$this->assertFalse( $response->has_errors() );
|
268 |
+
$this->assertEqual( $response->get( 'token' ), 'EC-1OIN4UJGFOK54YFV' );
|
269 |
+
$this->assertEqual( $response->get( 'timestamp' ), 1309872232 );
|
270 |
+
$this->assertEqual( $response->get( 'datetime' ), '2011-07-05T13:23:52Z' );
|
271 |
+
$this->assertEqual( $response->get( 'correlation_id' ), '224f0e4a32d14' );
|
272 |
+
$this->assertEqual( $response->get( 'version' ), '2.30000' );
|
273 |
+
$this->assertEqual( $response->get( 'build' ), '1.0006' );
|
274 |
+
}
|
275 |
+
|
276 |
+
public function test_correct_response_is_returned_when_get_express_checkout_details_is_successful() {
|
277 |
+
$mock_response = 'TOKEN=EC%2d6EC97401PF4449255'.
|
278 |
+
|
279 |
+
// API Info
|
280 |
+
'&CHECKOUTSTATUS=PaymentActionNotInitiated'.
|
281 |
+
'&TIMESTAMP=2011%2d08%2d25T08%3a04%3a26Z'.
|
282 |
+
'&CORRELATIONID=b5ae9bd5c735f'.
|
283 |
+
'&ACK=Success'.
|
284 |
+
'&VERSION=114%2e0'.
|
285 |
+
'&BUILD=2085867'.
|
286 |
+
|
287 |
+
// Payer info
|
288 |
+
'&EMAIL=visa_1304648966_per%40garyc40%2ecom'.
|
289 |
+
'&PAYERID=BC798KQ2QU22W'.
|
290 |
+
'&PAYERSTATUS=verified'.
|
291 |
+
'&FIRSTNAME=Test'.
|
292 |
+
'&LASTNAME=User'.
|
293 |
+
'&COUNTRYCODE=US'.
|
294 |
+
'&SHIPTONAME=Gary%20Cao'.
|
295 |
+
'&SHIPTOSTREET=1%20Infinite%20Loop'.
|
296 |
+
'&SHIPTOSTREET2=Apple%20Headquarter'.
|
297 |
+
'&SHIPTOCITY=Cupertino'.
|
298 |
+
'&SHIPTOSTATE=CA'.
|
299 |
+
'&SHIPTOZIP=95014'.
|
300 |
+
'&SHIPTOCOUNTRYCODE=US'.
|
301 |
+
'&SHIPTOPHONENUM=%28877%29%20412%2d7753'.
|
302 |
+
'&SHIPTOCOUNTRYNAME=United%20States'.
|
303 |
+
'&ADDRESSSTATUS=Unconfirmed'.
|
304 |
+
|
305 |
+
// Legacy parameters (old API)
|
306 |
+
'&CURRENCYCODE=JPY'.
|
307 |
+
'&AMT=15337'.
|
308 |
+
'&ITEMAMT=13700'.
|
309 |
+
'&SHIPPINGAMT=1500'.
|
310 |
+
'&HANDLINGAMT=0'.
|
311 |
+
'&TAXAMT=137'.
|
312 |
+
'&DESC=Order%20for%20example%2ecom'.
|
313 |
+
'&INVNUM=E84A90G94'.
|
314 |
+
'&NOTIFYURL=http%3a%2f%2fexample%2ecom%2fipn'.
|
315 |
+
'&INSURANCEAMT=0'.
|
316 |
+
'&SHIPDISCAMT=0'.
|
317 |
+
|
318 |
+
// Legacy parameters (old API)
|
319 |
+
'&L_NAME0=Gold%20Cart%20Plugin'.
|
320 |
+
'&L_NAME1=Member%20Access%20Plugin'.
|
321 |
+
'&L_NAME2=Amazon%20S3'.
|
322 |
+
'&L_QTY0=1'.
|
323 |
+
'&L_QTY1=1'.
|
324 |
+
'&L_QTY2=1'.
|
325 |
+
'&L_TAXAMT0=40'.
|
326 |
+
'&L_TAXAMT1=50'.
|
327 |
+
'&L_TAXAMT2=47'.
|
328 |
+
'&L_AMT0=4000'.
|
329 |
+
'&L_AMT1=5000'.
|
330 |
+
'&L_AMT2=4700'.
|
331 |
+
'&L_DESC0=Gold%20Cart%20extends%20your%20WP%20e%2dCommerce%20store%20by%20enabling%20additional%20features%20and%20functionality%2e'.
|
332 |
+
'&L_DESC1=Create%20pay%20to%20view%20subscription%20sites'.
|
333 |
+
'&L_DESC2=This%20Plugin%20allows%20downloadable%20products%20on%20your%20WP%20e%2dCommerce%20site%20to%20be%20hosted%20on%20Amazon%20S3%2e'.
|
334 |
+
'&L_ITEMWEIGHTVALUE0=%20%20%200%2e00000'.
|
335 |
+
'&L_ITEMWEIGHTVALUE1=%20%20%200%2e00000'.
|
336 |
+
'&L_ITEMWEIGHTVALUE2=%20%20%200%2e00000'.
|
337 |
+
'&L_ITEMLENGTHVALUE0=%20%20%200%2e00000'.
|
338 |
+
'&L_ITEMLENGTHVALUE1=%20%20%200%2e00000'.
|
339 |
+
'&L_ITEMLENGTHVALUE2=%20%20%200%2e00000'.
|
340 |
+
'&L_ITEMWIDTHVALUE0=%20%20%200%2e00000'.
|
341 |
+
'&L_ITEMWIDTHVALUE1=%20%20%200%2e00000'.
|
342 |
+
'&L_ITEMWIDTHVALUE2=%20%20%200%2e00000'.
|
343 |
+
'&L_ITEMHEIGHTVALUE0=%20%20%200%2e00000'.
|
344 |
+
'&L_ITEMHEIGHTVALUE1=%20%20%200%2e00000'.
|
345 |
+
'&L_ITEMHEIGHTVALUE2=%20%20%200%2e00000'.
|
346 |
+
|
347 |
+
// Payment Information
|
348 |
+
'&PAYMENTREQUEST_0_CURRENCYCODE=JPY'.
|
349 |
+
'&PAYMENTREQUEST_0_AMT=15337'.
|
350 |
+
'&PAYMENTREQUEST_0_ITEMAMT=13700'.
|
351 |
+
'&PAYMENTREQUEST_0_SHIPPINGAMT=1500'.
|
352 |
+
'&PAYMENTREQUEST_0_HANDLINGAMT=0'.
|
353 |
+
'&PAYMENTREQUEST_0_TAXAMT=137'.
|
354 |
+
'&PAYMENTREQUEST_0_DESC=Order%20for%20example%2ecom'.
|
355 |
+
'&PAYMENTREQUEST_0_INVNUM=E84A90G94'.
|
356 |
+
'&PAYMENTREQUEST_0_NOTIFYURL=http%3a%2f%2fexample%2ecom%2fipn'.
|
357 |
+
'&PAYMENTREQUEST_0_INSURANCEAMT=0'.
|
358 |
+
'&PAYMENTREQUEST_0_SHIPDISCAMT=0'.
|
359 |
+
'&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false'.
|
360 |
+
|
361 |
+
// Item Information
|
362 |
+
'&L_PAYMENTREQUEST_0_NAME0=Gold%20Cart%20Plugin'.
|
363 |
+
'&L_PAYMENTREQUEST_0_NAME1=Member%20Access%20Plugin'.
|
364 |
+
'&L_PAYMENTREQUEST_0_NAME2=Amazon%20S3'.
|
365 |
+
'&L_PAYMENTREQUEST_0_QTY0=1'.
|
366 |
+
'&L_PAYMENTREQUEST_0_QTY1=1'.
|
367 |
+
'&L_PAYMENTREQUEST_0_QTY2=1'.
|
368 |
+
'&L_PAYMENTREQUEST_0_TAXAMT0=40'.
|
369 |
+
'&L_PAYMENTREQUEST_0_TAXAMT1=50'.
|
370 |
+
'&L_PAYMENTREQUEST_0_TAXAMT2=47'.
|
371 |
+
'&L_PAYMENTREQUEST_0_AMT0=4000'.
|
372 |
+
'&L_PAYMENTREQUEST_0_AMT1=5000'.
|
373 |
+
'&L_PAYMENTREQUEST_0_AMT2=4700'.
|
374 |
+
'&L_PAYMENTREQUEST_0_DESC0=Gold%20Cart%20extends%20your%20WP%20e%2dCommerce%20store%20by%20enabling%20additional%20features%20and%20functionality%2e'.
|
375 |
+
'&L_PAYMENTREQUEST_0_DESC1=Create%20pay%20to%20view%20subscription%20sites'.
|
376 |
+
'&L_PAYMENTREQUEST_0_DESC2=This%20Plugin%20allows%20downloadable%20products%20on%20your%20WP%20e%2dCommerce%20site%20to%20be%20hosted%20on%20Amazon%20S3%2e'.
|
377 |
+
'&L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0=%20%20%200%2e00000'.
|
378 |
+
'&L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE1=%20%20%200%2e00000'.
|
379 |
+
'&L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE2=%20%20%200%2e00000'.
|
380 |
+
'&L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0=%20%20%200%2e00000'.
|
381 |
+
'&L_PAYMENTREQUEST_0_ITEMLENGTHVALUE1=%20%20%200%2e00000'.
|
382 |
+
'&L_PAYMENTREQUEST_0_ITEMLENGTHVALUE2=%20%20%200%2e00000'.
|
383 |
+
'&L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0=%20%20%200%2e00000'.
|
384 |
+
'&L_PAYMENTREQUEST_0_ITEMWIDTHVALUE1=%20%20%200%2e00000'.
|
385 |
+
'&L_PAYMENTREQUEST_0_ITEMWIDTHVALUE2=%20%20%200%2e00000'.
|
386 |
+
'&L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0=%20%20%200%2e00000'.
|
387 |
+
'&L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE1=%20%20%200%2e00000'.
|
388 |
+
'&L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE2=%20%20%200%2e00000'.
|
389 |
+
|
390 |
+
// Errors
|
391 |
+
'&PAYMENTREQUESTINFO_0_ERRORCODE=0';
|
392 |
+
|
393 |
+
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
394 |
+
$response = $this->bogus->get_details_for( $this->token );
|
395 |
+
|
396 |
+
$this->assertTrue( $response->is_successful() );
|
397 |
+
$this->assertFalse( $response->has_errors() );
|
398 |
+
|
399 |
+
// API Info
|
400 |
+
$this->assertTrue( $response->is_checkout_not_initiated() );
|
401 |
+
$this->assertFalse( $response->is_checkout_failed() );
|
402 |
+
$this->assertFalse( $response->is_checkout_in_progress() );
|
403 |
+
$this->assertFalse( $response->is_checkout_completed() );
|
404 |
+
$this->assertEqual( $response->get( 'checkout_status' ), 'Not-Initiated' );
|
405 |
+
$this->assertEqual( $response->get( 'token' ), 'EC-6EC97401PF4449255' );
|
406 |
+
$this->assertEqual( $response->get( 'timestamp' ), 1314259466 );
|
407 |
+
$this->assertEqual( $response->get( 'datetime' ), '2011-08-25T08:04:26Z' );
|
408 |
+
$this->assertEqual( $response->get( 'correlation_id' ), 'b5ae9bd5c735f' );
|
409 |
+
$this->assertEqual( $response->get( 'version' ), '114.0' );
|
410 |
+
$this->assertEqual( $response->get( 'build' ), '2085867' );
|
411 |
+
|
412 |
+
// Payer Information
|
413 |
+
$mock_payer = (Object) array(
|
414 |
+
'email' => 'visa_1304648966_per@garyc40.com',
|
415 |
+
'id' => 'BC798KQ2QU22W',
|
416 |
+
'status' => 'verified',
|
417 |
+
'shipping_status' => 'Unconfirmed',
|
418 |
+
'first_name' => 'Test',
|
419 |
+
'last_name' => 'User',
|
420 |
+
'country' => 'US',
|
421 |
+
);
|
422 |
+
$this->assertEqual( $response->get( 'payer' ), $mock_payer );
|
423 |
+
|
424 |
+
// Shipping Address
|
425 |
+
$mock_shipping_address = array(
|
426 |
+
'name' => 'Gary Cao',
|
427 |
+
'street' => '1 Infinite Loop',
|
428 |
+
'street2' => 'Apple Headquarter',
|
429 |
+
'city' => 'Cupertino',
|
430 |
+
'state' => 'CA',
|
431 |
+
'zip' => '95014',
|
432 |
+
'country_code' => 'US',
|
433 |
+
'country' => 'United States',
|
434 |
+
'phone' => '(877) 412-7753',
|
435 |
+
);
|
436 |
+
$this->assertEqual( $response->get( 'shipping_address' ), $mock_shipping_address );
|
437 |
+
|
438 |
+
// Payment Information
|
439 |
+
$this->assertEqual( $response->get( 'currency' ), 'JPY' );
|
440 |
+
$this->assertEqual( $response->get( 'amount' ), 15337 );
|
441 |
+
$this->assertEqual( $response->get( 'subtotal' ), 13700 );
|
442 |
+
$this->assertEqual( $response->get( 'shipping' ), 1500 );
|
443 |
+
$this->assertEqual( $response->get( 'handling' ), 0 );
|
444 |
+
$this->assertEqual( $response->get( 'tax' ), 137 );
|
445 |
+
$this->assertEqual( $response->get( 'invoice' ), 'E84A90G94' );
|
446 |
+
$this->assertEqual( $response->get( 'notify_url' ), 'http://example.com/ipn' );
|
447 |
+
$this->assertEqual( $response->get( 'shipping_discount' ), 0 );
|
448 |
+
|
449 |
+
// Item Information
|
450 |
+
$items = $response->get( 'items' );
|
451 |
+
$mock_items = array();
|
452 |
+
|
453 |
+
$mock_items[0] = new stdClass();
|
454 |
+
$mock_items[0]->name = 'Gold Cart Plugin';
|
455 |
+
$mock_items[0]->description = 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.';
|
456 |
+
$mock_items[0]->amount = 4000;
|
457 |
+
$mock_items[0]->quantity = 1;
|
458 |
+
$mock_items[0]->tax = 40;
|
459 |
+
|
460 |
+
$mock_items[1] = new stdClass();
|
461 |
+
$mock_items[1]->name = 'Member Access Plugin';
|
462 |
+
$mock_items[1]->description = 'Create pay to view subscription sites';
|
463 |
+
$mock_items[1]->amount = 5000;
|
464 |
+
$mock_items[1]->quantity = 1;
|
465 |
+
$mock_items[1]->tax = 50;
|
466 |
+
|
467 |
+
$mock_items[2] = new stdClass();
|
468 |
+
$mock_items[2]->name = 'Amazon S3';
|
469 |
+
$mock_items[2]->description = 'This Plugin allows downloadable products on your WP eCommerce site to be hosted on Amazon S3.';
|
470 |
+
$mock_items[2]->amount = 4700;
|
471 |
+
$mock_items[2]->quantity = 1;
|
472 |
+
$mock_items[2]->tax = 47;
|
473 |
+
|
474 |
+
$this->assertEqual( $items, $mock_items );
|
475 |
+
}
|
476 |
+
|
477 |
+
public function test_correct_response_is_returned_when_set_express_checkout_fails() {
|
478 |
+
$mock_response = 'ACK=Failure&CORRELATIONID=224f0e4a32d14&TIMESTAMP=2011%2d07%2d05T13%253A23%253A52Z&VERSION=2%2e30000&BUILD=1%2e0006&TOKEN=EC%2d1OIN4UJGFOK54YFV&L_ERRORCODE0=10412&L_SHORTMESSAGE0=Duplicate%20invoice&L_LONGMESSAGE0=Payment%20has%20already%20been%20made%20for%20this%20InvoiceID.&L_SEVERITYCODE0=3&L_ERRORCODE1=10010&L_SHORTMESSAGE1=Invalid%20Invoice&L_LONGMESSAGE1=Non-ASCII%20invoice%20id%20is%20not%20supported.&L_SEVERITYCODE1=3';
|
479 |
+
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
480 |
+
$response = $this->bogus->setup_purchase( $this->setup_purchase_options );
|
481 |
+
|
482 |
+
$this->assertFalse( $response->is_successful() );
|
483 |
+
$this->assertTrue( $response->has_errors() );
|
484 |
+
$this->assertEqual( $response->get( 'timestamp' ), 1309872232 );
|
485 |
+
$this->assertEqual( $response->get( 'datetime' ), '2011-07-05T13:23:52Z' );
|
486 |
+
$this->assertEqual( $response->get( 'correlation_id' ), '224f0e4a32d14' );
|
487 |
+
$this->assertEqual( $response->get( 'version' ), '2.30000' );
|
488 |
+
$this->assertEqual( $response->get( 'build' ), '1.0006' );
|
489 |
+
|
490 |
+
$expected_errors = array(
|
491 |
+
array(
|
492 |
+
'code' => 10412,
|
493 |
+
'message' => 'Duplicate invoice',
|
494 |
+
'details' => 'Payment has already been made for this InvoiceID.',
|
495 |
+
),
|
496 |
+
|
497 |
+
array(
|
498 |
+
'code' => 10010,
|
499 |
+
'message' => 'Invalid Invoice',
|
500 |
+
'details' => 'Non-ASCII invoice id is not supported.',
|
501 |
+
),
|
502 |
+
);
|
503 |
+
$actual_errors = $response->get_errors();
|
504 |
+
$this->assertEqual( $actual_errors, $expected_errors );
|
505 |
+
}
|
506 |
+
|
507 |
+
public function test_correct_response_is_returned_when_set_express_checkout_is_successful_with_warning() {
|
508 |
+
$mock_response = 'ACK=SuccessWithWarning&CORRELATIONID=224f0e4a32d14&TIMESTAMP=2011%2d07%2d05T13%253A23%253A52Z&VERSION=2%2e30000&BUILD=1%2e0006&TOKEN=EC%2d1OIN4UJGFOK54YFV&L_ERRORCODE0=10412&L_SHORTMESSAGE0=Duplicate%20invoice&L_LONGMESSAGE0=Payment%20has%20already%20been%20made%20for%20this%20InvoiceID.&L_SEVERITYCODE0=3&L_ERRORCODE1=10010&L_SHORTMESSAGE1=Invalid%20Invoice&L_LONGMESSAGE1=Non-ASCII%20invoice%20id%20is%20not%20supported.&L_SEVERITYCODE1=3';
|
509 |
+
|
510 |
+
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
511 |
+
$response = $this->bogus->setup_purchase( $this->setup_purchase_options );
|
512 |
+
|
513 |
+
$this->assertTrue( $response->is_successful() );
|
514 |
+
$this->assertTrue( $response->has_errors() );
|
515 |
+
$this->assertEqual( $response->get( 'token' ), 'EC-1OIN4UJGFOK54YFV' );
|
516 |
+
$this->assertEqual( $response->get( 'timestamp' ), 1309872232 );
|
517 |
+
$this->assertEqual( $response->get( 'datetime' ), '2011-07-05T13:23:52Z' );
|
518 |
+
$this->assertEqual( $response->get( 'correlation_id' ), '224f0e4a32d14' );
|
519 |
+
$this->assertEqual( $response->get( 'version' ), '2.30000' );
|
520 |
+
$this->assertEqual( $response->get( 'build' ), '1.0006' );
|
521 |
+
|
522 |
+
$expected_errors = array(
|
523 |
+
array(
|
524 |
+
'code' => 10412,
|
525 |
+
'message' => 'Duplicate invoice',
|
526 |
+
'details' => 'Payment has already been made for this InvoiceID.',
|
527 |
+
),
|
528 |
+
|
529 |
+
array(
|
530 |
+
'code' => 10010,
|
531 |
+
'message' => 'Invalid Invoice',
|
532 |
+
'details' => 'Non-ASCII invoice id is not supported.',
|
533 |
+
),
|
534 |
+
);
|
535 |
+
$actual_errors = $response->get_errors();
|
536 |
+
$this->assertEqual( $actual_errors, $expected_errors );
|
537 |
+
|
538 |
+
}
|
539 |
+
}
|
540 |
+
|
541 |
+
require_once( PHP_MERCHANT_PATH . '/common/http-curl.php' );
|
542 |
+
Mock::generate( 'PHP_Merchant_HTTP_CURL' );
|
543 |
+
|
544 |
+
class PHP_Merchant_Paypal_Express_Checkout_Bogus extends PHP_Merchant_Paypal_Express_Checkout
|
545 |
+
{
|
546 |
+
public $http;
|
547 |
+
|
548 |
+
public function __construct( $options = array() ) {
|
549 |
+
$options['http_client'] = new MockPHP_Merchant_HTTP_CURL();
|
550 |
+
parent::__construct( $options );
|
551 |
+
}
|
552 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-ipn.php
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-ipn.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_IPN_Test extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $http;
|
8 |
+
|
9 |
+
public $ipn_request = array(
|
10 |
+
'mc_gross' => '-27.50',
|
11 |
+
'invoice' => '1411316760920',
|
12 |
+
'settle_amount' => '19.02',
|
13 |
+
'protection_eligibility' => 'Eligible',
|
14 |
+
'item_number1' => '',
|
15 |
+
'payer_id' => 'BC798KQ2QU22W',
|
16 |
+
'address_street' => '1 Main St',
|
17 |
+
'payment_date' => '00:06:09 Sep 23, 2011 PDT',
|
18 |
+
'payment_status' => 'Pending',
|
19 |
+
'charset' => 'windows-1252',
|
20 |
+
'address_zip' => '95131',
|
21 |
+
'mc_shipping' => '0.00',
|
22 |
+
'mc_handling' => '0.00',
|
23 |
+
'first_name' => 'Test',
|
24 |
+
'mc_fee' => '-1.25',
|
25 |
+
'address_country_code' => 'US',
|
26 |
+
'exchange_rate' => '0.724571',
|
27 |
+
'address_name' => 'Test User',
|
28 |
+
'notify_version' => '3.4',
|
29 |
+
'reason_code' => 'refund',
|
30 |
+
'settle_currency' => 'USD',
|
31 |
+
'custom' => '',
|
32 |
+
'address_country' => 'United States',
|
33 |
+
'mc_handling1' => '0.00',
|
34 |
+
'address_city' => 'San Jose',
|
35 |
+
'verify_sign' => 'An5ns1Kso7MWUdW4ErQKJJJ4qi4-AVcXYpICHDtcWk34bsCJQf7rc93o',
|
36 |
+
'payer_email' => 'visa_1304648966_per@garyc40.com',
|
37 |
+
'mc_shipping1' => '0.00',
|
38 |
+
'parent_txn_id' => '3BC81385RB1253259',
|
39 |
+
'txn_id' => '64B91482UD035471X',
|
40 |
+
'payment_type' => 'echeck',
|
41 |
+
'last_name' => 'User',
|
42 |
+
'address_state' => 'CA',
|
43 |
+
'item_name1' => 'Test Product',
|
44 |
+
'receiver_email' => 'pro_1304085877_biz@garyc40.com',
|
45 |
+
'payment_fee' => '',
|
46 |
+
'quantity1' => '1',
|
47 |
+
'receiver_id' => 'S2FHLPD5HHGMJ',
|
48 |
+
'pending_reason' => 'echeck',
|
49 |
+
'mc_gross_1' => '25.00',
|
50 |
+
'mc_currency' => 'NZD',
|
51 |
+
'residence_country' => 'US',
|
52 |
+
'test_ipn' => '1',
|
53 |
+
'transaction_subject' => '',
|
54 |
+
'payment_gross' => '',
|
55 |
+
'ipn_track_id' => 'qXFPBOM1pjBuIydRsesfyQ',
|
56 |
+
);
|
57 |
+
|
58 |
+
public function __construct() {
|
59 |
+
parent::__construct( 'PHP_Merchant_Paypal_IPN test cases' );
|
60 |
+
require_once( PHP_MERCHANT_PATH . '/common/http-curl.php' );
|
61 |
+
Mock::generate( 'PHP_Merchant_HTTP_CURL' );
|
62 |
+
}
|
63 |
+
|
64 |
+
public function test_correct_request_is_returned_to_IPN() {
|
65 |
+
$live_url = 'https://www.paypal.com/cgi-bin/webscr';
|
66 |
+
$sandbox_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
|
67 |
+
|
68 |
+
$verify_request = array( 'cmd' => '_notify-validate' );
|
69 |
+
$verify_request += $this->ipn_request;
|
70 |
+
|
71 |
+
// expects to send to Live URL and receive "VERIFIED" message from Paypal
|
72 |
+
$http = new MockPHP_Merchant_HTTP_CURL();
|
73 |
+
$http->returns( 'post', 'VERIFIED' );
|
74 |
+
$ipn = new PHP_Merchant_Paypal_IPN( $this->ipn_request, false, $http );
|
75 |
+
$http->expectOnce( 'post', array( $live_url, $verify_request ) ); // make sure $verify_request is constructed correctly
|
76 |
+
$this->assertTrue( $ipn->is_verified() );
|
77 |
+
|
78 |
+
// expects to send to Sandbox URL and receive "INVALID" message from Paypal
|
79 |
+
$http = new MockPHP_Merchant_HTTP_CURL();
|
80 |
+
$http->returns( 'post', 'INVALID' );
|
81 |
+
$ipn = new PHP_Merchant_Paypal_IPN( $this->ipn_request, true, $http );
|
82 |
+
$http->expectOnce( 'post', array( $sandbox_url, $verify_request ) ); // make sure $verify_request is constructed correctly
|
83 |
+
$this->assertFalse( $ipn->is_verified() );
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
class PHP_Merchant_Paypal_IPN_Bogus extends PHP_Merchant_Paypal_IPN
|
88 |
+
{
|
89 |
+
public $http;
|
90 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal.php
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Test extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $bogus;
|
8 |
+
|
9 |
+
public function __construct() {
|
10 |
+
parent::__construct( 'PHP_Merchant_Paypal test cases' );
|
11 |
+
}
|
12 |
+
|
13 |
+
public function setUp() {
|
14 |
+
$options = array(
|
15 |
+
'api_username' => 'sdk-three_api1.sdk.com',
|
16 |
+
'api_password' => 'QFZCWN5HZM8VBG7Q',
|
17 |
+
'api_signature' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
18 |
+
);
|
19 |
+
$this->bogus = new PHP_Merchant_Paypal_Bogus( $options );
|
20 |
+
}
|
21 |
+
|
22 |
+
public function test_api_credentials_are_properly_generated() {
|
23 |
+
$params = array(
|
24 |
+
'USER' => 'sdk-three_api1.sdk.com',
|
25 |
+
'PWD' => 'QFZCWN5HZM8VBG7Q',
|
26 |
+
'VERSION' => '114.0',
|
27 |
+
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
28 |
+
);
|
29 |
+
$this->assertEqual( $this->bogus->add_credentials(), $params );
|
30 |
+
}
|
31 |
+
|
32 |
+
public function test_check_whether_currency_is_supported_by_paypal() {
|
33 |
+
$supported = array(
|
34 |
+
'AUD',
|
35 |
+
'BRL',
|
36 |
+
'CAD',
|
37 |
+
'CHF',
|
38 |
+
'CZK',
|
39 |
+
'DKK',
|
40 |
+
'EUR',
|
41 |
+
'GBP',
|
42 |
+
'HKD',
|
43 |
+
'HUF',
|
44 |
+
'ILS',
|
45 |
+
'JPY',
|
46 |
+
'MXN',
|
47 |
+
'MYR',
|
48 |
+
'NOK',
|
49 |
+
'NZD',
|
50 |
+
'PHP',
|
51 |
+
'PLN',
|
52 |
+
'SEK',
|
53 |
+
'SGD',
|
54 |
+
'THB',
|
55 |
+
'TWD',
|
56 |
+
'USD',
|
57 |
+
);
|
58 |
+
|
59 |
+
$this->assertEqual( $supported, PHP_Merchant_Paypal_Bogus::get_supported_currencies() );
|
60 |
+
|
61 |
+
foreach ( $supported as $currency ) {
|
62 |
+
$this->assertTrue( PHP_Merchant_Paypal_Bogus::is_currency_supported( $currency ) );
|
63 |
+
}
|
64 |
+
|
65 |
+
$this->assertFalse( PHP_Merchant_Paypal_Bogus::is_currency_supported( 'ZAR' ) );
|
66 |
+
}
|
67 |
+
|
68 |
+
public function test_build_request_function_correctly_handles_custom_request_array() {
|
69 |
+
$additional_params = array(
|
70 |
+
'PAYMENTREQUEST_0_SHIPTONAME' => 'Gary Cao',
|
71 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET' => '1 Infinite Loop',
|
72 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Apple Headquarter',
|
73 |
+
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Cupertino',
|
74 |
+
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'CA',
|
75 |
+
'PAYMENTREQUEST_0_SHIPTOZIP' => '95014',
|
76 |
+
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
|
77 |
+
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '(877) 412-7753',
|
78 |
+
);
|
79 |
+
|
80 |
+
$full_param_list = array(
|
81 |
+
'USER' => 'sdk-three_api1.sdk.com',
|
82 |
+
'PWD' => 'QFZCWN5HZM8VBG7Q',
|
83 |
+
'VERSION' => '114.0',
|
84 |
+
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
85 |
+
'METHOD' => 'SetExpressCheckout',
|
86 |
+
|
87 |
+
'PAYMENTREQUEST_0_SHIPTONAME' => 'Gary Cao',
|
88 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET' => '1 Infinite Loop',
|
89 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Apple Headquarter',
|
90 |
+
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Cupertino',
|
91 |
+
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'CA',
|
92 |
+
'PAYMENTREQUEST_0_SHIPTOZIP' => '95014',
|
93 |
+
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
|
94 |
+
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '(877) 412-7753',
|
95 |
+
);
|
96 |
+
|
97 |
+
$request = $this->bogus->build_request( 'SetExpressCheckout', $additional_params );
|
98 |
+
$this->assertEqual( $request, $full_param_list );
|
99 |
+
}
|
100 |
+
|
101 |
+
public function test_get_url_returns_sandbox_url_when_in_test_mode() {
|
102 |
+
$this->bogus->set_option( 'test', true );
|
103 |
+
$this->assertEqual( $this->bogus->get_url(), 'https://api-3t.sandbox.paypal.com/nvp' );
|
104 |
+
}
|
105 |
+
|
106 |
+
public function test_get_url_returns_live_url_when_in_live_mode() {
|
107 |
+
$this->assertEqual( $this->bogus->get_url(), 'https://api-3t.paypal.com/nvp' );
|
108 |
+
|
109 |
+
$this->bogus->set_option( 'test', false );
|
110 |
+
$this->assertEqual( $this->bogus->get_url(), 'https://api-3t.paypal.com/nvp' );
|
111 |
+
}
|
112 |
+
}
|
113 |
+
|
114 |
+
class PHP_Merchant_Paypal_Bogus extends PHP_Merchant_Paypal
|
115 |
+
{
|
116 |
+
public $request = array();
|
117 |
+
|
118 |
+
public function add_credentials() {
|
119 |
+
return parent::add_credentials();
|
120 |
+
}
|
121 |
+
|
122 |
+
public function build_request( $action = '', $request = array() ) {
|
123 |
+
return parent::build_request( $action, $request );
|
124 |
+
}
|
125 |
+
|
126 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/index.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Check for Remote Tests
|
3 |
+
global $remote;
|
4 |
+
global $argv;
|
5 |
+
$remote = false;
|
6 |
+
if ( in_array( '--enable-remote', $argv ) || ! empty( $_GET['remote'] ) ) {
|
7 |
+
$remote = true;
|
8 |
+
}
|
9 |
+
if ( $remote ) {
|
10 |
+
require_once( 'simpletest/web_tester.php' );
|
11 |
+
require_once( 'common/test-accounts.php' );
|
12 |
+
}
|
13 |
+
|
14 |
+
require_once( 'simpletest/varlog.php' );
|
15 |
+
require_once( 'simpletest/autorun.php' );
|
16 |
+
|
17 |
+
define( 'PHP_MERCHANT_PATH', realpath( '../' ) );
|
18 |
+
define( 'PHP_MERCHANT_TEST_PATH', dirname( __FILE__ ) );
|
19 |
+
|
20 |
+
class PHP_Merchant_Test_Suite extends TestSuite
|
21 |
+
{
|
22 |
+
function __construct() {
|
23 |
+
global $remote;
|
24 |
+
parent::__construct( 'PHP Merchant Test Suite' );
|
25 |
+
$tests = array(
|
26 |
+
'common/php-merchant',
|
27 |
+
'common/http-curl',
|
28 |
+
'gateways/paypal',
|
29 |
+
'gateways/paypal-express-checkout',
|
30 |
+
'gateways/paypal-ipn',
|
31 |
+
);
|
32 |
+
|
33 |
+
// Since we are running the SimpleTest Tests from the command-line,
|
34 |
+
// we are adding a command-line key for remote tests
|
35 |
+
if ( $remote ) {
|
36 |
+
$tests = array_merge( $tests, array(
|
37 |
+
'remote/http-curl',
|
38 |
+
'remote/paypal-express-checkout',
|
39 |
+
'remote/paypal-ec-cert-x1',
|
40 |
+
'remote/paypal-ec-cert-x2',
|
41 |
+
'remote/paypal-ec-cert-x3',
|
42 |
+
'remote/paypal-ec-cert-x4',
|
43 |
+
'remote/paypal-ec-cert-x5',
|
44 |
+
'remote/paypal-ec-cert-x6',
|
45 |
+
'remote/paypal-dg-cert-x1',
|
46 |
+
'remote/paypal-dg-cert-x2',
|
47 |
+
'remote/paypal-dg-cert-x3',
|
48 |
+
'remote/paypal-dg-cert-x4',
|
49 |
+
'remote/paypal-pro-cert-x1',
|
50 |
+
'remote/paypal-pro-cert-x2',
|
51 |
+
) );
|
52 |
+
}
|
53 |
+
|
54 |
+
$dir = dirname( __FILE__ );
|
55 |
+
|
56 |
+
foreach ( $tests as $test ) {
|
57 |
+
$this->addFile( $dir . '/' . $test . '.php' );
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/http-curl.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/common/http-curl.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_HTTP_CURL_Remote_Test extends WebTestCase
|
6 |
+
{
|
7 |
+
public function __construct() {
|
8 |
+
parent::__construct( 'PHP_Merchant_HTTP_CURL Remote Unit Tests' );
|
9 |
+
}
|
10 |
+
|
11 |
+
public function test_http_curl_get_request_returns_correct_response() {
|
12 |
+
$expected_content = "c7194f7e74fedaf84525235d3b37c203\n";
|
13 |
+
|
14 |
+
$http = new PHP_Merchant_HTTP_CURL();
|
15 |
+
$actual_content = $http->get( 'https://raw.githubusercontent.com/wp-e-commerce/Science-Repository/master/json' );
|
16 |
+
$this->assertEqual( $expected_content, $actual_content );
|
17 |
+
}
|
18 |
+
|
19 |
+
public function test_http_curl_post_request_returns_correct_response() {
|
20 |
+
$expected_content = "key_1 => value 1\ntest_another_key => value 2\n";
|
21 |
+
|
22 |
+
$http = new PHP_Merchant_HTTP_CURL();
|
23 |
+
$actual_content = $http->post( 'https://raw.githubusercontent.com/wp-e-commerce/Science-Repository/master/post', array(
|
24 |
+
'key 1' => 'value 1',
|
25 |
+
'test another key' => 'value 2',
|
26 |
+
) );
|
27 |
+
$this->assertEqual( $expected_content, $actual_content );
|
28 |
+
}
|
29 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x1.php
ADDED
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-digital-goods.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Digital_Goods_Certification_Test_X1 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Digital_Goods test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Digital_Goods( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 1.01
|
80 |
+
*
|
81 |
+
* Standard Fields Test
|
82 |
+
*
|
83 |
+
* @return void
|
84 |
+
* @since 3.9
|
85 |
+
*/
|
86 |
+
public function test_setexpresscheckout_standard_ref101() {
|
87 |
+
// Call SetExpressCheckout
|
88 |
+
$options = is_array( $this->purchase_options ) ? $this->purchase_options : array();
|
89 |
+
$response = $this->gateway->setup_purchase( $options, 'Sale' );
|
90 |
+
|
91 |
+
$this->assertTrue( $response->is_successful() );
|
92 |
+
|
93 |
+
// Display the transaction Id
|
94 |
+
st_echo('Test Case 1.01: ' . $response->get( 'token' ) . "\n" );
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Test Case Reference 1.02
|
99 |
+
*
|
100 |
+
* No Shipping
|
101 |
+
*
|
102 |
+
* @return void
|
103 |
+
* @since 3.9
|
104 |
+
*/
|
105 |
+
public function test_setexpresscheckout_standard_ref102() {
|
106 |
+
// Max Amount
|
107 |
+
$this->purchase_options['no_shipping'] = true;
|
108 |
+
|
109 |
+
// Call SetExpressCheckout
|
110 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
111 |
+
|
112 |
+
$this->assertTrue( $response->is_successful() );
|
113 |
+
|
114 |
+
// Display the transaction Id
|
115 |
+
st_echo('Test Case 1.02: ' . $response->get( 'token' ) . "\n" );
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Test Case Reference 1.03
|
120 |
+
*
|
121 |
+
* @return void
|
122 |
+
* @since 3.9
|
123 |
+
*/
|
124 |
+
public function test_setexpresscheckout_standard_ref103() {
|
125 |
+
// Shipping Details
|
126 |
+
$this->purchase_options['shipping_address'] = array(
|
127 |
+
'name' => 'Abid Omar',
|
128 |
+
'street' => '',
|
129 |
+
'street2' => '',
|
130 |
+
'city' => 'Cupertino',
|
131 |
+
'state' => 'CA',
|
132 |
+
'country' => 'US',
|
133 |
+
'zip' => '95014',
|
134 |
+
'phone' => '(877) 412-7753',
|
135 |
+
);
|
136 |
+
|
137 |
+
// Call SetExpressCheckout
|
138 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
139 |
+
|
140 |
+
$this->assertFalse( $response->is_successful() );
|
141 |
+
|
142 |
+
// Display the transaction Id
|
143 |
+
$error = $response->get_error();
|
144 |
+
st_echo( 'Test Case 1.03: ' . $response->get( 'correlation_id' ) . ' - ' . $error['details'] . "\n" );
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Test Case Reference 1.04
|
149 |
+
*
|
150 |
+
* @return void
|
151 |
+
* @since 3.9
|
152 |
+
*/
|
153 |
+
public function test_setexpresscheckout_standard_ref104() {
|
154 |
+
// Shipping Details
|
155 |
+
$this->purchase_options['shipping_address'] = array(
|
156 |
+
'name' => 'Abid Omar',
|
157 |
+
'street' => '1 Infinite Loop',
|
158 |
+
'street2' => 'Apple Headquarter',
|
159 |
+
'city' => '',
|
160 |
+
'state' => 'CA',
|
161 |
+
'country' => 'US',
|
162 |
+
'zip' => '95014',
|
163 |
+
'phone' => '(877) 412-7753',
|
164 |
+
);
|
165 |
+
|
166 |
+
// Call SetExpressCheckout
|
167 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
168 |
+
|
169 |
+
$this->assertFalse( $response->is_successful() );
|
170 |
+
|
171 |
+
// Display the transaction Id
|
172 |
+
$error = $response->get_error();
|
173 |
+
st_echo( 'Test Case 1.04: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Test Case Reference 1.05
|
178 |
+
*
|
179 |
+
* @return void
|
180 |
+
* @since 3.9
|
181 |
+
*/
|
182 |
+
public function test_setexpresscheckout_standard_ref105() {
|
183 |
+
// Shipping Details
|
184 |
+
$this->purchase_options['shipping_address'] = array(
|
185 |
+
'name' => 'Abid Omar',
|
186 |
+
'street' => '1 Infinite Loop',
|
187 |
+
'street2' => 'Apple Headquarter',
|
188 |
+
'city' => 'Cupertino',
|
189 |
+
'state' => '',
|
190 |
+
'country' => 'US',
|
191 |
+
'zip' => '95014',
|
192 |
+
'phone' => '(877) 412-7753',
|
193 |
+
);
|
194 |
+
|
195 |
+
// Call SetExpressCheckout
|
196 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
197 |
+
|
198 |
+
$this->assertFalse( $response->is_successful() );
|
199 |
+
|
200 |
+
// Display the transaction Id
|
201 |
+
$error = $response->get_error();
|
202 |
+
st_echo( 'Test Case 1.05: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Test Case Reference 1.06
|
207 |
+
*
|
208 |
+
* @return void
|
209 |
+
* @since 3.9
|
210 |
+
*/
|
211 |
+
public function test_setexpresscheckout_standard_ref106() {
|
212 |
+
// Shipping Details
|
213 |
+
$this->purchase_options['shipping_address'] = array(
|
214 |
+
'name' => 'Abid Omar',
|
215 |
+
'street' => '1 Infinite Loop',
|
216 |
+
'street2' => 'Apple Headquarter',
|
217 |
+
'city' => 'Cupertino',
|
218 |
+
'state' => 'CA',
|
219 |
+
'country' => 'US',
|
220 |
+
'zip' => '',
|
221 |
+
'phone' => '(877) 412-7753',
|
222 |
+
);
|
223 |
+
|
224 |
+
// Call SetExpressCheckout
|
225 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
226 |
+
|
227 |
+
$this->assertFalse( $response->is_successful() );
|
228 |
+
|
229 |
+
// Display the transaction Id
|
230 |
+
$error = $response->get_error();
|
231 |
+
st_echo( 'Test Case 1.06: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Test Case Reference 1.07
|
236 |
+
*
|
237 |
+
* @return void
|
238 |
+
* @since 3.9
|
239 |
+
*/
|
240 |
+
public function test_setexpresscheckout_standard_ref107() {
|
241 |
+
// Shipping Details
|
242 |
+
$this->purchase_options['shipping_address'] = array(
|
243 |
+
'name' => 'Abid Omar',
|
244 |
+
'street' => '1 Infinite Loop',
|
245 |
+
'street2' => 'Apple Headquarter',
|
246 |
+
'city' => 'Cupertino',
|
247 |
+
'state' => 'CA',
|
248 |
+
'country' => '',
|
249 |
+
'zip' => '95014',
|
250 |
+
'phone' => '(877) 412-7753',
|
251 |
+
);
|
252 |
+
|
253 |
+
// Call SetExpressCheckout
|
254 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
255 |
+
|
256 |
+
$this->assertFalse( $response->is_successful() );
|
257 |
+
|
258 |
+
// Display the transaction Id
|
259 |
+
$error = $response->get_error();
|
260 |
+
st_echo( 'Test Case 1.07: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Test Case Reference 1.08
|
265 |
+
*
|
266 |
+
* @return void
|
267 |
+
* @since 3.9
|
268 |
+
*/
|
269 |
+
public function test_setexpresscheckout_standard_ref108() {
|
270 |
+
// Shipping Details
|
271 |
+
$this->purchase_options['shipping_address'] = array(
|
272 |
+
'name' => 'Abid Omar',
|
273 |
+
'street' => '123 Any Street',
|
274 |
+
'street2' => '',
|
275 |
+
'city' => 'New York',
|
276 |
+
'state' => 'NY',
|
277 |
+
'country' => 'US',
|
278 |
+
'zip' => '90210',
|
279 |
+
'phone' => '(877) 412-7753',
|
280 |
+
);
|
281 |
+
|
282 |
+
// Call SetExpressCheckout
|
283 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
284 |
+
|
285 |
+
$this->assertFalse( $response->is_successful() );
|
286 |
+
|
287 |
+
// Display the transaction Id
|
288 |
+
$error = $response->get_error();
|
289 |
+
st_echo( 'Test Case 1.08: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
290 |
+
}
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Test Case Reference 1.09
|
294 |
+
*
|
295 |
+
* @return void
|
296 |
+
* @since 3.9
|
297 |
+
*/
|
298 |
+
public function test_setexpresscheckout_standard_ref109() {
|
299 |
+
// Negative Testing
|
300 |
+
$this->purchase_options['subtotal'] = 100.01;
|
301 |
+
$this->purchase_options['shipping'] = 0;
|
302 |
+
$this->purchase_options['tax'] = 0;
|
303 |
+
$this->purchase_options['amount'] = 100.01;
|
304 |
+
$this->purchase_options['max_amount'] = 100.01;
|
305 |
+
$this->purchase_options['items'] = array();
|
306 |
+
|
307 |
+
// Call SetExpressCheckout
|
308 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
309 |
+
|
310 |
+
$this->assertFalse( $response->is_successful() );
|
311 |
+
|
312 |
+
// Display the transaction Id
|
313 |
+
$error = $response->get_error();
|
314 |
+
st_echo( 'Test Case 1.09: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
315 |
+
}
|
316 |
+
|
317 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x2.php
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-digital-goods.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Digital_Goods_Certification_Test_X2 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Digital_Goods test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Digital_Goods( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 2.1
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
* @since 3.9
|
83 |
+
*/
|
84 |
+
public function test_doexpresscheckout_ref21() {
|
85 |
+
// Using the Token and Payer Id for another transaction
|
86 |
+
$token = 'EC-9HN89702CD731133X';
|
87 |
+
|
88 |
+
// Call DoExpressCheckout
|
89 |
+
$response = $this->gateway->get_details_for( $token );
|
90 |
+
|
91 |
+
$this->assertTrue( $response->is_successful() );
|
92 |
+
|
93 |
+
// Display the Transaction Id
|
94 |
+
st_echo( 'Test Case 2.1: ' . $response->get( 'correlation_id' ) . "\n" );
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Test Case Reference 2.2
|
99 |
+
*
|
100 |
+
* @return void
|
101 |
+
* @since 3.9
|
102 |
+
*/
|
103 |
+
public function test_doexpresscheckout_ref22() {
|
104 |
+
// Using the Token and Payer Id for another transaction
|
105 |
+
$transaction_id = '10001';
|
106 |
+
|
107 |
+
// Call DoExpressCheckout
|
108 |
+
$response = $this->gateway->get_transaction_details( $transaction_id );
|
109 |
+
|
110 |
+
$this->assertFalse( $response->is_successful() );
|
111 |
+
|
112 |
+
// Display the Transaction Id
|
113 |
+
st_echo( 'Test Case 2.2: ' . $response->get( 'correlation_id' ) . "\n" );
|
114 |
+
}
|
115 |
+
|
116 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x3.php
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-digital-goods.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Digital_Goods_Certification_Test_X3 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Digital_Goods( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 3.1
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
* @since 3.9
|
83 |
+
*/
|
84 |
+
public function test_doexpresscheckout_ref31() {
|
85 |
+
// Using the Token and Payer Id for another transaction
|
86 |
+
$this->purchase_options['token'] = 'EC-3W674134AM197213K';
|
87 |
+
$this->purchase_options['payer_id'] = 'FQQ7Q9EVPAB86';
|
88 |
+
|
89 |
+
// Call DoExpressCheckout
|
90 |
+
$response = $this->gateway->purchase( $this->purchase_options );
|
91 |
+
|
92 |
+
$this->assertTrue( $response->is_successful() );
|
93 |
+
|
94 |
+
// Display the Transaction Id
|
95 |
+
st_echo( 'Test Case 3.1: ' . $response->get( 'transaction_id' ) . "\n" );
|
96 |
+
st_echo( 'Test Case 3.2: ' . $response->get( 'transaction_id' ) . "\n" );
|
97 |
+
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Test Case Reference 3.3
|
102 |
+
*
|
103 |
+
* @return void
|
104 |
+
* @since 3.9
|
105 |
+
*/
|
106 |
+
public function test_doexpresscheckout_ref33() {
|
107 |
+
// Negative Testing
|
108 |
+
$this->purchase_options['subtotal'] = 100.01;
|
109 |
+
$this->purchase_options['shipping'] = 0;
|
110 |
+
$this->purchase_options['tax'] = 0;
|
111 |
+
$this->purchase_options['amount'] = 100.01;
|
112 |
+
$this->purchase_options['max_amount'] = 100.01;
|
113 |
+
$this->purchase_options['items'] = array();
|
114 |
+
|
115 |
+
// Using the Token and Payer Id for another transaction
|
116 |
+
$this->purchase_options['token'] = 'EC-3W674134AM197213K';
|
117 |
+
$this->purchase_options['payer_id'] = 'FQQ7Q9EVPAB86';
|
118 |
+
|
119 |
+
// Call DoExpressCheckout
|
120 |
+
$response = $this->gateway->purchase( $this->purchase_options );
|
121 |
+
|
122 |
+
$this->assertFalse( $response->is_successful() );
|
123 |
+
|
124 |
+
// Display the Transaction Id
|
125 |
+
st_echo( 'Test Case 3.3: ' . $response->get( 'correlation_id' ) . "\n" );
|
126 |
+
}
|
127 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-dg-cert-x4.php
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-digital-goods.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Digital_Goods_Certification_Test_X4 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Digital_Goods test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
/*
|
27 |
+
'amount' => 15.337,
|
28 |
+
'subtotal' => 13.700,
|
29 |
+
'shipping' => 1.500,
|
30 |
+
'tax' => 0.137,
|
31 |
+
*/
|
32 |
+
'description' => 'A sample order',
|
33 |
+
'invoice' => $inv,
|
34 |
+
'notify_url' => 'http://example.com/ipn',
|
35 |
+
|
36 |
+
// Items
|
37 |
+
'items' => array(
|
38 |
+
array(
|
39 |
+
'name' => 'Gold Cart Plugin',
|
40 |
+
'description' => 'Gold Cart extends your WP e-Commerce store by enabling additional features and functionality.',
|
41 |
+
'amount' => 4,
|
42 |
+
'quantity' => 1,
|
43 |
+
'tax' => 0.040,
|
44 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
45 |
+
'number' => '7A12343-WHT-XL',
|
46 |
+
),
|
47 |
+
array(
|
48 |
+
'name' => 'Member Access Plugin',
|
49 |
+
'description' => 'Create pay to view subscription sites',
|
50 |
+
'amount' => 5,
|
51 |
+
'quantity' => 1,
|
52 |
+
'tax' => 0.05,
|
53 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
54 |
+
'number' => '7A12344-WHT-XL',
|
55 |
+
),
|
56 |
+
array(
|
57 |
+
'name' => 'Amazon S3',
|
58 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP e-Commerce site to be hosted within Amazon S3.',
|
59 |
+
'amount' => 4.7,
|
60 |
+
'quantity' => 1,
|
61 |
+
'tax' => 0.047,
|
62 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
63 |
+
'number' => '7A12345-WHT-XL',
|
64 |
+
),
|
65 |
+
),
|
66 |
+
);
|
67 |
+
}
|
68 |
+
|
69 |
+
public function setUp() {
|
70 |
+
global $test_accounts;
|
71 |
+
$this->gateway = new PHP_Merchant_Paypal_Digital_Goods( $test_accounts['paypal-ec-oa'] );
|
72 |
+
$this->purchase_options = $this->default_options;
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
public function tearDown() {
|
77 |
+
$this->purchase_options = null;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Test Case Reference 4.1
|
82 |
+
*
|
83 |
+
* @return void
|
84 |
+
* @since 3.9
|
85 |
+
*/
|
86 |
+
public function test_doexpresscheckout_ref41() {
|
87 |
+
/*
|
88 |
+
$this->purchase_options['token'] = 'EC-6YT23592N88199745';
|
89 |
+
$this->purchase_options['message_id'] = 'abcedfght';
|
90 |
+
$this->purchase_options['invoice'] = 'E84A90G811';
|
91 |
+
$this->purchase_options['transaction_id'] = '91E227400G099735F';
|
92 |
+
|
93 |
+
$response = $this->gateway->credit( $this->purchase_options );
|
94 |
+
$this->assertTrue( $response->is_successful() );
|
95 |
+
st_log( $response );
|
96 |
+
*/
|
97 |
+
|
98 |
+
// Fully Refunded Transaction
|
99 |
+
$response = $this->gateway->get_transaction_details( '91E227400G099735F' );
|
100 |
+
|
101 |
+
$this->assertTrue( $response->is_successful() );
|
102 |
+
st_echo( 'Test Case 4.1:' . "\n" );
|
103 |
+
st_echo( 'Transaction ID: 91E227400G099735F' . "\n" );
|
104 |
+
st_echo( 'Payment Status: ' . $response->get_params()['PAYMENTSTATUS'] . "\n" );
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Test Case Reference 4.2
|
109 |
+
*
|
110 |
+
* @return void
|
111 |
+
* @since 3.9
|
112 |
+
*/
|
113 |
+
public function test_doexpresscheckout_ref42() {
|
114 |
+
/*
|
115 |
+
$this->purchase_options['token'] = 'EC-8AU95879WD9646218';
|
116 |
+
$this->purchase_options['message_id'] = 'abcedfghkk';
|
117 |
+
$this->purchase_options['invoice'] = 'E84A90G555';
|
118 |
+
$this->purchase_options['transaction_id'] = '2WH811268W276704P';
|
119 |
+
$this->purchase_options['refund_type'] = 'partial';
|
120 |
+
$this->purchase_options['amount'] = 6.5;
|
121 |
+
|
122 |
+
// Call DoExpressCheckout 8P404440G06461422
|
123 |
+
$response = $this->gateway->credit( $this->purchase_options );
|
124 |
+
|
125 |
+
|
126 |
+
$this->assertTrue( $response->is_successful() );
|
127 |
+
st_log( $response );
|
128 |
+
*/
|
129 |
+
|
130 |
+
// Fully Refunded Transaction
|
131 |
+
$response = $this->gateway->get_transaction_details( '2WH811268W276704P' );
|
132 |
+
|
133 |
+
$this->assertTrue( $response->is_successful() );
|
134 |
+
st_echo( 'Test Case 4.2:' . "\n" );
|
135 |
+
st_echo( 'Transaction ID: 2WH811268W276704P' . "\n" );
|
136 |
+
st_echo( 'Payment Status: ' . $response->get_params()['PAYMENTSTATUS'] . "\n" );
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Test Case Reference 4.3
|
141 |
+
*
|
142 |
+
* @return void
|
143 |
+
* @since 3.9
|
144 |
+
*/
|
145 |
+
public function test_doexpresscheckout_ref43() {
|
146 |
+
$this->purchase_options['token'] = 'EC-8AU95879WD9646218';
|
147 |
+
$this->purchase_options['message_id'] = 'abcedfghkk';
|
148 |
+
$this->purchase_options['invoice'] = 'E84A90G555';
|
149 |
+
$this->purchase_options['transaction_id'] = '2WH811268W276704P';
|
150 |
+
$this->purchase_options['amount'] = 100.01;
|
151 |
+
|
152 |
+
// Call DoRefund
|
153 |
+
$response = $this->gateway->credit( $this->purchase_options );
|
154 |
+
|
155 |
+
$this->assertFalse( $response->is_successful() );
|
156 |
+
|
157 |
+
// Display the Transaction Id
|
158 |
+
st_echo( 'Test Case 4.3: ' . $response->get( 'correlation_id' ) . "\n" );
|
159 |
+
|
160 |
+
|
161 |
+
}
|
162 |
+
|
163 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x1.php
ADDED
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Certification_Test_X1 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 1.01
|
80 |
+
*
|
81 |
+
* Standard Fields Test
|
82 |
+
*
|
83 |
+
* @return void
|
84 |
+
* @since 3.9
|
85 |
+
*/
|
86 |
+
public function test_setexpresscheckout_standard_ref101() {
|
87 |
+
// Call SetExpressCheckout
|
88 |
+
$options = is_array( $this->purchase_options ) ? $this->purchase_options : array();
|
89 |
+
$response = $this->gateway->setup_purchase( $options );
|
90 |
+
|
91 |
+
$this->assertTrue( $response->is_successful() );
|
92 |
+
|
93 |
+
// Display the transaction Id
|
94 |
+
st_echo('Test Case 1.01: ' . $response->get( 'token' ) . "\n" );
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Test Case Reference 1.02
|
99 |
+
*
|
100 |
+
* @return void
|
101 |
+
* @since 3.9
|
102 |
+
*/
|
103 |
+
public function test_setexpresscheckout_standard_ref102() {
|
104 |
+
// Shipping Details
|
105 |
+
$this->purchase_options['shipping_address'] = array(
|
106 |
+
'name' => 'Abid Omar',
|
107 |
+
'street' => '1 Infinite Loop',
|
108 |
+
'street2' => 'Apple Headquarter ext',
|
109 |
+
'city' => 'Cupertino',
|
110 |
+
'state' => 'CA',
|
111 |
+
'country' => 'US',
|
112 |
+
'zip' => '95014',
|
113 |
+
'phone' => '(877) 412-7753',
|
114 |
+
);
|
115 |
+
|
116 |
+
// Call SetExpressCheckout
|
117 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
118 |
+
|
119 |
+
$this->assertTrue( $response->is_successful() );
|
120 |
+
|
121 |
+
// Display the transaction Id
|
122 |
+
st_echo('Test Case 1.02: ' . $response->get( 'token' ) . "\n" );
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Test Case Reference 1.03
|
127 |
+
*
|
128 |
+
* @return void
|
129 |
+
* @since 3.9
|
130 |
+
*/
|
131 |
+
public function test_setexpresscheckout_standard_ref103() {
|
132 |
+
// Max Amount
|
133 |
+
$this->purchase_options['max_amount'] = 15.9;
|
134 |
+
$this->purchase_options['solution_type'] = 'Mark';
|
135 |
+
|
136 |
+
// Call SetExpressCheckout
|
137 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
138 |
+
|
139 |
+
$this->assertTrue( $response->is_successful() );
|
140 |
+
|
141 |
+
// Display the transaction Id
|
142 |
+
st_echo('Test Case 1.03: ' . $response->get( 'token' ) . "\n" );
|
143 |
+
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Test Case Reference 1.04
|
148 |
+
*
|
149 |
+
* @return void
|
150 |
+
* @since 3.9
|
151 |
+
*/
|
152 |
+
public function test_setexpresscheckout_standard_ref104() {
|
153 |
+
// Max Amount
|
154 |
+
$this->purchase_options['max_amount'] = 15.9;
|
155 |
+
$this->purchase_options['solution_type'] = 'Sole';
|
156 |
+
|
157 |
+
// Call SetExpressCheckout
|
158 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
159 |
+
|
160 |
+
$this->assertTrue( $response->is_successful() );
|
161 |
+
|
162 |
+
// Display the transaction Id
|
163 |
+
st_echo('Test Case 1.04: ' . $response->get( 'token' ) . "\n" );
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Test Case Reference 1.05
|
168 |
+
*
|
169 |
+
* @return void
|
170 |
+
* @since 3.9
|
171 |
+
*/
|
172 |
+
public function test_setexpresscheckout_standard_ref105() {
|
173 |
+
// Max Amount
|
174 |
+
$this->purchase_options['no_shipping'] = true;
|
175 |
+
|
176 |
+
// Call SetExpressCheckout
|
177 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
178 |
+
|
179 |
+
$this->assertTrue( $response->is_successful() );
|
180 |
+
|
181 |
+
// Display the transaction Id
|
182 |
+
st_echo('Test Case 1.05: ' . $response->get( 'token' ) . "\n" );
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Test Case Reference 1.06
|
187 |
+
*
|
188 |
+
* @return void
|
189 |
+
* @since 3.9
|
190 |
+
*/
|
191 |
+
public function test_setexpresscheckout_standard_ref106() {
|
192 |
+
// Billing Agreement description
|
193 |
+
$this->purchase_options['billing_type'] = 'MerchantInitiatedBillingSingleAgreement';
|
194 |
+
$this->purchase_options['billing_description'] = 'One Time Payment';
|
195 |
+
|
196 |
+
// Call SetExpressCheckout
|
197 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
198 |
+
|
199 |
+
$this->assertTrue( $response->is_successful() );
|
200 |
+
|
201 |
+
// Display the transaction Id
|
202 |
+
st_echo('Test Case 1.06: ' . $response->get( 'token' ) . "\n" );
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Test Case Reference 1.08
|
207 |
+
*
|
208 |
+
* @return void
|
209 |
+
* @since 3.9
|
210 |
+
*/
|
211 |
+
public function test_setexpresscheckout_standard_ref108() {
|
212 |
+
// Shipping Details
|
213 |
+
$this->purchase_options['shipping_address'] = array(
|
214 |
+
'name' => 'Abid Omar',
|
215 |
+
'street' => '',
|
216 |
+
'street2' => '',
|
217 |
+
'city' => 'Cupertino',
|
218 |
+
'state' => 'CA',
|
219 |
+
'country' => 'US',
|
220 |
+
'zip' => '95014',
|
221 |
+
'phone' => '(877) 412-7753',
|
222 |
+
);
|
223 |
+
|
224 |
+
// Call SetExpressCheckout
|
225 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
226 |
+
|
227 |
+
$this->assertFalse( $response->is_successful() );
|
228 |
+
|
229 |
+
// Display the transaction Id
|
230 |
+
$error = $response->get_error();
|
231 |
+
st_echo( 'Test Case 1.08: ' . $response->get( 'correlation_id' ) . ' - ' . $error['details'] . "\n" );
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Test Case Reference 1.09
|
236 |
+
*
|
237 |
+
* @return void
|
238 |
+
* @since 3.9
|
239 |
+
*/
|
240 |
+
public function test_setexpresscheckout_standard_ref109() {
|
241 |
+
// Shipping Details
|
242 |
+
$this->purchase_options['shipping_address'] = array(
|
243 |
+
'name' => 'Abid Omar',
|
244 |
+
'street' => '1 Infinite Loop',
|
245 |
+
'street2' => 'Apple Headquarter',
|
246 |
+
'city' => '',
|
247 |
+
'state' => 'CA',
|
248 |
+
'country' => 'US',
|
249 |
+
'zip' => '95014',
|
250 |
+
'phone' => '(877) 412-7753',
|
251 |
+
);
|
252 |
+
|
253 |
+
// Call SetExpressCheckout
|
254 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
255 |
+
|
256 |
+
$this->assertFalse( $response->is_successful() );
|
257 |
+
|
258 |
+
// Display the transaction Id
|
259 |
+
$error = $response->get_error();
|
260 |
+
st_echo( 'Test Case 1.09: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Test Case Reference 1.10
|
265 |
+
*
|
266 |
+
* @return void
|
267 |
+
* @since 3.9
|
268 |
+
*/
|
269 |
+
public function test_setexpresscheckout_standard_ref110() {
|
270 |
+
// Shipping Details
|
271 |
+
$this->purchase_options['shipping_address'] = array(
|
272 |
+
'name' => 'Abid Omar',
|
273 |
+
'street' => '1 Infinite Loop',
|
274 |
+
'street2' => 'Apple Headquarter',
|
275 |
+
'city' => 'Cupertino',
|
276 |
+
'state' => '',
|
277 |
+
'country' => 'US',
|
278 |
+
'zip' => '95014',
|
279 |
+
'phone' => '(877) 412-7753',
|
280 |
+
);
|
281 |
+
|
282 |
+
// Call SetExpressCheckout
|
283 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
284 |
+
|
285 |
+
$this->assertFalse( $response->is_successful() );
|
286 |
+
|
287 |
+
// Display the transaction Id
|
288 |
+
$error = $response->get_error();
|
289 |
+
st_echo( 'Test Case 1.10: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
290 |
+
}
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Test Case Reference 1.11
|
294 |
+
*
|
295 |
+
* @return void
|
296 |
+
* @since 3.9
|
297 |
+
*/
|
298 |
+
public function test_setexpresscheckout_standard_ref111() {
|
299 |
+
// Shipping Details
|
300 |
+
$this->purchase_options['shipping_address'] = array(
|
301 |
+
'name' => 'Abid Omar',
|
302 |
+
'street' => '1 Infinite Loop',
|
303 |
+
'street2' => 'Apple Headquarter',
|
304 |
+
'city' => 'Cupertino',
|
305 |
+
'state' => 'CA',
|
306 |
+
'country' => 'US',
|
307 |
+
'zip' => '',
|
308 |
+
'phone' => '(877) 412-7753',
|
309 |
+
);
|
310 |
+
|
311 |
+
// Call SetExpressCheckout
|
312 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
313 |
+
|
314 |
+
$this->assertFalse( $response->is_successful() );
|
315 |
+
|
316 |
+
// Display the transaction Id
|
317 |
+
$error = $response->get_error();
|
318 |
+
st_echo( 'Test Case 1.11: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Test Case Reference 1.12
|
323 |
+
*
|
324 |
+
* @return void
|
325 |
+
* @since 3.9
|
326 |
+
*/
|
327 |
+
public function test_setexpresscheckout_standard_ref112() {
|
328 |
+
// Shipping Details
|
329 |
+
$this->purchase_options['shipping_address'] = array(
|
330 |
+
'name' => 'Abid Omar',
|
331 |
+
'street' => '1 Infinite Loop',
|
332 |
+
'street2' => 'Apple Headquarter',
|
333 |
+
'city' => 'Cupertino',
|
334 |
+
'state' => 'CA',
|
335 |
+
'country' => '',
|
336 |
+
'zip' => '95014',
|
337 |
+
'phone' => '(877) 412-7753',
|
338 |
+
);
|
339 |
+
|
340 |
+
// Call SetExpressCheckout
|
341 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
342 |
+
|
343 |
+
$this->assertFalse( $response->is_successful() );
|
344 |
+
|
345 |
+
// Display the transaction Id
|
346 |
+
$error = $response->get_error();
|
347 |
+
st_echo( 'Test Case 1.12: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
348 |
+
}
|
349 |
+
|
350 |
+
/**
|
351 |
+
* Test Case Reference 1.13
|
352 |
+
*
|
353 |
+
* @return void
|
354 |
+
* @since 3.9
|
355 |
+
*/
|
356 |
+
public function test_setexpresscheckout_standard_ref113() {
|
357 |
+
// Shipping Details
|
358 |
+
$this->purchase_options['shipping_address'] = array(
|
359 |
+
'name' => 'Abid Omar',
|
360 |
+
'street' => '123 Any Street',
|
361 |
+
'street2' => '',
|
362 |
+
'city' => 'New York',
|
363 |
+
'state' => 'NY',
|
364 |
+
'country' => 'US',
|
365 |
+
'zip' => '90210',
|
366 |
+
'phone' => '(877) 412-7753',
|
367 |
+
);
|
368 |
+
|
369 |
+
// Call SetExpressCheckout
|
370 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
371 |
+
|
372 |
+
$this->assertFalse( $response->is_successful() );
|
373 |
+
|
374 |
+
// Display the transaction Id
|
375 |
+
$error = $response->get_error();
|
376 |
+
st_echo( 'Test Case 1.13: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* Test Case Reference 1.14
|
381 |
+
*
|
382 |
+
* @return void
|
383 |
+
* @since 3.9
|
384 |
+
*/
|
385 |
+
public function test_setexpresscheckout_standard_ref114() {
|
386 |
+
// Negative Testing
|
387 |
+
$this->purchase_options['subtotal'] = 100.01;
|
388 |
+
$this->purchase_options['shipping'] = 0;
|
389 |
+
$this->purchase_options['tax'] = 0;
|
390 |
+
$this->purchase_options['amount'] = 100.01;
|
391 |
+
$this->purchase_options['max_amount'] = 100.01;
|
392 |
+
$this->purchase_options['items'] = array();
|
393 |
+
|
394 |
+
// Call SetExpressCheckout
|
395 |
+
$response = $this->gateway->setup_purchase( $this->purchase_options );
|
396 |
+
|
397 |
+
$this->assertFalse( $response->is_successful() );
|
398 |
+
|
399 |
+
// Display the transaction Id
|
400 |
+
$error = $response->get_error();
|
401 |
+
st_echo( 'Test Case 1.14: ' . $response->get( 'correlation_id' ) . ' - '. $error['details'] . "\n" );
|
402 |
+
}
|
403 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x2.php
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Certification_Test_X2 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 2.1
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
* @since 3.9
|
83 |
+
*/
|
84 |
+
public function test_doexpresscheckout_ref21() {
|
85 |
+
// Using the Token and Payer Id for another transaction
|
86 |
+
$this->purchase_options['token'] = 'EC-2LX41209SH738634B';
|
87 |
+
$this->purchase_options['payer_id'] = 'FQQ7Q9EVPAB86';
|
88 |
+
|
89 |
+
// Call DoExpressCheckout
|
90 |
+
$response = $this->gateway->purchase( $this->purchase_options );
|
91 |
+
|
92 |
+
$this->assertTrue( $response->is_successful() );
|
93 |
+
|
94 |
+
// Display the Transaction Id
|
95 |
+
st_echo( 'Test Case 2.1: ' . $response->get( 'transaction_id' ) . "\n" );
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Test Case Reference 2.2
|
100 |
+
*
|
101 |
+
* @return void
|
102 |
+
* @since 3.9
|
103 |
+
*/
|
104 |
+
public function test_doexpresscheckout_ref22() {
|
105 |
+
// Using the Token and Payer Id for another transaction
|
106 |
+
$this->purchase_options['token'] = 'EC-5T412084S27270248';
|
107 |
+
$this->purchase_options['payer_id'] = 'FQQ7Q9EVPAB86';
|
108 |
+
|
109 |
+
// Call DoExpressCheckout
|
110 |
+
$response = $this->gateway->purchase( $this->purchase_options, 'Authorization' );
|
111 |
+
|
112 |
+
$this->assertTrue( $response->is_successful() );
|
113 |
+
|
114 |
+
// Display the Transaction Id
|
115 |
+
st_echo( 'Test Case 2.2: ' . $response->get( 'transaction_id' ) . "\n" );
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Test Case Reference 2.3
|
120 |
+
*
|
121 |
+
* @return void
|
122 |
+
* @since 3.9
|
123 |
+
*/
|
124 |
+
public function test_doexpresscheckout_ref23() {
|
125 |
+
// Using the Token and Payer Id for another transaction
|
126 |
+
$this->purchase_options['token'] = 'EC-94S08582T02646945';
|
127 |
+
$this->purchase_options['payer_id'] = 'FQQ7Q9EVPAB86';
|
128 |
+
|
129 |
+
// Call DoExpressCheckout
|
130 |
+
$response = $this->gateway->purchase( $this->purchase_options, 'Order' );
|
131 |
+
|
132 |
+
$this->assertTrue( $response->is_successful() );
|
133 |
+
|
134 |
+
// Display the Transaction Id
|
135 |
+
st_echo( 'Test Case 2.3: ' . $response->get( 'transaction_id' ) . "\n" );
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Test Case Reference 2.4
|
140 |
+
*
|
141 |
+
* @return void
|
142 |
+
* @since 3.9
|
143 |
+
*/
|
144 |
+
public function test_doexpresscheckout_ref24() {
|
145 |
+
// Using the Token and Payer Id for another transaction
|
146 |
+
$this->purchase_options['token'] = 'EC-2A077123HD2136914';
|
147 |
+
$this->purchase_options['payer_id'] = 'FQQ7Q9EVPAB86';
|
148 |
+
|
149 |
+
// Call DoExpressCheckout
|
150 |
+
$this->purchase_options['no_shipping'] = 1;
|
151 |
+
$response = $this->gateway->purchase( $this->purchase_options );
|
152 |
+
|
153 |
+
$this->assertTrue( $response->is_successful() );
|
154 |
+
|
155 |
+
// Display the Transaction Id
|
156 |
+
st_echo( 'Test Case 2.4: ' . $response->get( 'transaction_id' ) . "\n" );
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Test Case Reference 2.5
|
161 |
+
*
|
162 |
+
* @return void
|
163 |
+
* @since 3.9
|
164 |
+
*/
|
165 |
+
public function test_doexpresscheckout_ref25() {
|
166 |
+
// Negative Testing
|
167 |
+
$this->purchase_options['subtotal'] = 100.01;
|
168 |
+
$this->purchase_options['shipping'] = 0;
|
169 |
+
$this->purchase_options['tax'] = 0;
|
170 |
+
$this->purchase_options['amount'] = 100.01;
|
171 |
+
$this->purchase_options['max_amount'] = 100.01;
|
172 |
+
$this->purchase_options['items'] = array();
|
173 |
+
|
174 |
+
// Using the Token and Payer Id for another transaction
|
175 |
+
$this->purchase_options['token'] = 'EC-04C181866P316870M';
|
176 |
+
$this->purchase_options['payer_id'] = 'FQQ7Q9EVPAB86';
|
177 |
+
|
178 |
+
// Call DoExpressCheckout
|
179 |
+
$response = $this->gateway->purchase( $this->purchase_options );
|
180 |
+
|
181 |
+
$this->assertFalse( $response->is_successful() );
|
182 |
+
|
183 |
+
// Display the Transaction Id
|
184 |
+
st_echo( 'Test Case 2.5: ' . $response->get( 'correlation_id' ) . "\n" );
|
185 |
+
}
|
186 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x3.php
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Certification_Test_X3 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 3.1
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
* @since 3.9
|
83 |
+
*/
|
84 |
+
public function test_doexpresscheckout_ref31() {
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Test Case Reference 3.2
|
90 |
+
*
|
91 |
+
* @return void
|
92 |
+
* @since 3.9
|
93 |
+
*/
|
94 |
+
public function test_doexpresscheckout_ref32() {
|
95 |
+
|
96 |
+
}
|
97 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x4.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Certification_Test_X4 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 4.1
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
* @since 3.9
|
83 |
+
*/
|
84 |
+
public function test_doexpresscheckout_ref41() {
|
85 |
+
$this->purchase_options['complete_type'] = 'NotComplete';
|
86 |
+
$this->purchase_options['amount'] = 10;
|
87 |
+
$this->purchase_options['authorization_id'] = '3AU5391768007820J';
|
88 |
+
|
89 |
+
$response = $this->gateway->capture( $this->purchase_options );
|
90 |
+
|
91 |
+
$this->assertTrue( $response->is_successful() );
|
92 |
+
|
93 |
+
// Display the Transaction Id
|
94 |
+
st_echo('Test Case 4.1: ' . $response->get( 'transaction_id' ) . "\n" );
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Test Case Reference 4.2
|
99 |
+
*
|
100 |
+
* @return void
|
101 |
+
* @since 3.9
|
102 |
+
*/
|
103 |
+
public function test_doexpresscheckout_ref42() {
|
104 |
+
$this->purchase_options['complete_type'] = 'Complete';
|
105 |
+
$this->purchase_options['amount'] = 15.34;
|
106 |
+
$this->purchase_options['authorization_id'] = 'O-79124340AV3470941';
|
107 |
+
|
108 |
+
$response = $this->gateway->capture( $this->purchase_options );
|
109 |
+
|
110 |
+
$this->assertTrue( $response->is_successful() );
|
111 |
+
|
112 |
+
// Display the Transaction Id
|
113 |
+
st_echo('Test Case 4.2: ' . $response->get( 'transaction_id' ) . "\n" );
|
114 |
+
}
|
115 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x5.php
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Certification_Test_X5 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP e-Commerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP e-Commerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 5.1
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
* @since 3.9
|
83 |
+
*/
|
84 |
+
public function test_doexpresscheckout_ref51() {
|
85 |
+
// Fully Refunded Transaction
|
86 |
+
$response = $this->gateway->get_transaction_details( '0SH96542L88249424' );
|
87 |
+
|
88 |
+
$this->assertTrue( $response->is_successful() );
|
89 |
+
st_echo( 'Test Case 5.1:' . "\n" );
|
90 |
+
st_echo( 'Transaction ID: 0SH96542L88249424' . "\n" );
|
91 |
+
st_echo( 'Payment Status: ' . $response->get_params()['PAYMENTSTATUS'] . "\n" );
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Test Case Reference 5.2
|
96 |
+
*
|
97 |
+
* @return void
|
98 |
+
* @since 3.9
|
99 |
+
*/
|
100 |
+
public function test_doexpresscheckout_ref52() {
|
101 |
+
// Fully Refunded Transaction
|
102 |
+
$response = $this->gateway->get_transaction_details( '29585298U7589982T' );
|
103 |
+
|
104 |
+
$this->assertTrue( $response->is_successful() );
|
105 |
+
st_echo( 'Test Case 5.2:' . "\n" );
|
106 |
+
st_echo( 'Transaction ID: 29585298U7589982T' . "\n" );
|
107 |
+
st_echo( 'Payment Status: ' . $response->get_params()['PAYMENTSTATUS'] . "\n" );
|
108 |
+
}
|
109 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-ec-cert-x6.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Certification_Test_X6 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout test cases' );
|
14 |
+
// Generate an invoice number
|
15 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
16 |
+
|
17 |
+
// Common Options
|
18 |
+
$this->default_options = array(
|
19 |
+
// API info
|
20 |
+
'return_url' => 'http://example.com/return',
|
21 |
+
'cancel_url' => 'http://example.com/cancel',
|
22 |
+
'address_override' => 1,
|
23 |
+
|
24 |
+
// Payment info
|
25 |
+
'currency' => 'USD',
|
26 |
+
'amount' => 15.337,
|
27 |
+
'subtotal' => 13.700,
|
28 |
+
'shipping' => 1.500,
|
29 |
+
'tax' => 0.137,
|
30 |
+
'description' => 'A sample order',
|
31 |
+
'invoice' => $inv,
|
32 |
+
'notify_url' => 'http://example.com/ipn',
|
33 |
+
|
34 |
+
// Items
|
35 |
+
'items' => array(
|
36 |
+
array(
|
37 |
+
'name' => 'Gold Cart Plugin',
|
38 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
39 |
+
'amount' => 4,
|
40 |
+
'quantity' => 1,
|
41 |
+
'tax' => 0.040,
|
42 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
43 |
+
'number' => '7A12343-WHT-XL',
|
44 |
+
),
|
45 |
+
array(
|
46 |
+
'name' => 'Member Access Plugin',
|
47 |
+
'description' => 'Create pay to view subscription sites',
|
48 |
+
'amount' => 5,
|
49 |
+
'quantity' => 1,
|
50 |
+
'tax' => 0.05,
|
51 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
52 |
+
'number' => '7A12344-WHT-XL',
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'name' => 'Amazon S3',
|
56 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
57 |
+
'amount' => 4.7,
|
58 |
+
'quantity' => 1,
|
59 |
+
'tax' => 0.047,
|
60 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
61 |
+
'number' => '7A12345-WHT-XL',
|
62 |
+
),
|
63 |
+
),
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function setUp() {
|
68 |
+
global $test_accounts;
|
69 |
+
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-ec-oa'] );
|
70 |
+
$this->purchase_options = $this->default_options;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public function tearDown() {
|
75 |
+
$this->purchase_options = null;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Test Case Reference 6.1
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
* @since 3.9
|
83 |
+
*/
|
84 |
+
public function test_doexpresscheckout_ref61() {
|
85 |
+
// Cancelled Transaction
|
86 |
+
$response = $this->gateway->get_transaction_details( 'O-0CJ689879E5247331' );
|
87 |
+
|
88 |
+
$this->assertTrue( $response->is_successful() );
|
89 |
+
st_echo( 'Test Case 6.1:' . "\n" );
|
90 |
+
st_echo( 'Transaction ID: O-0CJ689879E5247331' . "\n" );
|
91 |
+
st_echo( 'Payment Status: ' . $response->get_params()['PAYMENTSTATUS'] . "\n" );
|
92 |
+
}
|
93 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-express-checkout.php
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-express-checkout.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Express_Checkout_Remote_Test extends WebTestCase
|
6 |
+
{
|
7 |
+
private $response;
|
8 |
+
|
9 |
+
public function __construct() {
|
10 |
+
parent::__construct( 'PHP_Merchant_Paypal_Express_Checkout Remote Unit Tests' );
|
11 |
+
}
|
12 |
+
|
13 |
+
public function test_successful_set_express_checkout_request() {
|
14 |
+
global $test_accounts;
|
15 |
+
$gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-express-checkout'] );
|
16 |
+
|
17 |
+
$purchase_options = array(
|
18 |
+
// API info
|
19 |
+
'return_url' => 'http://example.com/return',
|
20 |
+
'cancel_url' => 'http://example.com/cancel',
|
21 |
+
'address_override' => true,
|
22 |
+
|
23 |
+
// Shipping details
|
24 |
+
'shipping_address' => array(
|
25 |
+
'name' => 'Gary Cao',
|
26 |
+
'street' => '1 Infinite Loop',
|
27 |
+
'street2' => 'Apple Headquarter',
|
28 |
+
'city' => 'Cupertino',
|
29 |
+
'state' => 'CA',
|
30 |
+
'country' => 'US',
|
31 |
+
'zip' => '95014',
|
32 |
+
'phone' => '(877) 412-7753',
|
33 |
+
),
|
34 |
+
|
35 |
+
// Payment info
|
36 |
+
'currency' => 'JPY',
|
37 |
+
'subtotal' => 13700,
|
38 |
+
'shipping' => 1500,
|
39 |
+
'tax' => 137,
|
40 |
+
'amount' => 15337,
|
41 |
+
'description' => 'Order for example.com',
|
42 |
+
'invoice' => 'E84A90G94',
|
43 |
+
'notify_url' => 'http://example.com/ipn',
|
44 |
+
|
45 |
+
// Items
|
46 |
+
'items' => array(
|
47 |
+
array(
|
48 |
+
'name' => 'Gold Cart Plugin',
|
49 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
50 |
+
'amount' => 4000,
|
51 |
+
'quantity' => 1,
|
52 |
+
'tax' => 40,
|
53 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
54 |
+
),
|
55 |
+
array(
|
56 |
+
'name' => 'Member Access Plugin',
|
57 |
+
'description' => 'Create pay to view subscription sites',
|
58 |
+
'amount' => 5000,
|
59 |
+
'quantity' => 1,
|
60 |
+
'tax' => 50,
|
61 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
62 |
+
),
|
63 |
+
array(
|
64 |
+
'name' => 'Amazon S3',
|
65 |
+
'description' => 'This Plugin allows downloadable products on your WP eCommerce site to be hosted on Amazon S3.',
|
66 |
+
'amount' => 4700,
|
67 |
+
'quantity' => 1,
|
68 |
+
'tax' => 47,
|
69 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
70 |
+
),
|
71 |
+
),
|
72 |
+
);
|
73 |
+
|
74 |
+
$this->response = $response = $gateway->setup_purchase( $purchase_options );
|
75 |
+
$this->token = $response->get( 'token' );
|
76 |
+
$this->timestamp = $response->get( 'timestamp' );
|
77 |
+
$this->datetime = $response->get( 'datetime' );
|
78 |
+
$this->correlation_id = $response->get( 'correlation_id' );
|
79 |
+
$this->version = $response->get( 'version' );
|
80 |
+
$this->build = $response->get( 'build' );
|
81 |
+
$this->assertTrue( $response->is_successful() );
|
82 |
+
$this->assertFalse( $response->has_errors() );
|
83 |
+
}
|
84 |
+
|
85 |
+
public function test_successful_get_express_checkout_request() {
|
86 |
+
global $test_accounts;
|
87 |
+
|
88 |
+
// This is required to fill the response property
|
89 |
+
$this->test_successful_set_express_checkout_request();
|
90 |
+
|
91 |
+
$gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-express-checkout'] );
|
92 |
+
|
93 |
+
$response = $gateway->get_details_for( $this->response->get( 'token' ) );
|
94 |
+
|
95 |
+
$this->assertTrue( $response->is_successful() );
|
96 |
+
$this->assertFalse( $response->has_errors() );
|
97 |
+
|
98 |
+
// API Info
|
99 |
+
$this->assertTrue( $response->is_checkout_not_initiated() );
|
100 |
+
$this->assertFalse( $response->is_checkout_failed() );
|
101 |
+
$this->assertFalse( $response->is_checkout_in_progress() );
|
102 |
+
$this->assertFalse( $response->is_checkout_completed() );
|
103 |
+
$this->assertEqual( $response->get( 'checkout_status' ), 'Not-Initiated' );
|
104 |
+
$this->assertEqual( $response->get( 'token' ), $this->response->get( 'token' ) );
|
105 |
+
$this->assertEqual( $response->get( 'version' ), $this->response->get( 'version' ) );
|
106 |
+
$this->assertEqual( $response->get( 'build' ), $this->response->get( 'build' ) );
|
107 |
+
|
108 |
+
// Payment Information
|
109 |
+
$this->assertEqual( $response->get( 'currency' ), 'JPY' );
|
110 |
+
$this->assertEqual( $response->get( 'amount' ), 15337 );
|
111 |
+
$this->assertEqual( $response->get( 'subtotal' ), 13700 );
|
112 |
+
$this->assertEqual( $response->get( 'shipping' ), 1500 );
|
113 |
+
$this->assertEqual( $response->get( 'handling' ), 0 );
|
114 |
+
$this->assertEqual( $response->get( 'tax' ), 137 );
|
115 |
+
$this->assertEqual( $response->get( 'invoice' ), 'E84A90G94' );
|
116 |
+
$this->assertEqual( $response->get( 'notify_url' ), 'http://example.com/ipn' );
|
117 |
+
$this->assertEqual( $response->get( 'shipping_discount' ), 0 );
|
118 |
+
|
119 |
+
// Item Information
|
120 |
+
$items = $response->get( 'items' );
|
121 |
+
$mock_items = array();
|
122 |
+
|
123 |
+
$mock_items[0] = new stdClass();
|
124 |
+
$mock_items[0]->name = 'Gold Cart Plugin';
|
125 |
+
$mock_items[0]->description = 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.';
|
126 |
+
$mock_items[0]->amount = 4000;
|
127 |
+
$mock_items[0]->quantity = 1;
|
128 |
+
$mock_items[0]->tax = 40;
|
129 |
+
|
130 |
+
$mock_items[1] = new stdClass();
|
131 |
+
$mock_items[1]->name = 'Member Access Plugin';
|
132 |
+
$mock_items[1]->description = 'Create pay to view subscription sites';
|
133 |
+
$mock_items[1]->amount = 5000;
|
134 |
+
$mock_items[1]->quantity = 1;
|
135 |
+
$mock_items[1]->tax = 50;
|
136 |
+
|
137 |
+
$mock_items[2] = new stdClass();
|
138 |
+
$mock_items[2]->name = 'Amazon S3';
|
139 |
+
$mock_items[2]->description = 'This Plugin allows downloadable products on your WP eCommerce site to be hosted on Amazon S3.';
|
140 |
+
$mock_items[2]->amount = 4700;
|
141 |
+
$mock_items[2]->quantity = 1;
|
142 |
+
$mock_items[2]->tax = 47;
|
143 |
+
|
144 |
+
$this->assertEqual( $items, $mock_items );
|
145 |
+
}
|
146 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-pro-cert-x1.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-pro.php' );
|
3 |
+
|
4 |
+
class PHP_Merchant_Paypal_Pro_Certification_Test_X1 extends UnitTestCase
|
5 |
+
{
|
6 |
+
private $gateway;
|
7 |
+
private $token;
|
8 |
+
private $default_options;
|
9 |
+
private $purchase_options;
|
10 |
+
|
11 |
+
public function __construct() {
|
12 |
+
parent::__construct( 'PHP_Merchant_Paypal_Pro test cases' );
|
13 |
+
// Generate an invoice number
|
14 |
+
$inv = 'E84A90G' . mt_rand( 100, 999);
|
15 |
+
|
16 |
+
// Common Options
|
17 |
+
$this->default_options = array(
|
18 |
+
'paymentaction' => 'sale',
|
19 |
+
'template' => 'templateD',
|
20 |
+
'vendor' => 'wpp@omarabid.com',
|
21 |
+
|
22 |
+
// API info
|
23 |
+
'return_url' => 'http://example.com/return',
|
24 |
+
'cancel_url' => 'http://example.com/cancel',
|
25 |
+
'address_override' => 1,
|
26 |
+
|
27 |
+
// Payment info
|
28 |
+
'currency' => 'USD',
|
29 |
+
'amount' => 15.337,
|
30 |
+
'subtotal' => 13.700,
|
31 |
+
'shipping' => 1.500,
|
32 |
+
'tax' => 0.137,
|
33 |
+
'description' => 'A sample order',
|
34 |
+
'invoice' => $inv,
|
35 |
+
'notify_url' => 'http://example.com/ipn',
|
36 |
+
'shipping_address' => array(
|
37 |
+
'name' => 'Abid Omar',
|
38 |
+
'street' => '1 Infinite Loop',
|
39 |
+
'street2' => 'Apple Headquarter ext',
|
40 |
+
'city' => 'Cupertino',
|
41 |
+
'state' => 'CA',
|
42 |
+
'country' => 'US',
|
43 |
+
'zip' => '95014',
|
44 |
+
'phone' => '(877) 412-7753',
|
45 |
+
),
|
46 |
+
// Items
|
47 |
+
'items' => array(
|
48 |
+
array(
|
49 |
+
'name' => 'Gold Cart Plugin',
|
50 |
+
'description' => 'Gold Cart extends your WP eCommerce store by enabling additional features and functionality.',
|
51 |
+
'amount' => 4,
|
52 |
+
'quantity' => 1,
|
53 |
+
'tax' => 0.040,
|
54 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
55 |
+
'number' => '7A12343-WHT-XL',
|
56 |
+
),
|
57 |
+
array(
|
58 |
+
'name' => 'Member Access Plugin',
|
59 |
+
'description' => 'Create pay to view subscription sites',
|
60 |
+
'amount' => 5,
|
61 |
+
'quantity' => 1,
|
62 |
+
'tax' => 0.05,
|
63 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
64 |
+
'number' => '7A12344-WHT-XL',
|
65 |
+
),
|
66 |
+
array(
|
67 |
+
'name' => 'Amazon S3',
|
68 |
+
'description' => 'This Plugin allows downloadable products that you have for sale on your WP eCommerce site to be hosted within Amazon S3.',
|
69 |
+
'amount' => 4.7,
|
70 |
+
'quantity' => 1,
|
71 |
+
'tax' => 0.047,
|
72 |
+
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
73 |
+
'number' => '7A12345-WHT-XL',
|
74 |
+
),
|
75 |
+
),
|
76 |
+
);
|
77 |
+
}
|
78 |
+
|
79 |
+
public function setUp() {
|
80 |
+
global $test_accounts;
|
81 |
+
$this->gateway = new PHP_Merchant_Paypal_Pro( $test_accounts['paypal-pro-oa'] );
|
82 |
+
$this->purchase_options = $this->default_options;
|
83 |
+
}
|
84 |
+
|
85 |
+
|
86 |
+
public function tearDown() {
|
87 |
+
$this->purchase_options = null;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Test Case Reference A.6.1
|
92 |
+
*
|
93 |
+
* Standard Fields Test
|
94 |
+
*
|
95 |
+
* @return void
|
96 |
+
* @since 3.9
|
97 |
+
*/
|
98 |
+
public function test_setexpresscheckout_standard_refA61() {
|
99 |
+
// Call CreateButtom
|
100 |
+
$options = is_array( $this->purchase_options ) ? $this->purchase_options : array();
|
101 |
+
$response = $this->gateway->createButton( $options );
|
102 |
+
|
103 |
+
$this->assertTrue( $response->is_successful() );
|
104 |
+
|
105 |
+
// Display the correlation Id
|
106 |
+
st_echo('Test Case A.6.1: ' . $response->get( 'correlation_id' ) . "\n" );
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Test Case Reference A.6.2
|
111 |
+
*
|
112 |
+
* Standard Fields Test
|
113 |
+
*
|
114 |
+
* @return void
|
115 |
+
* @since 3.9
|
116 |
+
*/
|
117 |
+
public function test_setexpresscheckout_standard_refA62() {
|
118 |
+
// Call CreateButtom
|
119 |
+
$options = is_array( $this->purchase_options ) ? $this->purchase_options : array();
|
120 |
+
|
121 |
+
// Set Billing information
|
122 |
+
$options['billing_address'] = array(
|
123 |
+
'name' => 'Abid Omar',
|
124 |
+
'street' => '1 Infinite Loop',
|
125 |
+
'street2' => 'Apple Headquarter ext',
|
126 |
+
'city' => 'Cupertino',
|
127 |
+
'state' => 'CA',
|
128 |
+
'country' => 'US',
|
129 |
+
'zip' => '95014',
|
130 |
+
'phone' => '(877) 412-7753',
|
131 |
+
);
|
132 |
+
|
133 |
+
$response = $this->gateway->createButton( $options );
|
134 |
+
|
135 |
+
$this->assertTrue( $response->is_successful() );
|
136 |
+
|
137 |
+
// Display the correlation Id
|
138 |
+
st_echo('Test Case A.6.2: ' . $response->get( 'correlation_id' ) . "\n" );
|
139 |
+
}
|
140 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-pro-cert-x2.php
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( PHP_MERCHANT_PATH . '/gateways/paypal-pro.php' );
|
4 |
+
|
5 |
+
class PHP_Merchant_Paypal_Pro_Certification_Test_X2 extends UnitTestCase
|
6 |
+
{
|
7 |
+
private $gateway;
|
8 |
+
private $token;
|
9 |
+
private $default_options;
|
10 |
+
private $purchase_options;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
parent::__construct( 'PHP_Merchant_Paypal_Pro test cases' );
|
14 |
+
$this->default_options = array();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function setUp() {
|
18 |
+
global $test_accounts;
|
19 |
+
$this->gateway = new PHP_Merchant_Paypal_Pro( $test_accounts['paypal-pro-oa'] );
|
20 |
+
$this->purchase_options = $this->default_options;
|
21 |
+
}
|
22 |
+
|
23 |
+
|
24 |
+
public function tearDown() {
|
25 |
+
$this->purchase_options = null;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Test Case Reference A.1.1
|
30 |
+
*
|
31 |
+
* @return void
|
32 |
+
* @since 3.9
|
33 |
+
*/
|
34 |
+
public function test_paypalpro_refA11() {
|
35 |
+
// Fully Refunded Transaction
|
36 |
+
$response = $this->gateway->get_transaction_details( '57T574999A4979400' );
|
37 |
+
|
38 |
+
$this->assertTrue( $response->is_successful() );
|
39 |
+
st_echo( 'Test Case A1.1:' . "\n" );
|
40 |
+
st_echo( 'Transaction ID: 57T574999A4979400' . "\n" );
|
41 |
+
st_echo( 'Payment Status: ' . $response->get_params()['PAYMENTSTATUS'] . "\n" );
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Test Case Reference A.1.2
|
46 |
+
*
|
47 |
+
* @return void
|
48 |
+
* @since 3.9
|
49 |
+
*/
|
50 |
+
public function test_paypalpro_refA12() {
|
51 |
+
// Partially Refunded Transaction
|
52 |
+
$response = $this->gateway->get_transaction_details( '6XD74563HX9353102' );
|
53 |
+
|
54 |
+
$this->assertTrue( $response->is_successful() );
|
55 |
+
st_echo( 'Test Case A1.2:' . "\n" );
|
56 |
+
st_echo( 'Transaction ID: 6XD74563HX9353102' . "\n" );
|
57 |
+
st_echo( 'Payment Status: ' . $response->get_params()['PAYMENTSTATUS'] . "\n" );
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Test Case Reference A.1.3
|
62 |
+
*
|
63 |
+
* @return void
|
64 |
+
* @since 3.9
|
65 |
+
*/
|
66 |
+
public function test_paypalpro_refA13() {
|
67 |
+
// Negative Test
|
68 |
+
$this->purchase_options['message_id'] = '';
|
69 |
+
$this->purchase_options['transaction_id'] = '1MC14541JJ0533214';
|
70 |
+
$this->purchase_options['invoice'] = '2';
|
71 |
+
$this->purchase_options['refund_type'] = 'partial';
|
72 |
+
$this->purchase_options['amount'] = '100.01';
|
73 |
+
|
74 |
+
$response = $this->gateway->credit( $this->purchase_options );
|
75 |
+
|
76 |
+
$this->assertFalse( $response->is_successful() );
|
77 |
+
|
78 |
+
st_echo( 'Test Case A1.3:' . "\n" );
|
79 |
+
st_echo( 'Correlation ID: ' . $response->get_params()['CORRELATIONID'] . "\n" );
|
80 |
+
}
|
81 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE
ADDED
@@ -0,0 +1,399 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Simple Test interface changes
|
2 |
+
=============================
|
3 |
+
Because the SimpleTest tool set is still evolving it is likely that tests
|
4 |
+
written with earlier versions will fail with the newest ones. The most
|
5 |
+
dramatic changes are in the alpha releases. Here is a list of possible
|
6 |
+
problems and their fixes...
|
7 |
+
|
8 |
+
assertText() no longer finds a string inside a <script> tag
|
9 |
+
-----------------------------------------------------------
|
10 |
+
The assertText() method is intended to match only visible,
|
11 |
+
human-readable text on the web page. Therefore, the contents of script
|
12 |
+
tags should not be matched by this assertion. However there was a bug
|
13 |
+
in the text normalisation code of simpletest which meant that <script>
|
14 |
+
tags spanning multiple lines would not have their content stripped
|
15 |
+
out. If you want to check the content of a <script> tag, use
|
16 |
+
assertPattern(), or write a custom expectation.
|
17 |
+
|
18 |
+
Overloaded method not working
|
19 |
+
-----------------------------
|
20 |
+
All protected and private methods had underscores
|
21 |
+
removed. This means that any private/protected methods that
|
22 |
+
you overloaded with those names need to be updated.
|
23 |
+
|
24 |
+
Fatal error: Call to undefined method Classname::classname()
|
25 |
+
------------------------------------------------------------
|
26 |
+
SimpleTest renamed all of its constructors from
|
27 |
+
Classname to __construct; derived classes invoking
|
28 |
+
their parent constructors should replace parent::Classname()
|
29 |
+
with parent::__construct().
|
30 |
+
|
31 |
+
Custom CSS in HtmlReporter not being applied
|
32 |
+
--------------------------------------------
|
33 |
+
Batch rename of protected and private methods
|
34 |
+
means that _getCss() was renamed to getCss().
|
35 |
+
Please rename your method and it should work again.
|
36 |
+
|
37 |
+
setReturnReference() throws errors in E_STRICT
|
38 |
+
----------------------------------------------
|
39 |
+
Happens when an object is passed by reference.
|
40 |
+
This also happens with setReturnReferenceAt().
|
41 |
+
If you want to return objects then replace these
|
42 |
+
with calls to returns() and returnsAt() with the
|
43 |
+
same arguments. This change was forced in the 1.1
|
44 |
+
version for E_STRICT compatibility.
|
45 |
+
|
46 |
+
assertReference() throws errors in E_STRICT
|
47 |
+
-------------------------------------------
|
48 |
+
Due to language restrictions you cannot compare
|
49 |
+
both variables and objects in E_STRICT mode. Use
|
50 |
+
assertSame() in this mode with objects. This change
|
51 |
+
was forced the 1.1 version.
|
52 |
+
|
53 |
+
Cannot create GroupTest
|
54 |
+
-----------------------
|
55 |
+
The GroupTest has been renamed TestSuite (see below).
|
56 |
+
It was removed completely in 1.1 in favour of this
|
57 |
+
name.
|
58 |
+
|
59 |
+
No method getRelativeUrls() or getAbsoluteUrls()
|
60 |
+
------------------------------------------------
|
61 |
+
These methods were always a bit weird anyway, and
|
62 |
+
the new parsing of the base tag makes them more so.
|
63 |
+
They have been replaced with getUrls() instead. If
|
64 |
+
you want the old functionality then simply chop
|
65 |
+
off the current domain from getUrls().
|
66 |
+
|
67 |
+
Method setWildcard() removed in mocks
|
68 |
+
-------------------------------------
|
69 |
+
Even setWildcard() has been removed in 1.0.1beta now.
|
70 |
+
If you want to test explicitely for a '*' string, then
|
71 |
+
simply pass in new IdenticalExpectation('*') instead.
|
72 |
+
|
73 |
+
No method _getTest() on mocks
|
74 |
+
-----------------------------
|
75 |
+
This has finally been removed. It was a pretty esoteric
|
76 |
+
flex point anyway. It was there to allow the mocks to
|
77 |
+
work with other test tools, but no one does this.
|
78 |
+
|
79 |
+
No method assertError(), assertNoErrors(), swallowErrors()
|
80 |
+
----------------------------------------------------------
|
81 |
+
These have been deprecated in 1.0.1beta in favour of
|
82 |
+
expectError() and expectException(). assertNoErrors() is
|
83 |
+
redundant if you use expectError() as failures are now reported
|
84 |
+
immediately.
|
85 |
+
|
86 |
+
No method TestCase::signal()
|
87 |
+
----------------------------
|
88 |
+
This has been deprecated in favour of triggering an error or
|
89 |
+
throwing an exception. Deprecated as of 1.0.1beta.
|
90 |
+
|
91 |
+
No method TestCase::sendMessage()
|
92 |
+
---------------------------------
|
93 |
+
This has been deprecated as of 1.0.1beta.
|
94 |
+
|
95 |
+
Failure to connect now emits failures
|
96 |
+
-------------------------------------
|
97 |
+
It used to be that you would have to use the
|
98 |
+
getTransferError() call on the web tester to see if
|
99 |
+
there was a socket level error in a fetch. This check
|
100 |
+
is now always carried out by the WebTestCase unless
|
101 |
+
the fetch is prefaced with WebTestCase::ignoreErrors().
|
102 |
+
The ignore directive only lasts for the next fetching
|
103 |
+
action such as get() and click().
|
104 |
+
|
105 |
+
No method SimpleTestOptions::ignore()
|
106 |
+
-------------------------------------
|
107 |
+
This is deprecated in version 1.0.1beta and has been moved
|
108 |
+
to SimpleTest::ignore() as that is more readable. In
|
109 |
+
addition, parent classes are also ignored automatically.
|
110 |
+
If you are using PHP5 you can skip this directive simply
|
111 |
+
by marking your test case as abstract.
|
112 |
+
|
113 |
+
No method assertCopy()
|
114 |
+
----------------------
|
115 |
+
This is deprecated in 1.0.1 in favour of assertClone().
|
116 |
+
The assertClone() method is slightly different in that
|
117 |
+
the objects must be identical, but without being a
|
118 |
+
reference. It is thus not a strict inversion of
|
119 |
+
assertReference().
|
120 |
+
|
121 |
+
Constructor wildcard override has no effect in mocks
|
122 |
+
----------------------------------------------------
|
123 |
+
As of 1.0.1beta this is now set with setWildcard() instead
|
124 |
+
of in the constructor.
|
125 |
+
|
126 |
+
No methods setStubBaseClass()/getStubBaseClass()
|
127 |
+
------------------------------------------------
|
128 |
+
As mocks are now used instead of stubs, these methods
|
129 |
+
stopped working and are now removed as of the 1.0.1beta
|
130 |
+
release. The mock objects may be freely used instead.
|
131 |
+
|
132 |
+
No method addPartialMockCode()
|
133 |
+
------------------------------
|
134 |
+
The ability to insert arbitrary partial mock code
|
135 |
+
has been removed. This was a low value feature
|
136 |
+
causing needless complications. It was removed
|
137 |
+
in the 1.0.1beta release.
|
138 |
+
|
139 |
+
No method setMockBaseClass()
|
140 |
+
----------------------------
|
141 |
+
The ability to change the mock base class has been
|
142 |
+
scheduled for removal and is deprecated since the
|
143 |
+
1.0.1beta version. This was a rarely used feature
|
144 |
+
except as a workaround for PHP5 limitations. As
|
145 |
+
these limitations are being resolved it's hoped
|
146 |
+
that the bundled mocks can be used directly.
|
147 |
+
|
148 |
+
No class Stub
|
149 |
+
-------------
|
150 |
+
Server stubs are deprecated from 1.0.1 as the mocks now
|
151 |
+
have exactly the same interface. Just use mock objects
|
152 |
+
instead.
|
153 |
+
|
154 |
+
No class SimpleTestOptions
|
155 |
+
--------------------------
|
156 |
+
This was replced by the shorter SimpleTest in 1.0.1beta1
|
157 |
+
and is since deprecated.
|
158 |
+
|
159 |
+
No file simple_test.php
|
160 |
+
-----------------------
|
161 |
+
This was renamed test_case.php in 1.0.1beta to more accurately
|
162 |
+
reflect it's purpose. This file should never be directly
|
163 |
+
included in test suites though, as it's part of the
|
164 |
+
underlying mechanics and has a tendency to be refactored.
|
165 |
+
|
166 |
+
No class WantedPatternExpectation
|
167 |
+
---------------------------------
|
168 |
+
This was deprecated in 1.0.1alpha in favour of the simpler
|
169 |
+
name PatternExpectation.
|
170 |
+
|
171 |
+
No class NoUnwantedPatternExpectation
|
172 |
+
-------------------------------------
|
173 |
+
This was deprecated in 1.0.1alpha in favour of the simpler
|
174 |
+
name NoPatternExpectation.
|
175 |
+
|
176 |
+
No method assertNoUnwantedPattern()
|
177 |
+
-----------------------------------
|
178 |
+
This has been renamed to assertNoPattern() in 1.0.1alpha and
|
179 |
+
the old form is deprecated.
|
180 |
+
|
181 |
+
No method assertWantedPattern()
|
182 |
+
-------------------------------
|
183 |
+
This has been renamed to assertPattern() in 1.0.1alpha and
|
184 |
+
the old form is deprecated.
|
185 |
+
|
186 |
+
No method assertExpectation()
|
187 |
+
-----------------------------
|
188 |
+
This was renamed as assert() in 1.0.1alpha and the old form
|
189 |
+
has been deprecated.
|
190 |
+
|
191 |
+
No class WildcardExpectation
|
192 |
+
----------------------------
|
193 |
+
This was a mostly internal class for the mock objects. It was
|
194 |
+
renamed AnythingExpectation to bring it closer to JMock and
|
195 |
+
NMock in version 1.0.1alpha.
|
196 |
+
|
197 |
+
Missing UnitTestCase::assertErrorPattern()
|
198 |
+
------------------------------------------
|
199 |
+
This method is deprecated for version 1.0.1 onwards.
|
200 |
+
This method has been subsumed by assertError() that can now
|
201 |
+
take an expectation. Simply pass a PatternExpectation
|
202 |
+
into assertError() to simulate the old behaviour.
|
203 |
+
|
204 |
+
No HTML when matching page elements
|
205 |
+
-----------------------------------
|
206 |
+
This behaviour has been switched to using plain text as if it
|
207 |
+
were seen by the user of the browser. This means that HTML tags
|
208 |
+
are suppressed, entities are converted and whitespace is
|
209 |
+
normalised. This should make it easier to match items in forms.
|
210 |
+
Also images are replaced with their "alt" text so that they
|
211 |
+
can be matched as well.
|
212 |
+
|
213 |
+
No method SimpleRunner::_getTestCase()
|
214 |
+
--------------------------------------
|
215 |
+
This was made public as getTestCase() in 1.0RC2.
|
216 |
+
|
217 |
+
No method restartSession()
|
218 |
+
--------------------------
|
219 |
+
This was renamed to restart() in the WebTestCase, SimpleBrowser
|
220 |
+
and the underlying SimpleUserAgent in 1.0RC2. Because it was
|
221 |
+
undocumented anyway, no attempt was made at backward
|
222 |
+
compatibility.
|
223 |
+
|
224 |
+
My custom test case ignored by tally()
|
225 |
+
--------------------------------------
|
226 |
+
The _assertTrue method has had it's signature changed due to a bug
|
227 |
+
in the PHP 5.0.1 release. You must now use getTest() from within
|
228 |
+
that method to get the test case. Mock compatibility with other
|
229 |
+
unit testers is now deprecated as of 1.0.1alpha as PEAR::PHPUnit2
|
230 |
+
should soon have mock support of it's own.
|
231 |
+
|
232 |
+
Broken code extending SimpleRunner
|
233 |
+
----------------------------------
|
234 |
+
This was replaced with SimpleScorer so that I could use the runner
|
235 |
+
name in another class. This happened in RC1 development and there
|
236 |
+
is no easy backward compatibility fix. The solution is simply to
|
237 |
+
extend SimpleScorer instead.
|
238 |
+
|
239 |
+
Missing method getBaseCookieValue()
|
240 |
+
-----------------------------------
|
241 |
+
This was renamed getCurrentCookieValue() in RC1.
|
242 |
+
|
243 |
+
Missing files from the SimpleTest suite
|
244 |
+
---------------------------------------
|
245 |
+
Versions of SimpleTest prior to Beta6 required a SIMPLE_TEST constant
|
246 |
+
to point at the SimpleTest folder location before any of the toolset
|
247 |
+
was loaded. This is no longer documented as it is now unnecessary
|
248 |
+
for later versions. If you are using an earlier version you may
|
249 |
+
need this constant. Consult the documentation that was bundled with
|
250 |
+
the release that you are using or upgrade to Beta6 or later.
|
251 |
+
|
252 |
+
No method SimpleBrowser::getCurrentUrl()
|
253 |
+
--------------------------------------
|
254 |
+
This is replaced with the more versatile showRequest() for
|
255 |
+
debugging. It only existed in this context for version Beta5.
|
256 |
+
Later versions will have SimpleBrowser::getHistory() for tracking
|
257 |
+
paths through pages. It is renamed as getUrl() since 1.0RC1.
|
258 |
+
|
259 |
+
No method Stub::setStubBaseClass()
|
260 |
+
----------------------------------
|
261 |
+
This method has finally been removed in 1.0RC1. Use
|
262 |
+
SimpleTestOptions::setStubBaseClass() instead.
|
263 |
+
|
264 |
+
No class CommandLineReporter
|
265 |
+
----------------------------
|
266 |
+
This was renamed to TextReporter in Beta3 and the deprecated version
|
267 |
+
was removed in 1.0RC1.
|
268 |
+
|
269 |
+
No method requireReturn()
|
270 |
+
-------------------------
|
271 |
+
This was deprecated in Beta3 and is now removed.
|
272 |
+
|
273 |
+
No method expectCookie()
|
274 |
+
------------------------
|
275 |
+
This method was abruptly removed in Beta4 so as to simplify the internals
|
276 |
+
until another mechanism can replace it. As a workaround it is necessary
|
277 |
+
to assert that the cookie has changed by setting it before the page
|
278 |
+
fetch and then assert the desired value.
|
279 |
+
|
280 |
+
No method clickSubmitByFormId()
|
281 |
+
-------------------------------
|
282 |
+
This method had an incorrect name as no button was involved. It was
|
283 |
+
renamed to submitByFormId() in Beta4 and the old version deprecated.
|
284 |
+
Now removed.
|
285 |
+
|
286 |
+
No method paintStart() or paintEnd()
|
287 |
+
------------------------------------
|
288 |
+
You should only get this error if you have subclassed the lower level
|
289 |
+
reporting and test runner machinery. These methods have been broken
|
290 |
+
down into events for test methods, events for test cases and events
|
291 |
+
for group tests. The new methods are...
|
292 |
+
|
293 |
+
paintStart() --> paintMethodStart(), paintCaseStart(), paintGroupStart()
|
294 |
+
paintEnd() --> paintMethodEnd(), paintCaseEnd(), paintGroupEnd()
|
295 |
+
|
296 |
+
This change was made in Beta3, ironically to make it easier to subclass
|
297 |
+
the inner machinery. Simply duplicating the code you had in the previous
|
298 |
+
methods should provide a temporary fix.
|
299 |
+
|
300 |
+
No class TestDisplay
|
301 |
+
--------------------
|
302 |
+
This has been folded into SimpleReporter in Beta3 and is now deprecated.
|
303 |
+
It was removed in RC1.
|
304 |
+
|
305 |
+
No method WebTestCase::fetch()
|
306 |
+
------------------------------
|
307 |
+
This was renamed get() in Alpha8. It is removed in Beta3.
|
308 |
+
|
309 |
+
No method submit()
|
310 |
+
------------------
|
311 |
+
This has been renamed clickSubmit() in Beta1. The old method was
|
312 |
+
removed in Beta2.
|
313 |
+
|
314 |
+
No method clearHistory()
|
315 |
+
------------------------
|
316 |
+
This method is deprecated in Beta2 and removed in RC1.
|
317 |
+
|
318 |
+
No method getCallCount()
|
319 |
+
------------------------
|
320 |
+
This method has been deprecated since Beta1 and has now been
|
321 |
+
removed. There are now more ways to set expectations on counts
|
322 |
+
and so this method should be unecessery. Removed in RC1.
|
323 |
+
|
324 |
+
Cannot find file *
|
325 |
+
------------------
|
326 |
+
The following public name changes have occoured...
|
327 |
+
|
328 |
+
simple_html_test.php --> reporter.php
|
329 |
+
simple_mock.php --> mock_objects.php
|
330 |
+
simple_unit.php --> unit_tester.php
|
331 |
+
simple_web.php --> web_tester.php
|
332 |
+
|
333 |
+
The old names were deprecated in Alpha8 and removed in Beta1.
|
334 |
+
|
335 |
+
No method attachObserver()
|
336 |
+
--------------------------
|
337 |
+
Prior to the Alpha8 release the old internal observer pattern was
|
338 |
+
gutted and replaced with a visitor. This is to trade flexibility of
|
339 |
+
test case expansion against the ease of writing user interfaces.
|
340 |
+
|
341 |
+
Code such as...
|
342 |
+
|
343 |
+
$test = &new MyTestCase();
|
344 |
+
$test->attachObserver(new TestHtmlDisplay());
|
345 |
+
$test->run();
|
346 |
+
|
347 |
+
...should be rewritten as...
|
348 |
+
|
349 |
+
$test = &new MyTestCase();
|
350 |
+
$test->run(new HtmlReporter());
|
351 |
+
|
352 |
+
If you previously attached multiple observers then the workaround
|
353 |
+
is to run the tests twice, once with each, until they can be combined.
|
354 |
+
For one observer the old method is simulated in Alpha 8, but is
|
355 |
+
removed in Beta1.
|
356 |
+
|
357 |
+
No class TestHtmlDisplay
|
358 |
+
------------------------
|
359 |
+
This class has been renamed to HtmlReporter in Alpha8. It is supported,
|
360 |
+
but deprecated in Beta1 and removed in Beta2. If you have subclassed
|
361 |
+
the display for your own design, then you will have to extend this
|
362 |
+
class (HtmlReporter) instead.
|
363 |
+
|
364 |
+
If you have accessed the event queue by overriding the notify() method
|
365 |
+
then I am afraid you are in big trouble :(. The reporter is now
|
366 |
+
carried around the test suite by the runner classes and the methods
|
367 |
+
called directly. In the unlikely event that this is a problem and
|
368 |
+
you don't want to upgrade the test tool then simplest is to write your
|
369 |
+
own runner class and invoke the tests with...
|
370 |
+
|
371 |
+
$test->accept(new MyRunner(new MyReporter()));
|
372 |
+
|
373 |
+
...rather than the run method. This should be easier to extend
|
374 |
+
anyway and gives much more control. Even this method is overhauled
|
375 |
+
in Beta3 where the runner class can be set within the test case. Really
|
376 |
+
the best thing to do is to upgrade to this version as whatever you were
|
377 |
+
trying to achieve before should now be very much easier.
|
378 |
+
|
379 |
+
Missing set options method
|
380 |
+
--------------------------
|
381 |
+
All test suite options are now in one class called SimpleTestOptions.
|
382 |
+
This means that options are set differently...
|
383 |
+
|
384 |
+
GroupTest::ignore() --> SimpleTestOptions::ignore()
|
385 |
+
Mock::setMockBaseClass() --> SimpleTestOptions::setMockBaseClass()
|
386 |
+
|
387 |
+
These changed in Alpha8 and the old versions are now removed in RC1.
|
388 |
+
|
389 |
+
No method setExpected*()
|
390 |
+
------------------------
|
391 |
+
The mock expectations changed their names in Alpha4 and the old names
|
392 |
+
ceased to be supported in Alpha8. The changes are...
|
393 |
+
|
394 |
+
setExpectedArguments() --> expectArguments()
|
395 |
+
setExpectedArgumentsSequence() --> expectArgumentsAt()
|
396 |
+
setExpectedCallCount() --> expectCallCount()
|
397 |
+
setMaximumCallCount() --> expectMaximumCallCount()
|
398 |
+
|
399 |
+
The parameters remained the same.
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/LICENSE
ADDED
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2 |
+
Version 2.1, February 1999
|
3 |
+
|
4 |
+
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
5 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6 |
+
Everyone is permitted to copy and distribute verbatim copies
|
7 |
+
of this license document, but changing it is not allowed.
|
8 |
+
|
9 |
+
[This is the first released version of the Lesser GPL. It also counts
|
10 |
+
as the successor of the GNU Library Public License, version 2, hence
|
11 |
+
the version number 2.1.]
|
12 |
+
|
13 |
+
Preamble
|
14 |
+
|
15 |
+
The licenses for most software are designed to take away your
|
16 |
+
freedom to share and change it. By contrast, the GNU General Public
|
17 |
+
Licenses are intended to guarantee your freedom to share and change
|
18 |
+
free software--to make sure the software is free for all its users.
|
19 |
+
|
20 |
+
This license, the Lesser General Public License, applies to some
|
21 |
+
specially designated software packages--typically libraries--of the
|
22 |
+
Free Software Foundation and other authors who decide to use it. You
|
23 |
+
can use it too, but we suggest you first think carefully about whether
|
24 |
+
this license or the ordinary General Public License is the better
|
25 |
+
strategy to use in any particular case, based on the explanations below.
|
26 |
+
|
27 |
+
When we speak of free software, we are referring to freedom of use,
|
28 |
+
not price. Our General Public Licenses are designed to make sure that
|
29 |
+
you have the freedom to distribute copies of free software (and charge
|
30 |
+
for this service if you wish); that you receive source code or can get
|
31 |
+
it if you want it; that you can change the software and use pieces of
|
32 |
+
it in new free programs; and that you are informed that you can do
|
33 |
+
these things.
|
34 |
+
|
35 |
+
To protect your rights, we need to make restrictions that forbid
|
36 |
+
distributors to deny you these rights or to ask you to surrender these
|
37 |
+
rights. These restrictions translate to certain responsibilities for
|
38 |
+
you if you distribute copies of the library or if you modify it.
|
39 |
+
|
40 |
+
For example, if you distribute copies of the library, whether gratis
|
41 |
+
or for a fee, you must give the recipients all the rights that we gave
|
42 |
+
you. You must make sure that they, too, receive or can get the source
|
43 |
+
code. If you link other code with the library, you must provide
|
44 |
+
complete object files to the recipients, so that they can relink them
|
45 |
+
with the library after making changes to the library and recompiling
|
46 |
+
it. And you must show them these terms so they know their rights.
|
47 |
+
|
48 |
+
We protect your rights with a two-step method: (1) we copyright the
|
49 |
+
library, and (2) we offer you this license, which gives you legal
|
50 |
+
permission to copy, distribute and/or modify the library.
|
51 |
+
|
52 |
+
To protect each distributor, we want to make it very clear that
|
53 |
+
there is no warranty for the free library. Also, if the library is
|
54 |
+
modified by someone else and passed on, the recipients should know
|
55 |
+
that what they have is not the original version, so that the original
|
56 |
+
author's reputation will not be affected by problems that might be
|
57 |
+
introduced by others.
|
58 |
+
|
59 |
+
Finally, software patents pose a constant threat to the existence of
|
60 |
+
any free program. We wish to make sure that a company cannot
|
61 |
+
effectively restrict the users of a free program by obtaining a
|
62 |
+
restrictive license from a patent holder. Therefore, we insist that
|
63 |
+
any patent license obtained for a version of the library must be
|
64 |
+
consistent with the full freedom of use specified in this license.
|
65 |
+
|
66 |
+
Most GNU software, including some libraries, is covered by the
|
67 |
+
ordinary GNU General Public License. This license, the GNU Lesser
|
68 |
+
General Public License, applies to certain designated libraries, and
|
69 |
+
is quite different from the ordinary General Public License. We use
|
70 |
+
this license for certain libraries in order to permit linking those
|
71 |
+
libraries into non-free programs.
|
72 |
+
|
73 |
+
When a program is linked with a library, whether statically or using
|
74 |
+
a shared library, the combination of the two is legally speaking a
|
75 |
+
combined work, a derivative of the original library. The ordinary
|
76 |
+
General Public License therefore permits such linking only if the
|
77 |
+
entire combination fits its criteria of freedom. The Lesser General
|
78 |
+
Public License permits more lax criteria for linking other code with
|
79 |
+
the library.
|
80 |
+
|
81 |
+
We call this license the "Lesser" General Public License because it
|
82 |
+
does Less to protect the user's freedom than the ordinary General
|
83 |
+
Public License. It also provides other free software developers Less
|
84 |
+
of an advantage over competing non-free programs. These disadvantages
|
85 |
+
are the reason we use the ordinary General Public License for many
|
86 |
+
libraries. However, the Lesser license provides advantages in certain
|
87 |
+
special circumstances.
|
88 |
+
|
89 |
+
For example, on rare occasions, there may be a special need to
|
90 |
+
encourage the widest possible use of a certain library, so that it becomes
|
91 |
+
a de-facto standard. To achieve this, non-free programs must be
|
92 |
+
allowed to use the library. A more frequent case is that a free
|
93 |
+
library does the same job as widely used non-free libraries. In this
|
94 |
+
case, there is little to gain by limiting the free library to free
|
95 |
+
software only, so we use the Lesser General Public License.
|
96 |
+
|
97 |
+
In other cases, permission to use a particular library in non-free
|
98 |
+
programs enables a greater number of people to use a large body of
|
99 |
+
free software. For example, permission to use the GNU C Library in
|
100 |
+
non-free programs enables many more people to use the whole GNU
|
101 |
+
operating system, as well as its variant, the GNU/Linux operating
|
102 |
+
system.
|
103 |
+
|
104 |
+
Although the Lesser General Public License is Less protective of the
|
105 |
+
users' freedom, it does ensure that the user of a program that is
|
106 |
+
linked with the Library has the freedom and the wherewithal to run
|
107 |
+
that program using a modified version of the Library.
|
108 |
+
|
109 |
+
The precise terms and conditions for copying, distribution and
|
110 |
+
modification follow. Pay close attention to the difference between a
|
111 |
+
"work based on the library" and a "work that uses the library". The
|
112 |
+
former contains code derived from the library, whereas the latter must
|
113 |
+
be combined with the library in order to run.
|
114 |
+
|
115 |
+
GNU LESSER GENERAL PUBLIC LICENSE
|
116 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
117 |
+
|
118 |
+
0. This License Agreement applies to any software library or other
|
119 |
+
program which contains a notice placed by the copyright holder or
|
120 |
+
other authorized party saying it may be distributed under the terms of
|
121 |
+
this Lesser General Public License (also called "this License").
|
122 |
+
Each licensee is addressed as "you".
|
123 |
+
|
124 |
+
A "library" means a collection of software functions and/or data
|
125 |
+
prepared so as to be conveniently linked with application programs
|
126 |
+
(which use some of those functions and data) to form executables.
|
127 |
+
|
128 |
+
The "Library", below, refers to any such software library or work
|
129 |
+
which has been distributed under these terms. A "work based on the
|
130 |
+
Library" means either the Library or any derivative work under
|
131 |
+
copyright law: that is to say, a work containing the Library or a
|
132 |
+
portion of it, either verbatim or with modifications and/or translated
|
133 |
+
straightforwardly into another language. (Hereinafter, translation is
|
134 |
+
included without limitation in the term "modification".)
|
135 |
+
|
136 |
+
"Source code" for a work means the preferred form of the work for
|
137 |
+
making modifications to it. For a library, complete source code means
|
138 |
+
all the source code for all modules it contains, plus any associated
|
139 |
+
interface definition files, plus the scripts used to control compilation
|
140 |
+
and installation of the library.
|
141 |
+
|
142 |
+
Activities other than copying, distribution and modification are not
|
143 |
+
covered by this License; they are outside its scope. The act of
|
144 |
+
running a program using the Library is not restricted, and output from
|
145 |
+
such a program is covered only if its contents constitute a work based
|
146 |
+
on the Library (independent of the use of the Library in a tool for
|
147 |
+
writing it). Whether that is true depends on what the Library does
|
148 |
+
and what the program that uses the Library does.
|
149 |
+
|
150 |
+
1. You may copy and distribute verbatim copies of the Library's
|
151 |
+
complete source code as you receive it, in any medium, provided that
|
152 |
+
you conspicuously and appropriately publish on each copy an
|
153 |
+
appropriate copyright notice and disclaimer of warranty; keep intact
|
154 |
+
all the notices that refer to this License and to the absence of any
|
155 |
+
warranty; and distribute a copy of this License along with the
|
156 |
+
Library.
|
157 |
+
|
158 |
+
You may charge a fee for the physical act of transferring a copy,
|
159 |
+
and you may at your option offer warranty protection in exchange for a
|
160 |
+
fee.
|
161 |
+
|
162 |
+
2. You may modify your copy or copies of the Library or any portion
|
163 |
+
of it, thus forming a work based on the Library, and copy and
|
164 |
+
distribute such modifications or work under the terms of Section 1
|
165 |
+
above, provided that you also meet all of these conditions:
|
166 |
+
|
167 |
+
a) The modified work must itself be a software library.
|
168 |
+
|
169 |
+
b) You must cause the files modified to carry prominent notices
|
170 |
+
stating that you changed the files and the date of any change.
|
171 |
+
|
172 |
+
c) You must cause the whole of the work to be licensed at no
|
173 |
+
charge to all third parties under the terms of this License.
|
174 |
+
|
175 |
+
d) If a facility in the modified Library refers to a function or a
|
176 |
+
table of data to be supplied by an application program that uses
|
177 |
+
the facility, other than as an argument passed when the facility
|
178 |
+
is invoked, then you must make a good faith effort to ensure that,
|
179 |
+
in the event an application does not supply such function or
|
180 |
+
table, the facility still operates, and performs whatever part of
|
181 |
+
its purpose remains meaningful.
|
182 |
+
|
183 |
+
(For example, a function in a library to compute square roots has
|
184 |
+
a purpose that is entirely well-defined independent of the
|
185 |
+
application. Therefore, Subsection 2d requires that any
|
186 |
+
application-supplied function or table used by this function must
|
187 |
+
be optional: if the application does not supply it, the square
|
188 |
+
root function must still compute square roots.)
|
189 |
+
|
190 |
+
These requirements apply to the modified work as a whole. If
|
191 |
+
identifiable sections of that work are not derived from the Library,
|
192 |
+
and can be reasonably considered independent and separate works in
|
193 |
+
themselves, then this License, and its terms, do not apply to those
|
194 |
+
sections when you distribute them as separate works. But when you
|
195 |
+
distribute the same sections as part of a whole which is a work based
|
196 |
+
on the Library, the distribution of the whole must be on the terms of
|
197 |
+
this License, whose permissions for other licensees extend to the
|
198 |
+
entire whole, and thus to each and every part regardless of who wrote
|
199 |
+
it.
|
200 |
+
|
201 |
+
Thus, it is not the intent of this section to claim rights or contest
|
202 |
+
your rights to work written entirely by you; rather, the intent is to
|
203 |
+
exercise the right to control the distribution of derivative or
|
204 |
+
collective works based on the Library.
|
205 |
+
|
206 |
+
In addition, mere aggregation of another work not based on the Library
|
207 |
+
with the Library (or with a work based on the Library) on a volume of
|
208 |
+
a storage or distribution medium does not bring the other work under
|
209 |
+
the scope of this License.
|
210 |
+
|
211 |
+
3. You may opt to apply the terms of the ordinary GNU General Public
|
212 |
+
License instead of this License to a given copy of the Library. To do
|
213 |
+
this, you must alter all the notices that refer to this License, so
|
214 |
+
that they refer to the ordinary GNU General Public License, version 2,
|
215 |
+
instead of to this License. (If a newer version than version 2 of the
|
216 |
+
ordinary GNU General Public License has appeared, then you can specify
|
217 |
+
that version instead if you wish.) Do not make any other change in
|
218 |
+
these notices.
|
219 |
+
|
220 |
+
Once this change is made in a given copy, it is irreversible for
|
221 |
+
that copy, so the ordinary GNU General Public License applies to all
|
222 |
+
subsequent copies and derivative works made from that copy.
|
223 |
+
|
224 |
+
This option is useful when you wish to copy part of the code of
|
225 |
+
the Library into a program that is not a library.
|
226 |
+
|
227 |
+
4. You may copy and distribute the Library (or a portion or
|
228 |
+
derivative of it, under Section 2) in object code or executable form
|
229 |
+
under the terms of Sections 1 and 2 above provided that you accompany
|
230 |
+
it with the complete corresponding machine-readable source code, which
|
231 |
+
must be distributed under the terms of Sections 1 and 2 above on a
|
232 |
+
medium customarily used for software interchange.
|
233 |
+
|
234 |
+
If distribution of object code is made by offering access to copy
|
235 |
+
from a designated place, then offering equivalent access to copy the
|
236 |
+
source code from the same place satisfies the requirement to
|
237 |
+
distribute the source code, even though third parties are not
|
238 |
+
compelled to copy the source along with the object code.
|
239 |
+
|
240 |
+
5. A program that contains no derivative of any portion of the
|
241 |
+
Library, but is designed to work with the Library by being compiled or
|
242 |
+
linked with it, is called a "work that uses the Library". Such a
|
243 |
+
work, in isolation, is not a derivative work of the Library, and
|
244 |
+
therefore falls outside the scope of this License.
|
245 |
+
|
246 |
+
However, linking a "work that uses the Library" with the Library
|
247 |
+
creates an executable that is a derivative of the Library (because it
|
248 |
+
contains portions of the Library), rather than a "work that uses the
|
249 |
+
library". The executable is therefore covered by this License.
|
250 |
+
Section 6 states terms for distribution of such executables.
|
251 |
+
|
252 |
+
When a "work that uses the Library" uses material from a header file
|
253 |
+
that is part of the Library, the object code for the work may be a
|
254 |
+
derivative work of the Library even though the source code is not.
|
255 |
+
Whether this is true is especially significant if the work can be
|
256 |
+
linked without the Library, or if the work is itself a library. The
|
257 |
+
threshold for this to be true is not precisely defined by law.
|
258 |
+
|
259 |
+
If such an object file uses only numerical parameters, data
|
260 |
+
structure layouts and accessors, and small macros and small inline
|
261 |
+
functions (ten lines or less in length), then the use of the object
|
262 |
+
file is unrestricted, regardless of whether it is legally a derivative
|
263 |
+
work. (Executables containing this object code plus portions of the
|
264 |
+
Library will still fall under Section 6.)
|
265 |
+
|
266 |
+
Otherwise, if the work is a derivative of the Library, you may
|
267 |
+
distribute the object code for the work under the terms of Section 6.
|
268 |
+
Any executables containing that work also fall under Section 6,
|
269 |
+
whether or not they are linked directly with the Library itself.
|
270 |
+
|
271 |
+
6. As an exception to the Sections above, you may also combine or
|
272 |
+
link a "work that uses the Library" with the Library to produce a
|
273 |
+
work containing portions of the Library, and distribute that work
|
274 |
+
under terms of your choice, provided that the terms permit
|
275 |
+
modification of the work for the customer's own use and reverse
|
276 |
+
engineering for debugging such modifications.
|
277 |
+
|
278 |
+
You must give prominent notice with each copy of the work that the
|
279 |
+
Library is used in it and that the Library and its use are covered by
|
280 |
+
this License. You must supply a copy of this License. If the work
|
281 |
+
during execution displays copyright notices, you must include the
|
282 |
+
copyright notice for the Library among them, as well as a reference
|
283 |
+
directing the user to the copy of this License. Also, you must do one
|
284 |
+
of these things:
|
285 |
+
|
286 |
+
a) Accompany the work with the complete corresponding
|
287 |
+
machine-readable source code for the Library including whatever
|
288 |
+
changes were used in the work (which must be distributed under
|
289 |
+
Sections 1 and 2 above); and, if the work is an executable linked
|
290 |
+
with the Library, with the complete machine-readable "work that
|
291 |
+
uses the Library", as object code and/or source code, so that the
|
292 |
+
user can modify the Library and then relink to produce a modified
|
293 |
+
executable containing the modified Library. (It is understood
|
294 |
+
that the user who changes the contents of definitions files in the
|
295 |
+
Library will not necessarily be able to recompile the application
|
296 |
+
to use the modified definitions.)
|
297 |
+
|
298 |
+
b) Use a suitable shared library mechanism for linking with the
|
299 |
+
Library. A suitable mechanism is one that (1) uses at run time a
|
300 |
+
copy of the library already present on the user's computer system,
|
301 |
+
rather than copying library functions into the executable, and (2)
|
302 |
+
will operate properly with a modified version of the library, if
|
303 |
+
the user installs one, as long as the modified version is
|
304 |
+
interface-compatible with the version that the work was made with.
|
305 |
+
|
306 |
+
c) Accompany the work with a written offer, valid for at
|
307 |
+
least three years, to give the same user the materials
|
308 |
+
specified in Subsection 6a, above, for a charge no more
|
309 |
+
than the cost of performing this distribution.
|
310 |
+
|
311 |
+
d) If distribution of the work is made by offering access to copy
|
312 |
+
from a designated place, offer equivalent access to copy the above
|
313 |
+
specified materials from the same place.
|
314 |
+
|
315 |
+
e) Verify that the user has already received a copy of these
|
316 |
+
materials or that you have already sent this user a copy.
|
317 |
+
|
318 |
+
For an executable, the required form of the "work that uses the
|
319 |
+
Library" must include any data and utility programs needed for
|
320 |
+
reproducing the executable from it. However, as a special exception,
|
321 |
+
the materials to be distributed need not include anything that is
|
322 |
+
normally distributed (in either source or binary form) with the major
|
323 |
+
components (compiler, kernel, and so on) of the operating system on
|
324 |
+
which the executable runs, unless that component itself accompanies
|
325 |
+
the executable.
|
326 |
+
|
327 |
+
It may happen that this requirement contradicts the license
|
328 |
+
restrictions of other proprietary libraries that do not normally
|
329 |
+
accompany the operating system. Such a contradiction means you cannot
|
330 |
+
use both them and the Library together in an executable that you
|
331 |
+
distribute.
|
332 |
+
|
333 |
+
7. You may place library facilities that are a work based on the
|
334 |
+
Library side-by-side in a single library together with other library
|
335 |
+
facilities not covered by this License, and distribute such a combined
|
336 |
+
library, provided that the separate distribution of the work based on
|
337 |
+
the Library and of the other library facilities is otherwise
|
338 |
+
permitted, and provided that you do these two things:
|
339 |
+
|
340 |
+
a) Accompany the combined library with a copy of the same work
|
341 |
+
based on the Library, uncombined with any other library
|
342 |
+
facilities. This must be distributed under the terms of the
|
343 |
+
Sections above.
|
344 |
+
|
345 |
+
b) Give prominent notice with the combined library of the fact
|
346 |
+
that part of it is a work based on the Library, and explaining
|
347 |
+
where to find the accompanying uncombined form of the same work.
|
348 |
+
|
349 |
+
8. You may not copy, modify, sublicense, link with, or distribute
|
350 |
+
the Library except as expressly provided under this License. Any
|
351 |
+
attempt otherwise to copy, modify, sublicense, link with, or
|
352 |
+
distribute the Library is void, and will automatically terminate your
|
353 |
+
rights under this License. However, parties who have received copies,
|
354 |
+
or rights, from you under this License will not have their licenses
|
355 |
+
terminated so long as such parties remain in full compliance.
|
356 |
+
|
357 |
+
9. You are not required to accept this License, since you have not
|
358 |
+
signed it. However, nothing else grants you permission to modify or
|
359 |
+
distribute the Library or its derivative works. These actions are
|
360 |
+
prohibited by law if you do not accept this License. Therefore, by
|
361 |
+
modifying or distributing the Library (or any work based on the
|
362 |
+
Library), you indicate your acceptance of this License to do so, and
|
363 |
+
all its terms and conditions for copying, distributing or modifying
|
364 |
+
the Library or works based on it.
|
365 |
+
|
366 |
+
10. Each time you redistribute the Library (or any work based on the
|
367 |
+
Library), the recipient automatically receives a license from the
|
368 |
+
original licensor to copy, distribute, link with or modify the Library
|
369 |
+
subject to these terms and conditions. You may not impose any further
|
370 |
+
restrictions on the recipients' exercise of the rights granted herein.
|
371 |
+
You are not responsible for enforcing compliance by third parties with
|
372 |
+
this License.
|
373 |
+
|
374 |
+
11. If, as a consequence of a court judgment or allegation of patent
|
375 |
+
infringement or for any other reason (not limited to patent issues),
|
376 |
+
conditions are imposed on you (whether by court order, agreement or
|
377 |
+
otherwise) that contradict the conditions of this License, they do not
|
378 |
+
excuse you from the conditions of this License. If you cannot
|
379 |
+
distribute so as to satisfy simultaneously your obligations under this
|
380 |
+
License and any other pertinent obligations, then as a consequence you
|
381 |
+
may not distribute the Library at all. For example, if a patent
|
382 |
+
license would not permit royalty-free redistribution of the Library by
|
383 |
+
all those who receive copies directly or indirectly through you, then
|
384 |
+
the only way you could satisfy both it and this License would be to
|
385 |
+
refrain entirely from distribution of the Library.
|
386 |
+
|
387 |
+
If any portion of this section is held invalid or unenforceable under any
|
388 |
+
particular circumstance, the balance of the section is intended to apply,
|
389 |
+
and the section as a whole is intended to apply in other circumstances.
|
390 |
+
|
391 |
+
It is not the purpose of this section to induce you to infringe any
|
392 |
+
patents or other property right claims or to contest validity of any
|
393 |
+
such claims; this section has the sole purpose of protecting the
|
394 |
+
integrity of the free software distribution system which is
|
395 |
+
implemented by public license practices. Many people have made
|
396 |
+
generous contributions to the wide range of software distributed
|
397 |
+
through that system in reliance on consistent application of that
|
398 |
+
system; it is up to the author/donor to decide if he or she is willing
|
399 |
+
to distribute software through any other system and a licensee cannot
|
400 |
+
impose that choice.
|
401 |
+
|
402 |
+
This section is intended to make thoroughly clear what is believed to
|
403 |
+
be a consequence of the rest of this License.
|
404 |
+
|
405 |
+
12. If the distribution and/or use of the Library is restricted in
|
406 |
+
certain countries either by patents or by copyrighted interfaces, the
|
407 |
+
original copyright holder who places the Library under this License may add
|
408 |
+
an explicit geographical distribution limitation excluding those countries,
|
409 |
+
so that distribution is permitted only in or among countries not thus
|
410 |
+
excluded. In such case, this License incorporates the limitation as if
|
411 |
+
written in the body of this License.
|
412 |
+
|
413 |
+
13. The Free Software Foundation may publish revised and/or new
|
414 |
+
versions of the Lesser General Public License from time to time.
|
415 |
+
Such new versions will be similar in spirit to the present version,
|
416 |
+
but may differ in detail to address new problems or concerns.
|
417 |
+
|
418 |
+
Each version is given a distinguishing version number. If the Library
|
419 |
+
specifies a version number of this License which applies to it and
|
420 |
+
"any later version", you have the option of following the terms and
|
421 |
+
conditions either of that version or of any later version published by
|
422 |
+
the Free Software Foundation. If the Library does not specify a
|
423 |
+
license version number, you may choose any version ever published by
|
424 |
+
the Free Software Foundation.
|
425 |
+
|
426 |
+
14. If you wish to incorporate parts of the Library into other free
|
427 |
+
programs whose distribution conditions are incompatible with these,
|
428 |
+
write to the author to ask for permission. For software which is
|
429 |
+
copyrighted by the Free Software Foundation, write to the Free
|
430 |
+
Software Foundation; we sometimes make exceptions for this. Our
|
431 |
+
decision will be guided by the two goals of preserving the free status
|
432 |
+
of all derivatives of our free software and of promoting the sharing
|
433 |
+
and reuse of software generally.
|
434 |
+
|
435 |
+
NO WARRANTY
|
436 |
+
|
437 |
+
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
438 |
+
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
439 |
+
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
440 |
+
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
441 |
+
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
442 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
443 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
444 |
+
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
445 |
+
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
446 |
+
|
447 |
+
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
448 |
+
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
449 |
+
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
450 |
+
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
451 |
+
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
452 |
+
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
453 |
+
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
454 |
+
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
455 |
+
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
456 |
+
DAMAGES.
|
457 |
+
|
458 |
+
END OF TERMS AND CONDITIONS
|
459 |
+
|
460 |
+
How to Apply These Terms to Your New Libraries
|
461 |
+
|
462 |
+
If you develop a new library, and you want it to be of the greatest
|
463 |
+
possible use to the public, we recommend making it free software that
|
464 |
+
everyone can redistribute and change. You can do so by permitting
|
465 |
+
redistribution under these terms (or, alternatively, under the terms of the
|
466 |
+
ordinary General Public License).
|
467 |
+
|
468 |
+
To apply these terms, attach the following notices to the library. It is
|
469 |
+
safest to attach them to the start of each source file to most effectively
|
470 |
+
convey the exclusion of warranty; and each file should have at least the
|
471 |
+
"copyright" line and a pointer to where the full notice is found.
|
472 |
+
|
473 |
+
<one line to give the library's name and a brief idea of what it does.>
|
474 |
+
Copyright (C) <year> <name of author>
|
475 |
+
|
476 |
+
This library is free software; you can redistribute it and/or
|
477 |
+
modify it under the terms of the GNU Lesser General Public
|
478 |
+
License as published by the Free Software Foundation; either
|
479 |
+
version 2.1 of the License, or (at your option) any later version.
|
480 |
+
|
481 |
+
This library is distributed in the hope that it will be useful,
|
482 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
483 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
484 |
+
Lesser General Public License for more details.
|
485 |
+
|
486 |
+
You should have received a copy of the GNU Lesser General Public
|
487 |
+
License along with this library; if not, write to the Free Software
|
488 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
489 |
+
|
490 |
+
Also add information on how to contact you by electronic and paper mail.
|
491 |
+
|
492 |
+
You should also get your employer (if you work as a programmer) or your
|
493 |
+
school, if any, to sign a "copyright disclaimer" for the library, if
|
494 |
+
necessary. Here is a sample; alter the names:
|
495 |
+
|
496 |
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
497 |
+
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
498 |
+
|
499 |
+
<signature of Ty Coon>, 1 April 1990
|
500 |
+
Ty Coon, President of Vice
|
501 |
+
|
502 |
+
That's all there is to it!
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/README
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
SimpleTest
|
2 |
+
==========
|
3 |
+
|
4 |
+
You probably got this package from:
|
5 |
+
|
6 |
+
http://simpletest.org/en/download.html
|
7 |
+
|
8 |
+
If there is no licence agreement with this package please download
|
9 |
+
a version from the location above. You must read and accept that
|
10 |
+
licence to use this software. The file is titled simply LICENSE.
|
11 |
+
|
12 |
+
What is it? It's a framework for unit testing, web site testing and
|
13 |
+
mock objects for PHP 5.0.5+.
|
14 |
+
|
15 |
+
If you have used JUnit, you will find this PHP unit testing version very
|
16 |
+
similar. Also included is a mock objects and server stubs generator.
|
17 |
+
The stubs can have return values set for different arguments, can have
|
18 |
+
sequences set also by arguments and can return items by reference.
|
19 |
+
The mocks inherit all of this functionality and can also have
|
20 |
+
expectations set, again in sequences and for different arguments.
|
21 |
+
|
22 |
+
A web tester similar in concept to JWebUnit is also included. There is no
|
23 |
+
JavaScript or tables support, but forms, authentication, cookies and
|
24 |
+
frames are handled.
|
25 |
+
|
26 |
+
You can see a release schedule at http://simpletest.org/en/overview.html
|
27 |
+
which is also copied to the documentation folder with this release.
|
28 |
+
A full PHPDocumenter API documentation exists at
|
29 |
+
http://simpletest.org/api/.
|
30 |
+
|
31 |
+
The user interface is minimal in the extreme, but a lot of information
|
32 |
+
flows from the test suite. After version 1.0 we will release a better
|
33 |
+
web UI, but we are leaving XUL and GTK versions to volunteers as
|
34 |
+
everybody has their own opinion on a good GUI, and we don't want to
|
35 |
+
discourage development by shipping one with the toolkit. You can
|
36 |
+
download an Eclipse plug-in separately.
|
37 |
+
|
38 |
+
The unit tests for SimpleTest itself can be run here:
|
39 |
+
|
40 |
+
test/unit_tests.php
|
41 |
+
|
42 |
+
And tests involving live network connections as well are here:
|
43 |
+
|
44 |
+
test/all_tests.php
|
45 |
+
|
46 |
+
The full tests will typically overrun the 8Mb limit often allowed
|
47 |
+
to a PHP process. A workaround is to run the tests on the command
|
48 |
+
with a custom php.ini file or with the switch -dmemory_limit=-1
|
49 |
+
if you do not have access to your server version.
|
50 |
+
|
51 |
+
The full tests read some test data from simpletest.org. If the site
|
52 |
+
is down or has been modified for a later version then you will get
|
53 |
+
spurious errors. A unit_tests.php failure on the other hand would be
|
54 |
+
very serious. Please notify us if you find one.
|
55 |
+
|
56 |
+
Even if all of the tests run please verify that your existing test suites
|
57 |
+
also function as expected. The file:
|
58 |
+
|
59 |
+
HELP_MY_TESTS_DONT_WORK_ANYMORE
|
60 |
+
|
61 |
+
...contains information on interface changes. It also points out
|
62 |
+
deprecated interfaces, so you should read this even if all of
|
63 |
+
your current tests appear to run.
|
64 |
+
|
65 |
+
There is a documentation folder which contains the core reference information
|
66 |
+
in English and French, although this information is fairly basic.
|
67 |
+
You can find a tutorial on...
|
68 |
+
|
69 |
+
http://simpletest.org/en/first_test_tutorial.html
|
70 |
+
|
71 |
+
...to get you started and this material will eventually become included
|
72 |
+
with the project documentation. A French translation exists at:
|
73 |
+
|
74 |
+
http://simpletest.org/fr/first_test_tutorial.html
|
75 |
+
|
76 |
+
If you download and use, and possibly even extend this tool, please let us
|
77 |
+
know. Any feedback, even bad, is always welcome and we will work to get
|
78 |
+
your suggestions into the next release. Ideally please send your
|
79 |
+
comments to:
|
80 |
+
|
81 |
+
simpletest-support@lists.sourceforge.net
|
82 |
+
|
83 |
+
...so that others can read them too. We usually try to respond within 48
|
84 |
+
hours.
|
85 |
+
|
86 |
+
There is no change log except at Sourceforge. You can visit the
|
87 |
+
release notes to see the completed TODO list after each cycle and also the
|
88 |
+
status of any bugs, but if the bug is recent then it will be fixed in SVN only.
|
89 |
+
The SVN check-ins always have all the tests passing and so SVN snapshots should
|
90 |
+
be pretty usable, although the code may not look so good internally.
|
91 |
+
|
92 |
+
Oh, and one last thing: SimpleTest is called "Simple" because it should
|
93 |
+
be simple to use. We intend to add a complete set of tools for a test
|
94 |
+
first and "test as you code" type of development. "Simple" does not mean
|
95 |
+
"Lite" in this context.
|
96 |
+
|
97 |
+
Thanks to everyone who has sent comments and offered suggestions. They
|
98 |
+
really are invaluable, but sadly you are too many to mention in full.
|
99 |
+
Thanks to all on the advanced PHP forum on SitePoint, especially Harry
|
100 |
+
Fuecks. Early adopters are always an inspiration.
|
101 |
+
|
102 |
+
-- Marcus Baker, Jason Sweat, Travis Swicegood, Perrick Penet and Edward Z. Yang.
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/VERSION
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
1.1alpha3
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/authentication.php
ADDED
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Base include file for SimpleTest
|
4 |
+
* @package SimpleTest
|
5 |
+
* @subpackage WebTester
|
6 |
+
* @version $Id: authentication.php 2011 2011-04-29 08:22:48Z pp11 $
|
7 |
+
*/
|
8 |
+
/**
|
9 |
+
* include http class
|
10 |
+
*/
|
11 |
+
require_once(dirname(__FILE__) . '/http.php');
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Represents a single security realm's identity.
|
15 |
+
* @package SimpleTest
|
16 |
+
* @subpackage WebTester
|
17 |
+
*/
|
18 |
+
class SimpleRealm {
|
19 |
+
private $type;
|
20 |
+
private $root;
|
21 |
+
private $username;
|
22 |
+
private $password;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Starts with the initial entry directory.
|
26 |
+
* @param string $type Authentication type for this
|
27 |
+
* realm. Only Basic authentication
|
28 |
+
* is currently supported.
|
29 |
+
* @param SimpleUrl $url Somewhere in realm.
|
30 |
+
* @access public
|
31 |
+
*/
|
32 |
+
function SimpleRealm($type, $url) {
|
33 |
+
$this->type = $type;
|
34 |
+
$this->root = $url->getBasePath();
|
35 |
+
$this->username = false;
|
36 |
+
$this->password = false;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Adds another location to the realm.
|
41 |
+
* @param SimpleUrl $url Somewhere in realm.
|
42 |
+
* @access public
|
43 |
+
*/
|
44 |
+
function stretch($url) {
|
45 |
+
$this->root = $this->getCommonPath($this->root, $url->getPath());
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Finds the common starting path.
|
50 |
+
* @param string $first Path to compare.
|
51 |
+
* @param string $second Path to compare.
|
52 |
+
* @return string Common directories.
|
53 |
+
* @access private
|
54 |
+
*/
|
55 |
+
protected function getCommonPath($first, $second) {
|
56 |
+
$first = explode('/', $first);
|
57 |
+
$second = explode('/', $second);
|
58 |
+
for ($i = 0; $i < min(count($first), count($second)); $i++) {
|
59 |
+
if ($first[$i] != $second[$i]) {
|
60 |
+
return implode('/', array_slice($first, 0, $i)) . '/';
|
61 |
+
}
|
62 |
+
}
|
63 |
+
return implode('/', $first) . '/';
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Sets the identity to try within this realm.
|
68 |
+
* @param string $username Username in authentication dialog.
|
69 |
+
* @param string $username Password in authentication dialog.
|
70 |
+
* @access public
|
71 |
+
*/
|
72 |
+
function setIdentity($username, $password) {
|
73 |
+
$this->username = $username;
|
74 |
+
$this->password = $password;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Accessor for current identity.
|
79 |
+
* @return string Last succesful username.
|
80 |
+
* @access public
|
81 |
+
*/
|
82 |
+
function getUsername() {
|
83 |
+
return $this->username;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Accessor for current identity.
|
88 |
+
* @return string Last succesful password.
|
89 |
+
* @access public
|
90 |
+
*/
|
91 |
+
function getPassword() {
|
92 |
+
return $this->password;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Test to see if the URL is within the directory
|
97 |
+
* tree of the realm.
|
98 |
+
* @param SimpleUrl $url URL to test.
|
99 |
+
* @return boolean True if subpath.
|
100 |
+
* @access public
|
101 |
+
*/
|
102 |
+
function isWithin($url) {
|
103 |
+
if ($this->isIn($this->root, $url->getBasePath())) {
|
104 |
+
return true;
|
105 |
+
}
|
106 |
+
if ($this->isIn($this->root, $url->getBasePath() . $url->getPage() . '/')) {
|
107 |
+
return true;
|
108 |
+
}
|
109 |
+
return false;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Tests to see if one string is a substring of
|
114 |
+
* another.
|
115 |
+
* @param string $part Small bit.
|
116 |
+
* @param string $whole Big bit.
|
117 |
+
* @return boolean True if the small bit is
|
118 |
+
* in the big bit.
|
119 |
+
* @access private
|
120 |
+
*/
|
121 |
+
protected function isIn($part, $whole) {
|
122 |
+
return strpos($whole, $part) === 0;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Manages security realms.
|
128 |
+
* @package SimpleTest
|
129 |
+
* @subpackage WebTester
|
130 |
+
*/
|
131 |
+
class SimpleAuthenticator {
|
132 |
+
private $realms;
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Clears the realms.
|
136 |
+
* @access public
|
137 |
+
*/
|
138 |
+
function SimpleAuthenticator() {
|
139 |
+
$this->restartSession();
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Starts with no realms set up.
|
144 |
+
* @access public
|
145 |
+
*/
|
146 |
+
function restartSession() {
|
147 |
+
$this->realms = array();
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Adds a new realm centered the current URL.
|
152 |
+
* Browsers privatey wildly on their behaviour in this
|
153 |
+
* regard. Mozilla ignores the realm and presents
|
154 |
+
* only when challenged, wasting bandwidth. IE
|
155 |
+
* just carries on presenting until a new challenge
|
156 |
+
* occours. SimpleTest tries to follow the spirit of
|
157 |
+
* the original standards committee and treats the
|
158 |
+
* base URL as the root of a file tree shaped realm.
|
159 |
+
* @param SimpleUrl $url Base of realm.
|
160 |
+
* @param string $type Authentication type for this
|
161 |
+
* realm. Only Basic authentication
|
162 |
+
* is currently supported.
|
163 |
+
* @param string $realm Name of realm.
|
164 |
+
* @access public
|
165 |
+
*/
|
166 |
+
function addRealm($url, $type, $realm) {
|
167 |
+
$this->realms[$url->getHost()][$realm] = new SimpleRealm($type, $url);
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Sets the current identity to be presented
|
172 |
+
* against that realm.
|
173 |
+
* @param string $host Server hosting realm.
|
174 |
+
* @param string $realm Name of realm.
|
175 |
+
* @param string $username Username for realm.
|
176 |
+
* @param string $password Password for realm.
|
177 |
+
* @access public
|
178 |
+
*/
|
179 |
+
function setIdentityForRealm($host, $realm, $username, $password) {
|
180 |
+
if (isset($this->realms[$host][$realm])) {
|
181 |
+
$this->realms[$host][$realm]->setIdentity($username, $password);
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Finds the name of the realm by comparing URLs.
|
187 |
+
* @param SimpleUrl $url URL to test.
|
188 |
+
* @return SimpleRealm Name of realm.
|
189 |
+
* @access private
|
190 |
+
*/
|
191 |
+
protected function findRealmFromUrl($url) {
|
192 |
+
if (! isset($this->realms[$url->getHost()])) {
|
193 |
+
return false;
|
194 |
+
}
|
195 |
+
foreach ($this->realms[$url->getHost()] as $name => $realm) {
|
196 |
+
if ($realm->isWithin($url)) {
|
197 |
+
return $realm;
|
198 |
+
}
|
199 |
+
}
|
200 |
+
return false;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Presents the appropriate headers for this location.
|
205 |
+
* @param SimpleHttpRequest $request Request to modify.
|
206 |
+
* @param SimpleUrl $url Base of realm.
|
207 |
+
* @access public
|
208 |
+
*/
|
209 |
+
function addHeaders(&$request, $url) {
|
210 |
+
if ($url->getUsername() && $url->getPassword()) {
|
211 |
+
$username = $url->getUsername();
|
212 |
+
$password = $url->getPassword();
|
213 |
+
} elseif ($realm = $this->findRealmFromUrl($url)) {
|
214 |
+
$username = $realm->getUsername();
|
215 |
+
$password = $realm->getPassword();
|
216 |
+
} else {
|
217 |
+
return;
|
218 |
+
}
|
219 |
+
$this->addBasicHeaders($request, $username, $password);
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Presents the appropriate headers for this
|
224 |
+
* location for basic authentication.
|
225 |
+
* @param SimpleHttpRequest $request Request to modify.
|
226 |
+
* @param string $username Username for realm.
|
227 |
+
* @param string $password Password for realm.
|
228 |
+
* @access public
|
229 |
+
*/
|
230 |
+
static function addBasicHeaders(&$request, $username, $password) {
|
231 |
+
if ($username && $password) {
|
232 |
+
$request->addHeaderLine(
|
233 |
+
'Authorization: Basic ' . base64_encode("$username:$password"));
|
234 |
+
}
|
235 |
+
}
|
236 |
+
}
|
237 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/autorun.php
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Autorunner which runs all tests cases found in a file
|
4 |
+
* that includes this module.
|
5 |
+
* @package SimpleTest
|
6 |
+
* @version $Id: autorun.php 2011 2011-04-29 08:22:48Z pp11 $
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**#@+
|
10 |
+
* include simpletest files
|
11 |
+
*/
|
12 |
+
require_once dirname(__FILE__) . '/unit_tester.php';
|
13 |
+
require_once dirname(__FILE__) . '/mock_objects.php';
|
14 |
+
require_once dirname(__FILE__) . '/collector.php';
|
15 |
+
require_once dirname(__FILE__) . '/default_reporter.php';
|
16 |
+
/**#@-*/
|
17 |
+
|
18 |
+
$GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_CLASSES'] = get_declared_classes();
|
19 |
+
register_shutdown_function('simpletest_autorun');
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Exit handler to run all recent test cases and exit system if in CLI
|
23 |
+
*/
|
24 |
+
function simpletest_autorun() {
|
25 |
+
if (tests_have_run()) {
|
26 |
+
return;
|
27 |
+
}
|
28 |
+
$result = run_local_tests();
|
29 |
+
if (SimpleReporter::inCli()) {
|
30 |
+
exit($result ? 0 : 1);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* run all recent test cases if no test has
|
36 |
+
* so far been run. Uses the DefaultReporter which can have
|
37 |
+
* it's output controlled with SimpleTest::prefer().
|
38 |
+
* @return boolean/null false if there were test failures, true if
|
39 |
+
* there were no failures, null if tests are
|
40 |
+
* already running
|
41 |
+
*/
|
42 |
+
function run_local_tests() {
|
43 |
+
try {
|
44 |
+
if (tests_have_run()) {
|
45 |
+
return;
|
46 |
+
}
|
47 |
+
$candidates = capture_new_classes();
|
48 |
+
$loader = new SimpleFileLoader();
|
49 |
+
$suite = $loader->createSuiteFromClasses(
|
50 |
+
basename(initial_file()),
|
51 |
+
$loader->selectRunnableTests($candidates));
|
52 |
+
return $suite->run(new DefaultReporter());
|
53 |
+
} catch (Exception $stack_frame_fix) {
|
54 |
+
print $stack_frame_fix->getMessage();
|
55 |
+
return false;
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Checks the current test context to see if a test has
|
61 |
+
* ever been run.
|
62 |
+
* @return boolean True if tests have run.
|
63 |
+
*/
|
64 |
+
function tests_have_run() {
|
65 |
+
if ($context = SimpleTest::getContext()) {
|
66 |
+
return (boolean)$context->getTest();
|
67 |
+
}
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* The first autorun file.
|
73 |
+
* @return string Filename of first autorun script.
|
74 |
+
*/
|
75 |
+
function initial_file() {
|
76 |
+
static $file = false;
|
77 |
+
if (! $file) {
|
78 |
+
if (isset($_SERVER, $_SERVER['SCRIPT_FILENAME'])) {
|
79 |
+
$file = $_SERVER['SCRIPT_FILENAME'];
|
80 |
+
} else {
|
81 |
+
$included_files = get_included_files();
|
82 |
+
$file = reset($included_files);
|
83 |
+
}
|
84 |
+
}
|
85 |
+
return $file;
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Every class since the first autorun include. This
|
90 |
+
* is safe enough if require_once() is always used.
|
91 |
+
* @return array Class names.
|
92 |
+
*/
|
93 |
+
function capture_new_classes() {
|
94 |
+
global $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES;
|
95 |
+
return array_map('strtolower', array_diff(get_declared_classes(),
|
96 |
+
$SIMPLETEST_AUTORUNNER_INITIAL_CLASSES ?
|
97 |
+
$SIMPLETEST_AUTORUNNER_INITIAL_CLASSES : array()));
|
98 |
+
}
|
99 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/browser.php
ADDED
@@ -0,0 +1,1144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Base include file for SimpleTest
|
4 |
+
* @package SimpleTest
|
5 |
+
* @subpackage WebTester
|
6 |
+
* @version $Id: browser.php 2013 2011-04-29 09:29:45Z pp11 $
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**#@+
|
10 |
+
* include other SimpleTest class files
|
11 |
+
*/
|
12 |
+
require_once(dirname(__FILE__) . '/simpletest.php');
|
13 |
+
require_once(dirname(__FILE__) . '/http.php');
|
14 |
+
require_once(dirname(__FILE__) . '/encoding.php');
|
15 |
+
require_once(dirname(__FILE__) . '/page.php');
|
16 |
+
require_once(dirname(__FILE__) . '/php_parser.php');
|
17 |
+
require_once(dirname(__FILE__) . '/tidy_parser.php');
|
18 |
+
require_once(dirname(__FILE__) . '/selector.php');
|
19 |
+
require_once(dirname(__FILE__) . '/frames.php');
|
20 |
+
require_once(dirname(__FILE__) . '/user_agent.php');
|
21 |
+
if (! SimpleTest::getParsers()) {
|
22 |
+
SimpleTest::setParsers(array(new SimpleTidyPageBuilder(), new SimplePHPPageBuilder()));
|
23 |
+
//SimpleTest::setParsers(array(new SimplePHPPageBuilder()));
|
24 |
+
}
|
25 |
+
/**#@-*/
|
26 |
+
|
27 |
+
if (! defined('DEFAULT_MAX_NESTED_FRAMES')) {
|
28 |
+
define('DEFAULT_MAX_NESTED_FRAMES', 3);
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Browser history list.
|
33 |
+
* @package SimpleTest
|
34 |
+
* @subpackage WebTester
|
35 |
+
*/
|
36 |
+
class SimpleBrowserHistory {
|
37 |
+
private $sequence = array();
|
38 |
+
private $position = -1;
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Test for no entries yet.
|
42 |
+
* @return boolean True if empty.
|
43 |
+
* @access private
|
44 |
+
*/
|
45 |
+
protected function isEmpty() {
|
46 |
+
return ($this->position == -1);
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Test for being at the beginning.
|
51 |
+
* @return boolean True if first.
|
52 |
+
* @access private
|
53 |
+
*/
|
54 |
+
protected function atBeginning() {
|
55 |
+
return ($this->position == 0) && ! $this->isEmpty();
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Test for being at the last entry.
|
60 |
+
* @return boolean True if last.
|
61 |
+
* @access private
|
62 |
+
*/
|
63 |
+
protected function atEnd() {
|
64 |
+
return ($this->position + 1 >= count($this->sequence)) && ! $this->isEmpty();
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Adds a successfully fetched page to the history.
|
69 |
+
* @param SimpleUrl $url URL of fetch.
|
70 |
+
* @param SimpleEncoding $parameters Any post data with the fetch.
|
71 |
+
* @access public
|
72 |
+
*/
|
73 |
+
function recordEntry($url, $parameters) {
|
74 |
+
$this->dropFuture();
|
75 |
+
array_push(
|
76 |
+
$this->sequence,
|
77 |
+
array('url' => $url, 'parameters' => $parameters));
|
78 |
+
$this->position++;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Last fully qualified URL for current history
|
83 |
+
* position.
|
84 |
+
* @return SimpleUrl URL for this position.
|
85 |
+
* @access public
|
86 |
+
*/
|
87 |
+
function getUrl() {
|
88 |
+
if ($this->isEmpty()) {
|
89 |
+
return false;
|
90 |
+
}
|
91 |
+
return $this->sequence[$this->position]['url'];
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Parameters of last fetch from current history
|
96 |
+
* position.
|
97 |
+
* @return SimpleFormEncoding Post parameters.
|
98 |
+
* @access public
|
99 |
+
*/
|
100 |
+
function getParameters() {
|
101 |
+
if ($this->isEmpty()) {
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
return $this->sequence[$this->position]['parameters'];
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Step back one place in the history. Stops at
|
109 |
+
* the first page.
|
110 |
+
* @return boolean True if any previous entries.
|
111 |
+
* @access public
|
112 |
+
*/
|
113 |
+
function back() {
|
114 |
+
if ($this->isEmpty() || $this->atBeginning()) {
|
115 |
+
return false;
|
116 |
+
}
|
117 |
+
$this->position--;
|
118 |
+
return true;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Step forward one place. If already at the
|
123 |
+
* latest entry then nothing will happen.
|
124 |
+
* @return boolean True if any future entries.
|
125 |
+
* @access public
|
126 |
+
*/
|
127 |
+
function forward() {
|
128 |
+
if ($this->isEmpty() || $this->atEnd()) {
|
129 |
+
return false;
|
130 |
+
}
|
131 |
+
$this->position++;
|
132 |
+
return true;
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Ditches all future entries beyond the current
|
137 |
+
* point.
|
138 |
+
* @access private
|
139 |
+
*/
|
140 |
+
protected function dropFuture() {
|
141 |
+
if ($this->isEmpty()) {
|
142 |
+
return;
|
143 |
+
}
|
144 |
+
while (! $this->atEnd()) {
|
145 |
+
array_pop($this->sequence);
|
146 |
+
}
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Simulated web browser. This is an aggregate of
|
152 |
+
* the user agent, the HTML parsing, request history
|
153 |
+
* and the last header set.
|
154 |
+
* @package SimpleTest
|
155 |
+
* @subpackage WebTester
|
156 |
+
*/
|
157 |
+
class SimpleBrowser {
|
158 |
+
private $user_agent;
|
159 |
+
private $page;
|
160 |
+
private $history;
|
161 |
+
private $ignore_frames;
|
162 |
+
private $maximum_nested_frames;
|
163 |
+
private $parser;
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Starts with a fresh browser with no
|
167 |
+
* cookie or any other state information. The
|
168 |
+
* exception is that a default proxy will be
|
169 |
+
* set up if specified in the options.
|
170 |
+
* @access public
|
171 |
+
*/
|
172 |
+
function __construct() {
|
173 |
+
$this->user_agent = $this->createUserAgent();
|
174 |
+
$this->user_agent->useProxy(
|
175 |
+
SimpleTest::getDefaultProxy(),
|
176 |
+
SimpleTest::getDefaultProxyUsername(),
|
177 |
+
SimpleTest::getDefaultProxyPassword());
|
178 |
+
$this->page = new SimplePage();
|
179 |
+
$this->history = $this->createHistory();
|
180 |
+
$this->ignore_frames = false;
|
181 |
+
$this->maximum_nested_frames = DEFAULT_MAX_NESTED_FRAMES;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Creates the underlying user agent.
|
186 |
+
* @return SimpleFetcher Content fetcher.
|
187 |
+
* @access protected
|
188 |
+
*/
|
189 |
+
protected function createUserAgent() {
|
190 |
+
return new SimpleUserAgent();
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Creates a new empty history list.
|
195 |
+
* @return SimpleBrowserHistory New list.
|
196 |
+
* @access protected
|
197 |
+
*/
|
198 |
+
protected function createHistory() {
|
199 |
+
return new SimpleBrowserHistory();
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Get the HTML parser to use. Can be overridden by
|
204 |
+
* setParser. Otherwise scans through the available parsers and
|
205 |
+
* uses the first one which is available.
|
206 |
+
* @return object SimplePHPPageBuilder or SimpleTidyPageBuilder
|
207 |
+
*/
|
208 |
+
protected function getParser() {
|
209 |
+
if ($this->parser) {
|
210 |
+
return $this->parser;
|
211 |
+
}
|
212 |
+
foreach (SimpleTest::getParsers() as $parser) {
|
213 |
+
if ($parser->can()) {
|
214 |
+
return $parser;
|
215 |
+
}
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Override the default HTML parser, allowing parsers to be plugged in.
|
221 |
+
* @param object A parser object instance.
|
222 |
+
*/
|
223 |
+
public function setParser($parser) {
|
224 |
+
$this->parser = $parser;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Disables frames support. Frames will not be fetched
|
229 |
+
* and the frameset page will be used instead.
|
230 |
+
* @access public
|
231 |
+
*/
|
232 |
+
function ignoreFrames() {
|
233 |
+
$this->ignore_frames = true;
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Enables frames support. Frames will be fetched from
|
238 |
+
* now on.
|
239 |
+
* @access public
|
240 |
+
*/
|
241 |
+
function useFrames() {
|
242 |
+
$this->ignore_frames = false;
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Switches off cookie sending and recieving.
|
247 |
+
* @access public
|
248 |
+
*/
|
249 |
+
function ignoreCookies() {
|
250 |
+
$this->user_agent->ignoreCookies();
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Switches back on the cookie sending and recieving.
|
255 |
+
* @access public
|
256 |
+
*/
|
257 |
+
function useCookies() {
|
258 |
+
$this->user_agent->useCookies();
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Parses the raw content into a page. Will load further
|
263 |
+
* frame pages unless frames are disabled.
|
264 |
+
* @param SimpleHttpResponse $response Response from fetch.
|
265 |
+
* @param integer $depth Nested frameset depth.
|
266 |
+
* @return SimplePage Parsed HTML.
|
267 |
+
* @access private
|
268 |
+
*/
|
269 |
+
protected function parse($response, $depth = 0) {
|
270 |
+
$page = $this->buildPage($response);
|
271 |
+
if ($this->ignore_frames || ! $page->hasFrames() || ($depth > $this->maximum_nested_frames)) {
|
272 |
+
return $page;
|
273 |
+
}
|
274 |
+
$frameset = new SimpleFrameset($page);
|
275 |
+
foreach ($page->getFrameset() as $key => $url) {
|
276 |
+
$frame = $this->fetch($url, new SimpleGetEncoding(), $depth + 1);
|
277 |
+
$frameset->addFrame($frame, $key);
|
278 |
+
}
|
279 |
+
return $frameset;
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Assembles the parsing machinery and actually parses
|
284 |
+
* a single page. Frees all of the builder memory and so
|
285 |
+
* unjams the PHP memory management.
|
286 |
+
* @param SimpleHttpResponse $response Response from fetch.
|
287 |
+
* @return SimplePage Parsed top level page.
|
288 |
+
*/
|
289 |
+
protected function buildPage($response) {
|
290 |
+
return $this->getParser()->parse($response);
|
291 |
+
}
|
292 |
+
|
293 |
+
/**
|
294 |
+
* Fetches a page. Jointly recursive with the parse()
|
295 |
+
* method as it descends a frameset.
|
296 |
+
* @param string/SimpleUrl $url Target to fetch.
|
297 |
+
* @param SimpleEncoding $encoding GET/POST parameters.
|
298 |
+
* @param integer $depth Nested frameset depth protection.
|
299 |
+
* @return SimplePage Parsed page.
|
300 |
+
* @access private
|
301 |
+
*/
|
302 |
+
protected function fetch($url, $encoding, $depth = 0) {
|
303 |
+
$response = $this->user_agent->fetchResponse($url, $encoding);
|
304 |
+
if ($response->isError()) {
|
305 |
+
return new SimplePage($response);
|
306 |
+
}
|
307 |
+
return $this->parse($response, $depth);
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* Fetches a page or a single frame if that is the current
|
312 |
+
* focus.
|
313 |
+
* @param SimpleUrl $url Target to fetch.
|
314 |
+
* @param SimpleEncoding $parameters GET/POST parameters.
|
315 |
+
* @return string Raw content of page.
|
316 |
+
* @access private
|
317 |
+
*/
|
318 |
+
protected function load($url, $parameters) {
|
319 |
+
$frame = $url->getTarget();
|
320 |
+
if (! $frame || ! $this->page->hasFrames() || (strtolower($frame) == '_top')) {
|
321 |
+
return $this->loadPage($url, $parameters);
|
322 |
+
}
|
323 |
+
return $this->loadFrame(array($frame), $url, $parameters);
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Fetches a page and makes it the current page/frame.
|
328 |
+
* @param string/SimpleUrl $url Target to fetch as string.
|
329 |
+
* @param SimplePostEncoding $parameters POST parameters.
|
330 |
+
* @return string Raw content of page.
|
331 |
+
* @access private
|
332 |
+
*/
|
333 |
+
protected function loadPage($url, $parameters) {
|
334 |
+
$this->page = $this->fetch($url, $parameters);
|
335 |
+
$this->history->recordEntry(
|
336 |
+
$this->page->getUrl(),
|
337 |
+
$this->page->getRequestData());
|
338 |
+
return $this->page->getRaw();
|
339 |
+
}
|
340 |
+
|
341 |
+
/**
|
342 |
+
* Fetches a frame into the existing frameset replacing the
|
343 |
+
* original.
|
344 |
+
* @param array $frames List of names to drill down.
|
345 |
+
* @param string/SimpleUrl $url Target to fetch as string.
|
346 |
+
* @param SimpleFormEncoding $parameters POST parameters.
|
347 |
+
* @return string Raw content of page.
|
348 |
+
* @access private
|
349 |
+
*/
|
350 |
+
protected function loadFrame($frames, $url, $parameters) {
|
351 |
+
$page = $this->fetch($url, $parameters);
|
352 |
+
$this->page->setFrame($frames, $page);
|
353 |
+
return $page->getRaw();
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Removes expired and temporary cookies as if
|
358 |
+
* the browser was closed and re-opened.
|
359 |
+
* @param string/integer $date Time when session restarted.
|
360 |
+
* If omitted then all persistent
|
361 |
+
* cookies are kept.
|
362 |
+
* @access public
|
363 |
+
*/
|
364 |
+
function restart($date = false) {
|
365 |
+
$this->user_agent->restart($date);
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Adds a header to every fetch.
|
370 |
+
* @param string $header Header line to add to every
|
371 |
+
* request until cleared.
|
372 |
+
* @access public
|
373 |
+
*/
|
374 |
+
function addHeader($header) {
|
375 |
+
$this->user_agent->addHeader($header);
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* Ages the cookies by the specified time.
|
380 |
+
* @param integer $interval Amount in seconds.
|
381 |
+
* @access public
|
382 |
+
*/
|
383 |
+
function ageCookies($interval) {
|
384 |
+
$this->user_agent->ageCookies($interval);
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Sets an additional cookie. If a cookie has
|
389 |
+
* the same name and path it is replaced.
|
390 |
+
* @param string $name Cookie key.
|
391 |
+
* @param string $value Value of cookie.
|
392 |
+
* @param string $host Host upon which the cookie is valid.
|
393 |
+
* @param string $path Cookie path if not host wide.
|
394 |
+
* @param string $expiry Expiry date.
|
395 |
+
* @access public
|
396 |
+
*/
|
397 |
+
function setCookie($name, $value, $host = false, $path = '/', $expiry = false) {
|
398 |
+
$this->user_agent->setCookie($name, $value, $host, $path, $expiry);
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Reads the most specific cookie value from the
|
403 |
+
* browser cookies.
|
404 |
+
* @param string $host Host to search.
|
405 |
+
* @param string $path Applicable path.
|
406 |
+
* @param string $name Name of cookie to read.
|
407 |
+
* @return string False if not present, else the
|
408 |
+
* value as a string.
|
409 |
+
* @access public
|
410 |
+
*/
|
411 |
+
function getCookieValue($host, $path, $name) {
|
412 |
+
return $this->user_agent->getCookieValue($host, $path, $name);
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Reads the current cookies for the current URL.
|
417 |
+
* @param string $name Key of cookie to find.
|
418 |
+
* @return string Null if there is no current URL, false
|
419 |
+
* if the cookie is not set.
|
420 |
+
* @access public
|
421 |
+
*/
|
422 |
+
function getCurrentCookieValue($name) {
|
423 |
+
return $this->user_agent->getBaseCookieValue($name, $this->page->getUrl());
|
424 |
+
}
|
425 |
+
|
426 |
+
/**
|
427 |
+
* Sets the maximum number of redirects before
|
428 |
+
* a page will be loaded anyway.
|
429 |
+
* @param integer $max Most hops allowed.
|
430 |
+
* @access public
|
431 |
+
*/
|
432 |
+
function setMaximumRedirects($max) {
|
433 |
+
$this->user_agent->setMaximumRedirects($max);
|
434 |
+
}
|
435 |
+
|
436 |
+
/**
|
437 |
+
* Sets the maximum number of nesting of framed pages
|
438 |
+
* within a framed page to prevent loops.
|
439 |
+
* @param integer $max Highest depth allowed.
|
440 |
+
* @access public
|
441 |
+
*/
|
442 |
+
function setMaximumNestedFrames($max) {
|
443 |
+
$this->maximum_nested_frames = $max;
|
444 |
+
}
|
445 |
+
|
446 |
+
/**
|
447 |
+
* Sets the socket timeout for opening a connection.
|
448 |
+
* @param integer $timeout Maximum time in seconds.
|
449 |
+
* @access public
|
450 |
+
*/
|
451 |
+
function setConnectionTimeout($timeout) {
|
452 |
+
$this->user_agent->setConnectionTimeout($timeout);
|
453 |
+
}
|
454 |
+
|
455 |
+
/**
|
456 |
+
* Sets proxy to use on all requests for when
|
457 |
+
* testing from behind a firewall. Set URL
|
458 |
+
* to false to disable.
|
459 |
+
* @param string $proxy Proxy URL.
|
460 |
+
* @param string $username Proxy username for authentication.
|
461 |
+
* @param string $password Proxy password for authentication.
|
462 |
+
* @access public
|
463 |
+
*/
|
464 |
+
function useProxy($proxy, $username = false, $password = false) {
|
465 |
+
$this->user_agent->useProxy($proxy, $username, $password);
|
466 |
+
}
|
467 |
+
|
468 |
+
/**
|
469 |
+
* Fetches the page content with a HEAD request.
|
470 |
+
* Will affect cookies, but will not change the base URL.
|
471 |
+
* @param string/SimpleUrl $url Target to fetch as string.
|
472 |
+
* @param hash/SimpleHeadEncoding $parameters Additional parameters for
|
473 |
+
* HEAD request.
|
474 |
+
* @return boolean True if successful.
|
475 |
+
* @access public
|
476 |
+
*/
|
477 |
+
function head($url, $parameters = false) {
|
478 |
+
if (! is_object($url)) {
|
479 |
+
$url = new SimpleUrl($url);
|
480 |
+
}
|
481 |
+
if ($this->getUrl()) {
|
482 |
+
$url = $url->makeAbsolute($this->getUrl());
|
483 |
+
}
|
484 |
+
$response = $this->user_agent->fetchResponse($url, new SimpleHeadEncoding($parameters));
|
485 |
+
$this->page = new SimplePage($response);
|
486 |
+
return ! $response->isError();
|
487 |
+
}
|
488 |
+
|
489 |
+
/**
|
490 |
+
* Fetches the page content with a simple GET request.
|
491 |
+
* @param string/SimpleUrl $url Target to fetch.
|
492 |
+
* @param hash/SimpleFormEncoding $parameters Additional parameters for
|
493 |
+
* GET request.
|
494 |
+
* @return string Content of page or false.
|
495 |
+
* @access public
|
496 |
+
*/
|
497 |
+
function get($url, $parameters = false) {
|
498 |
+
if (! is_object($url)) {
|
499 |
+
$url = new SimpleUrl($url);
|
500 |
+
}
|
501 |
+
if ($this->getUrl()) {
|
502 |
+
$url = $url->makeAbsolute($this->getUrl());
|
503 |
+
}
|
504 |
+
return $this->load($url, new SimpleGetEncoding($parameters));
|
505 |
+
}
|
506 |
+
|
507 |
+
/**
|
508 |
+
* Fetches the page content with a POST request.
|
509 |
+
* @param string/SimpleUrl $url Target to fetch as string.
|
510 |
+
* @param hash/SimpleFormEncoding $parameters POST parameters or request body.
|
511 |
+
* @param string $content_type MIME Content-Type of the request body
|
512 |
+
* @return string Content of page.
|
513 |
+
* @access public
|
514 |
+
*/
|
515 |
+
function post($url, $parameters = false, $content_type = false) {
|
516 |
+
if (! is_object($url)) {
|
517 |
+
$url = new SimpleUrl($url);
|
518 |
+
}
|
519 |
+
if ($this->getUrl()) {
|
520 |
+
$url = $url->makeAbsolute($this->getUrl());
|
521 |
+
}
|
522 |
+
return $this->load($url, new SimplePostEncoding($parameters, $content_type));
|
523 |
+
}
|
524 |
+
|
525 |
+
/**
|
526 |
+
* Fetches the page content with a PUT request.
|
527 |
+
* @param string/SimpleUrl $url Target to fetch as string.
|
528 |
+
* @param hash/SimpleFormEncoding $parameters PUT request body.
|
529 |
+
* @param string $content_type MIME Content-Type of the request body
|
530 |
+
* @return string Content of page.
|
531 |
+
* @access public
|
532 |
+
*/
|
533 |
+
function put($url, $parameters = false, $content_type = false) {
|
534 |
+
if (! is_object($url)) {
|
535 |
+
$url = new SimpleUrl($url);
|
536 |
+
}
|
537 |
+
return $this->load($url, new SimplePutEncoding($parameters, $content_type));
|
538 |
+
}
|
539 |
+
|
540 |
+
/**
|
541 |
+
* Sends a DELETE request and fetches the response.
|
542 |
+
* @param string/SimpleUrl $url Target to fetch.
|
543 |
+
* @param hash/SimpleFormEncoding $parameters Additional parameters for
|
544 |
+
* DELETE request.
|
545 |
+
* @return string Content of page or false.
|
546 |
+
* @access public
|
547 |
+
*/
|
548 |
+
function delete($url, $parameters = false) {
|
549 |
+
if (! is_object($url)) {
|
550 |
+
$url = new SimpleUrl($url);
|
551 |
+
}
|
552 |
+
return $this->load($url, new SimpleDeleteEncoding($parameters));
|
553 |
+
}
|
554 |
+
|
555 |
+
/**
|
556 |
+
* Equivalent to hitting the retry button on the
|
557 |
+
* browser. Will attempt to repeat the page fetch. If
|
558 |
+
* there is no history to repeat it will give false.
|
559 |
+
* @return string/boolean Content if fetch succeeded
|
560 |
+
* else false.
|
561 |
+
* @access public
|
562 |
+
*/
|
563 |
+
function retry() {
|
564 |
+
$frames = $this->page->getFrameFocus();
|
565 |
+
if (count($frames) > 0) {
|
566 |
+
$this->loadFrame(
|
567 |
+
$frames,
|
568 |
+
$this->page->getUrl(),
|
569 |
+
$this->page->getRequestData());
|
570 |
+
return $this->page->getRaw();
|
571 |
+
}
|
572 |
+
if ($url = $this->history->getUrl()) {
|
573 |
+
$this->page = $this->fetch($url, $this->history->getParameters());
|
574 |
+
return $this->page->getRaw();
|
575 |
+
}
|
576 |
+
return false;
|
577 |
+
}
|
578 |
+
|
579 |
+
/**
|
580 |
+
* Equivalent to hitting the back button on the
|
581 |
+
* browser. The browser history is unchanged on
|
582 |
+
* failure. The page content is refetched as there
|
583 |
+
* is no concept of content caching in SimpleTest.
|
584 |
+
* @return boolean True if history entry and
|
585 |
+
* fetch succeeded
|
586 |
+
* @access public
|
587 |
+
*/
|
588 |
+
function back() {
|
589 |
+
if (! $this->history->back()) {
|
590 |
+
return false;
|
591 |
+
}
|
592 |
+
$content = $this->retry();
|
593 |
+
if (! $content) {
|
594 |
+
$this->history->forward();
|
595 |
+
}
|
596 |
+
return $content;
|
597 |
+
}
|
598 |
+
|
599 |
+
/**
|
600 |
+
* Equivalent to hitting the forward button on the
|
601 |
+
* browser. The browser history is unchanged on
|
602 |
+
* failure. The page content is refetched as there
|
603 |
+
* is no concept of content caching in SimpleTest.
|
604 |
+
* @return boolean True if history entry and
|
605 |
+
* fetch succeeded
|
606 |
+
* @access public
|
607 |
+
*/
|
608 |
+
function forward() {
|
609 |
+
if (! $this->history->forward()) {
|
610 |
+
return false;
|
611 |
+
}
|
612 |
+
$content = $this->retry();
|
613 |
+
if (! $content) {
|
614 |
+
$this->history->back();
|
615 |
+
}
|
616 |
+
return $content;
|
617 |
+
}
|
618 |
+
|
619 |
+
/**
|
620 |
+
* Retries a request after setting the authentication
|
621 |
+
* for the current realm.
|
622 |
+
* @param string $username Username for realm.
|
623 |
+
* @param string $password Password for realm.
|
624 |
+
* @return boolean True if successful fetch. Note
|
625 |
+
* that authentication may still have
|
626 |
+
* failed.
|
627 |
+
* @access public
|
628 |
+
*/
|
629 |
+
function authenticate($username, $password) {
|
630 |
+
if (! $this->page->getRealm()) {
|
631 |
+
return false;
|
632 |
+
}
|
633 |
+
$url = $this->page->getUrl();
|
634 |
+
if (! $url) {
|
635 |
+
return false;
|
636 |
+
}
|
637 |
+
$this->user_agent->setIdentity(
|
638 |
+
$url->getHost(),
|
639 |
+
$this->page->getRealm(),
|
640 |
+
$username,
|
641 |
+
$password);
|
642 |
+
return $this->retry();
|
643 |
+
}
|
644 |
+
|
645 |
+
/**
|
646 |
+
* Accessor for a breakdown of the frameset.
|
647 |
+
* @return array Hash tree of frames by name
|
648 |
+
* or index if no name.
|
649 |
+
* @access public
|
650 |
+
*/
|
651 |
+
function getFrames() {
|
652 |
+
return $this->page->getFrames();
|
653 |
+
}
|
654 |
+
|
655 |
+
/**
|
656 |
+
* Accessor for current frame focus. Will be
|
657 |
+
* false if no frame has focus.
|
658 |
+
* @return integer/string/boolean Label if any, otherwise
|
659 |
+
* the position in the frameset
|
660 |
+
* or false if none.
|
661 |
+
* @access public
|
662 |
+
*/
|
663 |
+
function getFrameFocus() {
|
664 |
+
return $this->page->getFrameFocus();
|
665 |
+
}
|
666 |
+
|
667 |
+
/**
|
668 |
+
* Sets the focus by index. The integer index starts from 1.
|
669 |
+
* @param integer $choice Chosen frame.
|
670 |
+
* @return boolean True if frame exists.
|
671 |
+
* @access public
|
672 |
+
*/
|
673 |
+
function setFrameFocusByIndex($choice) {
|
674 |
+
return $this->page->setFrameFocusByIndex($choice);
|
675 |
+
}
|
676 |
+
|
677 |
+
/**
|
678 |
+
* Sets the focus by name.
|
679 |
+
* @param string $name Chosen frame.
|
680 |
+
* @return boolean True if frame exists.
|
681 |
+
* @access public
|
682 |
+
*/
|
683 |
+
function setFrameFocus($name) {
|
684 |
+
return $this->page->setFrameFocus($name);
|
685 |
+
}
|
686 |
+
|
687 |
+
/**
|
688 |
+
* Clears the frame focus. All frames will be searched
|
689 |
+
* for content.
|
690 |
+
* @access public
|
691 |
+
*/
|
692 |
+
function clearFrameFocus() {
|
693 |
+
return $this->page->clearFrameFocus();
|
694 |
+
}
|
695 |
+
|
696 |
+
/**
|
697 |
+
* Accessor for last error.
|
698 |
+
* @return string Error from last response.
|
699 |
+
* @access public
|
700 |
+
*/
|
701 |
+
function getTransportError() {
|
702 |
+
return $this->page->getTransportError();
|
703 |
+
}
|
704 |
+
|
705 |
+
/**
|
706 |
+
* Accessor for current MIME type.
|
707 |
+
* @return string MIME type as string; e.g. 'text/html'
|
708 |
+
* @access public
|
709 |
+
*/
|
710 |
+
function getMimeType() {
|
711 |
+
return $this->page->getMimeType();
|
712 |
+
}
|
713 |
+
|
714 |
+
/**
|
715 |
+
* Accessor for last response code.
|
716 |
+
* @return integer Last HTTP response code received.
|
717 |
+
* @access public
|
718 |
+
*/
|
719 |
+
function getResponseCode() {
|
720 |
+
return $this->page->getResponseCode();
|
721 |
+
}
|
722 |
+
|
723 |
+
/**
|
724 |
+
* Accessor for last Authentication type. Only valid
|
725 |
+
* straight after a challenge (401).
|
726 |
+
* @return string Description of challenge type.
|
727 |
+
* @access public
|
728 |
+
*/
|
729 |
+
function getAuthentication() {
|
730 |
+
return $this->page->getAuthentication();
|
731 |
+
}
|
732 |
+
|
733 |
+
/**
|
734 |
+
* Accessor for last Authentication realm. Only valid
|
735 |
+
* straight after a challenge (401).
|
736 |
+
* @return string Name of security realm.
|
737 |
+
* @access public
|
738 |
+
*/
|
739 |
+
function getRealm() {
|
740 |
+
return $this->page->getRealm();
|
741 |
+
}
|
742 |
+
|
743 |
+
/**
|
744 |
+
* Accessor for current URL of page or frame if
|
745 |
+
* focused.
|
746 |
+
* @return string Location of current page or frame as
|
747 |
+
* a string.
|
748 |
+
*/
|
749 |
+
function getUrl() {
|
750 |
+
$url = $this->page->getUrl();
|
751 |
+
return $url ? $url->asString() : false;
|
752 |
+
}
|
753 |
+
|
754 |
+
/**
|
755 |
+
* Accessor for base URL of page if set via BASE tag
|
756 |
+
* @return string base URL
|
757 |
+
*/
|
758 |
+
function getBaseUrl() {
|
759 |
+
$url = $this->page->getBaseUrl();
|
760 |
+
return $url ? $url->asString() : false;
|
761 |
+
}
|
762 |
+
|
763 |
+
/**
|
764 |
+
* Accessor for raw bytes sent down the wire.
|
765 |
+
* @return string Original text sent.
|
766 |
+
* @access public
|
767 |
+
*/
|
768 |
+
function getRequest() {
|
769 |
+
return $this->page->getRequest();
|
770 |
+
}
|
771 |
+
|
772 |
+
/**
|
773 |
+
* Accessor for raw header information.
|
774 |
+
* @return string Header block.
|
775 |
+
* @access public
|
776 |
+
*/
|
777 |
+
function getHeaders() {
|
778 |
+
return $this->page->getHeaders();
|
779 |
+
}
|
780 |
+
|
781 |
+
/**
|
782 |
+
* Accessor for raw page information.
|
783 |
+
* @return string Original text content of web page.
|
784 |
+
* @access public
|
785 |
+
*/
|
786 |
+
function getContent() {
|
787 |
+
return $this->page->getRaw();
|
788 |
+
}
|
789 |
+
|
790 |
+
/**
|
791 |
+
* Accessor for plain text version of the page.
|
792 |
+
* @return string Normalised text representation.
|
793 |
+
* @access public
|
794 |
+
*/
|
795 |
+
function getContentAsText() {
|
796 |
+
return $this->page->getText();
|
797 |
+
}
|
798 |
+
|
799 |
+
/**
|
800 |
+
* Accessor for parsed title.
|
801 |
+
* @return string Title or false if no title is present.
|
802 |
+
* @access public
|
803 |
+
*/
|
804 |
+
function getTitle() {
|
805 |
+
return $this->page->getTitle();
|
806 |
+
}
|
807 |
+
|
808 |
+
/**
|
809 |
+
* Accessor for a list of all links in current page.
|
810 |
+
* @return array List of urls with scheme of
|
811 |
+
* http or https and hostname.
|
812 |
+
* @access public
|
813 |
+
*/
|
814 |
+
function getUrls() {
|
815 |
+
return $this->page->getUrls();
|
816 |
+
}
|
817 |
+
|
818 |
+
/**
|
819 |
+
* Sets all form fields with that name.
|
820 |
+
* @param string $label Name or label of field in forms.
|
821 |
+
* @param string $value New value of field.
|
822 |
+
* @return boolean True if field exists, otherwise false.
|
823 |
+
* @access public
|
824 |
+
*/
|
825 |
+
function setField($label, $value, $position=false) {
|
826 |
+
return $this->page->setField(new SimpleByLabelOrName($label), $value, $position);
|
827 |
+
}
|
828 |
+
|
829 |
+
/**
|
830 |
+
* Sets all form fields with that name. Will use label if
|
831 |
+
* one is available (not yet implemented).
|
832 |
+
* @param string $name Name of field in forms.
|
833 |
+
* @param string $value New value of field.
|
834 |
+
* @return boolean True if field exists, otherwise false.
|
835 |
+
* @access public
|
836 |
+
*/
|
837 |
+
function setFieldByName($name, $value, $position=false) {
|
838 |
+
return $this->page->setField(new SimpleByName($name), $value, $position);
|
839 |
+
}
|
840 |
+
|
841 |
+
/**
|
842 |
+
* Sets all form fields with that id attribute.
|
843 |
+
* @param string/integer $id Id of field in forms.
|
844 |
+
* @param string $value New value of field.
|
845 |
+
* @return boolean True if field exists, otherwise false.
|
846 |
+
* @access public
|
847 |
+
*/
|
848 |
+
function setFieldById($id, $value) {
|
849 |
+
return $this->page->setField(new SimpleById($id), $value);
|
850 |
+
}
|
851 |
+
|
852 |
+
/**
|
853 |
+
* Accessor for a form element value within the page.
|
854 |
+
* Finds the first match.
|
855 |
+
* @param string $label Field label.
|
856 |
+
* @return string/boolean A value if the field is
|
857 |
+
* present, false if unchecked
|
858 |
+
* and null if missing.
|
859 |
+
* @access public
|
860 |
+
*/
|
861 |
+
function getField($label) {
|
862 |
+
return $this->page->getField(new SimpleByLabelOrName($label));
|
863 |
+
}
|
864 |
+
|
865 |
+
/**
|
866 |
+
* Accessor for a form element value within the page.
|
867 |
+
* Finds the first match.
|
868 |
+
* @param string $name Field name.
|
869 |
+
* @return string/boolean A string if the field is
|
870 |
+
* present, false if unchecked
|
871 |
+
* and null if missing.
|
872 |
+
* @access public
|
873 |
+
*/
|
874 |
+
function getFieldByName($name) {
|
875 |
+
return $this->page->getField(new SimpleByName($name));
|
876 |
+
}
|
877 |
+
|
878 |
+
/**
|
879 |
+
* Accessor for a form element value within the page.
|
880 |
+
* @param string/integer $id Id of field in forms.
|
881 |
+
* @return string/boolean A string if the field is
|
882 |
+
* present, false if unchecked
|
883 |
+
* and null if missing.
|
884 |
+
* @access public
|
885 |
+
*/
|
886 |
+
function getFieldById($id) {
|
887 |
+
return $this->page->getField(new SimpleById($id));
|
888 |
+
}
|
889 |
+
|
890 |
+
/**
|
891 |
+
* Clicks the submit button by label. The owning
|
892 |
+
* form will be submitted by this.
|
893 |
+
* @param string $label Button label. An unlabeled
|
894 |
+
* button can be triggered by 'Submit'.
|
895 |
+
* @param hash $additional Additional form data.
|
896 |
+
* @return string/boolean Page on success.
|
897 |
+
* @access public
|
898 |
+
*/
|
899 |
+
function clickSubmit($label = 'Submit', $additional = false) {
|
900 |
+
if (! ($form = $this->page->getFormBySubmit(new SimpleByLabel($label)))) {
|
901 |
+
return false;
|
902 |
+
}
|
903 |
+
$success = $this->load(
|
904 |
+
$form->getAction(),
|
905 |
+
$form->submitButton(new SimpleByLabel($label), $additional));
|
906 |
+
return ($success ? $this->getContent() : $success);
|
907 |
+
}
|
908 |
+
|
909 |
+
/**
|
910 |
+
* Clicks the submit button by name attribute. The owning
|
911 |
+
* form will be submitted by this.
|
912 |
+
* @param string $name Button name.
|
913 |
+
* @param hash $additional Additional form data.
|
914 |
+
* @return string/boolean Page on success.
|
915 |
+
* @access public
|
916 |
+
*/
|
917 |
+
function clickSubmitByName($name, $additional = false) {
|
918 |
+
if (! ($form = $this->page->getFormBySubmit(new SimpleByName($name)))) {
|
919 |
+
return false;
|
920 |
+
}
|
921 |
+
$success = $this->load(
|
922 |
+
$form->getAction(),
|
923 |
+
$form->submitButton(new SimpleByName($name), $additional));
|
924 |
+
return ($success ? $this->getContent() : $success);
|
925 |
+
}
|
926 |
+
|
927 |
+
/**
|
928 |
+
* Clicks the submit button by ID attribute of the button
|
929 |
+
* itself. The owning form will be submitted by this.
|
930 |
+
* @param string $id Button ID.
|
931 |
+
* @param hash $additional Additional form data.
|
932 |
+
* @return string/boolean Page on success.
|
933 |
+
* @access public
|
934 |
+
*/
|
935 |
+
function clickSubmitById($id, $additional = false) {
|
936 |
+
if (! ($form = $this->page->getFormBySubmit(new SimpleById($id)))) {
|
937 |
+
return false;
|
938 |
+
}
|
939 |
+
$success = $this->load(
|
940 |
+
$form->getAction(),
|
941 |
+
$form->submitButton(new SimpleById($id), $additional));
|
942 |
+
return ($success ? $this->getContent() : $success);
|
943 |
+
}
|
944 |
+
|
945 |
+
/**
|
946 |
+
* Tests to see if a submit button exists with this
|
947 |
+
* label.
|
948 |
+
* @param string $label Button label.
|
949 |
+
* @return boolean True if present.
|
950 |
+
* @access public
|
951 |
+
*/
|
952 |
+
function isSubmit($label) {
|
953 |
+
return (boolean)$this->page->getFormBySubmit(new SimpleByLabel($label));
|
954 |
+
}
|
955 |
+
|
956 |
+
/**
|
957 |
+
* Clicks the submit image by some kind of label. Usually
|
958 |
+
* the alt tag or the nearest equivalent. The owning
|
959 |
+
* form will be submitted by this. Clicking outside of
|
960 |
+
* the boundary of the coordinates will result in
|
961 |
+
* a failure.
|
962 |
+
* @param string $label ID attribute of button.
|
963 |
+
* @param integer $x X-coordinate of imaginary click.
|
964 |
+
* @param integer $y Y-coordinate of imaginary click.
|
965 |
+
* @param hash $additional Additional form data.
|
966 |
+
* @return string/boolean Page on success.
|
967 |
+
* @access public
|
968 |
+
*/
|
969 |
+
function clickImage($label, $x = 1, $y = 1, $additional = false) {
|
970 |
+
if (! ($form = $this->page->getFormByImage(new SimpleByLabel($label)))) {
|
971 |
+
return false;
|
972 |
+
}
|
973 |
+
$success = $this->load(
|
974 |
+
$form->getAction(),
|
975 |
+
$form->submitImage(new SimpleByLabel($label), $x, $y, $additional));
|
976 |
+
return ($success ? $this->getContent() : $success);
|
977 |
+
}
|
978 |
+
|
979 |
+
/**
|
980 |
+
* Clicks the submit image by the name. Usually
|
981 |
+
* the alt tag or the nearest equivalent. The owning
|
982 |
+
* form will be submitted by this. Clicking outside of
|
983 |
+
* the boundary of the coordinates will result in
|
984 |
+
* a failure.
|
985 |
+
* @param string $name Name attribute of button.
|
986 |
+
* @param integer $x X-coordinate of imaginary click.
|
987 |
+
* @param integer $y Y-coordinate of imaginary click.
|
988 |
+
* @param hash $additional Additional form data.
|
989 |
+
* @return string/boolean Page on success.
|
990 |
+
* @access public
|
991 |
+
*/
|
992 |
+
function clickImageByName($name, $x = 1, $y = 1, $additional = false) {
|
993 |
+
if (! ($form = $this->page->getFormByImage(new SimpleByName($name)))) {
|
994 |
+
return false;
|
995 |
+
}
|
996 |
+
$success = $this->load(
|
997 |
+
$form->getAction(),
|
998 |
+
$form->submitImage(new SimpleByName($name), $x, $y, $additional));
|
999 |
+
return ($success ? $this->getContent() : $success);
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
/**
|
1003 |
+
* Clicks the submit image by ID attribute. The owning
|
1004 |
+
* form will be submitted by this. Clicking outside of
|
1005 |
+
* the boundary of the coordinates will result in
|
1006 |
+
* a failure.
|
1007 |
+
* @param integer/string $id ID attribute of button.
|
1008 |
+
* @param integer $x X-coordinate of imaginary click.
|
1009 |
+
* @param integer $y Y-coordinate of imaginary click.
|
1010 |
+
* @param hash $additional Additional form data.
|
1011 |
+
* @return string/boolean Page on success.
|
1012 |
+
* @access public
|
1013 |
+
*/
|
1014 |
+
function clickImageById($id, $x = 1, $y = 1, $additional = false) {
|
1015 |
+
if (! ($form = $this->page->getFormByImage(new SimpleById($id)))) {
|
1016 |
+
return false;
|
1017 |
+
}
|
1018 |
+
$success = $this->load(
|
1019 |
+
$form->getAction(),
|
1020 |
+
$form->submitImage(new SimpleById($id), $x, $y, $additional));
|
1021 |
+
return ($success ? $this->getContent() : $success);
|
1022 |
+
}
|
1023 |
+
|
1024 |
+
/**
|
1025 |
+
* Tests to see if an image exists with this
|
1026 |
+
* title or alt text.
|
1027 |
+
* @param string $label Image text.
|
1028 |
+
* @return boolean True if present.
|
1029 |
+
* @access public
|
1030 |
+
*/
|
1031 |
+
function isImage($label) {
|
1032 |
+
return (boolean)$this->page->getFormByImage(new SimpleByLabel($label));
|
1033 |
+
}
|
1034 |
+
|
1035 |
+
/**
|
1036 |
+
* Submits a form by the ID.
|
1037 |
+
* @param string $id The form ID. No submit button value
|
1038 |
+
* will be sent.
|
1039 |
+
* @return string/boolean Page on success.
|
1040 |
+
* @access public
|
1041 |
+
*/
|
1042 |
+
function submitFormById($id, $additional = false) {
|
1043 |
+
if (! ($form = $this->page->getFormById($id))) {
|
1044 |
+
return false;
|
1045 |
+
}
|
1046 |
+
$success = $this->load(
|
1047 |
+
$form->getAction(),
|
1048 |
+
$form->submit($additional));
|
1049 |
+
return ($success ? $this->getContent() : $success);
|
1050 |
+
}
|
1051 |
+
|
1052 |
+
/**
|
1053 |
+
* Finds a URL by label. Will find the first link
|
1054 |
+
* found with this link text by default, or a later
|
1055 |
+
* one if an index is given. The match ignores case and
|
1056 |
+
* white space issues.
|
1057 |
+
* @param string $label Text between the anchor tags.
|
1058 |
+
* @param integer $index Link position counting from zero.
|
1059 |
+
* @return string/boolean URL on success.
|
1060 |
+
* @access public
|
1061 |
+
*/
|
1062 |
+
function getLink($label, $index = 0) {
|
1063 |
+
$urls = $this->page->getUrlsByLabel($label);
|
1064 |
+
if (count($urls) == 0) {
|
1065 |
+
return false;
|
1066 |
+
}
|
1067 |
+
if (count($urls) < $index + 1) {
|
1068 |
+
return false;
|
1069 |
+
}
|
1070 |
+
return $urls[$index];
|
1071 |
+
}
|
1072 |
+
|
1073 |
+
/**
|
1074 |
+
* Follows a link by label. Will click the first link
|
1075 |
+
* found with this link text by default, or a later
|
1076 |
+
* one if an index is given. The match ignores case and
|
1077 |
+
* white space issues.
|
1078 |
+
* @param string $label Text between the anchor tags.
|
1079 |
+
* @param integer $index Link position counting from zero.
|
1080 |
+
* @return string/boolean Page on success.
|
1081 |
+
* @access public
|
1082 |
+
*/
|
1083 |
+
function clickLink($label, $index = 0) {
|
1084 |
+
$url = $this->getLink($label, $index);
|
1085 |
+
if ($url === false) {
|
1086 |
+
return false;
|
1087 |
+
}
|
1088 |
+
$this->load($url, new SimpleGetEncoding());
|
1089 |
+
return $this->getContent();
|
1090 |
+
}
|
1091 |
+
|
1092 |
+
/**
|
1093 |
+
* Finds a link by id attribute.
|
1094 |
+
* @param string $id ID attribute value.
|
1095 |
+
* @return string/boolean URL on success.
|
1096 |
+
* @access public
|
1097 |
+
*/
|
1098 |
+
function getLinkById($id) {
|
1099 |
+
return $this->page->getUrlById($id);
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
/**
|
1103 |
+
* Follows a link by id attribute.
|
1104 |
+
* @param string $id ID attribute value.
|
1105 |
+
* @return string/boolean Page on success.
|
1106 |
+
* @access public
|
1107 |
+
*/
|
1108 |
+
function clickLinkById($id) {
|
1109 |
+
if (! ($url = $this->getLinkById($id))) {
|
1110 |
+
return false;
|
1111 |
+
}
|
1112 |
+
$this->load($url, new SimpleGetEncoding());
|
1113 |
+
return $this->getContent();
|
1114 |
+
}
|
1115 |
+
|
1116 |
+
/**
|
1117 |
+
* Clicks a visible text item. Will first try buttons,
|
1118 |
+
* then links and then images.
|
1119 |
+
* @param string $label Visible text or alt text.
|
1120 |
+
* @return string/boolean Raw page or false.
|
1121 |
+
* @access public
|
1122 |
+
*/
|
1123 |
+
function click($label) {
|
1124 |
+
$raw = $this->clickSubmit($label);
|
1125 |
+
if (! $raw) {
|
1126 |
+
$raw = $this->clickLink($label);
|
1127 |
+
}
|
1128 |
+
if (! $raw) {
|
1129 |
+
$raw = $this->clickImage($label);
|
1130 |
+
}
|
1131 |
+
return $raw;
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
/**
|
1135 |
+
* Tests to see if a click target exists.
|
1136 |
+
* @param string $label Visible text or alt text.
|
1137 |
+
* @return boolean True if target present.
|
1138 |
+
* @access public
|
1139 |
+
*/
|
1140 |
+
function isClickable($label) {
|
1141 |
+
return $this->isSubmit($label) || ($this->getLink($label) !== false) || $this->isImage($label);
|
1142 |
+
}
|
1143 |
+
}
|
1144 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/collector.php
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This file contains the following classes: {@link SimpleCollector},
|
4 |
+
* {@link SimplePatternCollector}.
|
5 |
+
*
|
6 |
+
* @author Travis Swicegood <development@domain51.com>
|
7 |
+
* @package SimpleTest
|
8 |
+
* @subpackage UnitTester
|
9 |
+
* @version $Id: collector.php 2011 2011-04-29 08:22:48Z pp11 $
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* The basic collector for {@link GroupTest}
|
14 |
+
*
|
15 |
+
* @see collect(), GroupTest::collect()
|
16 |
+
* @package SimpleTest
|
17 |
+
* @subpackage UnitTester
|
18 |
+
*/
|
19 |
+
class SimpleCollector {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Strips off any kind of slash at the end so as to normalise the path.
|
23 |
+
* @param string $path Path to normalise.
|
24 |
+
* @return string Path without trailing slash.
|
25 |
+
*/
|
26 |
+
protected function removeTrailingSlash($path) {
|
27 |
+
if (substr($path, -1) == DIRECTORY_SEPARATOR) {
|
28 |
+
return substr($path, 0, -1);
|
29 |
+
} elseif (substr($path, -1) == '/') {
|
30 |
+
return substr($path, 0, -1);
|
31 |
+
} else {
|
32 |
+
return $path;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Scans the directory and adds what it can.
|
38 |
+
* @param object $test Group test with {@link GroupTest::addTestFile()} method.
|
39 |
+
* @param string $path Directory to scan.
|
40 |
+
* @see _attemptToAdd()
|
41 |
+
*/
|
42 |
+
function collect(&$test, $path) {
|
43 |
+
$path = $this->removeTrailingSlash($path);
|
44 |
+
if ($handle = opendir($path)) {
|
45 |
+
while (($entry = readdir($handle)) !== false) {
|
46 |
+
if ($this->isHidden($entry)) {
|
47 |
+
continue;
|
48 |
+
}
|
49 |
+
$this->handle($test, $path . DIRECTORY_SEPARATOR . $entry);
|
50 |
+
}
|
51 |
+
closedir($handle);
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* This method determines what should be done with a given file and adds
|
57 |
+
* it via {@link GroupTest::addTestFile()} if necessary.
|
58 |
+
*
|
59 |
+
* This method should be overriden to provide custom matching criteria,
|
60 |
+
* such as pattern matching, recursive matching, etc. For an example, see
|
61 |
+
* {@link SimplePatternCollector::_handle()}.
|
62 |
+
*
|
63 |
+
* @param object $test Group test with {@link GroupTest::addTestFile()} method.
|
64 |
+
* @param string $filename A filename as generated by {@link collect()}
|
65 |
+
* @see collect()
|
66 |
+
* @access protected
|
67 |
+
*/
|
68 |
+
protected function handle(&$test, $file) {
|
69 |
+
if (is_dir($file)) {
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
$test->addFile($file);
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Tests for hidden files so as to skip them. Currently
|
77 |
+
* only tests for Unix hidden files.
|
78 |
+
* @param string $filename Plain filename.
|
79 |
+
* @return boolean True if hidden file.
|
80 |
+
* @access private
|
81 |
+
*/
|
82 |
+
protected function isHidden($filename) {
|
83 |
+
return strncmp($filename, '.', 1) == 0;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* An extension to {@link SimpleCollector} that only adds files matching a
|
89 |
+
* given pattern.
|
90 |
+
*
|
91 |
+
* @package SimpleTest
|
92 |
+
* @subpackage UnitTester
|
93 |
+
* @see SimpleCollector
|
94 |
+
*/
|
95 |
+
class SimplePatternCollector extends SimpleCollector {
|
96 |
+
private $pattern;
|
97 |
+
|
98 |
+
/**
|
99 |
+
*
|
100 |
+
* @param string $pattern Perl compatible regex to test name against
|
101 |
+
* See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE}
|
102 |
+
* for full documentation of valid pattern.s
|
103 |
+
*/
|
104 |
+
function __construct($pattern = '/php$/i') {
|
105 |
+
$this->pattern = $pattern;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Attempts to add files that match a given pattern.
|
110 |
+
*
|
111 |
+
* @see SimpleCollector::_handle()
|
112 |
+
* @param object $test Group test with {@link GroupTest::addTestFile()} method.
|
113 |
+
* @param string $path Directory to scan.
|
114 |
+
* @access protected
|
115 |
+
*/
|
116 |
+
protected function handle(&$test, $filename) {
|
117 |
+
if (preg_match($this->pattern, $filename)) {
|
118 |
+
parent::handle($test, $filename);
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/compatibility.php
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* base include file for SimpleTest
|
4 |
+
* @package SimpleTest
|
5 |
+
* @version $Id: compatibility.php 1900 2009-07-29 11:44:37Z lastcraft $
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Static methods for compatibility between different
|
10 |
+
* PHP versions.
|
11 |
+
* @package SimpleTest
|
12 |
+
*/
|
13 |
+
class SimpleTestCompatibility {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Creates a copy whether in PHP5 or PHP4.
|
17 |
+
* @param object $object Thing to copy.
|
18 |
+
* @return object A copy.
|
19 |
+
* @access public
|
20 |
+
*/
|
21 |
+
static function copy($object) {
|
22 |
+
if (version_compare(phpversion(), '5') >= 0) {
|
23 |
+
eval('$copy = clone $object;');
|
24 |
+
return $copy;
|
25 |
+
}
|
26 |
+
return $object;
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Identity test. Drops back to equality + types for PHP5
|
31 |
+
* objects as the === operator counts as the
|
32 |
+
* stronger reference constraint.
|
33 |
+
* @param mixed $first Test subject.
|
34 |
+
* @param mixed $second Comparison object.
|
35 |
+
* @return boolean True if identical.
|
36 |
+
* @access public
|
37 |
+
*/
|
38 |
+
static function isIdentical($first, $second) {
|
39 |
+
if (version_compare(phpversion(), '5') >= 0) {
|
40 |
+
return SimpleTestCompatibility::isIdenticalType($first, $second);
|
41 |
+
}
|
42 |
+
if ($first != $second) {
|
43 |
+
return false;
|
44 |
+
}
|
45 |
+
return ($first === $second);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Recursive type test.
|
50 |
+
* @param mixed $first Test subject.
|
51 |
+
* @param mixed $second Comparison object.
|
52 |
+
* @return boolean True if same type.
|
53 |
+
* @access private
|
54 |
+
*/
|
55 |
+
protected static function isIdenticalType($first, $second) {
|
56 |
+
if (gettype($first) != gettype($second)) {
|
57 |
+
return false;
|
58 |
+
}
|
59 |
+
if (is_object($first) && is_object($second)) {
|
60 |
+
if (get_class($first) != get_class($second)) {
|
61 |
+
return false;
|
62 |
+
}
|
63 |
+
return SimpleTestCompatibility::isArrayOfIdenticalTypes(
|
64 |
+
(array) $first,
|
65 |
+
(array) $second);
|
66 |
+
}
|
67 |
+
if (is_array($first) && is_array($second)) {
|
68 |
+
return SimpleTestCompatibility::isArrayOfIdenticalTypes($first, $second);
|
69 |
+
}
|
70 |
+
if ($first !== $second) {
|
71 |
+
return false;
|
72 |
+
}
|
73 |
+
return true;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Recursive type test for each element of an array.
|
78 |
+
* @param mixed $first Test subject.
|
79 |
+
* @param mixed $second Comparison object.
|
80 |
+
* @return boolean True if identical.
|
81 |
+
* @access private
|
82 |
+
*/
|
83 |
+
protected static function isArrayOfIdenticalTypes($first, $second) {
|
84 |
+
if (array_keys($first) != array_keys($second)) {
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
foreach (array_keys($first) as $key) {
|
88 |
+
$is_identical = SimpleTestCompatibility::isIdenticalType(
|
89 |
+
$first[$key],
|
90 |
+
$second[$key]);
|
91 |
+
if (! $is_identical) {
|
92 |
+
return false;
|
93 |
+
}
|
94 |
+
}
|
95 |
+
return true;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Test for two variables being aliases.
|
100 |
+
* @param mixed $first Test subject.
|
101 |
+
* @param mixed $second Comparison object.
|
102 |
+
* @return boolean True if same.
|
103 |
+
* @access public
|
104 |
+
*/
|
105 |
+
static function isReference(&$first, &$second) {
|
106 |
+
if (version_compare(phpversion(), '5', '>=') && is_object($first)) {
|
107 |
+
return ($first === $second);
|
108 |
+
}
|
109 |
+
if (is_object($first) && is_object($second)) {
|
110 |
+
$id = uniqid("test");
|
111 |
+
$first->$id = true;
|
112 |
+
$is_ref = isset($second->$id);
|
113 |
+
unset($first->$id);
|
114 |
+
return $is_ref;
|
115 |
+
}
|
116 |
+
$temp = $first;
|
117 |
+
$first = uniqid("test");
|
118 |
+
$is_ref = ($first === $second);
|
119 |
+
$first = $temp;
|
120 |
+
return $is_ref;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Test to see if an object is a member of a
|
125 |
+
* class hiearchy.
|
126 |
+
* @param object $object Object to test.
|
127 |
+
* @param string $class Root name of hiearchy.
|
128 |
+
* @return boolean True if class in hiearchy.
|
129 |
+
* @access public
|
130 |
+
*/
|
131 |
+
static function isA($object, $class) {
|
132 |
+
if (version_compare(phpversion(), '5') >= 0) {
|
133 |
+
if (! class_exists($class, false)) {
|
134 |
+
if (function_exists('interface_exists')) {
|
135 |
+
if (! interface_exists($class, false)) {
|
136 |
+
return false;
|
137 |
+
}
|
138 |
+
}
|
139 |
+
}
|
140 |
+
eval("\$is_a = \$object instanceof $class;");
|
141 |
+
return $is_a;
|
142 |
+
}
|
143 |
+
if (function_exists('is_a')) {
|
144 |
+
return is_a($object, $class);
|
145 |
+
}
|
146 |
+
return ((strtolower($class) == get_class($object))
|
147 |
+
or (is_subclass_of($object, $class)));
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Sets a socket timeout for each chunk.
|
152 |
+
* @param resource $handle Socket handle.
|
153 |
+
* @param integer $timeout Limit in seconds.
|
154 |
+
* @access public
|
155 |
+
*/
|
156 |
+
static function setTimeout($handle, $timeout) {
|
157 |
+
if (function_exists('stream_set_timeout')) {
|
158 |
+
stream_set_timeout($handle, $timeout, 0);
|
159 |
+
} elseif (function_exists('socket_set_timeout')) {
|
160 |
+
socket_set_timeout($handle, $timeout, 0);
|
161 |
+
} elseif (function_exists('set_socket_timeout')) {
|
162 |
+
set_socket_timeout($handle, $timeout, 0);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/cookies.php
ADDED
@@ -0,0 +1,380 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Base include file for SimpleTest
|
4 |
+
* @package SimpleTest
|
5 |
+
* @subpackage WebTester
|
6 |
+
* @version $Id: cookies.php 2011 2011-04-29 08:22:48Z pp11 $
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**#@+
|
10 |
+
* include other SimpleTest class files
|
11 |
+
*/
|
12 |
+
require_once(dirname(__FILE__) . '/url.php');
|
13 |
+
/**#@-*/
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Cookie data holder. Cookie rules are full of pretty
|
17 |
+
* arbitary stuff. I have used...
|
18 |
+
* http://wp.netscape.com/newsref/std/cookie_spec.html
|
19 |
+
* http://www.cookiecentral.com/faq/
|
20 |
+
* @package SimpleTest
|
21 |
+
* @subpackage WebTester
|
22 |
+
*/
|
23 |
+
class SimpleCookie {
|
24 |
+
private $host;
|
25 |
+
private $name;
|
26 |
+
private $value;
|
27 |
+
private $path;
|
28 |
+
private $expiry;
|
29 |
+
private $is_secure;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Constructor. Sets the stored values.
|
33 |
+
* @param string $name Cookie key.
|
34 |
+
* @param string $value Value of cookie.
|
35 |
+
* @param string $path Cookie path if not host wide.
|
36 |
+
* @param string $expiry Expiry date as string.
|
37 |
+
* @param boolean $is_secure Currently ignored.
|
38 |
+
*/
|
39 |
+
function __construct($name, $value = false, $path = false, $expiry = false, $is_secure = false) {
|
40 |
+
$this->host = false;
|
41 |
+
$this->name = $name;
|
42 |
+
$this->value = $value;
|
43 |
+
$this->path = ($path ? $this->fixPath($path) : "/");
|
44 |
+
$this->expiry = false;
|
45 |
+
if (is_string($expiry)) {
|
46 |
+
$this->expiry = strtotime($expiry);
|
47 |
+
} elseif (is_integer($expiry)) {
|
48 |
+
$this->expiry = $expiry;
|
49 |
+
}
|
50 |
+
$this->is_secure = $is_secure;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Sets the host. The cookie rules determine
|
55 |
+
* that the first two parts are taken for
|
56 |
+
* certain TLDs and three for others. If the
|
57 |
+
* new host does not match these rules then the
|
58 |
+
* call will fail.
|
59 |
+
* @param string $host New hostname.
|
60 |
+
* @return boolean True if hostname is valid.
|
61 |
+
* @access public
|
62 |
+
*/
|
63 |
+
function setHost($host) {
|
64 |
+
if ($host = $this->truncateHost($host)) {
|
65 |
+
$this->host = $host;
|
66 |
+
return true;
|
67 |
+
}
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Accessor for the truncated host to which this
|
73 |
+
* cookie applies.
|
74 |
+
* @return string Truncated hostname.
|
75 |
+
* @access public
|
76 |
+
*/
|
77 |
+
function getHost() {
|
78 |
+
return $this->host;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Test for a cookie being valid for a host name.
|
83 |
+
* @param string $host Host to test against.
|
84 |
+
* @return boolean True if the cookie would be valid
|
85 |
+
* here.
|
86 |
+
*/
|
87 |
+
function isValidHost($host) {
|
88 |
+
return ($this->truncateHost($host) === $this->getHost());
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Extracts just the domain part that determines a
|
93 |
+
* cookie's host validity.
|
94 |
+
* @param string $host Host name to truncate.
|
95 |
+
* @return string Domain or false on a bad host.
|
96 |
+
* @access private
|
97 |
+
*/
|
98 |
+
protected function truncateHost($host) {
|
99 |
+
$tlds = SimpleUrl::getAllTopLevelDomains();
|
100 |
+
if (preg_match('/[a-z\-]+\.(' . $tlds . ')$/i', $host, $matches)) {
|
101 |
+
return $matches[0];
|
102 |
+
} elseif (preg_match('/[a-z\-]+\.[a-z\-]+\.[a-z\-]+$/i', $host, $matches)) {
|
103 |
+
return $matches[0];
|
104 |
+
}
|
105 |
+
return false;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Accessor for name.
|
110 |
+
* @return string Cookie key.
|
111 |
+
* @access public
|
112 |
+
*/
|
113 |
+
function getName() {
|
114 |
+
return $this->name;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Accessor for value. A deleted cookie will
|
119 |
+
* have an empty string for this.
|
120 |
+
* @return string Cookie value.
|
121 |
+
* @access public
|
122 |
+
*/
|
123 |
+
function getValue() {
|
124 |
+
return $this->value;
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Accessor for path.
|
129 |
+
* @return string Valid cookie path.
|
130 |
+
* @access public
|
131 |
+
*/
|
132 |
+
function getPath() {
|
133 |
+
return $this->path;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Tests a path to see if the cookie applies
|
138 |
+
* there. The test path must be longer or
|
139 |
+
* equal to the cookie path.
|
140 |
+
* @param string $path Path to test against.
|
141 |
+
* @return boolean True if cookie valid here.
|
142 |
+
* @access public
|
143 |
+
*/
|
144 |
+
function isValidPath($path) {
|
145 |
+
return (strncmp(
|
146 |
+
$this->fixPath($path),
|
147 |
+
$this->getPath(),
|
148 |
+
strlen($this->getPath())) == 0);
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Accessor for expiry.
|
153 |
+
* @return string Expiry string.
|
154 |
+
* @access public
|
155 |
+
*/
|
156 |
+
function getExpiry() {
|
157 |
+
if (! $this->expiry) {
|
158 |
+
return false;
|
159 |
+
}
|
160 |
+
return gmdate("D, d M Y H:i:s", $this->expiry) . " GMT";
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Test to see if cookie is expired against
|
165 |
+
* the cookie format time or timestamp.
|
166 |
+
* Will give true for a session cookie.
|
167 |
+
* @param integer/string $now Time to test against. Result
|
168 |
+
* will be false if this time
|
169 |
+
* is later than the cookie expiry.
|
170 |
+
* Can be either a timestamp integer
|
171 |
+
* or a cookie format date.
|
172 |
+
* @access public
|
173 |
+
*/
|
174 |
+
function isExpired($now) {
|
175 |
+
if (! $this->expiry) {
|
176 |
+
return true;
|
177 |
+
}
|
178 |
+
if (is_string($now)) {
|
179 |
+
$now = strtotime($now);
|
180 |
+
}
|
181 |
+
return ($this->expiry < $now);
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Ages the cookie by the specified number of
|
186 |
+
* seconds.
|
187 |
+
* @param integer $interval In seconds.
|
188 |
+
* @public
|
189 |
+
*/
|
190 |
+
function agePrematurely($interval) {
|
191 |
+
if ($this->expiry) {
|
192 |
+
$this->expiry -= $interval;
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Accessor for the secure flag.
|
198 |
+
* @return boolean True if cookie needs SSL.
|
199 |
+
* @access public
|
200 |
+
*/
|
201 |
+
function isSecure() {
|
202 |
+
return $this->is_secure;
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Adds a trailing and leading slash to the path
|
207 |
+
* if missing.
|
208 |
+
* @param string $path Path to fix.
|
209 |
+
* @access private
|
210 |
+
*/
|
211 |
+
protected function fixPath($path) {
|
212 |
+
if (substr($path, 0, 1) != '/') {
|
213 |
+
$path = '/' . $path;
|
214 |
+
}
|
215 |
+
if (substr($path, -1, 1) != '/') {
|
216 |
+
$path .= '/';
|
217 |
+
}
|
218 |
+
return $path;
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Repository for cookies. This stuff is a
|
224 |
+
* tiny bit browser dependent.
|
225 |
+
* @package SimpleTest
|
226 |
+
* @subpackage WebTester
|
227 |
+
*/
|
228 |
+
class SimpleCookieJar {
|
229 |
+
private $cookies;
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Constructor. Jar starts empty.
|
233 |
+
* @access public
|
234 |
+
*/
|
235 |
+
function __construct() {
|
236 |
+
$this->cookies = array();
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Removes expired and temporary cookies as if
|
241 |
+
* the browser was closed and re-opened.
|
242 |
+
* @param string/integer $now Time to test expiry against.
|
243 |
+
* @access public
|
244 |
+
*/
|
245 |
+
function restartSession($date = false) {
|
246 |
+
$surviving_cookies = array();
|
247 |
+
for ($i = 0; $i < count($this->cookies); $i++) {
|
248 |
+
if (! $this->cookies[$i]->getValue()) {
|
249 |
+
continue;
|
250 |
+
}
|
251 |
+
if (! $this->cookies[$i]->getExpiry()) {
|
252 |
+
continue;
|
253 |
+
}
|
254 |
+
if ($date && $this->cookies[$i]->isExpired($date)) {
|
255 |
+
continue;
|
256 |
+
}
|
257 |
+
$surviving_cookies[] = $this->cookies[$i];
|
258 |
+
}
|
259 |
+
$this->cookies = $surviving_cookies;
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Ages all cookies in the cookie jar.
|
264 |
+
* @param integer $interval The old session is moved
|
265 |
+
* into the past by this number
|
266 |
+
* of seconds. Cookies now over
|
267 |
+
* age will be removed.
|
268 |
+
* @access public
|
269 |
+
*/
|
270 |
+
function agePrematurely($interval) {
|
271 |
+
for ($i = 0; $i < count($this->cookies); $i++) {
|
272 |
+
$this->cookies[$i]->agePrematurely($interval);
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Sets an additional cookie. If a cookie has
|
278 |
+
* the same name and path it is replaced.
|
279 |
+
* @param string $name Cookie key.
|
280 |
+
* @param string $value Value of cookie.
|
281 |
+
* @param string $host Host upon which the cookie is valid.
|
282 |
+
* @param string $path Cookie path if not host wide.
|
283 |
+
* @param string $expiry Expiry date.
|
284 |
+
* @access public
|
285 |
+
*/
|
286 |
+
function setCookie($name, $value, $host = false, $path = '/', $expiry = false) {
|
287 |
+
$cookie = new SimpleCookie($name, $value, $path, $expiry);
|
288 |
+
if ($host) {
|
289 |
+
$cookie->setHost($host);
|
290 |
+
}
|
291 |
+
$this->cookies[$this->findFirstMatch($cookie)] = $cookie;
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Finds a matching cookie to write over or the
|
296 |
+
* first empty slot if none.
|
297 |
+
* @param SimpleCookie $cookie Cookie to write into jar.
|
298 |
+
* @return integer Available slot.
|
299 |
+
* @access private
|
300 |
+
*/
|
301 |
+
protected function findFirstMatch($cookie) {
|
302 |
+
for ($i = 0; $i < count($this->cookies); $i++) {
|
303 |
+
$is_match = $this->isMatch(
|
304 |
+
$cookie,
|
305 |
+
$this->cookies[$i]->getHost(),
|
306 |
+
$this->cookies[$i]->getPath(),
|
307 |
+
$this->cookies[$i]->getName());
|
308 |
+
if ($is_match) {
|
309 |
+
return $i;
|
310 |
+
}
|
311 |
+
}
|
312 |
+
return count($this->cookies);
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Reads the most specific cookie value from the
|
317 |
+
* browser cookies. Looks for the longest path that
|
318 |
+
* matches.
|
319 |
+
* @param string $host Host to search.
|
320 |
+
* @param string $path Applicable path.
|
321 |
+
* @param string $name Name of cookie to read.
|
322 |
+
* @return string False if not present, else the
|
323 |
+
* value as a string.
|
324 |
+
* @access public
|
325 |
+
*/
|
326 |
+
function getCookieValue($host, $path, $name) {
|
327 |
+
$longest_path = '';
|
328 |
+
foreach ($this->cookies as $cookie) {
|
329 |
+
if ($this->isMatch($cookie, $host, $path, $name)) {
|
330 |
+
if (strlen($cookie->getPath()) > strlen($longest_path)) {
|
331 |
+
$value = $cookie->getValue();
|
332 |
+
$longest_path = $cookie->getPath();
|
333 |
+
}
|
334 |
+
}
|
335 |
+
}
|
336 |
+
return (isset($value) ? $value : false);
|
337 |
+
}
|
338 |
+
|
339 |
+
/**
|
340 |
+
* Tests cookie for matching against search
|
341 |
+
* criteria.
|
342 |
+
* @param SimpleTest $cookie Cookie to test.
|
343 |
+
* @param string $host Host must match.
|
344 |
+
* @param string $path Cookie path must be shorter than
|
345 |
+
* this path.
|
346 |
+
* @param string $name Name must match.
|
347 |
+
* @return boolean True if matched.
|
348 |
+
* @access private
|
349 |
+
*/
|
350 |
+
protected function isMatch($cookie, $host, $path, $name) {
|
351 |
+
if ($cookie->getName() != $name) {
|
352 |
+
return false;
|
353 |
+
}
|
354 |
+
if ($host && $cookie->getHost() && ! $cookie->isValidHost($host)) {
|
355 |
+
return false;
|
356 |
+
}
|
357 |
+
if (! $cookie->isValidPath($path)) {
|
358 |
+
return false;
|
359 |
+
}
|
360 |
+
return true;
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Uses a URL to sift relevant cookies by host and
|
365 |
+
* path. Results are list of strings of form "name=value".
|
366 |
+
* @param SimpleUrl $url Url to select by.
|
367 |
+
* @return array Valid name and value pairs.
|
368 |
+
* @access public
|
369 |
+
*/
|
370 |
+
function selectAsPairs($url) {
|
371 |
+
$pairs = array();
|
372 |
+
foreach ($this->cookies as $cookie) {
|
373 |
+
if ($this->isMatch($cookie, $url->getHost(), $url->getPath(), $cookie->getName())) {
|
374 |
+
$pairs[] = $cookie->getName() . '=' . $cookie->getValue();
|
375 |
+
}
|
376 |
+
}
|
377 |
+
return $pairs;
|
378 |
+
}
|
379 |
+
}
|
380 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/default_reporter.php
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Optional include file for SimpleTest
|
4 |
+
* @package SimpleTest
|
5 |
+
* @subpackage UnitTester
|
6 |
+
* @version $Id: default_reporter.php 2011 2011-04-29 08:22:48Z pp11 $
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**#@+
|
10 |
+
* include other SimpleTest class files
|
11 |
+
*/
|
12 |
+
require_once(dirname(__FILE__) . '/simpletest.php');
|
13 |
+
require_once(dirname(__FILE__) . '/scorer.php');
|
14 |
+
require_once(dirname(__FILE__) . '/reporter.php');
|
15 |
+
require_once(dirname(__FILE__) . '/xml.php');
|
16 |
+
/**#@-*/
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Parser for command line arguments. Extracts
|
20 |
+
* the a specific test to run and engages XML
|
21 |
+
* reporting when necessary.
|
22 |
+
* @package SimpleTest
|
23 |
+
* @subpackage UnitTester
|
24 |
+
*/
|
25 |
+
class SimpleCommandLineParser {
|
26 |
+
private $to_property = array(
|
27 |
+
'case' => 'case', 'c' => 'case',
|
28 |
+
'test' => 'test', 't' => 'test',
|
29 |
+
);
|
30 |
+
private $case = '';
|
31 |
+
private $test = '';
|
32 |
+
private $xml = false;
|
33 |
+
private $help = false;
|
34 |
+
private $no_skips = false;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Parses raw command line arguments into object properties.
|
38 |
+
* @param string $arguments Raw commend line arguments.
|
39 |
+
*/
|
40 |
+
function __construct($arguments) {
|
41 |
+
if (! is_array($arguments)) {
|
42 |
+
return;
|
43 |
+
}
|
44 |
+
foreach ($arguments as $i => $argument) {
|
45 |
+
if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
|
46 |
+
$property = $this->to_property[$matches[1]];
|
47 |
+
$this->$property = $matches[2];
|
48 |
+
} elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
|
49 |
+
$property = $this->to_property[$matches[1]];
|
50 |
+
if (isset($arguments[$i + 1])) {
|
51 |
+
$this->$property = $arguments[$i + 1];
|
52 |
+
}
|
53 |
+
} elseif (preg_match('/^--?(xml|x)$/', $argument)) {
|
54 |
+
$this->xml = true;
|
55 |
+
} elseif (preg_match('/^--?(no-skip|no-skips|s)$/', $argument)) {
|
56 |
+
$this->no_skips = true;
|
57 |
+
} elseif (preg_match('/^--?(help|h)$/', $argument)) {
|
58 |
+
$this->help = true;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Run only this test.
|
65 |
+
* @return string Test name to run.
|
66 |
+
*/
|
67 |
+
function getTest() {
|
68 |
+
return $this->test;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Run only this test suite.
|
73 |
+
* @return string Test class name to run.
|
74 |
+
*/
|
75 |
+
function getTestCase() {
|
76 |
+
return $this->case;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Output should be XML or not.
|
81 |
+
* @return boolean True if XML desired.
|
82 |
+
*/
|
83 |
+
function isXml() {
|
84 |
+
return $this->xml;
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Output should suppress skip messages.
|
89 |
+
* @return boolean True for no skips.
|
90 |
+
*/
|
91 |
+
function noSkips() {
|
92 |
+
return $this->no_skips;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Output should be a help message. Disabled during XML mode.
|
97 |
+
* @return boolean True if help message desired.
|
98 |
+
*/
|
99 |
+
function help() {
|
100 |
+
return $this->help && ! $this->xml;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Returns plain-text help message for command line runner.
|
105 |
+
* @return string String help message
|
106 |
+
*/
|
107 |
+
function getHelpText() {
|
108 |
+
return <<<HELP
|
109 |
+
SimpleTest command line default reporter (autorun)
|
110 |
+
Usage: php <test_file> [args...]
|
111 |
+
|
112 |
+
-c <class> Run only the test-case <class>
|
113 |
+
-t <method> Run only the test method <method>
|
114 |
+
-s Suppress skip messages
|
115 |
+
-x Return test results in XML
|
116 |
+
-h Display this help message
|
117 |
+
|
118 |
+
HELP;
|
119 |
+
}
|
120 |
+
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* The default reporter used by SimpleTest's autorun
|
125 |
+
* feature. The actual reporters used are dependency
|
126 |
+
* injected and can be overridden.
|
127 |
+
* @package SimpleTest
|
128 |
+
* @subpackage UnitTester
|
129 |
+
*/
|
130 |
+
class DefaultReporter extends SimpleReporterDecorator {
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Assembles the appropriate reporter for the environment.
|
134 |
+
*/
|
135 |
+
function __construct() {
|
136 |
+
if (SimpleReporter::inCli()) {
|
137 |
+
$parser = new SimpleCommandLineParser($_SERVER['argv']);
|
138 |
+
$interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
|
139 |
+
if ($parser->help()) {
|
140 |
+
// I'm not sure if we should do the echo'ing here -- ezyang
|
141 |
+
echo $parser->getHelpText();
|
142 |
+
exit(1);
|
143 |
+
}
|
144 |
+
$reporter = new SelectiveReporter(
|
145 |
+
SimpleTest::preferred($interfaces),
|
146 |
+
$parser->getTestCase(),
|
147 |
+
$parser->getTest());
|
148 |
+
if ($parser->noSkips()) {
|
149 |
+
$reporter = new NoSkipsReporter($reporter);
|
150 |
+
}
|
151 |
+
} else {
|
152 |
+
$reporter = new SelectiveReporter(
|
153 |
+
SimpleTest::preferred('HtmlReporter'),
|
154 |
+
@$_GET['c'],
|
155 |
+
@$_GET['t']);
|
156 |
+
if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') {
|
157 |
+
$reporter = new NoSkipsReporter($reporter);
|
158 |
+
}
|
159 |
+
}
|
160 |
+
parent::__construct($reporter);
|
161 |
+
}
|
162 |
+
}
|
163 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/detached.php
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* base include file for SimpleTest
|
4 |
+
* @package SimpleTest
|
5 |
+
* @subpackage UnitTester
|
6 |
+
* @version $Id: detached.php 1784 2008-04-26 13:07:14Z pp11 $
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**#@+
|
10 |
+
* include other SimpleTest class files
|
11 |
+
*/
|
12 |
+
require_once(dirname(__FILE__) . '/xml.php');
|
13 |
+
require_once(dirname(__FILE__) . '/shell_tester.php');
|
14 |
+
/**#@-*/
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Runs an XML formated test in a separate process.
|
18 |
+
* @package SimpleTest
|
19 |
+
* @subpackage UnitTester
|
20 |
+
*/
|
21 |
+
class DetachedTestCase {
|
22 |
+
private $command;
|
23 |
+
private $dry_command;
|
24 |
+
private $size;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Sets the location of the remote test.
|
28 |
+
* @param string $command Test script.
|
29 |
+
* @param string $dry_command Script for dry run.
|
30 |
+
* @access public
|
31 |
+
*/
|
32 |
+
function __construct($command, $dry_command = false) {
|
33 |
+
$this->command = $command;
|
34 |
+
$this->dry_command = $dry_command ? $dry_command : $command;
|
35 |
+
$this->size = false;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Accessor for the test name for subclasses.
|
40 |
+
* @return string Name of the test.
|
41 |
+
* @access public
|
42 |
+
*/
|
43 |
+
function getLabel() {
|
44 |
+
return $this->command;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Runs the top level test for this class. Currently
|
49 |
+
* reads the data as a single chunk. I'll fix this
|
50 |
+
* once I have added iteration to the browser.
|
51 |
+
* @param SimpleReporter $reporter Target of test results.
|
52 |
+
* @returns boolean True if no failures.
|
53 |
+
* @access public
|
54 |
+
*/
|
55 |
+
function run(&$reporter) {
|
56 |
+
$shell = &new SimpleShell();
|
57 |
+
$shell->execute($this->command);
|
58 |
+
$parser = &$this->createParser($reporter);
|
59 |
+
if (! $parser->parse($shell->getOutput())) {
|
60 |
+
trigger_error('Cannot parse incoming XML from [' . $this->command . ']');
|
61 |
+
return false;
|
62 |
+
}
|
63 |
+
return true;
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Accessor for the number of subtests.
|
68 |
+
* @return integer Number of test cases.
|
69 |
+
* @access public
|
70 |
+
*/
|
71 |
+
function getSize() {
|
72 |
+
if ($this->size === false) {
|
73 |
+
$shell = &new SimpleShell();
|
74 |
+
$shell->execute($this->dry_command);
|
75 |
+
$reporter = &new SimpleReporter();
|
76 |
+
$parser = &$this->createParser($reporter);
|
77 |
+
if (! $parser->parse($shell->getOutput())) {
|
78 |
+
trigger_error('Cannot parse incoming XML from [' . $this->dry_command . ']');
|
79 |
+
return false;
|
80 |
+
}
|
81 |
+
$this->size = $reporter->getTestCaseCount();
|
82 |
+
}
|
83 |
+
return $this->size;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Creates the XML parser.
|
88 |
+
* @param SimpleReporter $reporter Target of test results.
|
89 |
+
* @return SimpleTestXmlListener XML reader.
|
90 |
+
* @access protected
|
91 |
+
*/
|
92 |
+
protected function &createParser(&$reporter) {
|
93 |
+
return new SimpleTestXmlParser($reporter);
|
94 |
+
}
|
95 |
+
}
|
96 |
+
?>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/authentication_documentation.html
ADDED
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest documentation for testing log-in and authentication</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<span class="chosen">Authentication</span>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Authentication documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
Getting through <a href="#basic">Basic HTTP authentication</a>
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
Testing <a href="#cookies">cookie based authentication</a>
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
Managing <a href="#session">browser sessions</a> and timeouts
|
44 |
+
</li>
|
45 |
+
</ul>
|
46 |
+
<div class="content">
|
47 |
+
|
48 |
+
<p>
|
49 |
+
One of the trickiest, and yet most important, areas
|
50 |
+
of testing web sites is the security.
|
51 |
+
Testing these schemes is one of the core goals of
|
52 |
+
the SimpleTest web tester.
|
53 |
+
</p>
|
54 |
+
|
55 |
+
<h2>
|
56 |
+
<a class="target" name="basic"></a>Basic HTTP authentication</h2>
|
57 |
+
<p>
|
58 |
+
If you fetch a page protected by basic authentication then
|
59 |
+
rather than receiving content, you will instead get a 401
|
60 |
+
header.
|
61 |
+
We can illustrate this with this test...
|
62 |
+
<pre>
|
63 |
+
class AuthenticationTest extends WebTestCase {<strong>
|
64 |
+
function test401Header() {
|
65 |
+
$this->get('http://www.lastcraft.com/protected/');
|
66 |
+
$this->showHeaders();
|
67 |
+
}</strong>
|
68 |
+
}
|
69 |
+
</pre>
|
70 |
+
This allows us to see the challenge header...
|
71 |
+
<div class="demo">
|
72 |
+
<h1>File test</h1>
|
73 |
+
<pre>
|
74 |
+
HTTP/1.1 401 Authorization Required
|
75 |
+
Date: Sat, 18 Sep 2004 19:25:18 GMT
|
76 |
+
Server: Apache/1.3.29 (Unix) PHP/4.3.4
|
77 |
+
WWW-Authenticate: Basic realm="SimpleTest basic authentication"
|
78 |
+
Connection: close
|
79 |
+
Content-Type: text/html; charset=iso-8859-1
|
80 |
+
</pre>
|
81 |
+
<div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">1/1 test cases complete.
|
82 |
+
<strong>0</strong> passes, <strong>0</strong> fails and <strong>0</strong> exceptions.</div>
|
83 |
+
</div>
|
84 |
+
We are trying to get away from visual inspection though, and so SimpleTest
|
85 |
+
allows to make automated assertions against the challenge.
|
86 |
+
Here is a thorough test of our header...
|
87 |
+
<pre>
|
88 |
+
class AuthenticationTest extends WebTestCase {
|
89 |
+
function test401Header() {
|
90 |
+
$this->get('http://www.lastcraft.com/protected/');<strong>
|
91 |
+
$this->assertAuthentication('Basic');
|
92 |
+
$this->assertResponse(401);
|
93 |
+
$this->assertRealm('SimpleTest basic authentication');</strong>
|
94 |
+
}
|
95 |
+
}
|
96 |
+
</pre>
|
97 |
+
Any one of these tests would normally do on it's own depending
|
98 |
+
on the amount of detail you want to see.
|
99 |
+
</p>
|
100 |
+
<p>
|
101 |
+
One theme that runs through SimpleTest is the ability to use
|
102 |
+
<span class="new_code">SimpleExpectation</span> objects wherever a simple
|
103 |
+
match is not enough.
|
104 |
+
If you want only an approximate match to the realm for
|
105 |
+
example, you can do this...
|
106 |
+
<pre>
|
107 |
+
class AuthenticationTest extends WebTestCase {
|
108 |
+
function test401Header() {
|
109 |
+
$this->get('http://www.lastcraft.com/protected/');
|
110 |
+
$this->assertRealm(<strong>new PatternExpectation('/simpletest/i')</strong>);
|
111 |
+
}
|
112 |
+
}
|
113 |
+
</pre>
|
114 |
+
This type of test, testing HTTP responses, is not typical.
|
115 |
+
</p>
|
116 |
+
<p>
|
117 |
+
Most of the time we are not interested in testing the
|
118 |
+
authentication itself, but want to get past it to test
|
119 |
+
the pages underneath.
|
120 |
+
As soon as the challenge has been issued we can reply with
|
121 |
+
an authentication response...
|
122 |
+
<pre>
|
123 |
+
class AuthenticationTest extends WebTestCase {
|
124 |
+
function testCanAuthenticate() {
|
125 |
+
$this->get('http://www.lastcraft.com/protected/');<strong>
|
126 |
+
$this->authenticate('Me', 'Secret');</strong>
|
127 |
+
$this->assertTitle(...);
|
128 |
+
}
|
129 |
+
}
|
130 |
+
</pre>
|
131 |
+
The username and password will now be sent with every
|
132 |
+
subsequent request to that directory and subdirectories.
|
133 |
+
You will have to authenticate again if you step outside
|
134 |
+
the authenticated directory, but SimpleTest is smart enough
|
135 |
+
to merge subdirectories into a common realm.
|
136 |
+
</p>
|
137 |
+
<p>
|
138 |
+
If you want, you can shortcut this step further by encoding
|
139 |
+
the log in details straight into the URL...
|
140 |
+
<pre>
|
141 |
+
class AuthenticationTest extends WebTestCase {
|
142 |
+
function testCanReadAuthenticatedPages() {
|
143 |
+
$this->get('http://<strong>Me:Secret@</strong>www.lastcraft.com/protected/');
|
144 |
+
$this->assertTitle(...);
|
145 |
+
}
|
146 |
+
}
|
147 |
+
</pre>
|
148 |
+
If your username or password has special characters, then you
|
149 |
+
will have to URL encode them or the request will not be parsed
|
150 |
+
correctly.
|
151 |
+
I'm afraid we leave this up to you.
|
152 |
+
</p>
|
153 |
+
<p>
|
154 |
+
A problem with encoding the login details directly in the URL is
|
155 |
+
the authentication header will not be sent on subsequent requests.
|
156 |
+
If you navigate with relative URLs though, the authentication
|
157 |
+
information will be preserved along with the domain name.
|
158 |
+
</p>
|
159 |
+
<p>
|
160 |
+
Normally though, you use the <span class="new_code">authenticate()</span> call.
|
161 |
+
SimpleTest will then remember your login information on each request.
|
162 |
+
</p>
|
163 |
+
<p>
|
164 |
+
Only testing with basic authentication is currently supported, and
|
165 |
+
this is only really secure in tandem with HTTPS connections.
|
166 |
+
This is usually good enough to protect test server from prying eyes,
|
167 |
+
however.
|
168 |
+
Digest authentication and NTLM authentication may be added
|
169 |
+
in the future if enough people request this feature.
|
170 |
+
</p>
|
171 |
+
|
172 |
+
<h2>
|
173 |
+
<a class="target" name="cookies"></a>Cookies</h2>
|
174 |
+
<p>
|
175 |
+
Basic authentication doesn't give enough control over the
|
176 |
+
user interface for web developers.
|
177 |
+
More likely this functionality will be coded directly into
|
178 |
+
the web architecture using cookies with complicated timeouts.
|
179 |
+
We need to be able to test this too.
|
180 |
+
</p>
|
181 |
+
<p>
|
182 |
+
Starting with a simple log-in form...
|
183 |
+
<pre>
|
184 |
+
<form>
|
185 |
+
Username:
|
186 |
+
<input type="text" name="u" value="" /><br />
|
187 |
+
Password:
|
188 |
+
<input type="password" name="p" value="" /><br />
|
189 |
+
<input type="submit" value="Log in" />
|
190 |
+
</form>
|
191 |
+
</pre>
|
192 |
+
Which looks like...
|
193 |
+
</p>
|
194 |
+
<p>
|
195 |
+
<form class="demo">
|
196 |
+
Username:
|
197 |
+
<input type="text" name="u" value=""><br>
|
198 |
+
Password:
|
199 |
+
<input type="password" name="p" value=""><br>
|
200 |
+
<input type="submit" value="Log in">
|
201 |
+
</form>
|
202 |
+
</p>
|
203 |
+
<p>
|
204 |
+
Let's suppose that in fetching this page a cookie has been
|
205 |
+
set with a session ID.
|
206 |
+
We are not going to fill the form in yet, just test that
|
207 |
+
we are tracking the user.
|
208 |
+
Here is the test...
|
209 |
+
<pre>
|
210 |
+
class LogInTest extends WebTestCase {
|
211 |
+
function testSessionCookieSetBeforeForm() {
|
212 |
+
$this->get('http://www.my-site.com/login.php');<strong>
|
213 |
+
$this->assertCookie('SID');</strong>
|
214 |
+
}
|
215 |
+
}
|
216 |
+
</pre>
|
217 |
+
All we are doing is confirming that the cookie is set.
|
218 |
+
As the value is likely to be rather cryptic it's not
|
219 |
+
really worth testing this with...
|
220 |
+
<pre>
|
221 |
+
class LogInTest extends WebTestCase {
|
222 |
+
function testSessionCookieIsCorrectPattern() {
|
223 |
+
$this->get('http://www.my-site.com/login.php');
|
224 |
+
$this->assertCookie('SID', <strong>new PatternExpectation('/[a-f0-9]{32}/i')</strong>);
|
225 |
+
}
|
226 |
+
}
|
227 |
+
</pre>
|
228 |
+
If you are using PHP to handle sessions for you then
|
229 |
+
this test is even more useless, as we are just testing PHP itself.
|
230 |
+
</p>
|
231 |
+
<p>
|
232 |
+
The simplest test of logging in is to visually inspect the
|
233 |
+
next page to see if you are really logged in.
|
234 |
+
Just test the next page with <span class="new_code">WebTestCase::assertText()</span>.
|
235 |
+
</p>
|
236 |
+
<p>
|
237 |
+
The test is similar to any other form test,
|
238 |
+
but we might want to confirm that we still have the same
|
239 |
+
cookie after log-in as before we entered.
|
240 |
+
We wouldn't want to lose track of this after all.
|
241 |
+
Here is a possible test for this...
|
242 |
+
<pre>
|
243 |
+
class LogInTest extends WebTestCase {
|
244 |
+
...
|
245 |
+
function testSessionCookieSameAfterLogIn() {
|
246 |
+
$this->get('http://www.my-site.com/login.php');<strong>
|
247 |
+
$session = $this->getCookie('SID');
|
248 |
+
$this->setField('u', 'Me');
|
249 |
+
$this->setField('p', 'Secret');
|
250 |
+
$this->click('Log in');
|
251 |
+
$this->assertText('Welcome Me');
|
252 |
+
$this->assertCookie('SID', $session);</strong>
|
253 |
+
}
|
254 |
+
}
|
255 |
+
</pre>
|
256 |
+
This confirms that the session identifier is maintained
|
257 |
+
afer log-in and we haven't accidently reset it.
|
258 |
+
</p>
|
259 |
+
<p>
|
260 |
+
We could even attempt to hack our own system by setting
|
261 |
+
arbitrary cookies to gain access...
|
262 |
+
<pre>
|
263 |
+
class LogInTest extends WebTestCase {
|
264 |
+
...
|
265 |
+
function testSessionCookieSameAfterLogIn() {
|
266 |
+
$this->get('http://www.my-site.com/login.php');<strong>
|
267 |
+
$this->setCookie('SID', 'Some other session');
|
268 |
+
$this->get('http://www.my-site.com/restricted.php');</strong>
|
269 |
+
$this->assertText('Access denied');
|
270 |
+
}
|
271 |
+
}
|
272 |
+
</pre>
|
273 |
+
Is your site protected from this attack?
|
274 |
+
</p>
|
275 |
+
|
276 |
+
<h2>
|
277 |
+
<a class="target" name="session"></a>Browser sessions</h2>
|
278 |
+
<p>
|
279 |
+
If you are testing an authentication system a critical piece
|
280 |
+
of behaviour is what happens when a user logs back in.
|
281 |
+
We would like to simulate closing and reopening a browser...
|
282 |
+
<pre>
|
283 |
+
class LogInTest extends WebTestCase {
|
284 |
+
...
|
285 |
+
function testLoseAuthenticationAfterBrowserClose() {
|
286 |
+
$this->get('http://www.my-site.com/login.php');
|
287 |
+
$this->setField('u', 'Me');
|
288 |
+
$this->setField('p', 'Secret');
|
289 |
+
$this->click('Log in');
|
290 |
+
$this->assertText('Welcome Me');<strong>
|
291 |
+
|
292 |
+
$this->restart();
|
293 |
+
$this->get('http://www.my-site.com/restricted.php');
|
294 |
+
$this->assertText('Access denied');</strong>
|
295 |
+
}
|
296 |
+
}
|
297 |
+
</pre>
|
298 |
+
The <span class="new_code">WebTestCase::restart()</span> method will
|
299 |
+
preserve cookies that have unexpired timeouts, but throw away
|
300 |
+
those that are temporary or expired.
|
301 |
+
You can optionally specify the time and date that the restart
|
302 |
+
happened.
|
303 |
+
</p>
|
304 |
+
<p>
|
305 |
+
Expiring cookies can be a problem.
|
306 |
+
After all, if you have a cookie that expires after an hour,
|
307 |
+
you don't want to stall the test for an hour while waiting
|
308 |
+
for the cookie to pass it's timeout.
|
309 |
+
</p>
|
310 |
+
<p>
|
311 |
+
To push the cookies over the hour limit you can age them
|
312 |
+
before you restart the session...
|
313 |
+
<pre>
|
314 |
+
class LogInTest extends WebTestCase {
|
315 |
+
...
|
316 |
+
function testLoseAuthenticationAfterOneHour() {
|
317 |
+
$this->get('http://www.my-site.com/login.php');
|
318 |
+
$this->setField('u', 'Me');
|
319 |
+
$this->setField('p', 'Secret');
|
320 |
+
$this->click('Log in');
|
321 |
+
$this->assertText('Welcome Me');
|
322 |
+
<strong>
|
323 |
+
$this->ageCookies(3600);</strong>
|
324 |
+
$this->restart();
|
325 |
+
$this->get('http://www.my-site.com/restricted.php');
|
326 |
+
$this->assertText('Access denied');
|
327 |
+
}
|
328 |
+
}
|
329 |
+
</pre>
|
330 |
+
After the restart it will appear that cookies are an
|
331 |
+
hour older, and any that pass their expiry will have
|
332 |
+
disappeared.
|
333 |
+
</p>
|
334 |
+
|
335 |
+
</div>
|
336 |
+
References and related information...
|
337 |
+
<ul>
|
338 |
+
<li>
|
339 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
340 |
+
</li>
|
341 |
+
<li>
|
342 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
343 |
+
</li>
|
344 |
+
<li>
|
345 |
+
The <a href="http://simpletest.org/api/">developer's API for SimpleTest</a>
|
346 |
+
gives full detail on the classes and assertions available.
|
347 |
+
</li>
|
348 |
+
</ul>
|
349 |
+
<div class="menu_back"><div class="menu">
|
350 |
+
<a href="index.html">SimpleTest</a>
|
351 |
+
|
|
352 |
+
<a href="overview.html">Overview</a>
|
353 |
+
|
|
354 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
355 |
+
|
|
356 |
+
<a href="group_test_documentation.html">Group tests</a>
|
357 |
+
|
|
358 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
359 |
+
|
|
360 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
361 |
+
|
|
362 |
+
<a href="reporter_documentation.html">Reporting</a>
|
363 |
+
|
|
364 |
+
<a href="expectation_documentation.html">Expectations</a>
|
365 |
+
|
|
366 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
367 |
+
|
|
368 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
369 |
+
|
|
370 |
+
<span class="chosen">Authentication</span>
|
371 |
+
|
|
372 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
373 |
+
</div></div>
|
374 |
+
<div class="copyright">
|
375 |
+
Copyright<br>Marcus Baker 2006
|
376 |
+
</div>
|
377 |
+
</body>
|
378 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/browser_documentation.html
ADDED
@@ -0,0 +1,501 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest documentation for the scriptable web browser component</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<span class="chosen">Scriptable browser</span>
|
32 |
+
</div></div>
|
33 |
+
<h1>PHP Scriptable Web Browser</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
Using the bundled <a href="#scripting">web browser in scripts</a>
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
<a href="#debug">Debugging</a> failed pages
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
Complex <a href="#unit">tests with multiple web browsers</a>
|
44 |
+
</li>
|
45 |
+
</ul>
|
46 |
+
<div class="content">
|
47 |
+
|
48 |
+
<p>
|
49 |
+
SimpleTest's web browser component can be used not just
|
50 |
+
outside of the <span class="new_code">WebTestCase</span> class, but also
|
51 |
+
independently of the SimpleTest framework itself.
|
52 |
+
</p>
|
53 |
+
|
54 |
+
<h2>
|
55 |
+
<a class="target" name="scripting"></a>The Scriptable Browser</h2>
|
56 |
+
<p>
|
57 |
+
You can use the web browser in PHP scripts to confirm
|
58 |
+
services are up and running, or to extract information
|
59 |
+
from them at a regular basis.
|
60 |
+
For example, here is a small script to extract the current number of
|
61 |
+
open PHP 5 bugs from the <a href="http://www.php.net/">PHP web site</a>...
|
62 |
+
<pre>
|
63 |
+
<strong><?php
|
64 |
+
require_once('simpletest/browser.php');
|
65 |
+
|
66 |
+
$browser = &new SimpleBrowser();
|
67 |
+
$browser->get('http://php.net/');
|
68 |
+
$browser->click('reporting bugs');
|
69 |
+
$browser->click('statistics');
|
70 |
+
$page = $browser->click('PHP 5 bugs only');
|
71 |
+
preg_match('/status=Open.*?by=Any.*?(\d+)<\/a>/', $page, $matches);
|
72 |
+
print $matches[1];
|
73 |
+
?></strong>
|
74 |
+
</pre>
|
75 |
+
There are simpler methods to do this particular example in PHP
|
76 |
+
of course.
|
77 |
+
For example you can just use the PHP <span class="new_code">file()</span>
|
78 |
+
command against what here is a pretty fixed page.
|
79 |
+
However, using the web browser for scripts allows authentication,
|
80 |
+
correct handling of cookies, automatic loading of frames, redirects,
|
81 |
+
form submission and the ability to examine the page headers.
|
82 |
+
<p>
|
83 |
+
</p>
|
84 |
+
Methods such as periodic scraping are fragile against a site that is constantly
|
85 |
+
evolving and you would want a more direct way of accessing
|
86 |
+
data in a permanent set up, but for simple tasks this can provide
|
87 |
+
a very rapid solution.
|
88 |
+
</p>
|
89 |
+
<p>
|
90 |
+
All of the navigation methods used in the
|
91 |
+
<a href="web_tester_documentation.html">WebTestCase</a>
|
92 |
+
are present in the <span class="new_code">SimpleBrowser</span> class, but
|
93 |
+
the assertions are replaced with simpler accessors.
|
94 |
+
Here is a full list of the page navigation methods...
|
95 |
+
<table><tbody>
|
96 |
+
<tr>
|
97 |
+
<td><span class="new_code">addHeader($header)</span></td>
|
98 |
+
<td>Adds a header to every fetch</td>
|
99 |
+
</tr>
|
100 |
+
<tr>
|
101 |
+
<td><span class="new_code">useProxy($proxy, $username, $password)</span></td>
|
102 |
+
<td>Use this proxy from now on</td>
|
103 |
+
</tr>
|
104 |
+
<tr>
|
105 |
+
<td><span class="new_code">head($url, $parameters)</span></td>
|
106 |
+
<td>Perform a HEAD request</td>
|
107 |
+
</tr>
|
108 |
+
<tr>
|
109 |
+
<td><span class="new_code">get($url, $parameters)</span></td>
|
110 |
+
<td>Fetch a page with GET</td>
|
111 |
+
</tr>
|
112 |
+
<tr>
|
113 |
+
<td><span class="new_code">post($url, $parameters)</span></td>
|
114 |
+
<td>Fetch a page with POST</td>
|
115 |
+
</tr>
|
116 |
+
<tr>
|
117 |
+
<td><span class="new_code">click($label)</span></td>
|
118 |
+
<td>Clicks visible link or button text</td>
|
119 |
+
</tr>
|
120 |
+
<tr>
|
121 |
+
<td><span class="new_code">clickLink($label)</span></td>
|
122 |
+
<td>Follows a link by label</td>
|
123 |
+
</tr>
|
124 |
+
<tr>
|
125 |
+
<td><span class="new_code">clickLinkById($id)</span></td>
|
126 |
+
<td>Follows a link by attribute</td>
|
127 |
+
</tr>
|
128 |
+
<tr>
|
129 |
+
<td><span class="new_code">getUrl()</span></td>
|
130 |
+
<td>Current URL of page or frame</td>
|
131 |
+
</tr>
|
132 |
+
<tr>
|
133 |
+
<td><span class="new_code">getTitle()</span></td>
|
134 |
+
<td>Page title</td>
|
135 |
+
</tr>
|
136 |
+
<tr>
|
137 |
+
<td><span class="new_code">getContent()</span></td>
|
138 |
+
<td>Raw page or frame</td>
|
139 |
+
</tr>
|
140 |
+
<tr>
|
141 |
+
<td><span class="new_code">getContentAsText()</span></td>
|
142 |
+
<td>HTML removed except for alt text</td>
|
143 |
+
</tr>
|
144 |
+
<tr>
|
145 |
+
<td><span class="new_code">retry()</span></td>
|
146 |
+
<td>Repeat the last request</td>
|
147 |
+
</tr>
|
148 |
+
<tr>
|
149 |
+
<td><span class="new_code">back()</span></td>
|
150 |
+
<td>Use the browser back button</td>
|
151 |
+
</tr>
|
152 |
+
<tr>
|
153 |
+
<td><span class="new_code">forward()</span></td>
|
154 |
+
<td>Use the browser forward button</td>
|
155 |
+
</tr>
|
156 |
+
<tr>
|
157 |
+
<td><span class="new_code">authenticate($username, $password)</span></td>
|
158 |
+
<td>Retry page or frame after a 401 response</td>
|
159 |
+
</tr>
|
160 |
+
<tr>
|
161 |
+
<td><span class="new_code">restart($date)</span></td>
|
162 |
+
<td>Restarts the browser for a new session</td>
|
163 |
+
</tr>
|
164 |
+
<tr>
|
165 |
+
<td><span class="new_code">ageCookies($interval)</span></td>
|
166 |
+
<td>Ages the cookies by the specified time</td>
|
167 |
+
</tr>
|
168 |
+
<tr>
|
169 |
+
<td><span class="new_code">setCookie($name, $value)</span></td>
|
170 |
+
<td>Sets an additional cookie</td>
|
171 |
+
</tr>
|
172 |
+
<tr>
|
173 |
+
<td><span class="new_code">getCookieValue($host, $path, $name)</span></td>
|
174 |
+
<td>Reads the most specific cookie</td>
|
175 |
+
</tr>
|
176 |
+
<tr>
|
177 |
+
<td><span class="new_code">getCurrentCookieValue($name)</span></td>
|
178 |
+
<td>Reads cookie for the current context</td>
|
179 |
+
</tr>
|
180 |
+
</tbody></table>
|
181 |
+
The methods <span class="new_code">SimpleBrowser::useProxy()</span> and
|
182 |
+
<span class="new_code">SimpleBrowser::addHeader()</span> are special.
|
183 |
+
Once called they continue to apply to all subsequent fetches.
|
184 |
+
</p>
|
185 |
+
<p>
|
186 |
+
Navigating forms is similar to the
|
187 |
+
<a href="form_testing_documentation.html">WebTestCase form navigation</a>...
|
188 |
+
<table><tbody>
|
189 |
+
<tr>
|
190 |
+
<td><span class="new_code">setField($label, $value)</span></td>
|
191 |
+
<td>Sets all form fields with that label or name</td>
|
192 |
+
</tr>
|
193 |
+
<tr>
|
194 |
+
<td><span class="new_code">setFieldByName($name, $value)</span></td>
|
195 |
+
<td>Sets all form fields with that name</td>
|
196 |
+
</tr>
|
197 |
+
<tr>
|
198 |
+
<td><span class="new_code">setFieldById($id, $value)</span></td>
|
199 |
+
<td>Sets all form fields with that id</td>
|
200 |
+
</tr>
|
201 |
+
<tr>
|
202 |
+
<td><span class="new_code">getField($label)</span></td>
|
203 |
+
<td>Accessor for a form element value by label tag and then name</td>
|
204 |
+
</tr>
|
205 |
+
<tr>
|
206 |
+
<td><span class="new_code">getFieldByName($name)</span></td>
|
207 |
+
<td>Accessor for a form element value using name attribute</td>
|
208 |
+
</tr>
|
209 |
+
<tr>
|
210 |
+
<td><span class="new_code">getFieldById($id)</span></td>
|
211 |
+
<td>Accessor for a form element value</td>
|
212 |
+
</tr>
|
213 |
+
<tr>
|
214 |
+
<td><span class="new_code">clickSubmit($label)</span></td>
|
215 |
+
<td>Submits form by button label</td>
|
216 |
+
</tr>
|
217 |
+
<tr>
|
218 |
+
<td><span class="new_code">clickSubmitByName($name)</span></td>
|
219 |
+
<td>Submits form by button attribute</td>
|
220 |
+
</tr>
|
221 |
+
<tr>
|
222 |
+
<td><span class="new_code">clickSubmitById($id)</span></td>
|
223 |
+
<td>Submits form by button attribute</td>
|
224 |
+
</tr>
|
225 |
+
<tr>
|
226 |
+
<td><span class="new_code">clickImage($label, $x, $y)</span></td>
|
227 |
+
<td>Clicks an input tag of type image by title or alt text</td>
|
228 |
+
</tr>
|
229 |
+
<tr>
|
230 |
+
<td><span class="new_code">clickImageByName($name, $x, $y)</span></td>
|
231 |
+
<td>Clicks an input tag of type image by name</td>
|
232 |
+
</tr>
|
233 |
+
<tr>
|
234 |
+
<td><span class="new_code">clickImageById($id, $x, $y)</span></td>
|
235 |
+
<td>Clicks an input tag of type image by ID attribute</td>
|
236 |
+
</tr>
|
237 |
+
<tr>
|
238 |
+
<td><span class="new_code">submitFormById($id)</span></td>
|
239 |
+
<td>Submits by the form tag attribute</td>
|
240 |
+
</tr>
|
241 |
+
</tbody></table>
|
242 |
+
At the moment there aren't many methods to list available links and fields.
|
243 |
+
<table><tbody>
|
244 |
+
<tr>
|
245 |
+
<td><span class="new_code">isClickable($label)</span></td>
|
246 |
+
<td>Test to see if a click target exists by label or name</td>
|
247 |
+
</tr>
|
248 |
+
<tr>
|
249 |
+
<td><span class="new_code">isSubmit($label)</span></td>
|
250 |
+
<td>Test for the existence of a button with that label or name</td>
|
251 |
+
</tr>
|
252 |
+
<tr>
|
253 |
+
<td><span class="new_code">isImage($label)</span></td>
|
254 |
+
<td>Test for the existence of an image button with that label or name</td>
|
255 |
+
</tr>
|
256 |
+
<tr>
|
257 |
+
<td><span class="new_code">getLink($label)</span></td>
|
258 |
+
<td>Finds a URL from its label</td>
|
259 |
+
</tr>
|
260 |
+
<tr>
|
261 |
+
<td><span class="new_code">getLinkById($label)</span></td>
|
262 |
+
<td>Finds a URL from its ID attribute</td>
|
263 |
+
</tr>
|
264 |
+
<tr>
|
265 |
+
<td><span class="new_code">getUrls()</span></td>
|
266 |
+
<td>Lists available links in the current page</td>
|
267 |
+
</tr>
|
268 |
+
</tbody></table>
|
269 |
+
This will be expanded in later versions of SimpleTest.
|
270 |
+
</p>
|
271 |
+
<p>
|
272 |
+
Frames are a rather esoteric feature these days, but SimpleTest has
|
273 |
+
retained support for them.
|
274 |
+
</p>
|
275 |
+
<p>
|
276 |
+
Within a page, individual frames can be selected.
|
277 |
+
If no selection is made then all the frames are merged together
|
278 |
+
in one large conceptual page.
|
279 |
+
The content of the current page will be a concatenation of all of the
|
280 |
+
frames in the order that they were specified in the "frameset"
|
281 |
+
tags.
|
282 |
+
<table><tbody>
|
283 |
+
<tr>
|
284 |
+
<td><span class="new_code">getFrames()</span></td>
|
285 |
+
<td>A dump of the current frame structure</td>
|
286 |
+
</tr>
|
287 |
+
<tr>
|
288 |
+
<td><span class="new_code">getFrameFocus()</span></td>
|
289 |
+
<td>Current frame label or index</td>
|
290 |
+
</tr>
|
291 |
+
<tr>
|
292 |
+
<td><span class="new_code">setFrameFocusByIndex($choice)</span></td>
|
293 |
+
<td>Select a frame numbered from 1</td>
|
294 |
+
</tr>
|
295 |
+
<tr>
|
296 |
+
<td><span class="new_code">setFrameFocus($name)</span></td>
|
297 |
+
<td>Select frame by label</td>
|
298 |
+
</tr>
|
299 |
+
<tr>
|
300 |
+
<td><span class="new_code">clearFrameFocus()</span></td>
|
301 |
+
<td>Treat all the frames as a single page</td>
|
302 |
+
</tr>
|
303 |
+
</tbody></table>
|
304 |
+
When focused on a single frame, the content will come from
|
305 |
+
that frame only.
|
306 |
+
This includes links to click and forms to submit.
|
307 |
+
</p>
|
308 |
+
|
309 |
+
<h2>
|
310 |
+
<a class="target" name="debug"></a>What went wrong?</h2>
|
311 |
+
<p>
|
312 |
+
All of this functionality is great when we actually manage to fetch pages,
|
313 |
+
but that doesn't always happen.
|
314 |
+
To help figure out what went wrong, the browser has some methods to
|
315 |
+
aid in debugging...
|
316 |
+
<table><tbody>
|
317 |
+
<tr>
|
318 |
+
<td><span class="new_code">setConnectionTimeout($timeout)</span></td>
|
319 |
+
<td>Close the socket on overrun</td>
|
320 |
+
</tr>
|
321 |
+
<tr>
|
322 |
+
<td><span class="new_code">getUrl()</span></td>
|
323 |
+
<td>Url of most recent page fetched</td>
|
324 |
+
</tr>
|
325 |
+
<tr>
|
326 |
+
<td><span class="new_code">getRequest()</span></td>
|
327 |
+
<td>Raw request header of page or frame</td>
|
328 |
+
</tr>
|
329 |
+
<tr>
|
330 |
+
<td><span class="new_code">getHeaders()</span></td>
|
331 |
+
<td>Raw response header of page or frame</td>
|
332 |
+
</tr>
|
333 |
+
<tr>
|
334 |
+
<td><span class="new_code">getTransportError()</span></td>
|
335 |
+
<td>Any socket level errors in the last fetch</td>
|
336 |
+
</tr>
|
337 |
+
<tr>
|
338 |
+
<td><span class="new_code">getResponseCode()</span></td>
|
339 |
+
<td>HTTP response of page or frame</td>
|
340 |
+
</tr>
|
341 |
+
<tr>
|
342 |
+
<td><span class="new_code">getMimeType()</span></td>
|
343 |
+
<td>Mime type of page or frame</td>
|
344 |
+
</tr>
|
345 |
+
<tr>
|
346 |
+
<td><span class="new_code">getAuthentication()</span></td>
|
347 |
+
<td>Authentication type in 401 challenge header</td>
|
348 |
+
</tr>
|
349 |
+
<tr>
|
350 |
+
<td><span class="new_code">getRealm()</span></td>
|
351 |
+
<td>Authentication realm in 401 challenge header</td>
|
352 |
+
</tr>
|
353 |
+
<tr>
|
354 |
+
<td><span class="new_code">getBaseUrl()</span></td>
|
355 |
+
<td>Base url only of most recent page fetched</td>
|
356 |
+
</tr>
|
357 |
+
<tr>
|
358 |
+
<td><span class="new_code">setMaximumRedirects($max)</span></td>
|
359 |
+
<td>Number of redirects before page is loaded anyway</td>
|
360 |
+
</tr>
|
361 |
+
<tr>
|
362 |
+
<td><span class="new_code">setMaximumNestedFrames($max)</span></td>
|
363 |
+
<td>Protection against recursive framesets</td>
|
364 |
+
</tr>
|
365 |
+
<tr>
|
366 |
+
<td><span class="new_code">ignoreFrames()</span></td>
|
367 |
+
<td>Disables frames support</td>
|
368 |
+
</tr>
|
369 |
+
<tr>
|
370 |
+
<td><span class="new_code">useFrames()</span></td>
|
371 |
+
<td>Enables frames support</td>
|
372 |
+
</tr>
|
373 |
+
<tr>
|
374 |
+
<td><span class="new_code">ignoreCookies()</span></td>
|
375 |
+
<td>Disables sending and receiving of cookies</td>
|
376 |
+
</tr>
|
377 |
+
<tr>
|
378 |
+
<td><span class="new_code">useCookies()</span></td>
|
379 |
+
<td>Enables cookie support</td>
|
380 |
+
</tr>
|
381 |
+
</tbody></table>
|
382 |
+
The methods <span class="new_code">SimpleBrowser::setConnectionTimeout()</span>
|
383 |
+
<span class="new_code">SimpleBrowser::setMaximumRedirects()</span>,
|
384 |
+
<span class="new_code">SimpleBrowser::setMaximumNestedFrames()</span>,
|
385 |
+
<span class="new_code">SimpleBrowser::ignoreFrames()</span>,
|
386 |
+
<span class="new_code">SimpleBrowser::useFrames()</span>,
|
387 |
+
<span class="new_code">SimpleBrowser::ignoreCookies()</span> and
|
388 |
+
<span class="new_code">SimpleBrowser::useCokies()</span> continue to apply
|
389 |
+
to every subsequent request.
|
390 |
+
The other methods are frames aware.
|
391 |
+
This means that if you have an individual frame that is not
|
392 |
+
loading, navigate to it using <span class="new_code">SimpleBrowser::setFrameFocus()</span>
|
393 |
+
and you can then use <span class="new_code">SimpleBrowser::getRequest()</span>, etc to
|
394 |
+
see what happened.
|
395 |
+
</p>
|
396 |
+
|
397 |
+
<h2>
|
398 |
+
<a class="target" name="unit"></a>Complex unit tests with multiple browsers</h2>
|
399 |
+
<p>
|
400 |
+
Anything that could be done in a
|
401 |
+
<a href="web_tester_documentation.html">WebTestCase</a> can
|
402 |
+
now be done in a <a href="unit_tester_documentation.html">UnitTestCase</a>.
|
403 |
+
This means that we could freely mix domain object testing with the
|
404 |
+
web interface...
|
405 |
+
<pre>
|
406 |
+
<strong>class TestOfRegistration extends UnitTestCase {
|
407 |
+
function testNewUserAddedToAuthenticator() {</strong>
|
408 |
+
$browser = new SimpleBrowser();
|
409 |
+
$browser->get('http://my-site.com/register.php');
|
410 |
+
$browser->setField('email', 'me@here');
|
411 |
+
$browser->setField('password', 'Secret');
|
412 |
+
$browser->click('Register');
|
413 |
+
<strong>
|
414 |
+
$authenticator = new Authenticator();
|
415 |
+
$member = $authenticator->findByEmail('me@here');
|
416 |
+
$this->assertEqual($member->getPassword(), 'Secret');
|
417 |
+
}
|
418 |
+
}</strong>
|
419 |
+
</pre>
|
420 |
+
While this may be a useful temporary expediency, I am not a fan
|
421 |
+
of this type of testing.
|
422 |
+
The testing has cut across application layers, make it twice as
|
423 |
+
likely it will need refactoring when the code changes.
|
424 |
+
</p>
|
425 |
+
<p>
|
426 |
+
A more useful case of where using the browser directly can be helpful
|
427 |
+
is where the <span class="new_code">WebTestCase</span> cannot cope.
|
428 |
+
An example is where two browsers are needed at the same time.
|
429 |
+
</p>
|
430 |
+
<p>
|
431 |
+
For example, say we want to disallow multiple simultaneous
|
432 |
+
usage of a site with the same username.
|
433 |
+
This test case will do the job...
|
434 |
+
<pre>
|
435 |
+
class TestOfSecurity extends UnitTestCase {
|
436 |
+
function testNoMultipleLoginsFromSameUser() {<strong>
|
437 |
+
$first_attempt = new SimpleBrowser();
|
438 |
+
$first_attempt->get('http://my-site.com/login.php');
|
439 |
+
$first_attempt->setField('name', 'Me');
|
440 |
+
$first_attempt->setField('password', 'Secret');
|
441 |
+
$first_attempt->click('Enter');
|
442 |
+
$this->assertEqual($first_attempt->getTitle(), 'Welcome');
|
443 |
+
|
444 |
+
$second_attempt = new SimpleBrowser();
|
445 |
+
$second_attempt->get('http://my-site.com/login.php');
|
446 |
+
$second_attempt->setField('name', 'Me');
|
447 |
+
$second_attempt->setField('password', 'Secret');
|
448 |
+
$second_attempt->click('Enter');
|
449 |
+
$this->assertEqual($second_attempt->getTitle(), 'Access Denied');</strong>
|
450 |
+
}
|
451 |
+
}
|
452 |
+
</pre>
|
453 |
+
You can also use the <span class="new_code">SimpleBrowser</span> class
|
454 |
+
directly when you want to write test cases using a different
|
455 |
+
test tool than SimpleTest, such as PHPUnit.
|
456 |
+
</p>
|
457 |
+
|
458 |
+
</div>
|
459 |
+
References and related information...
|
460 |
+
<ul>
|
461 |
+
<li>
|
462 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
463 |
+
</li>
|
464 |
+
<li>
|
465 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
466 |
+
</li>
|
467 |
+
<li>
|
468 |
+
The <a href="http://simpletest.org/api/">developer's API for SimpleTest</a>
|
469 |
+
gives full detail on the classes and assertions available.
|
470 |
+
</li>
|
471 |
+
</ul>
|
472 |
+
<div class="menu_back"><div class="menu">
|
473 |
+
<a href="index.html">SimpleTest</a>
|
474 |
+
|
|
475 |
+
<a href="overview.html">Overview</a>
|
476 |
+
|
|
477 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
478 |
+
|
|
479 |
+
<a href="group_test_documentation.html">Group tests</a>
|
480 |
+
|
|
481 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
482 |
+
|
|
483 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
484 |
+
|
|
485 |
+
<a href="reporter_documentation.html">Reporting</a>
|
486 |
+
|
|
487 |
+
<a href="expectation_documentation.html">Expectations</a>
|
488 |
+
|
|
489 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
490 |
+
|
|
491 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
492 |
+
|
|
493 |
+
<a href="authentication_documentation.html">Authentication</a>
|
494 |
+
|
|
495 |
+
<span class="chosen">Scriptable browser</span>
|
496 |
+
</div></div>
|
497 |
+
<div class="copyright">
|
498 |
+
Copyright<br>Marcus Baker 2006
|
499 |
+
</div>
|
500 |
+
</body>
|
501 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/docs.css
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
padding-left: 3%;
|
3 |
+
padding-right: 3%;
|
4 |
+
}
|
5 |
+
h1, h2, h3 {
|
6 |
+
font-family: sans-serif;
|
7 |
+
}
|
8 |
+
h1 {
|
9 |
+
text-align: center;
|
10 |
+
}
|
11 |
+
pre {
|
12 |
+
font-family: "courier new", courier, typewriter, monospace;
|
13 |
+
font-size: 90%;
|
14 |
+
border: 1px solid;
|
15 |
+
border-color: #999966;
|
16 |
+
background-color: #ffffcc;
|
17 |
+
padding: 5px;
|
18 |
+
margin-left: 20px;
|
19 |
+
margin-right: 40px;
|
20 |
+
}
|
21 |
+
.code, .new_code, pre.new_code {
|
22 |
+
font-family: "courier new", courier, typewriter, monospace;
|
23 |
+
font-weight: bold;
|
24 |
+
}
|
25 |
+
div.copyright {
|
26 |
+
font-size: 80%;
|
27 |
+
color: gray;
|
28 |
+
}
|
29 |
+
div.copyright a {
|
30 |
+
margin-top: 1em;
|
31 |
+
color: gray;
|
32 |
+
}
|
33 |
+
ul.api {
|
34 |
+
border: 2px outset;
|
35 |
+
border-color: gray;
|
36 |
+
background-color: white;
|
37 |
+
margin: 5px;
|
38 |
+
margin-left: 5%;
|
39 |
+
margin-right: 5%;
|
40 |
+
}
|
41 |
+
ul.api li {
|
42 |
+
margin-top: 0.2em;
|
43 |
+
margin-bottom: 0.2em;
|
44 |
+
list-style: none;
|
45 |
+
text-indent: -3em;
|
46 |
+
padding-left: 1em;
|
47 |
+
}
|
48 |
+
div.demo {
|
49 |
+
border: 4px ridge;
|
50 |
+
border-color: gray;
|
51 |
+
padding: 10px;
|
52 |
+
margin: 5px;
|
53 |
+
margin-left: 20px;
|
54 |
+
margin-right: 40px;
|
55 |
+
background-color: white;
|
56 |
+
}
|
57 |
+
div.demo span.fail {
|
58 |
+
color: red;
|
59 |
+
}
|
60 |
+
div.demo span.pass {
|
61 |
+
color: green;
|
62 |
+
}
|
63 |
+
div.demo h1 {
|
64 |
+
font-size: 12pt;
|
65 |
+
text-align: left;
|
66 |
+
font-weight: bold;
|
67 |
+
}
|
68 |
+
div.menu {
|
69 |
+
text-align: center;
|
70 |
+
}
|
71 |
+
table {
|
72 |
+
border: 2px outset;
|
73 |
+
border-color: gray;
|
74 |
+
background-color: white;
|
75 |
+
margin: 5px;
|
76 |
+
margin-left: 5%;
|
77 |
+
margin-right: 5%;
|
78 |
+
}
|
79 |
+
td {
|
80 |
+
font-size: 90%;
|
81 |
+
}
|
82 |
+
.shell {
|
83 |
+
color: white;
|
84 |
+
}
|
85 |
+
pre.shell {
|
86 |
+
border: 4px ridge;
|
87 |
+
border-color: gray;
|
88 |
+
padding: 10px;
|
89 |
+
margin: 5px;
|
90 |
+
margin-left: 20px;
|
91 |
+
margin-right: 40px;
|
92 |
+
background-color: #000100;
|
93 |
+
color: #99ff99;
|
94 |
+
font-size: 90%;
|
95 |
+
}
|
96 |
+
pre.file {
|
97 |
+
color: black;
|
98 |
+
border: 1px solid;
|
99 |
+
border-color: black;
|
100 |
+
padding: 10px;
|
101 |
+
margin: 5px;
|
102 |
+
margin-left: 20px;
|
103 |
+
margin-right: 40px;
|
104 |
+
background-color: white;
|
105 |
+
font-size: 90%;
|
106 |
+
}
|
107 |
+
form.demo {
|
108 |
+
background-color: lightgray;
|
109 |
+
border: 4px outset;
|
110 |
+
border-color: lightgray;
|
111 |
+
padding: 10px;
|
112 |
+
margin-right: 40%;
|
113 |
+
}
|
114 |
+
dl, dd {
|
115 |
+
margin: 10px;
|
116 |
+
margin-left: 30px;
|
117 |
+
}
|
118 |
+
em {
|
119 |
+
font-weight: bold;
|
120 |
+
font-family: "courier new", courier, typewriter, monospace;
|
121 |
+
}
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/expectation_documentation.html
ADDED
@@ -0,0 +1,476 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>
|
5 |
+
Extending the SimpleTest unit tester with additional expectation classes
|
6 |
+
</title>
|
7 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<div class="menu_back"><div class="menu">
|
11 |
+
<a href="index.html">SimpleTest</a>
|
12 |
+
|
|
13 |
+
<a href="overview.html">Overview</a>
|
14 |
+
|
|
15 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
16 |
+
|
|
17 |
+
<a href="group_test_documentation.html">Group tests</a>
|
18 |
+
|
|
19 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
20 |
+
|
|
21 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
22 |
+
|
|
23 |
+
<a href="reporter_documentation.html">Reporting</a>
|
24 |
+
|
|
25 |
+
<span class="chosen">Expectations</span>
|
26 |
+
|
|
27 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
28 |
+
|
|
29 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
30 |
+
|
|
31 |
+
<a href="authentication_documentation.html">Authentication</a>
|
32 |
+
|
|
33 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
34 |
+
</div></div>
|
35 |
+
<h1>Expectation documentation</h1>
|
36 |
+
This page...
|
37 |
+
<ul>
|
38 |
+
<li>
|
39 |
+
Using expectations for
|
40 |
+
<a href="#mock">more precise testing with mock objects</a>
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
<a href="#behaviour">Changing mock object behaviour</a> with expectations
|
44 |
+
</li>
|
45 |
+
<li>
|
46 |
+
<a href="#extending">Extending the expectations</a>
|
47 |
+
</li>
|
48 |
+
<li>
|
49 |
+
Underneath SimpleTest <a href="#unit">uses expectation classes</a>
|
50 |
+
</li>
|
51 |
+
</ul>
|
52 |
+
<div class="content">
|
53 |
+
<h2>
|
54 |
+
<a class="target" name="mock"></a>More control over mock objects</h2>
|
55 |
+
<p>
|
56 |
+
The default behaviour of the
|
57 |
+
<a href="mock_objects_documentation.html">mock objects</a>
|
58 |
+
in
|
59 |
+
<a href="http://sourceforge.net/projects/simpletest/">SimpleTest</a>
|
60 |
+
is either an identical match on the argument or to allow any argument at all.
|
61 |
+
For almost all tests this is sufficient.
|
62 |
+
Sometimes, though, you want to weaken a test case.
|
63 |
+
</p>
|
64 |
+
<p>
|
65 |
+
One place where a test can be too tightly coupled is with
|
66 |
+
text matching.
|
67 |
+
Suppose we have a component that outputs a helpful error
|
68 |
+
message when something goes wrong.
|
69 |
+
You want to test that the correct error was sent, but the actual
|
70 |
+
text may be rather long.
|
71 |
+
If you test for the text exactly, then every time the exact wording
|
72 |
+
of the message changes, you will have to go back and edit the test suite.
|
73 |
+
</p>
|
74 |
+
<p>
|
75 |
+
For example, suppose we have a news service that has failed
|
76 |
+
to connect to its remote source.
|
77 |
+
<pre>
|
78 |
+
<strong>class NewsService {
|
79 |
+
...
|
80 |
+
function publish($writer) {
|
81 |
+
if (! $this->isConnected()) {
|
82 |
+
$writer->write('Cannot connect to news service "' .
|
83 |
+
$this->_name . '" at this time. ' .
|
84 |
+
'Please try again later.');
|
85 |
+
}
|
86 |
+
...
|
87 |
+
}
|
88 |
+
}</strong>
|
89 |
+
</pre>
|
90 |
+
Here it is sending its content to a
|
91 |
+
<span class="new_code">Writer</span> class.
|
92 |
+
We could test this behaviour with a
|
93 |
+
<span class="new_code">MockWriter</span> like so...
|
94 |
+
<pre>
|
95 |
+
class TestOfNewsService extends UnitTestCase {
|
96 |
+
...
|
97 |
+
function testConnectionFailure() {<strong>
|
98 |
+
$writer = new MockWriter();
|
99 |
+
$writer->expectOnce('write', array(
|
100 |
+
'Cannot connect to news service ' .
|
101 |
+
'"BBC News" at this time. ' .
|
102 |
+
'Please try again later.'));
|
103 |
+
|
104 |
+
$service = new NewsService('BBC News');
|
105 |
+
$service->publish($writer);</strong>
|
106 |
+
}
|
107 |
+
}
|
108 |
+
</pre>
|
109 |
+
This is a good example of a brittle test.
|
110 |
+
If we decide to add additional instructions, such as
|
111 |
+
suggesting an alternative news source, we will break
|
112 |
+
our tests even though no underlying functionality
|
113 |
+
has been altered.
|
114 |
+
</p>
|
115 |
+
<p>
|
116 |
+
To get around this, we would like to do a regular expression
|
117 |
+
test rather than an exact match.
|
118 |
+
We can actually do this with...
|
119 |
+
<pre>
|
120 |
+
class TestOfNewsService extends UnitTestCase {
|
121 |
+
...
|
122 |
+
function testConnectionFailure() {
|
123 |
+
$writer = new MockWriter();<strong>
|
124 |
+
$writer->expectOnce(
|
125 |
+
'write',
|
126 |
+
array(new PatternExpectation('/cannot connect/i')));</strong>
|
127 |
+
|
128 |
+
$service = new NewsService('BBC News');
|
129 |
+
$service->publish($writer);
|
130 |
+
}
|
131 |
+
}
|
132 |
+
</pre>
|
133 |
+
Instead of passing in the expected parameter to the
|
134 |
+
<span class="new_code">MockWriter</span> we pass an
|
135 |
+
expectation class called
|
136 |
+
<span class="new_code">PatternExpectation</span>.
|
137 |
+
The mock object is smart enough to recognise this as special
|
138 |
+
and to treat it differently.
|
139 |
+
Rather than simply comparing the incoming argument to this
|
140 |
+
object, it uses the expectation object itself to
|
141 |
+
perform the test.
|
142 |
+
</p>
|
143 |
+
<p>
|
144 |
+
The <span class="new_code">PatternExpectation</span> takes
|
145 |
+
the regular expression to match in its constructor.
|
146 |
+
Whenever a comparison is made by the <span class="new_code">MockWriter</span>
|
147 |
+
against this expectation class, it will do a
|
148 |
+
<span class="new_code">preg_match()</span> with this pattern.
|
149 |
+
With our test case above, as long as "cannot connect"
|
150 |
+
appears in the text of the string, the mock will issue a pass
|
151 |
+
to the unit tester.
|
152 |
+
The rest of the text does not matter.
|
153 |
+
</p>
|
154 |
+
<p>
|
155 |
+
The possible expectation classes are...
|
156 |
+
<table><tbody>
|
157 |
+
<tr>
|
158 |
+
<td><span class="new_code">AnythingExpectation</span></td>
|
159 |
+
<td>Will always match</td>
|
160 |
+
</tr>
|
161 |
+
<tr>
|
162 |
+
<td><span class="new_code">EqualExpectation</span></td>
|
163 |
+
<td>An equality, rather than the stronger identity comparison</td>
|
164 |
+
</tr>
|
165 |
+
<tr>
|
166 |
+
<td><span class="new_code">NotEqualExpectation</span></td>
|
167 |
+
<td>An inequality comparison</td>
|
168 |
+
</tr>
|
169 |
+
<tr>
|
170 |
+
<td><span class="new_code">IndenticalExpectation</span></td>
|
171 |
+
<td>The default mock object check which must match exactly</td>
|
172 |
+
</tr>
|
173 |
+
<tr>
|
174 |
+
<td><span class="new_code">NotIndenticalExpectation</span></td>
|
175 |
+
<td>Inverts the mock object logic</td>
|
176 |
+
</tr>
|
177 |
+
<tr>
|
178 |
+
<td><span class="new_code">WithinMarginExpectation</span></td>
|
179 |
+
<td>Compares a value to within a margin</td>
|
180 |
+
</tr>
|
181 |
+
<tr>
|
182 |
+
<td><span class="new_code">OutsideMarginExpectation</span></td>
|
183 |
+
<td>Checks that a value is out side the margin</td>
|
184 |
+
</tr>
|
185 |
+
<tr>
|
186 |
+
<td><span class="new_code">PatternExpectation</span></td>
|
187 |
+
<td>Uses a Perl Regex to match a string</td>
|
188 |
+
</tr>
|
189 |
+
<tr>
|
190 |
+
<td><span class="new_code">NoPatternExpectation</span></td>
|
191 |
+
<td>Passes only if failing a Perl Regex</td>
|
192 |
+
</tr>
|
193 |
+
<tr>
|
194 |
+
<td><span class="new_code">IsAExpectation</span></td>
|
195 |
+
<td>Checks the type or class name only</td>
|
196 |
+
</tr>
|
197 |
+
<tr>
|
198 |
+
<td><span class="new_code">NotAExpectation</span></td>
|
199 |
+
<td>Opposite of the <span class="new_code">IsAExpectation</span>
|
200 |
+
</td>
|
201 |
+
</tr>
|
202 |
+
<tr>
|
203 |
+
<td><span class="new_code">MethodExistsExpectation</span></td>
|
204 |
+
<td>Checks a method is available on an object</td>
|
205 |
+
</tr>
|
206 |
+
<tr>
|
207 |
+
<td><span class="new_code">TrueExpectation</span></td>
|
208 |
+
<td>Accepts any PHP variable that evaluates to true</td>
|
209 |
+
</tr>
|
210 |
+
<tr>
|
211 |
+
<td><span class="new_code">FalseExpectation</span></td>
|
212 |
+
<td>Accepts any PHP variable that evaluates to false</td>
|
213 |
+
</tr>
|
214 |
+
</tbody></table>
|
215 |
+
Most take the expected value in the constructor.
|
216 |
+
The exceptions are the pattern matchers, which take a regular expression,
|
217 |
+
and the <span class="new_code">IsAExpectation</span> and <span class="new_code">NotAExpectation</span> which takes a type
|
218 |
+
or class name as a string.
|
219 |
+
</p>
|
220 |
+
<p>
|
221 |
+
Some examples...
|
222 |
+
</p>
|
223 |
+
<p>
|
224 |
+
<pre>
|
225 |
+
$mock->expectOnce('method', array(new IdenticalExpectation(14)));
|
226 |
+
</pre>
|
227 |
+
This is the same as <span class="new_code">$mock->expectOnce('method', array(14))</span>.
|
228 |
+
<pre>
|
229 |
+
$mock->expectOnce('method', array(new EqualExpectation(14)));
|
230 |
+
</pre>
|
231 |
+
This is different from the previous version in that the string
|
232 |
+
<span class="new_code">"14"</span> as a parameter will also pass.
|
233 |
+
Sometimes the additional type checks of SimpleTest are too restrictive.
|
234 |
+
<pre>
|
235 |
+
$mock->expectOnce('method', array(new AnythingExpectation(14)));
|
236 |
+
</pre>
|
237 |
+
This is the same as <span class="new_code">$mock->expectOnce('method', array('*'))</span>.
|
238 |
+
<pre>
|
239 |
+
$mock->expectOnce('method', array(new IdenticalExpectation('*')));
|
240 |
+
</pre>
|
241 |
+
This is handy if you want to assert a literal <span class="new_code">"*"</span>.
|
242 |
+
<pre>
|
243 |
+
new NotIdenticalExpectation(14)
|
244 |
+
</pre>
|
245 |
+
This matches on anything other than integer 14.
|
246 |
+
Even the string <span class="new_code">"14"</span> would pass.
|
247 |
+
<pre>
|
248 |
+
new WithinMarginExpectation(14.0, 0.001)
|
249 |
+
</pre>
|
250 |
+
This will accept any value from 13.999 to 14.001 inclusive.
|
251 |
+
</p>
|
252 |
+
|
253 |
+
<h2>
|
254 |
+
<a class="target" name="behaviour"></a>Using expectations to control stubs</h2>
|
255 |
+
<p>
|
256 |
+
The expectation classes can be used not just for sending assertions
|
257 |
+
from mock objects, but also for selecting behaviour for the
|
258 |
+
<a href="mock_objects_documentation.html">mock objects</a>.
|
259 |
+
Anywhere a list of arguments is given, a list of expectation objects
|
260 |
+
can be inserted instead.
|
261 |
+
</p>
|
262 |
+
<p>
|
263 |
+
Suppose we want a mock authorisation server to simulate a successful login,
|
264 |
+
but only if it receives a valid session object.
|
265 |
+
We can do this as follows...
|
266 |
+
<pre>
|
267 |
+
Mock::generate('Authorisation');
|
268 |
+
<strong>
|
269 |
+
$authorisation = new MockAuthorisation();
|
270 |
+
$authorisation->returns(
|
271 |
+
'isAllowed',
|
272 |
+
true,
|
273 |
+
array(new IsAExpectation('Session', 'Must be a session')));
|
274 |
+
$authorisation->returns('isAllowed', false);</strong>
|
275 |
+
</pre>
|
276 |
+
We have set the default mock behaviour to return false when
|
277 |
+
<span class="new_code">isAllowed</span> is called.
|
278 |
+
When we call the method with a single parameter that
|
279 |
+
is a <span class="new_code">Session</span> object, it will return true.
|
280 |
+
We have also added a second parameter as a message.
|
281 |
+
This will be displayed as part of the mock object
|
282 |
+
failure message if this expectation is the cause of
|
283 |
+
a failure.
|
284 |
+
</p>
|
285 |
+
<p>
|
286 |
+
This kind of sophistication is rarely useful, but is included for
|
287 |
+
completeness.
|
288 |
+
</p>
|
289 |
+
|
290 |
+
<h2>
|
291 |
+
<a class="target" name="extending"></a>Creating your own expectations</h2>
|
292 |
+
<p>
|
293 |
+
The expectation classes have a very simple structure.
|
294 |
+
So simple that it is easy to create your own versions for
|
295 |
+
commonly used test logic.
|
296 |
+
</p>
|
297 |
+
<p>
|
298 |
+
As an example here is the creation of a class to test for
|
299 |
+
valid IP addresses.
|
300 |
+
In order to work correctly with the stubs and mocks the new
|
301 |
+
expectation class should extend
|
302 |
+
<span class="new_code">SimpleExpectation</span> or further extend a subclass...
|
303 |
+
<pre>
|
304 |
+
<strong>class ValidIp extends SimpleExpectation {
|
305 |
+
|
306 |
+
function test($ip) {
|
307 |
+
return (ip2long($ip) != -1);
|
308 |
+
}
|
309 |
+
|
310 |
+
function testMessage($ip) {
|
311 |
+
return "Address [$ip] should be a valid IP address";
|
312 |
+
}
|
313 |
+
}</strong>
|
314 |
+
</pre>
|
315 |
+
There are only two methods to implement.
|
316 |
+
The <span class="new_code">test()</span> method should
|
317 |
+
evaluate to true if the expectation is to pass, and
|
318 |
+
false otherwise.
|
319 |
+
The <span class="new_code">testMessage()</span> method
|
320 |
+
should simply return some helpful text explaining the test
|
321 |
+
that was carried out.
|
322 |
+
</p>
|
323 |
+
<p>
|
324 |
+
This class can now be used in place of the earlier expectation
|
325 |
+
classes.
|
326 |
+
</p>
|
327 |
+
<p>
|
328 |
+
Here is a more typical example, matching part of a hash...
|
329 |
+
<pre>
|
330 |
+
<strong>class JustField extends EqualExpectation {
|
331 |
+
private $key;
|
332 |
+
|
333 |
+
function __construct($key, $expected) {
|
334 |
+
parent::__construct($expected);
|
335 |
+
$this->key = $key;
|
336 |
+
}
|
337 |
+
|
338 |
+
function test($compare) {
|
339 |
+
if (! isset($compare[$this->key])) {
|
340 |
+
return false;
|
341 |
+
}
|
342 |
+
return parent::test($compare[$this->key]);
|
343 |
+
}
|
344 |
+
|
345 |
+
function testMessage($compare) {
|
346 |
+
if (! isset($compare[$this->key])) {
|
347 |
+
return 'Key [' . $this->key . '] does not exist';
|
348 |
+
}
|
349 |
+
return 'Key [' . $this->key . '] -> ' .
|
350 |
+
parent::testMessage($compare[$this->key]);
|
351 |
+
}
|
352 |
+
}</strong>
|
353 |
+
</pre>
|
354 |
+
We tend to seperate message clauses with
|
355 |
+
"&nbsp;->&nbsp;".
|
356 |
+
This allows derivative tools to reformat the output.
|
357 |
+
</p>
|
358 |
+
<p>
|
359 |
+
Suppose some authenticator is expecting to be given
|
360 |
+
a database row corresponding to the user, and we
|
361 |
+
only need to confirm the username is correct.
|
362 |
+
We can assert just their username with...
|
363 |
+
<pre>
|
364 |
+
$mock->expectOnce('authenticate',
|
365 |
+
array(new JustKey('username', 'marcus')));
|
366 |
+
</pre>
|
367 |
+
</p>
|
368 |
+
|
369 |
+
<h2>
|
370 |
+
<a class="target" name="unit"></a>Under the bonnet of the unit tester</h2>
|
371 |
+
<p>
|
372 |
+
The <a href="http://sourceforge.net/projects/simpletest/">SimpleTest unit testing framework</a>
|
373 |
+
also uses the expectation classes internally for the
|
374 |
+
<a href="unit_test_documentation.html">UnitTestCase class</a>.
|
375 |
+
We can also take advantage of these mechanisms to reuse our
|
376 |
+
homebrew expectation classes within the test suites directly.
|
377 |
+
</p>
|
378 |
+
<p>
|
379 |
+
The most crude way of doing this is to use the generic
|
380 |
+
<span class="new_code">SimpleTest::assert()</span> method to
|
381 |
+
test against it directly...
|
382 |
+
<pre>
|
383 |
+
<strong>class TestOfNetworking extends UnitTestCase {
|
384 |
+
...
|
385 |
+
function testGetValidIp() {
|
386 |
+
$server = &new Server();
|
387 |
+
$this->assert(
|
388 |
+
new ValidIp(),
|
389 |
+
$server->getIp(),
|
390 |
+
'Server IP address->%s');
|
391 |
+
}
|
392 |
+
}</strong>
|
393 |
+
</pre>
|
394 |
+
<span class="new_code">assert()</span> will test any expectation class directly.
|
395 |
+
</p>
|
396 |
+
<p>
|
397 |
+
This is a little untidy compared with our usual
|
398 |
+
<span class="new_code">assert...()</span> syntax.
|
399 |
+
</p>
|
400 |
+
<p>
|
401 |
+
For such a simple case we would normally create a
|
402 |
+
separate assertion method on our test case rather
|
403 |
+
than bother using the expectation class.
|
404 |
+
If we pretend that our expectation is a little more
|
405 |
+
complicated for a moment, so that we want to reuse it,
|
406 |
+
we get...
|
407 |
+
<pre>
|
408 |
+
class TestOfNetworking extends UnitTestCase {
|
409 |
+
...<strong>
|
410 |
+
function assertValidIp($ip, $message = '%s') {
|
411 |
+
$this->assert(new ValidIp(), $ip, $message);
|
412 |
+
}</strong>
|
413 |
+
|
414 |
+
function testGetValidIp() {
|
415 |
+
$server = &new Server();<strong>
|
416 |
+
$this->assertValidIp(
|
417 |
+
$server->getIp(),
|
418 |
+
'Server IP address->%s');</strong>
|
419 |
+
}
|
420 |
+
}
|
421 |
+
</pre>
|
422 |
+
It is rare to need the expectations for more than pattern
|
423 |
+
matching, but these facilities do allow testers to build
|
424 |
+
some sort of domain language for testing their application.
|
425 |
+
Also, complex expectation classes could make the tests
|
426 |
+
harder to read and debug.
|
427 |
+
In effect extending the test framework to create their own tool set.
|
428 |
+
</p>
|
429 |
+
|
430 |
+
</div>
|
431 |
+
References and related information...
|
432 |
+
<ul>
|
433 |
+
<li>
|
434 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
435 |
+
</li>
|
436 |
+
<li>
|
437 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
438 |
+
</li>
|
439 |
+
<li>
|
440 |
+
The expectations mimic the constraints in <a href="http://www.jmock.org/">JMock</a>.
|
441 |
+
</li>
|
442 |
+
<li>
|
443 |
+
<a href="http://simpletest.org/api/">Full API for SimpleTest</a>
|
444 |
+
from the PHPDoc.
|
445 |
+
</li>
|
446 |
+
</ul>
|
447 |
+
<div class="menu_back"><div class="menu">
|
448 |
+
<a href="index.html">SimpleTest</a>
|
449 |
+
|
|
450 |
+
<a href="overview.html">Overview</a>
|
451 |
+
|
|
452 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
453 |
+
|
|
454 |
+
<a href="group_test_documentation.html">Group tests</a>
|
455 |
+
|
|
456 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
457 |
+
|
|
458 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
459 |
+
|
|
460 |
+
<a href="reporter_documentation.html">Reporting</a>
|
461 |
+
|
|
462 |
+
<span class="chosen">Expectations</span>
|
463 |
+
|
|
464 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
465 |
+
|
|
466 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
467 |
+
|
|
468 |
+
<a href="authentication_documentation.html">Authentication</a>
|
469 |
+
|
|
470 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
471 |
+
</div></div>
|
472 |
+
<div class="copyright">
|
473 |
+
Copyright<br>Marcus Baker 2006
|
474 |
+
</div>
|
475 |
+
</body>
|
476 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/form_testing_documentation.html
ADDED
@@ -0,0 +1,351 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest documentation for testing HTML forms</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<span class="chosen">Testing forms</span>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Form testing documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
Changing form values and successfully
|
38 |
+
<a href="#submit">Submitting a simple form</a>
|
39 |
+
</li>
|
40 |
+
<li>
|
41 |
+
Handling <a href="#multiple">widgets with multiple values</a>
|
42 |
+
by setting lists.
|
43 |
+
</li>
|
44 |
+
<li>
|
45 |
+
Bypassing javascript to <a href="#hidden-field">set a hidden field</a>.
|
46 |
+
</li>
|
47 |
+
<li>
|
48 |
+
<a href="#raw">Raw posting</a> when you don't have a button
|
49 |
+
to click.
|
50 |
+
</li>
|
51 |
+
</ul>
|
52 |
+
<div class="content">
|
53 |
+
<h2>
|
54 |
+
<a class="target" name="submit"></a>Submitting a simple form</h2>
|
55 |
+
<p>
|
56 |
+
When a page is fetched by the <span class="new_code">WebTestCase</span>
|
57 |
+
using <span class="new_code">get()</span> or
|
58 |
+
<span class="new_code">post()</span> the page content is
|
59 |
+
automatically parsed.
|
60 |
+
This results in any form controls that are inside <form> tags
|
61 |
+
being available from within the test case.
|
62 |
+
For example, if we have this snippet of HTML...
|
63 |
+
<pre>
|
64 |
+
<form>
|
65 |
+
<input type="text" name="a" value="A default" />
|
66 |
+
<input type="submit" value="Go" />
|
67 |
+
</form>
|
68 |
+
</pre>
|
69 |
+
Which looks like this...
|
70 |
+
</p>
|
71 |
+
<p>
|
72 |
+
<form class="demo">
|
73 |
+
<input type="text" name="a" value="A default">
|
74 |
+
<input type="submit" value="Go">
|
75 |
+
</form>
|
76 |
+
</p>
|
77 |
+
<p>
|
78 |
+
We can navigate to this code, via the
|
79 |
+
<a href="http://www.lastcraft.com/form_testing_documentation.php">LastCraft</a>
|
80 |
+
site, with the following test...
|
81 |
+
<pre>
|
82 |
+
class SimpleFormTests extends WebTestCase {<strong>
|
83 |
+
function testDefaultValue() {
|
84 |
+
$this->get('http://www.lastcraft.com/form_testing_documentation.php');
|
85 |
+
$this->assertField('a', 'A default');
|
86 |
+
}</strong>
|
87 |
+
}
|
88 |
+
</pre>
|
89 |
+
Immediately after loading the page all of the HTML controls are set at
|
90 |
+
their default values just as they would appear in the web browser.
|
91 |
+
The assertion tests that a HTML widget exists in the page with the
|
92 |
+
name "a" and that it is currently set to the value
|
93 |
+
"A default".
|
94 |
+
As usual, we could use a pattern expectation instead of a fixed
|
95 |
+
string.
|
96 |
+
<pre>
|
97 |
+
class SimpleFormTests extends WebTestCase {
|
98 |
+
function testDefaultValue() {
|
99 |
+
$this->get('http://www.lastcraft.com/form_testing_documentation.php');
|
100 |
+
$this->assertField('a', <strong>new PatternExpectation('/default/')</strong>);
|
101 |
+
}
|
102 |
+
}
|
103 |
+
</pre>
|
104 |
+
We could submit the form straight away, but first we'll change
|
105 |
+
the value of the text field and only then submit it...
|
106 |
+
<pre>
|
107 |
+
class SimpleFormTests extends WebTestCase {
|
108 |
+
function testDefaultValue() {
|
109 |
+
$this->get('http://www.my-site.com/');
|
110 |
+
$this->assertField('a', 'A default');<strong>
|
111 |
+
$this->setField('a', 'New value');
|
112 |
+
$this->click('Go');</strong>
|
113 |
+
}
|
114 |
+
}
|
115 |
+
</pre>
|
116 |
+
Because we didn't specify a method attribute on the form tag, and
|
117 |
+
didn't specify an action either, the test case will follow
|
118 |
+
the usual browser behaviour of submitting the form data as a <em>GET</em>
|
119 |
+
request back to the same location.
|
120 |
+
In general SimpleTest tries to emulate typical browser behaviour as much as possible,
|
121 |
+
rather than attempting to catch any form of HTML omission.
|
122 |
+
This is because the target of the testing framework is the PHP application
|
123 |
+
logic, not syntax or other errors in the HTML code.
|
124 |
+
For HTML errors, other tools such as
|
125 |
+
<a href="http://www.w3.org/People/Raggett/tidy/">HTMLTidy</a> should be used,
|
126 |
+
or any of the HTML and CSS validators already out there.
|
127 |
+
</p>
|
128 |
+
<p>
|
129 |
+
If a field is not present in any form, or if an option is unavailable,
|
130 |
+
then <span class="new_code">WebTestCase::setField()</span> will return
|
131 |
+
<span class="new_code">false</span>.
|
132 |
+
For example, suppose we wish to verify that a "Superuser"
|
133 |
+
option is not present in this form...
|
134 |
+
<pre>
|
135 |
+
<strong>Select type of user to add:</strong>
|
136 |
+
<select name="type">
|
137 |
+
<option>Subscriber</option>
|
138 |
+
<option>Author</option>
|
139 |
+
<option>Administrator</option>
|
140 |
+
</select>
|
141 |
+
</pre>
|
142 |
+
Which looks like...
|
143 |
+
</p>
|
144 |
+
<p>
|
145 |
+
<form class="demo">
|
146 |
+
<strong>Select type of user to add:</strong>
|
147 |
+
<select name="type">
|
148 |
+
<option>Subscriber</option>
|
149 |
+
<option>Author</option>
|
150 |
+
<option>Administrator</option>
|
151 |
+
</select>
|
152 |
+
</form>
|
153 |
+
</p>
|
154 |
+
<p>
|
155 |
+
The following test will confirm it...
|
156 |
+
<pre>
|
157 |
+
class SimpleFormTests extends WebTestCase {
|
158 |
+
...
|
159 |
+
function testNoSuperuserChoiceAvailable() {<strong>
|
160 |
+
$this->get('http://www.lastcraft.com/form_testing_documentation.php');
|
161 |
+
$this->assertFalse($this->setField('type', 'Superuser'));</strong>
|
162 |
+
}
|
163 |
+
}
|
164 |
+
</pre>
|
165 |
+
The current selection will not be changed if the new value is not an option.
|
166 |
+
</p>
|
167 |
+
<p>
|
168 |
+
Here is the full list of widgets currently supported...
|
169 |
+
<ul>
|
170 |
+
<li>Text fields, including hidden and password fields.</li>
|
171 |
+
<li>Submit buttons including the button tag, although not yet reset buttons</li>
|
172 |
+
<li>Text area. This includes text wrapping behaviour.</li>
|
173 |
+
<li>Checkboxes, including multiple checkboxes in the same form.</li>
|
174 |
+
<li>Drop down selections, including multiple selects.</li>
|
175 |
+
<li>Radio buttons.</li>
|
176 |
+
<li>Images.</li>
|
177 |
+
</ul>
|
178 |
+
</p>
|
179 |
+
<p>
|
180 |
+
The browser emulation offered by SimpleTest mimics
|
181 |
+
the actions which can be perform by a user on a
|
182 |
+
standard HTML page. Javascript is not supported, and
|
183 |
+
it's unlikely that support will be added any time
|
184 |
+
soon.
|
185 |
+
</p>
|
186 |
+
<p>
|
187 |
+
Of particular note is that the Javascript idiom of
|
188 |
+
passing form results by setting a hidden field cannot
|
189 |
+
be performed using the normal SimpleTest
|
190 |
+
commands. See below for a way to test such forms.
|
191 |
+
</p>
|
192 |
+
|
193 |
+
<h2>
|
194 |
+
<a class="target" name="multiple"></a>Fields with multiple values</h2>
|
195 |
+
<p>
|
196 |
+
SimpleTest can cope with two types of multivalue controls: Multiple
|
197 |
+
selection drop downs, and multiple checkboxes with the same name
|
198 |
+
within a form.
|
199 |
+
The multivalue nature of these means that setting and testing
|
200 |
+
are slightly different.
|
201 |
+
Using checkboxes as an example...
|
202 |
+
<pre>
|
203 |
+
<form class="demo">
|
204 |
+
<strong>Create privileges allowed:</strong>
|
205 |
+
<input type="checkbox" name="crud" value="c" checked><br>
|
206 |
+
<strong>Retrieve privileges allowed:</strong>
|
207 |
+
<input type="checkbox" name="crud" value="r" checked><br>
|
208 |
+
<strong>Update privileges allowed:</strong>
|
209 |
+
<input type="checkbox" name="crud" value="u" checked><br>
|
210 |
+
<strong>Destroy privileges allowed:</strong>
|
211 |
+
<input type="checkbox" name="crud" value="d" checked><br>
|
212 |
+
<input type="submit" value="Enable Privileges">
|
213 |
+
</form>
|
214 |
+
</pre>
|
215 |
+
Which renders as...
|
216 |
+
</p>
|
217 |
+
<p>
|
218 |
+
<form class="demo">
|
219 |
+
<strong>Create privileges allowed:</strong>
|
220 |
+
<input type="checkbox" name="crud" value="c" checked><br>
|
221 |
+
<strong>Retrieve privileges allowed:</strong>
|
222 |
+
<input type="checkbox" name="crud" value="r" checked><br>
|
223 |
+
<strong>Update privileges allowed:</strong>
|
224 |
+
<input type="checkbox" name="crud" value="u" checked><br>
|
225 |
+
<strong>Destroy privileges allowed:</strong>
|
226 |
+
<input type="checkbox" name="crud" value="d" checked><br>
|
227 |
+
<input type="submit" value="Enable Privileges">
|
228 |
+
</form>
|
229 |
+
</p>
|
230 |
+
<p>
|
231 |
+
If we wish to disable all but the retrieval privileges and
|
232 |
+
submit this information we can do it like this...
|
233 |
+
<pre>
|
234 |
+
class SimpleFormTests extends WebTestCase {
|
235 |
+
...<strong>
|
236 |
+
function testDisableNastyPrivileges() {
|
237 |
+
$this->get('http://www.lastcraft.com/form_testing_documentation.php');
|
238 |
+
$this->assertField('crud', array('c', 'r', 'u', 'd'));
|
239 |
+
$this->setField('crud', array('r'));
|
240 |
+
$this->click('Enable Privileges');
|
241 |
+
}</strong>
|
242 |
+
}
|
243 |
+
</pre>
|
244 |
+
Instead of setting the field to a single value, we give it a list
|
245 |
+
of values.
|
246 |
+
We do the same when testing expected values.
|
247 |
+
We can then write other test code to confirm the effect of this, perhaps
|
248 |
+
by logging in as that user and attempting an update.
|
249 |
+
</p>
|
250 |
+
|
251 |
+
<h2>
|
252 |
+
<a class="target" name="hidden-field"></a>Forms which use javascript to set a hidden field</h2>
|
253 |
+
<p>
|
254 |
+
If you want to test a form which relies on javascript to set a hidden
|
255 |
+
field, you can't just call setField().
|
256 |
+
The following code will <em>not</em> work:
|
257 |
+
<pre>
|
258 |
+
class SimpleFormTests extends WebTestCase {
|
259 |
+
function testEmulateMyJavascriptForm() {
|
260 |
+
<strong>// This does *not* work</strong>
|
261 |
+
$this->setField('a_hidden_field', '123');
|
262 |
+
$this->clickSubmit('OK');
|
263 |
+
}
|
264 |
+
}
|
265 |
+
</pre>
|
266 |
+
Instead, you need to pass the additional form parameters to the
|
267 |
+
clickSubmit() method:
|
268 |
+
<pre>
|
269 |
+
class SimpleFormTests extends WebTestCase {
|
270 |
+
function testMyJavascriptForm() {
|
271 |
+
<strong>$this->clickSubmit('OK', array('a_hidden_field'=>'123'));</strong>
|
272 |
+
}
|
273 |
+
|
274 |
+
}
|
275 |
+
</pre>
|
276 |
+
Bear in mind that in doing this you're effectively stubbing out a
|
277 |
+
part of your software (the javascript code in the form), and
|
278 |
+
perhaps you might be better off using something like
|
279 |
+
<a href="http://selenium.openqa.org/">Selenium</a> to ensure a complete
|
280 |
+
test.
|
281 |
+
</p>
|
282 |
+
|
283 |
+
<h2>
|
284 |
+
<a class="target" name="raw"></a>Raw posting</h2>
|
285 |
+
<p>
|
286 |
+
If you want to test a form handler, but have not yet written
|
287 |
+
or do not have access to the form itself, you can create a
|
288 |
+
form submission by hand.
|
289 |
+
<pre>
|
290 |
+
class SimpleFormTests extends WebTestCase {
|
291 |
+
...<strong>
|
292 |
+
function testAttemptedHack() {
|
293 |
+
$this->post(
|
294 |
+
'http://www.my-site.com/add_user.php',
|
295 |
+
array('type' => 'superuser'));
|
296 |
+
$this->assertNoText('user created');
|
297 |
+
}</strong>
|
298 |
+
}
|
299 |
+
</pre>
|
300 |
+
By adding data to the <span class="new_code">WebTestCase::post()</span>
|
301 |
+
method, we are emulating a form submission.
|
302 |
+
You would normally only do this as a temporary expedient, or where
|
303 |
+
you are expecting a 3rd party to submit to a form.
|
304 |
+
The exception is when you want tests to protect you from
|
305 |
+
attempts to spoof your pages.
|
306 |
+
</p>
|
307 |
+
|
308 |
+
</div>
|
309 |
+
References and related information...
|
310 |
+
<ul>
|
311 |
+
<li>
|
312 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
313 |
+
</li>
|
314 |
+
<li>
|
315 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
316 |
+
</li>
|
317 |
+
<li>
|
318 |
+
The <a href="http://simpletest.org/api/">developer's API for SimpleTest</a>
|
319 |
+
gives full detail on the classes and assertions available.
|
320 |
+
</li>
|
321 |
+
</ul>
|
322 |
+
<div class="menu_back"><div class="menu">
|
323 |
+
<a href="index.html">SimpleTest</a>
|
324 |
+
|
|
325 |
+
<a href="overview.html">Overview</a>
|
326 |
+
|
|
327 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
328 |
+
|
|
329 |
+
<a href="group_test_documentation.html">Group tests</a>
|
330 |
+
|
|
331 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
332 |
+
|
|
333 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
334 |
+
|
|
335 |
+
<a href="reporter_documentation.html">Reporting</a>
|
336 |
+
|
|
337 |
+
<a href="expectation_documentation.html">Expectations</a>
|
338 |
+
|
|
339 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
340 |
+
|
|
341 |
+
<span class="chosen">Testing forms</span>
|
342 |
+
|
|
343 |
+
<a href="authentication_documentation.html">Authentication</a>
|
344 |
+
|
|
345 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
346 |
+
</div></div>
|
347 |
+
<div class="copyright">
|
348 |
+
Copyright<br>Marcus Baker 2006
|
349 |
+
</div>
|
350 |
+
</body>
|
351 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/group_test_documentation.html
ADDED
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest for PHP test suites</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<span class="chosen">Group tests</span>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Test suite documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
Different ways to <a href="#group">group tests</a> together.
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
Combining group tests into <a href="#higher">larger groups</a>.
|
41 |
+
</li>
|
42 |
+
</ul>
|
43 |
+
<div class="content">
|
44 |
+
<h2>
|
45 |
+
<a class="target" name="group"></a>Grouping tests into suites</h2>
|
46 |
+
<p>
|
47 |
+
There are many ways to group tests together into test suites.
|
48 |
+
One way is to simply place multiple test cases into a single file...
|
49 |
+
<pre>
|
50 |
+
<strong><?php
|
51 |
+
require_once(dirname(__FILE__) . '/simpletest/autorun.php');
|
52 |
+
require_once(dirname(__FILE__) . '/../classes/io.php');
|
53 |
+
|
54 |
+
class FileTester extends UnitTestCase {
|
55 |
+
...
|
56 |
+
}
|
57 |
+
|
58 |
+
class SocketTester extends UnitTestCase {
|
59 |
+
...
|
60 |
+
}
|
61 |
+
?></strong>
|
62 |
+
</pre>
|
63 |
+
As many cases as needed can appear in a single file.
|
64 |
+
They should include any code they need, such as the library
|
65 |
+
being tested, but need none of the SimpleTest libraries.
|
66 |
+
</p>
|
67 |
+
<p>
|
68 |
+
Occasionally special subclasses are created that methods useful
|
69 |
+
for testing part of the application.
|
70 |
+
These new base classes are then used in place of <span class="new_code">UnitTestCase</span>
|
71 |
+
or <span class="new_code">WebTestCase</span>.
|
72 |
+
You don't normally want to run these as test cases.
|
73 |
+
Simply mark any base test cases that should not be run as abstract...
|
74 |
+
<pre>
|
75 |
+
<strong>abstract</strong> class MyFileTestCase extends UnitTestCase {
|
76 |
+
...
|
77 |
+
}
|
78 |
+
|
79 |
+
class FileTester extends MyFileTestCase { ... }
|
80 |
+
|
81 |
+
class SocketTester extends UnitTestCase { ... }
|
82 |
+
</pre>
|
83 |
+
Here the <span class="new_code">FileTester</span> class does
|
84 |
+
not contain any actual tests, but is the base class for other
|
85 |
+
test cases.
|
86 |
+
</p>
|
87 |
+
<p>
|
88 |
+
We will call this sample <em>file_test.php</em>.
|
89 |
+
Currently the test cases are grouped simply by being in the same file.
|
90 |
+
We can build larger constructs just by including other test files in.
|
91 |
+
<pre>
|
92 |
+
<?php
|
93 |
+
require_once('simpletest/autorun.php');
|
94 |
+
require_once('file_test.php');
|
95 |
+
?>
|
96 |
+
</pre>
|
97 |
+
This will work, but create a purely flat hierarchy.
|
98 |
+
INstead we create a test suite file.
|
99 |
+
Our top level test suite can look like this...
|
100 |
+
<pre>
|
101 |
+
<?php
|
102 |
+
require_once('simpletest/autorun.php');
|
103 |
+
|
104 |
+
class AllFileTests extends TestSuite {
|
105 |
+
function __construct() {
|
106 |
+
parent::__construct();
|
107 |
+
<strong>$this->addFile('file_test.php');</strong>
|
108 |
+
}
|
109 |
+
}
|
110 |
+
?>
|
111 |
+
</pre>
|
112 |
+
What happens here is that the <span class="new_code">TestSuite</span>
|
113 |
+
class will do the <span class="new_code">require_once()</span>
|
114 |
+
for us.
|
115 |
+
It then checks to see if any new test case classes
|
116 |
+
have been created by the new file and automatically composes
|
117 |
+
them to the test suite.
|
118 |
+
This method gives us the most control as we just manually add
|
119 |
+
more test files as our test suite grows.
|
120 |
+
</p>
|
121 |
+
<p>
|
122 |
+
If this is too much typing, and you are willing to group
|
123 |
+
test suites together in their own directories or otherwise
|
124 |
+
tag the file names, then there is a more automatic way...
|
125 |
+
<pre>
|
126 |
+
<?php
|
127 |
+
require_once('simpletest/autorun.php');
|
128 |
+
|
129 |
+
class AllFileTests extends TestSuite {
|
130 |
+
function __construct() {
|
131 |
+
parent::__construct();
|
132 |
+
$this->collect(dirname(__FILE__) . '/unit',
|
133 |
+
new SimplePatternCollector('/_test.php/'));
|
134 |
+
}
|
135 |
+
}
|
136 |
+
?>
|
137 |
+
</pre>
|
138 |
+
This will scan a directory called "unit" for any files
|
139 |
+
ending with "_test.php" and load them.
|
140 |
+
You don't have to use <span class="new_code">SimplePatternCollector</span> to
|
141 |
+
filter by a pattern in the filename, but this is the most common
|
142 |
+
usage.
|
143 |
+
</p>
|
144 |
+
<p>
|
145 |
+
That snippet above is very common in practice.
|
146 |
+
Now all you have to do is drop a file of test cases into the
|
147 |
+
directory and it will run just by running the test suite script.
|
148 |
+
</p>
|
149 |
+
<p>
|
150 |
+
The catch is that you cannot control the order in which the test
|
151 |
+
cases are run.
|
152 |
+
If you want to see lower level components fail first in the test suite,
|
153 |
+
and this will make diagnosis a lot easier, then you should manually
|
154 |
+
call <span class="new_code">addFile()</span> for these.
|
155 |
+
Tests cases are only loaded once, so it's fine to have these included
|
156 |
+
again by a directory scan.
|
157 |
+
</p>
|
158 |
+
<p>
|
159 |
+
Test cases loaded with the <span class="new_code">addFile</span> method have some
|
160 |
+
useful properties.
|
161 |
+
You can guarantee that the constructor is run
|
162 |
+
just before the first test method and the destructor
|
163 |
+
is run just after the last test method.
|
164 |
+
This allows you to place test case wide set up and tear down
|
165 |
+
code in the constructor and destructor, just like a normal
|
166 |
+
class.
|
167 |
+
</p>
|
168 |
+
|
169 |
+
<h2>
|
170 |
+
<a class="target" name="higher"></a>Composite suites</h2>
|
171 |
+
<p>
|
172 |
+
The above method places all of the test cases into one large suite.
|
173 |
+
For larger projects though this may not be flexible enough; you
|
174 |
+
may want to group the tests together in all sorts of ways.
|
175 |
+
</p>
|
176 |
+
<p>
|
177 |
+
Everything we have described so far with test scripts applies to
|
178 |
+
<span class="new_code">TestSuite</span>s as well...
|
179 |
+
<pre>
|
180 |
+
<?php
|
181 |
+
require_once('simpletest/autorun.php');
|
182 |
+
<strong>
|
183 |
+
class BigTestSuite extends TestSuite {
|
184 |
+
function __construct() {
|
185 |
+
parent::__construct();
|
186 |
+
$this->addFile('file_tests.php');
|
187 |
+
}
|
188 |
+
}</strong>
|
189 |
+
?>
|
190 |
+
</pre>
|
191 |
+
This effectively adds our test cases and a single suite below
|
192 |
+
the first.
|
193 |
+
When a test fails, we see the breadcrumb trail of the nesting.
|
194 |
+
We can even mix groups and test cases freely as long as
|
195 |
+
we are careful about loops in our includes.
|
196 |
+
<pre>
|
197 |
+
<?php
|
198 |
+
require_once('simpletest/autorun.php');
|
199 |
+
|
200 |
+
class BigTestSuite extends TestSuite {
|
201 |
+
function __construct() {
|
202 |
+
parent::__construct();
|
203 |
+
$this->addFile('file_tests.php');
|
204 |
+
<strong>$this->addFile('some_other_test.php');</strong>
|
205 |
+
}
|
206 |
+
}
|
207 |
+
?>
|
208 |
+
</pre>
|
209 |
+
Note that in the event of a double include, ony the first instance
|
210 |
+
of the test case will be run.
|
211 |
+
</p>
|
212 |
+
|
213 |
+
</div>
|
214 |
+
References and related information...
|
215 |
+
<ul>
|
216 |
+
<li>
|
217 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
218 |
+
</li>
|
219 |
+
<li>
|
220 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
221 |
+
</li>
|
222 |
+
</ul>
|
223 |
+
<div class="menu_back"><div class="menu">
|
224 |
+
<a href="index.html">SimpleTest</a>
|
225 |
+
|
|
226 |
+
<a href="overview.html">Overview</a>
|
227 |
+
|
|
228 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
229 |
+
|
|
230 |
+
<span class="chosen">Group tests</span>
|
231 |
+
|
|
232 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
233 |
+
|
|
234 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
235 |
+
|
|
236 |
+
<a href="reporter_documentation.html">Reporting</a>
|
237 |
+
|
|
238 |
+
<a href="expectation_documentation.html">Expectations</a>
|
239 |
+
|
|
240 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
241 |
+
|
|
242 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
243 |
+
|
|
244 |
+
<a href="authentication_documentation.html">Authentication</a>
|
245 |
+
|
|
246 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
247 |
+
</div></div>
|
248 |
+
<div class="copyright">
|
249 |
+
Copyright<br>Marcus Baker 2006
|
250 |
+
</div>
|
251 |
+
</body>
|
252 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/index.html
ADDED
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>
|
5 |
+
Download the SimpleTest testing framework -
|
6 |
+
Unit tests and mock objects for PHP
|
7 |
+
</title>
|
8 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
9 |
+
</head>
|
10 |
+
<body>
|
11 |
+
<div class="menu_back"><div class="menu">
|
12 |
+
<span class="chosen">SimpleTest</span>
|
13 |
+
|
|
14 |
+
<a href="overview.html">Overview</a>
|
15 |
+
|
|
16 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
17 |
+
|
|
18 |
+
<a href="group_test_documentation.html">Group tests</a>
|
19 |
+
|
|
20 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
21 |
+
|
|
22 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
23 |
+
|
|
24 |
+
<a href="reporter_documentation.html">Reporting</a>
|
25 |
+
|
|
26 |
+
<a href="expectation_documentation.html">Expectations</a>
|
27 |
+
|
|
28 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
29 |
+
|
|
30 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
31 |
+
|
|
32 |
+
<a href="authentication_documentation.html">Authentication</a>
|
33 |
+
|
|
34 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
35 |
+
</div></div>
|
36 |
+
<h1>SimpleTest for PHP</h1>
|
37 |
+
This page...
|
38 |
+
<ul>
|
39 |
+
<li>
|
40 |
+
<a href="#unit">Using unit tester</a>
|
41 |
+
with an example.
|
42 |
+
</li>
|
43 |
+
<li>
|
44 |
+
<a href="#group">Grouping tests</a>
|
45 |
+
for testing with one click.
|
46 |
+
</li>
|
47 |
+
<li>
|
48 |
+
<a href="#mock">Using mock objects</a>
|
49 |
+
to ease testing and gain tighter control.
|
50 |
+
</li>
|
51 |
+
<li>
|
52 |
+
<a href="#web">Testing web pages</a>
|
53 |
+
at the browser level.
|
54 |
+
</li>
|
55 |
+
</ul>
|
56 |
+
<div class="content">
|
57 |
+
|
58 |
+
|
59 |
+
<p>
|
60 |
+
The following assumes that you are familiar with the concept
|
61 |
+
of unit testing as well as the PHP web development language.
|
62 |
+
It is a guide for the impatient new user of
|
63 |
+
<a href="https://sourceforge.net/project/showfiles.php?group_id=76550">SimpleTest</a>.
|
64 |
+
For fuller documentation, especially if you are new
|
65 |
+
to unit testing see the ongoing
|
66 |
+
<a href="unit_test_documentation.html">documentation</a>, and for
|
67 |
+
example test cases see the
|
68 |
+
<a href="http://www.lastcraft.com/first_test_tutorial.php">unit testing tutorial</a>.
|
69 |
+
</p>
|
70 |
+
|
71 |
+
<h2>
|
72 |
+
<a class="target" name="unit"></a>Using the tester quickly</h2>
|
73 |
+
<p>
|
74 |
+
Amongst software testing tools, a unit tester is the one
|
75 |
+
closest to the developer.
|
76 |
+
In the context of agile development the test code sits right
|
77 |
+
next to the source code as both are written simultaneously.
|
78 |
+
In this context SimpleTest aims to be a complete PHP developer
|
79 |
+
test solution and is called "Simple" because it
|
80 |
+
should be easy to use and extend.
|
81 |
+
It wasn't a good choice of name really.
|
82 |
+
It includes all of the typical functions you would expect from
|
83 |
+
<a href="http://www.junit.org/">JUnit</a> and the
|
84 |
+
<a href="http://sourceforge.net/projects/phpunit/">PHPUnit</a>
|
85 |
+
ports, and includes
|
86 |
+
<a href="http://www.mockobjects.com">mock objects</a>.
|
87 |
+
</p>
|
88 |
+
<p>
|
89 |
+
What makes this tool immediately useful to the PHP developer is the internal
|
90 |
+
web browser.
|
91 |
+
This allows tests that navigate web sites, fill in forms and test pages.
|
92 |
+
Being able to write these test in PHP means that it is easy to write
|
93 |
+
integrated tests.
|
94 |
+
An example might be confirming that a user was written to a database
|
95 |
+
after a signing up through the web site.
|
96 |
+
</p>
|
97 |
+
<p>
|
98 |
+
The quickest way to demonstrate SimpleTest is with an example.
|
99 |
+
</p>
|
100 |
+
<p>
|
101 |
+
Let us suppose we are testing a simple file logging class called
|
102 |
+
<span class="new_code">Log</span> in <em>classes/log.php</em>.
|
103 |
+
We start by creating a test script which we will call
|
104 |
+
<em>tests/log_test.php</em> and populate it as follows...
|
105 |
+
<pre>
|
106 |
+
<?php
|
107 |
+
<strong>require_once('simpletest/autorun.php');</strong>
|
108 |
+
require_once('../classes/log.php');
|
109 |
+
|
110 |
+
class TestOfLogging extends <strong>UnitTestCase</strong> {
|
111 |
+
}
|
112 |
+
?>
|
113 |
+
</pre>
|
114 |
+
Here the <em>simpletest</em> folder is either local or in the path.
|
115 |
+
You would have to edit these locations depending on where you
|
116 |
+
unpacked the toolset.
|
117 |
+
The "autorun.php" file does more than just include the
|
118 |
+
SimpleTest files, it also runs our test for us.
|
119 |
+
</p>
|
120 |
+
<p>
|
121 |
+
The <span class="new_code">TestOfLogging</span> is our first test case and it's
|
122 |
+
currently empty.
|
123 |
+
Each test case is a class that extends one of the SimpleTet base classes
|
124 |
+
and we can have as many of these in the file as we want.
|
125 |
+
</p>
|
126 |
+
<p>
|
127 |
+
With three lines of scaffolding, and our <span class="new_code">Log</span> class
|
128 |
+
include, we have a test suite.
|
129 |
+
No tests though.
|
130 |
+
</p>
|
131 |
+
<p>
|
132 |
+
For our first test, we'll assume that the <span class="new_code">Log</span> class
|
133 |
+
takes the file name to write to in the constructor, and we have
|
134 |
+
a temporary folder in which to place this file...
|
135 |
+
<pre>
|
136 |
+
<?php
|
137 |
+
require_once('simpletest/autorun.php');
|
138 |
+
require_once('../classes/log.php');
|
139 |
+
|
140 |
+
class TestOfLogging extends UnitTestCase {
|
141 |
+
function <strong>testLogCreatesNewFileOnFirstMessage()</strong> {
|
142 |
+
@unlink('/temp/test.log');
|
143 |
+
$log = new Log('/temp/test.log');
|
144 |
+
<strong>$this->assertFalse(file_exists('/temp/test.log'));</strong>
|
145 |
+
$log->message('Should write this to a file');
|
146 |
+
<strong>$this->assertTrue(file_exists('/temp/test.log'));</strong>
|
147 |
+
}
|
148 |
+
}
|
149 |
+
?>
|
150 |
+
</pre>
|
151 |
+
When a test case runs, it will search for any method that
|
152 |
+
starts with the string "test"
|
153 |
+
and execute that method.
|
154 |
+
If the method starts "test", it's a test.
|
155 |
+
Note the very long name <span class="new_code">testLogCreatesNewFileOnFirstMessage()</span>.
|
156 |
+
This is considered good style and makes the test output more readable.
|
157 |
+
</p>
|
158 |
+
<p>
|
159 |
+
We would normally have more than one test method in a test case,
|
160 |
+
but that's for later.
|
161 |
+
</p>
|
162 |
+
<p>
|
163 |
+
Assertions within the test methods trigger messages to the
|
164 |
+
test framework which displays the result immediately.
|
165 |
+
This immediate response is important, not just in the event
|
166 |
+
of the code causing a crash, but also so that
|
167 |
+
<span class="new_code">print</span> statements can display
|
168 |
+
their debugging content right next to the assertion concerned.
|
169 |
+
</p>
|
170 |
+
<p>
|
171 |
+
To see these results we have to actually run the tests.
|
172 |
+
No other code is necessary - we can just open the page
|
173 |
+
with our browser.
|
174 |
+
</p>
|
175 |
+
<p>
|
176 |
+
On failure the display looks like this...
|
177 |
+
<div class="demo">
|
178 |
+
<h1>TestOfLogging</h1>
|
179 |
+
<span class="fail">Fail</span>: testLogCreatesNewFileOnFirstMessage->True assertion failed.<br>
|
180 |
+
<div style="padding: 8px; margin-top: 1em; background-color: red; color: white;">1/1 test cases complete.
|
181 |
+
<strong>1</strong> passes and <strong>1</strong> fails.</div>
|
182 |
+
</div>
|
183 |
+
...and if it passes like this...
|
184 |
+
<div class="demo">
|
185 |
+
<h1>TestOfLogging</h1>
|
186 |
+
<div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">1/1 test cases complete.
|
187 |
+
<strong>2</strong> passes and <strong>0</strong> fails.</div>
|
188 |
+
</div>
|
189 |
+
And if you get this...
|
190 |
+
<div class="demo">
|
191 |
+
<b>Fatal error</b>: Failed opening required '../classes/log.php' (include_path='') in <b>/home/marcus/projects/lastcraft/tutorial_tests/Log/tests/log_test.php</b> on line <b>7</b>
|
192 |
+
</div>
|
193 |
+
it means you're missing the <em>classes/Log.php</em> file that could look like...
|
194 |
+
<pre>
|
195 |
+
<?php<strong>
|
196 |
+
class Log {
|
197 |
+
function Log($file_path) {
|
198 |
+
}
|
199 |
+
|
200 |
+
function message() {
|
201 |
+
}
|
202 |
+
}</strong>
|
203 |
+
?>
|
204 |
+
</pre>
|
205 |
+
It's fun to write the code after the test.
|
206 |
+
More than fun even -
|
207 |
+
this system is called "Test Driven Development".
|
208 |
+
</p>
|
209 |
+
<p>
|
210 |
+
For more information about <span class="new_code">UnitTestCase</span>, see
|
211 |
+
the <a href="unit_test_documentation.html">unit test documentation</a>.
|
212 |
+
</p>
|
213 |
+
|
214 |
+
<h2>
|
215 |
+
<a class="target" name="group"></a>Building test suites</h2>
|
216 |
+
<p>
|
217 |
+
It is unlikely in a real application that we will only ever run
|
218 |
+
one test case.
|
219 |
+
This means that we need a way of grouping cases into a test
|
220 |
+
script that can, if need be, run every test for the application.
|
221 |
+
</p>
|
222 |
+
<p>
|
223 |
+
Our first step is to create a new file called <em>tests/all_tests.php</em>
|
224 |
+
and insert the following code...
|
225 |
+
<pre>
|
226 |
+
<?php
|
227 |
+
<strong>require_once('simpletest/autorun.php');</strong>
|
228 |
+
|
229 |
+
class AllTests extends <strong>TestSuite</strong> {
|
230 |
+
function AllTests() {
|
231 |
+
$this->TestSuite(<strong>'All tests'</strong>);
|
232 |
+
<strong>$this->addFile('log_test.php');</strong>
|
233 |
+
}
|
234 |
+
}
|
235 |
+
?>
|
236 |
+
</pre>
|
237 |
+
The "autorun" include allows our upcoming test suite
|
238 |
+
to be run just by invoking this script.
|
239 |
+
</p>
|
240 |
+
<p>
|
241 |
+
The <span class="new_code">TestSuite</span> subclass must chain it's constructor.
|
242 |
+
This limitation will be removed in future versions.
|
243 |
+
</p>
|
244 |
+
<p>
|
245 |
+
The method <span class="new_code">TestSuite::addFile()</span>
|
246 |
+
will include the test case file and read any new classes
|
247 |
+
that are descended from <span class="new_code">SimpleTestCase</span>.
|
248 |
+
<span class="new_code">UnitTestCase</span> is just one example of a class derived from
|
249 |
+
<span class="new_code">SimpleTestCase</span>, and you can create your own.
|
250 |
+
<span class="new_code">TestSuite::addFile()</span> can include other test suites.
|
251 |
+
</p>
|
252 |
+
<p>
|
253 |
+
The class will not be instantiated yet.
|
254 |
+
When the test suite runs it will construct each instance once
|
255 |
+
it reaches that test, then destroy it straight after.
|
256 |
+
This means that the constructor is run just before each run
|
257 |
+
of that test case, and the destructor is run before the next test case starts.
|
258 |
+
</p>
|
259 |
+
<p>
|
260 |
+
It is common to group test case code into superclasses which are not
|
261 |
+
supposed to run, but become the base classes of other tests.
|
262 |
+
For "autorun" to work properly the test case file should not blindly run
|
263 |
+
any other test case extensions that do not actually run tests.
|
264 |
+
This could result in extra test cases being counted during the test
|
265 |
+
run.
|
266 |
+
Hardly a major problem, but to avoid this inconvenience simply mark your
|
267 |
+
base class as <span class="new_code">abstract</span>.
|
268 |
+
SimpleTest won't run abstract classes.
|
269 |
+
If you are still using PHP4, then
|
270 |
+
a <span class="new_code">SimpleTestOptions::ignore()</span> directive
|
271 |
+
somewhere in the test case file will have the same effect.
|
272 |
+
</p>
|
273 |
+
<p>
|
274 |
+
Also, the test case file should not have been included
|
275 |
+
elsewhere or no cases will be added to this group test.
|
276 |
+
This would be a more serious error as if the test case classes are
|
277 |
+
already loaded by PHP the <span class="new_code">TestSuite::addFile()</span>
|
278 |
+
method will not detect them.
|
279 |
+
</p>
|
280 |
+
<p>
|
281 |
+
To display the results it is necessary only to invoke
|
282 |
+
<em>tests/all_tests.php</em> from the web server or the command line.
|
283 |
+
</p>
|
284 |
+
<p>
|
285 |
+
For more information about building test suites,
|
286 |
+
see the <a href="group_test_documentation.html">test suite documentation</a>.
|
287 |
+
</p>
|
288 |
+
|
289 |
+
<h2>
|
290 |
+
<a class="target" name="mock"></a>Using mock objects</h2>
|
291 |
+
<p>
|
292 |
+
Let's move further into the future and do something really complicated.
|
293 |
+
</p>
|
294 |
+
<p>
|
295 |
+
Assume that our logging class is tested and completed.
|
296 |
+
Assume also that we are testing another class that is
|
297 |
+
required to write log messages, say a
|
298 |
+
<span class="new_code">SessionPool</span>.
|
299 |
+
We want to test a method that will probably end up looking
|
300 |
+
like this...
|
301 |
+
<pre><strong>
|
302 |
+
class SessionPool {
|
303 |
+
...
|
304 |
+
function logIn($username) {
|
305 |
+
...
|
306 |
+
$this->_log->message("User $username logged in.");
|
307 |
+
...
|
308 |
+
}
|
309 |
+
...
|
310 |
+
}
|
311 |
+
</strong>
|
312 |
+
</pre>
|
313 |
+
In the spirit of reuse, we are using our
|
314 |
+
<span class="new_code">Log</span> class.
|
315 |
+
A conventional test case might look like this...
|
316 |
+
<pre>
|
317 |
+
<?php
|
318 |
+
require_once('simpletest/autorun.php');
|
319 |
+
require_once('../classes/log.php');
|
320 |
+
<strong>require_once('../classes/session_pool.php');</strong>
|
321 |
+
|
322 |
+
class <strong>TestOfSessionLogging</strong> extends UnitTestCase {
|
323 |
+
|
324 |
+
function setUp() {
|
325 |
+
<strong>@unlink('/temp/test.log');</strong>
|
326 |
+
}
|
327 |
+
|
328 |
+
function tearDown() {
|
329 |
+
<strong>@unlink('/temp/test.log');</strong>
|
330 |
+
}
|
331 |
+
|
332 |
+
function testLoggingInIsLogged() {
|
333 |
+
<strong>$log = new Log('/temp/test.log');
|
334 |
+
$session_pool = &new SessionPool($log);
|
335 |
+
$session_pool->logIn('fred');</strong>
|
336 |
+
$messages = file('/temp/test.log');
|
337 |
+
$this->assertEqual($messages[0], "User fred logged in.<strong>\n</strong>");
|
338 |
+
}
|
339 |
+
}
|
340 |
+
?>
|
341 |
+
</pre>
|
342 |
+
We'll explain the <span class="new_code">setUp()</span> and <span class="new_code">tearDown()</span>
|
343 |
+
methods later.
|
344 |
+
</p>
|
345 |
+
<p>
|
346 |
+
This test case design is not all bad, but it could be improved.
|
347 |
+
We are spending time fiddling with log files which are
|
348 |
+
not part of our test.
|
349 |
+
We have created close ties with the <span class="new_code">Log</span> class and
|
350 |
+
this test.
|
351 |
+
What if we don't use files any more, but use ths
|
352 |
+
<em>syslog</em> library instead?
|
353 |
+
It means that our <span class="new_code">TestOfSessionLogging</span> test will
|
354 |
+
fail, even thouh it's not testing Logging.
|
355 |
+
</p>
|
356 |
+
<p>
|
357 |
+
It's fragile in smaller ways too.
|
358 |
+
Did you notice the extra carriage return in the message?
|
359 |
+
Was that added by the logger?
|
360 |
+
What if it also added a time stamp or other data?
|
361 |
+
</p>
|
362 |
+
<p>
|
363 |
+
The only part that we really want to test is that a particular
|
364 |
+
message was sent to the logger.
|
365 |
+
We can reduce coupling if we pass in a fake logging class
|
366 |
+
that simply records the message calls for testing, but
|
367 |
+
takes no action.
|
368 |
+
It would have to look exactly like our original though.
|
369 |
+
</p>
|
370 |
+
<p>
|
371 |
+
If the fake object doesn't write to a file then we save on deleting
|
372 |
+
the file before and after each test. We could save even more
|
373 |
+
test code if the fake object would kindly run the assertion for us.
|
374 |
+
<p>
|
375 |
+
</p>
|
376 |
+
Too good to be true?
|
377 |
+
We can create such an object easily...
|
378 |
+
<pre>
|
379 |
+
<?php
|
380 |
+
require_once('simpletest/autorun.php');
|
381 |
+
require_once('../classes/log.php');
|
382 |
+
require_once('../classes/session_pool.php');
|
383 |
+
|
384 |
+
<strong>Mock::generate('Log');</strong>
|
385 |
+
|
386 |
+
class TestOfSessionLogging extends UnitTestCase {
|
387 |
+
|
388 |
+
function testLoggingInIsLogged() {<strong>
|
389 |
+
$log = &new MockLog();
|
390 |
+
$log->expectOnce('message', array('User fred logged in.'));</strong>
|
391 |
+
$session_pool = &new SessionPool(<strong>$log</strong>);
|
392 |
+
$session_pool->logIn('fred');
|
393 |
+
}
|
394 |
+
}
|
395 |
+
?>
|
396 |
+
</pre>
|
397 |
+
The <span class="new_code">Mock::generate()</span> call code generated a new class
|
398 |
+
called <span class="new_code">MockLog</span>.
|
399 |
+
This looks like an identical clone, except that we can wire test code
|
400 |
+
to it.
|
401 |
+
That's what <span class="new_code">expectOnce()</span> does.
|
402 |
+
It says that if <span class="new_code">message()</span> is ever called on me, it had
|
403 |
+
better be with the parameter "User fred logged in.".
|
404 |
+
</p>
|
405 |
+
<p>
|
406 |
+
The test will be triggered when the call to
|
407 |
+
<span class="new_code">message()</span> is invoked on the
|
408 |
+
<span class="new_code">MockLog</span> object by <span class="new_code">SessionPool::logIn()</span> code.
|
409 |
+
The mock call will trigger a parameter comparison and then send the
|
410 |
+
resulting pass or fail event to the test display.
|
411 |
+
Wildcards can be included here too, so you don't have to test every parameter of
|
412 |
+
a call when you only want to test one.
|
413 |
+
</p>
|
414 |
+
<p>
|
415 |
+
If the mock reaches the end of the test case without the
|
416 |
+
method being called, the <span class="new_code">expectOnce()</span>
|
417 |
+
expectation will trigger a test failure.
|
418 |
+
In other words the mocks can detect the absence of
|
419 |
+
behaviour as well as the presence.
|
420 |
+
</p>
|
421 |
+
<p>
|
422 |
+
The mock objects in the SimpleTest suite can have arbitrary
|
423 |
+
return values set, sequences of returns, return values
|
424 |
+
selected according to the incoming arguments, sequences of
|
425 |
+
parameter expectations and limits on the number of times
|
426 |
+
a method is to be invoked.
|
427 |
+
</p>
|
428 |
+
<p>
|
429 |
+
For more information about mocking and stubbing, see the
|
430 |
+
<a href="mock_objects_documentation.html">mock objects documentation</a>.
|
431 |
+
</p>
|
432 |
+
|
433 |
+
<h2>
|
434 |
+
<a class="target" name="web"></a>Web page testing</h2>
|
435 |
+
<p>
|
436 |
+
One of the requirements of web sites is that they produce web
|
437 |
+
pages.
|
438 |
+
If you are building a project top-down and you want to fully
|
439 |
+
integrate testing along the way then you will want a way of
|
440 |
+
automatically navigating a site and examining output for
|
441 |
+
correctness.
|
442 |
+
This is the job of a web tester.
|
443 |
+
</p>
|
444 |
+
<p>
|
445 |
+
The web testing in SimpleTest is fairly primitive, as there is
|
446 |
+
no JavaScript.
|
447 |
+
Most other browser operations are simulated.
|
448 |
+
</p>
|
449 |
+
<p>
|
450 |
+
To give an idea here is a trivial example where a home
|
451 |
+
page is fetched, from which we navigate to an "about"
|
452 |
+
page and then test some client determined content.
|
453 |
+
<pre>
|
454 |
+
<?php
|
455 |
+
require_once('simpletest/autorun.php');
|
456 |
+
<strong>require_once('simpletest/web_tester.php');</strong>
|
457 |
+
|
458 |
+
class TestOfAbout extends <strong>WebTestCase</strong> {
|
459 |
+
function testOurAboutPageGivesFreeReignToOurEgo() {
|
460 |
+
<strong>$this->get('http://test-server/index.php');
|
461 |
+
$this->click('About');
|
462 |
+
$this->assertTitle('About why we are so great');
|
463 |
+
$this->assertText('We are really great');</strong>
|
464 |
+
}
|
465 |
+
}
|
466 |
+
?>
|
467 |
+
</pre>
|
468 |
+
With this code as an acceptance test, you can ensure that
|
469 |
+
the content always meets the specifications of both the
|
470 |
+
developers, and the other project stakeholders.
|
471 |
+
</p>
|
472 |
+
<p>
|
473 |
+
You can navigate forms too...
|
474 |
+
<pre>
|
475 |
+
<?php
|
476 |
+
require_once('simpletest/autorun.php');
|
477 |
+
require_once('simpletest/web_tester.php');
|
478 |
+
|
479 |
+
class TestOfRankings extends WebTestCase {
|
480 |
+
function testWeAreTopOfGoogle() {
|
481 |
+
$this->get('http://google.com/');
|
482 |
+
$this->setField('q', 'simpletest');
|
483 |
+
$this->click("I'm Feeling Lucky");
|
484 |
+
$this->assertTitle('SimpleTest - Unit Testing for PHP');
|
485 |
+
}
|
486 |
+
}
|
487 |
+
?>
|
488 |
+
</pre>
|
489 |
+
...although this could violate Google's(tm) terms and conditions.
|
490 |
+
</p>
|
491 |
+
<p>
|
492 |
+
For more information about web testing, see the
|
493 |
+
<a href="browser_documentation.html">scriptable
|
494 |
+
browser documentation</a> and the
|
495 |
+
<a href="web_tester_documentation.html">WebTestCase</a>.
|
496 |
+
</p>
|
497 |
+
<p>
|
498 |
+
<a href="http://sourceforge.net/projects/simpletest/"><img src="http://sourceforge.net/sflogo.php?group_id=76550&type=5" width="210" height="62" border="0" alt="SourceForge.net Logo"></a>
|
499 |
+
</p>
|
500 |
+
|
501 |
+
</div>
|
502 |
+
References and related information...
|
503 |
+
<ul>
|
504 |
+
<li>
|
505 |
+
<a href="https://sourceforge.net/project/showfiles.php?group_id=76550&release_id=153280">Download PHP SimpleTest</a>
|
506 |
+
from <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
507 |
+
</li>
|
508 |
+
<li>
|
509 |
+
The <a href="http://simpletest.org/api/">developer's API for SimpleTest</a>
|
510 |
+
gives full detail on the classes and assertions available.
|
511 |
+
</li>
|
512 |
+
</ul>
|
513 |
+
<div class="menu_back"><div class="menu">
|
514 |
+
<span class="chosen">SimpleTest</span>
|
515 |
+
|
|
516 |
+
<a href="overview.html">Overview</a>
|
517 |
+
|
|
518 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
519 |
+
|
|
520 |
+
<a href="group_test_documentation.html">Group tests</a>
|
521 |
+
|
|
522 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
523 |
+
|
|
524 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
525 |
+
|
|
526 |
+
<a href="reporter_documentation.html">Reporting</a>
|
527 |
+
|
|
528 |
+
<a href="expectation_documentation.html">Expectations</a>
|
529 |
+
|
|
530 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
531 |
+
|
|
532 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
533 |
+
|
|
534 |
+
<a href="authentication_documentation.html">Authentication</a>
|
535 |
+
|
|
536 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
537 |
+
</div></div>
|
538 |
+
<div class="copyright">
|
539 |
+
Copyright<br>Marcus Baker 2006
|
540 |
+
</div>
|
541 |
+
</body>
|
542 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/mock_objects_documentation.html
ADDED
@@ -0,0 +1,870 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest for PHP mock objects documentation</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<span class="chosen">Mock objects</span>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Mock objects documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
<a href="#what">What are mock objects?</a>
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
<a href="#creation">Creating mock objects</a>.
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
<a href="#expectations">Mocks as critics</a> with expectations.
|
44 |
+
</li>
|
45 |
+
</ul>
|
46 |
+
<div class="content">
|
47 |
+
<h2>
|
48 |
+
<a class="target" name="what"></a>What are mock objects?</h2>
|
49 |
+
<p>
|
50 |
+
Mock objects have two roles during a test case: actor and critic.
|
51 |
+
</p>
|
52 |
+
<p>
|
53 |
+
The actor behaviour is to simulate objects that are difficult to
|
54 |
+
set up or time consuming to set up for a test.
|
55 |
+
The classic example is a database connection.
|
56 |
+
Setting up a test database at the start of each test would slow
|
57 |
+
testing to a crawl and would require the installation of the
|
58 |
+
database engine and test data on the test machine.
|
59 |
+
If we can simulate the connection and return data of our
|
60 |
+
choosing we not only win on the pragmatics of testing, but can
|
61 |
+
also feed our code spurious data to see how it responds.
|
62 |
+
We can simulate databases being down or other extremes
|
63 |
+
without having to create a broken database for real.
|
64 |
+
In other words, we get greater control of the test environment.
|
65 |
+
</p>
|
66 |
+
<p>
|
67 |
+
If mock objects only behaved as actors they would simply be
|
68 |
+
known as "server stubs".
|
69 |
+
This was originally a pattern named by Robert Binder (<a href="">Testing
|
70 |
+
object-oriented systems</a>: models, patterns, and tools,
|
71 |
+
Addison-Wesley) in 1999.
|
72 |
+
</p>
|
73 |
+
<p>
|
74 |
+
A server stub is a simulation of an object or component.
|
75 |
+
It should exactly replace a component in a system for test
|
76 |
+
or prototyping purposes, but remain lightweight.
|
77 |
+
This allows tests to run more quickly, or if the simulated
|
78 |
+
class has not been written, to run at all.
|
79 |
+
</p>
|
80 |
+
<p>
|
81 |
+
However, the mock objects not only play a part (by supplying chosen
|
82 |
+
return values on demand) they are also sensitive to the
|
83 |
+
messages sent to them (via expectations).
|
84 |
+
By setting expected parameters for a method call they act
|
85 |
+
as a guard that the calls upon them are made correctly.
|
86 |
+
If expectations are not met they save us the effort of
|
87 |
+
writing a failed test assertion by performing that duty on our
|
88 |
+
behalf.
|
89 |
+
</p>
|
90 |
+
<p>
|
91 |
+
In the case of an imaginary database connection they can
|
92 |
+
test that the query, say SQL, was correctly formed by
|
93 |
+
the object that is using the connection.
|
94 |
+
Set them up with fairly tight expectations and you will
|
95 |
+
hardly need manual assertions at all.
|
96 |
+
</p>
|
97 |
+
|
98 |
+
<h2>
|
99 |
+
<a class="target" name="creation"></a>Creating mock objects</h2>
|
100 |
+
<p>
|
101 |
+
All we need is an existing class or interface, say a database connection
|
102 |
+
that looks like this...
|
103 |
+
<pre>
|
104 |
+
<strong>class DatabaseConnection {
|
105 |
+
function DatabaseConnection() { }
|
106 |
+
function query($sql) { }
|
107 |
+
function selectQuery($sql) { }
|
108 |
+
}</strong>
|
109 |
+
</pre>
|
110 |
+
To create a mock version of the class we need to run a
|
111 |
+
code generator...
|
112 |
+
<pre>
|
113 |
+
require_once('simpletest/autorun.php');
|
114 |
+
require_once('database_connection.php');
|
115 |
+
|
116 |
+
<strong>Mock::generate('DatabaseConnection');</strong>
|
117 |
+
</pre>
|
118 |
+
This code generates a clone class called
|
119 |
+
<span class="new_code">MockDatabaseConnection</span>.
|
120 |
+
This new class appears to be the same, but actually has no behaviour at all.
|
121 |
+
</p>
|
122 |
+
<p>
|
123 |
+
The new class is usually a subclass of <span class="new_code">DatabaseConnection</span>.
|
124 |
+
Unfortunately, there is no way to create a mock version of a
|
125 |
+
class with a <span class="new_code">final</span> method without having a living version of
|
126 |
+
that method.
|
127 |
+
We consider that unsafe.
|
128 |
+
If the target is an interface, or if <span class="new_code">final</span> methods are
|
129 |
+
present in a target class, then a whole new class
|
130 |
+
is created, but one implemeting the same interfaces.
|
131 |
+
If you try to pass this separate class through a type hint that specifies
|
132 |
+
the old concrete class name, it will fail.
|
133 |
+
Code like that insists on type hinting to a class with <span class="new_code">final</span>
|
134 |
+
methods probably cannot be safely tested with mocks.
|
135 |
+
</p>
|
136 |
+
<p>
|
137 |
+
If you want to see the generated code, then simply <span class="new_code">print</span>
|
138 |
+
the output of <span class="new_code">Mock::generate()</span>.
|
139 |
+
Here is the generated code for the <span class="new_code">DatabaseConnection</span>
|
140 |
+
class rather than the interface version...
|
141 |
+
<pre>
|
142 |
+
class MockDatabaseConnection extends DatabaseConnection {
|
143 |
+
public $mock;
|
144 |
+
protected $mocked_methods = array('databaseconnection', 'query', 'selectquery');
|
145 |
+
|
146 |
+
function MockDatabaseConnection() {
|
147 |
+
$this->mock = new SimpleMock();
|
148 |
+
$this->mock->disableExpectationNameChecks();
|
149 |
+
}
|
150 |
+
...
|
151 |
+
function DatabaseConnection() {
|
152 |
+
$args = func_get_args();
|
153 |
+
$result = &$this->mock->invoke("DatabaseConnection", $args);
|
154 |
+
return $result;
|
155 |
+
}
|
156 |
+
function query($sql) {
|
157 |
+
$args = func_get_args();
|
158 |
+
$result = &$this->mock->invoke("query", $args);
|
159 |
+
return $result;
|
160 |
+
}
|
161 |
+
function selectQuery($sql) {
|
162 |
+
$args = func_get_args();
|
163 |
+
$result = &$this->mock->invoke("selectQuery", $args);
|
164 |
+
return $result;
|
165 |
+
}
|
166 |
+
}
|
167 |
+
</pre>
|
168 |
+
Your output may vary depending on the exact version
|
169 |
+
of SimpleTest you are using.
|
170 |
+
</p>
|
171 |
+
<p>
|
172 |
+
Besides the original methods of the class, you will see some extra
|
173 |
+
methods that help testing.
|
174 |
+
More on these later.
|
175 |
+
</p>
|
176 |
+
<p>
|
177 |
+
We can now create instances of the new class within
|
178 |
+
our test case...
|
179 |
+
<pre>
|
180 |
+
require_once('simpletest/autorun.php');
|
181 |
+
require_once('database_connection.php');
|
182 |
+
|
183 |
+
Mock::generate('DatabaseConnection');
|
184 |
+
|
185 |
+
class MyTestCase extends UnitTestCase {
|
186 |
+
|
187 |
+
function testSomething() {
|
188 |
+
<strong>$connection = new MockDatabaseConnection();</strong>
|
189 |
+
}
|
190 |
+
}
|
191 |
+
</pre>
|
192 |
+
The mock version now has all the methods of the original.
|
193 |
+
Also, any type hints will be faithfully preserved.
|
194 |
+
Say our query methods expect a <span class="new_code">Query</span> object...
|
195 |
+
<pre>
|
196 |
+
<strong>class DatabaseConnection {
|
197 |
+
function DatabaseConnection() { }
|
198 |
+
function query(Query $query) { }
|
199 |
+
function selectQuery(Query $query) { }
|
200 |
+
}</strong>
|
201 |
+
</pre>
|
202 |
+
If we now pass the wrong type of object, or worse a non-object...
|
203 |
+
<pre>
|
204 |
+
class MyTestCase extends UnitTestCase {
|
205 |
+
|
206 |
+
function testSomething() {
|
207 |
+
$connection = new MockDatabaseConnection();
|
208 |
+
$connection->query('insert into accounts () values ()');
|
209 |
+
}
|
210 |
+
}
|
211 |
+
</pre>
|
212 |
+
...the code will throw a type violation at you just as the
|
213 |
+
original class would.
|
214 |
+
</p>
|
215 |
+
<p>
|
216 |
+
The mock version now has all the methods of the original.
|
217 |
+
Unfortunately, they all return <span class="new_code">null</span>.
|
218 |
+
As methods that always return <span class="new_code">null</span> are not that useful,
|
219 |
+
we need to be able to set them to something else...
|
220 |
+
</p>
|
221 |
+
<p>
|
222 |
+
<a class="target" name="stub"><h2>Mocks as actors</h2></a>
|
223 |
+
</p>
|
224 |
+
<p>
|
225 |
+
Changing the return value of a method from <span class="new_code">null</span>
|
226 |
+
to something else is pretty easy...
|
227 |
+
<pre>
|
228 |
+
<strong>$connection->returns('query', 37)</strong>
|
229 |
+
</pre>
|
230 |
+
Now every time we call
|
231 |
+
<span class="new_code">$connection->query()</span> we get
|
232 |
+
the result of 37.
|
233 |
+
There is nothing special about 37.
|
234 |
+
The return value can be arbitrarily complicated.
|
235 |
+
</p>
|
236 |
+
<p>
|
237 |
+
Parameters are irrelevant here, we always get the same
|
238 |
+
values back each time once they have been set up this way.
|
239 |
+
That may not sound like a convincing replica of a
|
240 |
+
database connection, but for the half a dozen lines of
|
241 |
+
a test method it is usually all you need.
|
242 |
+
</p>
|
243 |
+
<p>
|
244 |
+
Things aren't always that simple though.
|
245 |
+
One common problem is iterators, where constantly returning
|
246 |
+
the same value could cause an endless loop in the object
|
247 |
+
being tested.
|
248 |
+
For these we need to set up sequences of values.
|
249 |
+
Let's say we have a simple iterator that looks like this...
|
250 |
+
<pre>
|
251 |
+
class Iterator {
|
252 |
+
function Iterator() { }
|
253 |
+
function next() { }
|
254 |
+
}
|
255 |
+
</pre>
|
256 |
+
This is about the simplest iterator you could have.
|
257 |
+
Assuming that this iterator only returns text until it
|
258 |
+
reaches the end, when it returns false, we can simulate it
|
259 |
+
with...
|
260 |
+
<pre>
|
261 |
+
Mock::generate('Iterator');
|
262 |
+
|
263 |
+
class IteratorTest extends UnitTestCase() {
|
264 |
+
|
265 |
+
function testASequence() {<strong>
|
266 |
+
$iterator = new MockIterator();
|
267 |
+
$iterator->returns('next', false);
|
268 |
+
$iterator->returnsAt(0, 'next', 'First string');
|
269 |
+
$iterator->returnsAt(1, 'next', 'Second string');</strong>
|
270 |
+
...
|
271 |
+
}
|
272 |
+
}
|
273 |
+
</pre>
|
274 |
+
When <span class="new_code">next()</span> is called on the
|
275 |
+
<span class="new_code">MockIterator</span> it will first return "First string",
|
276 |
+
on the second call "Second string" will be returned
|
277 |
+
and on any other call <span class="new_code">false</span> will
|
278 |
+
be returned.
|
279 |
+
The sequenced return values take precedence over the constant
|
280 |
+
return value.
|
281 |
+
The constant one is a kind of default if you like.
|
282 |
+
</p>
|
283 |
+
<p>
|
284 |
+
Another tricky situation is an overloaded
|
285 |
+
<span class="new_code">get()</span> operation.
|
286 |
+
An example of this is an information holder with name/value pairs.
|
287 |
+
Say we have a configuration class like...
|
288 |
+
<pre>
|
289 |
+
class Configuration {
|
290 |
+
function Configuration() { ... }
|
291 |
+
function get($key) { ... }
|
292 |
+
}
|
293 |
+
</pre>
|
294 |
+
This is a likely situation for using mock objects, as
|
295 |
+
actual configuration will vary from machine to machine and
|
296 |
+
even from test to test.
|
297 |
+
The problem though is that all the data comes through the
|
298 |
+
<span class="new_code">get()</span> method and yet
|
299 |
+
we want different results for different keys.
|
300 |
+
Luckily the mocks have a filter system...
|
301 |
+
<pre>
|
302 |
+
<strong>$config = &new MockConfiguration();
|
303 |
+
$config->returns('get', 'primary', array('db_host'));
|
304 |
+
$config->returns('get', 'admin', array('db_user'));
|
305 |
+
$config->returns('get', 'secret', array('db_password'));</strong>
|
306 |
+
</pre>
|
307 |
+
The extra parameter is a list of arguments to attempt
|
308 |
+
to match.
|
309 |
+
In this case we are trying to match only one argument which
|
310 |
+
is the look up key.
|
311 |
+
Now when the mock object has the
|
312 |
+
<span class="new_code">get()</span> method invoked
|
313 |
+
like this...
|
314 |
+
<pre>
|
315 |
+
$config->get('db_user')
|
316 |
+
</pre>
|
317 |
+
...it will return "admin".
|
318 |
+
It finds this by attempting to match the calling arguments
|
319 |
+
to its list of returns one after another until
|
320 |
+
a complete match is found.
|
321 |
+
</p>
|
322 |
+
<p>
|
323 |
+
You can set a default argument argument like so...
|
324 |
+
<pre><strong>
|
325 |
+
$config->returns('get', false, array('*'));</strong>
|
326 |
+
</pre>
|
327 |
+
This is not the same as setting the return value without
|
328 |
+
any argument requirements like this...
|
329 |
+
<pre><strong>
|
330 |
+
$config->returns('get', false);</strong>
|
331 |
+
</pre>
|
332 |
+
In the first case it will accept any single argument,
|
333 |
+
but exactly one is required.
|
334 |
+
In the second case any number of arguments will do and
|
335 |
+
it acts as a catchall after all other matches.
|
336 |
+
Note that if we add further single parameter options after
|
337 |
+
the wildcard in the first case, they will be ignored as the wildcard
|
338 |
+
will match first.
|
339 |
+
With complex parameter lists the ordering could be important
|
340 |
+
or else desired matches could be masked by earlier wildcard
|
341 |
+
ones.
|
342 |
+
Declare the most specific matches first if you are not sure.
|
343 |
+
</p>
|
344 |
+
<p>
|
345 |
+
There are times when you want a specific reference to be
|
346 |
+
dished out by the mock rather than a copy or object handle.
|
347 |
+
This a rarity to say the least, but you might be simulating
|
348 |
+
a container that can hold primitives such as strings.
|
349 |
+
For example...
|
350 |
+
<pre>
|
351 |
+
class Pad {
|
352 |
+
function Pad() { }
|
353 |
+
function &note($index) { }
|
354 |
+
}
|
355 |
+
</pre>
|
356 |
+
In this case you can set a reference into the mock's
|
357 |
+
return list...
|
358 |
+
<pre>
|
359 |
+
function testTaskReads() {
|
360 |
+
$note = 'Buy books';
|
361 |
+
$pad = new MockPad();
|
362 |
+
$vector-><strong>returnsByReference(</strong>'note', $note, array(3)<strong>)</strong>;
|
363 |
+
$task = new Task($pad);
|
364 |
+
...
|
365 |
+
}
|
366 |
+
</pre>
|
367 |
+
With this arrangement you know that every time
|
368 |
+
<span class="new_code">$pad->note(3)</span> is
|
369 |
+
called it will return the same <span class="new_code">$note</span> each time,
|
370 |
+
even if it get's modified.
|
371 |
+
</p>
|
372 |
+
<p>
|
373 |
+
These three factors, timing, parameters and whether to copy,
|
374 |
+
can be combined orthogonally.
|
375 |
+
For example...
|
376 |
+
<pre>
|
377 |
+
$buy_books = 'Buy books';
|
378 |
+
$write_code = 'Write code';
|
379 |
+
$pad = new MockPad();
|
380 |
+
$vector-><strong>returnsByReferenceAt(0, 'note', $buy_books, array('*', 3));</strong>
|
381 |
+
$vector-><strong>returnsByReferenceAt(1, 'note', $write_code, array('*', 3));</strong>
|
382 |
+
</pre>
|
383 |
+
This will return a reference to <span class="new_code">$buy_books</span> and
|
384 |
+
then to <span class="new_code">$write_code</span>, but only if two parameters
|
385 |
+
were set the second of which must be the integer 3.
|
386 |
+
That should cover most situations.
|
387 |
+
</p>
|
388 |
+
<p>
|
389 |
+
A final tricky case is one object creating another, known
|
390 |
+
as a factory pattern.
|
391 |
+
Suppose that on a successful query to our imaginary
|
392 |
+
database, a result set is returned as an iterator, with
|
393 |
+
each call to the the iterator's <span class="new_code">next()</span> giving
|
394 |
+
one row until false.
|
395 |
+
This sounds like a simulation nightmare, but in fact it can all
|
396 |
+
be mocked using the mechanics above...
|
397 |
+
<pre>
|
398 |
+
Mock::generate('DatabaseConnection');
|
399 |
+
Mock::generate('ResultIterator');
|
400 |
+
|
401 |
+
class DatabaseTest extends UnitTestCase {
|
402 |
+
|
403 |
+
function testUserFinderReadsResultsFromDatabase() {<strong>
|
404 |
+
$result = new MockResultIterator();
|
405 |
+
$result->returns('next', false);
|
406 |
+
$result->returnsAt(0, 'next', array(1, 'tom'));
|
407 |
+
$result->returnsAt(1, 'next', array(3, 'dick'));
|
408 |
+
$result->returnsAt(2, 'next', array(6, 'harry'));
|
409 |
+
|
410 |
+
$connection = new MockDatabaseConnection();
|
411 |
+
$connection->returns('selectQuery', $result);</strong>
|
412 |
+
|
413 |
+
$finder = new UserFinder(<strong>$connection</strong>);
|
414 |
+
$this->assertIdentical(
|
415 |
+
$finder->findNames(),
|
416 |
+
array('tom', 'dick', 'harry'));
|
417 |
+
}
|
418 |
+
}
|
419 |
+
</pre>
|
420 |
+
Now only if our
|
421 |
+
<span class="new_code">$connection</span> is called with the
|
422 |
+
<span class="new_code">query()</span> method will the
|
423 |
+
<span class="new_code">$result</span> be returned that is
|
424 |
+
itself exhausted after the third call to <span class="new_code">next()</span>.
|
425 |
+
This should be enough
|
426 |
+
information for our <span class="new_code">UserFinder</span> class,
|
427 |
+
the class actually
|
428 |
+
being tested here, to come up with goods.
|
429 |
+
A very precise test and not a real database in sight.
|
430 |
+
</p>
|
431 |
+
<p>
|
432 |
+
We could refine this test further by insisting that the correct
|
433 |
+
query is sent...
|
434 |
+
<pre>
|
435 |
+
$connection->returns('selectQuery', $result, array(<strong>'select name, id from people'</strong>));
|
436 |
+
</pre>
|
437 |
+
This is actually a bad idea.
|
438 |
+
</p>
|
439 |
+
<p>
|
440 |
+
We have a <span class="new_code">UserFinder</span> in object land, talking to
|
441 |
+
database tables using a large interface - the whole of SQL.
|
442 |
+
Imagine that we have written a lot of tests that now depend
|
443 |
+
on the exact SQL string passed.
|
444 |
+
These queries could change en masse for all sorts of reasons
|
445 |
+
not related to the specific test.
|
446 |
+
For example the quoting rules could change, a table name could
|
447 |
+
change, a link table added or whatever.
|
448 |
+
This would require the rewriting of every single test any time
|
449 |
+
one of these refactoring is made, yet the intended behaviour has
|
450 |
+
stayed the same.
|
451 |
+
Tests are supposed to help refactoring, not hinder it.
|
452 |
+
I'd certainly like to have a test suite that passes while I change
|
453 |
+
table names.
|
454 |
+
</p>
|
455 |
+
<p>
|
456 |
+
As a rule it is best not to mock a fat interface.
|
457 |
+
</p>
|
458 |
+
<p>
|
459 |
+
By contrast, here is the round trip test...
|
460 |
+
<pre>
|
461 |
+
class DatabaseTest extends UnitTestCase {<strong>
|
462 |
+
function setUp() { ... }
|
463 |
+
function tearDown() { ... }</strong>
|
464 |
+
|
465 |
+
function testUserFinderReadsResultsFromDatabase() {
|
466 |
+
$finder = new UserFinder(<strong>new DatabaseConnection()</strong>);
|
467 |
+
$finder->add('tom');
|
468 |
+
$finder->add('dick');
|
469 |
+
$finder->add('harry');
|
470 |
+
$this->assertIdentical(
|
471 |
+
$finder->findNames(),
|
472 |
+
array('tom', 'dick', 'harry'));
|
473 |
+
}
|
474 |
+
}
|
475 |
+
</pre>
|
476 |
+
This test is immune to schema changes.
|
477 |
+
It will only fail if you actually break the functionality, which
|
478 |
+
is what you want a test to do.
|
479 |
+
</p>
|
480 |
+
<p>
|
481 |
+
The catch is those <span class="new_code">setUp()</span> and <span class="new_code">tearDown()</span>
|
482 |
+
methods that we've rather glossed over.
|
483 |
+
They have to clear out the database tables and ensure that the
|
484 |
+
schema is defined correctly.
|
485 |
+
That can be a chunk of extra work, but you usually have this code
|
486 |
+
lying around anyway for deployment purposes.
|
487 |
+
</p>
|
488 |
+
<p>
|
489 |
+
One place where you definitely need a mock is simulating failures.
|
490 |
+
Say the database goes down while <span class="new_code">UserFinder</span> is doing
|
491 |
+
it's work.
|
492 |
+
Does <span class="new_code">UserFinder</span> behave well...?
|
493 |
+
<pre>
|
494 |
+
class DatabaseTest extends UnitTestCase {
|
495 |
+
|
496 |
+
function testUserFinder() {
|
497 |
+
$connection = new MockDatabaseConnection();<strong>
|
498 |
+
$connection->throwOn('selectQuery', new TimedOut('Ouch!'));</strong>
|
499 |
+
$alert = new MockAlerts();<strong>
|
500 |
+
$alert->expectOnce('notify', 'Database is busy - please retry');</strong>
|
501 |
+
$finder = new UserFinder($connection, $alert);
|
502 |
+
$this->assertIdentical($finder->findNames(), array());
|
503 |
+
}
|
504 |
+
}
|
505 |
+
</pre>
|
506 |
+
We've passed the <span class="new_code">UserFinder</span> an <span class="new_code">$alert</span>
|
507 |
+
object.
|
508 |
+
This is going to do some kind of pretty notifications in the
|
509 |
+
user interface in the event of an error.
|
510 |
+
We'd rather not sprinkle our code with hard wired <span class="new_code">print</span>
|
511 |
+
statements if we can avoid it.
|
512 |
+
Wrapping the means of output means we can use this code anywhere.
|
513 |
+
It also makes testing easier.
|
514 |
+
</p>
|
515 |
+
<p>
|
516 |
+
To pass this test, the finder has to write a nice user friendly
|
517 |
+
message to <span class="new_code">$alert</span>, rather than propogating the exception.
|
518 |
+
So far, so good.
|
519 |
+
</p>
|
520 |
+
<p>
|
521 |
+
How do we get the mock <span class="new_code">DatabaseConnection</span> to throw an exception?
|
522 |
+
We generate the exception using the <span class="new_code">throwOn</span> method
|
523 |
+
on the mock.
|
524 |
+
</p>
|
525 |
+
<p>
|
526 |
+
Finally, what if the method you want to simulate does not exist yet?
|
527 |
+
If you set a return value on a method that is not there, SimpleTest
|
528 |
+
will throw an error.
|
529 |
+
What if you are using <span class="new_code">__call()</span> to simulate dynamic methods?
|
530 |
+
</p>
|
531 |
+
<p>
|
532 |
+
Objects with dynamic interfaces, using <span class="new_code">__call</span>, can
|
533 |
+
be problematic with the current mock objects implementation.
|
534 |
+
You can mock the <span class="new_code">__call()</span> method, but this is ugly.
|
535 |
+
Why should a test know anything about such low level implementation details?
|
536 |
+
It just wants to simulate the call.
|
537 |
+
</p>
|
538 |
+
<p>
|
539 |
+
The way round this is to add extra methods to the mock when
|
540 |
+
generating it.
|
541 |
+
<pre>
|
542 |
+
<strong>Mock::generate('DatabaseConnection', 'MockDatabaseConnection', array('setOptions'));</strong>
|
543 |
+
</pre>
|
544 |
+
In a large test suite this could cause trouble, as you probably
|
545 |
+
already have a mock version of the class called
|
546 |
+
<span class="new_code">MockDatabaseConnection</span> without the extra methods.
|
547 |
+
The code generator will not generate a mock version of the class if
|
548 |
+
one of the same name already exists.
|
549 |
+
You will confusingly fail to see your method if another definition
|
550 |
+
was run first.
|
551 |
+
</p>
|
552 |
+
<p>
|
553 |
+
To cope with this, SimpleTest allows you to choose any name for the
|
554 |
+
new class at the same time as you add the extra methods.
|
555 |
+
<pre>
|
556 |
+
Mock::generate('DatabaseConnection', <strong>'MockDatabaseConnectionWithOptions'</strong>, array('setOptions'));
|
557 |
+
</pre>
|
558 |
+
Here the mock will behave as if the <span class="new_code">setOptions()</span>
|
559 |
+
existed in the original class.
|
560 |
+
</p>
|
561 |
+
<p>
|
562 |
+
Mock objects can only be used within test cases, as upon expectations
|
563 |
+
they send messages straight to the currently running test case.
|
564 |
+
Creating them outside a test case will cause a run time error
|
565 |
+
when an expectation is triggered and there is no running test case
|
566 |
+
for the message to end up.
|
567 |
+
We cover expectations next.
|
568 |
+
</p>
|
569 |
+
|
570 |
+
<h2>
|
571 |
+
<a class="target" name="expectations"></a>Mocks as critics</h2>
|
572 |
+
<p>
|
573 |
+
Although the server stubs approach insulates your tests from
|
574 |
+
real world disruption, it is only half the benefit.
|
575 |
+
You can have the class under test receiving the required
|
576 |
+
messages, but is your new class sending correct ones?
|
577 |
+
Testing this can get messy without a mock objects library.
|
578 |
+
</p>
|
579 |
+
<p>
|
580 |
+
By way of example, let's take a simple <span class="new_code">PageController</span>
|
581 |
+
class to handle a credit card payment form...
|
582 |
+
<pre>
|
583 |
+
class PaymentForm extends PageController {
|
584 |
+
function __construct($alert, $payment_gateway) { ... }
|
585 |
+
function makePayment($request) { ... }
|
586 |
+
}
|
587 |
+
</pre>
|
588 |
+
This class takes a <span class="new_code">PaymentGateway</span> to actually talk
|
589 |
+
to the bank.
|
590 |
+
It also takes an <span class="new_code">Alert</span> object to handle errors.
|
591 |
+
This class talks to the page or template.
|
592 |
+
It's responsible for painting the error message and highlighting any
|
593 |
+
form fields that are incorrect.
|
594 |
+
</p>
|
595 |
+
<p>
|
596 |
+
It might look something like...
|
597 |
+
<pre>
|
598 |
+
class Alert {
|
599 |
+
function warn($warning, $id) {
|
600 |
+
print '<div class="warning">' . $warning . '</div>';
|
601 |
+
print '<style type="text/css">#' . $id . ' { background-color: red }</style>';
|
602 |
+
}
|
603 |
+
}
|
604 |
+
</pre>
|
605 |
+
</p>
|
606 |
+
<p>
|
607 |
+
Our interest is in the <span class="new_code">makePayment()</span> method.
|
608 |
+
If we fail to enter a "CVV2" number (the three digit number
|
609 |
+
on the back of the credit card), we want to show an error rather than
|
610 |
+
try to process the payment.
|
611 |
+
In test form...
|
612 |
+
<pre>
|
613 |
+
<?php
|
614 |
+
require_once('simpletest/autorun.php');
|
615 |
+
require_once('payment_form.php');
|
616 |
+
Mock::generate('Alert');
|
617 |
+
Mock::generate('PaymentGateway');
|
618 |
+
|
619 |
+
class PaymentFormFailuresShouldBeGraceful extends UnitTestCase {
|
620 |
+
|
621 |
+
function testMissingCvv2CausesAlert() {
|
622 |
+
$alert = new MockAlert();
|
623 |
+
<strong>$alert->expectOnce(
|
624 |
+
'warn',
|
625 |
+
array('Missing three digit security code', 'cvv2'));</strong>
|
626 |
+
$controller = new PaymentForm(<strong>$alert</strong>, new MockPaymentGateway());
|
627 |
+
$controller->makePayment($this->requestWithMissingCvv2());
|
628 |
+
}
|
629 |
+
|
630 |
+
function requestWithMissingCvv2() { ... }
|
631 |
+
}
|
632 |
+
?>
|
633 |
+
</pre>
|
634 |
+
The first question you may be asking is, where are the assertions?
|
635 |
+
</p>
|
636 |
+
<p>
|
637 |
+
The call to <span class="new_code">expectOnce('warn', array(...))</span> instructs the mock
|
638 |
+
to expect a call to <span class="new_code">warn()</span> before the test ends.
|
639 |
+
When it gets a call to <span class="new_code">warn()</span>, it checks the arguments.
|
640 |
+
If the arguments don't match, then a failure is generated.
|
641 |
+
It also fails if the method is never called at all.
|
642 |
+
</p>
|
643 |
+
<p>
|
644 |
+
The test above not only asserts that <span class="new_code">warn</span> was called,
|
645 |
+
but that it received the string "Missing three digit security code"
|
646 |
+
and also the tag "cvv2".
|
647 |
+
The equivalent of <span class="new_code">assertIdentical()</span> is applied to both
|
648 |
+
fields when the parameters are compared.
|
649 |
+
</p>
|
650 |
+
<p>
|
651 |
+
If you are not interested in the actual message, and we are not
|
652 |
+
for user interface code that changes often, we can skip that
|
653 |
+
parameter with the "*" operator...
|
654 |
+
<pre>
|
655 |
+
class PaymentFormFailuresShouldBeGraceful extends UnitTestCase {
|
656 |
+
|
657 |
+
function testMissingCvv2CausesAlert() {
|
658 |
+
$alert = new MockAlert();
|
659 |
+
$alert->expectOnce('warn', array(<strong>'*'</strong>, 'cvv2'));
|
660 |
+
$controller = new PaymentForm($alert, new MockPaymentGateway());
|
661 |
+
$controller->makePayment($this->requestWithMissingCvv2());
|
662 |
+
}
|
663 |
+
|
664 |
+
function requestWithMissingCvv2() { ... }
|
665 |
+
}
|
666 |
+
</pre>
|
667 |
+
We can weaken the test further by missing
|
668 |
+
out the parameters array...
|
669 |
+
<pre>
|
670 |
+
function testMissingCvv2CausesAlert() {
|
671 |
+
$alert = new MockAlert();
|
672 |
+
<strong>$alert->expectOnce('warn');</strong>
|
673 |
+
$controller = new PaymentForm($alert, new MockPaymentGateway());
|
674 |
+
$controller->makePayment($this->requestWithMissingCvv2());
|
675 |
+
}
|
676 |
+
</pre>
|
677 |
+
This will only test that the method is called,
|
678 |
+
which is a bit drastic in this case.
|
679 |
+
Later on, we'll see how we can weaken the expectations more precisely.
|
680 |
+
</p>
|
681 |
+
<p>
|
682 |
+
Tests without assertions can be both compact and very expressive.
|
683 |
+
Because we intercept the call on the way into an object, here of
|
684 |
+
the <span class="new_code">Alert</span> class, we avoid having to assert its state
|
685 |
+
afterwards.
|
686 |
+
This not only avoids the assertions in the tests, but also having
|
687 |
+
to add extra test only accessors to the original code.
|
688 |
+
If you catch yourself adding such accessors, called "state based testing",
|
689 |
+
it's probably time to consider using mocks in the tests.
|
690 |
+
This is called "behaviour based testing", and is normally superior.
|
691 |
+
</p>
|
692 |
+
<p>
|
693 |
+
Let's add another test.
|
694 |
+
Let's make sure that we don't even attempt a payment without a CVV2...
|
695 |
+
<pre>
|
696 |
+
class PaymentFormFailuresShouldBeGraceful extends UnitTestCase {
|
697 |
+
|
698 |
+
function testMissingCvv2CausesAlert() { ... }
|
699 |
+
|
700 |
+
function testNoPaymentAttemptedWithMissingCvv2() {
|
701 |
+
$payment_gateway = new MockPaymentGateway();
|
702 |
+
<strong>$payment_gateway->expectNever('pay');</strong>
|
703 |
+
$controller = new PaymentForm(new MockAlert(), $payment_gateway);
|
704 |
+
$controller->makePayment($this->requestWithMissingCvv2());
|
705 |
+
}
|
706 |
+
|
707 |
+
...
|
708 |
+
}
|
709 |
+
</pre>
|
710 |
+
Asserting a negative can be very hard in tests, but
|
711 |
+
<span class="new_code">expectNever()</span> makes it easy.
|
712 |
+
</p>
|
713 |
+
<p>
|
714 |
+
<span class="new_code">expectOnce()</span> and <span class="new_code">expectNever()</span> are
|
715 |
+
sufficient for most tests, but
|
716 |
+
occasionally you want to test multiple events.
|
717 |
+
Normally for usability purposes we want all missing fields
|
718 |
+
in the form to light up, not just the first one.
|
719 |
+
This means that we should get multiple calls to
|
720 |
+
<span class="new_code">Alert::warn()</span>, not just one...
|
721 |
+
<pre>
|
722 |
+
function testAllRequiredFieldsHighlightedOnEmptyRequest() {
|
723 |
+
$alert = new MockAlert();<strong>
|
724 |
+
$alert->expectAt(0, 'warn', array('*', 'cc_number'));
|
725 |
+
$alert->expectAt(1, 'warn', array('*', 'expiry'));
|
726 |
+
$alert->expectAt(2, 'warn', array('*', 'cvv2'));
|
727 |
+
$alert->expectAt(3, 'warn', array('*', 'card_holder'));
|
728 |
+
$alert->expectAt(4, 'warn', array('*', 'address'));
|
729 |
+
$alert->expectAt(5, 'warn', array('*', 'postcode'));
|
730 |
+
$alert->expectAt(6, 'warn', array('*', 'country'));
|
731 |
+
$alert->expectCallCount('warn', 7);</strong>
|
732 |
+
$controller = new PaymentForm($alert, new MockPaymentGateway());
|
733 |
+
$controller->makePayment($this->requestWithMissingCvv2());
|
734 |
+
}
|
735 |
+
</pre>
|
736 |
+
The counter in <span class="new_code">expectAt()</span> is the number of times
|
737 |
+
the method has been called already.
|
738 |
+
Here we are asserting that every field will be highlighted.
|
739 |
+
</p>
|
740 |
+
<p>
|
741 |
+
Note that we are forced to assert the order too.
|
742 |
+
SimpleTest does not yet have a way to avoid this, but
|
743 |
+
this will be fixed in future versions.
|
744 |
+
</p>
|
745 |
+
<p>
|
746 |
+
Here is the full list of expectations you can set on a mock object
|
747 |
+
in <a href="http://simpletest.org/">SimpleTest</a>.
|
748 |
+
As with the assertions, these methods take an optional failure message.
|
749 |
+
<table>
|
750 |
+
<thead><tr>
|
751 |
+
<th>Expectation</th>
|
752 |
+
<th>Description</th>
|
753 |
+
</tr></thead>
|
754 |
+
<tbody>
|
755 |
+
<tr>
|
756 |
+
<td><span class="new_code">expect($method, $args)</span></td>
|
757 |
+
<td>Arguments must match if called</td>
|
758 |
+
</tr>
|
759 |
+
<tr>
|
760 |
+
<td><span class="new_code">expectAt($timing, $method, $args)</span></td>
|
761 |
+
<td>Arguments must match when called on the <span class="new_code">$timing</span>'th time</td>
|
762 |
+
</tr>
|
763 |
+
<tr>
|
764 |
+
<td><span class="new_code">expectCallCount($method, $count)</span></td>
|
765 |
+
<td>The method must be called exactly this many times</td>
|
766 |
+
</tr>
|
767 |
+
<tr>
|
768 |
+
<td><span class="new_code">expectMaximumCallCount($method, $count)</span></td>
|
769 |
+
<td>Call this method no more than <span class="new_code">$count</span> times</td>
|
770 |
+
</tr>
|
771 |
+
<tr>
|
772 |
+
<td><span class="new_code">expectMinimumCallCount($method, $count)</span></td>
|
773 |
+
<td>Must be called at least <span class="new_code">$count</span> times</td>
|
774 |
+
</tr>
|
775 |
+
<tr>
|
776 |
+
<td><span class="new_code">expectNever($method)</span></td>
|
777 |
+
<td>Must never be called</td>
|
778 |
+
</tr>
|
779 |
+
<tr>
|
780 |
+
<td><span class="new_code">expectOnce($method, $args)</span></td>
|
781 |
+
<td>Must be called once and with the expected arguments if supplied</td>
|
782 |
+
</tr>
|
783 |
+
<tr>
|
784 |
+
<td><span class="new_code">expectAtLeastOnce($method, $args)</span></td>
|
785 |
+
<td>Must be called at least once, and always with any expected arguments</td>
|
786 |
+
</tr>
|
787 |
+
</tbody>
|
788 |
+
</table>
|
789 |
+
Where the parameters are...
|
790 |
+
<dl>
|
791 |
+
<dt class="new_code">$method</dt>
|
792 |
+
<dd>The method name, as a string, to apply the condition to.</dd>
|
793 |
+
<dt class="new_code">$args</dt>
|
794 |
+
<dd>
|
795 |
+
The arguments as a list. Wildcards can be included in the same
|
796 |
+
manner as for <span class="new_code">setReturn()</span>.
|
797 |
+
This argument is optional for <span class="new_code">expectOnce()</span>
|
798 |
+
and <span class="new_code">expectAtLeastOnce()</span>.
|
799 |
+
</dd>
|
800 |
+
<dt class="new_code">$timing</dt>
|
801 |
+
<dd>
|
802 |
+
The only point in time to test the condition.
|
803 |
+
The first call starts at zero and the count is for
|
804 |
+
each method independently.
|
805 |
+
</dd>
|
806 |
+
<dt class="new_code">$count</dt>
|
807 |
+
<dd>The number of calls expected.</dd>
|
808 |
+
</dl>
|
809 |
+
</p>
|
810 |
+
<p>
|
811 |
+
If you have just one call in your test, make sure you're using
|
812 |
+
<span class="new_code">expectOnce</span>.<br>
|
813 |
+
Using <span class="new_code">$mocked->expectAt(0, 'method', 'args);</span>
|
814 |
+
on its own will allow the method to never be called.
|
815 |
+
Checking the arguments and the overall call count
|
816 |
+
are currently independant.
|
817 |
+
Add an <span class="new_code">expectCallCount()</span> expectation when you
|
818 |
+
are using <span class="new_code">expectAt()</span> unless zero calls is allowed.
|
819 |
+
</p>
|
820 |
+
<p>
|
821 |
+
Like the assertions within test cases, all of the expectations
|
822 |
+
can take a message override as an extra parameter.
|
823 |
+
Also the original failure message can be embedded in the output
|
824 |
+
as "%s".
|
825 |
+
</p>
|
826 |
+
|
827 |
+
</div>
|
828 |
+
References and related information...
|
829 |
+
<ul>
|
830 |
+
<li>
|
831 |
+
The original
|
832 |
+
<a href="http://www.mockobjects.com/">Mock objects</a> paper.
|
833 |
+
</li>
|
834 |
+
<li>
|
835 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
836 |
+
</li>
|
837 |
+
<li>
|
838 |
+
SimpleTest home page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
839 |
+
</li>
|
840 |
+
</ul>
|
841 |
+
<div class="menu_back"><div class="menu">
|
842 |
+
<a href="index.html">SimpleTest</a>
|
843 |
+
|
|
844 |
+
<a href="overview.html">Overview</a>
|
845 |
+
|
|
846 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
847 |
+
|
|
848 |
+
<a href="group_test_documentation.html">Group tests</a>
|
849 |
+
|
|
850 |
+
<span class="chosen">Mock objects</span>
|
851 |
+
|
|
852 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
853 |
+
|
|
854 |
+
<a href="reporter_documentation.html">Reporting</a>
|
855 |
+
|
|
856 |
+
<a href="expectation_documentation.html">Expectations</a>
|
857 |
+
|
|
858 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
859 |
+
|
|
860 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
861 |
+
|
|
862 |
+
<a href="authentication_documentation.html">Authentication</a>
|
863 |
+
|
|
864 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
865 |
+
</div></div>
|
866 |
+
<div class="copyright">
|
867 |
+
Copyright<br>Marcus Baker 2006
|
868 |
+
</div>
|
869 |
+
</body>
|
870 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/overview.html
ADDED
@@ -0,0 +1,487 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>
|
5 |
+
Overview and feature list for the SimpleTest PHP unit tester and web tester
|
6 |
+
</title>
|
7 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<div class="menu_back"><div class="menu">
|
11 |
+
<a href="index.html">SimpleTest</a>
|
12 |
+
|
|
13 |
+
<span class="chosen">Overview</span>
|
14 |
+
|
|
15 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
16 |
+
|
|
17 |
+
<a href="group_test_documentation.html">Group tests</a>
|
18 |
+
|
|
19 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
20 |
+
|
|
21 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
22 |
+
|
|
23 |
+
<a href="reporter_documentation.html">Reporting</a>
|
24 |
+
|
|
25 |
+
<a href="expectation_documentation.html">Expectations</a>
|
26 |
+
|
|
27 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
28 |
+
|
|
29 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
30 |
+
|
|
31 |
+
<a href="authentication_documentation.html">Authentication</a>
|
32 |
+
|
|
33 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
34 |
+
</div></div>
|
35 |
+
<h1>Overview of SimpleTest</h1>
|
36 |
+
This page...
|
37 |
+
<ul>
|
38 |
+
<li>
|
39 |
+
<a href="#summary">Quick summary</a>
|
40 |
+
of the SimpleTest tool for PHP.
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
<a href="#features">List of features</a>,
|
44 |
+
both current ones and those planned.
|
45 |
+
</li>
|
46 |
+
</ul>
|
47 |
+
<div class="content">
|
48 |
+
<h2>
|
49 |
+
<a class="target" name="summary"></a>What is SimpleTest?</h2>
|
50 |
+
<p>
|
51 |
+
The heart of SimpleTest is a testing framework built around
|
52 |
+
test case classes.
|
53 |
+
These are written as extensions of base test case classes,
|
54 |
+
each extended with methods that actually contain test code.
|
55 |
+
Each test method of a test case class is written to invoke
|
56 |
+
various assertions that the developer expects to be true such as
|
57 |
+
<span class="new_code">assertEqual()</span>.
|
58 |
+
If the expectation is correct, then a successful result is
|
59 |
+
dispatched to the observing test reporter, but any failure
|
60 |
+
or unexpected exception triggers an alert and a description
|
61 |
+
of the mismatch.
|
62 |
+
These test case declarations are transformed into executable
|
63 |
+
test scripts by including a SimpleTest aurorun.php file.
|
64 |
+
</p>
|
65 |
+
<p>
|
66 |
+
These documents apply to SimpleTest version 1.1, although we
|
67 |
+
try hard to maintain compatibility between versions.
|
68 |
+
If you get a test failure after an upgrade, check out the
|
69 |
+
file "HELP_MY_TESTS_DONT_WORK_ANYMORE" in the
|
70 |
+
simpletest directory to see if a feature you are using
|
71 |
+
has since been deprecated and later removed.
|
72 |
+
</p>
|
73 |
+
<p>
|
74 |
+
A <a href="unit_test_documentation.html">test case</a> looks like this...
|
75 |
+
<pre>
|
76 |
+
<?php
|
77 |
+
require_once('simpletest/autorun.php');
|
78 |
+
|
79 |
+
class <strong>CanAddUp</strong> extends UnitTestCase {<strong>
|
80 |
+
function testOneAndOneMakesTwo() {
|
81 |
+
$this->assertEqual(1 + 1, 2);
|
82 |
+
}</strong>
|
83 |
+
}
|
84 |
+
?>
|
85 |
+
</pre>
|
86 |
+
Tests are grouped into test cases, which are just
|
87 |
+
PHP classes that extend <span class="new_code">UnitTestCase</span>
|
88 |
+
or <span class="new_code">WebTestCase</span>.
|
89 |
+
The tests themselves are just normal methods that start
|
90 |
+
their name with the letters "test".
|
91 |
+
You can have as many test cases as you want in a test
|
92 |
+
script and each test case can have as many test methods
|
93 |
+
as it wants too.
|
94 |
+
</p>
|
95 |
+
<p>
|
96 |
+
This test script is immediately runnable.
|
97 |
+
You just invoke it on the command line like so...
|
98 |
+
<pre class="shell">
|
99 |
+
php adding_test.php
|
100 |
+
</pre>
|
101 |
+
</p>
|
102 |
+
<p>
|
103 |
+
When run on the command line you should see something like...
|
104 |
+
<pre class="shell">
|
105 |
+
adding_test.php
|
106 |
+
OK
|
107 |
+
Test cases run: 1/1, Passes: 1, Failures: 0, Exceptions: 0
|
108 |
+
</pre>
|
109 |
+
</p>
|
110 |
+
<p>
|
111 |
+
If you place it on a web server and point your
|
112 |
+
web browser at it...
|
113 |
+
<div class="demo">
|
114 |
+
<h1>adding_test.php</h1>
|
115 |
+
<div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">1/1 test cases complete.
|
116 |
+
<strong>6</strong> passes, <strong>0</strong> fails and <strong>0</strong> exceptions.</div>
|
117 |
+
</div>
|
118 |
+
</p>
|
119 |
+
<p>
|
120 |
+
Of course this is a silly example.
|
121 |
+
A more realistic example might be...
|
122 |
+
<pre>
|
123 |
+
<?php
|
124 |
+
require_once('simpletest/autorun.php');
|
125 |
+
require_once('log.php');
|
126 |
+
|
127 |
+
class <strong>TestOfLogging</strong> extends UnitTestCase {
|
128 |
+
function testWillCreateLogFileOnFirstMessage() {
|
129 |
+
$log = new Log('my.log');
|
130 |
+
$this->assertFalse(file_exists('my.log'));
|
131 |
+
$log->message('Hello');
|
132 |
+
$this->assertTrue(file_exists('my.log'));
|
133 |
+
}</strong>
|
134 |
+
}
|
135 |
+
?>
|
136 |
+
</pre>
|
137 |
+
</p>
|
138 |
+
<p>
|
139 |
+
This tool is designed for the developer.
|
140 |
+
The target audience of this tool is anyone developing a small
|
141 |
+
to medium PHP application, including developers new to
|
142 |
+
unit and web regression testing.
|
143 |
+
The core principles are ease of use first, with extendibility and
|
144 |
+
essential features.
|
145 |
+
</p>
|
146 |
+
<p>
|
147 |
+
Tests are written in the PHP language itself more or less
|
148 |
+
as the application itself is built.
|
149 |
+
The advantage of using PHP as the testing language is that
|
150 |
+
there are no new languages to learn, testing can start straight away,
|
151 |
+
and the developer can test any part of the code.
|
152 |
+
Basically, all parts that can be accessed by the application code can also be
|
153 |
+
accessed by the test code when they are in the same programming language.
|
154 |
+
</p>
|
155 |
+
<p>
|
156 |
+
The simplest type of test case is the
|
157 |
+
<a href="unit_tester_documentation.html">UnitTestCase</a>.
|
158 |
+
This class of test case includes standard tests for equality,
|
159 |
+
references and pattern matching.
|
160 |
+
All these test the typical expectations of what you would
|
161 |
+
expect the result of a function or method to be.
|
162 |
+
This is by far the most common type of test in the daily
|
163 |
+
routine of development, making up about 95% of test cases.
|
164 |
+
</p>
|
165 |
+
<p>
|
166 |
+
The top level task of a web application though is not to
|
167 |
+
produce correct output from its methods and objects, but
|
168 |
+
to generate web pages.
|
169 |
+
The <a href="web_tester_documentation.html">WebTestCase</a> class tests web
|
170 |
+
pages.
|
171 |
+
It simulates a web browser requesting a page, complete with
|
172 |
+
cookies, proxies, secure connections, authentication, forms, frames and most
|
173 |
+
navigation elements.
|
174 |
+
With this type of test case, the developer can assert that
|
175 |
+
information is present in the page and that forms and
|
176 |
+
sessions are handled correctly.
|
177 |
+
</p>
|
178 |
+
<p>
|
179 |
+
A <a href="web_tester_documentation.html">WebTestCase</a> looks like this...
|
180 |
+
<pre>
|
181 |
+
<?php
|
182 |
+
require_once('simpletest/autorun.php');
|
183 |
+
require_once('simpletest/web_tester.php');
|
184 |
+
|
185 |
+
class <strong>MySiteTest</strong> extends WebTestCase {
|
186 |
+
<strong>
|
187 |
+
function testHomePageHasContactDetailsLink() {
|
188 |
+
$this->get('http://www.my-site.com/index.php');
|
189 |
+
$this->assertTitle('My Home Page');
|
190 |
+
$this->clickLink('Contact');
|
191 |
+
$this->assertTitle('Contact me');
|
192 |
+
$this->assertText('/Email me at/');
|
193 |
+
}</strong>
|
194 |
+
}
|
195 |
+
?>
|
196 |
+
</pre>
|
197 |
+
</p>
|
198 |
+
|
199 |
+
<h2>
|
200 |
+
<a class="target" name="features"></a>Feature list</h2>
|
201 |
+
<p>
|
202 |
+
The following is a very rough outline of past and future features
|
203 |
+
and their expected point of release.
|
204 |
+
I am afraid it is liable to change without warning, as meeting the
|
205 |
+
milestones rather depends on time available.
|
206 |
+
</p>
|
207 |
+
<p>
|
208 |
+
Green stuff has been coded, but not necessarily released yet.
|
209 |
+
If you have a pressing need for a green but unreleased feature
|
210 |
+
then you should check-out the code from Sourceforge SVN directly.
|
211 |
+
<table>
|
212 |
+
<thead>
|
213 |
+
<tr>
|
214 |
+
<th>Feature</th>
|
215 |
+
<th>Description</th>
|
216 |
+
<th>Release</th>
|
217 |
+
</tr>
|
218 |
+
</thead>
|
219 |
+
<tbody>
|
220 |
+
<tr>
|
221 |
+
<td>Unit test case</td>
|
222 |
+
<td>Core test case class and assertions</td>
|
223 |
+
<td style="color: green;">1.0</td>
|
224 |
+
</tr>
|
225 |
+
<tr>
|
226 |
+
<td>Html display</td>
|
227 |
+
<td>Simplest possible display</td>
|
228 |
+
<td style="color: green;">1.0</td>
|
229 |
+
</tr>
|
230 |
+
<tr>
|
231 |
+
<td>Autoloading of test cases</td>
|
232 |
+
<td>
|
233 |
+
Reading a file with test cases and loading them into a
|
234 |
+
group test automatically
|
235 |
+
</td>
|
236 |
+
<td style="color: green;">1.0</td>
|
237 |
+
</tr>
|
238 |
+
<tr>
|
239 |
+
<td>Mock objects</td>
|
240 |
+
<td>
|
241 |
+
Objects capable of simulating other objects removing
|
242 |
+
test dependencies
|
243 |
+
</td>
|
244 |
+
<td style="color: green;">1.0</td>
|
245 |
+
</tr>
|
246 |
+
<tr>
|
247 |
+
<td>Web test case</td>
|
248 |
+
<td>Allows link following and title tag matching</td>
|
249 |
+
<td style="color: green;">1.0</td>
|
250 |
+
</tr>
|
251 |
+
<tr>
|
252 |
+
<td>Partial mocks</td>
|
253 |
+
<td>
|
254 |
+
Mocking parts of a class for testing less than a class
|
255 |
+
or for complex simulations
|
256 |
+
</td>
|
257 |
+
<td style="color: green;">1.0</td>
|
258 |
+
</tr>
|
259 |
+
<tr>
|
260 |
+
<td>Web cookie handling</td>
|
261 |
+
<td>Correct handling of cookies when fetching pages</td>
|
262 |
+
<td style="color: green;">1.0</td>
|
263 |
+
</tr>
|
264 |
+
<tr>
|
265 |
+
<td>Following redirects</td>
|
266 |
+
<td>Page fetching automatically follows 300 redirects</td>
|
267 |
+
<td style="color: green;">1.0</td>
|
268 |
+
</tr>
|
269 |
+
<tr>
|
270 |
+
<td>Form parsing</td>
|
271 |
+
<td>Ability to submit simple forms and read default form values</td>
|
272 |
+
<td style="color: green;">1.0</td>
|
273 |
+
</tr>
|
274 |
+
<tr>
|
275 |
+
<td>Command line interface</td>
|
276 |
+
<td>Test display without the need of a web browser</td>
|
277 |
+
<td style="color: green;">1.0</td>
|
278 |
+
</tr>
|
279 |
+
<tr>
|
280 |
+
<td>Exposure of expectation classes</td>
|
281 |
+
<td>Can create precise tests with mocks as well as test cases</td>
|
282 |
+
<td style="color: green;">1.0</td>
|
283 |
+
</tr>
|
284 |
+
<tr>
|
285 |
+
<td>XML output and parsing</td>
|
286 |
+
<td>
|
287 |
+
Allows multi host testing and the integration of acceptance
|
288 |
+
testing extensions
|
289 |
+
</td>
|
290 |
+
<td style="color: green;">1.0</td>
|
291 |
+
</tr>
|
292 |
+
<tr>
|
293 |
+
<td>Browser component</td>
|
294 |
+
<td>
|
295 |
+
Exposure of lower level web browser interface for more
|
296 |
+
detailed test cases
|
297 |
+
</td>
|
298 |
+
<td style="color: green;">1.0</td>
|
299 |
+
</tr>
|
300 |
+
<tr>
|
301 |
+
<td>HTTP authentication</td>
|
302 |
+
<td>
|
303 |
+
Fetching protected web pages with basic authentication
|
304 |
+
only
|
305 |
+
</td>
|
306 |
+
<td style="color: green;">1.0</td>
|
307 |
+
</tr>
|
308 |
+
<tr>
|
309 |
+
<td>SSL support</td>
|
310 |
+
<td>Can connect to https: pages</td>
|
311 |
+
<td style="color: green;">1.0</td>
|
312 |
+
</tr>
|
313 |
+
<tr>
|
314 |
+
<td>Proxy support</td>
|
315 |
+
<td>Can connect via. common proxies</td>
|
316 |
+
<td style="color: green;">1.0</td>
|
317 |
+
</tr>
|
318 |
+
<tr>
|
319 |
+
<td>Frames support</td>
|
320 |
+
<td>Handling of frames in web test cases</td>
|
321 |
+
<td style="color: green;">1.0</td>
|
322 |
+
</tr>
|
323 |
+
<tr>
|
324 |
+
<td>File upload testing</td>
|
325 |
+
<td>Can simulate the input type file tag</td>
|
326 |
+
<td style="color: green;">1.0.1</td>
|
327 |
+
</tr>
|
328 |
+
<tr>
|
329 |
+
<td>Mocking interfaces</td>
|
330 |
+
<td>
|
331 |
+
Can generate mock objects to interfaces as well as classes
|
332 |
+
and class interfaces are carried for type hints
|
333 |
+
</td>
|
334 |
+
<td style="color: green;">1.0.1</td>
|
335 |
+
</tr>
|
336 |
+
<tr>
|
337 |
+
<td>Testing exceptions</td>
|
338 |
+
<td>Similar to testing PHP errors</td>
|
339 |
+
<td style="color: green;">1.0.1</td>
|
340 |
+
</tr>
|
341 |
+
<tr>
|
342 |
+
<td>HTML label support</td>
|
343 |
+
<td>Can access all controls using the visual label</td>
|
344 |
+
<td style="color: green;">1.0.1</td>
|
345 |
+
</tr>
|
346 |
+
<tr>
|
347 |
+
<td>Base tag support</td>
|
348 |
+
<td>Respects page base tag when clicking</td>
|
349 |
+
<td style="color: green;">1.0.1</td>
|
350 |
+
</tr>
|
351 |
+
<tr>
|
352 |
+
<td>PHP 5 E_STRICT compliant</td>
|
353 |
+
<td>PHP 5 only version that works with the E_STRICT error level</td>
|
354 |
+
<td style="color: green;">1.1</td>
|
355 |
+
</tr>
|
356 |
+
<tr>
|
357 |
+
<td>Alternate HTML parsers</td>
|
358 |
+
<td>Can detect compiled parsers for performance improvements</td>
|
359 |
+
<td style="color: green;">1.1</td>
|
360 |
+
</tr>
|
361 |
+
<tr>
|
362 |
+
<td>REST support</td>
|
363 |
+
<td>Support for REST verbs as put(), delete(), etc.</td>
|
364 |
+
<td style="color: green;">1.1</td>
|
365 |
+
</tr>
|
366 |
+
<tr>
|
367 |
+
<td>BDD style fixtures</td>
|
368 |
+
<td>Can import fixtures using a mixin like given() method</td>
|
369 |
+
<td style="color: red;">1.5</td>
|
370 |
+
</tr>
|
371 |
+
<tr>
|
372 |
+
<td>Plug-in architecture</td>
|
373 |
+
<td>Automatic import of extensions including command line options</td>
|
374 |
+
<td style="color: red;">1.5</td>
|
375 |
+
</tr>
|
376 |
+
<tr>
|
377 |
+
<td>Reporting machinery enhancements</td>
|
378 |
+
<td>Improved message passing for better cooperation with IDEs</td>
|
379 |
+
<td style="color: red;">1.5</td>
|
380 |
+
</tr>
|
381 |
+
<tr>
|
382 |
+
<td>Fluent mock interface</td>
|
383 |
+
<td>More flexible and concise mock objects</td>
|
384 |
+
<td style="color: red;">1.6</td>
|
385 |
+
</tr>
|
386 |
+
<tr>
|
387 |
+
<td>Localisation</td>
|
388 |
+
<td>Messages abstracted and code generated as well as UTF support</td>
|
389 |
+
<td style="color: red;">1.6</td>
|
390 |
+
</tr>
|
391 |
+
<tr>
|
392 |
+
<td>CSS selectors</td>
|
393 |
+
<td>HTML content can be examined using CSS selectors</td>
|
394 |
+
<td style="color: red;">1.7</td>
|
395 |
+
</tr>
|
396 |
+
<tr>
|
397 |
+
<td>HTML table assertions</td>
|
398 |
+
<td>Can match HTML or other table elements to expectations</td>
|
399 |
+
<td style="color: red;">1.7</td>
|
400 |
+
</tr>
|
401 |
+
<tr>
|
402 |
+
<td>Unified acceptance testing model</td>
|
403 |
+
<td>Content searchable through selectors combined with expectations</td>
|
404 |
+
<td style="color: red;">1.7</td>
|
405 |
+
</tr>
|
406 |
+
<tr>
|
407 |
+
<td>DatabaseTestCase</td>
|
408 |
+
<td>SQL selectors and DB drivers</td>
|
409 |
+
<td style="color: red;">1.7</td>
|
410 |
+
</tr>
|
411 |
+
<tr>
|
412 |
+
<td>IFrame support</td>
|
413 |
+
<td>Reads IFrame content that can be refreshed</td>
|
414 |
+
<td style="color: red;">1.8</td>
|
415 |
+
</tr>
|
416 |
+
<tr>
|
417 |
+
<td>Integrated Selenium support</td>
|
418 |
+
<td>Easy to use built in Selenium driver and tutorial or similar browser automation</td>
|
419 |
+
<td style="color: red;">1.9</td>
|
420 |
+
</tr>
|
421 |
+
<tr>
|
422 |
+
<td>Code coverage</td>
|
423 |
+
<td>Reports using the bundled tool when using XDebug</td>
|
424 |
+
<td style="color: red;">1.9</td>
|
425 |
+
</tr>
|
426 |
+
<tr>
|
427 |
+
<td>Deprecation of old methods</td>
|
428 |
+
<td>Simpler interface for SimpleTest2</td>
|
429 |
+
<td style="color: red;">2.0</td>
|
430 |
+
</tr>
|
431 |
+
<tr>
|
432 |
+
<td>Javascript suport</td>
|
433 |
+
<td>Use of PECL module to add Javascript to the native browser</td>
|
434 |
+
<td style="color: red;">3.0</td>
|
435 |
+
</tr>
|
436 |
+
</tbody>
|
437 |
+
</table>
|
438 |
+
PHP 5 migration is complete, which means that only PHP 5.0.3+
|
439 |
+
will be supported in SimpleTest version 1.1+.
|
440 |
+
Earlier versions of SimpleTest are compatible with PHP 4.2 up to
|
441 |
+
PHP 5 (non E_STRICT).
|
442 |
+
</p>
|
443 |
+
|
444 |
+
</div>
|
445 |
+
References and related information...
|
446 |
+
<ul>
|
447 |
+
<li>
|
448 |
+
<a href="unit_test_documentation.html">Documentation for SimpleTest</a>.
|
449 |
+
</li>
|
450 |
+
<li>
|
451 |
+
<a href="http://www.lastcraft.com/first_test_tutorial.php">How to write PHP test cases</a>
|
452 |
+
is a fairly advanced tutorial.
|
453 |
+
</li>
|
454 |
+
<li>
|
455 |
+
<a href="http://simpletest.org/api/">SimpleTest API</a> from phpdoc.
|
456 |
+
</li>
|
457 |
+
</ul>
|
458 |
+
<div class="menu_back"><div class="menu">
|
459 |
+
<a href="index.html">SimpleTest</a>
|
460 |
+
|
|
461 |
+
<span class="chosen">Overview</span>
|
462 |
+
|
|
463 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
464 |
+
|
|
465 |
+
<a href="group_test_documentation.html">Group tests</a>
|
466 |
+
|
|
467 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
468 |
+
|
|
469 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
470 |
+
|
|
471 |
+
<a href="reporter_documentation.html">Reporting</a>
|
472 |
+
|
|
473 |
+
<a href="expectation_documentation.html">Expectations</a>
|
474 |
+
|
|
475 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
476 |
+
|
|
477 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
478 |
+
|
|
479 |
+
<a href="authentication_documentation.html">Authentication</a>
|
480 |
+
|
|
481 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
482 |
+
</div></div>
|
483 |
+
<div class="copyright">
|
484 |
+
Copyright<br>Marcus Baker 2006
|
485 |
+
</div>
|
486 |
+
</body>
|
487 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/partial_mocks_documentation.html
ADDED
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest for PHP partial mocks documentation</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<span class="chosen">Partial mocks</span>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Partial mock objects documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
<a href="#inject">The mock injection problem</a>.
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
Moving creation to a <a href="#creation">protected factory</a> method.
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
<a href="#partial">Partial mocks</a> generate subclasses.
|
44 |
+
</li>
|
45 |
+
<li>
|
46 |
+
Partial mocks <a href="#less">test less than a class</a>.
|
47 |
+
</li>
|
48 |
+
</ul>
|
49 |
+
<div class="content">
|
50 |
+
|
51 |
+
<p>
|
52 |
+
A partial mock is simply a pattern to alleviate a specific problem
|
53 |
+
in testing with mock objects,
|
54 |
+
that of getting mock objects into tight corners.
|
55 |
+
It's quite a limited tool and possibly not even a good idea.
|
56 |
+
It is included with SimpleTest because I have found it useful
|
57 |
+
on more than one occasion and has saved a lot of work at that point.
|
58 |
+
</p>
|
59 |
+
|
60 |
+
<h2>
|
61 |
+
<a class="target" name="inject"></a>The mock injection problem</h2>
|
62 |
+
<p>
|
63 |
+
When one object uses another it is very simple to just pass a mock
|
64 |
+
version in already set up with its expectations.
|
65 |
+
Things are rather tricker if one object creates another and the
|
66 |
+
creator is the one you want to test.
|
67 |
+
This means that the created object should be mocked, but we can
|
68 |
+
hardly tell our class under test to create a mock instead.
|
69 |
+
The tested class doesn't even know it is running inside a test
|
70 |
+
after all.
|
71 |
+
</p>
|
72 |
+
<p>
|
73 |
+
For example, suppose we are building a telnet client and it
|
74 |
+
needs to create a network socket to pass its messages.
|
75 |
+
The connection method might look something like...
|
76 |
+
<pre>
|
77 |
+
<strong><?php
|
78 |
+
require_once('socket.php');
|
79 |
+
|
80 |
+
class Telnet {
|
81 |
+
...
|
82 |
+
function connect($ip, $port, $username, $password) {
|
83 |
+
$socket = new Socket($ip, $port);
|
84 |
+
$socket->read( ... );
|
85 |
+
...
|
86 |
+
}
|
87 |
+
}
|
88 |
+
?></strong>
|
89 |
+
</pre>
|
90 |
+
We would really like to have a mock object version of the socket
|
91 |
+
here, what can we do?
|
92 |
+
</p>
|
93 |
+
<p>
|
94 |
+
The first solution is to pass the socket in as a parameter,
|
95 |
+
forcing the creation up a level.
|
96 |
+
Having the client handle this is actually a very good approach
|
97 |
+
if you can manage it and should lead to factoring the creation from
|
98 |
+
the doing.
|
99 |
+
In fact, this is one way in which testing with mock objects actually
|
100 |
+
forces you to code more tightly focused solutions.
|
101 |
+
They improve your programming.
|
102 |
+
</p>
|
103 |
+
<p>
|
104 |
+
Here this would be...
|
105 |
+
<pre>
|
106 |
+
<?php
|
107 |
+
require_once('socket.php');
|
108 |
+
|
109 |
+
class Telnet {
|
110 |
+
...
|
111 |
+
<strong>function connect($socket, $username, $password) {
|
112 |
+
$socket->read( ... );
|
113 |
+
...
|
114 |
+
}</strong>
|
115 |
+
}
|
116 |
+
?>
|
117 |
+
</pre>
|
118 |
+
This means that the test code is typical for a test involving
|
119 |
+
mock objects.
|
120 |
+
<pre>
|
121 |
+
class TelnetTest extends UnitTestCase {
|
122 |
+
...
|
123 |
+
function testConnection() {<strong>
|
124 |
+
$socket = new MockSocket();
|
125 |
+
...
|
126 |
+
$telnet = new Telnet();
|
127 |
+
$telnet->connect($socket, 'Me', 'Secret');
|
128 |
+
...</strong>
|
129 |
+
}
|
130 |
+
}
|
131 |
+
</pre>
|
132 |
+
It is pretty obvious though that one level is all you can go.
|
133 |
+
You would hardly want your top level application creating
|
134 |
+
every low level file, socket and database connection ever
|
135 |
+
needed.
|
136 |
+
It wouldn't know the constructor parameters anyway.
|
137 |
+
</p>
|
138 |
+
<p>
|
139 |
+
The next simplest compromise is to have the created object passed
|
140 |
+
in as an optional parameter...
|
141 |
+
<pre>
|
142 |
+
<?php
|
143 |
+
require_once('socket.php');
|
144 |
+
|
145 |
+
class Telnet {
|
146 |
+
...<strong>
|
147 |
+
function connect($ip, $port, $username, $password, $socket = false) {
|
148 |
+
if (! $socket) {
|
149 |
+
$socket = new Socket($ip, $port);
|
150 |
+
}
|
151 |
+
$socket->read( ... );</strong>
|
152 |
+
...
|
153 |
+
return $socket;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
?>
|
157 |
+
</pre>
|
158 |
+
For a quick solution this is usually good enough.
|
159 |
+
The test now looks almost the same as if the parameter
|
160 |
+
was formally passed...
|
161 |
+
<pre>
|
162 |
+
class TelnetTest extends UnitTestCase {
|
163 |
+
...
|
164 |
+
function testConnection() {<strong>
|
165 |
+
$socket = new MockSocket();
|
166 |
+
...
|
167 |
+
$telnet = new Telnet();
|
168 |
+
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret', $socket);
|
169 |
+
...</strong>
|
170 |
+
}
|
171 |
+
}
|
172 |
+
</pre>
|
173 |
+
The problem with this approach is its untidiness.
|
174 |
+
There is test code in the main class and parameters passed
|
175 |
+
in the test case that are never used.
|
176 |
+
This is a quick and dirty approach, but nevertheless effective
|
177 |
+
in most situations.
|
178 |
+
</p>
|
179 |
+
<p>
|
180 |
+
The next method is to pass in a factory object to do the creation...
|
181 |
+
<pre>
|
182 |
+
<?php
|
183 |
+
require_once('socket.php');
|
184 |
+
|
185 |
+
class Telnet {<strong>
|
186 |
+
function Telnet($network) {
|
187 |
+
$this->_network = $network;
|
188 |
+
}</strong>
|
189 |
+
...
|
190 |
+
function connect($ip, $port, $username, $password) {<strong>
|
191 |
+
$socket = $this->_network->createSocket($ip, $port);
|
192 |
+
$socket->read( ... );</strong>
|
193 |
+
...
|
194 |
+
return $socket;
|
195 |
+
}
|
196 |
+
}
|
197 |
+
?>
|
198 |
+
</pre>
|
199 |
+
This is probably the most highly factored answer as creation
|
200 |
+
is now moved into a small specialist class.
|
201 |
+
The networking factory can now be tested separately, but mocked
|
202 |
+
easily when we are testing the telnet class...
|
203 |
+
<pre>
|
204 |
+
class TelnetTest extends UnitTestCase {
|
205 |
+
...
|
206 |
+
function testConnection() {<strong>
|
207 |
+
$socket = new MockSocket();
|
208 |
+
...
|
209 |
+
$network = new MockNetwork();
|
210 |
+
$network->returnsByReference('createSocket', $socket);
|
211 |
+
$telnet = new Telnet($network);
|
212 |
+
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');</strong>
|
213 |
+
}
|
214 |
+
}
|
215 |
+
</pre>
|
216 |
+
The downside is that we are adding a lot more classes to the
|
217 |
+
library.
|
218 |
+
Also we are passing a lot of factories around which will
|
219 |
+
make the code a little less intuitive.
|
220 |
+
The most flexible solution, but the most complex.
|
221 |
+
</p>
|
222 |
+
<p>
|
223 |
+
Well techniques like "Dependency Injection" tackle the problem of
|
224 |
+
instantiating a lot of constructor parameters.
|
225 |
+
Unfortunately knowledge of this pattern is not widespread, and if you
|
226 |
+
are trying to get older code to work, rearchitecting the whole
|
227 |
+
application is not really an option.
|
228 |
+
</p>
|
229 |
+
<p>
|
230 |
+
Is there a middle ground?
|
231 |
+
</p>
|
232 |
+
|
233 |
+
<h2>
|
234 |
+
<a class="target" name="creation"></a>Protected factory method</h2>
|
235 |
+
<p>
|
236 |
+
There is a way we can circumvent the problem without creating
|
237 |
+
any new application classes, but it involves creating a subclass
|
238 |
+
when we do the actual testing.
|
239 |
+
Firstly we move the socket creation into its own method...
|
240 |
+
<pre>
|
241 |
+
<?php
|
242 |
+
require_once('socket.php');
|
243 |
+
|
244 |
+
class Telnet {
|
245 |
+
...
|
246 |
+
function connect($ip, $port, $username, $password) {
|
247 |
+
<strong>$socket = $this->createSocket($ip, $port);</strong>
|
248 |
+
$socket->read( ... );
|
249 |
+
...
|
250 |
+
}<strong>
|
251 |
+
|
252 |
+
protected function createSocket($ip, $port) {
|
253 |
+
return new Socket($ip, $port);
|
254 |
+
}</strong>
|
255 |
+
}
|
256 |
+
?>
|
257 |
+
</pre>
|
258 |
+
This is a pretty safe step even for very tangled legacy code.
|
259 |
+
This is the only change we make to the application.
|
260 |
+
</p>
|
261 |
+
<p>
|
262 |
+
For the test case we have to create a subclass so that
|
263 |
+
we can intercept the socket creation...
|
264 |
+
<pre>
|
265 |
+
<strong>class TelnetTestVersion extends Telnet {
|
266 |
+
var $mock;
|
267 |
+
|
268 |
+
function TelnetTestVersion($mock) {
|
269 |
+
$this->mock = $mock;
|
270 |
+
$this->Telnet();
|
271 |
+
}
|
272 |
+
|
273 |
+
protected function createSocket() {
|
274 |
+
return $this->mock;
|
275 |
+
}
|
276 |
+
}</strong>
|
277 |
+
</pre>
|
278 |
+
Here I have passed the mock in the constructor, but a
|
279 |
+
setter would have done just as well.
|
280 |
+
Note that the mock was set into the object variable
|
281 |
+
before the constructor was chained.
|
282 |
+
This is necessary in case the constructor calls
|
283 |
+
<span class="new_code">connect()</span>.
|
284 |
+
Otherwise it could get a null value from
|
285 |
+
<span class="new_code">createSocket()</span>.
|
286 |
+
</p>
|
287 |
+
<p>
|
288 |
+
After the completion of all of this extra work the
|
289 |
+
actual test case is fairly easy.
|
290 |
+
We just test our new class instead...
|
291 |
+
<pre>
|
292 |
+
class TelnetTest extends UnitTestCase {
|
293 |
+
...
|
294 |
+
function testConnection() {<strong>
|
295 |
+
$socket = new MockSocket();
|
296 |
+
...
|
297 |
+
$telnet = new TelnetTestVersion($socket);
|
298 |
+
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');</strong>
|
299 |
+
}
|
300 |
+
}
|
301 |
+
</pre>
|
302 |
+
The new class is very simple of course.
|
303 |
+
It just sets up a return value, rather like a mock.
|
304 |
+
It would be nice if it also checked the incoming parameters
|
305 |
+
as well.
|
306 |
+
Just like a mock.
|
307 |
+
It seems we are likely to do this often, can
|
308 |
+
we automate the subclass creation?
|
309 |
+
</p>
|
310 |
+
|
311 |
+
<h2>
|
312 |
+
<a class="target" name="partial"></a>A partial mock</h2>
|
313 |
+
<p>
|
314 |
+
Of course the answer is "yes" or I would have stopped writing
|
315 |
+
this by now!
|
316 |
+
The previous test case was a lot of work, but we can
|
317 |
+
generate the subclass using a similar approach to the mock objects.
|
318 |
+
</p>
|
319 |
+
<p>
|
320 |
+
Here is the partial mock version of the test...
|
321 |
+
<pre>
|
322 |
+
<strong>Mock::generatePartial(
|
323 |
+
'Telnet',
|
324 |
+
'TelnetTestVersion',
|
325 |
+
array('createSocket'));</strong>
|
326 |
+
|
327 |
+
class TelnetTest extends UnitTestCase {
|
328 |
+
...
|
329 |
+
function testConnection() {<strong>
|
330 |
+
$socket = new MockSocket();
|
331 |
+
...
|
332 |
+
$telnet = new TelnetTestVersion();
|
333 |
+
$telnet->setReturnReference('createSocket', $socket);
|
334 |
+
$telnet->Telnet();
|
335 |
+
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');</strong>
|
336 |
+
}
|
337 |
+
}
|
338 |
+
</pre>
|
339 |
+
The partial mock is a subclass of the original with
|
340 |
+
selected methods "knocked out" with test
|
341 |
+
versions.
|
342 |
+
The <span class="new_code">generatePartial()</span> call
|
343 |
+
takes three parameters: the class to be subclassed,
|
344 |
+
the new test class name and a list of methods to mock.
|
345 |
+
</p>
|
346 |
+
<p>
|
347 |
+
Instantiating the resulting objects is slightly tricky.
|
348 |
+
The only constructor parameter of a partial mock is
|
349 |
+
the unit tester reference.
|
350 |
+
As with the normal mock objects this is needed for sending
|
351 |
+
test results in response to checked expectations.
|
352 |
+
</p>
|
353 |
+
<p>
|
354 |
+
The original constructor is not run yet.
|
355 |
+
This is necessary in case the constructor is going to
|
356 |
+
make use of the as yet unset mocked methods.
|
357 |
+
We set any return values at this point and then run the
|
358 |
+
constructor with its normal parameters.
|
359 |
+
This three step construction of "new", followed
|
360 |
+
by setting up the methods, followed by running the constructor
|
361 |
+
proper is what distinguishes the partial mock code.
|
362 |
+
</p>
|
363 |
+
<p>
|
364 |
+
Apart from construction, all of the mocked methods have
|
365 |
+
the same features as mock objects and all of the unmocked
|
366 |
+
methods behave as before.
|
367 |
+
We can set expectations very easily...
|
368 |
+
<pre>
|
369 |
+
class TelnetTest extends UnitTestCase {
|
370 |
+
...
|
371 |
+
function testConnection() {
|
372 |
+
$socket = new MockSocket();
|
373 |
+
...
|
374 |
+
$telnet = new TelnetTestVersion();
|
375 |
+
$telnet->setReturnReference('createSocket', $socket);
|
376 |
+
<strong>$telnet->expectOnce('createSocket', array('127.0.0.1', 21));</strong>
|
377 |
+
$telnet->Telnet();
|
378 |
+
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');
|
379 |
+
}
|
380 |
+
}
|
381 |
+
</pre>
|
382 |
+
Partial mocks are not used often.
|
383 |
+
I consider them transitory.
|
384 |
+
Useful while refactoring, but once the application has
|
385 |
+
all of it's dependencies nicely separated then the
|
386 |
+
partial mocks can wither away.
|
387 |
+
</p>
|
388 |
+
|
389 |
+
<h2>
|
390 |
+
<a class="target" name="less"></a>Testing less than a class</h2>
|
391 |
+
<p>
|
392 |
+
The mocked out methods don't have to be factory methods,
|
393 |
+
they could be any sort of method.
|
394 |
+
In this way partial mocks allow us to take control of any part of
|
395 |
+
a class except the constructor.
|
396 |
+
We could even go as far as to mock every method
|
397 |
+
except one we actually want to test.
|
398 |
+
</p>
|
399 |
+
<p>
|
400 |
+
This last situation is all rather hypothetical, as I've hardly
|
401 |
+
tried it.
|
402 |
+
I am a little worried that
|
403 |
+
forcing object granularity may be better for the code quality.
|
404 |
+
I personally use partial mocks as a way of overriding creation
|
405 |
+
or for occasional testing of the TemplateMethod pattern.
|
406 |
+
</p>
|
407 |
+
<p>
|
408 |
+
It's all going to come down to the coding standards of your
|
409 |
+
project to decide if you allow test mechanisms like this.
|
410 |
+
</p>
|
411 |
+
|
412 |
+
</div>
|
413 |
+
References and related information...
|
414 |
+
<ul>
|
415 |
+
<li>
|
416 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
417 |
+
</li>
|
418 |
+
<li>
|
419 |
+
<a href="http://simpletest.org/api/">Full API for SimpleTest</a>
|
420 |
+
from the PHPDoc.
|
421 |
+
</li>
|
422 |
+
<li>
|
423 |
+
The protected factory is described in
|
424 |
+
<a href="http://www-106.ibm.com/developerworks/java/library/j-mocktest.html">this paper from IBM</a>.
|
425 |
+
This is the only formal comment I have seen on this problem.
|
426 |
+
</li>
|
427 |
+
</ul>
|
428 |
+
<div class="menu_back"><div class="menu">
|
429 |
+
<a href="index.html">SimpleTest</a>
|
430 |
+
|
|
431 |
+
<a href="overview.html">Overview</a>
|
432 |
+
|
|
433 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
434 |
+
|
|
435 |
+
<a href="group_test_documentation.html">Group tests</a>
|
436 |
+
|
|
437 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
438 |
+
|
|
439 |
+
<span class="chosen">Partial mocks</span>
|
440 |
+
|
|
441 |
+
<a href="reporter_documentation.html">Reporting</a>
|
442 |
+
|
|
443 |
+
<a href="expectation_documentation.html">Expectations</a>
|
444 |
+
|
|
445 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
446 |
+
|
|
447 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
448 |
+
|
|
449 |
+
<a href="authentication_documentation.html">Authentication</a>
|
450 |
+
|
|
451 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
452 |
+
</div></div>
|
453 |
+
<div class="copyright">
|
454 |
+
Copyright<br>Marcus Baker 2006
|
455 |
+
</div>
|
456 |
+
</body>
|
457 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/reporter_documentation.html
ADDED
@@ -0,0 +1,616 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest for PHP test runner and display documentation</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<span class="chosen">Reporting</span>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Test reporter documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
Displaying <a href="#html">results in HTML</a>
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
Displaying and <a href="#other">reporting results</a>
|
41 |
+
in other formats
|
42 |
+
</li>
|
43 |
+
<li>
|
44 |
+
Using <a href="#cli">SimpleTest from the command line</a>
|
45 |
+
</li>
|
46 |
+
<li>
|
47 |
+
<a href="#xml">Using XML</a> for remote testing
|
48 |
+
</li>
|
49 |
+
</ul>
|
50 |
+
<div class="content">
|
51 |
+
|
52 |
+
<p>
|
53 |
+
SimpleTest pretty much follows the MVC-ish pattern
|
54 |
+
(Model-View-Controller).
|
55 |
+
The reporter classes are the view and the model is your
|
56 |
+
test cases and their hiearchy.
|
57 |
+
The controller is mostly hidden from the user of
|
58 |
+
SimpleTest unless you want to change how the test cases
|
59 |
+
are actually run, in which case it is possible to
|
60 |
+
override the runner objects from within the test case.
|
61 |
+
As usual with MVC, the controller is mostly undefined
|
62 |
+
and there are other places to control the test run.
|
63 |
+
</p>
|
64 |
+
|
65 |
+
<h2>
|
66 |
+
<a class="target" name="html"></a>Reporting results in HTML</h2>
|
67 |
+
<p>
|
68 |
+
The default HTML display is minimal in the extreme.
|
69 |
+
It reports success and failure with the conventional red and
|
70 |
+
green bars and shows a breadcrumb trail of test groups
|
71 |
+
for every failed assertion.
|
72 |
+
Here's a fail...
|
73 |
+
<div class="demo">
|
74 |
+
<h1>File test</h1>
|
75 |
+
<span class="fail">Fail</span>: createnewfile->True assertion failed.<br>
|
76 |
+
<div style="padding: 8px; margin-top: 1em; background-color: red; color: white;">1/1 test cases complete.
|
77 |
+
<strong>0</strong> passes, <strong>1</strong> fails and <strong>0</strong> exceptions.</div>
|
78 |
+
</div>
|
79 |
+
And here all tests passed...
|
80 |
+
<div class="demo">
|
81 |
+
<h1>File test</h1>
|
82 |
+
<div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">1/1 test cases complete.
|
83 |
+
<strong>1</strong> passes, <strong>0</strong> fails and <strong>0</strong> exceptions.</div>
|
84 |
+
</div>
|
85 |
+
The good news is that there are several points in the display
|
86 |
+
hiearchy for subclassing.
|
87 |
+
</p>
|
88 |
+
<p>
|
89 |
+
For web page based displays there is the
|
90 |
+
<span class="new_code">HtmlReporter</span> class with the following
|
91 |
+
signature...
|
92 |
+
<pre>
|
93 |
+
class HtmlReporter extends SimpleReporter {
|
94 |
+
public __construct($encoding) { ... }
|
95 |
+
public makeDry(boolean $is_dry) { ... }
|
96 |
+
public void paintHeader(string $test_name) { ... }
|
97 |
+
public void sendNoCacheHeaders() { ... }
|
98 |
+
public void paintFooter(string $test_name) { ... }
|
99 |
+
public void paintGroupStart(string $test_name, integer $size) { ... }
|
100 |
+
public void paintGroupEnd(string $test_name) { ... }
|
101 |
+
public void paintCaseStart(string $test_name) { ... }
|
102 |
+
public void paintCaseEnd(string $test_name) { ... }
|
103 |
+
public void paintMethodStart(string $test_name) { ... }
|
104 |
+
public void paintMethodEnd(string $test_name) { ... }
|
105 |
+
public void paintFail(string $message) { ... }
|
106 |
+
public void paintPass(string $message) { ... }
|
107 |
+
public void paintError(string $message) { ... }
|
108 |
+
public void paintException(string $message) { ... }
|
109 |
+
public void paintMessage(string $message) { ... }
|
110 |
+
public void paintFormattedMessage(string $message) { ... }
|
111 |
+
protected string getCss() { ... }
|
112 |
+
public array getTestList() { ... }
|
113 |
+
public integer getPassCount() { ... }
|
114 |
+
public integer getFailCount() { ... }
|
115 |
+
public integer getExceptionCount() { ... }
|
116 |
+
public integer getTestCaseCount() { ... }
|
117 |
+
public integer getTestCaseProgress() { ... }
|
118 |
+
}
|
119 |
+
</pre>
|
120 |
+
Here is what some of these methods mean. First the display methods
|
121 |
+
that you will probably want to override...
|
122 |
+
<ul class="api">
|
123 |
+
<li>
|
124 |
+
<span class="new_code">HtmlReporter(string $encoding)</span><br>
|
125 |
+
is the constructor.
|
126 |
+
Note that the unit test sets up the link to the display
|
127 |
+
rather than the other way around.
|
128 |
+
The display is a mostly passive receiver of test events.
|
129 |
+
This allows easy adaption of the display for other test
|
130 |
+
systems beside unit tests, such as monitoring servers.
|
131 |
+
The encoding is the character encoding you wish to
|
132 |
+
display the test output in.
|
133 |
+
In order to correctly render debug output when
|
134 |
+
using the web tester, this should match the encoding
|
135 |
+
of the site you are trying to test.
|
136 |
+
The available character set strings are described in
|
137 |
+
the PHP <a href="http://www.php.net/manual/en/function.htmlentities.php">html_entities()</a>
|
138 |
+
function.
|
139 |
+
</li>
|
140 |
+
<li>
|
141 |
+
<span class="new_code">void paintHeader(string $test_name)</span><br>
|
142 |
+
is called once at the very start of the test when the first
|
143 |
+
start event arrives.
|
144 |
+
The first start event is usually delivered by the top level group
|
145 |
+
test and so this is where <span class="new_code">$test_name</span>
|
146 |
+
comes from.
|
147 |
+
It paints the page title, CSS, body tag, etc.
|
148 |
+
It returns nothing (<span class="new_code">void</span>).
|
149 |
+
</li>
|
150 |
+
<li>
|
151 |
+
<span class="new_code">void paintFooter(string $test_name)</span><br>
|
152 |
+
Called at the very end of the test to close any tags opened
|
153 |
+
by the page header.
|
154 |
+
By default it also displays the red/green bar and the final
|
155 |
+
count of results.
|
156 |
+
Actually the end of the test happens when a test end event
|
157 |
+
comes in with the same name as the one that started it all
|
158 |
+
at the same level.
|
159 |
+
The tests nest you see.
|
160 |
+
Closing the last test finishes the display.
|
161 |
+
</li>
|
162 |
+
<li>
|
163 |
+
<span class="new_code">void paintMethodStart(string $test_name)</span><br>
|
164 |
+
is called at the start of each test method.
|
165 |
+
The name normally comes from method name.
|
166 |
+
The other test start events behave the same way except
|
167 |
+
that the group test one tells the reporter how large
|
168 |
+
it is in number of held test cases.
|
169 |
+
This is so that the reporter can display a progress bar
|
170 |
+
as the runner churns through the test cases.
|
171 |
+
</li>
|
172 |
+
<li>
|
173 |
+
<span class="new_code">void paintMethodEnd(string $test_name)</span><br>
|
174 |
+
backs out of the test started with the same name.
|
175 |
+
</li>
|
176 |
+
<li>
|
177 |
+
<span class="new_code">void paintFail(string $message)</span><br>
|
178 |
+
paints a failure.
|
179 |
+
By default it just displays the word fail, a breadcrumbs trail
|
180 |
+
showing the current test nesting and the message issued by
|
181 |
+
the assertion.
|
182 |
+
</li>
|
183 |
+
<li>
|
184 |
+
<span class="new_code">void paintPass(string $message)</span><br>
|
185 |
+
by default does nothing.
|
186 |
+
</li>
|
187 |
+
<li>
|
188 |
+
<span class="new_code">string getCss()</span><br>
|
189 |
+
Returns the CSS styles as a string for the page header
|
190 |
+
method.
|
191 |
+
Additional styles have to be appended here if you are
|
192 |
+
not overriding the page header.
|
193 |
+
You will want to use this method in an overriden page header
|
194 |
+
if you want to include the original CSS.
|
195 |
+
</li>
|
196 |
+
</ul>
|
197 |
+
There are also some accessors to get information on the current
|
198 |
+
state of the test suite.
|
199 |
+
Use these to enrich the display...
|
200 |
+
<ul class="api">
|
201 |
+
<li>
|
202 |
+
<span class="new_code">array getTestList()</span><br>
|
203 |
+
is the first convenience method for subclasses.
|
204 |
+
Lists the current nesting of the tests as a list
|
205 |
+
of test names.
|
206 |
+
The first, top level test case, is first in the
|
207 |
+
list and the current test method will be last.
|
208 |
+
</li>
|
209 |
+
<li>
|
210 |
+
<span class="new_code">integer getPassCount()</span><br>
|
211 |
+
returns the number of passes chalked up so far.
|
212 |
+
Needed for the display at the end.
|
213 |
+
</li>
|
214 |
+
<li>
|
215 |
+
<span class="new_code">integer getFailCount()</span><br>
|
216 |
+
is likewise the number of fails so far.
|
217 |
+
</li>
|
218 |
+
<li>
|
219 |
+
<span class="new_code">integer getExceptionCount()</span><br>
|
220 |
+
is likewise the number of errors so far.
|
221 |
+
</li>
|
222 |
+
<li>
|
223 |
+
<span class="new_code">integer getTestCaseCount()</span><br>
|
224 |
+
is the total number of test cases in the test run.
|
225 |
+
This includes the grouping tests themselves.
|
226 |
+
</li>
|
227 |
+
<li>
|
228 |
+
<span class="new_code">integer getTestCaseProgress()</span><br>
|
229 |
+
is the number of test cases completed so far.
|
230 |
+
</li>
|
231 |
+
</ul>
|
232 |
+
One simple modification is to get the HtmlReporter to display
|
233 |
+
the passes as well as the failures and errors...
|
234 |
+
<pre>
|
235 |
+
<strong>class ReporterShowingPasses extends HtmlReporter {
|
236 |
+
|
237 |
+
function paintPass($message) {
|
238 |
+
parent::paintPass($message);
|
239 |
+
print "<span class=\"pass\">Pass</span>: ";
|
240 |
+
$breadcrumb = $this->getTestList();
|
241 |
+
array_shift($breadcrumb);
|
242 |
+
print implode("-&gt;", $breadcrumb);
|
243 |
+
print "-&gt;$message<br />\n";
|
244 |
+
}
|
245 |
+
|
246 |
+
protected function getCss() {
|
247 |
+
return parent::getCss() . ' .pass { color: green; }';
|
248 |
+
}
|
249 |
+
}</strong>
|
250 |
+
</pre>
|
251 |
+
</p>
|
252 |
+
<p>
|
253 |
+
One method that was glossed over was the <span class="new_code">makeDry()</span>
|
254 |
+
method.
|
255 |
+
If you run this method, with no parameters, on the reporter
|
256 |
+
before the test suite is run no actual test methods
|
257 |
+
will be called.
|
258 |
+
You will still get the events of entering and leaving the
|
259 |
+
test methods and test cases, but no passes or failures etc,
|
260 |
+
because the test code will not actually be executed.
|
261 |
+
</p>
|
262 |
+
<p>
|
263 |
+
The reason for this is to allow for more sophistcated
|
264 |
+
GUI displays that allow the selection of individual test
|
265 |
+
cases.
|
266 |
+
In order to build a list of possible tests they need a
|
267 |
+
report on the test structure for drawing, say a tree view
|
268 |
+
of the test suite.
|
269 |
+
With a reporter set to dry run that just sends drawing events
|
270 |
+
this is easily accomplished.
|
271 |
+
</p>
|
272 |
+
|
273 |
+
<h2>
|
274 |
+
<a class="target" name="other"></a>Extending the reporter</h2>
|
275 |
+
<p>
|
276 |
+
Rather than simply modifying the existing display, you might want to
|
277 |
+
produce a whole new HTML look, or even generate text or XML.
|
278 |
+
Rather than override every method in
|
279 |
+
<span class="new_code">HtmlReporter</span> we can take one
|
280 |
+
step up the class hiearchy to <span class="new_code">SimpleReporter</span>
|
281 |
+
in the <em>simple_test.php</em> source file.
|
282 |
+
</p>
|
283 |
+
<p>
|
284 |
+
A do nothing display, a blank canvas for your own creation, would
|
285 |
+
be...
|
286 |
+
<pre>
|
287 |
+
<strong>require_once('simpletest/simpletest.php');</strong>
|
288 |
+
|
289 |
+
class MyDisplay extends SimpleReporter {<strong>
|
290 |
+
</strong>
|
291 |
+
function paintHeader($test_name) { }
|
292 |
+
|
293 |
+
function paintFooter($test_name) { }
|
294 |
+
|
295 |
+
function paintStart($test_name, $size) {<strong>
|
296 |
+
parent::paintStart($test_name, $size);</strong>
|
297 |
+
}
|
298 |
+
|
299 |
+
function paintEnd($test_name, $size) {<strong>
|
300 |
+
parent::paintEnd($test_name, $size);</strong>
|
301 |
+
}
|
302 |
+
|
303 |
+
function paintPass($message) {<strong>
|
304 |
+
parent::paintPass($message);</strong>
|
305 |
+
}
|
306 |
+
|
307 |
+
function paintFail($message) {<strong>
|
308 |
+
parent::paintFail($message);</strong>
|
309 |
+
}
|
310 |
+
|
311 |
+
function paintError($message) {<strong>
|
312 |
+
parent::paintError($message);</strong>
|
313 |
+
}
|
314 |
+
|
315 |
+
function paintException($exception) {<strong>
|
316 |
+
parent::paintException($exception);</strong>
|
317 |
+
}
|
318 |
+
}
|
319 |
+
</pre>
|
320 |
+
No output would come from this class until you add it.
|
321 |
+
</p>
|
322 |
+
<p>
|
323 |
+
The catch with using this low level class is that you must
|
324 |
+
explicitely invoke it in the test script.
|
325 |
+
The "autorun" facility will not be able to use
|
326 |
+
it's runime context (whether it's running in a web browser
|
327 |
+
or the command line) to select the reporter.
|
328 |
+
</p>
|
329 |
+
<p>
|
330 |
+
You explicitely invoke the test runner like so...
|
331 |
+
<pre>
|
332 |
+
<?php
|
333 |
+
require_once('simpletest/autorun.php');
|
334 |
+
|
335 |
+
$test = new TestSuite('File test');
|
336 |
+
$test->addFile('tests/file_test.php');
|
337 |
+
$test->run(<strong>new MyReporter()</strong>);
|
338 |
+
?>
|
339 |
+
</pre>
|
340 |
+
...perhaps like this...
|
341 |
+
<pre>
|
342 |
+
<?php
|
343 |
+
require_once('simpletest/simpletest.php');
|
344 |
+
require_once('my_reporter.php');
|
345 |
+
|
346 |
+
class MyTest extends TestSuite {
|
347 |
+
function __construct() {
|
348 |
+
parent::__construct();
|
349 |
+
$this->addFile('tests/file_test.php');
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
$test = new MyTest();
|
354 |
+
$test->run(<strong>new MyReporter()</strong>);
|
355 |
+
?>
|
356 |
+
</pre>
|
357 |
+
We'll show how to fit in with "autorun" later.
|
358 |
+
</p>
|
359 |
+
|
360 |
+
<h2>
|
361 |
+
<a class="target" name="cli"></a>The command line reporter</h2>
|
362 |
+
<p>
|
363 |
+
SimpleTest also ships with a minimal command line reporter.
|
364 |
+
The interface mimics JUnit to some extent, but paints the
|
365 |
+
failure messages as they arrive.
|
366 |
+
To use the command line reporter explicitely, substitute it
|
367 |
+
for the HTML version...
|
368 |
+
<pre>
|
369 |
+
<?php
|
370 |
+
require_once('simpletest/autorun.php');
|
371 |
+
|
372 |
+
$test = new TestSuite('File test');
|
373 |
+
$test->addFile('tests/file_test.php');
|
374 |
+
$test->run(<strong>new TextReporter()</strong>);
|
375 |
+
?>
|
376 |
+
</pre>
|
377 |
+
Then invoke the test suite from the command line...
|
378 |
+
<pre class="shell">
|
379 |
+
php file_test.php
|
380 |
+
</pre>
|
381 |
+
You will need the command line version of PHP installed
|
382 |
+
of course.
|
383 |
+
A passing test suite looks like this...
|
384 |
+
<pre class="shell">
|
385 |
+
File test
|
386 |
+
OK
|
387 |
+
Test cases run: 1/1, Passes: 1, Failures: 0, Exceptions: 0
|
388 |
+
</pre>
|
389 |
+
A failure triggers a display like this...
|
390 |
+
<pre class="shell">
|
391 |
+
File test
|
392 |
+
1) True assertion failed.
|
393 |
+
in createNewFile
|
394 |
+
FAILURES!!!
|
395 |
+
Test cases run: 1/1, Passes: 0, Failures: 1, Exceptions: 0
|
396 |
+
</pre>
|
397 |
+
</p>
|
398 |
+
<p>
|
399 |
+
One of the main reasons for using a command line driven
|
400 |
+
test suite is of using the tester as part of some automated
|
401 |
+
process.
|
402 |
+
To function properly in shell scripts the test script should
|
403 |
+
return a non-zero exit code on failure.
|
404 |
+
If a test suite fails the value <span class="new_code">false</span>
|
405 |
+
is returned from the <span class="new_code">SimpleTest::run()</span>
|
406 |
+
method.
|
407 |
+
We can use that result to exit the script with the desired return
|
408 |
+
code...
|
409 |
+
<pre>
|
410 |
+
<?php
|
411 |
+
require_once('simpletest/autorun.php');
|
412 |
+
|
413 |
+
$test = new TestSuite('File test');
|
414 |
+
$test->addFile('tests/file_test.php');
|
415 |
+
<strong>exit ($test->run(new TextReporter()) ? 0 : 1);</strong>
|
416 |
+
?>
|
417 |
+
</pre>
|
418 |
+
Of course we wouldn't really want to create two test scripts,
|
419 |
+
a command line one and a web browser one, for each test suite.
|
420 |
+
The command line reporter includes a method to sniff out the
|
421 |
+
run time environment...
|
422 |
+
<pre>
|
423 |
+
<?php
|
424 |
+
require_once('simpletest/autorun.php');
|
425 |
+
|
426 |
+
$test = new TestSuite('File test');
|
427 |
+
$test->addFile('tests/file_test.php');
|
428 |
+
<strong>if (TextReporter::inCli()) {</strong>
|
429 |
+
exit ($test->run(new TextReporter()) ? 0 : 1);
|
430 |
+
<strong>}</strong>
|
431 |
+
$test->run(new HtmlReporter());
|
432 |
+
?>
|
433 |
+
</pre>
|
434 |
+
This is the form used within SimpleTest itself.
|
435 |
+
When you use the "autorun.php", and no
|
436 |
+
test has been run by the end, this is pretty much
|
437 |
+
the code that SimpleTest will run for you implicitely.
|
438 |
+
</p>
|
439 |
+
<p>
|
440 |
+
In other words, this is gives the same result...
|
441 |
+
<pre>
|
442 |
+
<?php
|
443 |
+
require_once('simpletest/autorun.php');
|
444 |
+
|
445 |
+
class MyTest extends TestSuite {
|
446 |
+
function __construct() {
|
447 |
+
parent::__construct();
|
448 |
+
$this->addFile('tests/file_test.php');
|
449 |
+
}
|
450 |
+
}
|
451 |
+
?>
|
452 |
+
</pre>
|
453 |
+
</p>
|
454 |
+
|
455 |
+
<h2>
|
456 |
+
<a class="target" name="xml"></a>Remote testing</h2>
|
457 |
+
<p>
|
458 |
+
SimpleTest ships with an <span class="new_code">XmlReporter</span> class
|
459 |
+
used for internal communication.
|
460 |
+
When run the output looks like...
|
461 |
+
<pre class="shell">
|
462 |
+
<?xml version="1.0"?>
|
463 |
+
<run>
|
464 |
+
<group size="4">
|
465 |
+
<name>Remote tests</name>
|
466 |
+
<group size="4">
|
467 |
+
<name>Visual test with 48 passes, 48 fails and 4 exceptions</name>
|
468 |
+
<case>
|
469 |
+
<name>testofunittestcaseoutput</name>
|
470 |
+
<test>
|
471 |
+
<name>testofresults</name>
|
472 |
+
<pass>This assertion passed</pass>
|
473 |
+
<fail>This assertion failed</fail>
|
474 |
+
</test>
|
475 |
+
<test>
|
476 |
+
...
|
477 |
+
</test>
|
478 |
+
</case>
|
479 |
+
</group>
|
480 |
+
</group>
|
481 |
+
</run>
|
482 |
+
</pre>
|
483 |
+
To get your normal test cases to produce this format, on the
|
484 |
+
command line add the <span class="new_code">--xml</span> flag.
|
485 |
+
<pre class="shell">
|
486 |
+
php my_test.php --xml
|
487 |
+
</pre>
|
488 |
+
You can do teh same thing in the web browser by adding the
|
489 |
+
URL parameter <span class="new_code">xml=1</span>.
|
490 |
+
Any true value will do.
|
491 |
+
</p>
|
492 |
+
<p>
|
493 |
+
You can consume this format with the parser
|
494 |
+
supplied as part of SimpleTest itself.
|
495 |
+
This is called <span class="new_code">SimpleTestXmlParser</span> and
|
496 |
+
resides in <em>xml.php</em> within the SimpleTest package...
|
497 |
+
<pre>
|
498 |
+
<?php
|
499 |
+
require_once('simpletest/xml.php');
|
500 |
+
|
501 |
+
...
|
502 |
+
$parser = new SimpleTestXmlParser(new HtmlReporter());
|
503 |
+
$parser->parse($test_output);
|
504 |
+
?>
|
505 |
+
</pre>
|
506 |
+
The <span class="new_code">$test_output</span> should be the XML format
|
507 |
+
from the XML reporter, and could come from say a command
|
508 |
+
line run of a test case.
|
509 |
+
The parser sends events to the reporter just like any
|
510 |
+
other test run.
|
511 |
+
There are some odd occasions where this is actually useful.
|
512 |
+
</p>
|
513 |
+
<p>
|
514 |
+
Most likely it's when you want to isolate a problematic crash
|
515 |
+
prone test.
|
516 |
+
You can collect the XML output using the backtick operator
|
517 |
+
from another test.
|
518 |
+
In that way it runs in it's own process...
|
519 |
+
<pre>
|
520 |
+
<?php
|
521 |
+
require_once('simpletest/xml.php');
|
522 |
+
|
523 |
+
if (TextReporter::inCli()) {
|
524 |
+
$parser = new SimpleTestXmlParser(new TextReporter());
|
525 |
+
} else {
|
526 |
+
$parser = new SimpleTestXmlParser(new HtmlReporter());
|
527 |
+
}
|
528 |
+
$parser->parse(`php flakey_test.php --xml`);
|
529 |
+
?>
|
530 |
+
</pre>
|
531 |
+
</p>
|
532 |
+
<p>
|
533 |
+
Another use is breaking up large test suites.
|
534 |
+
</p>
|
535 |
+
<p>
|
536 |
+
A problem with large test suites is thet they can exhaust
|
537 |
+
the default 16Mb memory limit on a PHP process.
|
538 |
+
By having the test groups output in XML and run in
|
539 |
+
separate processes, the output can be reparsed to
|
540 |
+
aggregate the results into a much smaller footprint top level
|
541 |
+
test.
|
542 |
+
</p>
|
543 |
+
<p>
|
544 |
+
Because the XML output can come from anywhere, this opens
|
545 |
+
up the possibility of aggregating test runs from remote
|
546 |
+
servers.
|
547 |
+
A test case already exists to do this within the SimpleTest
|
548 |
+
framework, but it is currently experimental...
|
549 |
+
<pre>
|
550 |
+
<?php
|
551 |
+
<strong>require_once('../remote.php');</strong>
|
552 |
+
require_once('simpletest/autorun.php');
|
553 |
+
|
554 |
+
$test_url = ...;
|
555 |
+
$dry_url = ...;
|
556 |
+
|
557 |
+
class MyTestOnAnotherServer extends RemoteTestCase {
|
558 |
+
function __construct() {
|
559 |
+
$test_url = ...
|
560 |
+
parent::__construct($test_url, $test_url . ' --dry');
|
561 |
+
}
|
562 |
+
}
|
563 |
+
?>
|
564 |
+
</pre>
|
565 |
+
The <span class="new_code">RemoteTestCase</span> takes the actual location
|
566 |
+
of the test runner, basically a web page in XML format.
|
567 |
+
It also takes the URL of a reporter set to do a dry run.
|
568 |
+
This is so that progress can be reported upward correctly.
|
569 |
+
The <span class="new_code">RemoteTestCase</span> can be added to test suites
|
570 |
+
just like any other test suite.
|
571 |
+
</p>
|
572 |
+
|
573 |
+
</div>
|
574 |
+
References and related information...
|
575 |
+
<ul>
|
576 |
+
<li>
|
577 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
578 |
+
</li>
|
579 |
+
<li>
|
580 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
581 |
+
</li>
|
582 |
+
<li>
|
583 |
+
The <a href="http://simpletest.org/api/">developer's API for SimpleTest</a>
|
584 |
+
gives full detail on the classes and assertions available.
|
585 |
+
</li>
|
586 |
+
</ul>
|
587 |
+
<div class="menu_back"><div class="menu">
|
588 |
+
<a href="index.html">SimpleTest</a>
|
589 |
+
|
|
590 |
+
<a href="overview.html">Overview</a>
|
591 |
+
|
|
592 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
593 |
+
|
|
594 |
+
<a href="group_test_documentation.html">Group tests</a>
|
595 |
+
|
|
596 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
597 |
+
|
|
598 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
599 |
+
|
|
600 |
+
<span class="chosen">Reporting</span>
|
601 |
+
|
|
602 |
+
<a href="expectation_documentation.html">Expectations</a>
|
603 |
+
|
|
604 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
605 |
+
|
|
606 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
607 |
+
|
|
608 |
+
<a href="authentication_documentation.html">Authentication</a>
|
609 |
+
|
|
610 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
611 |
+
</div></div>
|
612 |
+
<div class="copyright">
|
613 |
+
Copyright<br>Marcus Baker 2006
|
614 |
+
</div>
|
615 |
+
</body>
|
616 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/unit_test_documentation.html
ADDED
@@ -0,0 +1,442 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest for PHP regression test documentation</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<span class="chosen">Unit tester</span>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>PHP Unit Test documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
<a href="#unit">Unit test cases</a> and basic assertions.
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
<a href="#extending_unit">Extending test cases</a> to
|
41 |
+
customise them for your own project.
|
42 |
+
</li>
|
43 |
+
<li>
|
44 |
+
<a href="#running_unit">Running a single case</a> as
|
45 |
+
a single script.
|
46 |
+
</li>
|
47 |
+
</ul>
|
48 |
+
<div class="content">
|
49 |
+
<h2>
|
50 |
+
<a class="target" name="unit"></a>Unit test cases</h2>
|
51 |
+
<p>
|
52 |
+
The core system is a regression testing framework built around
|
53 |
+
test cases.
|
54 |
+
A sample test case looks like this...
|
55 |
+
<pre>
|
56 |
+
<strong>class FileTestCase extends UnitTestCase {
|
57 |
+
}</strong>
|
58 |
+
</pre>
|
59 |
+
Actual tests are added as methods in the test case whose names
|
60 |
+
by default start with the string "test" and
|
61 |
+
when the test case is invoked all such methods are run in
|
62 |
+
the order that PHP introspection finds them.
|
63 |
+
As many test methods can be added as needed.
|
64 |
+
</p>
|
65 |
+
<p>
|
66 |
+
For example...
|
67 |
+
<pre>
|
68 |
+
require_once('simpletest/autorun.php');
|
69 |
+
require_once('../classes/writer.php');
|
70 |
+
|
71 |
+
class FileTestCase extends UnitTestCase {
|
72 |
+
function FileTestCase() {
|
73 |
+
$this->UnitTestCase('File test');
|
74 |
+
}<strong>
|
75 |
+
|
76 |
+
function setUp() {
|
77 |
+
@unlink('../temp/test.txt');
|
78 |
+
}
|
79 |
+
|
80 |
+
function tearDown() {
|
81 |
+
@unlink('../temp/test.txt');
|
82 |
+
}
|
83 |
+
|
84 |
+
function testCreation() {
|
85 |
+
$writer = &new FileWriter('../temp/test.txt');
|
86 |
+
$writer->write('Hello');
|
87 |
+
$this->assertTrue(file_exists('../temp/test.txt'), 'File created');
|
88 |
+
}</strong>
|
89 |
+
}
|
90 |
+
</pre>
|
91 |
+
The constructor is optional and usually omitted.
|
92 |
+
Without a name, the class name is taken as the name of the test case.
|
93 |
+
</p>
|
94 |
+
<p>
|
95 |
+
Our only test method at the moment is <span class="new_code">testCreation()</span>
|
96 |
+
where we check that a file has been created by our
|
97 |
+
<span class="new_code">Writer</span> object.
|
98 |
+
We could have put the <span class="new_code">unlink()</span>
|
99 |
+
code into this method as well, but by placing it in
|
100 |
+
<span class="new_code">setUp()</span> and
|
101 |
+
<span class="new_code">tearDown()</span> we can use it with
|
102 |
+
other test methods that we add.
|
103 |
+
</p>
|
104 |
+
<p>
|
105 |
+
The <span class="new_code">setUp()</span> method is run
|
106 |
+
just before each and every test method.
|
107 |
+
<span class="new_code">tearDown()</span> is run just after
|
108 |
+
each and every test method.
|
109 |
+
</p>
|
110 |
+
<p>
|
111 |
+
You can place some test case set up into the constructor to
|
112 |
+
be run once for all the methods in the test case, but
|
113 |
+
you risk test interference that way.
|
114 |
+
This way is slightly slower, but it is safer.
|
115 |
+
Note that if you come from a JUnit background this will not
|
116 |
+
be the behaviour you are used to.
|
117 |
+
JUnit surprisingly reinstantiates the test case for each test
|
118 |
+
method to prevent such interference.
|
119 |
+
SimpleTest requires the end user to use <span class="new_code">setUp()</span>, but
|
120 |
+
supplies additional hooks for library writers.
|
121 |
+
</p>
|
122 |
+
<p>
|
123 |
+
The means of reporting test results (see below) are by a
|
124 |
+
visiting display class
|
125 |
+
that is notified by various <span class="new_code">assert...()</span>
|
126 |
+
methods.
|
127 |
+
Here is the full list for the <span class="new_code">UnitTestCase</span>
|
128 |
+
class, the default for SimpleTest...
|
129 |
+
<table><tbody>
|
130 |
+
<tr>
|
131 |
+
<td><span class="new_code">assertTrue($x)</span></td>
|
132 |
+
<td>Fail if $x is false</td>
|
133 |
+
</tr>
|
134 |
+
<tr>
|
135 |
+
<td><span class="new_code">assertFalse($x)</span></td>
|
136 |
+
<td>Fail if $x is true</td>
|
137 |
+
</tr>
|
138 |
+
<tr>
|
139 |
+
<td><span class="new_code">assertNull($x)</span></td>
|
140 |
+
<td>Fail if $x is set</td>
|
141 |
+
</tr>
|
142 |
+
<tr>
|
143 |
+
<td><span class="new_code">assertNotNull($x)</span></td>
|
144 |
+
<td>Fail if $x not set</td>
|
145 |
+
</tr>
|
146 |
+
<tr>
|
147 |
+
<td><span class="new_code">assertIsA($x, $t)</span></td>
|
148 |
+
<td>Fail if $x is not the class or type $t</td>
|
149 |
+
</tr>
|
150 |
+
<tr>
|
151 |
+
<td><span class="new_code">assertNotA($x, $t)</span></td>
|
152 |
+
<td>Fail if $x is of the class or type $t</td>
|
153 |
+
</tr>
|
154 |
+
<tr>
|
155 |
+
<td><span class="new_code">assertEqual($x, $y)</span></td>
|
156 |
+
<td>Fail if $x == $y is false</td>
|
157 |
+
</tr>
|
158 |
+
<tr>
|
159 |
+
<td><span class="new_code">assertNotEqual($x, $y)</span></td>
|
160 |
+
<td>Fail if $x == $y is true</td>
|
161 |
+
</tr>
|
162 |
+
<tr>
|
163 |
+
<td><span class="new_code">assertWithinMargin($x, $y, $m)</span></td>
|
164 |
+
<td>Fail if abs($x - $y) < $m is false</td>
|
165 |
+
</tr>
|
166 |
+
<tr>
|
167 |
+
<td><span class="new_code">assertOutsideMargin($x, $y, $m)</span></td>
|
168 |
+
<td>Fail if abs($x - $y) < $m is true</td>
|
169 |
+
</tr>
|
170 |
+
<tr>
|
171 |
+
<td><span class="new_code">assertIdentical($x, $y)</span></td>
|
172 |
+
<td>Fail if $x == $y is false or a type mismatch</td>
|
173 |
+
</tr>
|
174 |
+
<tr>
|
175 |
+
<td><span class="new_code">assertNotIdentical($x, $y)</span></td>
|
176 |
+
<td>Fail if $x == $y is true and types match</td>
|
177 |
+
</tr>
|
178 |
+
<tr>
|
179 |
+
<td><span class="new_code">assertReference($x, $y)</span></td>
|
180 |
+
<td>Fail unless $x and $y are the same variable</td>
|
181 |
+
</tr>
|
182 |
+
<tr>
|
183 |
+
<td><span class="new_code">assertClone($x, $y)</span></td>
|
184 |
+
<td>Fail unless $x and $y are identical copies</td>
|
185 |
+
</tr>
|
186 |
+
<tr>
|
187 |
+
<td><span class="new_code">assertPattern($p, $x)</span></td>
|
188 |
+
<td>Fail unless the regex $p matches $x</td>
|
189 |
+
</tr>
|
190 |
+
<tr>
|
191 |
+
<td><span class="new_code">assertNoPattern($p, $x)</span></td>
|
192 |
+
<td>Fail if the regex $p matches $x</td>
|
193 |
+
</tr>
|
194 |
+
<tr>
|
195 |
+
<td><span class="new_code">expectError($x)</span></td>
|
196 |
+
<td>Fail if matching error does not occour</td>
|
197 |
+
</tr>
|
198 |
+
<tr>
|
199 |
+
<td><span class="new_code">expectException($x)</span></td>
|
200 |
+
<td>Fail if matching exception is not thrown</td>
|
201 |
+
</tr>
|
202 |
+
<tr>
|
203 |
+
<td><span class="new_code">ignoreException($x)</span></td>
|
204 |
+
<td>Swallows any upcoming matching exception</td>
|
205 |
+
</tr>
|
206 |
+
<tr>
|
207 |
+
<td><span class="new_code">assert($e)</span></td>
|
208 |
+
<td>Fail on failed <a href="expectation_documentation.html">expectation</a> object $e</td>
|
209 |
+
</tr>
|
210 |
+
</tbody></table>
|
211 |
+
All assertion methods can take an optional description as a
|
212 |
+
last parameter.
|
213 |
+
This is to label the displayed result with.
|
214 |
+
If omitted a default message is sent instead, which is usually
|
215 |
+
sufficient.
|
216 |
+
This default message can still be embedded in your own message
|
217 |
+
if you include "%s" within the string.
|
218 |
+
All the assertions return true on a pass or false on failure.
|
219 |
+
</p>
|
220 |
+
<p>
|
221 |
+
Some examples...
|
222 |
+
<pre>
|
223 |
+
$variable = null;
|
224 |
+
<strong>$this->assertNull($variable, 'Should be cleared');</strong>
|
225 |
+
</pre>
|
226 |
+
...will pass and normally show no message.
|
227 |
+
If you have
|
228 |
+
<a href="http://www.lastcraft.com/display_subclass_tutorial.php">set up the tester to display passes</a>
|
229 |
+
as well then the message will be displayed as is.
|
230 |
+
<pre>
|
231 |
+
<strong>$this->assertIdentical(0, false, 'Zero is not false [%s]');</strong>
|
232 |
+
</pre>
|
233 |
+
This will fail as it performs a type
|
234 |
+
check, as well as a comparison, between the two values.
|
235 |
+
The "%s" part is replaced by the default
|
236 |
+
error message that would have been shown if we had not
|
237 |
+
supplied our own.
|
238 |
+
<pre>
|
239 |
+
$a = 1;
|
240 |
+
$b = $a;
|
241 |
+
<strong>$this->assertReference($a, $b);</strong>
|
242 |
+
</pre>
|
243 |
+
Will fail as the variable <span class="new_code">$a</span> is a copy of <span class="new_code">$b</span>.
|
244 |
+
<pre>
|
245 |
+
<strong>$this->assertPattern('/hello/i', 'Hello world');</strong>
|
246 |
+
</pre>
|
247 |
+
This will pass as using a case insensitive match the string
|
248 |
+
<span class="new_code">hello</span> is contained in <span class="new_code">Hello world</span>.
|
249 |
+
<pre>
|
250 |
+
<strong>$this->expectError();</strong>
|
251 |
+
trigger_error('Catastrophe');
|
252 |
+
</pre>
|
253 |
+
Here the check catches the "Catastrophe"
|
254 |
+
message without checking the text and passes.
|
255 |
+
This removes the error from the queue.
|
256 |
+
<pre>
|
257 |
+
<strong>$this->expectError('Catastrophe');</strong>
|
258 |
+
trigger_error('Catastrophe');
|
259 |
+
</pre>
|
260 |
+
The next error check tests not only the existence of the error,
|
261 |
+
but also the text which, here matches so another pass.
|
262 |
+
If any unchecked errors are left at the end of a test method then
|
263 |
+
an exception will be reported in the test.
|
264 |
+
</p>
|
265 |
+
<p>
|
266 |
+
Note that SimpleTest cannot catch compile time PHP errors.
|
267 |
+
</p>
|
268 |
+
<p>
|
269 |
+
The test cases also have some convenience methods for debugging
|
270 |
+
code or extending the suite...
|
271 |
+
<table><tbody>
|
272 |
+
<tr>
|
273 |
+
<td><span class="new_code">setUp()</span></td>
|
274 |
+
<td>Runs this before each test method</td>
|
275 |
+
</tr>
|
276 |
+
<tr>
|
277 |
+
<td><span class="new_code">tearDown()</span></td>
|
278 |
+
<td>Runs this after each test method</td>
|
279 |
+
</tr>
|
280 |
+
<tr>
|
281 |
+
<td><span class="new_code">pass()</span></td>
|
282 |
+
<td>Sends a test pass</td>
|
283 |
+
</tr>
|
284 |
+
<tr>
|
285 |
+
<td><span class="new_code">fail()</span></td>
|
286 |
+
<td>Sends a test failure</td>
|
287 |
+
</tr>
|
288 |
+
<tr>
|
289 |
+
<td><span class="new_code">error()</span></td>
|
290 |
+
<td>Sends an exception event</td>
|
291 |
+
</tr>
|
292 |
+
<tr>
|
293 |
+
<td><span class="new_code">signal($type, $payload)</span></td>
|
294 |
+
<td>Sends a user defined message to the test reporter</td>
|
295 |
+
</tr>
|
296 |
+
<tr>
|
297 |
+
<td><span class="new_code">dump($var)</span></td>
|
298 |
+
<td>Does a formatted <span class="new_code">print_r()</span> for quick and dirty debugging</td>
|
299 |
+
</tr>
|
300 |
+
</tbody></table>
|
301 |
+
</p>
|
302 |
+
|
303 |
+
<h2>
|
304 |
+
<a class="target" name="extending_unit"></a>Extending test cases</h2>
|
305 |
+
<p>
|
306 |
+
Of course additional test methods can be added to create
|
307 |
+
specific types of test case, so as to extend framework...
|
308 |
+
<pre>
|
309 |
+
require_once('simpletest/autorun.php');
|
310 |
+
<strong>
|
311 |
+
class FileTester extends UnitTestCase {
|
312 |
+
function FileTester($name = false) {
|
313 |
+
$this->UnitTestCase($name);
|
314 |
+
}
|
315 |
+
|
316 |
+
function assertFileExists($filename, $message = '%s') {
|
317 |
+
$this->assertTrue(
|
318 |
+
file_exists($filename),
|
319 |
+
sprintf($message, 'File [$filename] existence check'));
|
320 |
+
}</strong>
|
321 |
+
}
|
322 |
+
</pre>
|
323 |
+
Here the SimpleTest library is held in a folder called
|
324 |
+
<em>simpletest</em> that is local.
|
325 |
+
Substitute your own path for this.
|
326 |
+
</p>
|
327 |
+
<p>
|
328 |
+
To prevent this test case being run accidently, it is
|
329 |
+
advisable to mark it as <span class="new_code">abstract</span>.
|
330 |
+
</p>
|
331 |
+
<p>
|
332 |
+
Alternatively you could add a
|
333 |
+
<span class="new_code">SimpleTestOptions::ignore('FileTester');</span>
|
334 |
+
directive in your code.
|
335 |
+
</p>
|
336 |
+
<p>
|
337 |
+
This new case can be now be inherited just like
|
338 |
+
a normal test case...
|
339 |
+
<pre>
|
340 |
+
class FileTestCase extends <strong>FileTester</strong> {
|
341 |
+
|
342 |
+
function setUp() {
|
343 |
+
@unlink('../temp/test.txt');
|
344 |
+
}
|
345 |
+
|
346 |
+
function tearDown() {
|
347 |
+
@unlink('../temp/test.txt');
|
348 |
+
}
|
349 |
+
|
350 |
+
function testCreation() {
|
351 |
+
$writer = &new FileWriter('../temp/test.txt');
|
352 |
+
$writer->write('Hello');<strong>
|
353 |
+
$this->assertFileExists('../temp/test.txt');</strong>
|
354 |
+
}
|
355 |
+
}
|
356 |
+
</pre>
|
357 |
+
</p>
|
358 |
+
<p>
|
359 |
+
If you want a test case that does not have all of the
|
360 |
+
<span class="new_code">UnitTestCase</span> assertions,
|
361 |
+
only your own and a few basics,
|
362 |
+
you need to extend the <span class="new_code">SimpleTestCase</span>
|
363 |
+
class instead.
|
364 |
+
It is found in <em>simple_test.php</em> rather than
|
365 |
+
<em>unit_tester.php</em>.
|
366 |
+
See <a href="group_test_documentation.html">later</a> if you
|
367 |
+
want to incorporate other unit tester's
|
368 |
+
test cases in your test suites.
|
369 |
+
</p>
|
370 |
+
|
371 |
+
<h2>
|
372 |
+
<a class="target" name="running_unit"></a>Running a single test case</h2>
|
373 |
+
<p>
|
374 |
+
You won't often run single test cases except when bashing
|
375 |
+
away at a module that is having difficulty, and you don't
|
376 |
+
want to upset the main test suite.
|
377 |
+
With <em>autorun</em> no particular scaffolding is needed,
|
378 |
+
just launch your particular test file and you're ready to go.
|
379 |
+
</p>
|
380 |
+
<p>
|
381 |
+
You can even decide which reporter (for example,
|
382 |
+
<span class="new_code">TextReporter</span> or <span class="new_code">HtmlReporter</span>)
|
383 |
+
you prefer for a specific file when launched on its own...
|
384 |
+
<pre>
|
385 |
+
<?php
|
386 |
+
require_once('simpletest/autorun.php');<strong>
|
387 |
+
SimpleTest :: prefer(new TextReporter());</strong>
|
388 |
+
require_once('../classes/writer.php');
|
389 |
+
|
390 |
+
class FileTestCase extends UnitTestCase {
|
391 |
+
...
|
392 |
+
}
|
393 |
+
?>
|
394 |
+
</pre>
|
395 |
+
This script will run as is, but of course will output zero passes
|
396 |
+
and zero failures until test methods are added.
|
397 |
+
</p>
|
398 |
+
|
399 |
+
</div>
|
400 |
+
References and related information...
|
401 |
+
<ul>
|
402 |
+
<li>
|
403 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
404 |
+
</li>
|
405 |
+
<li>
|
406 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
407 |
+
</li>
|
408 |
+
<li>
|
409 |
+
<a href="http://simpletest.org/api/">Full API for SimpleTest</a>
|
410 |
+
from the PHPDoc.
|
411 |
+
</li>
|
412 |
+
</ul>
|
413 |
+
<div class="menu_back"><div class="menu">
|
414 |
+
<a href="index.html">SimpleTest</a>
|
415 |
+
|
|
416 |
+
<a href="overview.html">Overview</a>
|
417 |
+
|
|
418 |
+
<span class="chosen">Unit tester</span>
|
419 |
+
|
|
420 |
+
<a href="group_test_documentation.html">Group tests</a>
|
421 |
+
|
|
422 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
423 |
+
|
|
424 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
425 |
+
|
|
426 |
+
<a href="reporter_documentation.html">Reporting</a>
|
427 |
+
|
|
428 |
+
<a href="expectation_documentation.html">Expectations</a>
|
429 |
+
|
|
430 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
431 |
+
|
|
432 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
433 |
+
|
|
434 |
+
<a href="authentication_documentation.html">Authentication</a>
|
435 |
+
|
|
436 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
437 |
+
</div></div>
|
438 |
+
<div class="copyright">
|
439 |
+
Copyright<br>Marcus Baker 2006
|
440 |
+
</div>
|
441 |
+
</body>
|
442 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/web_tester_documentation.html
ADDED
@@ -0,0 +1,588 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>SimpleTest for PHP web script testing documentation</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<span class="chosen">Web tester</span>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Web tester documentation</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
Successfully <a href="#fetch">fetching a web page</a>
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
Testing the <a href="#content">page content</a>
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
<a href="#navigation">Navigating a web site</a>
|
44 |
+
while testing
|
45 |
+
</li>
|
46 |
+
<li>
|
47 |
+
<a href="#request">Raw request modifications</a> and debugging methods
|
48 |
+
</li>
|
49 |
+
</ul>
|
50 |
+
<div class="content">
|
51 |
+
<h2>
|
52 |
+
<a class="target" name="fetch"></a>Fetching a page</h2>
|
53 |
+
<p>
|
54 |
+
Testing classes is all very well, but PHP is predominately
|
55 |
+
a language for creating functionality within web pages.
|
56 |
+
How do we test the front end presentation role of our PHP
|
57 |
+
applications?
|
58 |
+
Well the web pages are just text, so we should be able to
|
59 |
+
examine them just like any other test data.
|
60 |
+
</p>
|
61 |
+
<p>
|
62 |
+
This leads to a tricky issue.
|
63 |
+
If we test at too low a level, testing for matching tags
|
64 |
+
in the page with pattern matching for example, our tests will
|
65 |
+
be brittle.
|
66 |
+
The slightest change in layout could break a large number of
|
67 |
+
tests.
|
68 |
+
If we test at too high a level, say using mock versions of a
|
69 |
+
template engine, then we lose the ability to automate some classes
|
70 |
+
of test.
|
71 |
+
For example, the interaction of forms and navigation will
|
72 |
+
have to be tested manually.
|
73 |
+
These types of test are extremely repetitive and error prone.
|
74 |
+
</p>
|
75 |
+
<p>
|
76 |
+
SimpleTest includes a special form of test case for the testing
|
77 |
+
of web page actions.
|
78 |
+
The <span class="new_code">WebTestCase</span> includes facilities
|
79 |
+
for navigation, content and cookie checks and form handling.
|
80 |
+
Usage of these test cases is similar to the
|
81 |
+
<a href="unit_tester_documentation.html">UnitTestCase</a>...
|
82 |
+
<pre>
|
83 |
+
<strong>class TestOfLastcraft extends WebTestCase {
|
84 |
+
}</strong>
|
85 |
+
</pre>
|
86 |
+
Here we are about to test the
|
87 |
+
<a href="http://www.lastcraft.com/">Last Craft</a> site itself.
|
88 |
+
If this test case is in a file called <em>lastcraft_test.php</em>
|
89 |
+
then it can be loaded in a runner script just like unit tests...
|
90 |
+
<pre>
|
91 |
+
<?php
|
92 |
+
require_once('simpletest/autorun.php');<strong>
|
93 |
+
require_once('simpletest/web_tester.php');</strong>
|
94 |
+
SimpleTest::prefer(new TextReporter());
|
95 |
+
|
96 |
+
class WebTests extends TestSuite {
|
97 |
+
function WebTests() {
|
98 |
+
$this->TestSuite('Web site tests');<strong>
|
99 |
+
$this->addFile('lastcraft_test.php');</strong>
|
100 |
+
}
|
101 |
+
}
|
102 |
+
?>
|
103 |
+
</pre>
|
104 |
+
I am using the text reporter here to more clearly
|
105 |
+
distinguish the web content from the test output.
|
106 |
+
</p>
|
107 |
+
<p>
|
108 |
+
Nothing is being tested yet.
|
109 |
+
We can fetch the home page by using the
|
110 |
+
<span class="new_code">get()</span> method...
|
111 |
+
<pre>
|
112 |
+
class TestOfLastcraft extends WebTestCase {
|
113 |
+
<strong>
|
114 |
+
function testHomepage() {
|
115 |
+
$this->assertTrue($this->get('http://www.lastcraft.com/'));
|
116 |
+
}</strong>
|
117 |
+
}
|
118 |
+
</pre>
|
119 |
+
The <span class="new_code">get()</span> method will
|
120 |
+
return true only if page content was successfully
|
121 |
+
loaded.
|
122 |
+
It is a simple, but crude way to check that a web page
|
123 |
+
was actually delivered by the web server.
|
124 |
+
However that content may be a 404 response and yet
|
125 |
+
our <span class="new_code">get()</span> method will still return true.
|
126 |
+
</p>
|
127 |
+
<p>
|
128 |
+
Assuming that the web server for the Last Craft site is up
|
129 |
+
(sadly not always the case), we should see...
|
130 |
+
<pre class="shell">
|
131 |
+
Web site tests
|
132 |
+
OK
|
133 |
+
Test cases run: 1/1, Failures: 0, Exceptions: 0
|
134 |
+
</pre>
|
135 |
+
All we have really checked is that any kind of page was
|
136 |
+
returned.
|
137 |
+
We don't yet know if it was the right one.
|
138 |
+
</p>
|
139 |
+
|
140 |
+
<h2>
|
141 |
+
<a class="target" name="content"></a>Testing page content</h2>
|
142 |
+
<p>
|
143 |
+
To confirm that the page we think we are on is actually the
|
144 |
+
page we are on, we need to verify the page content.
|
145 |
+
<pre>
|
146 |
+
class TestOfLastcraft extends WebTestCase {
|
147 |
+
|
148 |
+
function testHomepage() {<strong>
|
149 |
+
$this->get('http://www.lastcraft.com/');
|
150 |
+
$this->assertText('Why the last craft');</strong>
|
151 |
+
}
|
152 |
+
}
|
153 |
+
</pre>
|
154 |
+
The page from the last fetch is held in a buffer in
|
155 |
+
the test case, so there is no need to refer to it directly.
|
156 |
+
The pattern match is always made against the buffer.
|
157 |
+
</p>
|
158 |
+
<p>
|
159 |
+
Here is the list of possible content assertions...
|
160 |
+
<table><tbody>
|
161 |
+
<tr>
|
162 |
+
<td><span class="new_code">assertTitle($title)</span></td>
|
163 |
+
<td>Pass if title is an exact match</td>
|
164 |
+
</tr>
|
165 |
+
<tr>
|
166 |
+
<td><span class="new_code">assertText($text)</span></td>
|
167 |
+
<td>Pass if matches visible and "alt" text</td>
|
168 |
+
</tr>
|
169 |
+
<tr>
|
170 |
+
<td><span class="new_code">assertNoText($text)</span></td>
|
171 |
+
<td>Pass if doesn't match visible and "alt" text</td>
|
172 |
+
</tr>
|
173 |
+
<tr>
|
174 |
+
<td><span class="new_code">assertPattern($pattern)</span></td>
|
175 |
+
<td>A Perl pattern match against the page content</td>
|
176 |
+
</tr>
|
177 |
+
<tr>
|
178 |
+
<td><span class="new_code">assertNoPattern($pattern)</span></td>
|
179 |
+
<td>A Perl pattern match to not find content</td>
|
180 |
+
</tr>
|
181 |
+
<tr>
|
182 |
+
<td><span class="new_code">assertLink($label)</span></td>
|
183 |
+
<td>Pass if a link with this text is present</td>
|
184 |
+
</tr>
|
185 |
+
<tr>
|
186 |
+
<td><span class="new_code">assertNoLink($label)</span></td>
|
187 |
+
<td>Pass if no link with this text is present</td>
|
188 |
+
</tr>
|
189 |
+
<tr>
|
190 |
+
<td><span class="new_code">assertLinkById($id)</span></td>
|
191 |
+
<td>Pass if a link with this id attribute is present</td>
|
192 |
+
</tr>
|
193 |
+
<tr>
|
194 |
+
<td><span class="new_code">assertNoLinkById($id)</span></td>
|
195 |
+
<td>Pass if no link with this id attribute is present</td>
|
196 |
+
</tr>
|
197 |
+
<tr>
|
198 |
+
<td><span class="new_code">assertField($name, $value)</span></td>
|
199 |
+
<td>Pass if an input tag with this name has this value</td>
|
200 |
+
</tr>
|
201 |
+
<tr>
|
202 |
+
<td><span class="new_code">assertFieldById($id, $value)</span></td>
|
203 |
+
<td>Pass if an input tag with this id has this value</td>
|
204 |
+
</tr>
|
205 |
+
<tr>
|
206 |
+
<td><span class="new_code">assertResponse($codes)</span></td>
|
207 |
+
<td>Pass if HTTP response matches this list</td>
|
208 |
+
</tr>
|
209 |
+
<tr>
|
210 |
+
<td><span class="new_code">assertMime($types)</span></td>
|
211 |
+
<td>Pass if MIME type is in this list</td>
|
212 |
+
</tr>
|
213 |
+
<tr>
|
214 |
+
<td><span class="new_code">assertAuthentication($protocol)</span></td>
|
215 |
+
<td>Pass if the current challenge is this protocol</td>
|
216 |
+
</tr>
|
217 |
+
<tr>
|
218 |
+
<td><span class="new_code">assertNoAuthentication()</span></td>
|
219 |
+
<td>Pass if there is no current challenge</td>
|
220 |
+
</tr>
|
221 |
+
<tr>
|
222 |
+
<td><span class="new_code">assertRealm($name)</span></td>
|
223 |
+
<td>Pass if the current challenge realm matches</td>
|
224 |
+
</tr>
|
225 |
+
<tr>
|
226 |
+
<td><span class="new_code">assertHeader($header, $content)</span></td>
|
227 |
+
<td>Pass if a header was fetched matching this value</td>
|
228 |
+
</tr>
|
229 |
+
<tr>
|
230 |
+
<td><span class="new_code">assertNoHeader($header)</span></td>
|
231 |
+
<td>Pass if a header was not fetched</td>
|
232 |
+
</tr>
|
233 |
+
<tr>
|
234 |
+
<td><span class="new_code">assertCookie($name, $value)</span></td>
|
235 |
+
<td>Pass if there is currently a matching cookie</td>
|
236 |
+
</tr>
|
237 |
+
<tr>
|
238 |
+
<td><span class="new_code">assertNoCookie($name)</span></td>
|
239 |
+
<td>Pass if there is currently no cookie of this name</td>
|
240 |
+
</tr>
|
241 |
+
</tbody></table>
|
242 |
+
As usual with the SimpleTest assertions, they all return
|
243 |
+
false on failure and true on pass.
|
244 |
+
They also allow an optional test message and you can embed
|
245 |
+
the original test message inside using "%s" inside
|
246 |
+
your custom message.
|
247 |
+
</p>
|
248 |
+
<p>
|
249 |
+
So now we could instead test against the title tag with...
|
250 |
+
<pre>
|
251 |
+
<strong>$this->assertTitle('The Last Craft? Web developer tutorials on PHP, Extreme programming and Object Oriented development');</strong>
|
252 |
+
</pre>
|
253 |
+
...or, if that is too long and fragile...
|
254 |
+
<pre>
|
255 |
+
<strong>$this->assertTitle(new PatternExpectation('/The Last Craft/'));</strong>
|
256 |
+
</pre>
|
257 |
+
As well as the simple HTML content checks we can check
|
258 |
+
that the MIME type is in a list of allowed types with...
|
259 |
+
<pre>
|
260 |
+
<strong>$this->assertMime(array('text/plain', 'text/html'));</strong>
|
261 |
+
</pre>
|
262 |
+
More interesting is checking the HTTP response code.
|
263 |
+
Like the MIME type, we can assert that the response code
|
264 |
+
is in a list of allowed values...
|
265 |
+
<pre>
|
266 |
+
class TestOfLastcraft extends WebTestCase {
|
267 |
+
|
268 |
+
function testRedirects() {
|
269 |
+
$this->get('http://www.lastcraft.com/test/redirect.php');
|
270 |
+
$this->assertResponse(200);</strong>
|
271 |
+
}
|
272 |
+
}
|
273 |
+
</pre>
|
274 |
+
Here we are checking that the fetch is successful by
|
275 |
+
allowing only a 200 HTTP response.
|
276 |
+
This test will pass, but it is not actually correct to do so.
|
277 |
+
There is no page, instead the server issues a redirect.
|
278 |
+
The <span class="new_code">WebTestCase</span> will
|
279 |
+
automatically follow up to three such redirects.
|
280 |
+
The tests are more robust this way and we are usually
|
281 |
+
interested in the interaction with the pages rather
|
282 |
+
than their delivery.
|
283 |
+
If the redirects are of interest then this ability must
|
284 |
+
be disabled...
|
285 |
+
<pre>
|
286 |
+
class TestOfLastcraft extends WebTestCase {
|
287 |
+
|
288 |
+
function testHomepage() {<strong>
|
289 |
+
$this->setMaximumRedirects(0);</strong>
|
290 |
+
$this->get('http://www.lastcraft.com/test/redirect.php');
|
291 |
+
$this->assertResponse(200);
|
292 |
+
}
|
293 |
+
}
|
294 |
+
</pre>
|
295 |
+
The assertion now fails as expected...
|
296 |
+
<pre class="shell">
|
297 |
+
Web site tests
|
298 |
+
1) Expecting response in [200] got [302]
|
299 |
+
in testhomepage
|
300 |
+
in testoflastcraft
|
301 |
+
in lastcraft_test.php
|
302 |
+
FAILURES!!!
|
303 |
+
Test cases run: 1/1, Failures: 1, Exceptions: 0
|
304 |
+
</pre>
|
305 |
+
We can modify the test to correctly assert redirects with...
|
306 |
+
<pre>
|
307 |
+
class TestOfLastcraft extends WebTestCase {
|
308 |
+
|
309 |
+
function testHomepage() {
|
310 |
+
$this->setMaximumRedirects(0);
|
311 |
+
$this->get('http://www.lastcraft.com/test/redirect.php');
|
312 |
+
$this->assertResponse(<strong>array(301, 302, 303, 307)</strong>);
|
313 |
+
}
|
314 |
+
}
|
315 |
+
</pre>
|
316 |
+
This now passes.
|
317 |
+
</p>
|
318 |
+
|
319 |
+
<h2>
|
320 |
+
<a class="target" name="navigation"></a>Navigating a web site</h2>
|
321 |
+
<p>
|
322 |
+
Users don't often navigate sites by typing in URLs, but by
|
323 |
+
clicking links and buttons.
|
324 |
+
Here we confirm that the contact details can be reached
|
325 |
+
from the home page...
|
326 |
+
<pre>
|
327 |
+
class TestOfLastcraft extends WebTestCase {
|
328 |
+
...
|
329 |
+
function testContact() {
|
330 |
+
$this->get('http://www.lastcraft.com/');<strong>
|
331 |
+
$this->clickLink('About');
|
332 |
+
$this->assertTitle(new PatternExpectation('/About Last Craft/'));</strong>
|
333 |
+
}
|
334 |
+
}
|
335 |
+
</pre>
|
336 |
+
The parameter is the text of the link.
|
337 |
+
</p>
|
338 |
+
<p>
|
339 |
+
If the target is a button rather than an anchor tag, then
|
340 |
+
<span class="new_code">clickSubmit()</span> can be used
|
341 |
+
with the button title...
|
342 |
+
<pre>
|
343 |
+
<strong>$this->clickSubmit('Go!');</strong>
|
344 |
+
</pre>
|
345 |
+
If you are not sure or don't care, the usual case, then just
|
346 |
+
use the <span class="new_code">click()</span> method...
|
347 |
+
<pre>
|
348 |
+
<strong>$this->click('Go!');</strong>
|
349 |
+
</pre>
|
350 |
+
</p>
|
351 |
+
<p>
|
352 |
+
The list of navigation methods is...
|
353 |
+
<table><tbody>
|
354 |
+
<tr>
|
355 |
+
<td><span class="new_code">getUrl()</span></td>
|
356 |
+
<td>The current location</td>
|
357 |
+
</tr>
|
358 |
+
<tr>
|
359 |
+
<td><span class="new_code">get($url, $parameters)</span></td>
|
360 |
+
<td>Send a GET request with these parameters</td>
|
361 |
+
</tr>
|
362 |
+
<tr>
|
363 |
+
<td><span class="new_code">post($url, $parameters)</span></td>
|
364 |
+
<td>Send a POST request with these parameters</td>
|
365 |
+
</tr>
|
366 |
+
<tr>
|
367 |
+
<td><span class="new_code">head($url, $parameters)</span></td>
|
368 |
+
<td>Send a HEAD request without replacing the page content</td>
|
369 |
+
</tr>
|
370 |
+
<tr>
|
371 |
+
<td><span class="new_code">retry()</span></td>
|
372 |
+
<td>Reload the last request</td>
|
373 |
+
</tr>
|
374 |
+
<tr>
|
375 |
+
<td><span class="new_code">back()</span></td>
|
376 |
+
<td>Like the browser back button</td>
|
377 |
+
</tr>
|
378 |
+
<tr>
|
379 |
+
<td><span class="new_code">forward()</span></td>
|
380 |
+
<td>Like the browser forward button</td>
|
381 |
+
</tr>
|
382 |
+
<tr>
|
383 |
+
<td><span class="new_code">authenticate($name, $password)</span></td>
|
384 |
+
<td>Retry after a challenge</td>
|
385 |
+
</tr>
|
386 |
+
<tr>
|
387 |
+
<td><span class="new_code">restart()</span></td>
|
388 |
+
<td>Restarts the browser as if a new session</td>
|
389 |
+
</tr>
|
390 |
+
<tr>
|
391 |
+
<td><span class="new_code">getCookie($name)</span></td>
|
392 |
+
<td>Gets the cookie value for the current context</td>
|
393 |
+
</tr>
|
394 |
+
<tr>
|
395 |
+
<td><span class="new_code">ageCookies($interval)</span></td>
|
396 |
+
<td>Ages current cookies prior to a restart</td>
|
397 |
+
</tr>
|
398 |
+
<tr>
|
399 |
+
<td><span class="new_code">clearFrameFocus()</span></td>
|
400 |
+
<td>Go back to treating all frames as one page</td>
|
401 |
+
</tr>
|
402 |
+
<tr>
|
403 |
+
<td><span class="new_code">clickSubmit($label)</span></td>
|
404 |
+
<td>Click the first button with this label</td>
|
405 |
+
</tr>
|
406 |
+
<tr>
|
407 |
+
<td><span class="new_code">clickSubmitByName($name)</span></td>
|
408 |
+
<td>Click the button with this name attribute</td>
|
409 |
+
</tr>
|
410 |
+
<tr>
|
411 |
+
<td><span class="new_code">clickSubmitById($id)</span></td>
|
412 |
+
<td>Click the button with this ID attribute</td>
|
413 |
+
</tr>
|
414 |
+
<tr>
|
415 |
+
<td><span class="new_code">clickImage($label, $x, $y)</span></td>
|
416 |
+
<td>Click an input tag of type image by title or alt text</td>
|
417 |
+
</tr>
|
418 |
+
<tr>
|
419 |
+
<td><span class="new_code">clickImageByName($name, $x, $y)</span></td>
|
420 |
+
<td>Click an input tag of type image by name</td>
|
421 |
+
</tr>
|
422 |
+
<tr>
|
423 |
+
<td><span class="new_code">clickImageById($id, $x, $y)</span></td>
|
424 |
+
<td>Click an input tag of type image by ID attribute</td>
|
425 |
+
</tr>
|
426 |
+
<tr>
|
427 |
+
<td><span class="new_code">submitFormById($id)</span></td>
|
428 |
+
<td>Submit a form without the submit value</td>
|
429 |
+
</tr>
|
430 |
+
<tr>
|
431 |
+
<td><span class="new_code">clickLink($label, $index)</span></td>
|
432 |
+
<td>Click an anchor by the visible label text</td>
|
433 |
+
</tr>
|
434 |
+
<tr>
|
435 |
+
<td><span class="new_code">clickLinkById($id)</span></td>
|
436 |
+
<td>Click an anchor by the ID attribute</td>
|
437 |
+
</tr>
|
438 |
+
<tr>
|
439 |
+
<td><span class="new_code">getFrameFocus()</span></td>
|
440 |
+
<td>The name of the currently selected frame</td>
|
441 |
+
</tr>
|
442 |
+
<tr>
|
443 |
+
<td><span class="new_code">setFrameFocusByIndex($choice)</span></td>
|
444 |
+
<td>Focus on a frame counting from 1</td>
|
445 |
+
</tr>
|
446 |
+
<tr>
|
447 |
+
<td><span class="new_code">setFrameFocus($name)</span></td>
|
448 |
+
<td>Focus on a frame by name</td>
|
449 |
+
</tr>
|
450 |
+
</tbody></table>
|
451 |
+
</p>
|
452 |
+
<p>
|
453 |
+
The parameters in the <span class="new_code">get()</span>, <span class="new_code">post()</span> or
|
454 |
+
<span class="new_code">head()</span> methods are optional.
|
455 |
+
The HTTP HEAD fetch does not change the browser context, only loads
|
456 |
+
cookies.
|
457 |
+
This can be useful for when an image or stylesheet sets a cookie
|
458 |
+
for crafty robot blocking.
|
459 |
+
</p>
|
460 |
+
<p>
|
461 |
+
The <span class="new_code">retry()</span>, <span class="new_code">back()</span> and
|
462 |
+
<span class="new_code">forward()</span> commands work as they would on
|
463 |
+
your web browser.
|
464 |
+
They use the history to retry pages.
|
465 |
+
This can be handy for checking the effect of hitting the
|
466 |
+
back button on your forms.
|
467 |
+
</p>
|
468 |
+
<p>
|
469 |
+
The frame methods need a little explanation.
|
470 |
+
By default a framed page is treated just like any other.
|
471 |
+
Content will be searced for throughout the entire frameset,
|
472 |
+
so clicking a link will work no matter which frame
|
473 |
+
the anchor tag is in.
|
474 |
+
You can override this behaviour by focusing on a single
|
475 |
+
frame.
|
476 |
+
If you do that, all searches and actions will apply to that
|
477 |
+
frame alone, such as authentication and retries.
|
478 |
+
If a link or button is not in a focused frame then it cannot
|
479 |
+
be clicked.
|
480 |
+
</p>
|
481 |
+
<p>
|
482 |
+
Testing navigation on fixed pages only tells you when you
|
483 |
+
have broken an entire script.
|
484 |
+
For highly dynamic pages, such as for bulletin boards, this can
|
485 |
+
be crucial for verifying the correctness of the application.
|
486 |
+
For most applications though, the really tricky logic is usually in
|
487 |
+
the handling of forms and sessions.
|
488 |
+
Fortunately SimpleTest includes
|
489 |
+
<a href="form_testing_documentation.html">tools for testing web forms</a>
|
490 |
+
as well.
|
491 |
+
</p>
|
492 |
+
|
493 |
+
<h2>
|
494 |
+
<a class="target" name="request"></a>Modifying the request</h2>
|
495 |
+
<p>
|
496 |
+
Although SimpleTest does not have the goal of testing networking
|
497 |
+
problems, it does include some methods to modify and debug
|
498 |
+
the requests it makes.
|
499 |
+
Here is another method list...
|
500 |
+
<table><tbody>
|
501 |
+
<tr>
|
502 |
+
<td><span class="new_code">getTransportError()</span></td>
|
503 |
+
<td>The last socket error</td>
|
504 |
+
</tr>
|
505 |
+
<tr>
|
506 |
+
<td><span class="new_code">showRequest()</span></td>
|
507 |
+
<td>Dump the outgoing request</td>
|
508 |
+
</tr>
|
509 |
+
<tr>
|
510 |
+
<td><span class="new_code">showHeaders()</span></td>
|
511 |
+
<td>Dump the incoming headers</td>
|
512 |
+
</tr>
|
513 |
+
<tr>
|
514 |
+
<td><span class="new_code">showSource()</span></td>
|
515 |
+
<td>Dump the raw HTML page content</td>
|
516 |
+
</tr>
|
517 |
+
<tr>
|
518 |
+
<td><span class="new_code">ignoreFrames()</span></td>
|
519 |
+
<td>Do not load framesets</td>
|
520 |
+
</tr>
|
521 |
+
<tr>
|
522 |
+
<td><span class="new_code">setCookie($name, $value)</span></td>
|
523 |
+
<td>Set a cookie from now on</td>
|
524 |
+
</tr>
|
525 |
+
<tr>
|
526 |
+
<td><span class="new_code">addHeader($header)</span></td>
|
527 |
+
<td>Always add this header to the request</td>
|
528 |
+
</tr>
|
529 |
+
<tr>
|
530 |
+
<td><span class="new_code">setMaximumRedirects($max)</span></td>
|
531 |
+
<td>Stop after this many redirects</td>
|
532 |
+
</tr>
|
533 |
+
<tr>
|
534 |
+
<td><span class="new_code">setConnectionTimeout($timeout)</span></td>
|
535 |
+
<td>Kill the connection after this time between bytes</td>
|
536 |
+
</tr>
|
537 |
+
<tr>
|
538 |
+
<td><span class="new_code">useProxy($proxy, $name, $password)</span></td>
|
539 |
+
<td>Make requests via this proxy URL</td>
|
540 |
+
</tr>
|
541 |
+
</tbody></table>
|
542 |
+
These methods are principally for debugging.
|
543 |
+
</p>
|
544 |
+
|
545 |
+
</div>
|
546 |
+
References and related information...
|
547 |
+
<ul>
|
548 |
+
<li>
|
549 |
+
SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
550 |
+
</li>
|
551 |
+
<li>
|
552 |
+
SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
553 |
+
</li>
|
554 |
+
<li>
|
555 |
+
The <a href="http://simpletest.org/api/">developer's API for SimpleTest</a>
|
556 |
+
gives full detail on the classes and assertions available.
|
557 |
+
</li>
|
558 |
+
</ul>
|
559 |
+
<div class="menu_back"><div class="menu">
|
560 |
+
<a href="index.html">SimpleTest</a>
|
561 |
+
|
|
562 |
+
<a href="overview.html">Overview</a>
|
563 |
+
|
|
564 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
565 |
+
|
|
566 |
+
<a href="group_test_documentation.html">Group tests</a>
|
567 |
+
|
|
568 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
569 |
+
|
|
570 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
571 |
+
|
|
572 |
+
<a href="reporter_documentation.html">Reporting</a>
|
573 |
+
|
|
574 |
+
<a href="expectation_documentation.html">Expectations</a>
|
575 |
+
|
|
576 |
+
<span class="chosen">Web tester</span>
|
577 |
+
|
|
578 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
579 |
+
|
|
580 |
+
<a href="authentication_documentation.html">Authentication</a>
|
581 |
+
|
|
582 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
583 |
+
</div></div>
|
584 |
+
<div class="copyright">
|
585 |
+
Copyright<br>Marcus Baker 2006
|
586 |
+
</div>
|
587 |
+
</body>
|
588 |
+
</html>
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/authentication_documentation.html
ADDED
@@ -0,0 +1,371 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
+
<title>Documentation Simple Test : tester l'authentification</title>
|
5 |
+
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="menu_back"><div class="menu">
|
9 |
+
<a href="index.html">SimpleTest</a>
|
10 |
+
|
|
11 |
+
<a href="overview.html">Overview</a>
|
12 |
+
|
|
13 |
+
<a href="unit_test_documentation.html">Unit tester</a>
|
14 |
+
|
|
15 |
+
<a href="group_test_documentation.html">Group tests</a>
|
16 |
+
|
|
17 |
+
<a href="mock_objects_documentation.html">Mock objects</a>
|
18 |
+
|
|
19 |
+
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
20 |
+
|
|
21 |
+
<a href="reporter_documentation.html">Reporting</a>
|
22 |
+
|
|
23 |
+
<a href="expectation_documentation.html">Expectations</a>
|
24 |
+
|
|
25 |
+
<a href="web_tester_documentation.html">Web tester</a>
|
26 |
+
|
|
27 |
+
<a href="form_testing_documentation.html">Testing forms</a>
|
28 |
+
|
|
29 |
+
<a href="authentication_documentation.html">Authentication</a>
|
30 |
+
|
|
31 |
+
<a href="browser_documentation.html">Scriptable browser</a>
|
32 |
+
</div></div>
|
33 |
+
<h1>Documentation sur l'authentification</h1>
|
34 |
+
This page...
|
35 |
+
<ul>
|
36 |
+
<li>
|
37 |
+
Passer au travers d'une <a href="#basique">authentification HTTP basique</a>
|
38 |
+
</li>
|
39 |
+
<li>
|
40 |
+
Tester l'<a href="#cookies">authentification basée sur des cookies</a>
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
Gérer les <a href="#session">sessions du navigateur</a> et les timeouts
|
44 |
+
</li>
|
45 |
+
</ul>
|
46 |
+
<div class="content">
|
47 |
+
|
48 |
+
<p>
|
49 |
+
Un des secteurs à la fois délicat et important lors d'un test
|
50 |
+
de site web reste la sécurité. Tester ces schémas est au coeur
|
51 |
+
des objectifs du testeur web de SimpleTest.
|
52 |
+
</p>
|
53 |
+
|
54 |
+
<h2>
|
55 |
+
<a class="target" name="basique"></a>Authentification HTTP basique</h2>
|
56 |
+
<p>
|
57 |
+
Si vous allez chercher une page web protégée
|
58 |
+
par une authentification basique, vous hériterez d'une entête 401.
|
59 |
+
Nous pouvons représenter ceci par ce test...
|
60 |
+
<pre>
|
61 |
+
class AuthenticationTest extends WebTestCase {<strong>
|
62 |
+
function test401Header() {
|
63 |
+
$this->get('http://www.lastcraft.com/protected/');
|
64 |
+
$this->showHeaders();
|
65 |
+
}</strong>
|
66 |
+
}
|
67 |
+
</pre>
|
68 |
+
Ce qui nous permet de voir les entêtes reçues...
|
69 |
+
<div class="demo">
|
70 |
+
<h1>File test</h1>
|
71 |
+
<pre style="background-color: lightgray; color: black">
|
72 |
+
HTTP/1.1 401 Authorization Required
|
73 |
+
Date: Sat, 18 Sep 2004 19:25:18 GMT
|
74 |
+
Server: Apache/1.3.29 (Unix) PHP/4.3.4
|
75 |
+
WWW-Authenticate: Basic realm="SimpleTest basic authentication"
|
76 |
+
Connection: close
|
77 |
+
Content-Type: text/html; charset=iso-8859-1
|
78 |
+
</pre>
|
79 |
+
<div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">1/1 test cases complete.
|
80 |
+
<strong>0</strong> passes, <strong>0</strong> fails and <strong>0</strong> exceptions.</div>
|
81 |
+
</div>
|
82 |
+
Sauf que nous voulons éviter l'inspection visuelle,
|
83 |
+
on souhaite que SimpleTest puisse nous dire si oui ou non
|
84 |
+
la page est protégée. Voici un test en profondeur sur nos entêtes...
|
85 |
+
<pre>
|
86 |
+
class AuthenticationTest extends WebTestCase {
|
87 |
+
function test401Header() {
|
88 |
+
$this->get('http://www.lastcraft.com/protected/');<strong>
|
89 |
+
$this->assertAuthentication('Basic');
|
90 |
+
$this->assertResponse(401);
|
91 |
+
$this->assertRealm('SimpleTest basic authentication');</strong>
|
92 |
+
}
|
93 |
+
}
|
94 |
+
</pre>
|
95 |
+
N'importe laquelle de ces assertions suffirait,
|
96 |
+
tout dépend de la masse de détails que vous souhaitez voir.
|
97 |
+
</p>
|
98 |
+
<p>
|
99 |
+
Un des axes qui traverse SimpleTest est la possibilité d'utiliser
|
100 |
+
des objets <span class="new_code">SimpleExpectation</span> à chaque fois qu'une
|
101 |
+
vérification simple suffit.
|
102 |
+
Si vous souhaitez vérifiez simplement le contenu du realm - l'identification
|
103 |
+
du domaine - dans notre exemple, il suffit de faire...
|
104 |
+
<pre>
|
105 |
+
class AuthenticationTest extends WebTestCase {
|
106 |
+
function test401Header() {
|
107 |
+
$this->get('http://www.lastcraft.com/protected/');
|
108 |
+
$this->assertRealm(<strong>new PatternExpectation('/simpletest/i')</strong>);
|
109 |
+
}
|
110 |
+
}
|
111 |
+
</pre>
|
112 |
+
Ce type de test, vérifier les réponses HTTP, n'est cependant pas commun.
|
113 |
+
</p>
|
114 |
+
<p>
|
115 |
+
La plupart du temps, nous ne souhaitons pas tester
|
116 |
+
l'authentification en elle-même, mais plutôt
|
117 |
+
les pages protégées par cette authentification.
|
118 |
+
Dès que la tentative d'authentification est reçue,
|
119 |
+
nous pouvons y répondre à l'aide d'une réponse d'authentification :
|
120 |
+
<pre>
|
121 |
+
class AuthenticationTest extends WebTestCase {
|
122 |
+
function testAuthentication() {
|
123 |
+
$this->get('http://www.lastcraft.com/protected/');<strong>
|
124 |
+
$this->authenticate('Me', 'Secret');</strong>
|
125 |
+
$this->assertTitle(...);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
</pre>
|
129 |
+
Le nom d'utilisateur et le mot de passe seront désormais
|
130 |
+
envoyés à chaque requête vers ce répertoire
|
131 |
+
et ses sous-répertoires.
|
132 |
+
En revanche vous devrez vous authentifier à nouveau
|
133 |
+
si vous sortez de ce répertoire mais SimpleTest est assez
|
134 |
+
intelligent pour fusionner les sous-répertoires dans un même domaine.
|
135 |
+
</p>
|
136 |
+
<p>
|
137 |
+
Vous pouvez gagner une ligne en définissant
|
138 |
+
l'authentification au niveau de l'URL...
|
139 |
+
<pre>
|
140 |
+
class AuthenticationTest extends WebTestCase {
|
141 |
+
function testCanReadAuthenticatedPages() {
|
142 |
+
$this->get('http://<strong>Me:Secret@</strong>www.lastcraft.com/protected/');
|
143 |
+
$this->assertTitle(...);
|
144 |
+
}
|
145 |
+
}
|
146 |
+
</pre>
|
147 |
+
Si votre nom d'utilisateur ou mot de passe comporte
|
148 |
+
des caractères spéciaux, alors n'oubliez pas de les encoder,
|
149 |
+
sinon la requête ne sera pas analysée correctement.
|
150 |
+
De plus cette entête ne sera pas envoyée aux
|
151 |
+
sous requêtes si vous la définissez avec une URL absolue.
|
152 |
+
Par contre si vous naviguez avec des URL relatives,
|
153 |
+
l'information d'authentification sera préservée.
|
154 |
+
</p>
|
155 |
+
<p>
|
156 |
+
Normalement, vous utilisez l'appel <span class="new_code">authenticate()</span>. SimpleTest
|
157 |
+
utilisera alors vos informations de connexion à chaque requête.
|
158 |
+
</p>
|
159 |
+
<p>
|
160 |
+
Pour l'instant, seule l'authentification de base est implémentée
|
161 |
+
et elle n'est réellement fiable qu'en tandem avec une connexion HTTPS.
|
162 |
+
C'est généralement suffisant pour protéger
|
163 |
+
le serveur testé des regards malveillants.
|
164 |
+
Les authentifications Digest et NTLM pourraient être ajoutées prochainement.
|
165 |
+
</p>
|
166 |
+
|
167 |
+
<h2>
|
168 |
+
<a class="target" name="cookies"></a>Cookies</h2>
|
169 |
+
<p>
|
170 |
+
L'authentification de base ne donne pas assez de contrôle
|
171 |
+
au développeur Web sur l'interface utilisateur.
|
172 |
+
Il y a de forte chance pour que cette fonctionnalité
|
173 |
+
soit codée directement dans l'architecture web
|
174 |
+
à grand renfort de cookies et de timeouts compliqués.
|
175 |
+
</p>
|
176 |
+
<p>
|
177 |
+
Commençons par un simple formulaire de connexion...
|
178 |
+
<pre>
|
179 |
+
<form>
|
180 |
+
Username:
|
181 |
+
<input type="text" name="u" value="" /><br />
|
182 |
+
Password:
|
183 |
+
<input type="password" name="p" value="" /><br />
|
184 |
+
<input type="submit" value="Log in" />
|
185 |
+
</form>
|
186 |
+
</pre>
|
187 |
+
Lequel doit ressembler à...
|
188 |
+
</p>
|
189 |
+
<p>
|
190 |
+
<form class="demo">
|
191 |
+
Username:
|
192 |
+
<input type="text" name="u" value=""><br>
|
193 |
+
Password:
|
194 |
+
<input type="password" name="p" value=""><br>
|
195 |
+
<input type="submit" value="Log in">
|
196 |
+
</form>
|
197 |
+
</p>
|
198 |
+
<p>
|
199 |
+
Supposons que, durant le chargement de la page,
|
200 |
+
un cookie ait été inscrit avec un numéro d'identifiant de session.
|
201 |
+
Nous n'allons pas encore remplir le formulaire,
|
202 |
+
juste tester que nous pistons bien l'utilisateur.
|
203 |
+
Voici le test...
|
204 |
+
<pre>
|
205 |
+
class LogInTest extends WebTestCase {
|
206 |
+
function testSessionCookieSetBeforeForm() {
|
207 |
+
$this->get('http://www.my-site.com/login.php');<strong>
|
208 |
+
$this->assertCookie('SID');</strong>
|
209 |
+
}
|
210 |
+
}
|
211 |
+
</pre>
|
212 |
+
Nous nous contentons ici de vérifier que le cookie a bien été défini.
|
213 |
+
Etant donné que sa valeur est plutôt énigmatique,
|
214 |
+
elle ne vaudrait pas la peine d'être testée avec...
|
215 |
+
<pre>
|
216 |
+
class LogInTest extends WebTestCase {
|
217 |
+
function testSessionCookieIsCorrectPattern() {
|
218 |
+
$this->get('http://www.my-site.com/login.php');
|
219 |
+
$this->assertCookie('SID', <strong>new PatternExpectation('/[a-f0-9]{32}/i')</strong>);
|
220 |
+
}
|
221 |
+
}
|
222 |
+
</pre>
|
223 |
+
Si vous utilisez PHP pour gérer vos sessions alors
|
224 |
+
ce test est encore plus inutile, étant donné qu'il ne fait
|
225 |
+
que tester PHP lui-même.
|
226 |
+
</p>
|
227 |
+
<p>
|
228 |
+
Le test le plus simple pour vérifier que la connexion a bien eu lieu
|
229 |
+
reste d'inspecter visuellement la page suivante :
|
230 |
+
un simple appel à <span class="new_code">WebTestCase::assertText()</span> et le tour est joué.
|
231 |
+
</p>
|
232 |
+
<p>
|
233 |
+
Le reste du test est le même que dans n'importe quel autre formulaire,
|
234 |
+
mais nous pourrions souhaiter nous assurer
|
235 |
+
que le cookie n'a pas été modifié depuis la phase de connexion.
|
236 |
+
Voici comment cela pourrait être testé :
|
237 |
+
<pre>
|
238 |
+
class LogInTest extends WebTestCase {
|
239 |
+
...
|
240 |
+
function testSessionCookieSameAfterLogIn() {
|
241 |
+
$this->get('http://www.my-site.com/login.php');<strong>
|
242 |
+
$session = $this->getCookie('SID');
|
243 |
+
$this->setField('u', 'Me');
|
244 |
+
$this->setField('p', 'Secret');
|
245 |
+
$this->clickSubmit('Log in');
|
246 |
+
$this->assertWantedPattern('/Welcome Me/');
|
247 |
+
$this->assertCookie('SID', $session);</strong>
|
248 |
+
}
|
249 |
+
}
|
250 |
+
</pre>
|
251 |
+
Ceci confirme que l'identifiant de session
|
252 |
+
est identique avant et après la connexion.
|
253 |
+
</p>
|
254 |
+
<p>
|
255 |
+
Nous pouvons même essayer de duper notre propre système
|
256 |
+
en créant un cookie arbitraire pour se connecter...
|
257 |
+
<pre>
|
258 |
+
class LogInTest extends WebTestCase {
|
259 |
+
...
|
260 |
+
function testSessionCookieSameAfterLogIn() {
|
261 |
+
$this->get('http://www.my-site.com/login.php');<strong>
|
262 |
+
$this->setCookie('SID', 'Some other session');
|
263 |
+
$this->get('http://www.my-site.com/restricted.php');</strong>
|
264 |
+
$this->assertWantedPattern('/Access denied/');
|
265 |
+
}
|
266 |
+
}
|
267 |
+
</pre>
|
268 |
+
Votre site est-il protégé contre ce type d'attaque ?
|
269 |
+
</p>
|
270 |
+
|
271 |
+
<h2>
|
272 |
+
<a class="target" name="session"></a>Sessions de navigateur</h2>
|
273 |
+
<p>
|
274 |
+
Si vous testez un système d'authentification,
|
275 |
+
la reconnexion par un utilisateur est un point sensible.
|
276 |
+
Essayons de simuler ce qui se passe dans ce cas :
|
277 |
+
<pre>
|
278 |
+
class LogInTest extends WebTestCase {
|
279 |
+
...
|
280 |
+
function testLoseAuthenticationAfterBrowserClose() {
|
281 |
+
$this->get('http://www.my-site.com/login.php');
|
282 |
+
$this->setField('u', 'Me');
|
283 |
+
$this->setField('p', 'Secret');
|
284 |
+
$this->clickSubmit('Log in');
|
285 |
+
$this->assertWantedPattern('/Welcome Me/');<strong>
|
286 |
+
|
287 |
+
$this->restart();
|
288 |
+
$this->get('http://www.my-site.com/restricted.php');
|
289 |
+
$this->assertWantedPattern('/Access denied/');</strong>
|
290 |
+
}
|
291 |
+
}
|
292 |
+
</pr
|