Version Description
- Fix: Clear country cache automatically.
- Fix: Fixed notices when using quick edit.
- Fix: Fixed html in checkout form.
- Fix: Fixed shipping results not being displayed.
- Fix: Does not show errors when deprecated google checkout is used.
- Fix: Makes sure countries are validated if mandatory.
- Fix: Makes sure the payment gateway checks for first and last name.
- Fix: Only output html for shipping error page.
- Fix: Updated shipping calculator to check for new checkout information and made the calculator more efficient.
- Fix: USPS shipping now works for servers that don't support curl.
- Fix: Personalization forms are correctly initialized in database.
- Fix: Display of products in admin product gallery will display in the order admins want them to.
- New: Updated Polish and Russian language files.
- New: Added filter wpsc_uncategorized_product_category to change uncategorized section.
- New: New hook - wpsc_coupon_add_top and wpsc_coupon_add_bottom for the add coupon section.
- New: New hook - wpsc_element_is_visible to check and see if an element is visible.
- Change: Show region on shipping calculator.
- Change: Billing was accidentally referred to as shipping when billing state and region was a drop down.
Download this release
Release Info
Developer | JustinSainton |
Plugin | WP eCommerce |
Version | 3.8.14.2 |
Comparing to | |
See all releases |
Code changes from version 3.8.14.1 to 3.8.14.2
- readme.md +1 -1
- readme.txt +22 -1
- wp-shopping-cart.php +1 -1
- wpsc-admin/admin.php +6 -1
- wpsc-admin/display-coupon-add.php +6 -2
- wpsc-admin/display-coupon-edit.php +6 -2
- wpsc-admin/includes/display-items-functions.php +1208 -1106
- wpsc-admin/js/admin.js +20 -11
- wpsc-admin/js/media.js +5 -0
- wpsc-admin/media.php +1 -1
- wpsc-components/merchant-core-v3/classes/http.php +0 -34
- wpsc-components/merchant-core-v3/classes/payment-gateway.php +0 -611
- wpsc-components/merchant-core-v3/gateways/manual.php +0 -55
- wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php +0 -301
- wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php +0 -381
- wpsc-components/merchant-core-v3/gateways/php-merchant/README.md +0 -0
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/exception.php +0 -37
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/helpers.php +0 -15
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/http-curl.php +0 -49
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/http.php +0 -11
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/php-merchant.php +0 -130
- wpsc-components/merchant-core-v3/gateways/php-merchant/common/response.php +0 -39
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-digital-goods.php +0 -79
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout-response.php +0 -123
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php +0 -155
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-ipn.php +0 -138
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-response.php +0 -65
- wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal.php +0 -85
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/http-curl.php +0 -30
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/php-merchant.php +0 -170
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/test-accounts.php +0 -10
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-express-checkout.php +0 -543
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-ipn.php +0 -90
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal.php +0 -125
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/index.php +0 -38
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/http-curl.php +0 -29
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/paypal-express-checkout.php +0 -140
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE +0 -399
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/LICENSE +0 -502
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/README +0 -102
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/VERSION +0 -1
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/authentication.php +0 -237
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/autorun.php +0 -99
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/browser.php +0 -1144
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/collector.php +0 -122
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/compatibility.php +0 -166
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/cookies.php +0 -380
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/default_reporter.php +0 -163
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/detached.php +0 -96
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/authentication_documentation.html +0 -378
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/browser_documentation.html +0 -501
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/docs.css +0 -121
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/expectation_documentation.html +0 -476
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/form_testing_documentation.html +0 -351
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/group_test_documentation.html +0 -252
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/index.html +0 -542
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/mock_objects_documentation.html +0 -870
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/overview.html +0 -487
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/partial_mocks_documentation.html +0 -457
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/reporter_documentation.html +0 -616
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/unit_test_documentation.html +0 -442
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/en/web_tester_documentation.html +0 -588
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/authentication_documentation.html +0 -371
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/browser_documentation.html +0 -500
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/docs.css +0 -84
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/expectation_documentation.html +0 -451
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/form_testing_documentation.html +0 -353
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/group_test_documentation.html +0 -401
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/index.html +0 -576
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/mock_objects_documentation.html +0 -784
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/overview.html +0 -321
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/partial_mocks_documentation.html +0 -464
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/reporter_documentation.html +0 -538
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/unit_test_documentation.html +0 -450
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/web_tester_documentation.html +0 -570
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/dumper.php +0 -407
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/eclipse.php +0 -307
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/encoding.php +0 -649
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/errors.php +0 -267
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/exceptions.php +0 -226
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/expectation.php +0 -984
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/extensions/pear_test_case.php +0 -196
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/extensions/testdox.php +0 -53
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/extensions/testdox/test.php +0 -107
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/form.php +0 -361
- wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/frames.php +0 -187
readme.md
CHANGED
@@ -15,7 +15,7 @@ If you're looking for general user support, please submit your support request o
|
|
15 |
Development status
|
16 |
-------------------------
|
17 |
|
18 |
-
* The latest stable version is [3.8.14.
|
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)
|
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)
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://getshopped.org
|
|
4 |
Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
|
5 |
Requires at least: 3.7
|
6 |
Tested up to: 3.9
|
7 |
-
Stable tag: 3.8.14.
|
8 |
|
9 |
WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily.
|
10 |
|
@@ -36,6 +36,27 @@ After upgrading from earlier versions look for link "Update Store". This will up
|
|
36 |
|
37 |
== Changelog ==
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
= 3.8.14.1 =
|
40 |
|
41 |
* Fix: For users with older (3.7.x and older) templates copied into their theme directory, we inadvertently broke the visibility of the shipping calculator.
|
4 |
Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
|
5 |
Requires at least: 3.7
|
6 |
Tested up to: 3.9
|
7 |
+
Stable tag: 3.8.14.2
|
8 |
|
9 |
WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily.
|
10 |
|
36 |
|
37 |
== Changelog ==
|
38 |
|
39 |
+
= 3.8.14.2 =
|
40 |
+
|
41 |
+
* Fix: Clear country cache automatically.
|
42 |
+
* Fix: Fixed notices when using quick edit.
|
43 |
+
* Fix: Fixed html in checkout form.
|
44 |
+
* Fix: Fixed shipping results not being displayed.
|
45 |
+
* Fix: Does not show errors when deprecated google checkout is used.
|
46 |
+
* Fix: Makes sure countries are validated if mandatory.
|
47 |
+
* Fix: Makes sure the payment gateway checks for first and last name.
|
48 |
+
* Fix: Only output html for shipping error page.
|
49 |
+
* Fix: Updated shipping calculator to check for new checkout information and made the calculator more efficient.
|
50 |
+
* Fix: USPS shipping now works for servers that don't support curl.
|
51 |
+
* Fix: Personalization forms are correctly initialized in database.
|
52 |
+
* Fix: Display of products in admin product gallery will display in the order admins want them to.
|
53 |
+
* New: Updated Polish and Russian language files.
|
54 |
+
* New: Added filter wpsc_uncategorized_product_category to change uncategorized section.
|
55 |
+
* New: New hook - wpsc_coupon_add_top and wpsc_coupon_add_bottom for the add coupon section.
|
56 |
+
* New: New hook - wpsc_element_is_visible to check and see if an element is visible.
|
57 |
+
* Change: Show region on shipping calculator.
|
58 |
+
* Change: Billing was accidentally referred to as shipping when billing state and region was a drop down.
|
59 |
+
|
60 |
= 3.8.14.1 =
|
61 |
|
62 |
* Fix: For users with older (3.7.x and older) templates copied into their theme directory, we inadvertently broke the visibility of the shipping calculator.
|
wp-shopping-cart.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WP e-Commerce
|
4 |
* Plugin URI: http://getshopped.org/
|
5 |
* Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="https://wordpress.org/support/plugin/wp-e-commerce/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a>
|
6 |
-
* Version: 3.8.14.
|
7 |
* Author: Instinct Entertainment
|
8 |
* Author URI: http://getshopped.org/
|
9 |
**/
|
3 |
* Plugin Name: WP e-Commerce
|
4 |
* Plugin URI: http://getshopped.org/
|
5 |
* Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="https://wordpress.org/support/plugin/wp-e-commerce/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a>
|
6 |
+
* Version: 3.8.14.2
|
7 |
* Author: Instinct Entertainment
|
8 |
* Author URI: http://getshopped.org/
|
9 |
**/
|
wpsc-admin/admin.php
CHANGED
@@ -456,9 +456,14 @@ function wpsc_admin_include_coupon_js() {
|
|
456 |
// Coupon JS
|
457 |
wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
|
458 |
wp_enqueue_script( 'jquery-ui-datepicker' );
|
|
|
|
|
459 |
wp_enqueue_script( 'wp-e-commerce-admin_legacy', WPSC_URL . '/wpsc-admin/js/admin-legacy.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker' ), $version_identifier );
|
460 |
|
461 |
-
|
|
|
|
|
|
|
462 |
}
|
463 |
|
464 |
/**
|
456 |
// Coupon JS
|
457 |
wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
|
458 |
wp_enqueue_script( 'jquery-ui-datepicker' );
|
459 |
+
wp_enqueue_style( 'jquery-ui-datepicker' );
|
460 |
+
|
461 |
wp_enqueue_script( 'wp-e-commerce-admin_legacy', WPSC_URL . '/wpsc-admin/js/admin-legacy.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker' ), $version_identifier );
|
462 |
|
463 |
+
$admin_color = get_user_option( 'admin_color' );
|
464 |
+
$scheme = 'classic' === $admin_color ? $admin_color : 'fresh';
|
465 |
+
|
466 |
+
wp_enqueue_style( 'wpsc-jquery-ui-datepicker', WPSC_URL . '/wpsc-admin/css/jquery.ui.datepicker-' . $scheme . '.css', false, $version_identifier );
|
467 |
}
|
468 |
|
469 |
/**
|
wpsc-admin/display-coupon-add.php
CHANGED
@@ -5,6 +5,8 @@
|
|
5 |
<table class="form-table">
|
6 |
<tbody>
|
7 |
|
|
|
|
|
8 |
<tr class="form-field">
|
9 |
<th scope="row" valign="top">
|
10 |
<label for="add_coupon_code"><?php _e( 'Coupon Code', 'wpsc' ); ?></label>
|
@@ -20,8 +22,8 @@
|
|
20 |
<label for="add-coupon-code"><?php _e( 'Discount', 'wpsc' ); ?></label>
|
21 |
</th>
|
22 |
<td>
|
23 |
-
<input name="add_discount" id="add-coupon-code" type="number" class="small-text" min="0" />
|
24 |
-
<
|
25 |
</td>
|
26 |
</tr>
|
27 |
|
@@ -118,6 +120,8 @@
|
|
118 |
</td>
|
119 |
</tr>
|
120 |
|
|
|
|
|
121 |
</tbody>
|
122 |
</table>
|
123 |
|
5 |
<table class="form-table">
|
6 |
<tbody>
|
7 |
|
8 |
+
<?php do_action( 'wpsc_coupon_add_top' ); ?>
|
9 |
+
|
10 |
<tr class="form-field">
|
11 |
<th scope="row" valign="top">
|
12 |
<label for="add_coupon_code"><?php _e( 'Coupon Code', 'wpsc' ); ?></label>
|
22 |
<label for="add-coupon-code"><?php _e( 'Discount', 'wpsc' ); ?></label>
|
23 |
</th>
|
24 |
<td>
|
25 |
+
<input name="add_discount" step=".01" id="add-coupon-code" type="number" class="small-text" min="0" style="width: 300px" />
|
26 |
+
<p class="description"><?php _e( 'The discount amount', 'wpsc' ); ?></p>
|
27 |
</td>
|
28 |
</tr>
|
29 |
|
120 |
</td>
|
121 |
</tr>
|
122 |
|
123 |
+
<?php do_action( 'wpsc_coupon_add_bottom' ); ?>
|
124 |
+
|
125 |
</tbody>
|
126 |
</table>
|
127 |
|
wpsc-admin/display-coupon-edit.php
CHANGED
@@ -22,6 +22,8 @@ $coupon = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_COUP
|
|
22 |
<table class="form-table">
|
23 |
<tbody>
|
24 |
|
|
|
|
|
25 |
<tr class="form-field">
|
26 |
<th scope="row" valign="top">
|
27 |
<label for="edit_coupon_code"><?php _e( 'Coupon Code', 'wpsc' ); ?></label>
|
@@ -37,8 +39,8 @@ $coupon = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_COUP
|
|
37 |
<label for="edit_coupon_amount"><?php _e( 'Discount', 'wpsc' ); ?></label>
|
38 |
</th>
|
39 |
<td>
|
40 |
-
<input name="edit_coupon_amount" id="edit_coupon_amount" type="number" value="<?php esc_attr_e( $coupon['value'] ); ?>" class="small-text" min="0" />
|
41 |
-
<
|
42 |
</td>
|
43 |
</tr>
|
44 |
|
@@ -163,6 +165,8 @@ $coupon = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_COUP
|
|
163 |
</td>
|
164 |
</tr>
|
165 |
|
|
|
|
|
166 |
</tbody>
|
167 |
</table>
|
168 |
<input type="hidden" name="coupon_id" value="<?php echo esc_attr( $coupon_id ); ?>"/>
|
22 |
<table class="form-table">
|
23 |
<tbody>
|
24 |
|
25 |
+
<?php do_action( 'wpsc_coupon_edit_top', $coupon_id, $coupon ); ?>
|
26 |
+
|
27 |
<tr class="form-field">
|
28 |
<th scope="row" valign="top">
|
29 |
<label for="edit_coupon_code"><?php _e( 'Coupon Code', 'wpsc' ); ?></label>
|
39 |
<label for="edit_coupon_amount"><?php _e( 'Discount', 'wpsc' ); ?></label>
|
40 |
</th>
|
41 |
<td>
|
42 |
+
<input name="edit_coupon_amount" id="edit_coupon_amount" type="number" step=".01" value="<?php esc_attr_e( $coupon['value'] ); ?>" class="small-text" min="0" style="width: 300px" />
|
43 |
+
<p class="description"><?php _e( 'The discount amount', 'wpsc' ); ?></p>
|
44 |
</td>
|
45 |
</tr>
|
46 |
|
165 |
</td>
|
166 |
</tr>
|
167 |
|
168 |
+
<?php do_action( 'wpsc_coupon_edit_top', $coupon_id, $coupon ); ?>
|
169 |
+
|
170 |
</tbody>
|
171 |
</table>
|
172 |
<input type="hidden" name="coupon_id" value="<?php echo esc_attr( $coupon_id ); ?>"/>
|
wpsc-admin/includes/display-items-functions.php
CHANGED
@@ -9,483 +9,483 @@
|
|
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 |
<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 |
-
|
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 |
-
|
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 |
<?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 +496,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 +511,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 +530,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 +560,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 +585,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,267 +601,266 @@ 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 |
// aka custom meta form
|
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 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
}
|
817 |
|
818 |
-
|
|
|
|
|
819 |
function wpsc_product_external_link_forms() {
|
820 |
-
|
821 |
-
|
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 |
-
</tbody>
|
861 |
-
</table>
|
862 |
-
<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>
|
863 |
-
<?php
|
864 |
}
|
|
|
865 |
function wpsc_additional_desc() {
|
866 |
?>
|
867 |
<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,55 +877,67 @@ function wpsc_additional_desc() {
|
|
878 |
* @return void
|
879 |
*/
|
880 |
function wpsc_product_gallery( $post ) {
|
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 |
function wpsc_product_download_forms() {
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
|
913 |
-
|
914 |
-
|
915 |
|
916 |
-
|
917 |
?>
|
918 |
-
|
919 |
|
920 |
-
|
921 |
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
|
928 |
<?php
|
929 |
-
|
930 |
?>
|
931 |
<br />
|
932 |
<h4><?php esc_html_e( 'Select an MP3 file to upload as a preview', 'wpsc' ) ?></h4>
|
@@ -934,118 +945,122 @@ function wpsc_product_download_forms() {
|
|
934 |
|
935 |
<h4><?php esc_html_e( 'Your preview for this product', 'wpsc' ) ?>:</h4>
|
936 |
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
|
945 |
-
|
946 |
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
|
951 |
-
|
952 |
<br />
|
953 |
<?php
|
954 |
-
|
955 |
|
956 |
-
|
957 |
}
|
958 |
|
959 |
function wpsc_product_personalization_forms(){
|
|
|
|
|
|
|
|
|
960 |
?>
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
<?php
|
975 |
}
|
976 |
|
977 |
function wpsc_product_delivery_forms(){
|
978 |
-
|
979 |
|
980 |
-
|
981 |
?>
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
<?php
|
1012 |
}
|
1013 |
|
1014 |
function wpsc_product_details_forms(){
|
1015 |
?>
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
<?php
|
1045 |
}
|
1046 |
|
1047 |
function wpsc_form_multipart_encoding() {
|
1048 |
-
|
1049 |
}
|
1050 |
|
1051 |
add_action( 'post_edit_form_tag', 'wpsc_form_multipart_encoding' );
|
@@ -1069,131 +1084,131 @@ add_filter( 'gettext_with_context', 'wpsc_filter_gettex_with_context', 12, 4);
|
|
1069 |
*/
|
1070 |
function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
|
1071 |
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
}
|
1080 |
|
1081 |
function wpsc_attachment_fields( $form_fields, $post ) {
|
1082 |
-
|
1083 |
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
|
1089 |
-
|
1090 |
-
|
1091 |
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
<script type="text/javascript">
|
1096 |
|
1097 |
-
|
1098 |
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
|
1106 |
-
|
1107 |
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
|
1112 |
|
1113 |
-
|
1114 |
|
1115 |
</script>';
|
1116 |
-
|
1117 |
|
1118 |
-
|
1119 |
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
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 |
function wpsc_save_attachment_fields( $post, $attachment ) {
|
1183 |
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
|
1196 |
-
|
1197 |
}
|
1198 |
|
1199 |
/**
|
@@ -1207,20 +1222,20 @@ function wpsc_save_attachment_fields( $post, $attachment ) {
|
|
1207 |
*/
|
1208 |
|
1209 |
function wpsc_save_quickedit_box( $post_id ) {
|
1210 |
-
|
1211 |
|
1212 |
-
|
1213 |
-
|
1214 |
|
1215 |
-
|
1216 |
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
|
1225 |
$args = array(
|
1226 |
'post_parent' => $post_id,
|
@@ -1228,58 +1243,58 @@ function wpsc_save_quickedit_box( $post_id ) {
|
|
1228 |
'post_status' => 'inherit'
|
1229 |
);
|
1230 |
$children = get_children($args);
|
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 |
/**
|
@@ -1292,64 +1307,64 @@ function wpsc_save_quickedit_box( $post_id ) {
|
|
1292 |
*/
|
1293 |
|
1294 |
function wpsc_quick_edit_boxes( $col_name, $_screen_post_type = null ) {
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
?>
|
1300 |
|
1301 |
<fieldset class="inline-edit-col-left wpsc-cols">
|
1302 |
<div class="inline-edit-col">
|
1303 |
<div class="inline-edit-group">
|
1304 |
<?php
|
1305 |
-
|
1306 |
-
|
1307 |
?>
|
1308 |
<label style="max-width: 85%" class="alignleft">
|
1309 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'SKU:', 'wpsc' ); ?> </span>
|
1310 |
<input type="text" name="sku" class="wpsc_ie_sku" />
|
1311 |
-
|
1312 |
|
1313 |
</label>
|
1314 |
<?php
|
1315 |
-
|
1316 |
case 'weight' :
|
1317 |
?>
|
1318 |
<label style="max-width: 85%" class="alignleft">
|
1319 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Weight:', 'wpsc' ); ?> </span>
|
1320 |
<input type="text" name="weight" class="wpsc_ie_weight" />
|
1321 |
-
|
1322 |
</label>
|
1323 |
<?php
|
1324 |
-
|
1325 |
case 'stock' :
|
1326 |
?>
|
1327 |
<label style="max-width: 85%" class="alignleft">
|
1328 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Stock:', 'wpsc' ); ?> </span>
|
1329 |
<input type="text" name="stock" class="wpsc_ie_stock" />
|
1330 |
-
|
1331 |
</label>
|
1332 |
<?php
|
1333 |
-
|
1334 |
case 'price' :
|
1335 |
?>
|
1336 |
<label style="max-width: 85%" class="alignleft">
|
1337 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Price:', 'wpsc' ); ?> </span>
|
1338 |
<input type="text" name="price" class="wpsc_ie_price" />
|
1339 |
-
|
1340 |
</label>
|
1341 |
<?php
|
1342 |
-
|
1343 |
case 'sale_price' :
|
1344 |
?>
|
1345 |
<label style="max-width: 85%" class="alignleft">
|
1346 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Sale Price:', 'wpsc' ); ?> </span>
|
1347 |
<input type="text" name="sale_price" class="wpsc_ie_sale_price" />
|
1348 |
-
|
1349 |
</label>
|
1350 |
<?php
|
1351 |
-
|
1352 |
-
|
1353 |
?>
|
1354 |
</div>
|
1355 |
</div>
|
@@ -1368,54 +1383,54 @@ add_action( 'save_post', 'wpsc_save_quickedit_box' );
|
|
1368 |
* @param <type> $variation
|
1369 |
*/
|
1370 |
function variation_price_field( $variation ) {
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
<th scope="row" valign="top">
|
1410 |
-
|
1411 |
</th>
|
1412 |
<td>
|
1413 |
-
|
1414 |
-
|
1415 |
</td>
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
}
|
1420 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field' );
|
1421 |
add_action( 'wpsc-variation_add_form_fields', 'variation_price_field' );
|
@@ -1426,17 +1441,17 @@ Use Jquery to move the set variation (parent) field to the top and add a descrip
|
|
1426 |
*/
|
1427 |
function variation_set_field(){
|
1428 |
?>
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
<?php
|
1441 |
}
|
1442 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_set_field' );
|
@@ -1445,27 +1460,27 @@ add_action( 'wpsc-variation_add_form_fields', 'variation_set_field' );
|
|
1445 |
|
1446 |
function category_edit_form(){
|
1447 |
?>
|
1448 |
-
|
1449 |
|
1450 |
-
|
1451 |
<?php
|
1452 |
}
|
1453 |
|
1454 |
function variation_price_field_check( $variation ) {
|
1455 |
|
1456 |
-
|
1457 |
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
<?php
|
1470 |
}
|
1471 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field_check' );
|
@@ -1474,83 +1489,170 @@ add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field_check' );
|
|
1474 |
|
1475 |
/**
|
1476 |
* @todo - Should probably refactor this at some point - very procedural,
|
1477 |
-
*
|
1478 |
*
|
1479 |
* @param <type> $term_id
|
1480 |
*/
|
1481 |
function save_term_prices( $term_id ) {
|
1482 |
-
|
1483 |
-
|
1484 |
|
1485 |
-
|
1486 |
|
1487 |
-
|
1488 |
-
|
1489 |
|
1490 |
-
|
1491 |
-
|
1492 |
|
1493 |
-
|
1494 |
-
|
1495 |
|
1496 |
-
|
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 |
add_action( 'edited_wpsc-variation', 'save_term_prices' );
|
1538 |
add_action( 'created_wpsc-variation', 'save_term_prices' );
|
1539 |
|
1540 |
function wpsc_delete_variations( $postid ) {
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
}
|
1556 |
add_action( 'before_delete_post', 'wpsc_delete_variations' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
'engrave' => '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 |
|
280 |
<?php endif;
|
281 |
|
282 |
}
|
283 |
function wpsc_stock_control_forms() {
|
284 |
+
global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
|
285 |
|
286 |
+
$product_data = get_post_custom( $post->ID );
|
287 |
+
$product_data['meta'] = maybe_unserialize( $product_data );
|
288 |
|
289 |
+
foreach ( $product_data['meta'] as $meta_key => $meta_value ) {
|
290 |
+
$product_data['meta'][$meta_key] = $meta_value[0];
|
291 |
+
}
|
292 |
|
293 |
+
$product_meta = array();
|
294 |
|
295 |
+
if ( ! empty( $product_data['_wpsc_product_metadata'] ) ) {
|
296 |
+
$product_meta = maybe_unserialize( $product_data["_wpsc_product_metadata"][0] );
|
297 |
+
}
|
298 |
|
299 |
+
// this is to make sure after upgrading to 3.8.9, products will have
|
300 |
+
// "notify_when_none_left" enabled by default if "unpublish_when_none_left"
|
301 |
+
// is enabled.
|
302 |
+
if ( ! isset( $product_meta['notify_when_none_left'] ) ) {
|
303 |
+
$product_meta['notify_when_none_left'] = 0;
|
304 |
|
305 |
+
if ( ! empty( $product_meta['unpublish_when_none_left'] ) ) {
|
306 |
+
$product_meta['notify_when_none_left'] = 1;
|
307 |
+
}
|
308 |
+
}
|
309 |
|
310 |
+
if ( ! isset( $product_meta['unpublish_when_none_left'] ) ) {
|
311 |
+
$product_meta['unpublish_when_none_left'] = '';
|
312 |
+
}
|
313 |
|
314 |
+
// Display live title if stock is set
|
315 |
+
if ( isset( $product_data['meta']['_wpsc_stock'] ) && is_numeric( $product_data['meta']['_wpsc_stock'] ) ) {
|
316 |
+
$live_title = '<em id="wpsc_product_stock_metabox_live_title" class="wpsc_metabox_live_title">';
|
317 |
+
$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' ) );
|
318 |
+
$live_title .= '</em>';
|
319 |
|
320 |
+
echo $live_title;
|
321 |
+
}
|
322 |
|
323 |
+
if ( ! empty( $product_meta['unpublish_when_none_left'] ) && ! isset( $product_meta['notify_when_none_left'] ) )
|
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 |
+
global $post, $wpdb, $wpsc_product_defaults;
|
399 |
+
$product_data = get_post_custom( $post->ID );
|
400 |
+
|
401 |
+
$product_data['meta'] = $product_meta = array();
|
402 |
+
if ( !empty( $product_data['_wpsc_product_metadata'] ) )
|
403 |
+
$product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
|
404 |
+
|
405 |
+
if ( !isset( $product_data['meta']['_wpsc_custom_tax'] ) )
|
406 |
+
$product_data['meta']['_wpsc_custom_tax'] = '';
|
407 |
+
$custom_tax = $product_data['meta']['_wpsc_custom_tax'];
|
408 |
+
|
409 |
+
|
410 |
+
if ( !isset( $product_meta['custom_tax'] ) ) {
|
411 |
+
$product_meta['custom_tax'] = 0.00;
|
412 |
+
}
|
413 |
+
|
414 |
+
//Add New WPEC-Taxes Bands Here
|
415 |
+
$wpec_taxes_controller = new wpec_taxes_controller();
|
416 |
+
|
417 |
+
//display tax bands
|
418 |
+
$band_select_settings = array(
|
419 |
+
'id' => 'wpec_taxes_band',
|
420 |
+
'name' => 'meta[_wpsc_product_metadata][wpec_taxes_band]',
|
421 |
+
'label' => __( 'Custom Tax Band', 'wpsc' )
|
422 |
+
);
|
423 |
+
$wpec_taxes_band = '';
|
424 |
+
if ( isset( $product_meta['wpec_taxes_band'] ) ) {
|
425 |
+
$band = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_band_from_index( $product_meta['wpec_taxes_band'] );
|
426 |
+
$wpec_taxes_band = array( 'index'=>$band['index'], 'name'=>$band['name'] );
|
427 |
+
}
|
428 |
+
|
429 |
+
$taxable_checkbox_settings = array(
|
430 |
+
'type' => 'checkbox',
|
431 |
+
'id' => 'wpec_taxes_taxable',
|
432 |
+
'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable]',
|
433 |
+
'label' => __( 'Product is exempt from taxation.', 'wpsc' )
|
434 |
+
);
|
435 |
+
|
436 |
+
if ( isset( $product_meta['wpec_taxes_taxable'] ) && 'on' == $product_meta['wpec_taxes_taxable'] ) {
|
437 |
+
$taxable_checkbox_settings['checked'] = 'checked';
|
438 |
+
}
|
439 |
+
|
440 |
+
//add taxable amount only for exclusive tax
|
441 |
+
if ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) {
|
442 |
+
$taxable_amount_input_settings = array(
|
443 |
+
'id' => 'wpec_taxes_taxable_amount',
|
444 |
+
'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable_amount]',
|
445 |
+
'label' => __( 'Taxable Amount', 'wpsc' ),
|
446 |
+
'description' => __( 'Taxable amount in your currency, not percentage of price.', 'wpsc' ),
|
447 |
+
);
|
448 |
+
|
449 |
+
if ( isset( $product_meta['wpec_taxes_taxable_amount'] ) ) {
|
450 |
+
$taxable_amount_input_settings['value'] = $product_meta['wpec_taxes_taxable_amount'];
|
451 |
+
|
452 |
+
if ( ! empty( $product_meta['wpec_taxes_taxable_amount'] ) )
|
453 |
+
$taxable_amount_input_settings['value'] = wpsc_format_number(
|
454 |
+
$taxable_amount_input_settings['value']
|
455 |
+
);
|
456 |
+
}
|
457 |
+
}// if
|
458 |
+
|
459 |
+
$output = '<a name="wpsc_tax"></a>';
|
460 |
+
$output .= '<p>'.$wpec_taxes_controller->wpec_taxes_build_input( $taxable_checkbox_settings ).'</p>';
|
461 |
+
$output .= '<p>'.$wpec_taxes_controller->wpec_taxes_display_tax_bands( $band_select_settings, $wpec_taxes_band ).'</p>';
|
462 |
+
$output .= '<p>';
|
463 |
+
$output .= ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) ? $wpec_taxes_controller->wpec_taxes_build_input( $taxable_amount_input_settings ) : '';
|
464 |
+
$output .= '</p>';
|
465 |
+
|
466 |
+
if ( ! $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_enabled() ) {
|
467 |
+
$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>';
|
468 |
+
}
|
469 |
+
|
470 |
+
echo $output;
|
471 |
}
|
472 |
|
473 |
function wpsc_product_variation_forms() {
|
474 |
+
?>
|
475 |
+
<iframe src="<?php echo _wpsc_get_product_variation_form_url(); ?>"></iframe>
|
476 |
+
<?php
|
477 |
}
|
478 |
|
479 |
function _wpsc_get_product_variation_form_url( $id = false ) {
|
480 |
+
if ( ! $id ) {
|
481 |
+
$id = get_the_ID();
|
482 |
+
}
|
483 |
|
484 |
+
return admin_url( 'admin-ajax.php?action=wpsc_product_variations_table&product_id=' . $id . '&_wpnonce=' . wp_create_nonce( 'wpsc_product_variations_table' ) );
|
485 |
}
|
486 |
|
487 |
function wpsc_product_shipping_forms_metabox() {
|
488 |
+
wpsc_product_shipping_forms();
|
489 |
}
|
490 |
|
491 |
/**
|
496 |
* @return array List of valid dimension units.
|
497 |
*/
|
498 |
function wpsc_dimension_units() {
|
499 |
+
return array(
|
500 |
+
'in' => __( 'inches', 'wpsc' ),
|
501 |
+
'cm' => __( 'cm', 'wpsc' ),
|
502 |
+
'meter' => __( 'meters', 'wpsc' )
|
503 |
+
);
|
504 |
}
|
505 |
|
506 |
/**
|
511 |
* @return array List of valid weight units.
|
512 |
*/
|
513 |
function wpsc_weight_units() {
|
514 |
+
return array(
|
515 |
+
'pound' => __( 'pounds', 'wpsc' ),
|
516 |
+
'ounce' => __( 'ounces', 'wpsc' ),
|
517 |
+
'gram' => __( 'grams', 'wpsc' ),
|
518 |
+
'kilogram' => __( 'kilograms', 'wpsc' )
|
519 |
+
);
|
520 |
}
|
521 |
|
522 |
/**
|
530 |
* @return string Weight unit string.
|
531 |
*/
|
532 |
function wpsc_weight_unit_display( $unit ) {
|
533 |
+
switch ( $unit ) {
|
534 |
+
case 'pound' :
|
535 |
+
return __( ' lbs.', 'wpsc' );
|
536 |
+
case 'ounce' :
|
537 |
+
return __( ' oz.', 'wpsc' );
|
538 |
+
case 'gram' :
|
539 |
+
return __( ' g', 'wpsc' );
|
540 |
+
case 'kilograms' :
|
541 |
+
case 'kilogram' :
|
542 |
+
return __( ' kgs.', 'wpsc' );
|
543 |
+
}
|
544 |
+
return '';
|
545 |
}
|
546 |
|
547 |
/**
|
560 |
*/
|
561 |
function wpsc_validate_dimension_unit( $unit = '' ) {
|
562 |
|
563 |
+
$default_unit = apply_filters( 'wpsc_default_dimension_unit', $unit );
|
564 |
|
565 |
+
if ( empty( $unit ) && array_key_exists( $default_unit, wpsc_dimension_units() ) ) {
|
566 |
+
$unit = $default_unit;
|
567 |
+
}
|
568 |
|
569 |
+
return $unit;
|
570 |
}
|
571 |
|
572 |
/**
|
585 |
*/
|
586 |
function wpsc_validate_weight_unit( $unit = '' ) {
|
587 |
|
588 |
+
$default_unit = apply_filters( 'wpsc_default_weight_unit', $unit );
|
589 |
|
590 |
+
if ( empty( $unit ) && array_key_exists( $default_unit, wpsc_weight_units() ) ) {
|
591 |
+
$unit = $default_unit;
|
592 |
+
}
|
593 |
|
594 |
+
return $unit;
|
595 |
}
|
596 |
|
597 |
/**
|
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 |
+
if ( ! $product )
|
605 |
+
$product_id = get_the_ID();
|
606 |
+
else
|
607 |
+
$product_id = $product->ID;
|
608 |
+
|
609 |
+
$meta = get_post_meta( $product_id, '_wpsc_product_metadata', true );
|
610 |
+
if ( ! is_array( $meta ) )
|
611 |
+
$meta = array();
|
612 |
+
|
613 |
+
$defaults = array(
|
614 |
+
'weight' => '',
|
615 |
+
'weight_unit' => wpsc_validate_weight_unit(),
|
616 |
+
'demension_unit' => wpsc_validate_dimension_unit(),
|
617 |
+
'dimensions' => array(),
|
618 |
+
'shipping' => array(),
|
619 |
+
'no_shipping' => '',
|
620 |
+
'display_weight_as' => '',
|
621 |
+
);
|
622 |
+
$dimensions_defaults = array(
|
623 |
+
'height' => 0,
|
624 |
+
'width' => 0,
|
625 |
+
'length' => 0,
|
626 |
+
);
|
627 |
+
$shipping_defaults = array(
|
628 |
+
'local' => '',
|
629 |
+
'international' => '',
|
630 |
+
);
|
631 |
+
$meta = array_merge( $defaults, $meta );
|
632 |
+
$meta['dimensions'] = array_merge( $dimensions_defaults, $meta['dimensions'] );
|
633 |
+
$meta['shipping'] = array_merge( $shipping_defaults, $meta['shipping'] );
|
634 |
+
|
635 |
+
extract( $meta, EXTR_SKIP );
|
636 |
+
|
637 |
+
foreach ( $shipping as $key => &$val ) {
|
638 |
+
$val = wpsc_format_number( $val );
|
639 |
+
}
|
640 |
+
|
641 |
+
$weight = wpsc_convert_weight( $weight, 'pound', $weight_unit );
|
642 |
+
|
643 |
+
$dimension_units = wpsc_dimension_units();
|
644 |
+
$weight_units = wpsc_weight_units();
|
645 |
+
|
646 |
+
// Why we need this????
|
647 |
+
$measurements = $dimensions;
|
648 |
+
$measurements['weight'] = $weight;
|
649 |
+
$measurements['weight_unit'] = $weight_unit;
|
650 |
+
// End why
|
651 |
|
652 |
?>
|
653 |
+
<div class="wpsc-stock-editor<?php if ( $bulk ) echo ' wpsc-bulk-edit' ?>">
|
654 |
+
<p class="wpsc-form-field">
|
655 |
+
<input type="checkbox" name="<?php echo esc_attr( $field_name_prefix ); ?>[no_shipping]" value="1" <?php checked( $no_shipping && ! $bulk ); ?>>
|
656 |
+
<label><?php _e( 'Product will <em>not</em> be shipped to customer', 'wpsc' ); ?></label>
|
657 |
+
</p>
|
658 |
+
|
659 |
+
<div class="wpsc-product-shipping-section wpsc-product-shipping-weight-dimensions">
|
660 |
+
<p><strong><?php esc_html_e( 'Calculate Shipping Costs based on measurements', 'wpsc' ); ?></strong></p>
|
661 |
+
|
662 |
+
<!-- WEIGHT INPUT -->
|
663 |
+
<p class="wpsc-form-field">
|
664 |
+
<?php if ( $bulk ) : ?>
|
665 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][measurements][weight]" value="1" />
|
666 |
+
<?php endif; ?>
|
667 |
+
<label for="wpsc-product-shipping-weight"><?php echo esc_html_e( 'Weight', 'wpsc' ); ?></label>
|
668 |
+
<span class="wpsc-product-shipping-input">
|
669 |
+
<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 ) ); ?>" />
|
670 |
+
<select id="wpsc-product-shipping-weight-unit" name="<?php echo $field_name_prefix; ?>[weight_unit]">
|
671 |
+
<?php foreach ( $weight_units as $unit => $unit_label ): ?>
|
672 |
+
<option value="<?php echo esc_attr( $unit ); ?>" <?php if ( ! $bulk ) selected( $unit, $measurements['weight_unit'] ); ?>><?php echo esc_html( $unit_label ); ?></option>
|
673 |
+
<?php endforeach; ?>
|
674 |
+
</select>
|
675 |
+
</span>
|
676 |
+
</p>
|
677 |
+
<!-- END WEIGHT INPUT -->
|
678 |
+
|
679 |
+
<!-- DIMENSIONS INPUT -->
|
680 |
+
<p class="wpsc-form-field">
|
681 |
+
<?php if ( $bulk ) : ?>
|
682 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][measurements][dimensions]" value="1" />
|
683 |
+
<?php endif; ?>
|
684 |
+
<label for="wpsc-product-shipping-weight"><?php echo esc_html_e( 'Dimensions', 'wpsc' ); ?></label>
|
685 |
+
<span class="wpsc-product-shipping-input">
|
686 |
+
<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'] ) ); ?>" /> ×
|
687 |
+
<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'] ) ); ?>" /> ×
|
688 |
+
<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'] ) ); ?>" />
|
689 |
+
<select id="wpsc-product-shipping-dimensions-unit" name="<?php echo $field_name_prefix; ?>[dimension_unit]">
|
690 |
+
<?php foreach ( $dimension_units as $unit => $unit_label ): ?>
|
691 |
+
<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>
|
692 |
+
<?php endforeach; ?>
|
693 |
+
</select>
|
694 |
+
</span>
|
695 |
+
</p>
|
696 |
+
<!-- END DEMENSION INPUT -->
|
697 |
+
|
698 |
+
</div>
|
699 |
+
|
700 |
+
<?php
|
701 |
+
$currency_type = get_option( 'currency_type' );
|
702 |
+
$country = new WPSC_Country( $currency_type );
|
703 |
+
|
704 |
+
$ct_symb = $country->get_currency_symbol_html();
|
705 |
+
?>
|
706 |
+
|
707 |
+
<div class="wpsc-product-shipping-section wpsc-product-shipping-flat-rate">
|
708 |
+
<p><strong><?php esc_html_e( 'Flat Rate Settings', 'wpsc' ); ?></strong></p>
|
709 |
+
<p class="wpsc-form-field">
|
710 |
+
<?php if ( $bulk ): ?>
|
711 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][shipping][local]" value="1" />
|
712 |
+
<?php endif; ?>
|
713 |
+
<label for="wpsc-product-shipping-flatrate-local"><?php esc_html_e( 'Local Shipping Fee', 'wpsc' ); ?></label>
|
714 |
+
<span>
|
715 |
+
<?php echo esc_html( $ct_symb ); ?>
|
716 |
+
<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']; ?>" />
|
717 |
+
</span>
|
718 |
+
</p>
|
719 |
+
<p class="wpsc-form-field">
|
720 |
+
<?php if ( $bulk ): ?>
|
721 |
+
<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][shipping][international]" value="1" />
|
722 |
+
<?php endif; ?>
|
723 |
+
<label for="wpsc-product-shipping-flatrate-international"><?php esc_html_e( 'International Shipping Fee', 'wpsc' ); ?></label>
|
724 |
+
<span>
|
725 |
+
<?php echo esc_html( $ct_symb ); ?>
|
726 |
+
<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']; ?>" />
|
727 |
+
</span>
|
728 |
+
</p>
|
729 |
+
</div>
|
730 |
+
</div>
|
731 |
<?php
|
732 |
}
|
733 |
|
734 |
// aka custom meta form
|
735 |
function wpsc_product_advanced_forms() {
|
736 |
+
global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
|
737 |
+
$product_data = get_post_custom( $post->ID );
|
738 |
+
|
739 |
+
$product_data['meta'] = $product_meta = array();
|
740 |
+
if ( !empty( $product_data['_wpsc_product_metadata'] ) )
|
741 |
+
$product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
|
742 |
+
|
743 |
+
$delete_nonce = _wpsc_create_ajax_nonce( 'remove_product_meta' );
|
744 |
+
|
745 |
+
$custom_fields = $wpdb->get_results( "
|
746 |
+
SELECT
|
747 |
+
`meta_id`, `meta_key`, `meta_value`
|
748 |
+
FROM
|
749 |
+
`{$wpdb->postmeta}`
|
750 |
+
WHERE
|
751 |
+
`post_id` = {$post->ID}
|
752 |
+
AND
|
753 |
+
`meta_key` NOT LIKE '\_%'
|
754 |
+
ORDER BY
|
755 |
+
LOWER(meta_key)", ARRAY_A
|
756 |
+
);
|
757 |
+
|
758 |
+
if ( ! isset( $product_meta['engraved'] ) ) {
|
759 |
+
$product_meta['engraved'] = '';
|
760 |
+
}
|
761 |
+
|
762 |
+
if ( ! isset( $product_meta['can_have_uploaded_image'] ) ) {
|
763 |
+
$product_meta['can_have_uploaded_image'] = '';
|
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 |
+
|
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 |
+
global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
|
823 |
+
$product_data = get_post_custom( $post->ID );
|
824 |
+
|
825 |
+
$product_data['meta'] = $product_meta = array();
|
826 |
+
if ( ! empty( $product_data['_wpsc_product_metadata'] ) ) {
|
827 |
+
$product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
|
828 |
+
}
|
829 |
+
|
830 |
+
// Get External Link Values
|
831 |
+
$external_link_value = isset( $product_meta['external_link'] ) ? $product_meta['external_link'] : '';
|
832 |
+
$external_link_text_value = isset( $product_meta['external_link_text'] ) ? $product_meta['external_link_text'] : '';
|
833 |
+
$external_link_target_value = isset( $product_meta['external_link_target'] ) ? $product_meta['external_link_target'] : '';
|
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( $external_link_value ); ?>" 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( $external_link_text_value ); ?>" 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 |
+
<input type="radio" name="meta[_wpsc_product_metadata][external_link_target]" value=""<?php checked( '', $external_link_target_value ); ?> />
|
849 |
+
<span><?php _ex( 'Default (set by theme)', 'External product link target', 'wpsc' ); ?></span>
|
850 |
+
|
851 |
+
<input type="radio" name="meta[_wpsc_product_metadata][external_link_target]" value="_self"<?php checked( '_self', $external_link_target_value ); ?> />
|
852 |
+
<span><?php esc_html_e( 'Force open in same window', 'wpsc' ); ?></span>
|
853 |
+
|
854 |
+
<input type="radio" name="meta[_wpsc_product_metadata][external_link_target]" value="_blank"<?php checked( '_blank', $external_link_target_value ); ?> />
|
855 |
+
<span><?php esc_html_e( 'Force open in new window', 'wpsc' ); ?></span>
|
856 |
+
</td>
|
857 |
+
</tr>
|
858 |
+
</tbody>
|
859 |
+
</table>
|
860 |
+
<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>
|
861 |
+
<?php
|
|
|
|
|
|
|
|
|
862 |
}
|
863 |
+
|
864 |
function wpsc_additional_desc() {
|
865 |
?>
|
866 |
<textarea name='additional_description' id='additional_description' cols='40' rows='5' ><?php echo esc_textarea( get_post_field( 'post_excerpt', get_the_ID() ) ); ?></textarea>
|
877 |
* @return void
|
878 |
*/
|
879 |
function wpsc_product_gallery( $post ) {
|
880 |
+
// pull the old iframe source for non JS users
|
881 |
+
$upload_iframe_src = esc_url( get_upload_iframe_src( 'image', $post->ID ) );
|
882 |
+
// get our gallery image IDs if present
|
883 |
+
$images = wpsc_get_admin_product_gallery( $post->ID );
|
884 |
+
// begin HTML output
|
885 |
+
$output = '<div id="wpsc_product_gallery">';
|
886 |
+
$output .= '<ul>';
|
887 |
+
// check for images before beginngin loop
|
888 |
+
if ( $images ) {
|
889 |
+
// now loop images
|
890 |
+
foreach ( $images as $image_id ) {
|
891 |
+
// get the thumbnail URL
|
892 |
+
$thumb_url = wp_get_attachment_thumb_url( absint( $image_id ) );
|
893 |
+
// output each item
|
894 |
+
$output .= '<li>';
|
895 |
+
$output .= '<img src="' . esc_url( $thumb_url ) . '">';
|
896 |
+
$output .= '<input type="hidden" name="wpsc-product-gallery-imgs[]" value="' . absint( $image_id ) . '">';
|
897 |
+
$output .= '</li>';
|
898 |
+
}
|
899 |
+
}
|
900 |
+
$output .= '</ul>';
|
901 |
+
$output .= '<div class="clear"></div>';
|
902 |
+
$output .= '</div>';
|
903 |
+
// button for old iframe for non JS people
|
904 |
+
$output .= '<p class="hide-if-no-js">';
|
905 |
+
$output .= '<a class="button button-small thickbox" title="' . esc_attr__( 'Manage Product Image Gallery...', 'wpsc' ).'" href="' . $upload_iframe_src . '" id="wpsc-manage-product-gallery">';
|
906 |
+
$output .= esc_html__( 'Manage Product Image Gallery...', 'wpsc' );
|
907 |
+
$output .= '</a>';
|
908 |
+
$output .= '</p>';
|
909 |
+
|
910 |
+
// include a nonce for verification
|
911 |
+
$output .= wp_nonce_field( 'wpec_product_gallery_nonce', 'wpec_product_gallery_nonce', false, false );
|
912 |
+
|
913 |
+
// echo the gallery output
|
914 |
+
echo $output;
|
915 |
}
|
916 |
|
917 |
+
|
918 |
function wpsc_product_download_forms() {
|
919 |
+
global $post, $wpdb, $wpsc_product_defaults;
|
920 |
+
$product_data = get_post_custom( $post->ID );
|
921 |
+
$output = '';
|
922 |
+
$product_data['meta'] = array();
|
923 |
|
924 |
+
if ( !empty( $product_data['_wpsc_product_metadata'] ) )
|
925 |
+
$product_data['meta'] = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
|
926 |
|
927 |
+
$upload_max = wpsc_get_max_upload_size();
|
928 |
?>
|
929 |
+
<?php echo wpsc_select_product_file( $post->ID ); ?>
|
930 |
|
931 |
+
<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>
|
932 |
|
933 |
+
<div class="wpsc_fileUpload button button-small">
|
934 |
+
<span><?php esc_html_e('Upload new file...','wpsc'); ?></span>
|
935 |
+
<input type='file' name='file' class="button button-small" value='' onchange="wpsc_push_v2t(this, '#wpsc_fileupload_path')" />
|
936 |
+
</div>
|
937 |
+
<em id="wpsc_fileupload_path"></em>
|
938 |
|
939 |
<?php
|
940 |
+
if ( function_exists( "make_mp3_preview" ) || function_exists( "wpsc_media_player" ) ) {
|
941 |
?>
|
942 |
<br />
|
943 |
<h4><?php esc_html_e( 'Select an MP3 file to upload as a preview', 'wpsc' ) ?></h4>
|
945 |
|
946 |
<h4><?php esc_html_e( 'Your preview for this product', 'wpsc' ) ?>:</h4>
|
947 |
|
948 |
+
<?php
|
949 |
+
$args = array(
|
950 |
+
'post_type' => 'wpsc-preview-file',
|
951 |
+
'post_parent' => $post->ID,
|
952 |
+
'numberposts' => -1,
|
953 |
+
'post_status' => 'all'
|
954 |
+
);
|
955 |
|
956 |
+
$preview_files = (array) get_posts( $args );
|
957 |
|
958 |
+
foreach ( $preview_files as $preview ) {
|
959 |
+
echo $preview->post_title . '<br />';
|
960 |
+
}
|
961 |
|
962 |
+
?>
|
963 |
<br />
|
964 |
<?php
|
965 |
+
}
|
966 |
|
967 |
+
$output = apply_filters( 'wpsc_downloads_metabox', $output );
|
968 |
}
|
969 |
|
970 |
function wpsc_product_personalization_forms(){
|
971 |
+
global $post;
|
972 |
+
$product_meta = get_post_meta( $post->ID, '_wpsc_product_metadata', true );
|
973 |
+
if ( ! is_array( $product_meta ) )
|
974 |
+
$product_meta = array();
|
975 |
?>
|
976 |
+
<ul id="wpsc_product_personalization_option">
|
977 |
+
<li>
|
978 |
+
<input type='hidden' name='meta[_wpsc_product_metadata][engraved]' value='0' />
|
979 |
+
<input type='checkbox' name='meta[_wpsc_product_metadata][engraved]' <?php if ( isset( $product_meta['engraved'] ) ) checked( $product_meta['engraved'], '1' ); ?> id='add_engrave_text' />
|
980 |
+
<label for='add_engrave_text'><?php esc_html_e( 'Users can personalize this product by leaving a message on single product page', 'wpsc' ); ?></label>
|
981 |
+
</li>
|
982 |
+
<li>
|
983 |
+
<input type='hidden' name='meta[_wpsc_product_metadata][can_have_uploaded_image]' value='0' />
|
984 |
+
<input type='checkbox' name='meta[_wpsc_product_metadata][can_have_uploaded_image]' <?php if ( isset( $product_meta['can_have_uploaded_image'] ) ) checked( $product_meta['can_have_uploaded_image'], '1' ); ?> id='can_have_uploaded_image' />
|
985 |
+
<label for='can_have_uploaded_image'> <?php esc_html_e( 'Users can upload images on single product page to purchase logs.', 'wpsc' ); ?> </label>
|
986 |
+
</li>
|
987 |
+
</ul>
|
988 |
+
<em><?php _e( "Form fields for the customer to personalize this product will be shown on it's single product page.", 'wpsc' ); ?></em>
|
989 |
<?php
|
990 |
}
|
991 |
|
992 |
function wpsc_product_delivery_forms(){
|
993 |
+
$has_variations = wpsc_product_has_variations( get_post()->ID );
|
994 |
|
995 |
+
$show_if_variation = $has_variations ? 'display: block;' : 'display:none;';
|
996 |
?>
|
997 |
+
<em id="wpsc_product_delivery_metabox_live_title" class="wpsc_metabox_live_title">
|
998 |
+
<p></p>
|
999 |
+
</em>
|
1000 |
+
|
1001 |
+
<div id="wpsc_product_delivery_forms" class="categorydiv wpsc-categorydiv">
|
1002 |
+
<ul id="wpsc_product_delivery_tabs" class="category-tabs">
|
1003 |
+
<li class="tabs"><a href="#wpsc_product_delivery-shipping"><?php _e( 'Shipping', 'wpsc' ); ?></a></li>
|
1004 |
+
<li><a href="#wpsc_product_delivery-download"><?php _e( 'Download', 'wpsc' ); ?></a></li>
|
1005 |
+
<li><a href="#wpsc_product_delivery-external_link"><?php _e( 'External Link', 'wpsc' ); ?></a></li>
|
1006 |
+
</ul>
|
1007 |
+
|
1008 |
+
<div id="wpsc_product_delivery-shipping" class="tabs-panel" style="display:block;">
|
1009 |
+
<?php
|
1010 |
+
if ( ! $has_variations ) {
|
1011 |
+
wpsc_product_shipping_forms();
|
1012 |
+
} else {
|
1013 |
+
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>';
|
1014 |
+
}
|
1015 |
+
?>
|
1016 |
+
</div>
|
1017 |
+
|
1018 |
+
<div id="wpsc_product_delivery-download" class="tabs-panel" style="display:none;">
|
1019 |
+
<?php wpsc_product_download_forms(); ?>
|
1020 |
+
</div>
|
1021 |
+
|
1022 |
+
<div id="wpsc_product_delivery-external_link" class="tabs-panel" style="display: none;">
|
1023 |
+
<?php wpsc_product_external_link_forms(); ?>
|
1024 |
+
</div>
|
1025 |
+
</div>
|
1026 |
<?php
|
1027 |
}
|
1028 |
|
1029 |
function wpsc_product_details_forms(){
|
1030 |
?>
|
1031 |
+
<em id="wpsc_product_details_metabox_live_title" class="wpsc_metabox_live_title">
|
1032 |
+
<p></p>
|
1033 |
+
</em>
|
1034 |
+
|
1035 |
+
<div id="wpsc_product_details_forms" class="categorydiv wpsc-categorydiv">
|
1036 |
+
<ul id="wpsc_product_details_tabs" class="category-tabs">
|
1037 |
+
<li class="tabs"><a href="#wpsc_product_details-image"><?php _e( 'Image Gallery', 'wpsc' ); ?></a></li>
|
1038 |
+
<li><a href="#wpsc_product_details-desc"><?php _e( 'Short Description', 'wpsc' ); ?></a></li>
|
1039 |
+
<li><a href="#wpsc_product_details-personalization"><?php _e( 'Personalization', 'wpsc' ); ?></a></li>
|
1040 |
+
<li><a href="#wpsc_product_details-meta"><?php _e( 'Metadata', 'wpsc' ); ?></a></li>
|
1041 |
+
</ul>
|
1042 |
+
|
1043 |
+
<div id="wpsc_product_details-image" class="tabs-panel" style="display: block;">
|
1044 |
+
<?php wpsc_product_gallery( get_post() ); ?>
|
1045 |
+
</div>
|
1046 |
+
|
1047 |
+
<div id="wpsc_product_details-desc" class="tabs-panel" style="display: none;">
|
1048 |
+
<?php wpsc_additional_desc(); ?>
|
1049 |
+
</div>
|
1050 |
+
|
1051 |
+
<div id="wpsc_product_details-personalization" class="tabs-panel" style="display: none;">
|
1052 |
+
<?php wpsc_product_personalization_forms(); ?>
|
1053 |
+
</div>
|
1054 |
+
|
1055 |
+
<div id="wpsc_product_details-meta" class="tabs-panel" style="display: none;">
|
1056 |
+
<?php wpsc_product_advanced_forms(); ?>
|
1057 |
+
</div>
|
1058 |
+
</div>
|
1059 |
<?php
|
1060 |
}
|
1061 |
|
1062 |
function wpsc_form_multipart_encoding() {
|
1063 |
+
echo ' enctype="multipart/form-data"';
|
1064 |
}
|
1065 |
|
1066 |
add_action( 'post_edit_form_tag', 'wpsc_form_multipart_encoding' );
|
1084 |
*/
|
1085 |
function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
|
1086 |
|
1087 |
+
if ( 'Taxonomy Parent' == $context && 'Parent' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ) {
|
1088 |
+
$translations = get_translations_for_domain( $domain );
|
1089 |
+
return $translations->translate( 'Variation Set', 'wpsc' );
|
1090 |
+
//this will never happen, this is here only for gettext to pick up the translation
|
1091 |
+
return __( 'Variation Set', 'wpsc' );
|
1092 |
+
}
|
1093 |
+
return $translation;
|
1094 |
}
|
1095 |
|
1096 |
function wpsc_attachment_fields( $form_fields, $post ) {
|
1097 |
+
$out = '';
|
1098 |
|
1099 |
+
if( isset( $_REQUEST["post_id"] ) )
|
1100 |
+
$parent_post = get_post( absint( $_REQUEST["post_id"] ) );
|
1101 |
+
else
|
1102 |
+
$parent_post = get_post( $post->post_parent );
|
1103 |
|
1104 |
+
// check if post is set before accessing
|
1105 |
+
if ( isset( $parent_post ) && $parent_post->post_type == "wpsc-product" ) {
|
1106 |
|
1107 |
+
//Unfortunate hack, as I'm not sure why the From Computer tab doesn't process filters the same way the Gallery does
|
1108 |
+
ob_start();
|
1109 |
+
echo '
|
1110 |
<script type="text/javascript">
|
1111 |
|
1112 |
+
jQuery(function(){
|
1113 |
|
1114 |
+
jQuery("a.wp-post-thumbnail").each(function(){
|
1115 |
+
var product_image = jQuery(this).text();
|
1116 |
+
if (product_image == "' . esc_js( __( 'Use as featured image' ) ) . '") {
|
1117 |
+
jQuery(this).text("' . esc_js( __('Use as Product Thumbnail', 'wpsc') ) . '");
|
1118 |
+
}
|
1119 |
+
});
|
1120 |
|
1121 |
+
var trash = jQuery("#media-upload a.del-link").text();
|
1122 |
|
1123 |
+
if (trash == "' . esc_js( __( 'Delete' ) ) . '") {
|
1124 |
+
jQuery("#media-upload a.del-link").text("' . esc_js( __( 'Trash' ) ) . '");
|
1125 |
+
}
|
1126 |
|
1127 |
|
1128 |
+
});
|
1129 |
|
1130 |
</script>';
|
1131 |
+
$out .= ob_get_clean();
|
1132 |
|
1133 |
+
$size_names = array( 'small-product-thumbnail' => __( 'Default Product Thumbnail Size', 'wpsc' ), 'medium-single-product' => __( 'Single Product Image Size', 'wpsc' ), 'full' => __( 'Full Size', 'wpsc' ) );
|
1134 |
|
1135 |
+
$check = get_post_meta( $post->ID, '_wpsc_selected_image_size', true );
|
1136 |
+
if ( !$check )
|
1137 |
+
$check = 'medium-single-product';
|
1138 |
|
1139 |
+
$current_size = image_get_intermediate_size( $post->ID, $check );
|
1140 |
+
$settings_width = get_option( 'single_view_image_width' );
|
1141 |
+
$settings_height = get_option( 'single_view_image_height' );
|
1142 |
|
1143 |
+
// regenerate size metadata in case it's missing
|
1144 |
+
if ( ! $check || ( $current_size['width'] != $settings_width && $current_size['height'] != $settings_height ) ) {
|
1145 |
+
_wpsc_regenerate_thumbnail_size( $post->ID, $check );
|
1146 |
+
}
|
1147 |
|
1148 |
+
//This loop attaches the custom thumbnail/single image sizes to this page
|
1149 |
+
foreach ( $size_names as $size => $name ) {
|
1150 |
+
$downsize = image_downsize( $post->ID, $size );
|
1151 |
+
// is this size selectable?
|
1152 |
+
$enabled = ( $downsize[3] || 'full' == $size );
|
1153 |
+
$css_id = "image-size-{$size}-{$post->ID}";
|
1154 |
+
// if this size is the default but that's not available, don't select it
|
1155 |
|
1156 |
+
$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 ) . " />";
|
1157 |
|
1158 |
+
$html .= "<label for='{$css_id}'>$name</label>";
|
1159 |
+
// only show the dimensions if that choice is available
|
1160 |
+
if ( $enabled )
|
1161 |
+
$html .= " <label for='{$css_id}' class='help'>" . sprintf( __( "(%d × %d)", 'wpsc' ), $downsize[1], $downsize[2] ). "</label>";
|
1162 |
|
1163 |
+
$html .= '</div>';
|
1164 |
|
1165 |
+
$out .= $html;
|
1166 |
+
}
|
1167 |
|
1168 |
+
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"] );
|
1169 |
+
$form_fields['image_alt']['helps'] = __( 'Alt text for the product image, e.g. “Rockstar T-Shirt”', 'wpsc' );
|
1170 |
|
1171 |
+
$form_fields["wpsc_image_size"] = array(
|
1172 |
+
'label' => __( 'Single Product Page Thumbnail:', 'wpsc' ),
|
1173 |
+
'input' => 'html',
|
1174 |
+
'html' => $out,
|
1175 |
+
'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>"
|
1176 |
+
);
|
1177 |
|
1178 |
+
//This is for the custom thumbnail size.
|
1179 |
|
1180 |
+
$custom_thumb_size_w = get_post_meta( $post->ID, "_wpsc_custom_thumb_w", true );
|
1181 |
+
$custom_thumb_size_h = get_post_meta( $post->ID, "_wpsc_custom_thumb_h", true );
|
1182 |
+
$custom_thumb_html = "
|
1183 |
|
1184 |
+
<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}' />
|
1185 |
|
1186 |
+
";
|
1187 |
+
$form_fields["wpsc_custom_thumb"] = array(
|
1188 |
+
"label" => __( 'Products Page Thumbnail Size:', 'wpsc' ),
|
1189 |
+
"input" => "html", // this is default if "input" is omitted
|
1190 |
+
"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>",
|
1191 |
+
"html" => $custom_thumb_html
|
1192 |
+
);
|
1193 |
+
}
|
1194 |
+
return $form_fields;
|
1195 |
|
1196 |
}
|
1197 |
function wpsc_save_attachment_fields( $post, $attachment ) {
|
1198 |
|
1199 |
+
if ( isset( $attachment['wpsc_custom_thumb_w'] ) ) {
|
1200 |
+
update_post_meta( $post['ID'], '_wpsc_custom_thumb_w', $attachment['wpsc_custom_thumb_w'] );
|
1201 |
+
}
|
1202 |
|
1203 |
+
if ( isset( $attachment['wpsc_custom_thumb_h'] ) ) {
|
1204 |
+
update_post_meta( $post['ID'], '_wpsc_custom_thumb_h', $attachment['wpsc_custom_thumb_h'] );
|
1205 |
+
}
|
1206 |
|
1207 |
+
if ( isset( $attachment['wpsc_image_size'] ) ) {
|
1208 |
+
update_post_meta( $post['ID'], '_wpsc_selected_image_size', $attachment['wpsc_image_size'] );
|
1209 |
+
}
|
1210 |
|
1211 |
+
return $post;
|
1212 |
}
|
1213 |
|
1214 |
/**
|
1222 |
*/
|
1223 |
|
1224 |
function wpsc_save_quickedit_box( $post_id ) {
|
1225 |
+
global $doaction;
|
1226 |
|
1227 |
+
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || get_post_type( $post_id ) != 'wpsc-product' )
|
1228 |
+
return;
|
1229 |
|
1230 |
+
$bulk = isset( $doaction ) && $doaction =='edit';
|
1231 |
|
1232 |
+
$custom_fields = array(
|
1233 |
+
'weight' => 'product_metadata',
|
1234 |
+
'stock' => 'stock',
|
1235 |
+
'price' => 'price',
|
1236 |
+
'sale_price' => 'special_price',
|
1237 |
+
'sku' => 'sku',
|
1238 |
+
);
|
1239 |
|
1240 |
$args = array(
|
1241 |
'post_parent' => $post_id,
|
1243 |
'post_status' => 'inherit'
|
1244 |
);
|
1245 |
$children = get_children($args);
|
1246 |
+
$is_parent = (bool)$children;
|
1247 |
+
foreach ( $custom_fields as $post_key => $meta_key ) {
|
1248 |
+
$overideVariant = isset($_REQUEST[$post_key.'_variant']) && $_REQUEST[$post_key.'_variant'] == 'on';
|
1249 |
+
// 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)
|
1250 |
+
if ( ! isset( $_REQUEST[$post_key] ) || ( $bulk && empty( $_REQUEST[$post_key] ) ) ||
|
1251 |
+
( $is_parent && in_array( $post_key, array( 'weight', 'stock', 'price', 'special_price' )) && !$overideVariant ) ){
|
1252 |
+
continue;
|
1253 |
+
}
|
1254 |
+
|
1255 |
+
if($is_parent && count($children) >0){
|
1256 |
+
$products = $children;
|
1257 |
+
}else{
|
1258 |
+
$products = array($post_id);
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
foreach($products as $product){
|
1262 |
+
$value = $_REQUEST[$post_key];
|
1263 |
+
if($is_parent) $post_id = $product->ID;
|
1264 |
+
else $post_id = $product;
|
1265 |
+
switch ( $post_key ) {
|
1266 |
+
case 'weight':
|
1267 |
+
$product_meta = get_post_meta( $post_id, '_wpsc_product_metadata', true );
|
1268 |
+
if ( ! is_array( $product_meta ) )
|
1269 |
+
$product_meta = array();
|
1270 |
+
// draft products don't have product metadata set yet
|
1271 |
+
$weight_unit = isset( $product_meta["weight_unit"] ) ? $product_meta["weight_unit"] : 'pound';
|
1272 |
+
$weight = wpsc_convert_weight( $value, $weight_unit, "pound", true );
|
1273 |
+
|
1274 |
+
if ( isset( $product_meta["weight"] ) )
|
1275 |
+
unset( $product_meta["weight"] );
|
1276 |
+
|
1277 |
+
$product_meta["weight"] = $weight;
|
1278 |
+
|
1279 |
+
$value = $product_meta;
|
1280 |
+
break;
|
1281 |
+
|
1282 |
+
case 'stock':
|
1283 |
+
if ( ! is_numeric( $value ) )
|
1284 |
+
$value = '';
|
1285 |
+
break;
|
1286 |
+
|
1287 |
+
case 'sku':
|
1288 |
+
if ( $value == __( 'N/A', 'wpsc' ) )
|
1289 |
+
$value = '';
|
1290 |
+
break;
|
1291 |
+
}
|
1292 |
+
|
1293 |
+
update_post_meta( $post_id, "_wpsc_{$meta_key}", $value );
|
1294 |
+
}
|
1295 |
+
}
|
1296 |
+
|
1297 |
+
return $post_id;
|
1298 |
}
|
1299 |
|
1300 |
/**
|
1307 |
*/
|
1308 |
|
1309 |
function wpsc_quick_edit_boxes( $col_name, $_screen_post_type = null ) {
|
1310 |
+
// Avoid outputting this on term edit screens.
|
1311 |
+
// See http://core.trac.wordpress.org/ticket/16392#comment:9
|
1312 |
+
if ( current_filter() == 'quick_edit_custom_box' && $_screen_post_type == 'edit-tags' )
|
1313 |
+
return;
|
1314 |
?>
|
1315 |
|
1316 |
<fieldset class="inline-edit-col-left wpsc-cols">
|
1317 |
<div class="inline-edit-col">
|
1318 |
<div class="inline-edit-group">
|
1319 |
<?php
|
1320 |
+
switch ( $col_name ) :
|
1321 |
+
case 'SKU' :
|
1322 |
?>
|
1323 |
<label style="max-width: 85%" class="alignleft">
|
1324 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'SKU:', 'wpsc' ); ?> </span>
|
1325 |
<input type="text" name="sku" class="wpsc_ie_sku" />
|
1326 |
+
<input type="checkbox" name="sku_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1327 |
|
1328 |
</label>
|
1329 |
<?php
|
1330 |
+
break;
|
1331 |
case 'weight' :
|
1332 |
?>
|
1333 |
<label style="max-width: 85%" class="alignleft">
|
1334 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Weight:', 'wpsc' ); ?> </span>
|
1335 |
<input type="text" name="weight" class="wpsc_ie_weight" />
|
1336 |
+
<input type="checkbox" name="weight_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1337 |
</label>
|
1338 |
<?php
|
1339 |
+
break;
|
1340 |
case 'stock' :
|
1341 |
?>
|
1342 |
<label style="max-width: 85%" class="alignleft">
|
1343 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Stock:', 'wpsc' ); ?> </span>
|
1344 |
<input type="text" name="stock" class="wpsc_ie_stock" />
|
1345 |
+
<input type="checkbox" name="stock_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1346 |
</label>
|
1347 |
<?php
|
1348 |
+
break;
|
1349 |
case 'price' :
|
1350 |
?>
|
1351 |
<label style="max-width: 85%" class="alignleft">
|
1352 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Price:', 'wpsc' ); ?> </span>
|
1353 |
<input type="text" name="price" class="wpsc_ie_price" />
|
1354 |
+
<input type="checkbox" name="price_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1355 |
</label>
|
1356 |
<?php
|
1357 |
+
break;
|
1358 |
case 'sale_price' :
|
1359 |
?>
|
1360 |
<label style="max-width: 85%" class="alignleft">
|
1361 |
<span class="checkbox-title wpsc-quick-edit"><?php esc_html_e( 'Sale Price:', 'wpsc' ); ?> </span>
|
1362 |
<input type="text" name="sale_price" class="wpsc_ie_sale_price" />
|
1363 |
+
<input type="checkbox" name="sale_price_variant"> <span><?php esc_html_e( 'Update Variants', 'wpsc');?></span>
|
1364 |
</label>
|
1365 |
<?php
|
1366 |
+
break;
|
1367 |
+
endswitch;
|
1368 |
?>
|
1369 |
</div>
|
1370 |
</div>
|
1383 |
* @param <type> $variation
|
1384 |
*/
|
1385 |
function variation_price_field( $variation ) {
|
1386 |
+
$term_prices = get_option( 'term_prices' );
|
1387 |
+
|
1388 |
+
if ( is_object( $variation ) )
|
1389 |
+
$term_id = $variation->term_id;
|
1390 |
+
|
1391 |
+
if ( empty( $term_prices ) || !is_array( $term_prices ) ) {
|
1392 |
+
|
1393 |
+
$term_prices = array( );
|
1394 |
+
if ( isset( $term_id ) ) {
|
1395 |
+
$term_prices[$term_id] = array( );
|
1396 |
+
$term_prices[$term_id]["price"] = '';
|
1397 |
+
$term_prices[$term_id]["checked"] = '';
|
1398 |
+
}
|
1399 |
+
add_option( 'term_prices', $term_prices );
|
1400 |
+
}
|
1401 |
+
|
1402 |
+
if ( isset( $term_id ) && is_array( $term_prices ) && array_key_exists( $term_id, $term_prices ) )
|
1403 |
+
$price = esc_attr( $term_prices[$term_id]["price"] );
|
1404 |
+
else
|
1405 |
+
$price = '';
|
1406 |
+
|
1407 |
+
if( !isset( $_GET['action'] ) ) {
|
1408 |
+
?>
|
1409 |
+
<div class="form-field">
|
1410 |
+
<label for="variation_price"><?php esc_html_e( 'Variation Price', 'wpsc' ); ?></label>
|
1411 |
+
<input type="text" name="variation_price" id="variation_price" style="width:50px;" value="<?php echo $price; ?>"><br />
|
1412 |
+
<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>
|
1413 |
+
</div>
|
1414 |
+
<script type="text/javascript">
|
1415 |
+
jQuery('#parent option:contains(" ")').remove();
|
1416 |
+
jQuery('#parent').mousedown(function(){
|
1417 |
+
jQuery('#parent option:contains(" ")').remove();
|
1418 |
+
});
|
1419 |
+
</script>
|
1420 |
+
<?php
|
1421 |
+
} else{
|
1422 |
+
?>
|
1423 |
+
<tr class="form-field">
|
1424 |
<th scope="row" valign="top">
|
1425 |
+
<label for="variation_price"><?php esc_html_e( 'Variation Price', 'wpsc' ); ?></label>
|
1426 |
</th>
|
1427 |
<td>
|
1428 |
+
<input type="text" name="variation_price" id="variation_price" style="width:50px;" value="<?php echo $price; ?>"><br />
|
1429 |
+
<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>
|
1430 |
</td>
|
1431 |
+
</tr>
|
1432 |
+
<?php
|
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 |
*/
|
1442 |
function variation_set_field(){
|
1443 |
?>
|
1444 |
+
<script>
|
1445 |
+
/* change the text on the variation set from (none) to new variation set*/
|
1446 |
+
jQuery("#parent option[value='-1']").text("New Variation Set");
|
1447 |
+
/* Move to the top of the form and add a description */
|
1448 |
+
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>') );
|
1449 |
+
/*
|
1450 |
+
create a small description about variations below the add variation / set title
|
1451 |
+
we can then get rid of the big red danger warning
|
1452 |
+
*/
|
1453 |
+
( 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>') );
|
1454 |
+
</script>
|
1455 |
<?php
|
1456 |
}
|
1457 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_set_field' );
|
1460 |
|
1461 |
function category_edit_form(){
|
1462 |
?>
|
1463 |
+
<script type="text/javascript">
|
1464 |
|
1465 |
+
</script>
|
1466 |
<?php
|
1467 |
}
|
1468 |
|
1469 |
function variation_price_field_check( $variation ) {
|
1470 |
|
1471 |
+
$term_prices = get_option( 'term_prices' );
|
1472 |
|
1473 |
+
if ( is_array( $term_prices ) && array_key_exists( $variation->term_id, $term_prices ) )
|
1474 |
+
$checked = ($term_prices[$variation->term_id]["checked"] == 'checked') ? 'checked' : '';
|
1475 |
+
else
|
1476 |
+
$checked = ''; ?>
|
1477 |
|
1478 |
+
<tr class="form-field">
|
1479 |
+
<th scope="row" valign="top"><label for="apply_to_current"><?php esc_html_e( 'Apply to current variations?', 'wpsc' ) ?></label></th>
|
1480 |
+
<td>
|
1481 |
+
<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>
|
1482 |
+
</td>
|
1483 |
+
</tr>
|
1484 |
<?php
|
1485 |
}
|
1486 |
add_action( 'wpsc-variation_edit_form_fields', 'variation_price_field_check' );
|
1489 |
|
1490 |
/**
|
1491 |
* @todo - Should probably refactor this at some point - very procedural,
|
1492 |
+
* WAY too many foreach loops for my liking :) But it does the trick
|
1493 |
*
|
1494 |
* @param <type> $term_id
|
1495 |
*/
|
1496 |
function save_term_prices( $term_id ) {
|
1497 |
+
// First - Saves options from input
|
1498 |
+
if ( isset( $_POST['variation_price'] ) || isset( $_POST["apply_to_current"] ) ) {
|
1499 |
|
1500 |
+
$term_prices = get_option( 'term_prices' );
|
1501 |
|
1502 |
+
$term_prices[$term_id]["price"] = $_POST["variation_price"];
|
1503 |
+
$term_prices[$term_id]["checked"] = (isset( $_POST["apply_to_current"] )) ? "checked" : "unchecked";
|
1504 |
|
1505 |
+
update_option( 'term_prices', $term_prices );
|
1506 |
+
}
|
1507 |
|
1508 |
+
// 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
|
1509 |
+
if ( isset( $_POST["apply_to_current"] ) ) {
|
1510 |
|
1511 |
+
//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)
|
1512 |
+
$products_to_mod = get_objects_in_term( $term_id, "wpsc-variation" );
|
1513 |
+
$product_parents = array( );
|
1514 |
|
1515 |
+
foreach ( (array)$products_to_mod as $get_parent ) {
|
1516 |
|
1517 |
+
$post = get_post( $get_parent );
|
1518 |
|
1519 |
+
if ( !$post->post_parent )
|
1520 |
+
$product_parents[] = $post->ID;
|
1521 |
+
}
|
1522 |
|
1523 |
+
//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)
|
1524 |
|
1525 |
+
foreach ( $product_parents as $parent ) {
|
1526 |
+
$args = array(
|
1527 |
+
'post_parent' => $parent,
|
1528 |
+
'post_type' => 'wpsc-product'
|
1529 |
+
);
|
1530 |
+
$children = get_children( $args, ARRAY_A );
|
1531 |
|
1532 |
+
foreach ( $children as $childrens ) {
|
1533 |
+
$parent = $childrens["post_parent"];
|
1534 |
+
$children_ids[$parent][] = $childrens["ID"];
|
1535 |
+
$children_ids[$parent] = array_intersect( $children_ids[$parent], $products_to_mod );
|
1536 |
+
}
|
1537 |
+
}
|
1538 |
|
1539 |
+
//Got the right kids, let's grab their parent pricing and modify their pricing based on var_price_type
|
1540 |
|
1541 |
+
foreach ( (array)$children_ids as $parents => $kids ) {
|
1542 |
|
1543 |
+
$kids = array_values( $kids );
|
1544 |
|
1545 |
+
foreach ( $kids as $kiddos ) {
|
1546 |
+
$price = wpsc_determine_variation_price( $kiddos );
|
1547 |
+
update_product_meta( $kiddos, 'price', $price );
|
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 |
+
$post = get_post( $postid );
|
1557 |
+
if ( $post->post_type != 'wpsc-product' || $post->post_parent != 0 )
|
1558 |
+
return;
|
1559 |
+
$variations = get_posts( array(
|
1560 |
+
'post_type' => 'wpsc-product',
|
1561 |
+
'post_parent' => $postid,
|
1562 |
+
'post_status' => 'any',
|
1563 |
+
'numberposts' => -1,
|
1564 |
+
) );
|
1565 |
+
|
1566 |
+
if ( ! empty( $variations ) )
|
1567 |
+
foreach ( $variations as $variation ) {
|
1568 |
+
wp_delete_post( $variation->ID, true );
|
1569 |
+
}
|
1570 |
}
|
1571 |
add_action( 'before_delete_post', 'wpsc_delete_variations' );
|
1572 |
+
|
1573 |
+
|
1574 |
+
/**
|
1575 |
+
* fetch the items for display inside the admin product gallery
|
1576 |
+
* differs from the original `wpsc_get_product_gallery` in that
|
1577 |
+
* it only checks the postmeta for an actual gallery generated by
|
1578 |
+
* the user instead of pulling all attachments
|
1579 |
+
*
|
1580 |
+
* @since 3.8.14.2
|
1581 |
+
*
|
1582 |
+
* @param integer $product_id the product ID of the product
|
1583 |
+
* @return array $gallery the attachment IDs of the gallery if present
|
1584 |
+
*/
|
1585 |
+
function wpsc_get_admin_product_gallery( $product_id = 0 ) {
|
1586 |
+
|
1587 |
+
// grab our meta from the DB
|
1588 |
+
$gallery = get_post_meta( $product_id, '_wpsc_product_gallery', true );
|
1589 |
+
|
1590 |
+
// no custom gallery was created, so return nothing
|
1591 |
+
if ( ! $gallery ) {
|
1592 |
+
return;
|
1593 |
+
}
|
1594 |
+
|
1595 |
+
// now make sure the IDs present are actual attachments
|
1596 |
+
// by looping and unsetting them
|
1597 |
+
//
|
1598 |
+
// may want to add a MIME type check here, but not sure
|
1599 |
+
// if that would cause issues if people use non-images
|
1600 |
+
// in their galleries
|
1601 |
+
foreach( $gallery as $key => $image_id ) {
|
1602 |
+
if ( get_post_type( $image_id ) !== 'attachment' ) {
|
1603 |
+
unset( $gallery[$key] );
|
1604 |
+
}
|
1605 |
+
}
|
1606 |
+
|
1607 |
+
// somehow everything in the gallery
|
1608 |
+
// was not an attachment, so bail
|
1609 |
+
if ( empty( $gallery ) ) {
|
1610 |
+
return;
|
1611 |
+
}
|
1612 |
+
|
1613 |
+
// send it back
|
1614 |
+
return $gallery;
|
1615 |
+
|
1616 |
+
}
|
1617 |
+
|
1618 |
+
/**
|
1619 |
+
* save our gallery IDs on post save
|
1620 |
+
*
|
1621 |
+
* @since 3.8.14.2
|
1622 |
+
* @param integer $product_id the post ID being passed
|
1623 |
+
* @return void
|
1624 |
+
*/
|
1625 |
+
function wpsc_new_gallery_save( $product_id = 0 ) {
|
1626 |
+
|
1627 |
+
// do our nonce check. ALWAYS A NONCE CHECK
|
1628 |
+
if ( ! isset( $_POST['wpsc_product_gallery_nonce'] ) || ! wp_verify_nonce( $_POST['wpsc_product_gallery_nonce'], 'wpsc_product_gallery_nonce' ) ) {
|
1629 |
+
return $product_id;
|
1630 |
+
}
|
1631 |
+
|
1632 |
+
// set an empty array for the image IDs
|
1633 |
+
$image_ids = array();
|
1634 |
+
|
1635 |
+
// ok. we have image IDs to work with. do some filtering
|
1636 |
+
if ( ! empty( $_POST['wpsc-product-gallery-imgs'] ) ) {
|
1637 |
+
// make sure our IDs are set to an array
|
1638 |
+
$image_ids = (array) $_POST['wpsc-product-gallery-imgs'];
|
1639 |
+
// ensure nothing non-numeric got added in
|
1640 |
+
$image_ids = wp_parse_id_list( $image_ids );
|
1641 |
+
// filter out any empty items
|
1642 |
+
$image_ids = array_filter( $image_ids );
|
1643 |
+
}
|
1644 |
+
|
1645 |
+
// now if we have image IDs left after filtering, save them
|
1646 |
+
// if not, delete the meta key
|
1647 |
+
if ( ! empty( $image_ids ) ) {
|
1648 |
+
update_post_meta( $product_id, '_wpsc_product_gallery', $image_ids );
|
1649 |
+
} else {
|
1650 |
+
delete_post_meta( $product_id, '_wpsc_product_gallery' );
|
1651 |
+
}
|
1652 |
+
|
1653 |
+
// add an action for after the gallery being saved
|
1654 |
+
// passing the post ID and the image IDs
|
1655 |
+
do_action( 'wpsc_after_gallery_save', $product_id, $image_ids );
|
1656 |
+
|
1657 |
+
}
|
1658 |
+
add_action( 'wpsc_edit_product', 'wpsc_new_gallery_save' );
|
wpsc-admin/js/admin.js
CHANGED
@@ -191,7 +191,7 @@ jQuery(document).ready(function($){
|
|
191 |
});
|
192 |
jQuery("form[name='add_coupon']").submit(function() {
|
193 |
var title = jQuery("form[name='add_coupon'] input[name='add_coupon_code']").val();
|
194 |
-
if ( title
|
195 |
jQuery('<div id="notice" class="error"><p>' + wpsc_adminL10n.empty_coupon + '</p></div>').insertAfter('div.wrap > h2').delay(2500).hide(350);
|
196 |
return false;
|
197 |
}
|
@@ -205,7 +205,7 @@ jQuery(document).ready(function($){
|
|
205 |
var currencyRowTemplate = jQuery( '.wpsc-currency-layers tr.template' ).remove().removeClass( 'template hidden' ).removeAttr( 'id' );
|
206 |
|
207 |
// Hide table if empty
|
208 |
-
if ( jQuery( '.wpsc-currency-layers tbody tr' ).length
|
209 |
jQuery( '.wpsc-currency-layers table' ).hide();
|
210 |
}
|
211 |
|
@@ -221,7 +221,7 @@ jQuery(document).ready(function($){
|
|
221 |
var currencyRow = jQuery( this ).closest( 'tr' );
|
222 |
currencyRow.find( 'input' ).val( '' );
|
223 |
currencyRow.find( 'select' ).val( '' );
|
224 |
-
if ( currencyRow.siblings().length
|
225 |
currencyRow.closest( 'table' ).hide();
|
226 |
}
|
227 |
currencyRow.remove();
|
@@ -236,7 +236,7 @@ jQuery(document).ready(function($){
|
|
236 |
var qtyRowTemplate = jQuery( '.wpsc-quantity-discounts tr.template' ).remove().removeClass( 'template hidden' ).removeAttr( 'id' );
|
237 |
|
238 |
// Hide table if empty
|
239 |
-
if ( jQuery( '.wpsc-quantity-discounts tbody tr' ).length
|
240 |
jQuery( '.wpsc-quantity-discounts table' ).hide();
|
241 |
}
|
242 |
|
@@ -251,7 +251,7 @@ jQuery(document).ready(function($){
|
|
251 |
jQuery( '.wpsc-quantity-discounts' ).on( 'click', '.remove_line', function( e ) {
|
252 |
var qtyRow = jQuery( this ).closest( 'tr' );
|
253 |
qtyRow.find( 'input' ).val( '' );
|
254 |
-
if ( qtyRow.siblings().length
|
255 |
qtyRow.closest( 'table' ).hide();
|
256 |
}
|
257 |
qtyRow.remove();
|
@@ -306,7 +306,7 @@ jQuery(document).ready(function($){
|
|
306 |
jQuery('th.column-stock input, td.stock input').each(function(){
|
307 |
this.disabled = ! checked;
|
308 |
});
|
309 |
-
}
|
310 |
|
311 |
if (limited_stock_checkbox.size() > 0) {
|
312 |
toggle_stock_fields(limited_stock_checkbox.is(':checked'));
|
@@ -563,13 +563,22 @@ function wpsc_update_product_details_metabox_live_title(){
|
|
563 |
}
|
564 |
|
565 |
function wpsc_update_product_gallery_tab(obj){
|
566 |
-
var output;
|
|
|
567 |
output = '<div id="wpsc_product_gallery">';
|
568 |
output += '<ul>';
|
569 |
|
570 |
-
for (var i = 0; i < obj.length; i++){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
571 |
output += '<li>';
|
572 |
-
output += '<img src="' +
|
|
|
573 |
output += '</li>';
|
574 |
}
|
575 |
|
@@ -588,11 +597,11 @@ function hideOptionElement(id, option) {
|
|
588 |
if (prevOption == option) {
|
589 |
return;
|
590 |
}
|
591 |
-
if (prevElement
|
592 |
prevElement.style.display = "none";
|
593 |
}
|
594 |
|
595 |
-
if (id
|
596 |
prevElement = null;
|
597 |
} else {
|
598 |
prevElement = document.getElementById(id);
|
191 |
});
|
192 |
jQuery("form[name='add_coupon']").submit(function() {
|
193 |
var title = jQuery("form[name='add_coupon'] input[name='add_coupon_code']").val();
|
194 |
+
if ( title === '' ) {
|
195 |
jQuery('<div id="notice" class="error"><p>' + wpsc_adminL10n.empty_coupon + '</p></div>').insertAfter('div.wrap > h2').delay(2500).hide(350);
|
196 |
return false;
|
197 |
}
|
205 |
var currencyRowTemplate = jQuery( '.wpsc-currency-layers tr.template' ).remove().removeClass( 'template hidden' ).removeAttr( 'id' );
|
206 |
|
207 |
// Hide table if empty
|
208 |
+
if ( jQuery( '.wpsc-currency-layers tbody tr' ).length === 0 ) {
|
209 |
jQuery( '.wpsc-currency-layers table' ).hide();
|
210 |
}
|
211 |
|
221 |
var currencyRow = jQuery( this ).closest( 'tr' );
|
222 |
currencyRow.find( 'input' ).val( '' );
|
223 |
currencyRow.find( 'select' ).val( '' );
|
224 |
+
if ( currencyRow.siblings().length === 0 ) {
|
225 |
currencyRow.closest( 'table' ).hide();
|
226 |
}
|
227 |
currencyRow.remove();
|
236 |
var qtyRowTemplate = jQuery( '.wpsc-quantity-discounts tr.template' ).remove().removeClass( 'template hidden' ).removeAttr( 'id' );
|
237 |
|
238 |
// Hide table if empty
|
239 |
+
if ( jQuery( '.wpsc-quantity-discounts tbody tr' ).length === 0 ) {
|
240 |
jQuery( '.wpsc-quantity-discounts table' ).hide();
|
241 |
}
|
242 |
|
251 |
jQuery( '.wpsc-quantity-discounts' ).on( 'click', '.remove_line', function( e ) {
|
252 |
var qtyRow = jQuery( this ).closest( 'tr' );
|
253 |
qtyRow.find( 'input' ).val( '' );
|
254 |
+
if ( qtyRow.siblings().length === 0 ) {
|
255 |
qtyRow.closest( 'table' ).hide();
|
256 |
}
|
257 |
qtyRow.remove();
|
306 |
jQuery('th.column-stock input, td.stock input').each(function(){
|
307 |
this.disabled = ! checked;
|
308 |
});
|
309 |
+
};
|
310 |
|
311 |
if (limited_stock_checkbox.size() > 0) {
|
312 |
toggle_stock_fields(limited_stock_checkbox.is(':checked'));
|
563 |
}
|
564 |
|
565 |
function wpsc_update_product_gallery_tab(obj){
|
566 |
+
var output, url;
|
567 |
+
|
568 |
output = '<div id="wpsc_product_gallery">';
|
569 |
output += '<ul>';
|
570 |
|
571 |
+
for (var i = 0; i < obj.length; i++) {
|
572 |
+
|
573 |
+
if ( 'undefined' !== typeof obj[i].sizes.thumbnail ) {
|
574 |
+
url = obj[i].sizes.thumbnail.url;
|
575 |
+
} else {
|
576 |
+
url = obj[i].sizes.full.url;
|
577 |
+
}
|
578 |
+
|
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 |
|
597 |
if (prevOption == option) {
|
598 |
return;
|
599 |
}
|
600 |
+
if (prevElement !== null) {
|
601 |
prevElement.style.display = "none";
|
602 |
}
|
603 |
|
604 |
+
if (id === null) {
|
605 |
prevElement = null;
|
606 |
} else {
|
607 |
prevElement = document.getElementById(id);
|
wpsc-admin/js/media.js
CHANGED
@@ -392,5 +392,10 @@
|
|
392 |
|
393 |
frame.open();
|
394 |
});
|
|
|
|
|
|
|
|
|
|
|
395 |
});
|
396 |
}(jQuery));
|
392 |
|
393 |
frame.open();
|
394 |
});
|
395 |
+
// make our gallery sortable
|
396 |
+
$( 'div#wpsc_product_gallery' ).find( 'ul' ).sortable({
|
397 |
+
cursor: 'move',
|
398 |
+
revert: 300,
|
399 |
+
}).disableSelection();
|
400 |
});
|
401 |
}(jQuery));
|
wpsc-admin/media.php
CHANGED
@@ -15,7 +15,7 @@ function _wpsc_action_enqueue_media_scripts() {
|
|
15 |
$id = $post->ID;
|
16 |
|
17 |
$gallery = _wpsc_get_product_gallery_json( $id );
|
18 |
-
wp_enqueue_script( 'wpsc-media', WPSC_URL . '/wpsc-admin/js/media.js', array( 'media-editor', 'wp-e-commerce-admin', 'post' ), WPSC_VERSION );
|
19 |
wp_localize_script( 'wpsc-media', 'WPSC_Media', array(
|
20 |
'l10n' => array(
|
21 |
'productMediaTitle' => __( 'Add Images to Product Gallery', 'wpsc' ),
|
15 |
$id = $post->ID;
|
16 |
|
17 |
$gallery = _wpsc_get_product_gallery_json( $id );
|
18 |
+
wp_enqueue_script( 'wpsc-media', WPSC_URL . '/wpsc-admin/js/media.js', array( 'media-editor', 'wp-e-commerce-admin', 'jquery-ui-sortable', 'post' ), WPSC_VERSION );
|
19 |
wp_localize_script( 'wpsc-media', 'WPSC_Media', array(
|
20 |
'l10n' => array(
|
21 |
'productMediaTitle' => __( 'Add Images to Product Gallery', 'wpsc' ),
|
wpsc-components/merchant-core-v3/classes/http.php
DELETED
@@ -1,34 +0,0 @@
|
|
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 |
-
);
|
14 |
-
|
15 |
-
$args = array_merge( $defaults, $args );
|
16 |
-
$args['body'] = $fields;
|
17 |
-
|
18 |
-
$response = wp_remote_request( $url, $args );
|
19 |
-
|
20 |
-
if ( is_wp_error( $response ) )
|
21 |
-
throw new PHP_Merchant_Exception( PHPME_HTTP_REQUEST_FAILED, $response->get_error_message() );
|
22 |
-
|
23 |
-
return $response['body'];
|
24 |
-
}
|
25 |
-
|
26 |
-
public function post( $url, $fields = '', $args = array() ) {
|
27 |
-
$args['method'] = 'POST';
|
28 |
-
return $this->request( esc_url_raw( $url ), $fields, $args );
|
29 |
-
}
|
30 |
-
|
31 |
-
public function get( $url, $fields = '', $args = array() ) {
|
32 |
-
return $this->request( esc_url_raw( $url ), $fields, $args );
|
33 |
-
}
|
34 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/classes/payment-gateway.php
DELETED
@@ -1,611 +0,0 @@
|
|
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 |
-
self::$gateways[$filename] = $meta;
|
219 |
-
|
220 |
-
return true;
|
221 |
-
}
|
222 |
-
|
223 |
-
/**
|
224 |
-
* Updates the payment gateway cache when it's changed. This function is hooked
|
225 |
-
* into WordPress' wp_loaded action
|
226 |
-
*
|
227 |
-
* @access public
|
228 |
-
* @static
|
229 |
-
* @since 3.9
|
230 |
-
*
|
231 |
-
* @return void
|
232 |
-
*/
|
233 |
-
public static function action_save_payment_gateway_cache() {
|
234 |
-
if ( self::$payment_gateway_cache != self::$gateways )
|
235 |
-
update_option( 'wpsc_payment_gateway_cache', self::$gateways );
|
236 |
-
}
|
237 |
-
|
238 |
-
public function flush_cache() {
|
239 |
-
delete_option( 'wpsc_payment_gateway_cache' );
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* Gets metadata of a certain payment gateway. This is better than calling WPSC_Payment_Gateways->get( $gateway_name )->get_title()
|
244 |
-
* and the likes of it, since it doesn't require the gateway itself to be loaded.
|
245 |
-
*
|
246 |
-
* @access public
|
247 |
-
* @static
|
248 |
-
* @since 3.9
|
249 |
-
*
|
250 |
-
* @param string $gateway
|
251 |
-
* @return mixed Array containing the metadata. If the gateway is not registered,
|
252 |
-
* returns false.
|
253 |
-
*/
|
254 |
-
public static function get_meta( $gateway ) {
|
255 |
-
return isset( self::$gateways[$gateway] ) ? self::$gateways[$gateway] : false;
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
*
|
260 |
-
* Return an array containing registered gateway names.
|
261 |
-
*
|
262 |
-
* @access public
|
263 |
-
* @since 3.9
|
264 |
-
*
|
265 |
-
* @return array
|
266 |
-
*/
|
267 |
-
public static function get_gateways() {
|
268 |
-
return array_keys( self::$gateways );
|
269 |
-
}
|
270 |
-
|
271 |
-
public static function get_active_gateways() {
|
272 |
-
if ( empty( self::$active_gateways ) ) {
|
273 |
-
$selected_gateways = get_option( 'custom_gateway_options', array() );
|
274 |
-
$registered_gateways = self::get_gateways();
|
275 |
-
self::$active_gateways = array_intersect( $selected_gateways, $registered_gateways );
|
276 |
-
}
|
277 |
-
|
278 |
-
return self::$active_gateways;
|
279 |
-
}
|
280 |
-
|
281 |
-
/**
|
282 |
-
* No instantiation for this class
|
283 |
-
*
|
284 |
-
* @access private
|
285 |
-
* @since 3.9
|
286 |
-
*
|
287 |
-
*/
|
288 |
-
private function __construct() {}
|
289 |
-
}
|
290 |
-
|
291 |
-
abstract class WPSC_Payment_Gateway
|
292 |
-
{
|
293 |
-
|
294 |
-
/**
|
295 |
-
* Object that allows manipulation of payment gateway settings in a consistent
|
296 |
-
* manner
|
297 |
-
*
|
298 |
-
* @access public
|
299 |
-
* @var string
|
300 |
-
*/
|
301 |
-
public $setting;
|
302 |
-
|
303 |
-
public $purchase_log;
|
304 |
-
|
305 |
-
public $checkout_data;
|
306 |
-
|
307 |
-
public $currency_code;
|
308 |
-
|
309 |
-
/**
|
310 |
-
* Return the title of the payment gateway. For this to work, $this->title must
|
311 |
-
* be set already.
|
312 |
-
*
|
313 |
-
* It is recommended that the payment gateway title be properly localized using __()
|
314 |
-
*
|
315 |
-
* @access public
|
316 |
-
* @since 3.9
|
317 |
-
* @see __()
|
318 |
-
*
|
319 |
-
* @return string
|
320 |
-
*/
|
321 |
-
public function get_title() {
|
322 |
-
$title = empty( $this->title ) ? '' : $this->title;
|
323 |
-
return apply_filters( 'wpsc_payment_gateway_title', $title );
|
324 |
-
}
|
325 |
-
|
326 |
-
/**
|
327 |
-
* Display the payment gateway settings form as seen in WP e-Commerce Settings area.
|
328 |
-
* This method must be overridden by subclasses.
|
329 |
-
*
|
330 |
-
* @abstract
|
331 |
-
* @access public
|
332 |
-
* @since 3.9
|
333 |
-
*
|
334 |
-
* @return void
|
335 |
-
*/
|
336 |
-
public function setup_form() {
|
337 |
-
$checkout_field_types = array(
|
338 |
-
'billing' => __( 'Billing Fields', 'wpsc' ),
|
339 |
-
'shipping' => __( 'Shipping Fields', 'wpsc' ),
|
340 |
-
);
|
341 |
-
|
342 |
-
$fields = array(
|
343 |
-
'firstname' => __( 'First Name', 'wpsc' ),
|
344 |
-
'lastname' => __( 'Last Name', 'wpsc' ),
|
345 |
-
'address' => __( 'Address', 'wpsc' ),
|
346 |
-
'city' => __( 'City', 'wpsc' ),
|
347 |
-
'state' => __( 'State', 'wpsc' ),
|
348 |
-
'country' => __( 'Country', 'wpsc' ),
|
349 |
-
'postcode' => __( 'Postal Code', 'wpsc' ),
|
350 |
-
);
|
351 |
-
$checkout_form = WPSC_Checkout_Form::get();
|
352 |
-
foreach ( $checkout_field_types as $field_type => $title ): ?>
|
353 |
-
<tr>
|
354 |
-
<td colspan="2">
|
355 |
-
<h4><?php echo esc_html( $title ); ?></h4>
|
356 |
-
</td>
|
357 |
-
</tr>
|
358 |
-
<?php foreach ( $fields as $field_name => $field_title ):
|
359 |
-
$unique_name = $field_type . $field_name;
|
360 |
-
$selected_id = $this->setting->get( "checkout_field_{$unique_name}", $checkout_form->get_field_id_by_unique_name( $unique_name ) );
|
361 |
-
?>
|
362 |
-
<tr>
|
363 |
-
<td>
|
364 |
-
<label for="manual-form-<?php echo esc_attr( $unique_name ); ?>"><?php echo esc_html( $field_title ); ?></label>
|
365 |
-
</td>
|
366 |
-
<td>
|
367 |
-
<select name="<?php echo $this->setting->get_field_name( "checkout_field_{$unique_name}" ); ?>" id="manual-form-<?php echo esc_attr( $unique_name ); ?>">
|
368 |
-
<?php $checkout_form->field_drop_down_options( $selected_id ); ?>
|
369 |
-
</select>
|
370 |
-
</td>
|
371 |
-
</tr>
|
372 |
-
<?php endforeach;
|
373 |
-
endforeach;
|
374 |
-
}
|
375 |
-
|
376 |
-
/**
|
377 |
-
* Process and send payment details to payment gateways
|
378 |
-
*
|
379 |
-
* @abstract
|
380 |
-
* @access public
|
381 |
-
* @since 3.9
|
382 |
-
*
|
383 |
-
* @return void
|
384 |
-
*/
|
385 |
-
abstract public function process();
|
386 |
-
|
387 |
-
/**
|
388 |
-
* Returns the URL to the logo of the payment gateway (or any representative image).
|
389 |
-
*
|
390 |
-
* @access public
|
391 |
-
* @since 3.9
|
392 |
-
*
|
393 |
-
* @return mixed False if there's no image defined.
|
394 |
-
*/
|
395 |
-
public function get_image_url() {
|
396 |
-
return false;
|
397 |
-
}
|
398 |
-
|
399 |
-
public function set_purchase_log( &$purchase_log ) {
|
400 |
-
$this->purchase_log = &$purchase_log;
|
401 |
-
$this->checkout_data = new WPSC_Checkout_Form_Data( $purchase_log->get( 'id' ) );
|
402 |
-
}
|
403 |
-
|
404 |
-
public function get_currency_code() {
|
405 |
-
if ( ! $this->currency_code ) {
|
406 |
-
$country = new WPSC_Country( get_option( 'currency_type' ) );
|
407 |
-
$currency = $country->get( 'code' );
|
408 |
-
}
|
409 |
-
|
410 |
-
return $currency;
|
411 |
-
}
|
412 |
-
|
413 |
-
public function get_notification_url() {
|
414 |
-
return add_query_arg( 'wpsc_action', 'gateway_notification', (get_option( 'siteurl' ) . "/index.php" ) );
|
415 |
-
}
|
416 |
-
|
417 |
-
public function get_transaction_results_url() {
|
418 |
-
return get_option( 'transact_url' );
|
419 |
-
}
|
420 |
-
|
421 |
-
public function get_shopping_cart_url() {
|
422 |
-
return get_option( 'shopping_cart_url' );
|
423 |
-
}
|
424 |
-
|
425 |
-
public function get_products_page_url() {
|
426 |
-
return get_option( 'product_list_url' );
|
427 |
-
}
|
428 |
-
|
429 |
-
public function go_to_transaction_results() {
|
430 |
-
//Now to do actions once the payment has been attempted
|
431 |
-
switch ( $this->purchase_log->get( 'processed' ) ) {
|
432 |
-
case 3:
|
433 |
-
// payment worked
|
434 |
-
do_action('wpsc_payment_successful');
|
435 |
-
break;
|
436 |
-
case 1:
|
437 |
-
// payment declined
|
438 |
-
do_action('wpsc_payment_failed');
|
439 |
-
break;
|
440 |
-
case 2:
|
441 |
-
// something happened with the payment
|
442 |
-
do_action('wpsc_payment_incomplete');
|
443 |
-
break;
|
444 |
-
}
|
445 |
-
|
446 |
-
$transaction_url_with_sessionid = add_query_arg( 'sessionid', $this->purchase_log->get( 'sessionid' ), get_option( 'transact_url' ) );
|
447 |
-
wp_redirect( $transaction_url_with_sessionid );
|
448 |
-
|
449 |
-
exit();
|
450 |
-
}
|
451 |
-
|
452 |
-
/**
|
453 |
-
* Payment gateway constructor. Should use WPSC_Payment_Gateways::get( $gateway_name ) instead.
|
454 |
-
*
|
455 |
-
* @access public
|
456 |
-
* @return WPSC_Payment_Gateway
|
457 |
-
*/
|
458 |
-
public function __construct() {
|
459 |
-
$this->setting = new WPSC_Payment_Gateway_Setting( get_class( $this ) );
|
460 |
-
}
|
461 |
-
}
|
462 |
-
|
463 |
-
class WPSC_Payment_Gateway_Setting
|
464 |
-
{
|
465 |
-
/**
|
466 |
-
* Contain settings of the payment gateway
|
467 |
-
*
|
468 |
-
* @access private
|
469 |
-
* @var array
|
470 |
-
*/
|
471 |
-
private $settings;
|
472 |
-
|
473 |
-
/**
|
474 |
-
* Contain unsaved settings of the payment gateway. This is useful when the saving of the settings
|
475 |
-
* are deferred.
|
476 |
-
*
|
477 |
-
* @access private
|
478 |
-
* @var array
|
479 |
-
*/
|
480 |
-
private $unsaved_settings = array();
|
481 |
-
|
482 |
-
/**
|
483 |
-
* Name of the gateway
|
484 |
-
*
|
485 |
-
* @access private
|
486 |
-
* @var string
|
487 |
-
*/
|
488 |
-
private $gateway_name = '';
|
489 |
-
|
490 |
-
/**
|
491 |
-
* Name of the option containing all the settings in WP DB
|
492 |
-
*
|
493 |
-
* @access private
|
494 |
-
* @var string
|
495 |
-
*/
|
496 |
-
private $option_name = '';
|
497 |
-
|
498 |
-
/**
|
499 |
-
* Save settings when the payment gateway setup form is updated
|
500 |
-
*
|
501 |
-
* @access public
|
502 |
-
* @static
|
503 |
-
* @return void
|
504 |
-
*
|
505 |
-
* @since 3.9
|
506 |
-
*/
|
507 |
-
public static function action_update_payment_gateway_settings() {
|
508 |
-
if ( ! empty( $_POST['wpsc_payment_gateway_settings'] ) )
|
509 |
-
foreach ( $_POST['wpsc_payment_gateway_settings'] as $gateway_name => $new_settings ) {
|
510 |
-
$settings = new WPSC_Payment_Gateway_Setting( $gateway_name );
|
511 |
-
$settings->merge( $new_settings );
|
512 |
-
}
|
513 |
-
}
|
514 |
-
|
515 |
-
/**
|
516 |
-
* Constructor
|
517 |
-
*
|
518 |
-
* @access public
|
519 |
-
*
|
520 |
-
* @param string $gateway_name Name of the gateway
|
521 |
-
* @return WPSC_Payment_Gateway
|
522 |
-
*/
|
523 |
-
public function __construct( $gateway_name_or_class ) {
|
524 |
-
$name = str_replace( 'wpsc_payment_gateway_', '', strtolower( $gateway_name_or_class ) );
|
525 |
-
$name = str_replace( array( ' ', '-' ), '_', $name );
|
526 |
-
$this->gateway_name = $name;
|
527 |
-
$this->option_name = 'wpsc_payment_gateway_' . $this->gateway_name;
|
528 |
-
}
|
529 |
-
|
530 |
-
/**
|
531 |
-
* Lazy load the settings from the DB when necessary
|
532 |
-
*
|
533 |
-
* @access private
|
534 |
-
* @return void
|
535 |
-
*/
|
536 |
-
private function lazy_load() {
|
537 |
-
if ( is_null( $this->settings ) )
|
538 |
-
$this->settings = get_option( $this->option_name, array() );
|
539 |
-
}
|
540 |
-
|
541 |
-
/**
|
542 |
-
* Get the value of a setting
|
543 |
-
*
|
544 |
-
* @param string $setting
|
545 |
-
* @return mixed
|
546 |
-
* @since 3.9
|
547 |
-
*/
|
548 |
-
public function get( $setting, $default = false ) {
|
549 |
-
$this->lazy_load();
|
550 |
-
return isset( $this->settings[$setting] ) ? $this->settings[$setting] : $default;
|
551 |
-
}
|
552 |
-
|
553 |
-
/**
|
554 |
-
* Set the value of a setting
|
555 |
-
*
|
556 |
-
* @param string $setting
|
557 |
-
* @param mixed $value
|
558 |
-
* @param bool $defer True if you want to defer saving the settings array to the database
|
559 |
-
* @return void
|
560 |
-
* @since 3.9
|
561 |
-
*/
|
562 |
-
public function set( $setting, $value, $defer = false ) {
|
563 |
-
$this->lazy_load();
|
564 |
-
$this->unsaved_settings[$setting] = $value;
|
565 |
-
if ( ! $defer )
|
566 |
-
$this->save();
|
567 |
-
}
|
568 |
-
|
569 |
-
/**
|
570 |
-
* Overwrite current settings with an array of settings
|
571 |
-
*
|
572 |
-
* @access public
|
573 |
-
* @param string $settings Settings that you want to overwrite upon current settings
|
574 |
-
* @param string $defer Optional. Defaults to false. True if you want to defer
|
575 |
-
* saving the settings array to the database.
|
576 |
-
* @return void
|
577 |
-
* @since 3.9
|
578 |
-
*/
|
579 |
-
public function merge( $settings, $defer = false ) {
|
580 |
-
$this->lazy_load();
|
581 |
-
$this->unsaved_settings = array_merge( $this->unsaved_settings, $settings );
|
582 |
-
if ( ! $defer )
|
583 |
-
$this->save();
|
584 |
-
}
|
585 |
-
|
586 |
-
/**
|
587 |
-
* Returns the field name of the setting on payment gateway setup form
|
588 |
-
*
|
589 |
-
* @access public
|
590 |
-
* @param string $setting Setting names
|
591 |
-
* @return string
|
592 |
-
* @since 3.9
|
593 |
-
*/
|
594 |
-
public function get_field_name( $setting ) {
|
595 |
-
return "wpsc_payment_gateway_settings[{$this->gateway_name}][{$setting}]";
|
596 |
-
}
|
597 |
-
|
598 |
-
/**
|
599 |
-
* Save the settings into the database
|
600 |
-
*
|
601 |
-
* @return void
|
602 |
-
* @since 3.9
|
603 |
-
*/
|
604 |
-
public function save() {
|
605 |
-
$this->settings = array_merge( $this->settings, $this->unsaved_settings );
|
606 |
-
$this->unsaved_settings = array();
|
607 |
-
update_option( $this->option_name, $this->settings );
|
608 |
-
}
|
609 |
-
}
|
610 |
-
|
611 |
-
WPSC_Payment_Gateways::init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/manual.php
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WPSC_Payment_Gateway_Manual extends WPSC_Payment_Gateway
|
4 |
-
{
|
5 |
-
/**
|
6 |
-
* Constructor of Manual Payment Gateway
|
7 |
-
*
|
8 |
-
* @access public
|
9 |
-
* @since 3.9
|
10 |
-
*/
|
11 |
-
public function __construct() {
|
12 |
-
parent::__construct();
|
13 |
-
$this->title = __( 'Manual Payment Gateway 3.0', 'wpsc' );
|
14 |
-
}
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Displays the setup form
|
18 |
-
*
|
19 |
-
* @access public
|
20 |
-
* @since 3.9
|
21 |
-
* @uses WPSC_Checkout_Form::get()
|
22 |
-
* @uses WPSC_Checkout_Form::field_drop_down_options()
|
23 |
-
* @uses WPSC_Checkout_Form::get_field_id_by_unique_name()
|
24 |
-
* @uses WPSC_Payment_Gateway_Setting::get()
|
25 |
-
*
|
26 |
-
* @return void
|
27 |
-
*/
|
28 |
-
public function setup_form() {
|
29 |
-
?>
|
30 |
-
<tr>
|
31 |
-
<td colspan="2">
|
32 |
-
<p>
|
33 |
-
<label for="wpsc-manual-gateway-setup"><?php _e( 'Instructions', 'wpsc' ); ?></label><br />
|
34 |
-
<textarea id="wpsc-manual-gateway-setup" cols='' rows='10' name='<?php echo esc_attr( $this->setting->get_field_name( 'payment_instructions' ) ); ?>'><?php echo esc_html( $this->setting->get( 'payment_instructions' ) ); ?></textarea><br />
|
35 |
-
<small><?php _e('Enter the payment instructions that you wish to display to your customers when they make a purchase.', 'wpsc'); ?></small><br />
|
36 |
-
<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>
|
37 |
-
</p>
|
38 |
-
</td>
|
39 |
-
</tr>
|
40 |
-
<tr class='update_gateway' >
|
41 |
-
<td colspan='2'>
|
42 |
-
<div class='submit'>
|
43 |
-
<input type='submit' value='<?php _e( 'Update »', 'wpsc' ); ?>' name='updateoption' />
|
44 |
-
</div>
|
45 |
-
</td>
|
46 |
-
</tr>
|
47 |
-
<?php
|
48 |
-
parent::setup_form();
|
49 |
-
}
|
50 |
-
|
51 |
-
public function process() {
|
52 |
-
$this->purchase_log->set( 'processed', WPSC_PAYMENT_STATUS_RECEIVED )->save();
|
53 |
-
$this->go_to_transaction_results();
|
54 |
-
}
|
55 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php
DELETED
@@ -1,301 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once( 'paypal-express-checkout.php' );
|
4 |
-
|
5 |
-
class WPSC_Payment_Gateway_Paypal_Digital_Goods extends WPSC_Payment_Gateway_Paypal_Express_Checkout
|
6 |
-
{
|
7 |
-
const SANDBOX_URL = 'https://www.sandbox.paypal.com/incontext?token=';
|
8 |
-
const LIVE_URL = 'https://www.paypal.com/incontext?token=';
|
9 |
-
|
10 |
-
public $gateway;
|
11 |
-
|
12 |
-
public function __construct( $options ) {
|
13 |
-
|
14 |
-
require_once( 'php-merchant/gateways/paypal-digital-goods.php' );
|
15 |
-
$this->gateway = new PHP_Merchant_Paypal_Digital_Goods( $options );
|
16 |
-
|
17 |
-
// Now that the gateway is created, call parent constructor
|
18 |
-
parent::__construct( $options );
|
19 |
-
|
20 |
-
$this->title = __( 'Paypal Digital Goods for Express Checkout', 'wpsc' );
|
21 |
-
|
22 |
-
$this->gateway->set_options( array(
|
23 |
-
'api_username' => $this->setting->get( 'api_username' ),
|
24 |
-
'api_password' => $this->setting->get( 'api_password' ),
|
25 |
-
'api_signature' => $this->setting->get( 'api_signature' ),
|
26 |
-
'cancel_url' => get_option( 'shopping_cart_url' ),
|
27 |
-
'currency' => $this->get_currency_code(),
|
28 |
-
'test' => (bool) $this->setting->get( 'sandbox_mode' )
|
29 |
-
) );
|
30 |
-
|
31 |
-
add_action( 'wpsc_bottom_of_shopping_cart', array( $this, 'add_iframe_script' ) );
|
32 |
-
|
33 |
-
add_action( 'wpsc_confirm_checkout', array( $this, 'remove_iframe_script' ) );
|
34 |
-
|
35 |
-
add_filter( 'wpsc_purchase_log_gateway_data', array( get_parent_class( $this ), 'filter_purchase_log_gateway_data' ), 10, 2 );
|
36 |
-
}
|
37 |
-
|
38 |
-
/**
|
39 |
-
* To start the incontext checkout flow, a DGFlow object needs to be created. This JavaScript creates a
|
40 |
-
* DGFlow object if the "paypal-digital-goods" payment gateway radio button is checked.
|
41 |
-
*/
|
42 |
-
public function add_iframe_script() {
|
43 |
-
$this->remove_iframe_script(); ?>
|
44 |
-
<script src ="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>
|
45 |
-
<script>
|
46 |
-
jQuery(document).ready(function($){
|
47 |
-
$('form.wpsc_checkout_forms input[name="submit"]').click(function(){
|
48 |
-
if($('input[name="custom_gateway"]:checked').val() === undefined || $('input[name="custom_gateway"]:checked').val() == "paypal-digital-goods" ) {
|
49 |
-
var dg = new PAYPAL.apps.DGFlow({trigger:'submit-purchase'});
|
50 |
-
dg.startFlow();
|
51 |
-
}
|
52 |
-
return false;
|
53 |
-
});
|
54 |
-
});
|
55 |
-
</script>
|
56 |
-
<?php
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* When a buyer returns from PayPal, they will still be in the iframe. This function removes the iframe
|
61 |
-
* and returns the buyer to the main site.
|
62 |
-
*
|
63 |
-
* It also hides the body to prevent the second or two or showing the entire checkout page in the iframe.
|
64 |
-
*/
|
65 |
-
public function remove_iframe_script(){
|
66 |
-
if ( ! has_action( 'template_redirect', array( $this, 'close_iframe' ) ) )
|
67 |
-
add_action( 'template_redirect', array( $this, 'close_iframe' ), 1 );
|
68 |
-
}
|
69 |
-
|
70 |
-
public function close_iframe() {
|
71 |
-
echo '<script>if (window!=top) { document.body.style.display = "none"; top.location.replace(document.location); }</script>';
|
72 |
-
exit;
|
73 |
-
}
|
74 |
-
|
75 |
-
protected function get_return_url() {
|
76 |
-
$location = add_query_arg( array(
|
77 |
-
'sessionid' => $this->purchase_log->get( 'sessionid' ),
|
78 |
-
'payment_gateway' => 'paypal-digital-goods',
|
79 |
-
'payment_gateway_callback' => 'confirm_transaction',
|
80 |
-
),
|
81 |
-
home_url( 'index.php' )
|
82 |
-
);
|
83 |
-
return apply_filters( 'wpsc_paypal_digital_goods_return_url', $location );
|
84 |
-
}
|
85 |
-
|
86 |
-
protected function get_notify_url() {
|
87 |
-
$location = add_query_arg( array(
|
88 |
-
'payment_gateway' => 'paypal-digital-goods',
|
89 |
-
'payment_gateway_callback' => 'ipn',
|
90 |
-
), home_url( 'index.php' ) );
|
91 |
-
|
92 |
-
return apply_filters( 'wpsc_paypal_express_checkout_notify_url', $location );
|
93 |
-
}
|
94 |
-
|
95 |
-
public function callback_ipn() {
|
96 |
-
$ipn = new PHP_Merchant_Paypal_IPN( false, (bool) $this->setting->get( 'sandbox_mode', false ) );
|
97 |
-
|
98 |
-
if ( $ipn->is_verified() ) {
|
99 |
-
$sessionid = $ipn->get( 'invoice' );
|
100 |
-
$this->set_purchase_log_for_callbacks( $sessionid );
|
101 |
-
|
102 |
-
if ( $ipn->is_payment_denied() ) {
|
103 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::PAYMENT_DECLINED );
|
104 |
-
} elseif ( $ipn->is_payment_refunded() ) {
|
105 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUNDED );
|
106 |
-
} elseif ( $ipn->is_payment_completed() ) {
|
107 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
108 |
-
} elseif ( $ipn->is_payment_pending() ) {
|
109 |
-
if ( $ipn->is_payment_refund_pending() )
|
110 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUND_PENDING );
|
111 |
-
else
|
112 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
113 |
-
}
|
114 |
-
|
115 |
-
$this->purchase_log->save();
|
116 |
-
transaction_results( $sessionid, false );
|
117 |
-
}
|
118 |
-
|
119 |
-
exit;
|
120 |
-
}
|
121 |
-
|
122 |
-
public function callback_confirm_transaction() {
|
123 |
-
|
124 |
-
if ( ! isset( $_REQUEST['sessionid'] ) || ! isset( $_REQUEST['token'] ) || ! isset( $_REQUEST['PayerID'] ) )
|
125 |
-
return;
|
126 |
-
|
127 |
-
$this->set_purchase_log_for_callbacks();
|
128 |
-
|
129 |
-
$this->callback_process_confirmed_payment();
|
130 |
-
}
|
131 |
-
|
132 |
-
public function callback_process_confirmed_payment() {
|
133 |
-
|
134 |
-
$args = array_map( 'urldecode', $_GET );
|
135 |
-
|
136 |
-
extract( $args, EXTR_SKIP );
|
137 |
-
if ( ! isset( $sessionid ) || ! isset( $token ) || ! isset( $PayerID ) )
|
138 |
-
return;
|
139 |
-
|
140 |
-
$this->set_purchase_log_for_callbacks();
|
141 |
-
|
142 |
-
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
143 |
-
$options = array(
|
144 |
-
'token' => $token,
|
145 |
-
'payer_id' => $PayerID,
|
146 |
-
'invoice' => $this->purchase_log->get( 'sessionid' ),
|
147 |
-
);
|
148 |
-
$options += $this->checkout_data->get_gateway_data();
|
149 |
-
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
150 |
-
|
151 |
-
if ( $this->setting->get( 'ipn', false ) )
|
152 |
-
$options['notify_url'] = $this->get_notify_url();
|
153 |
-
|
154 |
-
$response = $this->gateway->purchase( $options );
|
155 |
-
|
156 |
-
$location = add_query_arg( array(
|
157 |
-
'sessionid' => $this->purchase_log->get( 'sessionid' ),
|
158 |
-
'token' => $token,
|
159 |
-
'PayerID' => $PayerID,
|
160 |
-
'payment_gateway' => 'paypal-digital-goods'
|
161 |
-
),
|
162 |
-
get_option( 'transact_url' )
|
163 |
-
);
|
164 |
-
|
165 |
-
if ( $response->has_errors() ) {
|
166 |
-
error_log( print_r( array( 'errors' => $response->get_errors(), 'options' => $options ) , 1 ), 1, 'justinsainton@gmail.com' );
|
167 |
-
wpsc_update_customer_meta( 'paypal_express_checkout_errors', $response->get_errors() );
|
168 |
-
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_paypal_error' ), $location );
|
169 |
-
} elseif ( $response->is_payment_completed() || $response->is_payment_pending() ) {
|
170 |
-
$location = remove_query_arg( 'payment_gateway', $location );
|
171 |
-
|
172 |
-
if ( $response->is_payment_completed() )
|
173 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
174 |
-
else
|
175 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
176 |
-
|
177 |
-
$this->purchase_log->set( 'transactid', $response->get( 'transaction_id' ) )
|
178 |
-
->set( 'date', time() )
|
179 |
-
->save();
|
180 |
-
} else {
|
181 |
-
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_generic_error' ), $location );
|
182 |
-
}
|
183 |
-
|
184 |
-
$location = apply_filters( 'wpsc_paypal_digital_goods_confirmed_payment_url', $location );
|
185 |
-
|
186 |
-
wp_redirect( $location );
|
187 |
-
exit;
|
188 |
-
}
|
189 |
-
|
190 |
-
/**
|
191 |
-
* Output the form on the Digital Goods settings page.
|
192 |
-
*/
|
193 |
-
public function setup_form() {
|
194 |
-
$paypal_currency = $this->get_currency_code();
|
195 |
-
?>
|
196 |
-
<tr>
|
197 |
-
<td>
|
198 |
-
<label for="wpsc-paypal-express-api-username"><?php _e( 'API Username', 'wpsc' ); ?></label>
|
199 |
-
</td>
|
200 |
-
<td>
|
201 |
-
<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" />
|
202 |
-
</td>
|
203 |
-
</tr>
|
204 |
-
<tr>
|
205 |
-
<td>
|
206 |
-
<label for="wpsc-paypal-express-api-password"><?php _e( 'API Password', 'wpsc' ); ?></label>
|
207 |
-
</td>
|
208 |
-
<td>
|
209 |
-
<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" />
|
210 |
-
</td>
|
211 |
-
</tr>
|
212 |
-
<tr>
|
213 |
-
<td>
|
214 |
-
<label for="wpsc-paypal-express-api-signature"><?php _e( 'API Signature', 'wpsc' ); ?></label>
|
215 |
-
</td>
|
216 |
-
<td>
|
217 |
-
<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" />
|
218 |
-
</td>
|
219 |
-
</tr>
|
220 |
-
<tr>
|
221 |
-
<td>
|
222 |
-
<label><?php _e( 'Sandbox Mode', 'wpsc' ); ?></label>
|
223 |
-
</td>
|
224 |
-
<td>
|
225 |
-
<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>
|
226 |
-
<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>
|
227 |
-
</td>
|
228 |
-
</tr>
|
229 |
-
<tr>
|
230 |
-
<td>
|
231 |
-
<label><?php _e( 'IPN', 'wpsc' ); ?></label>
|
232 |
-
</td>
|
233 |
-
<td>
|
234 |
-
<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>
|
235 |
-
<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>
|
236 |
-
</td>
|
237 |
-
</tr>
|
238 |
-
<?php if ( ! $this->is_currency_supported() ): ?>
|
239 |
-
<tr>
|
240 |
-
<td colspan="2">
|
241 |
-
<h4><?php _e( 'Currency Conversion', 'wpsc' ); ?></h4>
|
242 |
-
</td>
|
243 |
-
</tr>
|
244 |
-
<tr>
|
245 |
-
<td colspan="2">
|
246 |
-
<p><?php _e( 'Your base currency is currently not accepted by PayPal. As a result, before a payment request is sent to Paypal, WP e-Commerce has to convert the amounts into one of Paypal supported currencies. Please select your preferred currency below.', 'wpsc' ); ?></p>
|
247 |
-
</td>
|
248 |
-
</tr>
|
249 |
-
<tr>
|
250 |
-
<td>
|
251 |
-
<label for "wpsc-paypal-express-currency"><?php _e( 'Paypal Currency', 'wpsc' ); ?></label>
|
252 |
-
</td>
|
253 |
-
<td>
|
254 |
-
<select name="<?php echo esc_attr( $this->setting->get_field_name( 'currency' ) ); ?>" id="wpsc-paypal-express-currency">
|
255 |
-
<?php foreach ($this->gateway->get_supported_currencies() as $currency): ?>
|
256 |
-
<option <?php selected( $currency, $paypal_currency ); ?> value="<?php echo esc_attr( $currency ); ?>"><?php echo esc_html( $currency ); ?></option>
|
257 |
-
<?php endforeach ?>
|
258 |
-
</select>
|
259 |
-
</td>
|
260 |
-
</tr>
|
261 |
-
<?php endif ?>
|
262 |
-
|
263 |
-
<?php
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* Process a purchase.
|
268 |
-
*/
|
269 |
-
public function process( $args = array() ) {
|
270 |
-
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
271 |
-
$options = array(
|
272 |
-
'return_url' => $this->get_return_url(),
|
273 |
-
'invoice' => $this->purchase_log->get( 'sessionid' ),
|
274 |
-
);
|
275 |
-
$options += $this->checkout_data->get_gateway_data();
|
276 |
-
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
277 |
-
|
278 |
-
if ( $this->setting->get( 'ipn', false ) )
|
279 |
-
$options['notify_url'] = $this->get_notify_url();
|
280 |
-
|
281 |
-
$response = $this->gateway->setup_purchase( $options );
|
282 |
-
|
283 |
-
if ( $response->is_successful() ) {
|
284 |
-
$url = ( $this->setting->get( 'sandbox_mode' ) ? self::SANDBOX_URL : self::LIVE_URL ) . $response->get( 'token' );
|
285 |
-
} else {
|
286 |
-
error_log( print_r( array( 'errors' => $response->get_errors(), 'options' => $options ) , 1 ), 1, 'jmihaialexandru@gmail.com' );
|
287 |
-
wpsc_update_customer_meta( 'paypal_express_checkout_errors', $response->get_errors() );
|
288 |
-
$url = add_query_arg( array(
|
289 |
-
'payment_gateway' => 'paypal-digital-goods',
|
290 |
-
'payment_gateway_callback' => 'display_paypal_error',
|
291 |
-
), $this->get_return_url() );
|
292 |
-
}
|
293 |
-
|
294 |
-
if( ! isset( $args['return_only'] ) || $args['return_only'] !== true ) {
|
295 |
-
wp_redirect( $url );
|
296 |
-
exit;
|
297 |
-
}
|
298 |
-
|
299 |
-
return $url;
|
300 |
-
}
|
301 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php
DELETED
@@ -1,381 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WPSC_Payment_Gateway_Paypal_Express_Checkout extends WPSC_Payment_Gateway
|
4 |
-
{
|
5 |
-
const SANDBOX_URL = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=';
|
6 |
-
const LIVE_URL = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=';
|
7 |
-
private $gateway;
|
8 |
-
|
9 |
-
public function __construct( $options ) {
|
10 |
-
parent::__construct();
|
11 |
-
$this->title = __( 'Paypal Express Checkout 3.0', 'wpsc' );
|
12 |
-
require_once( 'php-merchant/gateways/paypal-express-checkout.php' );
|
13 |
-
$this->gateway = new PHP_Merchant_Paypal_Express_Checkout( $options );
|
14 |
-
$this->gateway->set_options( array(
|
15 |
-
'api_username' => $this->setting->get( 'api_username' ),
|
16 |
-
'api_password' => $this->setting->get( 'api_password' ),
|
17 |
-
'api_signature' => $this->setting->get( 'api_signature' ),
|
18 |
-
'cancel_url' => get_option('shopping_cart_url'),
|
19 |
-
'currency' => $this->get_currency_code(),
|
20 |
-
'test' => (bool) $this->setting->get( 'sandbox_mode' ),
|
21 |
-
'address_override' => true,
|
22 |
-
) );
|
23 |
-
|
24 |
-
add_filter( 'wpsc_purchase_log_gateway_data', array( $this, 'filter_purchase_log_gateway_data' ), 10, 2 );
|
25 |
-
}
|
26 |
-
|
27 |
-
public function filter_purchase_log_gateway_data( $gateway_data, $data ) {
|
28 |
-
// Because paypal express checkout API doesn't have full support for discount, we have to manually add an item here
|
29 |
-
if ( isset( $gateway_data['discount'] ) && (float) $gateway_data['discount'] != 0 ) {
|
30 |
-
$i =& $gateway_data['items'];
|
31 |
-
$d =& $gateway_data['discount'];
|
32 |
-
$s =& $gateway_data['subtotal'];
|
33 |
-
|
34 |
-
// If discount amount is larger than or equal to the item total, we need to set item total to 0.01
|
35 |
-
// because Paypal does not accept 0 item total.
|
36 |
-
if ( $d >= $gateway_data['subtotal'] ) {
|
37 |
-
$d = $s - 0.01;
|
38 |
-
|
39 |
-
// if there's shipping, we'll take 0.01 from there
|
40 |
-
if ( ! empty( $gateway_data['shipping'] ) )
|
41 |
-
$gateway_data['shipping'] -= 0.01;
|
42 |
-
else
|
43 |
-
$gateway_data['amount'] = 0.01;
|
44 |
-
}
|
45 |
-
$s -= $d;
|
46 |
-
|
47 |
-
$i[] = array(
|
48 |
-
'name' => __( 'Discount', 'wpsc' ),
|
49 |
-
'amount' => - $d,
|
50 |
-
'quantity' => 1,
|
51 |
-
);
|
52 |
-
}
|
53 |
-
return $gateway_data;
|
54 |
-
}
|
55 |
-
|
56 |
-
protected function get_return_url() {
|
57 |
-
$location = add_query_arg( array(
|
58 |
-
'sessionid' => $this->purchase_log->get( 'sessionid' ),
|
59 |
-
'payment_gateway' => 'paypal-express-checkout',
|
60 |
-
'payment_gateway_callback' => 'confirm_transaction',
|
61 |
-
),
|
62 |
-
get_option( 'transact_url' )
|
63 |
-
);
|
64 |
-
return apply_filters( 'wpsc_paypal_express_checkout_return_url', $location );
|
65 |
-
}
|
66 |
-
|
67 |
-
protected function get_notify_url() {
|
68 |
-
$location = add_query_arg( array(
|
69 |
-
'payment_gateway' => 'paypal-express-checkout',
|
70 |
-
'payment_gateway_callback' => 'ipn',
|
71 |
-
), home_url( 'index.php' ) );
|
72 |
-
|
73 |
-
return apply_filters( 'wpsc_paypal_express_checkout_notify_url', $location );
|
74 |
-
}
|
75 |
-
|
76 |
-
protected function set_purchase_log_for_callbacks( $sessionid = false ) {
|
77 |
-
if ( $sessionid === false )
|
78 |
-
$sessionid = $_REQUEST['sessionid'];
|
79 |
-
$purchase_log = new WPSC_Purchase_Log( $sessionid, 'sessionid' );
|
80 |
-
|
81 |
-
if ( ! $purchase_log->exists() )
|
82 |
-
return;
|
83 |
-
|
84 |
-
$this->set_purchase_log( $purchase_log );
|
85 |
-
}
|
86 |
-
|
87 |
-
public function callback_ipn() {
|
88 |
-
$ipn = new PHP_Merchant_Paypal_IPN( false, (bool) $this->setting->get( 'sandbox_mode', false ) );
|
89 |
-
|
90 |
-
if ( $ipn->is_verified() ) {
|
91 |
-
$sessionid = $ipn->get( 'invoice' );
|
92 |
-
$this->set_purchase_log_for_callbacks( $sessionid );
|
93 |
-
|
94 |
-
if ( $ipn->is_payment_denied() ) {
|
95 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::PAYMENT_DECLINED );
|
96 |
-
} elseif ( $ipn->is_payment_refunded() ) {
|
97 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUNDED );
|
98 |
-
} elseif ( $ipn->is_payment_completed() ) {
|
99 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
100 |
-
} elseif ( $ipn->is_payment_pending() ) {
|
101 |
-
if ( $ipn->is_payment_refund_pending() )
|
102 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::REFUND_PENDING );
|
103 |
-
else
|
104 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
105 |
-
}
|
106 |
-
|
107 |
-
$this->purchase_log->save();
|
108 |
-
transaction_results( $sessionid, false );
|
109 |
-
}
|
110 |
-
|
111 |
-
exit;
|
112 |
-
}
|
113 |
-
|
114 |
-
public function callback_confirm_transaction() {
|
115 |
-
if ( ! isset( $_REQUEST['sessionid'] ) || ! isset( $_REQUEST['token'] ) || ! isset( $_REQUEST['PayerID'] ) )
|
116 |
-
return;
|
117 |
-
|
118 |
-
$this->set_purchase_log_for_callbacks();
|
119 |
-
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_confirm_transaction_page' ) );
|
120 |
-
}
|
121 |
-
|
122 |
-
public function callback_display_paypal_error() {
|
123 |
-
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_paypal_error_page' ) );
|
124 |
-
}
|
125 |
-
|
126 |
-
public function callback_display_generic_error() {
|
127 |
-
add_filter( 'wpsc_get_transaction_html_output', array( $this, 'filter_generic_error_page' ) );
|
128 |
-
}
|
129 |
-
|
130 |
-
public function callback_process_confirmed_payment() {
|
131 |
-
$args = array_map( 'urldecode', $_GET );
|
132 |
-
extract( $args, EXTR_SKIP );
|
133 |
-
if ( ! isset( $sessionid ) || ! isset( $token ) || ! isset( $PayerID ) )
|
134 |
-
return;
|
135 |
-
|
136 |
-
$this->set_purchase_log_for_callbacks();
|
137 |
-
|
138 |
-
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
139 |
-
$options = array(
|
140 |
-
'token' => $token,
|
141 |
-
'payer_id' => $PayerID,
|
142 |
-
'invoice' => $this->purchase_log->get( 'sessionid' ),
|
143 |
-
);
|
144 |
-
$options += $this->checkout_data->get_gateway_data();
|
145 |
-
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
146 |
-
|
147 |
-
if ( $this->setting->get( 'ipn', false ) )
|
148 |
-
$options['notify_url'] = $this->get_notify_url();
|
149 |
-
|
150 |
-
$response = $this->gateway->purchase( $options );
|
151 |
-
$location = remove_query_arg( 'payment_gateway_callback' );
|
152 |
-
|
153 |
-
if ( $response->has_errors() ) {
|
154 |
-
wpsc_update_customer_meta( 'paypal_express_checkout_errors', $response->get_errors() );
|
155 |
-
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_paypal_error' ) );
|
156 |
-
} elseif ( $response->is_payment_completed() || $response->is_payment_pending() ) {
|
157 |
-
$location = remove_query_arg( 'payment_gateway' );
|
158 |
-
|
159 |
-
if ( $response->is_payment_completed() )
|
160 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT );
|
161 |
-
else
|
162 |
-
$this->purchase_log->set( 'processed', WPSC_Purchase_Log::ORDER_RECEIVED );
|
163 |
-
|
164 |
-
$this->purchase_log->set( 'transactid', $response->get( 'transaction_id' ) )
|
165 |
-
->set( 'date', time() )
|
166 |
-
->save();
|
167 |
-
} else {
|
168 |
-
$location = add_query_arg( array( 'payment_gateway_callback' => 'display_generic_error' ) );
|
169 |
-
}
|
170 |
-
|
171 |
-
wp_redirect( $location );
|
172 |
-
exit;
|
173 |
-
}
|
174 |
-
|
175 |
-
public function filter_paypal_error_page() {
|
176 |
-
$errors = wpsc_get_customer_meta( 'paypal_express_checkout_errors' );
|
177 |
-
ob_start();
|
178 |
-
?>
|
179 |
-
<p>
|
180 |
-
<?php _e( 'Sorry, your transaction could not be processed by Paypal. Please contact the site administrator. The following errors are returned:' ); ?>
|
181 |
-
</p>
|
182 |
-
<ul>
|
183 |
-
<?php foreach ( $errors as $error ): ?>
|
184 |
-
<li><?php echo esc_html( $error['details'] ) ?> (<?php echo esc_html( $error['code'] ); ?>)</li>
|
185 |
-
<?php endforeach; ?>
|
186 |
-
</ul>
|
187 |
-
<p><a href="<?php echo esc_attr( get_option( 'shopping_cart_url' ) ); ?>"><?php _e( 'Click here to go back to the checkout page.') ?></a></p>
|
188 |
-
<?php
|
189 |
-
$output = apply_filters( 'wpsc_paypal_express_checkout_gateway_error_message', ob_get_clean(), $errors );
|
190 |
-
return $output;
|
191 |
-
}
|
192 |
-
|
193 |
-
public function filter_generic_error_page() {
|
194 |
-
ob_start();
|
195 |
-
?>
|
196 |
-
<p><?php _e( 'Sorry, but your transaction could not be processed by Paypal for some reason. Please contact the site administrator.' ); ?></p>
|
197 |
-
<p><a href="<?php echo esc_attr( get_option( 'shopping_cart_url' ) ); ?>"><?php _e( 'Click here to go back to the checkout page.') ?></a></p>
|
198 |
-
<?php
|
199 |
-
$output = apply_filters( 'wpsc_paypal_express_checkout_generic_error_message', ob_get_clean() );
|
200 |
-
return $output;
|
201 |
-
}
|
202 |
-
|
203 |
-
public function filter_confirm_transaction_page() {
|
204 |
-
ob_start();
|
205 |
-
?>
|
206 |
-
<table width='400' class='paypal_express_form'>
|
207 |
-
<tr>
|
208 |
-
<td align='left' class='firstcol'><strong><?php _e( 'Order Total:', 'wpsc' ); ?></strong></td>
|
209 |
-
<td align='left'><?php echo wpsc_currency_display( $this->purchase_log->get( 'totalprice' ) ); ?></td>
|
210 |
-
</tr>
|
211 |
-
<tr>
|
212 |
-
<td align='left' colspan='2'><strong><?php _e( 'Shipping Details:', 'wpsc' ); ?></strong></td>
|
213 |
-
</tr>
|
214 |
-
<tr>
|
215 |
-
<td align='left' class='firstcol'>
|
216 |
-
<?php echo __('Address:', 'wpsc' ); ?>
|
217 |
-
</td>
|
218 |
-
<td align='left'>
|
219 |
-
<?php echo esc_html( $this->checkout_data->get( 'shippingaddress' ) ); ?>
|
220 |
-
</td>
|
221 |
-
</tr>
|
222 |
-
<tr>
|
223 |
-
<td align='left' class='firstcol'>
|
224 |
-
<?php echo __('City:', 'wpsc' ); ?>
|
225 |
-
</td>
|
226 |
-
<td align='left'><?php echo esc_html( $this->checkout_data->get( 'shippingcity' ) ); ?></td>
|
227 |
-
</tr>
|
228 |
-
<tr>
|
229 |
-
<td align='left' class='firstcol'>
|
230 |
-
<?php echo __('State:', 'wpsc' ); ?>
|
231 |
-
</td>
|
232 |
-
<td align='left'>
|
233 |
-
<?php echo esc_html( wpsc_get_region( $this->checkout_data->get( 'shippingstate' ) ) ); ?>
|
234 |
-
</td>
|
235 |
-
</tr>
|
236 |
-
<tr>
|
237 |
-
<td align='left' class='firstcol'>
|
238 |
-
<?php echo __('Postal code:', 'wpsc' ); ?>
|
239 |
-
</td>
|
240 |
-
<td align='left'><?php echo esc_html( $this->checkout_data->get( 'shippingpostcode' ) ); ?></td>
|
241 |
-
</tr>
|
242 |
-
<tr>
|
243 |
-
<td align='left' class='firstcol'>
|
244 |
-
<?php echo __('Country:', 'wpsc' ); ?></td>
|
245 |
-
<td align='left'><?php echo esc_html( wpsc_get_country( $this->checkout_data->get( 'shippingcountry' ) ) ); ?></td>
|
246 |
-
</tr>
|
247 |
-
<tr>
|
248 |
-
<td colspan='2'>
|
249 |
-
<form action="<?php echo remove_query_arg( array( 'payment_gateway', 'payment_gateway_callback' ) ); ?>" method='post'>
|
250 |
-
<input type='hidden' name='payment_gateway' value='paypal-express-checkout' />
|
251 |
-
<input type='hidden' name='payment_gateway_callback' value='process_confirmed_payment' />
|
252 |
-
<p><input name='action' type='submit' value='<?php _e( 'Confirm Payment', 'wpsc' ); ?>' /></p>
|
253 |
-
</form>
|
254 |
-
</td>
|
255 |
-
</tr>
|
256 |
-
</table>
|
257 |
-
<?php
|
258 |
-
$output = apply_filters( 'wpsc_confirm_payment_message', ob_get_clean(), $this->purchase_log );
|
259 |
-
return $output;
|
260 |
-
}
|
261 |
-
|
262 |
-
public function setup_form() {
|
263 |
-
$paypal_currency = $this->get_currency_code();
|
264 |
-
?>
|
265 |
-
<tr>
|
266 |
-
<td>
|
267 |
-
<label for="wpsc-paypal-express-api-username"><?php _e( 'API Username', 'wpsc' ); ?></label>
|
268 |
-
</td>
|
269 |
-
<td>
|
270 |
-
<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" />
|
271 |
-
</td>
|
272 |
-
</tr>
|
273 |
-
<tr>
|
274 |
-
<td>
|
275 |
-
<label for="wpsc-paypal-express-api-password"><?php _e( 'API Password', 'wpsc' ); ?></label>
|
276 |
-
</td>
|
277 |
-
<td>
|
278 |
-
<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" />
|
279 |
-
</td>
|
280 |
-
</tr>
|
281 |
-
<tr>
|
282 |
-
<td>
|
283 |
-
<label for="wpsc-paypal-express-api-signature"><?php _e( 'API Signature', 'wpsc' ); ?></label>
|
284 |
-
</td>
|
285 |
-
<td>
|
286 |
-
<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" />
|
287 |
-
</td>
|
288 |
-
</tr>
|
289 |
-
<tr>
|
290 |
-
<td>
|
291 |
-
<label><?php _e( 'Sandbox Mode', 'wpsc' ); ?></label>
|
292 |
-
</td>
|
293 |
-
<td>
|
294 |
-
<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>
|
295 |
-
<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>
|
296 |
-
</td>
|
297 |
-
</tr>
|
298 |
-
<tr>
|
299 |
-
<td>
|
300 |
-
<label><?php _e( 'IPN', 'wpsc' ); ?></label>
|
301 |
-
</td>
|
302 |
-
<td>
|
303 |
-
<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>
|
304 |
-
<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>
|
305 |
-
</td>
|
306 |
-
</tr>
|
307 |
-
<?php if ( ! $this->is_currency_supported() ): ?>
|
308 |
-
<tr>
|
309 |
-
<td colspan="2">
|
310 |
-
<h4><?php _e( 'Currency Conversion', 'wpsc' ); ?></h4>
|
311 |
-
</td>
|
312 |
-
</tr>
|
313 |
-
<tr>
|
314 |
-
<td colspan="2">
|
315 |
-
<p><?php _e( 'Your base currency is currently not accepted by PayPal. As a result, before a payment request is sent to Paypal, WP e-Commerce has to convert the amounts into one of Paypal supported currencies. Please select your preferred currency below.', 'wpsc' ); ?></p>
|
316 |
-
</td>
|
317 |
-
</tr>
|
318 |
-
<tr>
|
319 |
-
<td>
|
320 |
-
<label for "wpsc-paypal-express-currency"><?php _e( 'Paypal Currency', 'wpsc' ); ?></label>
|
321 |
-
</td>
|
322 |
-
<td>
|
323 |
-
<select name="<?php echo esc_attr( $this->setting->get_field_name( 'currency' ) ); ?>" id="wpsc-paypal-express-currency">
|
324 |
-
<?php foreach ($this->gateway->get_supported_currencies() as $currency): ?>
|
325 |
-
<option <?php selected( $currency, $paypal_currency ); ?> value="<?php echo esc_attr( $currency ); ?>"><?php echo esc_html( $currency ); ?></option>
|
326 |
-
<?php endforeach ?>
|
327 |
-
</select>
|
328 |
-
</td>
|
329 |
-
</tr>
|
330 |
-
<?php endif ?>
|
331 |
-
|
332 |
-
<?php
|
333 |
-
}
|
334 |
-
|
335 |
-
protected function is_currency_supported() {
|
336 |
-
$code = parent::get_currency_code();
|
337 |
-
return in_array( $code, $this->gateway->get_supported_currencies() );
|
338 |
-
}
|
339 |
-
|
340 |
-
public function get_currency_code() {
|
341 |
-
$code = parent::get_currency_code();
|
342 |
-
if ( ! in_array( $code, $this->gateway->get_supported_currencies() ) )
|
343 |
-
$code = $this->setting->get( 'currency', 'USD' );
|
344 |
-
return $code;
|
345 |
-
}
|
346 |
-
|
347 |
-
protected function convert( $amt ) {
|
348 |
-
if ( $this->is_currency_supported() )
|
349 |
-
return $amt;
|
350 |
-
|
351 |
-
return wpsc_convert_currency( $amt, parent::get_currency_code(), $this->get_currency_code() );
|
352 |
-
}
|
353 |
-
|
354 |
-
public function process() {
|
355 |
-
$total = $this->convert( $this->purchase_log->get( 'totalprice' ) );
|
356 |
-
$options = array(
|
357 |
-
'return_url' => $this->get_return_url(),
|
358 |
-
'invoice' => $this->purchase_log->get( 'sessionid' ),
|
359 |
-
);
|
360 |
-
$options += $this->checkout_data->get_gateway_data();
|
361 |
-
$options += $this->purchase_log->get_gateway_data( parent::get_currency_code(), $this->get_currency_code() );
|
362 |
-
|
363 |
-
if ( $this->setting->get( 'ipn', false ) )
|
364 |
-
$options['notify_url'] = $this->get_notify_url();
|
365 |
-
|
366 |
-
$response = $this->gateway->setup_purchase( $options );
|
367 |
-
if ( $response->is_successful() ) {
|
368 |
-
$url = ( $this->setting->get( 'sandbox_mode' ) ? self::SANDBOX_URL : self::LIVE_URL ) . $response->get( 'token' );
|
369 |
-
wp_redirect( $url );
|
370 |
-
} else {
|
371 |
-
wpsc_update_customer_meta( 'paypal_express_checkout_errors', $response->get_errors() );
|
372 |
-
$url = add_query_arg( array(
|
373 |
-
'payment_gateway' => 'paypal-express-checkout',
|
374 |
-
'payment_gateway_callback' => 'display_paypal_error',
|
375 |
-
), $this->get_return_url() );
|
376 |
-
}
|
377 |
-
|
378 |
-
wp_redirect( $url );
|
379 |
-
exit;
|
380 |
-
}
|
381 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/README.md
DELETED
File without changes
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/exception.php
DELETED
@@ -1,37 +0,0 @@
|
|
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
DELETED
@@ -1,15 +0,0 @@
|
|
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
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class PHP_Merchant_HTTP_CURL extends PHP_Merchant_HTTP
|
4 |
-
{
|
5 |
-
protected function request( $url, $fields = '', $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 = '', $args = array() ) {
|
42 |
-
$args['method'] = 'POST';
|
43 |
-
return $this->request( $url, $fields, $args );
|
44 |
-
}
|
45 |
-
|
46 |
-
public function get( $url, $fields = '', $args = array() ) {
|
47 |
-
return $this->request( $url, $fields, $args );
|
48 |
-
}
|
49 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/http.php
DELETED
@@ -1,11 +0,0 @@
|
|
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
DELETED
@@ -1,130 +0,0 @@
|
|
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 |
-
/**
|
18 |
-
* These currencies don't have decimal points. Eg: You never see JPY1000.5
|
19 |
-
*
|
20 |
-
* @var array
|
21 |
-
* @access protected
|
22 |
-
*/
|
23 |
-
protected $currencies_without_fractions = array( 'JPY', 'HUF' );
|
24 |
-
|
25 |
-
/**
|
26 |
-
* Options are passed into the object constructor or payment action methods (purchase,
|
27 |
-
* authorize, capture void, credit, recurring). These options will eventually be used
|
28 |
-
* to generate HTTP requests to payment gateways.
|
29 |
-
*
|
30 |
-
* @var array
|
31 |
-
* @access protected
|
32 |
-
*/
|
33 |
-
protected $options = array(
|
34 |
-
'currency' => 'USD',
|
35 |
-
);
|
36 |
-
|
37 |
-
/**
|
38 |
-
* This is the object that handles sending HTTP requests. The default HTTP client is CURL,
|
39 |
-
* but you can always set a custom HTTP client object that inherits from PHP_Merchant_HTTP.
|
40 |
-
*
|
41 |
-
* @var PHP_Merchant_HTTP
|
42 |
-
* @access protected
|
43 |
-
*/
|
44 |
-
protected $http;
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Constructor of the payment gateway. Accepts an array of options.
|
48 |
-
*
|
49 |
-
* @param array $options
|
50 |
-
*/
|
51 |
-
public function __construct( $options = array() ) {
|
52 |
-
if ( ! array_key_exists( 'http_client', $options ) ) {
|
53 |
-
require_once( 'http-curl.php' );
|
54 |
-
$this->http = new PHP_Merchant_HTTP_CURL();
|
55 |
-
} else {
|
56 |
-
$this->http =& $options['http_client'];
|
57 |
-
unset( $options['http_client'] );
|
58 |
-
}
|
59 |
-
|
60 |
-
$this->set_options( $options );
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Format the amount according to the currency being used.
|
65 |
-
*
|
66 |
-
* @param float $amt Amount
|
67 |
-
* @param string $currency Defaults to the currency specified in defined $options
|
68 |
-
* @return string
|
69 |
-
*/
|
70 |
-
public function format( $amt, $currency = false ) {
|
71 |
-
if ( ! $currency )
|
72 |
-
$currency = $this->options['currency'];
|
73 |
-
|
74 |
-
$dec = in_array( $currency, $this->currencies_without_fractions ) ? 0 : 2;
|
75 |
-
return number_format( $amt, $dec );
|
76 |
-
}
|
77 |
-
|
78 |
-
public function purchase( $options = array() ) {
|
79 |
-
$this->requires( 'amount' );
|
80 |
-
}
|
81 |
-
|
82 |
-
public function authorize() {
|
83 |
-
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'authorize' );
|
84 |
-
}
|
85 |
-
|
86 |
-
public function capture() {
|
87 |
-
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'capture' );
|
88 |
-
}
|
89 |
-
|
90 |
-
public function void() {
|
91 |
-
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'void' );
|
92 |
-
}
|
93 |
-
|
94 |
-
public function credit() {
|
95 |
-
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'credit' );
|
96 |
-
}
|
97 |
-
|
98 |
-
public function recurring() {
|
99 |
-
throw new PHP_Merchant_Exception( PHPME_FEATURE_NOT_SUPPORTED, 'recurring' );
|
100 |
-
}
|
101 |
-
|
102 |
-
public function get_options() {
|
103 |
-
return $this->options;
|
104 |
-
}
|
105 |
-
|
106 |
-
public function set_options( $options ) {
|
107 |
-
$this->options = array_merge( $this->options, $options );
|
108 |
-
return $this;
|
109 |
-
}
|
110 |
-
|
111 |
-
public function get_option( $key ) {
|
112 |
-
return array_key_exists( $key, $this->options ) ? $this->options[$key] : null;
|
113 |
-
}
|
114 |
-
|
115 |
-
public function set_option( $key, $value ) {
|
116 |
-
$this->options[$key] = $value;
|
117 |
-
return $this;
|
118 |
-
}
|
119 |
-
|
120 |
-
protected function requires( $options ) {
|
121 |
-
$missing = array();
|
122 |
-
foreach ( (array) $options as $option ) {
|
123 |
-
if ( ! isset( $this->options[$option] ) )
|
124 |
-
$missing[] = $option;
|
125 |
-
}
|
126 |
-
|
127 |
-
if ( ! empty( $missing ) )
|
128 |
-
throw new PHP_Merchant_Exception( PHPME_REQUIRED_OPTION_UNDEFINED, implode( ', ', $missing ) );
|
129 |
-
}
|
130 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/common/response.php
DELETED
@@ -1,39 +0,0 @@
|
|
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
DELETED
@@ -1,79 +0,0 @@
|
|
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 |
-
return $request;
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
* For Digital Goods purchases, PayPal requires the PAYMENTREQUEST_n_ITEMAMT. This function sets the 'items' flag to required
|
34 |
-
* then calls @see parent::setup_purchase() to initiate an Express Checkout payment.
|
35 |
-
*
|
36 |
-
* @uses self::requires() to flag 'items' as required
|
37 |
-
* @uses parent::setup_purchase() to create and make the request.
|
38 |
-
* @return PHP_Merchant_Paypal_Express_Checkout_Response An object containing the details of PayPal's response to the request.
|
39 |
-
*/
|
40 |
-
public function setup_purchase( $options = array() ) {
|
41 |
-
return parent::setup_purchase( $options );
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* For Digital Goods purchases, PayPal requires the PAYMENTREQUEST_n_ITEMAMT. This function sets the 'items' flag to required
|
46 |
-
* then calls @see parent::setup_purchase() to complete the payment.
|
47 |
-
*
|
48 |
-
* @uses self::requires() to flag 'items' as required
|
49 |
-
* @uses parent::setup_purchase() to create and make the request.
|
50 |
-
* @return PHP_Merchant_Paypal_Express_Checkout_Response An object containing the details of PayPal's response to the request.
|
51 |
-
*/
|
52 |
-
public function purchase( $options = array() ) {
|
53 |
-
return parent::purchase( $options );
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
/**
|
58 |
-
* The Javascript to invoke the digital goods in context checkout process.
|
59 |
-
*
|
60 |
-
* No need to call this function manually, required scripts are automatically printed with @see print_buy_buttion().
|
61 |
-
* If you do print this script manually, print it after the button in the DOM to ensure the
|
62 |
-
* click event is properly hooked.
|
63 |
-
*/
|
64 |
-
public function get_script( $args = array() ){
|
65 |
-
|
66 |
-
if( empty( $args['element_id'] ) )
|
67 |
-
$args['element_id'] = 'paypal-submit';
|
68 |
-
|
69 |
-
$dg_script = '<script src ="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>'
|
70 |
-
. '<script>'
|
71 |
-
. 'var dg = new PAYPAL.apps.DGFlow({'
|
72 |
-
. 'trigger: "' . $args['element_id'] . '"' // the ID of the HTML element which calls setExpressCheckout
|
73 |
-
. '}); </script>';
|
74 |
-
|
75 |
-
return $dg_script;
|
76 |
-
}
|
77 |
-
|
78 |
-
|
79 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout-response.php
DELETED
@@ -1,123 +0,0 @@
|
|
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 |
-
'first_name' => 'FIRSTNAME',
|
74 |
-
'last_name' => 'LASTNAME',
|
75 |
-
'country' => 'COUNTRYCODE',
|
76 |
-
), 'Object' );
|
77 |
-
|
78 |
-
if ( isset( $p['SHIPTONAME'] ) )
|
79 |
-
$this->options['shipping_address'] = phpme_map( $p, array(
|
80 |
-
'name' => 'SHIPTONAME',
|
81 |
-
'street' => 'SHIPTOSTREET',
|
82 |
-
'street2' => 'SHIPTOSTREET2',
|
83 |
-
'city' => 'SHIPTOCITY',
|
84 |
-
'state' => 'SHIPTOSTATE',
|
85 |
-
'zip' => 'SHIPTOZIP',
|
86 |
-
'country_code' => 'SHIPTOCOUNTRYCODE',
|
87 |
-
'country' => 'SHIPTOCOUNTRYNAME',
|
88 |
-
'phone' => 'SHIPTOPHONENUM',
|
89 |
-
) );
|
90 |
-
}
|
91 |
-
|
92 |
-
public function is_checkout_not_initiated() {
|
93 |
-
return $this->get( 'checkout_status' ) == 'Not-Initiated';
|
94 |
-
}
|
95 |
-
|
96 |
-
public function is_checkout_failed() {
|
97 |
-
return $this->get( 'checkout_status' ) == 'Failed';
|
98 |
-
}
|
99 |
-
|
100 |
-
public function is_checkout_in_progress() {
|
101 |
-
return $this->get( 'checkout_status' ) == 'In-Progress';
|
102 |
-
}
|
103 |
-
|
104 |
-
public function is_checkout_completed() {
|
105 |
-
return $this->get( 'checkout_status' ) == 'Completed';
|
106 |
-
}
|
107 |
-
|
108 |
-
public function is_payment_completed() {
|
109 |
-
return in_array( $this->get( 'payment_status' ), array( 'Completed', 'Processed' ) );
|
110 |
-
}
|
111 |
-
|
112 |
-
public function is_payment_pending() {
|
113 |
-
return $this->get( 'payment_status' ) == 'Pending';
|
114 |
-
}
|
115 |
-
|
116 |
-
public function is_payment_refunded() {
|
117 |
-
return $this->get( 'payment_status' ) == 'Refunded';
|
118 |
-
}
|
119 |
-
|
120 |
-
public function is_payment_denied() {
|
121 |
-
return $this->get( 'payment_status' ) == 'Denied';
|
122 |
-
}
|
123 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php
DELETED
@@ -1,155 +0,0 @@
|
|
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 |
-
protected function add_payment( $action ) {
|
12 |
-
$request = array(
|
13 |
-
'PAYMENTREQUEST_0_AMT' => $this->format( $this->options['amount'] ),
|
14 |
-
'PAYMENTREQUEST_0_CURRENCYCODE' => $this->options['currency'],
|
15 |
-
'PAYMENTREQUEST_0_PAYMENTACTION' => $action,
|
16 |
-
);
|
17 |
-
|
18 |
-
foreach ( array( 'subtotal', 'shipping', 'handling', 'tax' ) as $key ) {
|
19 |
-
if ( isset( $this->options[$key] ) )
|
20 |
-
$this->options[$key] = $this->format( $this->options[$key] );
|
21 |
-
}
|
22 |
-
|
23 |
-
$request += phpme_map( $this->options, array(
|
24 |
-
'PAYMENTREQUEST_0_ITEMAMT' => 'subtotal',
|
25 |
-
'PAYMENTREQUEST_0_SHIPPINGAMT' => 'shipping',
|
26 |
-
'PAYMENTREQUEST_0_HANDLINGAMT' => 'handling',
|
27 |
-
'PAYMENTREQUEST_0_TAXAMT' => 'tax',
|
28 |
-
'PAYMENTREQUEST_0_DESC' => 'description',
|
29 |
-
'PAYMENTREQUEST_0_INVNUM' => 'invoice',
|
30 |
-
'PAYMENTREQUEST_0_NOTIFYURL' => 'notify_url',
|
31 |
-
) );
|
32 |
-
|
33 |
-
$subtotal = 0;
|
34 |
-
|
35 |
-
$i = 0;
|
36 |
-
foreach ( $this->options['items'] as $item ) {
|
37 |
-
$item_optionals = array(
|
38 |
-
'description' => "L_PAYMENTREQUEST_0_DESC{$i}",
|
39 |
-
'tax' => "L_PAYMENTREQUEST_0_TAXAMT{$i}",
|
40 |
-
'url' => "L_PAYMENTREQUEST_0_ITEMURL{$i}",
|
41 |
-
);
|
42 |
-
|
43 |
-
$item['amount'] = $this->format( $item['amount'] );
|
44 |
-
$request += phpme_map( $item, array(
|
45 |
-
"L_PAYMENTREQUEST_0_NAME{$i}" => 'name',
|
46 |
-
"L_PAYMENTREQUEST_0_AMT{$i}" => 'amount',
|
47 |
-
"L_PAYMENTREQUEST_0_QTY{$i}" => 'quantity',
|
48 |
-
) );
|
49 |
-
|
50 |
-
foreach ( $item_optionals as $key => $param ) {
|
51 |
-
if ( ! empty( $this->options['items'][$i][$key] ) )
|
52 |
-
if ( $key == 'tax' )
|
53 |
-
$request[$param] = $this->format( $this->options['items'][$i][$key] );
|
54 |
-
else
|
55 |
-
$request[$param] = $this->options['items'][$i][$key];
|
56 |
-
}
|
57 |
-
|
58 |
-
$i ++;
|
59 |
-
}
|
60 |
-
|
61 |
-
return $request;
|
62 |
-
}
|
63 |
-
|
64 |
-
protected function add_address() {
|
65 |
-
$map = array(
|
66 |
-
'name' => 'PAYMENTREQUEST_0_SHIPTONAME',
|
67 |
-
'street' => 'PAYMENTREQUEST_0_SHIPTOSTREET',
|
68 |
-
'street2' => 'PAYMENTREQUEST_0_SHIPTOSTREET2',
|
69 |
-
'city' => 'PAYMENTREQUEST_0_SHIPTOCITY',
|
70 |
-
'state' => 'PAYMENTREQUEST_0_SHIPTOSTATE',
|
71 |
-
'zip' => 'PAYMENTREQUEST_0_SHIPTOZIP',
|
72 |
-
'country' => 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE',
|
73 |
-
'phone' => 'PAYMENTREQUEST_0_SHIPTOPHONENUM',
|
74 |
-
);
|
75 |
-
|
76 |
-
$request = array();
|
77 |
-
|
78 |
-
foreach ( $map as $key => $param ) {
|
79 |
-
if ( ! empty( $this->options['shipping_address'][$key] ) )
|
80 |
-
$request[$param] = $this->options['shipping_address'][$key];
|
81 |
-
}
|
82 |
-
|
83 |
-
return $request;
|
84 |
-
}
|
85 |
-
|
86 |
-
protected function build_checkout_request( $action, $options = array() ) {
|
87 |
-
$request = array();
|
88 |
-
|
89 |
-
if ( isset( $this->options['return_url'] ) )
|
90 |
-
$request['RETURNURL'] = $this->options['return_url'];
|
91 |
-
|
92 |
-
if ( isset( $this->options['cancel_url'] ) )
|
93 |
-
$request['CANCELURL'] = $this->options['cancel_url'];
|
94 |
-
|
95 |
-
$request += phpme_map( $this->options, array(
|
96 |
-
'MAXAMT' => 'max_amount',
|
97 |
-
'ALLOWNOTE' => 'allow_note',
|
98 |
-
'ADDROVERRIDE' => 'address_override',
|
99 |
-
'TOKEN' => 'token',
|
100 |
-
'PAYERID' => 'payer_id',
|
101 |
-
) );
|
102 |
-
|
103 |
-
if ( ! empty( $this->options['shipping'] ) && ! empty( $this->options['address_override'] ) )
|
104 |
-
$request += $this->add_address();
|
105 |
-
|
106 |
-
$request += $this->add_payment( $action );
|
107 |
-
return $request;
|
108 |
-
}
|
109 |
-
|
110 |
-
public function setup_purchase( $options = array() ) {
|
111 |
-
$this->options = array_merge( $this->options, $options );
|
112 |
-
$this->requires( 'amount', 'return_url', 'cancel_url' );
|
113 |
-
$request = $this->build_checkout_request( 'Sale', $options );
|
114 |
-
|
115 |
-
$response_str = $this->commit( 'SetExpressCheckout', $request );
|
116 |
-
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
117 |
-
}
|
118 |
-
|
119 |
-
public function build_get_details_request( $token ) {
|
120 |
-
return array(
|
121 |
-
'TOKEN' => $token,
|
122 |
-
);
|
123 |
-
}
|
124 |
-
|
125 |
-
public function get_details_for( $token ) {
|
126 |
-
$request = $this->build_get_details_request( $token );
|
127 |
-
$response_str = $this->commit( 'GetExpressCheckoutDetails', $request );
|
128 |
-
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
129 |
-
}
|
130 |
-
|
131 |
-
public function purchase( $options = array() ) {
|
132 |
-
$this->options = array_merge( $this->options, $options );
|
133 |
-
$this->requires( 'amount', 'token', 'payer_id' );
|
134 |
-
$request = $this->build_checkout_request( 'Sale', $options );
|
135 |
-
|
136 |
-
$response_str = $this->commit( 'DoExpressCheckoutPayment', $request );
|
137 |
-
return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str );
|
138 |
-
}
|
139 |
-
|
140 |
-
public function authorize() {
|
141 |
-
|
142 |
-
}
|
143 |
-
|
144 |
-
public function capture() {
|
145 |
-
|
146 |
-
}
|
147 |
-
|
148 |
-
public function void() {
|
149 |
-
|
150 |
-
}
|
151 |
-
|
152 |
-
public function credit() {
|
153 |
-
|
154 |
-
}
|
155 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-ipn.php
DELETED
@@ -1,138 +0,0 @@
|
|
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( realpath( '../' ) . '/common/http-curl.php' );
|
19 |
-
$this->http = new PHP_Merchant_HTTP_CURL();
|
20 |
-
}
|
21 |
-
|
22 |
-
if ( $data === false )
|
23 |
-
$data = $_POST;
|
24 |
-
$this->params = $data;
|
25 |
-
|
26 |
-
$this->url = $test ? self::SANDBOX_URL : self::LIVE_URL;
|
27 |
-
}
|
28 |
-
|
29 |
-
public function is_verified() {
|
30 |
-
if ( is_null( $this->verified ) ) {
|
31 |
-
$verifying_data = array( 'cmd' => '_notify-validate' );
|
32 |
-
$verifying_data += $this->params;
|
33 |
-
|
34 |
-
$verifying_response = $this->http->post( $this->url, $verifying_data );
|
35 |
-
|
36 |
-
if ( $verifying_response == 'VERIFIED' ) {
|
37 |
-
$this->verified = true;
|
38 |
-
|
39 |
-
/*
|
40 |
-
|
41 |
-
There's some confusing stuff regarding payment information:
|
42 |
-
mc_gross = total amount = total tax + item subtotal + total shipping
|
43 |
-
mc_gross_$i = item amount * quantity + item shipping
|
44 |
-
|
45 |
-
See: https://www.x.com/developers/paypal/forums/ipn/pdt/mcgross-does-not-include-tax-right
|
46 |
-
|
47 |
-
IPN only returns the item gross amount, so the single item amount will need to be
|
48 |
-
calculated so that the $this->data array is consistent with other Paypal Response classes.
|
49 |
-
|
50 |
-
*/
|
51 |
-
$this->data = phpme_map( $this->params, array(
|
52 |
-
'transaction_id' => 'txn_id',
|
53 |
-
'transaction_type' => 'txn_type',
|
54 |
-
'handling' => 'mc_handling',
|
55 |
-
'shipping' => 'mc_shipping',
|
56 |
-
'exchange_rate' => 'exchange_rate',
|
57 |
-
'invoice' => 'invoice',
|
58 |
-
'currency' => 'mc_currency',
|
59 |
-
'fee' => 'mc_fee',
|
60 |
-
'total' => 'mc_gross',
|
61 |
-
'amount' => 'mc_gross',
|
62 |
-
'payment_status' => 'payment_status',
|
63 |
-
'tax' => 'tax',
|
64 |
-
) );
|
65 |
-
|
66 |
-
// Strangely, Canceled_Reversal in IPN response is actually Canceled-Reversal in normal Paypal Express responses.
|
67 |
-
// Need to change the underscore to hyphen to maintain consistency
|
68 |
-
$this->data['payment_status'] = str_replace( '_', '-', $this->data['payment_status'] );
|
69 |
-
|
70 |
-
$i = 1;
|
71 |
-
$this->data['items'] = array();
|
72 |
-
while ( isset( $this->params["item_name{$i}"] ) ) {
|
73 |
-
$item = phpme_map( $this->params, array(
|
74 |
-
'name' => "item_name{$i}",
|
75 |
-
'quantity' => "quantity{$i}",
|
76 |
-
) );
|
77 |
-
|
78 |
-
$item['shipping'] = $shipping = isset( $this->params["mc_shipping{$i}"] ) ? $this->params["mc_shipping{$i}"] : 0;
|
79 |
-
$item['handling'] = $handling = isset( $this->params["mc_handling{$i}"] ) ? $this->params["mc_handling{$i}"] : 0;
|
80 |
-
$item['amount'] = ( $this->params["mc_gross_{$i}"] - $shipping - $handling ) / $item['quantity'];
|
81 |
-
$this->data['items'][] = $item;
|
82 |
-
$i++;
|
83 |
-
}
|
84 |
-
|
85 |
-
$this->data['payer'] = phpme_map( $this->params, array(
|
86 |
-
'first_name' => 'first_name',
|
87 |
-
'last_name' => 'last_name',
|
88 |
-
'business_name' => 'payer_business_name',
|
89 |
-
'status' => 'payer_status',
|
90 |
-
'id' => 'payer_id',
|
91 |
-
'email' => 'payer_email',
|
92 |
-
) );
|
93 |
-
|
94 |
-
$this->data['address'] = phpme_map( $this->params, array(
|
95 |
-
'street' => 'address_street',
|
96 |
-
'zip' => 'address_zip',
|
97 |
-
'city' => 'address_city',
|
98 |
-
'state' => 'address_state',
|
99 |
-
'country' => 'address_country',
|
100 |
-
'country_code' => 'address_country_code',
|
101 |
-
'name' => 'address_name',
|
102 |
-
'status' => 'address_status',
|
103 |
-
'phone' => 'contact_phone',
|
104 |
-
) );
|
105 |
-
}
|
106 |
-
}
|
107 |
-
|
108 |
-
return $this->verified;
|
109 |
-
}
|
110 |
-
|
111 |
-
public function get( $item ) {
|
112 |
-
return isset( $this->data[$item] ) ? $this->data[$item] : null;
|
113 |
-
}
|
114 |
-
|
115 |
-
public function get_data() {
|
116 |
-
return $this->data;
|
117 |
-
}
|
118 |
-
|
119 |
-
public function is_payment_completed() {
|
120 |
-
return in_array( $this->get( 'payment_status' ), array( 'Completed', 'Processed' ) );
|
121 |
-
}
|
122 |
-
|
123 |
-
public function is_payment_pending() {
|
124 |
-
return $this->get( 'payment_status' ) == 'Pending';
|
125 |
-
}
|
126 |
-
|
127 |
-
public function is_payment_refunded() {
|
128 |
-
return in_array( $this->get( 'payment_status' ), array( 'Refunded', 'Reversed' ) );
|
129 |
-
}
|
130 |
-
|
131 |
-
public function is_payment_refund_pending() {
|
132 |
-
return $this->is_payment_pending() && isset( $this->params['reason_code'] ) && $this->params['reason_code'] == 'refund';
|
133 |
-
}
|
134 |
-
|
135 |
-
public function is_payment_denied() {
|
136 |
-
return $this->get( 'payment_status' ) == 'Denied';
|
137 |
-
}
|
138 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-response.php
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class PHP_Merchant_Paypal_Response extends PHP_Merchant_Response
|
4 |
-
{
|
5 |
-
protected $params = array();
|
6 |
-
|
7 |
-
public function __construct( $response_str ) {
|
8 |
-
parent::__construct( $response_str );
|
9 |
-
|
10 |
-
parse_str( $response_str, $params );
|
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 |
-
$this->options['datetime'] = $params['TIMESTAMP'];
|
17 |
-
|
18 |
-
$time = rtrim( $params['TIMESTAMP'], 'Z' ) . '+0000';
|
19 |
-
if ( ! $time = strptime( $time, '%FT%T%z' ) )
|
20 |
-
$time = strptime( $time, '%FT%T%Z' );
|
21 |
-
|
22 |
-
switch ( $params['ACK'] ) {
|
23 |
-
case 'Success':
|
24 |
-
case 'SuccessWithWarning':
|
25 |
-
$this->is_successful = true;
|
26 |
-
break;
|
27 |
-
|
28 |
-
case 'Failure':
|
29 |
-
case 'FailureWithWarning':
|
30 |
-
case 'Warning':
|
31 |
-
$this->is_successful = false;
|
32 |
-
break;
|
33 |
-
}
|
34 |
-
|
35 |
-
if ( isset( $params['TOKEN'] ) )
|
36 |
-
$this->options['token'] = $params['TOKEN'];
|
37 |
-
|
38 |
-
$this->options['correlation_id'] = $params['CORRELATIONID'];
|
39 |
-
$this->options['version'] = $params['VERSION'];
|
40 |
-
$this->options['build'] = $params['BUILD'];
|
41 |
-
|
42 |
-
$i = 0;
|
43 |
-
while ( array_key_exists( "L_ERRORCODE{$i}", $params ) ) {
|
44 |
-
$error = array(
|
45 |
-
'code' => $params["L_ERRORCODE{$i}"],
|
46 |
-
'message' => $params["L_SHORTMESSAGE{$i}"],
|
47 |
-
'details' => $params["L_LONGMESSAGE{$i}"],
|
48 |
-
);
|
49 |
-
|
50 |
-
$this->errors[] = $error;
|
51 |
-
$i++;
|
52 |
-
}
|
53 |
-
|
54 |
-
if ( is_array( $time ) ) {
|
55 |
-
extract( $time, EXTR_SKIP );
|
56 |
-
$this->options['timestamp'] = mktime( $tm_hour, $tm_min, $tm_sec, 1 + $tm_mon, $tm_mday, 1900 + $tm_year );
|
57 |
-
} else {
|
58 |
-
$this->options['timestamp'] = time();
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
public function get_params() {
|
63 |
-
return $this->params;
|
64 |
-
}
|
65 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal.php
DELETED
@@ -1,85 +0,0 @@
|
|
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 = '74.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 |
-
return $this->request;
|
63 |
-
}
|
64 |
-
|
65 |
-
public static function get_supported_currencies() {
|
66 |
-
return self::$supported_currencies;
|
67 |
-
}
|
68 |
-
|
69 |
-
public function __construct( $options = array() ) {
|
70 |
-
parent::__construct( $options );
|
71 |
-
}
|
72 |
-
|
73 |
-
public function get_url() {
|
74 |
-
return empty( $this->options['test'] ) ? self::LIVE_URL : self::SANDBOX_URL;
|
75 |
-
}
|
76 |
-
|
77 |
-
public function is_currency_supported( $currency ) {
|
78 |
-
return in_array( $currency, self::$supported_currencies );
|
79 |
-
}
|
80 |
-
|
81 |
-
protected function commit( $action, $request = array() ) {
|
82 |
-
$this->build_request( $action, $request );
|
83 |
-
return $this->http->post( $this->get_url(), $this->request );
|
84 |
-
}
|
85 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/http-curl.php
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once( PHP_MERCHANT_PATH . '/common/http-curl.php' );
|
4 |
-
|
5 |
-
class PHP_Merchant_HTTP_CURL_Test extends UnitTestCase
|
6 |
-
{
|
7 |
-
public function __construct() {
|
8 |
-
parent::__construct( 'PHP_Merchant_HTTP_CURL unit tests' );
|
9 |
-
}
|
10 |
-
|
11 |
-
public function test_array_is_parsed_correctly_into_query_string() {
|
12 |
-
$http = new PHP_Merchant_HTTP_CURL_Bogus();
|
13 |
-
|
14 |
-
$args = array(
|
15 |
-
'key_1' => 'key 1 value',
|
16 |
-
'key_2' => 'key&2%value='
|
17 |
-
);
|
18 |
-
|
19 |
-
$query_string = 'key_1=key+1+value&key_2=key%262%25value%3D';
|
20 |
-
|
21 |
-
$this->assertEqual( $http->parse_args( $args ), $query_string );
|
22 |
-
}
|
23 |
-
}
|
24 |
-
|
25 |
-
class PHP_Merchant_HTTP_CURL_Bogus extends PHP_Merchant_HTTP_CURL
|
26 |
-
{
|
27 |
-
public function parse_args( $args ) {
|
28 |
-
return parent::parse_args( $args );
|
29 |
-
}
|
30 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/php-merchant.php
DELETED
@@ -1,170 +0,0 @@
|
|
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 |
-
|
149 |
-
class PHP_Merchant_Bogus extends PHP_Merchant {
|
150 |
-
public function requires( $options ) {
|
151 |
-
parent::requires( $options );
|
152 |
-
}
|
153 |
-
}
|
154 |
-
|
155 |
-
class PHP_Merchant_Bogus_Full_Features extends PHP_Merchant {
|
156 |
-
public function authorize() {
|
157 |
-
}
|
158 |
-
|
159 |
-
public function capture() {
|
160 |
-
}
|
161 |
-
|
162 |
-
public function void() {
|
163 |
-
}
|
164 |
-
|
165 |
-
public function credit() {
|
166 |
-
}
|
167 |
-
|
168 |
-
public function recurring() {
|
169 |
-
}
|
170 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/common/test-accounts.php
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
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 |
-
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-express-checkout.php
DELETED
@@ -1,543 +0,0 @@
|
|
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 e-Commerce 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 e-Commerce 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' => '74.0',
|
103 |
-
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
104 |
-
'METHOD' => 'SetExpressCheckout',
|
105 |
-
'RETURNURL' => 'http://example.com/return',
|
106 |
-
'CANCELURL' => 'http://example.com/cancel',
|
107 |
-
'ADDROVERRIDE' => 1,
|
108 |
-
|
109 |
-
// Shipping details
|
110 |
-
'PAYMENTREQUEST_0_SHIPTONAME' => 'Gary Cao',
|
111 |
-
'PAYMENTREQUEST_0_SHIPTOSTREET' => '1 Infinite Loop',
|
112 |
-
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Apple Headquarter',
|
113 |
-
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Cupertino',
|
114 |
-
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'CA',
|
115 |
-
'PAYMENTREQUEST_0_SHIPTOZIP' => '95014',
|
116 |
-
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
|
117 |
-
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '(877) 412-7753',
|
118 |
-
|
119 |
-
// Payment info
|
120 |
-
'PAYMENTREQUEST_0_AMT' => '15,337',
|
121 |
-
'PAYMENTREQUEST_0_CURRENCYCODE' => 'JPY',
|
122 |
-
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
|
123 |
-
'PAYMENTREQUEST_0_ITEMAMT' => '13,700',
|
124 |
-
'PAYMENTREQUEST_0_SHIPPINGAMT' => '1,500',
|
125 |
-
'PAYMENTREQUEST_0_TAXAMT' => '137',
|
126 |
-
'PAYMENTREQUEST_0_DESC' => 'Order for example.com',
|
127 |
-
'PAYMENTREQUEST_0_INVNUM' => 'E84A90G94',
|
128 |
-
'PAYMENTREQUEST_0_NOTIFYURL' => 'http://example.com/ipn',
|
129 |
-
|
130 |
-
// Items
|
131 |
-
'L_PAYMENTREQUEST_0_NAME0' => 'Gold Cart Plugin',
|
132 |
-
'L_PAYMENTREQUEST_0_AMT0' => '4,000',
|
133 |
-
'L_PAYMENTREQUEST_0_QTY0' => 1,
|
134 |
-
'L_PAYMENTREQUEST_0_DESC0' => 'Gold Cart extends your WP e-Commerce store by enabling additional features and functionality, including views, galleries, store search and payment gateways.',
|
135 |
-
'L_PAYMENTREQUEST_0_TAXAMT0' => '40',
|
136 |
-
'L_PAYMENTREQUEST_0_ITEMURL0' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
137 |
-
|
138 |
-
'L_PAYMENTREQUEST_0_NAME1' => 'Member Access Plugin',
|
139 |
-
'L_PAYMENTREQUEST_0_AMT1' => '5,000',
|
140 |
-
'L_PAYMENTREQUEST_0_QTY1' => 1,
|
141 |
-
'L_PAYMENTREQUEST_0_DESC1' => 'Create pay to view subscription sites',
|
142 |
-
'L_PAYMENTREQUEST_0_TAXAMT1' => '50',
|
143 |
-
'L_PAYMENTREQUEST_0_ITEMURL1' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
144 |
-
|
145 |
-
'L_PAYMENTREQUEST_0_NAME2' => 'Amazon S3',
|
146 |
-
'L_PAYMENTREQUEST_0_AMT2' => '4,700',
|
147 |
-
'L_PAYMENTREQUEST_0_QTY2' => 1,
|
148 |
-
'L_PAYMENTREQUEST_0_DESC2' => 'This Plugin allows downloadable products that you have for sale on your WP e-Commerce site to be hosted within Amazon S3.',
|
149 |
-
'L_PAYMENTREQUEST_0_TAXAMT2' => '47',
|
150 |
-
'L_PAYMENTREQUEST_0_ITEMURL2' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
151 |
-
);
|
152 |
-
|
153 |
-
$this->bogus->http->expectOnce( 'post', array( $url, $args ) );
|
154 |
-
try {
|
155 |
-
$this->bogus->setup_purchase( $this->setup_purchase_options );
|
156 |
-
} catch ( PHP_Merchant_Exception $e ) {
|
157 |
-
|
158 |
-
}
|
159 |
-
}
|
160 |
-
|
161 |
-
public function test_correct_parameters_are_sent_when_do_express_checkout_payment() {
|
162 |
-
// set up expectations for mock objects
|
163 |
-
$url = 'https://api-3t.paypal.com/nvp';
|
164 |
-
|
165 |
-
// how the request parameters should look like
|
166 |
-
$args = array(
|
167 |
-
// API info
|
168 |
-
'USER' => 'sdk-three_api1.sdk.com',
|
169 |
-
'PWD' => 'QFZCWN5HZM8VBG7Q',
|
170 |
-
'VERSION' => '74.0',
|
171 |
-
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
172 |
-
'METHOD' => 'DoExpressCheckoutPayment',
|
173 |
-
'RETURNURL' => 'http://example.com/return',
|
174 |
-
'CANCELURL' => 'http://example.com/cancel',
|
175 |
-
'ADDROVERRIDE' => 1,
|
176 |
-
|
177 |
-
// Payer ID
|
178 |
-
'TOKEN' => 'EC-2JJ0893331633543K',
|
179 |
-
'PAYERID' => 'BC798KQ2QU22W',
|
180 |
-
|
181 |
-
// Shipping details
|
182 |
-
'PAYMENTREQUEST_0_SHIPTONAME' => 'Gary Cao',
|
183 |
-
'PAYMENTREQUEST_0_SHIPTOSTREET' => '1 Infinite Loop',
|
184 |
-
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Apple Headquarter',
|
185 |
-
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Cupertino',
|
186 |
-
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'CA',
|
187 |
-
'PAYMENTREQUEST_0_SHIPTOZIP' => '95014',
|
188 |
-
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
|
189 |
-
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '(877) 412-7753',
|
190 |
-
|
191 |
-
// Payment info
|
192 |
-
'PAYMENTREQUEST_0_AMT' => '15,337',
|
193 |
-
'PAYMENTREQUEST_0_CURRENCYCODE' => 'JPY',
|
194 |
-
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
|
195 |
-
'PAYMENTREQUEST_0_ITEMAMT' => '13,700',
|
196 |
-
'PAYMENTREQUEST_0_SHIPPINGAMT' => '1,500',
|
197 |
-
'PAYMENTREQUEST_0_TAXAMT' => '137',
|
198 |
-
'PAYMENTREQUEST_0_DESC' => 'Order for example.com',
|
199 |
-
'PAYMENTREQUEST_0_INVNUM' => 'E84A90G94',
|
200 |
-
'PAYMENTREQUEST_0_NOTIFYURL' => 'http://example.com/ipn',
|
201 |
-
|
202 |
-
// Items
|
203 |
-
'L_PAYMENTREQUEST_0_NAME0' => 'Gold Cart Plugin',
|
204 |
-
'L_PAYMENTREQUEST_0_AMT0' => '4,000',
|
205 |
-
'L_PAYMENTREQUEST_0_QTY0' => 1,
|
206 |
-
'L_PAYMENTREQUEST_0_DESC0' => 'Gold Cart extends your WP e-Commerce store by enabling additional features and functionality, including views, galleries, store search and payment gateways.',
|
207 |
-
'L_PAYMENTREQUEST_0_TAXAMT0' => '40',
|
208 |
-
'L_PAYMENTREQUEST_0_ITEMURL0' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
209 |
-
|
210 |
-
'L_PAYMENTREQUEST_0_NAME1' => 'Member Access Plugin',
|
211 |
-
'L_PAYMENTREQUEST_0_AMT1' => '5,000',
|
212 |
-
'L_PAYMENTREQUEST_0_QTY1' => 1,
|
213 |
-
'L_PAYMENTREQUEST_0_DESC1' => 'Create pay to view subscription sites',
|
214 |
-
'L_PAYMENTREQUEST_0_TAXAMT1' => '50',
|
215 |
-
'L_PAYMENTREQUEST_0_ITEMURL1' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
216 |
-
|
217 |
-
'L_PAYMENTREQUEST_0_NAME2' => 'Amazon S3',
|
218 |
-
'L_PAYMENTREQUEST_0_AMT2' => '4,700',
|
219 |
-
'L_PAYMENTREQUEST_0_QTY2' => 1,
|
220 |
-
'L_PAYMENTREQUEST_0_DESC2' => 'This Plugin allows downloadable products that you have for sale on your WP e-Commerce site to be hosted within Amazon S3.',
|
221 |
-
'L_PAYMENTREQUEST_0_TAXAMT2' => '47',
|
222 |
-
'L_PAYMENTREQUEST_0_ITEMURL2' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
223 |
-
);
|
224 |
-
|
225 |
-
$this->bogus->http->expectOnce( 'post', array( $url, $args ) );
|
226 |
-
try {
|
227 |
-
$this->bogus->purchase( $this->purchase_options );
|
228 |
-
} catch ( PHP_Merchant_Exception $e ) {
|
229 |
-
|
230 |
-
}
|
231 |
-
}
|
232 |
-
|
233 |
-
public function test_correct_parameters_are_sent_when_get_express_checkout_details() {
|
234 |
-
$url = 'https://api-3t.paypal.com/nvp';
|
235 |
-
$args = array(
|
236 |
-
// API info
|
237 |
-
'USER' => 'sdk-three_api1.sdk.com',
|
238 |
-
'PWD' => 'QFZCWN5HZM8VBG7Q',
|
239 |
-
'VERSION' => '74.0',
|
240 |
-
'SIGNATURE' => 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
|
241 |
-
'METHOD' => 'GetExpressCheckoutDetails',
|
242 |
-
'TOKEN' => $this->token,
|
243 |
-
);
|
244 |
-
|
245 |
-
$this->bogus->http->expectOnce( 'post', array( $url, $args ) );
|
246 |
-
try {
|
247 |
-
$this->bogus->get_details_for( $this->token );
|
248 |
-
} catch ( PHP_Merchant_Exception $e ) {
|
249 |
-
|
250 |
-
}
|
251 |
-
}
|
252 |
-
|
253 |
-
public function test_correct_response_is_returned_when_set_express_checkout_is_successful() {
|
254 |
-
$mock_response = 'ACK=Success&CORRELATIONID=224f0e4a32d14&TIMESTAMP=2011%2d07%2d05T13%253A23%253A52Z&VERSION=2%2e30000&BUILD=1%2e0006&TOKEN=EC%2d1OIN4UJGFOK54YFV';
|
255 |
-
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
256 |
-
$response = $this->bogus->setup_purchase( $this->setup_purchase_options );
|
257 |
-
|
258 |
-
$this->assertTrue( $response->is_successful() );
|
259 |
-
$this->assertFalse( $response->has_errors() );
|
260 |
-
$this->assertEqual( $response->get( 'token' ), 'EC-1OIN4UJGFOK54YFV' );
|
261 |
-
$this->assertEqual( $response->get( 'timestamp' ), 1309872232 );
|
262 |
-
$this->assertEqual( $response->get( 'datetime' ), '2011-07-05T13:23:52Z' );
|
263 |
-
$this->assertEqual( $response->get( 'correlation_id' ), '224f0e4a32d14' );
|
264 |
-
$this->assertEqual( $response->get( 'version' ), '2.30000' );
|
265 |
-
$this->assertEqual( $response->get( 'build' ), '1.0006' );
|
266 |
-
}
|
267 |
-
|
268 |
-
public function test_correct_response_is_returned_when_get_express_checkout_details_is_successful() {
|
269 |
-
$mock_response = 'TOKEN=EC%2d6EC97401PF4449255'.
|
270 |
-
|
271 |
-
// API Info
|
272 |
-
'&CHECKOUTSTATUS=PaymentActionNotInitiated'.
|
273 |
-
'&TIMESTAMP=2011%2d08%2d25T08%3a04%3a26Z'.
|
274 |
-
'&CORRELATIONID=b5ae9bd5c735f'.
|
275 |
-
'&ACK=Success'.
|
276 |
-
'&VERSION=74%2e0'.
|
277 |
-
'&BUILD=2085867'.
|
278 |
-
|
279 |
-
// Payer info
|
280 |
-
'&EMAIL=visa_1304648966_per%40garyc40%2ecom'.
|
281 |
-
'&PAYERID=BC798KQ2QU22W'.
|
282 |
-
'&PAYERSTATUS=verified'.
|
283 |
-
'&FIRSTNAME=Test'.
|
284 |
-
'&LASTNAME=User'.
|
285 |
-
'&COUNTRYCODE=US'.
|
286 |
-
'&SHIPTONAME=Gary%20Cao'.
|
287 |
-
'&SHIPTOSTREET=1%20Infinite%20Loop'.
|
288 |
-
'&SHIPTOSTREET2=Apple%20Headquarter'.
|
289 |
-
'&SHIPTOCITY=Cupertino'.
|
290 |
-
'&SHIPTOSTATE=CA'.
|
291 |
-
'&SHIPTOZIP=95014'.
|
292 |
-
'&SHIPTOCOUNTRYCODE=US'.
|
293 |
-
'&SHIPTOPHONENUM=%28877%29%20412%2d7753'.
|
294 |
-
'&SHIPTOCOUNTRYNAME=United%20States'.
|
295 |
-
'&ADDRESSSTATUS=Unconfirmed'.
|
296 |
-
|
297 |
-
// Legacy parameters (old API)
|
298 |
-
'&CURRENCYCODE=JPY'.
|
299 |
-
'&AMT=15337'.
|
300 |
-
'&ITEMAMT=13700'.
|
301 |
-
'&SHIPPINGAMT=1500'.
|
302 |
-
'&HANDLINGAMT=0'.
|
303 |
-
'&TAXAMT=137'.
|
304 |
-
'&DESC=Order%20for%20example%2ecom'.
|
305 |
-
'&INVNUM=E84A90G94'.
|
306 |
-
'&NOTIFYURL=http%3a%2f%2fexample%2ecom%2fipn'.
|
307 |
-
'&INSURANCEAMT=0'.
|
308 |
-
'&SHIPDISCAMT=0'.
|
309 |
-
|
310 |
-
// Legacy parameters (old API)
|
311 |
-
'&L_NAME0=Gold%20Cart%20Plugin'.
|
312 |
-
'&L_NAME1=Member%20Access%20Plugin'.
|
313 |
-
'&L_NAME2=Amazon%20S3'.
|
314 |
-
'&L_QTY0=1'.
|
315 |
-
'&L_QTY1=1'.
|
316 |
-
'&L_QTY2=1'.
|
317 |
-
'&L_TAXAMT0=40'.
|
318 |
-
'&L_TAXAMT1=50'.
|
319 |
-
'&L_TAXAMT2=47'.
|
320 |
-
'&L_AMT0=4000'.
|
321 |
-
'&L_AMT1=5000'.
|
322 |
-
'&L_AMT2=4700'.
|
323 |
-
'&L_DESC0=Gold%20Cart%20extends%20your%20WP%20e%2dCommerce%20store%20by%20enabling%20additional%20features%20and%20functionality%2e'.
|
324 |
-
'&L_DESC1=Create%20pay%20to%20view%20subscription%20sites'.
|
325 |
-
'&L_DESC2=This%20Plugin%20allows%20downloadable%20products%20on%20your%20WP%20e%2dCommerce%20site%20to%20be%20hosted%20on%20Amazon%20S3%2e'.
|
326 |
-
'&L_ITEMWEIGHTVALUE0=%20%20%200%2e00000'.
|
327 |
-
'&L_ITEMWEIGHTVALUE1=%20%20%200%2e00000'.
|
328 |
-
'&L_ITEMWEIGHTVALUE2=%20%20%200%2e00000'.
|
329 |
-
'&L_ITEMLENGTHVALUE0=%20%20%200%2e00000'.
|
330 |
-
'&L_ITEMLENGTHVALUE1=%20%20%200%2e00000'.
|
331 |
-
'&L_ITEMLENGTHVALUE2=%20%20%200%2e00000'.
|
332 |
-
'&L_ITEMWIDTHVALUE0=%20%20%200%2e00000'.
|
333 |
-
'&L_ITEMWIDTHVALUE1=%20%20%200%2e00000'.
|
334 |
-
'&L_ITEMWIDTHVALUE2=%20%20%200%2e00000'.
|
335 |
-
'&L_ITEMHEIGHTVALUE0=%20%20%200%2e00000'.
|
336 |
-
'&L_ITEMHEIGHTVALUE1=%20%20%200%2e00000'.
|
337 |
-
'&L_ITEMHEIGHTVALUE2=%20%20%200%2e00000'.
|
338 |
-
|
339 |
-
// Payment Information
|
340 |
-
'&PAYMENTREQUEST_0_CURRENCYCODE=JPY'.
|
341 |
-
'&PAYMENTREQUEST_0_AMT=15337'.
|
342 |
-
'&PAYMENTREQUEST_0_ITEMAMT=13700'.
|
343 |
-
'&PAYMENTREQUEST_0_SHIPPINGAMT=1500'.
|
344 |
-
'&PAYMENTREQUEST_0_HANDLINGAMT=0'.
|
345 |
-
'&PAYMENTREQUEST_0_TAXAMT=137'.
|
346 |
-
'&PAYMENTREQUEST_0_DESC=Order%20for%20example%2ecom'.
|
347 |
-
'&PAYMENTREQUEST_0_INVNUM=E84A90G94'.
|
348 |
-
'&PAYMENTREQUEST_0_NOTIFYURL=http%3a%2f%2fexample%2ecom%2fipn'.
|
349 |
-
'&PAYMENTREQUEST_0_INSURANCEAMT=0'.
|
350 |
-
'&PAYMENTREQUEST_0_SHIPDISCAMT=0'.
|
351 |
-
'&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false'.
|
352 |
-
|
353 |
-
// Item Information
|
354 |
-
'&L_PAYMENTREQUEST_0_NAME0=Gold%20Cart%20Plugin'.
|
355 |
-
'&L_PAYMENTREQUEST_0_NAME1=Member%20Access%20Plugin'.
|
356 |
-
'&L_PAYMENTREQUEST_0_NAME2=Amazon%20S3'.
|
357 |
-
'&L_PAYMENTREQUEST_0_QTY0=1'.
|
358 |
-
'&L_PAYMENTREQUEST_0_QTY1=1'.
|
359 |
-
'&L_PAYMENTREQUEST_0_QTY2=1'.
|
360 |
-
'&L_PAYMENTREQUEST_0_TAXAMT0=40'.
|
361 |
-
'&L_PAYMENTREQUEST_0_TAXAMT1=50'.
|
362 |
-
'&L_PAYMENTREQUEST_0_TAXAMT2=47'.
|
363 |
-
'&L_PAYMENTREQUEST_0_AMT0=4000'.
|
364 |
-
'&L_PAYMENTREQUEST_0_AMT1=5000'.
|
365 |
-
'&L_PAYMENTREQUEST_0_AMT2=4700'.
|
366 |
-
'&L_PAYMENTREQUEST_0_DESC0=Gold%20Cart%20extends%20your%20WP%20e%2dCommerce%20store%20by%20enabling%20additional%20features%20and%20functionality%2e'.
|
367 |
-
'&L_PAYMENTREQUEST_0_DESC1=Create%20pay%20to%20view%20subscription%20sites'.
|
368 |
-
'&L_PAYMENTREQUEST_0_DESC2=This%20Plugin%20allows%20downloadable%20products%20on%20your%20WP%20e%2dCommerce%20site%20to%20be%20hosted%20on%20Amazon%20S3%2e'.
|
369 |
-
'&L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0=%20%20%200%2e00000'.
|
370 |
-
'&L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE1=%20%20%200%2e00000'.
|
371 |
-
'&L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE2=%20%20%200%2e00000'.
|
372 |
-
'&L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0=%20%20%200%2e00000'.
|
373 |
-
'&L_PAYMENTREQUEST_0_ITEMLENGTHVALUE1=%20%20%200%2e00000'.
|
374 |
-
'&L_PAYMENTREQUEST_0_ITEMLENGTHVALUE2=%20%20%200%2e00000'.
|
375 |
-
'&L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0=%20%20%200%2e00000'.
|
376 |
-
'&L_PAYMENTREQUEST_0_ITEMWIDTHVALUE1=%20%20%200%2e00000'.
|
377 |
-
'&L_PAYMENTREQUEST_0_ITEMWIDTHVALUE2=%20%20%200%2e00000'.
|
378 |
-
'&L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0=%20%20%200%2e00000'.
|
379 |
-
'&L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE1=%20%20%200%2e00000'.
|
380 |
-
'&L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE2=%20%20%200%2e00000'.
|
381 |
-
|
382 |
-
// Errors
|
383 |
-
'&PAYMENTREQUESTINFO_0_ERRORCODE=0';
|
384 |
-
|
385 |
-
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
386 |
-
$response = $this->bogus->get_details_for( $this->token );
|
387 |
-
|
388 |
-
$this->assertTrue( $response->is_successful() );
|
389 |
-
$this->assertFalse( $response->has_errors() );
|
390 |
-
|
391 |
-
// API Info
|
392 |
-
$this->assertTrue( $response->is_checkout_not_initiated() );
|
393 |
-
$this->assertFalse( $response->is_checkout_failed() );
|
394 |
-
$this->assertFalse( $response->is_checkout_in_progress() );
|
395 |
-
$this->assertFalse( $response->is_checkout_completed() );
|
396 |
-
$this->assertEqual( $response->get( 'checkout_status' ), 'Not-Initiated' );
|
397 |
-
$this->assertEqual( $response->get( 'token' ), 'EC-6EC97401PF4449255' );
|
398 |
-
$this->assertEqual( $response->get( 'timestamp' ), 1314259466 );
|
399 |
-
$this->assertEqual( $response->get( 'datetime' ), '2011-08-25T08:04:26Z' );
|
400 |
-
$this->assertEqual( $response->get( 'correlation_id' ), 'b5ae9bd5c735f' );
|
401 |
-
$this->assertEqual( $response->get( 'version' ), '74.0' );
|
402 |
-
$this->assertEqual( $response->get( 'build' ), '2085867' );
|
403 |
-
|
404 |
-
// Payer Information
|
405 |
-
$mock_payer = (Object) array(
|
406 |
-
'email' => 'visa_1304648966_per@garyc40.com',
|
407 |
-
'id' => 'BC798KQ2QU22W',
|
408 |
-
'status' => 'verified',
|
409 |
-
'first_name' => 'Test',
|
410 |
-
'last_name' => 'User',
|
411 |
-
'country' => 'US',
|
412 |
-
);
|
413 |
-
$this->assertEqual( $response->get( 'payer' ), $mock_payer );
|
414 |
-
|
415 |
-
// Shipping Address
|
416 |
-
$mock_shipping_address = array(
|
417 |
-
'name' => 'Gary Cao',
|
418 |
-
'street' => '1 Infinite Loop',
|
419 |
-
'street2' => 'Apple Headquarter',
|
420 |
-
'city' => 'Cupertino',
|
421 |
-
'state' => 'CA',
|
422 |
-
'zip' => '95014',
|
423 |
-
'country_code' => 'US',
|
424 |
-
'country' => 'United States',
|
425 |
-
'phone' => '(877) 412-7753',
|
426 |
-
);
|
427 |
-
$this->assertEqual( $response->get( 'shipping_address' ), $mock_shipping_address );
|
428 |
-
|
429 |
-
// Payment Information
|
430 |
-
$this->assertEqual( $response->get( 'currency' ), 'JPY' );
|
431 |
-
$this->assertEqual( $response->get( 'amount' ), 15337 );
|
432 |
-
$this->assertEqual( $response->get( 'subtotal' ), 13700 );
|
433 |
-
$this->assertEqual( $response->get( 'shipping' ), 1500 );
|
434 |
-
$this->assertEqual( $response->get( 'handling' ), 0 );
|
435 |
-
$this->assertEqual( $response->get( 'tax' ), 137 );
|
436 |
-
$this->assertEqual( $response->get( 'invoice' ), 'E84A90G94' );
|
437 |
-
$this->assertEqual( $response->get( 'notify_url' ), 'http://example.com/ipn' );
|
438 |
-
$this->assertEqual( $response->get( 'shipping_discount' ), 0 );
|
439 |
-
|
440 |
-
// Item Information
|
441 |
-
$items = $response->get( 'items' );
|
442 |
-
$mock_items = array();
|
443 |
-
|
444 |
-
$mock_items[0] = new stdClass();
|
445 |
-
$mock_items[0]->name = 'Gold Cart Plugin';
|
446 |
-
$mock_items[0]->description = 'Gold Cart extends your WP e-Commerce store by enabling additional features and functionality.';
|
447 |
-
$mock_items[0]->amount = 4000;
|
448 |
-
$mock_items[0]->quantity = 1;
|
449 |
-
$mock_items[0]->tax = 40;
|
450 |
-
|
451 |
-
$mock_items[1] = new stdClass();
|
452 |
-
$mock_items[1]->name = 'Member Access Plugin';
|
453 |
-
$mock_items[1]->description = 'Create pay to view subscription sites';
|
454 |
-
$mock_items[1]->amount = 5000;
|
455 |
-
$mock_items[1]->quantity = 1;
|
456 |
-
$mock_items[1]->tax = 50;
|
457 |
-
|
458 |
-
$mock_items[2] = new stdClass();
|
459 |
-
$mock_items[2]->name = 'Amazon S3';
|
460 |
-
$mock_items[2]->description = 'This Plugin allows downloadable products on your WP e-Commerce site to be hosted on Amazon S3.';
|
461 |
-
$mock_items[2]->amount = 4700;
|
462 |
-
$mock_items[2]->quantity = 1;
|
463 |
-
$mock_items[2]->tax = 47;
|
464 |
-
|
465 |
-
$this->assertEqual( $items, $mock_items );
|
466 |
-
}
|
467 |
-
|
468 |
-
public function test_correct_response_is_returned_when_set_express_checkout_fails() {
|
469 |
-
$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';
|
470 |
-
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
471 |
-
$response = $this->bogus->setup_purchase( $this->setup_purchase_options );
|
472 |
-
|
473 |
-
$this->assertFalse( $response->is_successful() );
|
474 |
-
$this->assertTrue( $response->has_errors() );
|
475 |
-
$this->assertEqual( $response->get( 'timestamp' ), 1309872232 );
|
476 |
-
$this->assertEqual( $response->get( 'datetime' ), '2011-07-05T13:23:52Z' );
|
477 |
-
$this->assertEqual( $response->get( 'correlation_id' ), '224f0e4a32d14' );
|
478 |
-
$this->assertEqual( $response->get( 'version' ), '2.30000' );
|
479 |
-
$this->assertEqual( $response->get( 'build' ), '1.0006' );
|
480 |
-
|
481 |
-
$expected_errors = array(
|
482 |
-
array(
|
483 |
-
'code' => 10412,
|
484 |
-
'message' => 'Duplicate invoice',
|
485 |
-
'details' => 'Payment has already been made for this InvoiceID.',
|
486 |
-
),
|
487 |
-
|
488 |
-
array(
|
489 |
-
'code' => 10010,
|
490 |
-
'message' => 'Invalid Invoice',
|
491 |
-
'details' => 'Non-ASCII invoice id is not supported.',
|
492 |
-
),
|
493 |
-
);
|
494 |
-
$actual_errors = $response->get_errors();
|
495 |
-
$this->assertEqual( $actual_errors, $expected_errors );
|
496 |
-
}
|
497 |
-
|
498 |
-
public function test_correct_response_is_returned_when_set_express_checkout_is_successful_with_warning() {
|
499 |
-
$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';
|
500 |
-
|
501 |
-
$this->bogus->http->returnsByValue( 'post', $mock_response );
|
502 |
-
$response = $this->bogus->setup_purchase( $this->setup_purchase_options );
|
503 |
-
|
504 |
-
$this->assertTrue( $response->is_successful() );
|
505 |
-
$this->assertTrue( $response->has_errors() );
|
506 |
-
$this->assertEqual( $response->get( 'token' ), 'EC-1OIN4UJGFOK54YFV' );
|
507 |
-
$this->assertEqual( $response->get( 'timestamp' ), 1309872232 );
|
508 |
-
$this->assertEqual( $response->get( 'datetime' ), '2011-07-05T13:23:52Z' );
|
509 |
-
$this->assertEqual( $response->get( 'correlation_id' ), '224f0e4a32d14' );
|
510 |
-
$this->assertEqual( $response->get( 'version' ), '2.30000' );
|
511 |
-
$this->assertEqual( $response->get( 'build' ), '1.0006' );
|
512 |
-
|
513 |
-
$expected_errors = array(
|
514 |
-
array(
|
515 |
-
'code' => 10412,
|
516 |
-
'message' => 'Duplicate invoice',
|
517 |
-
'details' => 'Payment has already been made for this InvoiceID.',
|
518 |
-
),
|
519 |
-
|
520 |
-
array(
|
521 |
-
'code' => 10010,
|
522 |
-
'message' => 'Invalid Invoice',
|
523 |
-
'details' => 'Non-ASCII invoice id is not supported.',
|
524 |
-
),
|
525 |
-
);
|
526 |
-
$actual_errors = $response->get_errors();
|
527 |
-
$this->assertEqual( $actual_errors, $expected_errors );
|
528 |
-
|
529 |
-
}
|
530 |
-
}
|
531 |
-
|
532 |
-
require_once( PHP_MERCHANT_PATH . '/common/http-curl.php' );
|
533 |
-
Mock::generate( 'PHP_Merchant_HTTP_CURL' );
|
534 |
-
|
535 |
-
class PHP_Merchant_Paypal_Express_Checkout_Bogus extends PHP_Merchant_Paypal_Express_Checkout
|
536 |
-
{
|
537 |
-
public $http;
|
538 |
-
|
539 |
-
public function __construct( $options = array() ) {
|
540 |
-
$options['http_client'] = new MockPHP_Merchant_HTTP_CURL();
|
541 |
-
parent::__construct( $options );
|
542 |
-
}
|
543 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/gateways/paypal-ipn.php
DELETED
@@ -1,90 +0,0 @@
|
|
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
DELETED
@@ -1,125 +0,0 @@
|
|
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' => '74.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' => '74.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 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/index.php
DELETED
@@ -1,38 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! empty( $_GET['remote'] ) ) {
|
4 |
-
require_once( 'simpletest/web_tester.php' );
|
5 |
-
require_once( 'common/test-accounts.php' );
|
6 |
-
}
|
7 |
-
|
8 |
-
require_once( 'simpletest/autorun.php' );
|
9 |
-
|
10 |
-
define( 'PHP_MERCHANT_PATH', realpath( '../' ) );
|
11 |
-
define( 'PHP_MERCHANT_TEST_PATH', dirname( __FILE__ ) );
|
12 |
-
|
13 |
-
class PHP_Merchant_Test_Suite extends TestSuite
|
14 |
-
{
|
15 |
-
function __construct() {
|
16 |
-
parent::__construct( 'PHP Merchant Test Suite' );
|
17 |
-
$tests = array(
|
18 |
-
'common/php-merchant',
|
19 |
-
'common/http-curl',
|
20 |
-
'gateways/paypal',
|
21 |
-
'gateways/paypal-express-checkout',
|
22 |
-
'gateways/paypal-ipn',
|
23 |
-
);
|
24 |
-
|
25 |
-
if ( ! empty( $_GET['remote'] ) ) {
|
26 |
-
$tests = array_merge( $tests, array(
|
27 |
-
'remote/http-curl',
|
28 |
-
'remote/paypal-express-checkout',
|
29 |
-
) );
|
30 |
-
}
|
31 |
-
|
32 |
-
$dir = dirname( __FILE__ );
|
33 |
-
|
34 |
-
foreach ( $tests as $test ) {
|
35 |
-
$this->addFile( $dir . '/' . $test . '.php' );
|
36 |
-
}
|
37 |
-
}
|
38 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/remote/http-curl.php
DELETED
@@ -1,29 +0,0 @@
|
|
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';
|
13 |
-
|
14 |
-
$http = new PHP_Merchant_HTTP_CURL();
|
15 |
-
$actual_content = $http->get( 'http://garyc40.com/test-get.php' );
|
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( 'http://garyc40.com/test-post.php', 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-express-checkout.php
DELETED
@@ -1,140 +0,0 @@
|
|
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 |
-
'description' => 'Order for example.com',
|
41 |
-
'invoice' => 'E84A90G94',
|
42 |
-
'notify_url' => 'http://example.com/ipn',
|
43 |
-
|
44 |
-
// Items
|
45 |
-
'items' => array(
|
46 |
-
array(
|
47 |
-
'name' => 'Gold Cart Plugin',
|
48 |
-
'description' => 'Gold Cart extends your WP e-Commerce store by enabling additional features and functionality.',
|
49 |
-
'amount' => 4000,
|
50 |
-
'quantity' => 1,
|
51 |
-
'tax' => 40,
|
52 |
-
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/gold-cart-plugin/',
|
53 |
-
),
|
54 |
-
array(
|
55 |
-
'name' => 'Member Access Plugin',
|
56 |
-
'description' => 'Create pay to view subscription sites',
|
57 |
-
'amount' => 5000,
|
58 |
-
'quantity' => 1,
|
59 |
-
'tax' => 50,
|
60 |
-
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/member-access-plugin/',
|
61 |
-
),
|
62 |
-
array(
|
63 |
-
'name' => 'Amazon S3',
|
64 |
-
'description' => 'This Plugin allows downloadable products on your WP e-Commerce site to be hosted on Amazon S3.',
|
65 |
-
'amount' => 4700,
|
66 |
-
'quantity' => 1,
|
67 |
-
'tax' => 47,
|
68 |
-
'url' => 'http://getshopped.org/extend/premium-upgrades/premium-upgrades/amazon-s3-plugin/',
|
69 |
-
),
|
70 |
-
),
|
71 |
-
);
|
72 |
-
|
73 |
-
$this->response = $response = $gateway->setup_purchase( 15337, $purchase_options );
|
74 |
-
$this->token = $response->get( 'token' );
|
75 |
-
$this->timestamp = $response->get( 'timestamp' );
|
76 |
-
$this->datetime = $response->get( 'datetime' );
|
77 |
-
$this->correlation_id = $response->get( 'correlation_id' );
|
78 |
-
$this->version = $response->get( 'version' );
|
79 |
-
$this->build = $response->get( 'build' );
|
80 |
-
$this->assertTrue( $response->is_successful() );
|
81 |
-
$this->assertFalse( $response->has_errors() );
|
82 |
-
}
|
83 |
-
|
84 |
-
public function test_successful_get_express_checkout_request() {
|
85 |
-
global $test_accounts;
|
86 |
-
$gateway = new PHP_Merchant_Paypal_Express_Checkout( $test_accounts['paypal-express-checkout'] );
|
87 |
-
$response = $gateway->get_details_for( $this->response->get( 'token' ) );
|
88 |
-
|
89 |
-
$this->assertTrue( $response->is_successful() );
|
90 |
-
$this->assertFalse( $response->has_errors() );
|
91 |
-
|
92 |
-
// API Info
|
93 |
-
$this->assertTrue( $response->is_checkout_not_initiated() );
|
94 |
-
$this->assertFalse( $response->is_checkout_failed() );
|
95 |
-
$this->assertFalse( $response->is_checkout_in_progress() );
|
96 |
-
$this->assertFalse( $response->is_checkout_completed() );
|
97 |
-
$this->assertEqual( $response->get( 'checkout_status' ), 'NotInitiated' );
|
98 |
-
$this->assertEqual( $response->get( 'token' ), $this->response->get( 'token' ) );
|
99 |
-
$this->assertEqual( $response->get( 'version' ), $this->response->get( 'version' ) );
|
100 |
-
$this->assertEqual( $response->get( 'build' ), $this->response->get( 'build' ) );
|
101 |
-
|
102 |
-
// Payment Information
|
103 |
-
$this->assertEqual( $response->get( 'currency' ), 'JPY' );
|
104 |
-
$this->assertEqual( $response->get( 'amount' ), 15337 );
|
105 |
-
$this->assertEqual( $response->get( 'subtotal' ), 13700 );
|
106 |
-
$this->assertEqual( $response->get( 'shipping' ), 1500 );
|
107 |
-
$this->assertEqual( $response->get( 'handling' ), 0 );
|
108 |
-
$this->assertEqual( $response->get( 'tax' ), 137 );
|
109 |
-
$this->assertEqual( $response->get( 'invoice' ), 'E84A90G94' );
|
110 |
-
$this->assertEqual( $response->get( 'notify_url' ), 'http://example.com/ipn' );
|
111 |
-
$this->assertEqual( $response->get( 'shipping_discount' ), 0 );
|
112 |
-
|
113 |
-
// Item Information
|
114 |
-
$items = $response->get( 'items' );
|
115 |
-
$mock_items = array();
|
116 |
-
|
117 |
-
$mock_items[0] = new stdClass();
|
118 |
-
$mock_items[0]->name = 'Gold Cart Plugin';
|
119 |
-
$mock_items[0]->description = 'Gold Cart extends your WP e-Commerce store by enabling additional features and functionality.';
|
120 |
-
$mock_items[0]->amount = 4000;
|
121 |
-
$mock_items[0]->quantity = 1;
|
122 |
-
$mock_items[0]->tax = 40;
|
123 |
-
|
124 |
-
$mock_items[1] = new stdClass();
|
125 |
-
$mock_items[1]->name = 'Member Access Plugin';
|
126 |
-
$mock_items[1]->description = 'Create pay to view subscription sites';
|
127 |
-
$mock_items[1]->amount = 5000;
|
128 |
-
$mock_items[1]->quantity = 1;
|
129 |
-
$mock_items[1]->tax = 50;
|
130 |
-
|
131 |
-
$mock_items[2] = new stdClass();
|
132 |
-
$mock_items[2]->name = 'Amazon S3';
|
133 |
-
$mock_items[2]->description = 'This Plugin allows downloadable products on your WP e-Commerce site to be hosted on Amazon S3.';
|
134 |
-
$mock_items[2]->amount = 4700;
|
135 |
-
$mock_items[2]->quantity = 1;
|
136 |
-
$mock_items[2]->tax = 47;
|
137 |
-
|
138 |
-
$this->assertEqual( $items, $mock_items );
|
139 |
-
}
|
140 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE
DELETED
@@ -1,399 +0,0 @@
|
|
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
DELETED
@@ -1,502 +0,0 @@
|
|
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
DELETED
@@ -1,102 +0,0 @@
|
|
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
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
1.1alpha3
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/authentication.php
DELETED
@@ -1,237 +0,0 @@
|
|
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
DELETED
@@ -1,99 +0,0 @@
|
|
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
DELETED
@@ -1,1144 +0,0 @@
|
|
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
DELETED
@@ -1,122 +0,0 @@
|
|
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
DELETED
@@ -1,166 +0,0 @@
|
|
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
DELETED
@@ -1,380 +0,0 @@
|
|
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
DELETED
@@ -1,163 +0,0 @@
|
|
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
DELETED
@@ -1,96 +0,0 @@
|
|
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
DELETED
@@ -1,378 +0,0 @@
|
|
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
DELETED
@@ -1,501 +0,0 @@
|
|
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
DELETED
@@ -1,121 +0,0 @@
|
|
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
DELETED
@@ -1,476 +0,0 @@
|
|
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
DELETED
@@ -1,351 +0,0 @@
|
|
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
DELETED
@@ -1,252 +0,0 @@
|
|
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
DELETED
@@ -1,542 +0,0 @@
|
|
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
DELETED
@@ -1,870 +0,0 @@
|
|
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
DELETED
@@ -1,487 +0,0 @@
|
|
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
DELETED
@@ -1,457 +0,0 @@
|
|
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
DELETED
@@ -1,616 +0,0 @@
|
|
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
DELETED
@@ -1,442 +0,0 @@
|
|
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
DELETED
@@ -1,588 +0,0 @@
|
|
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
DELETED
@@ -1,371 +0,0 @@
|
|
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 |
-
</pre>
|
293 |
-
La méthode <span class="new_code">WebTestCase::restart()</span> préserve les cookies
|
294 |
-
dont le timeout a expiré, mais conserve les cookies temporaires ou expirés.
|
295 |
-
Vous pouvez spécifier l'heure et la date de leur réactivation.
|
296 |
-
</p>
|
297 |
-
<p>
|
298 |
-
L'expiration des cookies peut être un problème.
|
299 |
-
Si vous avez un cookie qui doit expirer au bout d'une heure,
|
300 |
-
nous n'allons pas mettre le test en veille en attendant
|
301 |
-
que le cookie expire...
|
302 |
-
</p>
|
303 |
-
<p>
|
304 |
-
Afin de provoquer leur expiration,
|
305 |
-
vous pouvez dater manuellement les cookies,
|
306 |
-
avant le début de la session.
|
307 |
-
<pre>
|
308 |
-
class LogInTest extends WebTestCase {
|
309 |
-
...
|
310 |
-
function testLoseAuthenticationAfterOneHour() {
|
311 |
-
$this->get('http://www.my-site.com/login.php');
|
312 |
-
$this->setField('u', 'Me');
|
313 |
-
$this->setField('p', 'Secret');
|
314 |
-
$this->clickSubmit('Log in');
|
315 |
-
$this->assertWantedPattern('/Welcome Me/');
|
316 |
-
<strong>
|
317 |
-
$this->ageCookies(3600);</strong>
|
318 |
-
$this->restart();
|
319 |
-
$this->get('http://www.my-site.com/restricted.php');
|
320 |
-
$this->assertWantedPattern('/Access denied/');
|
321 |
-
}
|
322 |
-
}
|
323 |
-
</pre>
|
324 |
-
Après le redémarrage, les cookies seront plus vieux
|
325 |
-
d'une heure et que tous ceux dont la date d'expiration
|
326 |
-
sera passée auront disparus.
|
327 |
-
</p>
|
328 |
-
|
329 |
-
</div>
|
330 |
-
References and related information...
|
331 |
-
<ul>
|
332 |
-
<li>
|
333 |
-
La page du projet SimpleTest sur <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
334 |
-
</li>
|
335 |
-
<li>
|
336 |
-
La page de téléchargement de SimpleTest sur <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
337 |
-
</li>
|
338 |
-
<li>
|
339 |
-
<a href="http://simpletest.org/api/">L'API du développeur pour SimpleTest</a> donne tous les détails sur les classes et les assertions disponibles.
|
340 |
-
</li>
|
341 |
-
</ul>
|
342 |
-
<div class="menu_back"><div class="menu">
|
343 |
-
<a href="index.html">SimpleTest</a>
|
344 |
-
|
|
345 |
-
<a href="overview.html">Overview</a>
|
346 |
-
|
|
347 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
348 |
-
|
|
349 |
-
<a href="group_test_documentation.html">Group tests</a>
|
350 |
-
|
|
351 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
352 |
-
|
|
353 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
354 |
-
|
|
355 |
-
<a href="reporter_documentation.html">Reporting</a>
|
356 |
-
|
|
357 |
-
<a href="expectation_documentation.html">Expectations</a>
|
358 |
-
|
|
359 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
360 |
-
|
|
361 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
362 |
-
|
|
363 |
-
<a href="authentication_documentation.html">Authentication</a>
|
364 |
-
|
|
365 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
366 |
-
</div></div>
|
367 |
-
<div class="copyright">
|
368 |
-
Copyright<br>Marcus Baker 2006
|
369 |
-
</div>
|
370 |
-
</body>
|
371 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/browser_documentation.html
DELETED
@@ -1,500 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : le composant de navigation web scriptable</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 le navigateur scriptable</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
Utiliser le <a href="#scripting">navigateur web dans des scripts</a>
|
38 |
-
</li>
|
39 |
-
<li>
|
40 |
-
<a href="#deboguer">Déboguer</a> les erreurs sur les pages
|
41 |
-
</li>
|
42 |
-
<li>
|
43 |
-
<a href="#unit">Tests complexes avec des navigateurs web multiples</a>
|
44 |
-
</li>
|
45 |
-
</ul>
|
46 |
-
<div class="content">
|
47 |
-
|
48 |
-
<p>
|
49 |
-
Le composant de navigation web de SimpleTest peut être utilisé
|
50 |
-
non seulement à l'extérieur de la classe <span class="new_code">WebTestCase</span>,
|
51 |
-
mais aussi indépendamment du framework SimpleTest lui-même.
|
52 |
-
</p>
|
53 |
-
|
54 |
-
<h2>
|
55 |
-
<a class="target" name="script"></a>Le navigateur scriptable</h2>
|
56 |
-
<p>
|
57 |
-
Vous pouvez utiliser le navigateur web dans des scripts PHP
|
58 |
-
pour confirmer que des services marchent bien comme il faut
|
59 |
-
ou pour extraire des informations à partir de ceux-ci de façon régulière.
|
60 |
-
Par exemple, voici un petit script pour extraire
|
61 |
-
le nombre de bogues ouverts dans PHP 5 à partir
|
62 |
-
du <a href="http://www.php.net/">site web PHP</a>...
|
63 |
-
<pre>
|
64 |
-
<?php
|
65 |
-
require_once('simpletest/browser.php');
|
66 |
-
|
67 |
-
$browser = &new SimpleBrowser();
|
68 |
-
$browser->get('http://php.net/');
|
69 |
-
$browser->clickLink('reporting bugs');
|
70 |
-
$browser->clickLink('statistics');
|
71 |
-
$browser->clickLink('PHP 5 bugs only');
|
72 |
-
$page = $browser->getContent();
|
73 |
-
preg_match('/status=Open.*?by=Any.*?(\d+)<\/a>/', $page, $matches);
|
74 |
-
print $matches[1];
|
75 |
-
?>
|
76 |
-
</pre>
|
77 |
-
Bien sûr Il y a des méthodes plus simple pour réaliser
|
78 |
-
cet exemple en PHP. Par exemple, vous pourriez juste
|
79 |
-
utiliser la commande PHP <span class="new_code">file()</span> sur ce qui est
|
80 |
-
ici une page fixe. Cependant, en utilisant des scripts
|
81 |
-
avec le navigateur web vous vous autorisez l'authentification,
|
82 |
-
la gestion des cookies, le chargement automatique des fenêtres,
|
83 |
-
les redirections, la transmission de formulaires et la capacité
|
84 |
-
d'examiner les entêtes.
|
85 |
-
</p>
|
86 |
-
<p>
|
87 |
-
Ces méthodes qui se basent sur le contenu textuel des pages
|
88 |
-
sont fragiles dans un site en constante évolution
|
89 |
-
et vous voudrez employer une méthode plus directe
|
90 |
-
pour accéder aux données de façon permanente,
|
91 |
-
mais pour des tâches simples cette technique peut s'avérer
|
92 |
-
une solution très rapide.
|
93 |
-
</p>
|
94 |
-
<p>
|
95 |
-
Toutes les méthode de navigation utilisées dans <a href="web_tester_documentation.html">WebTestCase</a> sont présente dans la classe <span class="new_code">SimpleBrowser</span>, mais les assertions sont remplacées par de simples accesseurs. Voici une liste complète des méthodes de navigation de page à page...
|
96 |
-
<table><tbody>
|
97 |
-
<tr>
|
98 |
-
<td><span class="new_code">addHeader($header)</span></td>
|
99 |
-
<td>Ajouter une entête à chaque téléchargement</td>
|
100 |
-
</tr>
|
101 |
-
<tr>
|
102 |
-
<td><span class="new_code">useProxy($proxy, $username, $password)</span></td>
|
103 |
-
<td>Utilise ce proxy à partir de maintenant</td>
|
104 |
-
</tr>
|
105 |
-
<tr>
|
106 |
-
<td><span class="new_code">head($url, $parameters)</span></td>
|
107 |
-
<td>Effectue une requête HEAD</td>
|
108 |
-
</tr>
|
109 |
-
<tr>
|
110 |
-
<td><span class="new_code">get($url, $parameters)</span></td>
|
111 |
-
<td>Télécharge une page avec un GET</td>
|
112 |
-
</tr>
|
113 |
-
<tr>
|
114 |
-
<td><span class="new_code">post($url, $parameters)</span></td>
|
115 |
-
<td>Télécharge une page avec un POST</td>
|
116 |
-
</tr>
|
117 |
-
<tr>
|
118 |
-
<td><span class="new_code">click($label)</span></td>
|
119 |
-
<td>Suit un lien visible ou un bouton texte par son étiquette</td>
|
120 |
-
</tr>
|
121 |
-
<tr>
|
122 |
-
<td><span class="new_code">clickLink($label)</span></td>
|
123 |
-
<td>Suit un lien par son étiquette</td>
|
124 |
-
</tr>
|
125 |
-
<tr>
|
126 |
-
<td><span class="new_code">isLink($label)</span></td>
|
127 |
-
<td>Vérifie l'existance d'un lien par son étiquette</td>
|
128 |
-
</tr>
|
129 |
-
<tr>
|
130 |
-
<td><span class="new_code">clickLinkById($id)</span></td>
|
131 |
-
<td>Suit un lien par son attribut d'identification</td>
|
132 |
-
</tr>
|
133 |
-
<tr>
|
134 |
-
<td><span class="new_code">isLinkById($id)</span></td>
|
135 |
-
<td>Vérifie l'existance d'un lien par son attribut d'identification</td>
|
136 |
-
</tr>
|
137 |
-
<tr>
|
138 |
-
<td><span class="new_code">getUrl()</span></td>
|
139 |
-
<td>La page ou la fenêtre URL en cours</td>
|
140 |
-
</tr>
|
141 |
-
<tr>
|
142 |
-
<td><span class="new_code">getTitle()</span></td>
|
143 |
-
<td>Le titre de la page</td>
|
144 |
-
</tr>
|
145 |
-
<tr>
|
146 |
-
<td><span class="new_code">getContent()</span></td>
|
147 |
-
<td>Le page ou la fenêtre brute</td>
|
148 |
-
</tr>
|
149 |
-
<tr>
|
150 |
-
<td><span class="new_code">getContentAsText()</span></td>
|
151 |
-
<td>Sans code HTML à l'exception du text "alt"</td>
|
152 |
-
</tr>
|
153 |
-
<tr>
|
154 |
-
<td><span class="new_code">retry()</span></td>
|
155 |
-
<td>Répète la dernière requête</td>
|
156 |
-
</tr>
|
157 |
-
<tr>
|
158 |
-
<td><span class="new_code">back()</span></td>
|
159 |
-
<td>Utilise le bouton "précédent" du navigateur</td>
|
160 |
-
</tr>
|
161 |
-
<tr>
|
162 |
-
<td><span class="new_code">forward()</span></td>
|
163 |
-
<td>Utilise le bouton "suivant" du navigateur</td>
|
164 |
-
</tr>
|
165 |
-
<tr>
|
166 |
-
<td><span class="new_code">authenticate($username, $password)</span></td>
|
167 |
-
<td>Retente la page ou la fenêtre après une réponse 401</td>
|
168 |
-
</tr>
|
169 |
-
<tr>
|
170 |
-
<td><span class="new_code">restart($date)</span></td>
|
171 |
-
<td>Relance le navigateur pour une nouvelle session</td>
|
172 |
-
</tr>
|
173 |
-
<tr>
|
174 |
-
<td><span class="new_code">ageCookies($interval)</span></td>
|
175 |
-
<td>Change la date des cookies</td>
|
176 |
-
</tr>
|
177 |
-
<tr>
|
178 |
-
<td><span class="new_code">setCookie($name, $value)</span></td>
|
179 |
-
<td>Lance un nouveau cookie</td>
|
180 |
-
</tr>
|
181 |
-
<tr>
|
182 |
-
<td><span class="new_code">getCookieValue($host, $path, $name)</span></td>
|
183 |
-
<td>Lit le cookie le plus spécifique</td>
|
184 |
-
</tr>
|
185 |
-
<tr>
|
186 |
-
<td><span class="new_code">getCurrentCookieValue($name)</span></td>
|
187 |
-
<td>Lit le contenue du cookie en cours</td>
|
188 |
-
</tr>
|
189 |
-
</tbody></table>
|
190 |
-
Les méthode <span class="new_code">SimpleBrowser::useProxy()</span> et
|
191 |
-
<span class="new_code">SimpleBrowser::addHeader()</span> sont spéciales.
|
192 |
-
Une fois appelées, elles continuent à s'appliquer sur les téléchargements suivants.
|
193 |
-
</p>
|
194 |
-
<p>
|
195 |
-
Naviguer dans les formulaires est similaire à la <a href="form_testing_documentation.html">navigation des formulaires via WebTestCase</a>...
|
196 |
-
<table><tbody>
|
197 |
-
<tr>
|
198 |
-
<td><span class="new_code">setField($label, $value)</span></td>
|
199 |
-
<td>Modifie tous les champs avec cette étiquette ou ce nom</td>
|
200 |
-
</tr>
|
201 |
-
<tr>
|
202 |
-
<td><span class="new_code">setFieldByName($name, $value)</span></td>
|
203 |
-
<td>Modifie tous les champs avec ce nom</td>
|
204 |
-
</tr>
|
205 |
-
<tr>
|
206 |
-
<td><span class="new_code">setFieldById($id, $value)</span></td>
|
207 |
-
<td>Modifie tous les champs avec cet identifiant</td>
|
208 |
-
</tr>
|
209 |
-
<tr>
|
210 |
-
<td><span class="new_code">getField($label)</span></td>
|
211 |
-
<td>Accesseur de la valeur d'un élément de formulaire avec cette étiquette ou ce nom</td>
|
212 |
-
</tr>
|
213 |
-
<tr>
|
214 |
-
<td><span class="new_code">getFieldByName($name)</span></td>
|
215 |
-
<td>Accesseur de la valeur d'un élément de formulaire avec ce nom</td>
|
216 |
-
</tr>
|
217 |
-
<tr>
|
218 |
-
<td><span class="new_code">getFieldById($id)</span></td>
|
219 |
-
<td>Accesseur de la valeur de l'élément de formulaire avec cet identifiant</td>
|
220 |
-
</tr>
|
221 |
-
<tr>
|
222 |
-
<td><span class="new_code">clickSubmit($label)</span></td>
|
223 |
-
<td>Transmet le formulaire avec l'étiquette de son bouton</td>
|
224 |
-
</tr>
|
225 |
-
<tr>
|
226 |
-
<td><span class="new_code">clickSubmitByName($name)</span></td>
|
227 |
-
<td>Transmet le formulaire avec l'attribut de son bouton</td>
|
228 |
-
</tr>
|
229 |
-
<tr>
|
230 |
-
<td><span class="new_code">clickSubmitById($id)</span></td>
|
231 |
-
<td>Transmet le formulaire avec l'identifiant de son bouton</td>
|
232 |
-
</tr>
|
233 |
-
<tr>
|
234 |
-
<td><span class="new_code">clickImage($label, $x, $y)</span></td>
|
235 |
-
<td>Clique sur une balise input de type image par son titre (title="*") our son texte alternatif (alt="*")</td>
|
236 |
-
</tr>
|
237 |
-
<tr>
|
238 |
-
<td><span class="new_code">clickImageByName($name, $x, $y)</span></td>
|
239 |
-
<td>Clique sur une balise input de type image par son attribut (name="*")</td>
|
240 |
-
</tr>
|
241 |
-
<tr>
|
242 |
-
<td><span class="new_code">clickImageById($id, $x, $y)</span></td>
|
243 |
-
<td>Clique sur une balise input de type image par son identifiant (id="*")</td>
|
244 |
-
</tr>
|
245 |
-
<tr>
|
246 |
-
<td><span class="new_code">submitFormById($id)</span></td>
|
247 |
-
<td>Transmet le formulaire par son identifiant propre</td>
|
248 |
-
</tr>
|
249 |
-
</tbody></table>
|
250 |
-
Au jourd d'aujourd'hui il n'existe pas beaucoup de méthodes pour lister
|
251 |
-
les formulaires et les champs disponibles.
|
252 |
-
<table><tbody>
|
253 |
-
<tr>
|
254 |
-
<td><span class="new_code">isClickable($label)</span></td>
|
255 |
-
<td>Vérifie si un lien existe avec cette étiquette ou ce nom</td>
|
256 |
-
</tr>
|
257 |
-
<tr>
|
258 |
-
<td><span class="new_code">isSubmit($label)</span></td>
|
259 |
-
<td>Vérifie si un bouton existe avec cette étiquette ou ce nom</td>
|
260 |
-
</tr>
|
261 |
-
<tr>
|
262 |
-
<td><span class="new_code">isImage($label)</span></td>
|
263 |
-
<td>Vérifie si un bouton image existe avec cette étiquette ou ce nom</td>
|
264 |
-
</tr>
|
265 |
-
<tr>
|
266 |
-
<td><span class="new_code">getLink($label)</span></td>
|
267 |
-
<td>Trouve une URL à partir de son label</td>
|
268 |
-
</tr>
|
269 |
-
<tr>
|
270 |
-
<td><span class="new_code">getLinkById($label)</span></td>
|
271 |
-
<td>Trouve une URL à partir de son identifiant</td>
|
272 |
-
</tr>
|
273 |
-
<tr>
|
274 |
-
<td><span class="new_code">getUrls()</span></td>
|
275 |
-
<td>Liste l'ensemble des liens de la page courante</td>
|
276 |
-
</tr>
|
277 |
-
</tbody></table>
|
278 |
-
Ce sera probablement
|
279 |
-
ajouté dans des versions successives de SimpleTest.
|
280 |
-
</p>
|
281 |
-
<p>
|
282 |
-
A l'intérieur d'une page, les fenêtres individuelles peuvent être
|
283 |
-
sélectionnées. Si aucune sélection n'est réalisée alors
|
284 |
-
toutes les fenêtres sont fusionnées ensemble dans
|
285 |
-
une unique et grande page.
|
286 |
-
Le contenu de la page en cours sera une concaténation des
|
287 |
-
toutes les fenêtres dans l'ordre spécifié par les balises "frameset".
|
288 |
-
<table><tbody>
|
289 |
-
<tr>
|
290 |
-
<td><span class="new_code">getFrames()</span></td>
|
291 |
-
<td>Un déchargement de la structure de la fenêtre courante</td>
|
292 |
-
</tr>
|
293 |
-
<tr>
|
294 |
-
<td><span class="new_code">getFrameFocus()</span></td>
|
295 |
-
<td>L'index ou l'étiquette de la fenêtre en courante</td>
|
296 |
-
</tr>
|
297 |
-
<tr>
|
298 |
-
<td><span class="new_code">setFrameFocusByIndex($choice)</span></td>
|
299 |
-
<td>Sélectionne la fenêtre numérotée à partir de 1</td>
|
300 |
-
</tr>
|
301 |
-
<tr>
|
302 |
-
<td><span class="new_code">setFrameFocus($name)</span></td>
|
303 |
-
<td>Sélectionne une fenêtre par son étiquette</td>
|
304 |
-
</tr>
|
305 |
-
<tr>
|
306 |
-
<td><span class="new_code">clearFrameFocus()</span></td>
|
307 |
-
<td>Traite toutes les fenêtres comme une seule page</td>
|
308 |
-
</tr>
|
309 |
-
</tbody></table>
|
310 |
-
Lorsqu'on est focalisé sur une fenêtre unique,
|
311 |
-
le contenu viendra de celle-ci uniquement.
|
312 |
-
Cela comprend les liens à cliquer et les formulaires à transmettre.
|
313 |
-
</p>
|
314 |
-
|
315 |
-
<h2>
|
316 |
-
<a class="target" name="deboguer"></a>Où sont les erreurs ?</h2>
|
317 |
-
<p>
|
318 |
-
Toute cette masse de fonctionnalités est géniale
|
319 |
-
lorsqu'on arrive à bien télécharger les pages,
|
320 |
-
mais ce n'est pas toujours évident.
|
321 |
-
Pour aider à découvrir les erreurs, le navigateur a aussi
|
322 |
-
des méthodes pour aider au débogage.
|
323 |
-
<table><tbody>
|
324 |
-
<tr>
|
325 |
-
<td><span class="new_code">setConnectionTimeout($timeout)</span></td>
|
326 |
-
<td>Ferme la socket avec un délai trop long</td>
|
327 |
-
</tr>
|
328 |
-
<tr>
|
329 |
-
<td><span class="new_code">getUrl()</span></td>
|
330 |
-
<td>L'URL de la page chargée le plus récemment</td>
|
331 |
-
</tr>
|
332 |
-
<tr>
|
333 |
-
<td><span class="new_code">getRequest()</span></td>
|
334 |
-
<td>L'entête de la requête brute de la page ou de la fenêtre</td>
|
335 |
-
</tr>
|
336 |
-
<tr>
|
337 |
-
<td><span class="new_code">getHeaders()</span></td>
|
338 |
-
<td>L'entête de réponse de la page ou de la fenêtre</td>
|
339 |
-
</tr>
|
340 |
-
<tr>
|
341 |
-
<td><span class="new_code">getTransportError()</span></td>
|
342 |
-
<td>N'importe quel erreur au niveau de la socket dans le dernier téléchargement</td>
|
343 |
-
</tr>
|
344 |
-
<tr>
|
345 |
-
<td><span class="new_code">getResponseCode()</span></td>
|
346 |
-
<td>La réponse HTTP de la page ou de la fenêtre</td>
|
347 |
-
</tr>
|
348 |
-
<tr>
|
349 |
-
<td><span class="new_code">getMimeType()</span></td>
|
350 |
-
<td>Le type Mime de la page our de la fenêtre</td>
|
351 |
-
</tr>
|
352 |
-
<tr>
|
353 |
-
<td><span class="new_code">getAuthentication()</span></td>
|
354 |
-
<td>Le type d'authentification dans l'entête d'une provocation 401</td>
|
355 |
-
</tr>
|
356 |
-
<tr>
|
357 |
-
<td><span class="new_code">getRealm()</span></td>
|
358 |
-
<td>Le realm d'authentification dans l'entête d'une provocation 401</td>
|
359 |
-
</tr>
|
360 |
-
<tr>
|
361 |
-
<td><span class="new_code">getBaseUrl()</span></td>
|
362 |
-
<td>Uniquement la base de l'URL de la page chargée le plus récemment</td>
|
363 |
-
</tr>
|
364 |
-
<tr>
|
365 |
-
<td><span class="new_code">setMaximumRedirects($max)</span></td>
|
366 |
-
<td>Nombre de redirections avant que la page ne soit chargée automatiquement</td>
|
367 |
-
</tr>
|
368 |
-
<tr>
|
369 |
-
<td><span class="new_code">setMaximumNestedFrames($max)</span></td>
|
370 |
-
<td>Protection contre des framesets récursifs</td>
|
371 |
-
</tr>
|
372 |
-
<tr>
|
373 |
-
<td><span class="new_code">ignoreFrames()</span></td>
|
374 |
-
<td>Neutralise le support des fenêtres</td>
|
375 |
-
</tr>
|
376 |
-
<tr>
|
377 |
-
<td><span class="new_code">useFrames()</span></td>
|
378 |
-
<td>Autorise le support des fenêtres</td>
|
379 |
-
</tr>
|
380 |
-
</tbody></table>
|
381 |
-
Les méthodes <span class="new_code">SimpleBrowser::setConnectionTimeout()</span>,
|
382 |
-
<span class="new_code">SimpleBrowser::setMaximumRedirects()</span>,
|
383 |
-
<span class="new_code">SimpleBrowser::setMaximumNestedFrames()</span>,
|
384 |
-
<span class="new_code">SimpleBrowser::ignoreFrames()</span>
|
385 |
-
et <span class="new_code">SimpleBrowser::useFrames()</span> continuent à s'appliquer
|
386 |
-
sur toutes les requêtes suivantes.
|
387 |
-
Les autres méthodes tiennent compte des fenêtres.
|
388 |
-
Cela veut dire que si une fenêtre individuelle ne se charge pas,
|
389 |
-
il suffit de se diriger vers elle avec
|
390 |
-
<span class="new_code">SimpleBrowser::setFrameFocus()</span> : ensuite on utilisera
|
391 |
-
<span class="new_code">SimpleBrowser::getRequest()</span>, etc. pour voir ce qui se passe.
|
392 |
-
</p>
|
393 |
-
|
394 |
-
<h2>
|
395 |
-
<a class="target" name="unit"></a>Tests unitaires complexes avec des navigateurs multiples</h2>
|
396 |
-
<p>
|
397 |
-
Tout ce qui peut être fait dans
|
398 |
-
<a href="web_tester_documentation.html">WebTestCase</a> peut maintenant
|
399 |
-
être fait dans un <a href="unit_tester_documentation.html">UnitTestCase</a>.
|
400 |
-
Ce qui revient à dire que nous pouvons librement mélanger
|
401 |
-
des tests sur des objets de domaine avec l'interface web...
|
402 |
-
<pre><strong>
|
403 |
-
class TestOfRegistration extends UnitTestCase {
|
404 |
-
function testNewUserAddedToAuthenticator() {</strong>
|
405 |
-
$browser = new SimpleBrowser();
|
406 |
-
$browser->get('http://my-site.com/register.php');
|
407 |
-
$browser->setField('email', 'me@here');
|
408 |
-
$browser->setField('password', 'Secret');
|
409 |
-
$browser->clickSubmit('Register');
|
410 |
-
<strong>
|
411 |
-
$authenticator = new Authenticator();
|
412 |
-
$member = $authenticator->findByEmail('me@here');
|
413 |
-
$this->assertEqual($member->getPassword(), 'Secret');</strong>
|
414 |
-
}
|
415 |
-
}
|
416 |
-
</pre>
|
417 |
-
Bien que ça puisse être utile par convenance temporaire,
|
418 |
-
je ne suis pas fan de ce genre de test. Ce test s'applique
|
419 |
-
à plusieurs couches de l'application, ça implique qu'il est
|
420 |
-
plus que probable qu'il faudra le remanier lorsque le code changera.
|
421 |
-
</p>
|
422 |
-
<p>
|
423 |
-
Un cas plus utile d'utilisation directe du navigateur est
|
424 |
-
le moment où le <span class="new_code">WebTestCase</span> ne peut plus suivre.
|
425 |
-
Un exemple ? Quand deux navigateurs doivent être utilisés en même temps.
|
426 |
-
</p>
|
427 |
-
<p>
|
428 |
-
Par exemple, supposons que nous voulions interdire
|
429 |
-
des usages simultanés d'un site avec le même login d'identification.
|
430 |
-
Ce scénario de test le vérifie...
|
431 |
-
<pre>
|
432 |
-
class TestOfSecurity extends UnitTestCase {
|
433 |
-
function testNoMultipleLoginsFromSameUser() {
|
434 |
-
$first = &new SimpleBrowser();
|
435 |
-
$first->get('http://my-site.com/login.php');
|
436 |
-
$first->setField('name', 'Me');
|
437 |
-
$first->setField('password', 'Secret');
|
438 |
-
$first->clickSubmit('Enter');
|
439 |
-
$this->assertEqual($first->getTitle(), 'Welcome');
|
440 |
-
|
441 |
-
$second = &new SimpleBrowser();
|
442 |
-
$second->get('http://my-site.com/login.php');
|
443 |
-
$second->setField('name', 'Me');
|
444 |
-
$second->setField('password', 'Secret');
|
445 |
-
$second->clickSubmit('Enter');
|
446 |
-
$this->assertEqual($second->getTitle(), 'Access Denied');
|
447 |
-
}
|
448 |
-
}
|
449 |
-
</pre>
|
450 |
-
Vous pouvez aussi utiliser la classe <span class="new_code">SimpleBrowser</span>
|
451 |
-
quand vous souhaitez écrire des scénarios de test en utilisant
|
452 |
-
un autre outil que SimpleTest, comme PHPUnit par exemple.
|
453 |
-
</p>
|
454 |
-
|
455 |
-
</div>
|
456 |
-
References and related information...
|
457 |
-
<ul>
|
458 |
-
<li>
|
459 |
-
La page du projet SimpleTest sur
|
460 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
461 |
-
</li>
|
462 |
-
<li>
|
463 |
-
La page de téléchargement de SimpleTest sur
|
464 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
465 |
-
</li>
|
466 |
-
<li>
|
467 |
-
<a href="http://simpletest.org/api/">L'API de développeur pour SimpleTest</a>
|
468 |
-
donne tous les détails sur les classes et les assertions disponibles.
|
469 |
-
</li>
|
470 |
-
</ul>
|
471 |
-
<div class="menu_back"><div class="menu">
|
472 |
-
<a href="index.html">SimpleTest</a>
|
473 |
-
|
|
474 |
-
<a href="overview.html">Overview</a>
|
475 |
-
|
|
476 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
477 |
-
|
|
478 |
-
<a href="group_test_documentation.html">Group tests</a>
|
479 |
-
|
|
480 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
481 |
-
|
|
482 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
483 |
-
|
|
484 |
-
<a href="reporter_documentation.html">Reporting</a>
|
485 |
-
|
|
486 |
-
<a href="expectation_documentation.html">Expectations</a>
|
487 |
-
|
|
488 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
489 |
-
|
|
490 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
491 |
-
|
|
492 |
-
<a href="authentication_documentation.html">Authentication</a>
|
493 |
-
|
|
494 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
495 |
-
</div></div>
|
496 |
-
<div class="copyright">
|
497 |
-
Copyright<br>Marcus Baker 2006
|
498 |
-
</div>
|
499 |
-
</body>
|
500 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/docs.css
DELETED
@@ -1,84 +0,0 @@
|
|
1 |
-
body {
|
2 |
-
padding-left: 3%;
|
3 |
-
padding-right: 3%;
|
4 |
-
}
|
5 |
-
pre {
|
6 |
-
font-family: "courier new", courier;
|
7 |
-
font-size: 80%;
|
8 |
-
border: 1px solid;
|
9 |
-
background-color: #cccccc;
|
10 |
-
padding: 5px;
|
11 |
-
margin-left: 5%;
|
12 |
-
margin-right: 8%;
|
13 |
-
}
|
14 |
-
.code, .new_code, pre.new_code {
|
15 |
-
font-weight: bold;
|
16 |
-
}
|
17 |
-
div.copyright {
|
18 |
-
font-size: 80%;
|
19 |
-
color: gray;
|
20 |
-
}
|
21 |
-
div.copyright a {
|
22 |
-
color: gray;
|
23 |
-
}
|
24 |
-
ul.api {
|
25 |
-
padding-left: 0em;
|
26 |
-
padding-right: 25%;
|
27 |
-
}
|
28 |
-
ul.api li {
|
29 |
-
margin-top: 0.2em;
|
30 |
-
margin-bottom: 0.2em;
|
31 |
-
list-style: none;
|
32 |
-
text-indent: -3em;
|
33 |
-
padding-left: 3em;
|
34 |
-
}
|
35 |
-
div.demo {
|
36 |
-
border: 4px ridge;
|
37 |
-
border-color: gray;
|
38 |
-
padding: 10px;
|
39 |
-
margin: 5px;
|
40 |
-
margin-left: 20px;
|
41 |
-
margin-right: 40px;
|
42 |
-
background-color: white;
|
43 |
-
}
|
44 |
-
div.demo span.fail {
|
45 |
-
color: red;
|
46 |
-
}
|
47 |
-
div.demo span.pass {
|
48 |
-
color: green;
|
49 |
-
}
|
50 |
-
div.demo h1 {
|
51 |
-
font-size: 12pt;
|
52 |
-
text-align: left;
|
53 |
-
font-weight: bold;
|
54 |
-
}
|
55 |
-
table {
|
56 |
-
border: 2px outset;
|
57 |
-
border-color: gray;
|
58 |
-
background-color: white;
|
59 |
-
margin: 5px;
|
60 |
-
margin-left: 5%;
|
61 |
-
margin-right: 5%;
|
62 |
-
}
|
63 |
-
td {
|
64 |
-
font-size: 80%;
|
65 |
-
}
|
66 |
-
.shell {
|
67 |
-
color: white;
|
68 |
-
}
|
69 |
-
pre.shell {
|
70 |
-
border: 4px ridge;
|
71 |
-
border-color: gray;
|
72 |
-
padding: 10px;
|
73 |
-
margin: 5px;
|
74 |
-
margin-left: 20px;
|
75 |
-
margin-right: 40px;
|
76 |
-
background-color: black;
|
77 |
-
}
|
78 |
-
form.demo {
|
79 |
-
background-color: lightgray;
|
80 |
-
border: 4px outset;
|
81 |
-
border-color: lightgray;
|
82 |
-
padding: 10px;
|
83 |
-
margin-right: 40%;
|
84 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/expectation_documentation.html
DELETED
@@ -1,451 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : étendre le testeur unitaire avec des classes d'attentes supplémentaires</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 les attentes</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
Utiliser les attentes <a href="#fantaisie">pour des tests
|
38 |
-
plus précis avec des objets fantaisie</a>
|
39 |
-
</li>
|
40 |
-
<li>
|
41 |
-
<a href="#comportement">Changer le comportement d'un objet fantaisie</a>
|
42 |
-
avec des attentes
|
43 |
-
</li>
|
44 |
-
<li>
|
45 |
-
<a href="#etendre">Créer des attentes</a>
|
46 |
-
</li>
|
47 |
-
<li>
|
48 |
-
Par dessous SimpleTest <a href="#unitaire">utilise des classes d'attente</a>
|
49 |
-
</li>
|
50 |
-
</ul>
|
51 |
-
<div class="content">
|
52 |
-
<h2>
|
53 |
-
<a class="target" name="fantaisie"></a>Plus de contrôle sur les objets fantaisie</h2>
|
54 |
-
<p>
|
55 |
-
Le comportement par défaut des
|
56 |
-
<a href="mock_objects_documentation.html">objets fantaisie</a> dans
|
57 |
-
<a href="http://sourceforge.net/projects/simpletest/">SimpleTest</a>
|
58 |
-
est soit une correspondance identique sur l'argument,
|
59 |
-
soit l'acceptation de n'importe quel argument.
|
60 |
-
Pour la plupart des tests, c'est suffisant.
|
61 |
-
Cependant il est parfois nécessaire de ramollir un scénario de test.
|
62 |
-
</p>
|
63 |
-
<p>
|
64 |
-
Un des endroits où un test peut être trop serré
|
65 |
-
est la reconnaissance textuelle. Prenons l'exemple
|
66 |
-
d'un composant qui produirait un message d'erreur
|
67 |
-
utile lorsque quelque chose plante. Il serait utile de tester
|
68 |
-
que l'erreur correcte est renvoyée,
|
69 |
-
mais le texte proprement dit risque d'être plutôt long.
|
70 |
-
Si vous testez le texte dans son ensemble alors
|
71 |
-
à chaque modification de ce même message
|
72 |
-
-- même un point ou une virgule -- vous aurez
|
73 |
-
à revenir sur la suite de test pour la modifier.
|
74 |
-
</p>
|
75 |
-
<p>
|
76 |
-
Voici un cas concret, nous avons un service d'actualités
|
77 |
-
qui a échoué dans sa tentative de connexion à sa source distante.
|
78 |
-
<pre>
|
79 |
-
<strong>class NewsService {
|
80 |
-
...
|
81 |
-
function publish($writer) {
|
82 |
-
if (! $this->isConnected()) {
|
83 |
-
$writer->write('Cannot connect to news service "' .
|
84 |
-
$this->_name . '" at this time. ' .
|
85 |
-
'Please try again later.');
|
86 |
-
}
|
87 |
-
...
|
88 |
-
}
|
89 |
-
}</strong>
|
90 |
-
</pre>
|
91 |
-
Là il envoie son contenu vers un classe <span class="new_code">Writer</span>.
|
92 |
-
Nous pourrions tester ce comportement avec un <span class="new_code">MockWriter</span>...
|
93 |
-
<pre>
|
94 |
-
class TestOfNewsService extends UnitTestCase {
|
95 |
-
...
|
96 |
-
function testConnectionFailure() {<strong>
|
97 |
-
$writer = new MockWriter($this);
|
98 |
-
$writer->expectOnce('write', array(
|
99 |
-
'Cannot connect to news service ' .
|
100 |
-
'"BBC News" at this time. ' .
|
101 |
-
'Please try again later.'));
|
102 |
-
|
103 |
-
$service = new NewsService('BBC News');
|
104 |
-
$service->publish($writer);
|
105 |
-
|
106 |
-
$writer->tally();</strong>
|
107 |
-
}
|
108 |
-
}
|
109 |
-
</pre>
|
110 |
-
C'est un bon exemple d'un test fragile.
|
111 |
-
Si nous décidons d'ajouter des instructions complémentaires,
|
112 |
-
par exemple proposer une source d'actualités alternative,
|
113 |
-
nous casserons nos tests par la même occasion sans pourtant
|
114 |
-
avoir modifié une seule fonctionnalité.
|
115 |
-
</p>
|
116 |
-
<p>
|
117 |
-
Pour contourner ce problème, nous voudrions utiliser
|
118 |
-
un test avec une expression rationnelle plutôt
|
119 |
-
qu'une correspondance exacte. Nous pouvons y parvenir avec...
|
120 |
-
<pre>
|
121 |
-
class TestOfNewsService extends UnitTestCase {
|
122 |
-
...
|
123 |
-
function testConnectionFailure() {
|
124 |
-
$writer = new MockWriter($this);<strong>
|
125 |
-
$writer->expectOnce(
|
126 |
-
'write',
|
127 |
-
array(new PatternExpectation('/cannot connect/i')));</strong>
|
128 |
-
|
129 |
-
$service = new NewsService('BBC News');
|
130 |
-
$service->publish($writer);
|
131 |
-
|
132 |
-
$writer->tally();
|
133 |
-
}
|
134 |
-
}
|
135 |
-
</pre>
|
136 |
-
Plutôt que de transmettre le paramètre attendu au <span class="new_code">MockWriter</span>,
|
137 |
-
nous envoyons une classe d'attente appelée <span class="new_code">PatternExpectation</span>.
|
138 |
-
L'objet fantaisie est suffisamment élégant pour reconnaître
|
139 |
-
qu'il s'agit d'un truc spécial et pour le traiter différemment.
|
140 |
-
Plutôt que de comparer l'argument entrant à cet objet,
|
141 |
-
il utilise l'objet attente lui-même pour exécuter le test.
|
142 |
-
</p>
|
143 |
-
<p>
|
144 |
-
<span class="new_code">PatternExpectation</span> utilise
|
145 |
-
l'expression rationnelle pour la comparaison avec son constructeur.
|
146 |
-
A chaque fois qu'une comparaison est fait à travers
|
147 |
-
<span class="new_code">MockWriter</span> par rapport à cette classe attente,
|
148 |
-
elle fera un <span class="new_code">preg_match()</span> avec ce motif.
|
149 |
-
Dans notre scénario de test ci-dessus, aussi longtemps
|
150 |
-
que la chaîne "cannot connect" apparaît dans le texte,
|
151 |
-
la fantaisie transmettra un succès au testeur unitaire.
|
152 |
-
Peu importe le reste du texte.
|
153 |
-
</p>
|
154 |
-
<p>
|
155 |
-
Les classes attente possibles sont...
|
156 |
-
<table><tbody>
|
157 |
-
<tr>
|
158 |
-
<td><span class="new_code">AnythingExpectation</span></td>
|
159 |
-
<td>Sera toujours validé</td>
|
160 |
-
</tr>
|
161 |
-
<tr>
|
162 |
-
<td><span class="new_code">EqualExpectation</span></td>
|
163 |
-
<td>Une égalité, plutôt que la plus forte comparaison à l'identique</td>
|
164 |
-
</tr>
|
165 |
-
<tr>
|
166 |
-
<td><span class="new_code">NotEqualExpectation</span></td>
|
167 |
-
<td>Une comparaison sur la non-égalité</td>
|
168 |
-
</tr>
|
169 |
-
<tr>
|
170 |
-
<td><span class="new_code">IndenticalExpectation</span></td>
|
171 |
-
<td>La vérification par défaut de l'objet fantaisie qui doit correspondre exactement</td>
|
172 |
-
</tr>
|
173 |
-
<tr>
|
174 |
-
<td><span class="new_code">NotIndenticalExpectation</span></td>
|
175 |
-
<td>Inverse la logique de l'objet fantaisie</td>
|
176 |
-
</tr>
|
177 |
-
<tr>
|
178 |
-
<td><span class="new_code">PatternExpectation</span></td>
|
179 |
-
<td>Utilise une expression rationnelle Perl pour comparer une chaîne</td>
|
180 |
-
</tr>
|
181 |
-
<tr>
|
182 |
-
<td><span class="new_code">NoPatternExpectation</span></td>
|
183 |
-
<td>Passe seulement si l'expression rationnelle Perl échoue</td>
|
184 |
-
</tr>
|
185 |
-
<tr>
|
186 |
-
<td><span class="new_code">IsAExpectation</span></td>
|
187 |
-
<td>Vérifie le type ou le nom de la classe uniquement</td>
|
188 |
-
</tr>
|
189 |
-
<tr>
|
190 |
-
<td><span class="new_code">NotAExpectation</span></td>
|
191 |
-
<td>L'opposé de <span class="new_code">IsAExpectation</span>
|
192 |
-
</td>
|
193 |
-
</tr>
|
194 |
-
<tr>
|
195 |
-
<td><span class="new_code">MethodExistsExpectation</span></td>
|
196 |
-
<td>Vérifie si la méthode est disponible sur un objet</td>
|
197 |
-
</tr>
|
198 |
-
<tr>
|
199 |
-
<td><span class="new_code">TrueExpectation</span></td>
|
200 |
-
<td>Accepte n'importe quelle variable PHP qui vaut vrai</td>
|
201 |
-
</tr>
|
202 |
-
<tr>
|
203 |
-
<td><span class="new_code">FalseExpectation</span></td>
|
204 |
-
<td>Accepte n'importe quelle variable PHP qui vaut faux</td>
|
205 |
-
</tr>
|
206 |
-
</tbody></table>
|
207 |
-
La plupart utilisent la valeur attendue dans le constructeur.
|
208 |
-
Les exceptions sont les vérifications sur motif,
|
209 |
-
qui utilisent une expression rationnelle, ainsi que
|
210 |
-
<span class="new_code">IsAExpectation</span> et <span class="new_code">NotAExpectation</span>,
|
211 |
-
qui prennent un type ou un nom de classe comme chaîne.
|
212 |
-
</p>
|
213 |
-
|
214 |
-
<h2>
|
215 |
-
<a class="target" name="comportement"></a>Utiliser les attentes pour contrôler les bouchons serveur</h2>
|
216 |
-
<p>
|
217 |
-
Les classes attente peuvent servir à autre chose
|
218 |
-
que l'envoi d'assertions depuis les objets fantaisie,
|
219 |
-
afin de choisir le comportement d'un
|
220 |
-
<a href="mock_objects_documentation.html">objet fantaisie</a>
|
221 |
-
ou celui d'un <a href="server_stubs_documentation.html">bouchon serveur</a>.
|
222 |
-
A chaque fois qu'une liste d'arguments est donnée,
|
223 |
-
une liste d'objets d'attente peut être insérée à la place.
|
224 |
-
</p>
|
225 |
-
<p>
|
226 |
-
Mettons que nous voulons qu'un bouchon serveur
|
227 |
-
d'autorisation simule une connexion réussie seulement
|
228 |
-
si il reçoit un objet de session valide.
|
229 |
-
Nous pouvons y arriver avec ce qui suit...
|
230 |
-
<pre>
|
231 |
-
Stub::generate('Authorisation');
|
232 |
-
<strong>
|
233 |
-
$authorisation = new StubAuthorisation();
|
234 |
-
$authorisation->returns(
|
235 |
-
'isAllowed',
|
236 |
-
true,
|
237 |
-
array(new IsAExpectation('Session', 'Must be a session')));
|
238 |
-
$authorisation->returns('isAllowed', false);</strong>
|
239 |
-
</pre>
|
240 |
-
Le comportement par défaut du bouchon serveur
|
241 |
-
est défini pour renvoyer <span class="new_code">false</span>
|
242 |
-
quand <span class="new_code">isAllowed</span> est appelé.
|
243 |
-
Lorsque nous appelons cette méthode avec un unique paramètre
|
244 |
-
qui est un objet <span class="new_code">Session</span>, il renverra <span class="new_code">true</span>.
|
245 |
-
Nous avons aussi ajouté un deuxième paramètre comme message.
|
246 |
-
Il sera affiché dans le message d'erreur de l'objet fantaisie
|
247 |
-
si l'attente est la cause de l'échec.
|
248 |
-
</p>
|
249 |
-
<p>
|
250 |
-
Ce niveau de sophistication est rarement utile :
|
251 |
-
il n'est inclut que pour être complet.
|
252 |
-
</p>
|
253 |
-
|
254 |
-
<h2>
|
255 |
-
<a class="target" name="etendre"></a>Créer vos propres attentes</h2>
|
256 |
-
<p>
|
257 |
-
Les classes d'attentes ont une structure très simple.
|
258 |
-
Tellement simple qu'il devient très simple de créer
|
259 |
-
vos propres version de logique pour des tests utilisés couramment.
|
260 |
-
</p>
|
261 |
-
<p>
|
262 |
-
Par exemple voici la création d'une classe pour tester
|
263 |
-
la validité d'adresses IP. Pour fonctionner correctement
|
264 |
-
avec les bouchons serveurs et les objets fantaisie,
|
265 |
-
cette nouvelle classe d'attente devrait étendre
|
266 |
-
<span class="new_code">SimpleExpectation</span> ou une autre de ses sous-classes...
|
267 |
-
<pre>
|
268 |
-
<strong>class ValidIp extends SimpleExpectation {
|
269 |
-
|
270 |
-
function test($ip) {
|
271 |
-
return (ip2long($ip) != -1);
|
272 |
-
}
|
273 |
-
|
274 |
-
function testMessage($ip) {
|
275 |
-
return "Address [$ip] should be a valid IP address";
|
276 |
-
}
|
277 |
-
}</strong>
|
278 |
-
</pre>
|
279 |
-
Il n'y a véritablement que deux méthodes à mettre en place.
|
280 |
-
La méthode <span class="new_code">test()</span> devrait renvoyer un <span class="new_code">true</span>
|
281 |
-
si l'attente doit passer, et une erreur <span class="new_code">false</span>
|
282 |
-
dans le cas contraire. La méthode <span class="new_code">testMessage()</span>
|
283 |
-
ne devrait renvoyer que du texte utile à la compréhension du test en lui-même.
|
284 |
-
</p>
|
285 |
-
<p>
|
286 |
-
Cette classe peut désormais être employée à la place
|
287 |
-
des classes d'attente précédentes.
|
288 |
-
</p>
|
289 |
-
<p>
|
290 |
-
Voici un exemple plus typique, vérifier un hash...
|
291 |
-
<pre>
|
292 |
-
<strong>class JustField extends EqualExpectation {
|
293 |
-
private $key;
|
294 |
-
|
295 |
-
function __construct($key, $expected) {
|
296 |
-
parent::__construct($expected);
|
297 |
-
$this->key = $key;
|
298 |
-
}
|
299 |
-
|
300 |
-
function test($compare) {
|
301 |
-
if (! isset($compare[$this->key])) {
|
302 |
-
return false;
|
303 |
-
}
|
304 |
-
return parent::test($compare[$this->key]);
|
305 |
-
}
|
306 |
-
|
307 |
-
function testMessage($compare) {
|
308 |
-
if (! isset($compare[$this->key])) {
|
309 |
-
return 'Key [' . $this->key . '] does not exist';
|
310 |
-
}
|
311 |
-
return 'Key [' . $this->key . '] -> ' .
|
312 |
-
parent::testMessage($compare[$this->key]);
|
313 |
-
}
|
314 |
-
}</strong>
|
315 |
-
</pre>
|
316 |
-
L'habitude a été prise pour séparer les clauses du message avec
|
317 |
-
"&nbsp;->&nbsp;".
|
318 |
-
Cela permet aux outils dérivés de reformater la sortie.
|
319 |
-
</p>
|
320 |
-
<p>
|
321 |
-
Supposons qu'un authentificateur s'attend à recevoir
|
322 |
-
une ligne de base de données correspondant à l'utilisateur,
|
323 |
-
et que nous avons juste besoin de valider le nom d'utilisateur.
|
324 |
-
Nous pouvons le faire très simplement avec...
|
325 |
-
<pre>
|
326 |
-
$mock->expectOnce('authenticate',
|
327 |
-
array(new JustKey('username', 'marcus')));
|
328 |
-
</pre>
|
329 |
-
</p>
|
330 |
-
|
331 |
-
<h2>
|
332 |
-
<a class="target" name="unitaire"></a>Sous le capot du testeur unitaire</h2>
|
333 |
-
<p>
|
334 |
-
Le <a href="http://sourceforge.net/projects/simpletest/">framework
|
335 |
-
de test unitaire SimpleTest</a> utilise aussi dans son coeur
|
336 |
-
des classes d'attente pour
|
337 |
-
la <a href="unit_test_documentation.html">classe UnitTestCase</a>.
|
338 |
-
Nous pouvons aussi tirer parti de ces mécanismes pour réutiliser
|
339 |
-
nos propres classes attente à l'intérieur même des suites de test.
|
340 |
-
</p>
|
341 |
-
<p>
|
342 |
-
La méthode la plus directe est d'utiliser la méthode
|
343 |
-
<span class="new_code">SimpleTest::assert()</span> pour effectuer le test...
|
344 |
-
<pre>
|
345 |
-
<strong>class TestOfNetworking extends UnitTestCase {
|
346 |
-
...
|
347 |
-
function testGetValidIp() {
|
348 |
-
$server = &new Server();
|
349 |
-
$this->assert(
|
350 |
-
new ValidIp(),
|
351 |
-
$server->getIp(),
|
352 |
-
'Server IP address->%s');
|
353 |
-
}
|
354 |
-
}</strong>
|
355 |
-
</pre>
|
356 |
-
<span class="new_code">assert()</span> testera toute attente directement.
|
357 |
-
</p>
|
358 |
-
<p>
|
359 |
-
C'est plutôt sale par rapport à notre syntaxe habituelle
|
360 |
-
du type <span class="new_code">assert...()</span>.
|
361 |
-
</p>
|
362 |
-
<p>
|
363 |
-
Pour un cas aussi simple, nous créons d'ordinaire une méthode
|
364 |
-
d'assertion distincte en utilisant la classe d'attente.
|
365 |
-
Supposons un instant que notre attente soit un peu plus
|
366 |
-
compliquée et que par conséquent nous souhaitions la réutiliser,
|
367 |
-
nous obtenons...
|
368 |
-
<pre>
|
369 |
-
class TestOfNetworking extends UnitTestCase {
|
370 |
-
...<strong>
|
371 |
-
function assertValidIp($ip, $message = '%s') {
|
372 |
-
$this->assertExpectation(new ValidIp(), $ip, $message);
|
373 |
-
}</strong>
|
374 |
-
|
375 |
-
function testGetValidIp() {
|
376 |
-
$server = &new Server();<strong>
|
377 |
-
$this->assertValidIp(
|
378 |
-
$server->getIp(),
|
379 |
-
'Server IP address->%s');</strong>
|
380 |
-
}
|
381 |
-
}
|
382 |
-
</pre>
|
383 |
-
It is rare to need the expectations for more than pattern
|
384 |
-
matching, but these facilities do allow testers to build
|
385 |
-
some sort of domain language for testing their application.
|
386 |
-
Also, complex expectation classes could make the tests
|
387 |
-
harder to read and debug.
|
388 |
-
In effect extending the test framework to create their own tool set.
|
389 |
-
|
390 |
-
|
391 |
-
Il est assez rare que le besoin d'une attente dépasse
|
392 |
-
le stade de la reconnaissance d'un motif, mais ils permettent
|
393 |
-
aux testeurs de construire leur propre langage dédié ou DSL
|
394 |
-
(Domain Specific Language) pour tester leurs applications.
|
395 |
-
Attention, les classes d'attente complexes peuvent rendre
|
396 |
-
les tests difficiles à lire et à déboguer.
|
397 |
-
Ces mécanismes sont véritablement là pour les auteurs
|
398 |
-
de système qui étendront le framework de test
|
399 |
-
pour leurs propres outils de test.
|
400 |
-
</p>
|
401 |
-
|
402 |
-
</div>
|
403 |
-
References and related information...
|
404 |
-
<ul>
|
405 |
-
<li>
|
406 |
-
La page du projet SimpleTest sur
|
407 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
408 |
-
</li>
|
409 |
-
<li>
|
410 |
-
La page de téléchargement de SimpleTest sur
|
411 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
412 |
-
</li>
|
413 |
-
<li>
|
414 |
-
Les attentes imitent les contraintes dans
|
415 |
-
<a href="http://www.jmock.org/">JMock</a>.
|
416 |
-
</li>
|
417 |
-
<li>
|
418 |
-
<a href="http://simpletest.org/api/">L'API complète pour SimpleTest</a>
|
419 |
-
réalisé avec PHPDoc.
|
420 |
-
</li>
|
421 |
-
</ul>
|
422 |
-
<div class="menu_back"><div class="menu">
|
423 |
-
<a href="index.html">SimpleTest</a>
|
424 |
-
|
|
425 |
-
<a href="overview.html">Overview</a>
|
426 |
-
|
|
427 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
428 |
-
|
|
429 |
-
<a href="group_test_documentation.html">Group tests</a>
|
430 |
-
|
|
431 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
432 |
-
|
|
433 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
434 |
-
|
|
435 |
-
<a href="reporter_documentation.html">Reporting</a>
|
436 |
-
|
|
437 |
-
<a href="expectation_documentation.html">Expectations</a>
|
438 |
-
|
|
439 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
440 |
-
|
|
441 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
442 |
-
|
|
443 |
-
<a href="authentication_documentation.html">Authentication</a>
|
444 |
-
|
|
445 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
446 |
-
</div></div>
|
447 |
-
<div class="copyright">
|
448 |
-
Copyright<br>Marcus Baker 2006
|
449 |
-
</div>
|
450 |
-
</body>
|
451 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/form_testing_documentation.html
DELETED
@@ -1,353 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : tester des formulaires HTML</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 les tests de formulaire</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
Modifier les valeurs d'un formulaire et
|
38 |
-
<a href="#submit">réussir à transmettre un simple formulaire</a>
|
39 |
-
</li>
|
40 |
-
<li>
|
41 |
-
Gérer des <a href="#multiple">objets à valeurs multiples</a>
|
42 |
-
en initialisant des listes.
|
43 |
-
</li>
|
44 |
-
<li>
|
45 |
-
Le cas des formulaires utilisant Javascript pour
|
46 |
-
modifier <a href="#hidden-field">un champ caché</a>
|
47 |
-
</li>
|
48 |
-
<li>
|
49 |
-
<a href="#brut">Envoi brut</a> quand il n'existe pas de bouton à cliquer.
|
50 |
-
</li>
|
51 |
-
</ul>
|
52 |
-
<div class="content">
|
53 |
-
<h2>
|
54 |
-
<a class="target" name="submit"></a>Valider un formulaire simple</h2>
|
55 |
-
<p>
|
56 |
-
Lorsqu'une page est téléchargée par <span class="new_code">WebTestCase</span>
|
57 |
-
en utilisant <span class="new_code">get()</span> ou <span class="new_code">post()</span>
|
58 |
-
le contenu de la page est automatiquement analysé.
|
59 |
-
De cette analyse découle le fait que toutes les commandes
|
60 |
-
à l'intérieur de la balise <form> sont disponibles
|
61 |
-
depuis l'intérieur du scénario de test.
|
62 |
-
Prenons par exemple cet extrait de code 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 |
-
Il ressemble à...
|
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 |
-
Nous pouvons naviguer vers ce code, via le site
|
79 |
-
<a href="http://www.lastcraft.com/form_testing_documentation.php">LastCraft</a>,
|
80 |
-
avec le test suivant...
|
81 |
-
<pre>
|
82 |
-
class SimpleFormTests extends WebTestCase {
|
83 |
-
<strong>
|
84 |
-
function testDefaultValue() {
|
85 |
-
$this->get('http://www.lastcraft.com/form_testing_documentation.php');
|
86 |
-
$this->assertField('a', 'A default');
|
87 |
-
}</strong>
|
88 |
-
}
|
89 |
-
</pre>
|
90 |
-
Directement après le chargement de la page toutes les commandes HTML
|
91 |
-
sont initiées avec leur valeur par défaut, comme elles apparaîtraient
|
92 |
-
dans un navigateur web. L'assertion teste qu'un objet HTML
|
93 |
-
avec le nom "a" existe dans la page
|
94 |
-
et qu'il contient la valeur "A default".
|
95 |
-
</p>
|
96 |
-
<p>
|
97 |
-
Nous pourrions retourner le formulaire tout de suite,
|
98 |
-
mais d'abord nous allons changer la valeur du champ texte.
|
99 |
-
Ce n'est qu'après que nous le transmettrons...
|
100 |
-
<pre>
|
101 |
-
class SimpleFormTests extends WebTestCase {
|
102 |
-
|
103 |
-
function testDefaultValue() {
|
104 |
-
$this->get('http://www.my-site.com/');
|
105 |
-
$this->assertField('a', 'A default');<strong>
|
106 |
-
$this->setField('a', 'New value');
|
107 |
-
$this->clickSubmit('Go');</strong>
|
108 |
-
}
|
109 |
-
}
|
110 |
-
</pre>
|
111 |
-
Parce que nous n'avons spécifié ni attribut "method"
|
112 |
-
sur la balise form, ni attribut "action",
|
113 |
-
le scénario de test suivra le comportement classique d'un navigateur :
|
114 |
-
transmission des données avec une requête <em>GET</em>
|
115 |
-
vers la même page. SimpleTest essaie d'émuler
|
116 |
-
le comportement typique d'un navigateur autant que possible,
|
117 |
-
plutôt que d'essayer d'attraper des attributs manquants sur les balises.
|
118 |
-
La raison est simple : la cible d'un framework de test est
|
119 |
-
la logique d'une application PHP, pas les erreurs
|
120 |
-
-- de syntaxe ou autres -- du code HTML.
|
121 |
-
Pour les erreurs HTML, d'autres outils tel
|
122 |
-
<a href="http://www.w3.org/People/Raggett/tidy/">HTMLTidy</a>
|
123 |
-
devraient être employés.
|
124 |
-
</p>
|
125 |
-
<p>
|
126 |
-
Si un champ manque dans n'importe quel formulaire ou si
|
127 |
-
une option est indisponible alors <span class="new_code">WebTestCase::setField()</span>
|
128 |
-
renverra <span class="new_code">false</span>. Par exemple, supposons que
|
129 |
-
nous souhaitons vérifier qu'une option "Superuser"
|
130 |
-
n'est pas présente dans ce formulaire...
|
131 |
-
<pre>
|
132 |
-
<strong>Select type of user to add:</strong>
|
133 |
-
<select name="type">
|
134 |
-
<option>Subscriber</option>
|
135 |
-
<option>Author</option>
|
136 |
-
<option>Administrator</option>
|
137 |
-
</select>
|
138 |
-
</pre>
|
139 |
-
Qui ressemble à...
|
140 |
-
</p>
|
141 |
-
<p>
|
142 |
-
<form class="demo">
|
143 |
-
<strong>Select type of user to add:</strong>
|
144 |
-
<select name="type">
|
145 |
-
<option>Subscriber</option>
|
146 |
-
<option>Author</option>
|
147 |
-
<option>Administrator</option>
|
148 |
-
</select>
|
149 |
-
</form>
|
150 |
-
</p>
|
151 |
-
<p>
|
152 |
-
Le test suivant le confirmera...
|
153 |
-
<pre>
|
154 |
-
class SimpleFormTests extends WebTestCase {
|
155 |
-
...
|
156 |
-
function testNoSuperuserChoiceAvailable() {<strong>
|
157 |
-
$this->get('http://www.lastcraft.com/form_testing_documentation.php');
|
158 |
-
$this->assertFalse($this->setField('type', 'Superuser'));</strong>
|
159 |
-
}
|
160 |
-
}
|
161 |
-
</pre>
|
162 |
-
La sélection ne sera pas changée suite à un échec d'initialisation
|
163 |
-
d'une valeur sur un objet.
|
164 |
-
</p>
|
165 |
-
<p>
|
166 |
-
Voici la liste complète des objets supportés à aujourd'hui...
|
167 |
-
<ul>
|
168 |
-
<li>Champs texte, y compris les champs masqués (hidden) ou cryptés (password).</li>
|
169 |
-
<li>Boutons submit, en incluant aussi la balise button, mais pas encore les boutons reset</li>
|
170 |
-
<li>Aires texte (textarea) avec leur gestion des retours à la ligne (wrap).</li>
|
171 |
-
<li>Cases à cocher, y compris les cases à cocher multiples dans un même formulaire.</li>
|
172 |
-
<li>Listes à menu déroulant, y compris celles à sélections multiples.</li>
|
173 |
-
<li>Boutons radio.</li>
|
174 |
-
<li>Images.</li>
|
175 |
-
</ul>
|
176 |
-
</p>
|
177 |
-
<p>
|
178 |
-
Le navigateur proposé par SimpleTest émule les actions
|
179 |
-
qui peuvent être réalisées par un utilisateur sur
|
180 |
-
une page HTML standard. Javascript n'est pas supporté et
|
181 |
-
il y a peu de chance pour qu'il le soit prochainement.
|
182 |
-
</p>
|
183 |
-
<p>
|
184 |
-
Une attention particulière doit être porté aux techniques Javascript
|
185 |
-
qui changent la valeur d'un champ caché : elles ne peuvent pas être
|
186 |
-
réalisées avec les commandes classiques de SimpleTest.
|
187 |
-
Une méthode alternative est proposée plus loin.
|
188 |
-
</p>
|
189 |
-
|
190 |
-
<h2>
|
191 |
-
<a class="target" name="multiple"></a>Champs à valeurs multiples</h2>
|
192 |
-
<p>
|
193 |
-
SimpleTest peut gérer deux types de commandes à valeur multiple :
|
194 |
-
les menus déroulants à sélection multiple et les cases à cocher
|
195 |
-
avec le même nom à l'intérieur même d'un formulaire.
|
196 |
-
La nature de ceux-ci implique que leur initialisation
|
197 |
-
et leur test sont légèrement différents.
|
198 |
-
Voici un exemple avec des cases à cocher...
|
199 |
-
<pre>
|
200 |
-
<form class="demo">
|
201 |
-
<strong>Create privileges allowed:</strong>
|
202 |
-
<input type="checkbox" name="crud" value="c" checked><br>
|
203 |
-
<strong>Retrieve privileges allowed:</strong>
|
204 |
-
<input type="checkbox" name="crud" value="r" checked><br>
|
205 |
-
<strong>Update privileges allowed:</strong>
|
206 |
-
<input type="checkbox" name="crud" value="u" checked><br>
|
207 |
-
<strong>Destroy privileges allowed:</strong>
|
208 |
-
<input type="checkbox" name="crud" value="d" checked><br>
|
209 |
-
<input type="submit" value="Enable Privileges">
|
210 |
-
</form>
|
211 |
-
</pre>
|
212 |
-
Qui se traduit par...
|
213 |
-
</p>
|
214 |
-
<p>
|
215 |
-
<form class="demo">
|
216 |
-
<strong>Create privileges allowed:</strong>
|
217 |
-
<input type="checkbox" name="crud" value="c" checked><br>
|
218 |
-
<strong>Retrieve privileges allowed:</strong>
|
219 |
-
<input type="checkbox" name="crud" value="r" checked><br>
|
220 |
-
<strong>Update privileges allowed:</strong>
|
221 |
-
<input type="checkbox" name="crud" value="u" checked><br>
|
222 |
-
<strong>Destroy privileges allowed:</strong>
|
223 |
-
<input type="checkbox" name="crud" value="d" checked><br>
|
224 |
-
<input type="submit" value="Enable Privileges">
|
225 |
-
</form>
|
226 |
-
</p>
|
227 |
-
<p>
|
228 |
-
Si nous souhaitons désactiver tous les privilèges sauf
|
229 |
-
ceux de téléchargement (Retrieve) et transmettre cette information,
|
230 |
-
nous pouvons y arriver par...
|
231 |
-
<pre>
|
232 |
-
class SimpleFormTests extends WebTestCase {
|
233 |
-
...<strong>
|
234 |
-
function testDisableNastyPrivileges() {
|
235 |
-
$this->get('http://www.lastcraft.com/form_testing_documentation.php');
|
236 |
-
$this->assertField('crud', array('c', 'r', 'u', 'd'));
|
237 |
-
$this->setField('crud', array('r'));
|
238 |
-
$this->clickSubmit('Enable Privileges');
|
239 |
-
}</strong>
|
240 |
-
}
|
241 |
-
</pre>
|
242 |
-
Plutôt que d'initier le champ à une valeur unique,
|
243 |
-
nous lui donnons une liste de valeurs.
|
244 |
-
Nous faisons la même chose pour tester les valeurs attendues.
|
245 |
-
Nous pouvons écrire d'autres bouts de code de test
|
246 |
-
pour confirmer cet effet, peut-être en nous connectant
|
247 |
-
comme utilisateur et en essayant d'effectuer une mise à jour.
|
248 |
-
</p>
|
249 |
-
|
250 |
-
<h2>
|
251 |
-
<a class="target" name="hidden-field"></a>Formulaires utilisant Javascript pour changer un champ caché</h2>
|
252 |
-
<p>
|
253 |
-
Si vous souhaitez tester un formulaire dépendant de Javascript
|
254 |
-
pour la modification d'un champ caché, vous ne pouvez pas
|
255 |
-
simplement utiliser setField().
|
256 |
-
Le code suivant <em>ne fonctionnera pas</em> :
|
257 |
-
<pre>
|
258 |
-
class SimpleFormTests extends WebTestCase {
|
259 |
-
function testMyJavascriptForm() {
|
260 |
-
<strong>// Ne fonctionne *pas*</strong>
|
261 |
-
$this->setField('un_champ_caché', '123');
|
262 |
-
$this->clickSubmit('OK');
|
263 |
-
}
|
264 |
-
}
|
265 |
-
</pre>
|
266 |
-
A la place, vous aurez besoin d'ajouter le paramètre supplémentaire
|
267 |
-
du formulaire à la méthode clickSubmit() :
|
268 |
-
<pre>
|
269 |
-
class SimpleFormTests extends WebTestCase {
|
270 |
-
function testMyJavascriptForm() {
|
271 |
-
// Ajoute le champ caché comme variable POST supplémentaire
|
272 |
-
<strong>$this->clickSubmit('OK', array('un_champ_caché'=>'123'));</strong>
|
273 |
-
}
|
274 |
-
|
275 |
-
}
|
276 |
-
</pre>
|
277 |
-
</p>
|
278 |
-
<p>
|
279 |
-
N'oubliez pas que de la sorte, vous êtes effectivement en train
|
280 |
-
de court-circuitez une partie de votre application (le code Javascript
|
281 |
-
dans le formulaire) et que peut-être serait-il plus prudent
|
282 |
-
d'utiliser un outil comme
|
283 |
-
<a href="http://selenium.openqa.org/">Selenium</a> pour mettre sur pied
|
284 |
-
un test de recette complet.
|
285 |
-
</p>
|
286 |
-
|
287 |
-
<h2>
|
288 |
-
<a class="target" name="brut"></a>Envoi brut</h2>
|
289 |
-
<p>
|
290 |
-
Si vous souhaitez tester un gestionnaire de formulaire
|
291 |
-
mais que vous ne l'avez pas écrit ou que vous n'y avez
|
292 |
-
pas encore accès, vous pouvez créer un envoi de formulaire à la main.
|
293 |
-
<pre>
|
294 |
-
class SimpleFormTests extends WebTestCase {
|
295 |
-
...<strong>
|
296 |
-
function testAttemptedHack() {
|
297 |
-
$this->post(
|
298 |
-
'http://www.my-site.com/add_user.php',
|
299 |
-
array('type' => 'superuser'));
|
300 |
-
$this->assertNoUnwantedPattern('/user created/i');
|
301 |
-
}</strong>
|
302 |
-
}
|
303 |
-
</pre>
|
304 |
-
En ajoutant des données à la méthode <span class="new_code">WebTestCase::post()</span>,
|
305 |
-
nous essayons de télécharger la page via la transmission d'un formulaire.
|
306 |
-
</p>
|
307 |
-
|
308 |
-
</div>
|
309 |
-
References and related information...
|
310 |
-
<ul>
|
311 |
-
<li>
|
312 |
-
La page du projet SimpleTest sur
|
313 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
314 |
-
</li>
|
315 |
-
<li>
|
316 |
-
La page de téléchargement de SimpleTest sur
|
317 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
318 |
-
</li>
|
319 |
-
<li>
|
320 |
-
<a href="http://simpletest.org/api/">L'API du développeur pour SimpleTest</a>
|
321 |
-
donne tous les détails sur les classes et les assertions disponibles.
|
322 |
-
</li>
|
323 |
-
</ul>
|
324 |
-
<div class="menu_back"><div class="menu">
|
325 |
-
<a href="index.html">SimpleTest</a>
|
326 |
-
|
|
327 |
-
<a href="overview.html">Overview</a>
|
328 |
-
|
|
329 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
330 |
-
|
|
331 |
-
<a href="group_test_documentation.html">Group tests</a>
|
332 |
-
|
|
333 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
334 |
-
|
|
335 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
336 |
-
|
|
337 |
-
<a href="reporter_documentation.html">Reporting</a>
|
338 |
-
|
|
339 |
-
<a href="expectation_documentation.html">Expectations</a>
|
340 |
-
|
|
341 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
342 |
-
|
|
343 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
344 |
-
|
|
345 |
-
<a href="authentication_documentation.html">Authentication</a>
|
346 |
-
|
|
347 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
348 |
-
</div></div>
|
349 |
-
<div class="copyright">
|
350 |
-
Copyright<br>Marcus Baker 2006
|
351 |
-
</div>
|
352 |
-
</body>
|
353 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/group_test_documentation.html
DELETED
@@ -1,401 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : Grouper des tests</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 le groupement des tests</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
Plusieurs approches pour <a href="#group">grouper des tests</a> ensemble.
|
38 |
-
</li>
|
39 |
-
<li>
|
40 |
-
Combiner des groupes des tests dans des
|
41 |
-
<a href="#plus-haut">groupes plus grands</a>.
|
42 |
-
</li>
|
43 |
-
<li>
|
44 |
-
Intégrer des <a href="#heritage">scénarios de test hérités</a>
|
45 |
-
d'un autre type de PHPUnit.
|
46 |
-
</li>
|
47 |
-
</ul>
|
48 |
-
<div class="content">
|
49 |
-
<h2>
|
50 |
-
<a class="target" name="grouper"></a>Grouper des tests</h2>
|
51 |
-
<p>
|
52 |
-
Pour lancer les scénarios de tests en tant que groupe,
|
53 |
-
ils devraient être placés dans des fichiers sans le code du lanceur...
|
54 |
-
<pre>
|
55 |
-
<strong><?php
|
56 |
-
require_once('../classes/io.php');
|
57 |
-
|
58 |
-
class FileTester extends UnitTestCase {
|
59 |
-
...
|
60 |
-
}
|
61 |
-
|
62 |
-
class SocketTester extends UnitTestCase {
|
63 |
-
...
|
64 |
-
}
|
65 |
-
?></strong>
|
66 |
-
</pre>
|
67 |
-
Autant de scénarios que nécessaires peuvent être
|
68 |
-
mis dans un fichier unique. Ils doivent contenir
|
69 |
-
tout le code nécessaire, entre autres la bibliothèque testée,
|
70 |
-
mais aucune des bibliothèques de SimpleTest.
|
71 |
-
</p>
|
72 |
-
<p>
|
73 |
-
Si vous avez étendu l'un ou l'autre des scénarios de test,
|
74 |
-
vous pouvez aussi les inclure.
|
75 |
-
<pre>
|
76 |
-
<?php
|
77 |
-
require_once('../classes/io.php');
|
78 |
-
<strong>
|
79 |
-
class MyFileTestCase extends UnitTestCase {
|
80 |
-
...
|
81 |
-
}
|
82 |
-
SimpleTestOptions::ignore('MyFileTestCase');</strong>
|
83 |
-
|
84 |
-
class FileTester extends MyFileTestCase {
|
85 |
-
...
|
86 |
-
}
|
87 |
-
|
88 |
-
class SocketTester extends UnitTestCase {
|
89 |
-
...
|
90 |
-
}
|
91 |
-
?>
|
92 |
-
</pre>
|
93 |
-
La classe <span class="new_code">FileTester</span> ne contient aucun test véritable,
|
94 |
-
il s'agit d'une classe de base pour d'autres scénarios de test.
|
95 |
-
Pour cette raison nous utilisons la directive
|
96 |
-
<span class="new_code">SimpleTestOptions::ignore()</span> pour indiquer
|
97 |
-
au prochain groupe de tests de l'ignorer.
|
98 |
-
Cette directive peut se placer n'importe où dans le fichier
|
99 |
-
et fonctionne quand un fichier complet des scénarios de test
|
100 |
-
est chargé (cf. ci-dessous).
|
101 |
-
Nous l'appelons <em>file_test.php</em>.
|
102 |
-
</p>
|
103 |
-
<p>
|
104 |
-
Ensuite nous créons un fichier de groupe de tests,
|
105 |
-
disons <em>group_test.php</em>.
|
106 |
-
Vous penserez à un nom plus convaincant, j'en suis sûr.
|
107 |
-
Nous lui ajoutons le fichier de test avec une méthode sans risque...
|
108 |
-
<pre>
|
109 |
-
<?php
|
110 |
-
require_once('simpletest/unit_tester.php');
|
111 |
-
require_once('simpletest/reporter.php');<strong>
|
112 |
-
require_once('file_test.php');
|
113 |
-
|
114 |
-
$test = &new GroupTest('All file tests');
|
115 |
-
$test->addTestCase(new FileTestCase());
|
116 |
-
$test->run(new HtmlReporter());</strong>
|
117 |
-
?>
|
118 |
-
</pre>
|
119 |
-
Ceci instancie le scénario de test avant que
|
120 |
-
la suite de test ne soit lancée.
|
121 |
-
Ça pourrait devenir assez onéreux avec
|
122 |
-
un grand nombre de scénarios de test :
|
123 |
-
il existe donc une autre méthode qui instancie
|
124 |
-
la classe uniquement quand elle devient nécessaire...
|
125 |
-
<pre>
|
126 |
-
<?php
|
127 |
-
require_once('simpletest/unit_tester.php');
|
128 |
-
require_once('simpletest/reporter.php');
|
129 |
-
require_once('file_test.php');
|
130 |
-
|
131 |
-
$test = &new GroupTest('All file tests');<strong>
|
132 |
-
$test->addTestClass('FileTestCase');</strong>
|
133 |
-
$test->run(new HtmlReporter());
|
134 |
-
?>
|
135 |
-
</pre>
|
136 |
-
Le problème de cette technique est que pour
|
137 |
-
chaque scénario de test supplémentaire nous aurons à importer
|
138 |
-
(via <span class="new_code">require_once()</span>) le fichier de code de test
|
139 |
-
et à instancier manuellement chaque scénario de test.
|
140 |
-
Nous pouvons nous épargner beaucoup de dactylographie avec...
|
141 |
-
<pre>
|
142 |
-
<?php
|
143 |
-
require_once('simpletest/unit_tester.php');
|
144 |
-
require_once('simpletest/reporter.php');
|
145 |
-
|
146 |
-
$test = &new GroupTest('All file tests');<strong>
|
147 |
-
$test->addTestFile('file_test.php');</strong>
|
148 |
-
$test->run(new HtmlReporter());
|
149 |
-
?>
|
150 |
-
</pre>
|
151 |
-
Voici ce qui vient de se passer :
|
152 |
-
la classe <span class="new_code">GroupTest</span> a réalisé le
|
153 |
-
<span class="new_code">require_once()</span> pour nous.
|
154 |
-
Ensuite elle vérifie si de nouvelles classes de scénario
|
155 |
-
de test ont été créées par ce nouveau fichier
|
156 |
-
et les ajoute automatiquement au groupe de tests.
|
157 |
-
Désormais tout ce qu'il nous reste à faire,
|
158 |
-
c'est d'ajouter chaque nouveau fichier.
|
159 |
-
</p>
|
160 |
-
<p>
|
161 |
-
Il y a deux choses qui peuvent planter
|
162 |
-
et qui demandent un minimum d'attention...
|
163 |
-
<ol>
|
164 |
-
<li>
|
165 |
-
Le fichier peut déjà avoir été analysé par PHP
|
166 |
-
et dans ce cas aucune classe ne sera ajoutée.
|
167 |
-
Pensez à bien vérifier que les scénarios de test
|
168 |
-
ne sont inclus que dans ce fichier et dans aucun autre
|
169 |
-
(Note : avec la nouvelle fonctionnalité <cite>autorun</cite>,
|
170 |
-
ce problème a maintenant été résolu).
|
171 |
-
</li>
|
172 |
-
<li>
|
173 |
-
Les nouvelles classes d'extension de scénario
|
174 |
-
de test qui sont incluses seront placées
|
175 |
-
dans le groupe de tests et exécutées par la même occasion.
|
176 |
-
Vous aurez à ajouter une directive
|
177 |
-
<span class="new_code">SimpleTestOptions::ignore()</span> pour ces classes
|
178 |
-
ou alors pensez à les ajouter avant la ligne
|
179 |
-
<span class="new_code">GroupTest::addTestFile()</span>.
|
180 |
-
</li>
|
181 |
-
</ol>
|
182 |
-
</p>
|
183 |
-
|
184 |
-
<h2>
|
185 |
-
<a class="target" name="plus-haut"></a>Groupements de plus haut niveau</h2>
|
186 |
-
<p>
|
187 |
-
La technique ci-dessus place tous les scénarios de test
|
188 |
-
dans un unique et grand groupe.
|
189 |
-
Sauf que pour des projets plus conséquents,
|
190 |
-
ce n'est probablement pas assez souple;
|
191 |
-
vous voudriez peut-être grouper les tests tout à fait différemment.
|
192 |
-
</p>
|
193 |
-
<p>
|
194 |
-
Pour obtenir un groupe de tests plus souple
|
195 |
-
nous pouvons sous classer <span class="new_code">GroupTest</span>
|
196 |
-
et ensuite l'instancier au cas par cas...
|
197 |
-
<pre>
|
198 |
-
<?php
|
199 |
-
require_once('simpletest/unit_tester.php');
|
200 |
-
require_once('simpletest/reporter.php');
|
201 |
-
<strong>
|
202 |
-
class FileGroupTest extends GroupTest {
|
203 |
-
function FileGroupTest() {
|
204 |
-
$this->GroupTest('All file tests');
|
205 |
-
$this->addTestFile('file_test.php');
|
206 |
-
}
|
207 |
-
}</strong>
|
208 |
-
?>
|
209 |
-
</pre>
|
210 |
-
Ceci nomme le test dans le constructeur
|
211 |
-
et ensuite ajoute à la fois nos scénarios
|
212 |
-
de test et un unique groupe en dessous.
|
213 |
-
Bien sûr nous pouvons ajouter plus d'un groupe à cet instant.
|
214 |
-
Nous pouvons maintenant invoquer les tests
|
215 |
-
à partir d'un autre fichier d'exécution...
|
216 |
-
<pre>
|
217 |
-
<?php
|
218 |
-
require_once('file_group_test.php');
|
219 |
-
<strong>
|
220 |
-
$test = &new FileGroupTest();
|
221 |
-
$test->run(new HtmlReporter());</strong>
|
222 |
-
?>
|
223 |
-
</pre>
|
224 |
-
...ou alors nous pouvons les grouper
|
225 |
-
dans un groupe de tests encore plus grand...
|
226 |
-
<pre>
|
227 |
-
<?php
|
228 |
-
require_once('file_group_test.php');
|
229 |
-
<strong>
|
230 |
-
$test = &new BigGroupTest('Big group');
|
231 |
-
$test->addTestCase(new FileGroupTest());
|
232 |
-
$test->addTestCase(...);
|
233 |
-
$test->run(new HtmlReporter());</strong>
|
234 |
-
?>
|
235 |
-
</pre>
|
236 |
-
Si nous souhaitons lancer le groupe de tests original
|
237 |
-
sans utiliser ses petits fichiers d'exécution,
|
238 |
-
nous pouvons mettre le code du lanceur de test
|
239 |
-
derrière des barreaux quand nous créons chaque groupe.
|
240 |
-
<pre>
|
241 |
-
<?php
|
242 |
-
class FileGroupTest extends GroupTest {
|
243 |
-
function FileGroupTest() {
|
244 |
-
$this->GroupTest('All file tests');
|
245 |
-
$test->addTestFile('file_test.php');
|
246 |
-
}
|
247 |
-
}
|
248 |
-
<strong>
|
249 |
-
if (! defined('RUNNER')) {
|
250 |
-
define('RUNNER', true);</strong>
|
251 |
-
$test = &new FileGroupTest();
|
252 |
-
$test->run(new HtmlReporter());
|
253 |
-
}
|
254 |
-
?>
|
255 |
-
</pre>
|
256 |
-
Cette approche exige aux barrières d'être activées
|
257 |
-
à l'inclusion du fichier de groupe de tests,
|
258 |
-
mais c'est quand même moins de tracas que beaucoup
|
259 |
-
de fichiers de lancement éparpillés.
|
260 |
-
Reste à inclure des barreaux identiques
|
261 |
-
au niveau supérieur afin de s'assurer que
|
262 |
-
le <span class="new_code">run()</span> ne sera lancé qu'une seule fois
|
263 |
-
à partir du script de haut niveau qui l'a invoqué.
|
264 |
-
<pre>
|
265 |
-
<?php
|
266 |
-
define('RUNNER', true);
|
267 |
-
|
268 |
-
require_once('file_group_test.php');
|
269 |
-
$test = &new BigGroupTest('Big group');
|
270 |
-
$test->addTestCase(new FileGroupTest());
|
271 |
-
$test->addTestCase(...);
|
272 |
-
$test->run(new HtmlReporter());
|
273 |
-
?>
|
274 |
-
</pre>
|
275 |
-
Comme les scénarios de test normaux,
|
276 |
-
un <span class="new_code">GroupTest</span> peut être chargé avec la méthode
|
277 |
-
<span class="new_code">GroupTest::addTestFile()</span>.
|
278 |
-
<pre>
|
279 |
-
<?php
|
280 |
-
define('RUNNER', true);
|
281 |
-
|
282 |
-
$test = &new BigGroupTest('Big group');<strong>
|
283 |
-
$test->addTestFile('file_group_test.php');
|
284 |
-
$test->addTestFile(...);</strong>
|
285 |
-
$test->run(new HtmlReporter());
|
286 |
-
?>
|
287 |
-
</pre>
|
288 |
-
</p>
|
289 |
-
|
290 |
-
<h2>
|
291 |
-
<a class="target" name="heritage"></a>Intégrer des scénarios de test hérités</h2>
|
292 |
-
<p>
|
293 |
-
Si vous avez déjà des tests unitaires pour votre code
|
294 |
-
ou alors si vous étendez des classes externes
|
295 |
-
qui ont déjà leurs propres tests, il y a peu de chances
|
296 |
-
pour que ceux-ci soient déjà au format SimpleTest.
|
297 |
-
Heureusement il est possible d'incorporer ces scénarios
|
298 |
-
de test en provenance d'autres testeurs unitaires
|
299 |
-
directement dans des groupes de test SimpleTest.
|
300 |
-
</p>
|
301 |
-
<p>
|
302 |
-
Par exemple, supposons que nous ayons
|
303 |
-
ce scénario de test prévu pour
|
304 |
-
<a href="http://sourceforge.net/projects/phpunit">PhpUnit</a>
|
305 |
-
dans le fichier <em>config_test.php</em>...
|
306 |
-
<pre>
|
307 |
-
<strong>class ConfigFileTest extends TestCase {
|
308 |
-
function ConfigFileTest() {
|
309 |
-
$this->TestCase('Config file test');
|
310 |
-
}
|
311 |
-
|
312 |
-
function testContents() {
|
313 |
-
$config = new ConfigFile('test.conf');
|
314 |
-
$this->assertRegexp('/me/', $config->getValue('username'));
|
315 |
-
}
|
316 |
-
}</strong>
|
317 |
-
</pre>
|
318 |
-
Le groupe de tests peut le reconnaître à partir
|
319 |
-
du moment où nous mettons l'adaptateur approprié
|
320 |
-
avant d'ajouter le fichier de test...
|
321 |
-
<pre>
|
322 |
-
<?php
|
323 |
-
require_once('simpletest/unit_tester.php');
|
324 |
-
require_once('simpletest/reporter.php');<strong>
|
325 |
-
require_once('simpletest/adapters/phpunit_test_case.php');</strong>
|
326 |
-
|
327 |
-
$test = &new GroupTest('All file tests');<strong>
|
328 |
-
$test->addTestFile('config_test.php');</strong>
|
329 |
-
$test->run(new HtmlReporter());
|
330 |
-
?>
|
331 |
-
</pre>
|
332 |
-
Il n'y a que deux adaptateurs,
|
333 |
-
l'autre est pour le paquet testeur unitaire de
|
334 |
-
<a href="http://pear.php.net/manual/en/package.php.phpunit.php">PEAR</a>...
|
335 |
-
<pre>
|
336 |
-
<?php
|
337 |
-
require_once('simpletest/unit_tester.php');
|
338 |
-
require_once('simpletest/reporter.php');<strong>
|
339 |
-
require_once('simpletest/adapters/pear_test_case.php');</strong>
|
340 |
-
|
341 |
-
$test = &new GroupTest('All file tests');<strong>
|
342 |
-
$test->addTestFile('some_pear_test_cases.php');</strong>
|
343 |
-
$test->run(new HtmlReporter());
|
344 |
-
?>
|
345 |
-
</pre>
|
346 |
-
Les scénarios de test de PEAR peuvent être
|
347 |
-
librement mélangés avec ceux de SimpleTest
|
348 |
-
mais vous ne pouvez pas utiliser les assertions
|
349 |
-
de SimpleTest au sein des versions héritées
|
350 |
-
des scénarios de test. La raison ?
|
351 |
-
Une simple vérification que vous ne rendez pas
|
352 |
-
par accident vos scénarios de test complètement
|
353 |
-
dépendants de SimpleTest.
|
354 |
-
Peut-être que vous souhaitez publier
|
355 |
-
votre bibliothèque sur PEAR par exemple :
|
356 |
-
ça voudrait dire la livrer avec des scénarios de
|
357 |
-
test compatibles avec PEAR::PhpUnit.
|
358 |
-
</p>
|
359 |
-
|
360 |
-
</div>
|
361 |
-
References and related information...
|
362 |
-
<ul>
|
363 |
-
<li>
|
364 |
-
La page du projet SimpleTest sur
|
365 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
366 |
-
</li>
|
367 |
-
<li>
|
368 |
-
La page de téléchargement de SimpleTest sur
|
369 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
370 |
-
</li>
|
371 |
-
</ul>
|
372 |
-
<div class="menu_back"><div class="menu">
|
373 |
-
<a href="index.html">SimpleTest</a>
|
374 |
-
|
|
375 |
-
<a href="overview.html">Overview</a>
|
376 |
-
|
|
377 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
378 |
-
|
|
379 |
-
<a href="group_test_documentation.html">Group tests</a>
|
380 |
-
|
|
381 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
382 |
-
|
|
383 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
384 |
-
|
|
385 |
-
<a href="reporter_documentation.html">Reporting</a>
|
386 |
-
|
|
387 |
-
<a href="expectation_documentation.html">Expectations</a>
|
388 |
-
|
|
389 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
390 |
-
|
|
391 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
392 |
-
|
|
393 |
-
<a href="authentication_documentation.html">Authentication</a>
|
394 |
-
|
|
395 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
396 |
-
</div></div>
|
397 |
-
<div class="copyright">
|
398 |
-
Copyright<br>Marcus Baker 2006
|
399 |
-
</div>
|
400 |
-
</body>
|
401 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/index.html
DELETED
@@ -1,576 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>
|
5 |
-
Prise en main rapide de SimpleTest pour PHP -
|
6 |
-
Tests unitaire et objets fantaisie pour 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 |
-
<a href="index.html">SimpleTest</a>
|
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>Prise en main rapide de SimpleTest</h1>
|
37 |
-
This page...
|
38 |
-
<ul>
|
39 |
-
<li>
|
40 |
-
<a href="#unit">Utiliser le testeur rapidement</a>
|
41 |
-
avec un exemple.
|
42 |
-
</li>
|
43 |
-
<li>
|
44 |
-
<a href="#group">Groupes de tests</a>
|
45 |
-
pour tester en un seul clic.
|
46 |
-
</li>
|
47 |
-
<li>
|
48 |
-
<a href="#mock">Utiliser les objets fantaisie</a>
|
49 |
-
pour faciliter les tests et gagner en contrôle.
|
50 |
-
</li>
|
51 |
-
<li>
|
52 |
-
<a href="#web">Tester des pages web</a>
|
53 |
-
au niveau de l'HTML.
|
54 |
-
</li>
|
55 |
-
</ul>
|
56 |
-
<div class="content">
|
57 |
-
|
58 |
-
<p>
|
59 |
-
Le présent article présuppose que vous soyez familier avec
|
60 |
-
le concept de tests unitaires ainsi que celui de développement
|
61 |
-
web avec le langage PHP. Il s'agit d'un guide pour le nouvel
|
62 |
-
et impatient utilisateur de
|
63 |
-
<a href="https://sourceforge.net/project/showfiles.php?group_id=76550">SimpleTest</a>.
|
64 |
-
Pour une documentation plus complète, particulièrement si
|
65 |
-
vous découvrez les tests unitaires, consultez la
|
66 |
-
<a href="http://www.lastcraft.com/unit_test_documentation.php">documentation
|
67 |
-
en cours</a>, et pour des exemples de scénarios de test,
|
68 |
-
consultez le
|
69 |
-
<a href="http://www.lastcraft.com/first_test_tutorial.php">tutorial
|
70 |
-
sur les tests unitaires</a>.
|
71 |
-
</p>
|
72 |
-
|
73 |
-
<h2>
|
74 |
-
<a class="target" name="unit"></a>Utiliser le testeur rapidement</h2>
|
75 |
-
<p>
|
76 |
-
Parmi les outils de test pour logiciel, le testeur unitaire
|
77 |
-
est le plus proche du développeur. Dans un contexte de
|
78 |
-
développement agile, le code de test se place juste à côté
|
79 |
-
du code source étant donné que tous les deux sont écrits
|
80 |
-
simultanément. Dans ce contexte, SimpleTest aspire à être
|
81 |
-
une solution complète de test pour un développeur PHP et
|
82 |
-
s'appelle "Simple" parce qu'elle devrait être simple à
|
83 |
-
utiliser et à étendre. Ce nom n'était pas vraiment un bon
|
84 |
-
choix. Non seulement cette solution inclut toutes les
|
85 |
-
fonctions classiques qu'on est en droit d'attendre de la
|
86 |
-
part des portages de <a href="http://www.junit.org/">JUnit</a> et des <a href="http://sourceforge.net/projects/phpunit/">PHPUnit</a>,
|
87 |
-
mais elle inclut aussi les <a href="http://www.mockobjects.com/">objets fantaisie ou
|
88 |
-
"mock objects"</a>.
|
89 |
-
</p>
|
90 |
-
<p>
|
91 |
-
Ce qui rend cet outil immédiatement utile pour un développeur PHP,
|
92 |
-
c'est son navigateur web interne.
|
93 |
-
Il permet des tests qui parcourent des sites web, remplissent
|
94 |
-
des formulaires et testent le contenu des pages.
|
95 |
-
Etre capable d'écrire ces tests en PHP veut dire qu'il devient
|
96 |
-
facile d'écrire des tests de recette (ou d'intégration).
|
97 |
-
Un exemple serait de confirmer qu'un utilisateur a bien été ajouté
|
98 |
-
dans une base de données après s'être enregistré sur une site web.
|
99 |
-
</p>
|
100 |
-
<p>
|
101 |
-
La démonstration la plus rapide : l'exemple
|
102 |
-
</p>
|
103 |
-
<p>
|
104 |
-
Supposons que nous sommes en train de tester une simple
|
105 |
-
classe de log dans un fichier : elle s'appelle
|
106 |
-
<span class="new_code">Log</span> dans <em>classes/Log.php</em>. Commençons
|
107 |
-
par créer un script de test, appelé
|
108 |
-
<em>tests/log_test.php</em>. Son contenu est le suivant...
|
109 |
-
<pre>
|
110 |
-
<?php
|
111 |
-
<strong>require_once('simpletest/autorun.php');</strong>
|
112 |
-
require_once('../classes/log.php');
|
113 |
-
|
114 |
-
class TestOfLogging extends <strong>UnitTestCase</strong> {
|
115 |
-
}
|
116 |
-
?>
|
117 |
-
</pre>
|
118 |
-
Ici le répertoire <em>simpletest</em> est soit dans le
|
119 |
-
dossier courant, soit dans les dossiers pour fichiers
|
120 |
-
inclus. Vous auriez à éditer ces arborescences suivant
|
121 |
-
l'endroit où vous avez installé SimpleTest.
|
122 |
-
Le fichier "autorun.php" fait plus que juste inclure
|
123 |
-
les éléments de SimpleTest : il lance aussi les tests pour nous.
|
124 |
-
</p>
|
125 |
-
<p>
|
126 |
-
<span class="new_code">TestOfLogging</span> est notre premier scénario de test
|
127 |
-
et il est pour l'instant vide.
|
128 |
-
Chaque scénario de test est une classe qui étend une des classes
|
129 |
-
de base de SimpleTest. Nous pouvons avoir autant de classes de ce type
|
130 |
-
que nous voulons.
|
131 |
-
</p>
|
132 |
-
<p>
|
133 |
-
Avec ces trois lignes d'échafaudage
|
134 |
-
l'inclusion de notre classe <span class="new_code">Log</span>, nous avons une suite
|
135 |
-
de tests. Mais pas encore de test !
|
136 |
-
</p>
|
137 |
-
<p>
|
138 |
-
Pour notre premier test, supposons que la classe <span class="new_code">Log</span>
|
139 |
-
prenne le nom du fichier à écrire au sein du constructeur,
|
140 |
-
et que nous avons un répertoire temporaire dans lequel placer
|
141 |
-
ce fichier.
|
142 |
-
<pre>
|
143 |
-
<?php
|
144 |
-
require_once('simpletest/autorun.php');
|
145 |
-
require_once('../classes/log.php');
|
146 |
-
|
147 |
-
class TestOfLogging extends UnitTestCase {
|
148 |
-
function <strong>testLogCreatesNewFileOnFirstMessage()</strong> {
|
149 |
-
@unlink('/temp/test.log');
|
150 |
-
$log = new Log('/temp/test.log');
|
151 |
-
<strong>$this->assertFalse(file_exists('/temp/test.log'));</strong>
|
152 |
-
$log->message('Should write this to a file');
|
153 |
-
<strong>$this->assertTrue(file_exists('/temp/test.log'));</strong>
|
154 |
-
}
|
155 |
-
}
|
156 |
-
?>
|
157 |
-
</pre>
|
158 |
-
Au lancement du scénario de test, toutes les méthodes qui
|
159 |
-
commencent avec la chaîne <span class="new_code">test</span> sont
|
160 |
-
identifiées puis exécutées.
|
161 |
-
Si la méthode commence par <span class="new_code">test</span>, c'est un test.
|
162 |
-
Remarquez bien le nom très long de notre exemple :
|
163 |
-
<span class="new_code">testLogCreatesNewFileOnFirstMessage()</span>.
|
164 |
-
C'est bel et bien délibéré : ce style est considéré désirable
|
165 |
-
et il rend la sortie du test plus lisible.
|
166 |
-
</p>
|
167 |
-
<p>
|
168 |
-
D'ordinaire nous avons bien plusieurs méthodes de tests.
|
169 |
-
Mais ce sera pour plus tard.
|
170 |
-
</p>
|
171 |
-
<p>
|
172 |
-
Les assertions dans les
|
173 |
-
méthodes de test envoient des messages vers le framework de
|
174 |
-
test qui affiche immédiatement le résultat. Cette réponse
|
175 |
-
immédiate est importante, non seulement lors d'un crash
|
176 |
-
causé par le code, mais aussi de manière à rapprocher
|
177 |
-
l'affichage de l'erreur au plus près du scénario de test
|
178 |
-
concerné via un appel à <span class="new_code">print</span>code>.
|
179 |
-
</p>
|
180 |
-
<p>
|
181 |
-
Pour voir ces résultats lançons effectivement les tests.
|
182 |
-
Aucun autre code n'est nécessaire, il suffit d'ouvrir
|
183 |
-
la page dans un navigateur.
|
184 |
-
</p>
|
185 |
-
<p>
|
186 |
-
En cas échec, l'affichage ressemble à...
|
187 |
-
<div class="demo">
|
188 |
-
<h1>TestOfLogging</h1>
|
189 |
-
<span class="fail">Fail</span>: testcreatingnewfile->True assertion failed.<br>
|
190 |
-
<div style="padding: 8px; margin-top: 1em; background-color: red; color: white;">1/1 test cases complete.
|
191 |
-
<strong>1</strong> passes and <strong>1</strong> fails.</div>
|
192 |
-
</div>
|
193 |
-
...et si ça passe, on obtient...
|
194 |
-
<div class="demo">
|
195 |
-
<h1>TestOfLogging</h1>
|
196 |
-
<div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">1/1 test cases complete.
|
197 |
-
<strong>2</strong> passes and <strong>0</strong> fails.</div>
|
198 |
-
</div>
|
199 |
-
Et si vous obtenez ça...
|
200 |
-
<div class="demo">
|
201 |
-
<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>
|
202 |
-
</div>
|
203 |
-
c'est qu'il vous manque le fichier <em>classes/Log.php</em>
|
204 |
-
qui pourrait ressembler à :
|
205 |
-
<pre>
|
206 |
-
<?php<strong>
|
207 |
-
class Log {
|
208 |
-
function Log($file_path) {
|
209 |
-
}
|
210 |
-
|
211 |
-
function message() {
|
212 |
-
}
|
213 |
-
}</strong>
|
214 |
-
?>
|
215 |
-
</pre>
|
216 |
-
C'est largement plus sympathique d'écrire le code après le test.
|
217 |
-
Plus que sympatique même - cette technique s'appelle
|
218 |
-
"Développement Piloté par les Tests" ou
|
219 |
-
"Test Driven Development" en anglais.
|
220 |
-
</p>
|
221 |
-
<p>
|
222 |
-
Pour plus de renseignements sur le testeur, voyez la
|
223 |
-
<a href="unit_test_documentation.html">documentation pour les tests de régression</a>.
|
224 |
-
</p>
|
225 |
-
|
226 |
-
<h2>
|
227 |
-
<a class="target" name="group"></a>Construire des groupes de tests</h2>
|
228 |
-
<p>
|
229 |
-
Il est peu probable que dans une véritable application on
|
230 |
-
ait uniquement besoin de passer un seul scénario de test.
|
231 |
-
Cela veut dire que nous avons besoin de grouper les
|
232 |
-
scénarios dans un script de test qui peut, si nécessaire,
|
233 |
-
lancer tous les tests de l'application.
|
234 |
-
</p>
|
235 |
-
<p>
|
236 |
-
Notre première étape est de créer un nouveau fichier appelé
|
237 |
-
<em>tests/all_tests.php</em> et d'y inclure le code suivant...
|
238 |
-
<pre>
|
239 |
-
<?php
|
240 |
-
<strong>require_once('simpletest/autorun.php');</strong>
|
241 |
-
|
242 |
-
class AllTests extends <strong>TestSuite</strong> {
|
243 |
-
function AllTests() {
|
244 |
-
$this->TestSuite(<strong>'All tests'</strong>);
|
245 |
-
<strong>$this->addFile('log_test.php');</strong>
|
246 |
-
}
|
247 |
-
}
|
248 |
-
?>
|
249 |
-
</pre>
|
250 |
-
L'inclusion de "autorun" permettra à notre future suite
|
251 |
-
de tests d'être lancée juste en invoquant ce script.
|
252 |
-
</p>
|
253 |
-
<p>
|
254 |
-
La sous-classe <span class="new_code">TestSuite</span> doit chaîner
|
255 |
-
son constructeur. Cette limitation sera supprimée dans
|
256 |
-
les versions à venir.
|
257 |
-
</p>
|
258 |
-
<p>
|
259 |
-
The method <span class="new_code">TestSuite::addFile()</span>
|
260 |
-
will include the test case file and read any new classes
|
261 |
-
that are descended from <span class="new_code">SimpleTestCase</span>.
|
262 |
-
|
263 |
-
Cette méthode <span class="new_code">TestSuite::addTestFile()</span> va
|
264 |
-
inclure le fichier de scénarios de test et lire parmi
|
265 |
-
toutes les nouvelles classes créées celles qui sont issues
|
266 |
-
de <span class="new_code">SimpleTestCase</span>.
|
267 |
-
<span class="new_code">UnitTestCase</span> est juste un exemple de classe dérivée
|
268 |
-
depuis <span class="new_code">SimpleTestCase</span> et vous pouvez créer les vôtres.
|
269 |
-
<span class="new_code">TestSuite::addFile()</span> peut aussi inclure d'autres suites.
|
270 |
-
</p>
|
271 |
-
<p>
|
272 |
-
La classe ne sera pas encore instanciée.
|
273 |
-
Quand la suite de tests est lancée, elle construira chaque instance
|
274 |
-
une fois le test atteint, et le détuira juste ensuite.
|
275 |
-
Cela veut dire que le constructeur n'est lancé qu'une fois avant
|
276 |
-
chaque initialisation de ce scénario de test et que le destructeur
|
277 |
-
est lui aussi lancé avant que le test suivant ne commence.
|
278 |
-
</p>
|
279 |
-
<p>
|
280 |
-
Il est commun de grouper des scénarios de test dans des super-classes
|
281 |
-
qui ne sont pas sensées être lancées, mais qui deviennent une classe de base
|
282 |
-
pour d'autres tests.
|
283 |
-
Pour que "autorun" fonctionne proprement les fichiers
|
284 |
-
des scénarios de test ne devraient pas lancer aveuglement
|
285 |
-
d'autres extensions de scénarios de test qui ne lanceraient pas
|
286 |
-
effectivement des tests.
|
287 |
-
Cela pourrait aboutir à un mauvais comptages des scénarios de test
|
288 |
-
pendant la procédure.
|
289 |
-
Pas vraiement un problème majeure, mais pour éviter cet inconvénient
|
290 |
-
il suffit de marquer vos classes de base comme <span class="new_code">abstract</span>.
|
291 |
-
SimpleTest ne lance pas les classes abstraites. Et si vous utilisez encore
|
292 |
-
PHP4 alors une directive <span class="new_code">SimpleTestOptions::ignore()</span>
|
293 |
-
dans votre fichier de scénario de test aura le même effet.
|
294 |
-
</p>
|
295 |
-
<p>
|
296 |
-
Par ailleurs, le fichier avec le scénario de test ne devrait pas
|
297 |
-
avoir été inclus ailleurs. Sinon aucun scénario de test
|
298 |
-
ne sera inclus à ce groupe.
|
299 |
-
Ceci pourrait se transformer en un problème plus grave :
|
300 |
-
si des fichiers ont déjà été inclus par PHP alors la méthode
|
301 |
-
<span class="new_code">TestSuite::addFile()</span> ne les détectera pas.
|
302 |
-
</p>
|
303 |
-
<p>
|
304 |
-
Pour afficher les résultats, il est seulement nécessaire
|
305 |
-
d'invoquer <em>tests/all_tests.php</em> à partir du serveur
|
306 |
-
web.
|
307 |
-
</p>
|
308 |
-
<p>
|
309 |
-
Pour plus de renseignements des groupes de tests, voyez le
|
310 |
-
<a href="group_test_documentation.html">documentation sur le groupement des tests</a>.
|
311 |
-
</p>
|
312 |
-
|
313 |
-
<h2>
|
314 |
-
<a class="target" name="mock"></a>Utiliser les objets fantaisie</h2>
|
315 |
-
<p>
|
316 |
-
Avançons un peu plus dans le futur.
|
317 |
-
</p>
|
318 |
-
<p>
|
319 |
-
Supposons que notre class logging soit testée et terminée.
|
320 |
-
Supposons aussi que nous testons une autre classe qui ait
|
321 |
-
besoin d'écrire des messages de log, disons
|
322 |
-
<span class="new_code">SessionPool</span>. Nous voulons tester une méthode
|
323 |
-
qui ressemblera probablement à quelque chose comme...
|
324 |
-
<pre><strong>
|
325 |
-
class SessionPool {
|
326 |
-
...
|
327 |
-
function logIn($username) {
|
328 |
-
...
|
329 |
-
$this->_log->message('User $username logged in.');
|
330 |
-
...
|
331 |
-
}
|
332 |
-
...
|
333 |
-
}
|
334 |
-
</strong>
|
335 |
-
</pre>
|
336 |
-
Avec le concept de "réutilisation de code" comme fil
|
337 |
-
conducteur, nous utilisons notre class <span class="new_code">Log</span>. Un
|
338 |
-
scénario de test classique ressemblera peut-être à...
|
339 |
-
<pre>
|
340 |
-
<?php
|
341 |
-
require_once('simpletest/autorun.php');
|
342 |
-
require_once('../classes/log.php');
|
343 |
-
<strong>require_once('../classes/session_pool.php');</strong>
|
344 |
-
|
345 |
-
class <strong>TestOfSessionLogging</strong> extends UnitTestCase {
|
346 |
-
|
347 |
-
function setUp() {
|
348 |
-
<strong>@unlink('/temp/test.log');</strong>
|
349 |
-
}
|
350 |
-
|
351 |
-
function tearDown() {
|
352 |
-
<strong>@unlink('/temp/test.log');</strong>
|
353 |
-
}
|
354 |
-
|
355 |
-
function testLoggingInIsLogged() {
|
356 |
-
<strong>$log = new Log('/temp/test.log');
|
357 |
-
$session_pool = &new SessionPool($log);
|
358 |
-
$session_pool->logIn('fred');</strong>
|
359 |
-
$messages = file('/temp/test.log');
|
360 |
-
$this->assertEqual($messages[0], "User fred logged in.<strong>\n</strong>");
|
361 |
-
}
|
362 |
-
}
|
363 |
-
?>
|
364 |
-
</pre>
|
365 |
-
Nous expliquerons les méthodes <span class="new_code">setUp()</span>
|
366 |
-
et <span class="new_code">tearDown()</span> plus tard.
|
367 |
-
</p>
|
368 |
-
<p>
|
369 |
-
Le design de ce scénario de test n'est pas complètement
|
370 |
-
mauvais, mais on peut l'améliorer. Nous passons du temps à
|
371 |
-
tripoter les fichiers de log qui ne font pas partie de
|
372 |
-
notre test.
|
373 |
-
Pire, nous avons créé des liens de proximité
|
374 |
-
entre la classe <span class="new_code">Log</span> et ce test. Que se
|
375 |
-
passerait-il si nous n'utilisions plus de fichiers, mais la
|
376 |
-
bibliothèque <em>syslog</em> à la place ?
|
377 |
-
|
378 |
-
Cela veut dire que notre test <span class="new_code">TestOfSessionLogging</span>
|
379 |
-
enverra un échec alors même qu'il ne teste pas Logging.
|
380 |
-
</p>
|
381 |
-
<p>
|
382 |
-
Il est aussi fragile sur des petites retouches. Avez-vous
|
383 |
-
remarqué le retour chariot supplémentaire à la fin du
|
384 |
-
message ? A-t-il été ajouté par le loggueur ? Et si il
|
385 |
-
ajoutait aussi un timestamp ou d'autres données ?
|
386 |
-
</p>
|
387 |
-
<p>
|
388 |
-
L'unique partie à tester réellement est l'envoi d'un
|
389 |
-
message précis au loggueur.
|
390 |
-
Nous pouvons réduire le couplage en
|
391 |
-
créant une fausse classe de logging : elle ne fait
|
392 |
-
qu'enregistrer le message pour le test, mais ne produit
|
393 |
-
aucun résultat. Sauf qu'elle doit ressembler exactement à
|
394 |
-
l'original.
|
395 |
-
</p>
|
396 |
-
<p>
|
397 |
-
Si l'objet fantaisie n'écrit pas dans un fichier alors nous
|
398 |
-
nous épargnons la suppression du fichier avant et après le
|
399 |
-
test. Nous pourrions même nous épargner quelques lignes de
|
400 |
-
code supplémentaires si l'objet fantaisie pouvait exécuter
|
401 |
-
l'assertion.
|
402 |
-
<p>
|
403 |
-
</p>
|
404 |
-
Trop beau pour être vrai ? Pas vraiement on peut créer un tel
|
405 |
-
objet très facilement...
|
406 |
-
<pre>
|
407 |
-
<?php
|
408 |
-
require_once('simpletest/autorun.php');
|
409 |
-
require_once('../classes/log.php');
|
410 |
-
require_once('../classes/session_pool.php');
|
411 |
-
|
412 |
-
<strong>Mock::generate('Log');</strong>
|
413 |
-
|
414 |
-
class TestOfSessionLogging extends UnitTestCase {
|
415 |
-
|
416 |
-
function testLoggingInIsLogged() {<strong>
|
417 |
-
$log = &new MockLog();
|
418 |
-
$log->expectOnce('message', array('User fred logged in.'));</strong>
|
419 |
-
$session_pool = &new SessionPool(<strong>$log</strong>);
|
420 |
-
$session_pool->logIn('fred');
|
421 |
-
}
|
422 |
-
}
|
423 |
-
?>
|
424 |
-
</pre>
|
425 |
-
L'appel <span class="new_code">Mock::generate()</span> a généré
|
426 |
-
une nouvelle classe appelé <span class="new_code">MockLog</span>.
|
427 |
-
Cela ressemble à un clone identique, sauf que nous pouvons
|
428 |
-
y adjoindre du code de test.
|
429 |
-
C'est ce que fait <span class="new_code">expectOnce()</span>.
|
430 |
-
Cela dit que si <span class="new_code">message()</span> m'est appelé,
|
431 |
-
il a intérêt à l'être avec le paramètre
|
432 |
-
"User fred logged in.".
|
433 |
-
</p>
|
434 |
-
<p>
|
435 |
-
L'appel <span class="new_code">tally()</span> est nécessaire pour annoncer à
|
436 |
-
l'objet fantaisie qu'il n'y aura plus d'appels ultérieurs.
|
437 |
-
Sans ça l'objet fantaisie pourrait attendre pendant une
|
438 |
-
éternité l'appel de la méthode sans jamais prévenir le
|
439 |
-
scénario de test. Les autres tests sont déclenchés
|
440 |
-
automatiquement quand l'appel à <span class="new_code">message()</span> est
|
441 |
-
invoqué sur l'objet <span class="new_code">MockLog</span> par le code
|
442 |
-
<span class="new_code">SessionPool::logIn()</span>.
|
443 |
-
L'appel <span class="new_code">mock</span> va déclencher une comparaison des
|
444 |
-
paramètres et ensuite envoyer le message "pass" ou "fail"
|
445 |
-
au test pour l'affichage. Des jokers peuvent être inclus
|
446 |
-
pour ne pas avoir à tester tous les paramètres d'un appel
|
447 |
-
alors que vous ne souhaitez qu'en tester un.
|
448 |
-
</p>
|
449 |
-
<p>
|
450 |
-
Les objets fantaisie dans la suite SimpleTest peuvent avoir
|
451 |
-
un ensemble de valeurs de sortie arbitraires, des séquences
|
452 |
-
de sorties, des valeurs de sortie sélectionnées à partir
|
453 |
-
des arguments d'entrée, des séquences de paramètres
|
454 |
-
attendus et des limites sur le nombre de fois qu'une
|
455 |
-
méthode peut être invoquée.
|
456 |
-
</p>
|
457 |
-
<p>
|
458 |
-
Pour que ce test fonctionne la librairie avec les objets
|
459 |
-
fantaisie doit être incluse dans la suite de tests, par
|
460 |
-
exemple dans <em>all_tests.php</em>.
|
461 |
-
</p>
|
462 |
-
<p>
|
463 |
-
Pour plus de renseignements sur les objets fantaisie, voyez le
|
464 |
-
<a href="mock_objects_documentation.html">documentation sur les objets fantaisie</a>.
|
465 |
-
</p>
|
466 |
-
|
467 |
-
<h2>
|
468 |
-
<a class="target" name="web"></a>Tester une page web</h2>
|
469 |
-
<p>
|
470 |
-
Une des exigences des sites web, c'est qu'ils produisent
|
471 |
-
des pages web. Si vous construisez un projet de A à Z et
|
472 |
-
que vous voulez intégrer des tests au fur et à mesure alors
|
473 |
-
vous voulez un outil qui puisse effectuer une navigation
|
474 |
-
automatique et en examiner le résultat. C'est le boulot
|
475 |
-
d'un testeur web.
|
476 |
-
</p>
|
477 |
-
<p>
|
478 |
-
Effectuer un test web via SimpleTest reste assez primitif :
|
479 |
-
il n'y a pas de javascript par exemple.
|
480 |
-
La plupart des autres opérations d'un navigateur sont simulées.
|
481 |
-
</p>
|
482 |
-
<p>
|
483 |
-
Pour vous donner une idée, voici un exemple assez trivial :
|
484 |
-
aller chercher une page web,
|
485 |
-
à partir de là naviguer vers la page "about"
|
486 |
-
et finalement tester un contenu déterminé par le client.
|
487 |
-
<pre>
|
488 |
-
<?php
|
489 |
-
require_once('simpletest/autorun.php');
|
490 |
-
<strong>require_once('simpletest/web_tester.php');</strong>
|
491 |
-
|
492 |
-
class TestOfAbout extends <strong>WebTestCase</strong> {
|
493 |
-
function testOurAboutPageGivesFreeReignToOurEgo() {
|
494 |
-
<strong>$this->get('http://test-server/index.php');
|
495 |
-
$this->click('About');
|
496 |
-
$this->assertTitle('About why we are so great');
|
497 |
-
$this->assertText('We are really great');</strong>
|
498 |
-
}
|
499 |
-
}
|
500 |
-
?>
|
501 |
-
</pre>
|
502 |
-
Avec ce code comme test de recette, vous pouvez vous
|
503 |
-
assurer que le contenu corresponde toujours aux
|
504 |
-
spécifications à la fois des développeurs et des autres
|
505 |
-
parties prenantes au projet.
|
506 |
-
</p>
|
507 |
-
<p>
|
508 |
-
Vous pouvez aussi naviguer à travers des formulaires...
|
509 |
-
<pre>
|
510 |
-
<?php
|
511 |
-
require_once('simpletest/autorun.php');
|
512 |
-
require_once('simpletest/web_tester.php');
|
513 |
-
|
514 |
-
class TestOfRankings extends WebTestCase {
|
515 |
-
function testWeAreTopOfGoogle() {
|
516 |
-
$this->get('http://google.com/');
|
517 |
-
$this->setField('q', 'simpletest');
|
518 |
-
$this->click("I'm Feeling Lucky");
|
519 |
-
$this->assertTitle('SimpleTest - Unit Testing for PHP');
|
520 |
-
}
|
521 |
-
}
|
522 |
-
?>
|
523 |
-
</pre>
|
524 |
-
...même si cela pourrait constituer une violation
|
525 |
-
des documents juridiques de Google(tm).
|
526 |
-
</p>
|
527 |
-
<p>
|
528 |
-
Pour plus de renseignements sur comment tester une page web, voyez la
|
529 |
-
<a href="web_tester_documentation.html">documentation sur tester des scripts web</a>.
|
530 |
-
</p>
|
531 |
-
<p>
|
532 |
-
<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>
|
533 |
-
</p>
|
534 |
-
|
535 |
-
</div>
|
536 |
-
References and related information...
|
537 |
-
<ul>
|
538 |
-
<li>
|
539 |
-
<a href="https://sourceforge.net/project/showfiles.php?group_id=76550&release_id=153280">Télécharger PHP Simple Test</a>
|
540 |
-
depuis <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
541 |
-
</li>
|
542 |
-
<li>
|
543 |
-
L'<a href="http://simpletest.org/api/">API de SimpleTest pour développeur</a>
|
544 |
-
donne tous les détails sur les classes et assertions existantes.
|
545 |
-
</li>
|
546 |
-
</ul>
|
547 |
-
<div class="menu_back"><div class="menu">
|
548 |
-
<a href="index.html">SimpleTest</a>
|
549 |
-
|
|
550 |
-
<a href="overview.html">Overview</a>
|
551 |
-
|
|
552 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
553 |
-
|
|
554 |
-
<a href="group_test_documentation.html">Group tests</a>
|
555 |
-
|
|
556 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
557 |
-
|
|
558 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
559 |
-
|
|
560 |
-
<a href="reporter_documentation.html">Reporting</a>
|
561 |
-
|
|
562 |
-
<a href="expectation_documentation.html">Expectations</a>
|
563 |
-
|
|
564 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
565 |
-
|
|
566 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
567 |
-
|
|
568 |
-
<a href="authentication_documentation.html">Authentication</a>
|
569 |
-
|
|
570 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
571 |
-
</div></div>
|
572 |
-
<div class="copyright">
|
573 |
-
Copyright<br>Marcus Baker 2006
|
574 |
-
</div>
|
575 |
-
</body>
|
576 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/mock_objects_documentation.html
DELETED
@@ -1,784 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : les objets fantaise</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 les objets fantaisie</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
<a href="#quoi">Que sont les objets fantaisie ?</a>
|
38 |
-
</li>
|
39 |
-
<li>
|
40 |
-
<a href="#creation">Créer des objets fantaisie</a>.
|
41 |
-
</li>
|
42 |
-
<li>
|
43 |
-
<a href="#bouchon">L'objet fantaisie - acteur</a> ou bouchon.
|
44 |
-
</li>
|
45 |
-
<li>
|
46 |
-
<a href="#attentes">L'objet fantaisie - critique</a> avec des attentes.
|
47 |
-
</li>
|
48 |
-
<li>
|
49 |
-
<a href="#approches">D'autres approches</a>
|
50 |
-
y compris des librairies d'objets fantaisie.
|
51 |
-
</li>
|
52 |
-
<li>
|
53 |
-
Utiliser les objets fantaisie avec
|
54 |
-
<a href="#autres_testeurs">d'autres testeurs unitaires</a>.
|
55 |
-
</li>
|
56 |
-
</ul>
|
57 |
-
<div class="content">
|
58 |
-
<h2>
|
59 |
-
<a class="target" name="quoi"></a>Que sont les objets fantaisie ?</h2>
|
60 |
-
<p>
|
61 |
-
Les objets fantaisie - ou "mock objects" en anglais -
|
62 |
-
ont deux rôles pendant un scénario de test : acteur et critique.
|
63 |
-
</p>
|
64 |
-
<p>
|
65 |
-
Le comportement d'acteur est celui de simuler
|
66 |
-
des objets difficiles à initialiser ou trop consommateurs
|
67 |
-
en temps pendant un test.
|
68 |
-
Le cas classique est celui de la connexion à une base de données.
|
69 |
-
Mettre sur pied une base de données de test au lancement
|
70 |
-
de chaque test ralentirait considérablement les tests
|
71 |
-
et en plus exigerait l'installation d'un moteur
|
72 |
-
de base de données ainsi que des données sur la machine de test.
|
73 |
-
Si nous pouvons simuler la connexion
|
74 |
-
et renvoyer des données à notre guise
|
75 |
-
alors non seulement nous gagnons en pragmatisme
|
76 |
-
sur les tests mais en sus nous pouvons nourrir
|
77 |
-
notre base avec des données falsifiées
|
78 |
-
et voir comment il répond. Nous pouvons
|
79 |
-
simuler une base de données en suspens ou
|
80 |
-
d'autres cas extrêmes sans avoir à créer
|
81 |
-
une véritable panne de base de données.
|
82 |
-
En d'autres termes nous pouvons gagner
|
83 |
-
en contrôle sur l'environnement de test.
|
84 |
-
</p>
|
85 |
-
<p>
|
86 |
-
Si les objets fantaisie ne se comportaient que comme
|
87 |
-
des acteurs alors on les connaîtrait sous le nom de
|
88 |
-
<a href="server_stubs_documentation.html">bouchons serveur</a>.
|
89 |
-
</p>
|
90 |
-
<p>
|
91 |
-
Cependant non seulement les objets fantaisie jouent
|
92 |
-
un rôle (en fournissant à la demande les valeurs requises)
|
93 |
-
mais en plus ils sont aussi sensibles aux messages qui
|
94 |
-
leur sont envoyés (par le biais d'attentes).
|
95 |
-
En posant les paramètres attendus d'une méthode
|
96 |
-
ils agissent comme des gardiens :
|
97 |
-
un appel sur eux doit être réalisé correctement.
|
98 |
-
Si les attentes ne sont pas atteintes ils nous épargnent
|
99 |
-
l'effort de l'écriture d'une assertion de test avec
|
100 |
-
échec en réalisant cette tâche à notre place.
|
101 |
-
Dans le cas d'une connexion à une base de données
|
102 |
-
imaginaire ils peuvent tester si la requête, disons SQL,
|
103 |
-
a bien été formé par l'objet qui utilise cette connexion.
|
104 |
-
Mettez-les sur pied avec des attentes assez précises
|
105 |
-
et vous verrez que vous n'aurez presque plus d'assertion à écrire manuellement.
|
106 |
-
</p>
|
107 |
-
|
108 |
-
<h2>
|
109 |
-
<a class="target" name="creation"></a>Créer des objets fantaisie</h2>
|
110 |
-
<p>
|
111 |
-
Comme pour la création des bouchons serveur, tout ce dont
|
112 |
-
nous avons besoin c'est d'un classe existante.
|
113 |
-
La fameuse connexion à une base de données qui ressemblerait à...
|
114 |
-
<pre>
|
115 |
-
<strong>class DatabaseConnection {
|
116 |
-
function DatabaseConnection() {
|
117 |
-
}
|
118 |
-
|
119 |
-
function query() {
|
120 |
-
}
|
121 |
-
|
122 |
-
function selectQuery() {
|
123 |
-
}
|
124 |
-
}</strong>
|
125 |
-
</pre>
|
126 |
-
Cette classe n'a pas encore besoin d'être implémentée.
|
127 |
-
Pour en créer sa version fantaisie nous devons juste
|
128 |
-
inclure la librairie d'objet fantaisie puis lancer le générateur...
|
129 |
-
<pre>
|
130 |
-
<strong>require_once('simpletest/unit_tester.php');
|
131 |
-
require_once('simpletest/mock_objects.php');
|
132 |
-
require_once('database_connection.php');
|
133 |
-
|
134 |
-
Mock::generate('DatabaseConnection');</strong>
|
135 |
-
</pre>
|
136 |
-
Ceci génère une classe clone appelée <span class="new_code">MockDatabaseConnection</span>.
|
137 |
-
Nous pouvons désormais créer des instances de
|
138 |
-
cette nouvelle classe à l'intérieur même de notre scénario de test...
|
139 |
-
<pre>
|
140 |
-
require_once('simpletest/unit_tester.php');
|
141 |
-
require_once('simpletest/mock_objects.php');
|
142 |
-
require_once('database_connection.php');
|
143 |
-
|
144 |
-
Mock::generate('DatabaseConnection');
|
145 |
-
<strong>
|
146 |
-
class MyTestCase extends UnitTestCase {
|
147 |
-
|
148 |
-
function testSomething() {
|
149 |
-
$connection = &new MockDatabaseConnection($this);
|
150 |
-
}
|
151 |
-
}</strong>
|
152 |
-
</pre>
|
153 |
-
Contrairement aux bouchons, le constructeur
|
154 |
-
d'une classe fantaisie a besoin d'une référence au scénario
|
155 |
-
de test pour pouvoir transmettre les succès
|
156 |
-
et les échecs pendant qu'il vérifie les attentes.
|
157 |
-
Concrètement ça veut dire que les objets fantaisie
|
158 |
-
ne peuvent être utilisés qu'au sein d'un scénario de test.
|
159 |
-
Malgré tout, cette puissance supplémentaire implique
|
160 |
-
que les bouchons ne sont que rarement utilisés
|
161 |
-
si des objets fantaisie sont disponibles.
|
162 |
-
</p>
|
163 |
-
|
164 |
-
<h2>
|
165 |
-
<a class="target" name="bouchon"></a>Objets fantaisie en action</h2>
|
166 |
-
<p>
|
167 |
-
La version fantaisie d'une classe contient
|
168 |
-
toutes les méthodes de l'originale.
|
169 |
-
De la sorte une opération comme
|
170 |
-
<span class="new_code">$connection->query()</span>
|
171 |
-
est encore possible.
|
172 |
-
Tout comme avec les bouchons, nous pouvons remplacer
|
173 |
-
la valeur nulle renvoyée par défaut...
|
174 |
-
<pre>
|
175 |
-
<strong>$connection->setReturnValue('query', 37);</strong>
|
176 |
-
</pre>
|
177 |
-
Désormais à chaque appel de
|
178 |
-
<span class="new_code">$connection->query()</span>
|
179 |
-
nous recevons comme résultat 37.
|
180 |
-
Tout comme avec les bouchons nous pouvons utiliser
|
181 |
-
des jokers et surcharger le paramètre joker.
|
182 |
-
Nous pouvons aussi ajouter des méthodes supplémentaires
|
183 |
-
à l'objet fantaisie lors de sa génération
|
184 |
-
et lui choisir un nom de classe qui lui soit propre...
|
185 |
-
<pre>
|
186 |
-
<strong>Mock::generate('DatabaseConnection', 'MyMockDatabaseConnection', array('setOptions'));</strong>
|
187 |
-
</pre>
|
188 |
-
Ici l'objet fantaisie se comportera comme
|
189 |
-
si <span class="new_code">setOptions()</span> existait dans la classe originale.
|
190 |
-
C'est pratique si une classe a utilisé le mécanisme
|
191 |
-
<span class="new_code">overload()</span> de PHP pour ajouter des méthodes dynamiques.
|
192 |
-
Vous pouvez créer des fantaisies spéciales pour simuler cette situation.
|
193 |
-
</p>
|
194 |
-
<p>
|
195 |
-
Tous les modèles disponibles avec les bouchons serveur
|
196 |
-
le sont également avec les objets fantaisie...
|
197 |
-
<pre>
|
198 |
-
class Iterator {
|
199 |
-
function Iterator() {
|
200 |
-
}
|
201 |
-
|
202 |
-
function next() {
|
203 |
-
}
|
204 |
-
}
|
205 |
-
</pre>
|
206 |
-
Une nouvelle fois, supposons que cet itérateur
|
207 |
-
ne retourne que du texte jusqu'au moment où il atteint
|
208 |
-
son terme, quand il renvoie <span class="new_code">false</span>.
|
209 |
-
Nous pouvons le simuler avec...
|
210 |
-
<pre>
|
211 |
-
Mock::generate('Iterator');
|
212 |
-
|
213 |
-
class IteratorTest extends UnitTestCase() {
|
214 |
-
|
215 |
-
function testASequence() {<strong>
|
216 |
-
$iterator = &new MockIterator($this);
|
217 |
-
$iterator->setReturnValue('next', false);
|
218 |
-
$iterator->setReturnValueAt(0, 'next', 'First string');
|
219 |
-
$iterator->setReturnValueAt(1, 'next', 'Second string');</strong>
|
220 |
-
...
|
221 |
-
}
|
222 |
-
}
|
223 |
-
</pre>
|
224 |
-
Au moment du premier appel à <span class="new_code">next()</span>
|
225 |
-
sur l'itérateur fantaisie il renverra tout d'abord
|
226 |
-
"First string", puis ce sera au tour de
|
227 |
-
"Second string" au deuxième appel
|
228 |
-
et ensuite pour tout appel suivant <span class="new_code">false</span>
|
229 |
-
sera renvoyé.
|
230 |
-
Ces valeurs renvoyées successivement sont prioritaires
|
231 |
-
sur la valeur constante retournée.
|
232 |
-
Cette dernière est un genre de valeur par défaut si vous voulez.
|
233 |
-
</p>
|
234 |
-
<p>
|
235 |
-
Reprenons aussi le conteneur d'information bouchonné
|
236 |
-
avec des pairs clef / valeur...
|
237 |
-
<pre>
|
238 |
-
class Configuration {
|
239 |
-
function Configuration() {
|
240 |
-
}
|
241 |
-
|
242 |
-
function getValue($key) {
|
243 |
-
}
|
244 |
-
}
|
245 |
-
</pre>
|
246 |
-
Il s'agit là d'une situation classique
|
247 |
-
d'utilisation d'objets fantaisie étant donné
|
248 |
-
que la configuration peut varier grandement de machine à machine :
|
249 |
-
ça contraint fortement la fiabilité de nos tests
|
250 |
-
si nous l'utilisons directement.
|
251 |
-
Le problème est que toutes les données nous parviennent
|
252 |
-
à travers la méthode <span class="new_code">getValue()</span>
|
253 |
-
et que nous voulons des résultats différents pour des clefs différentes.
|
254 |
-
Heureusement les objets fantaisie ont un système de filtrage...
|
255 |
-
<pre>
|
256 |
-
<strong>$config = &new MockConfiguration($this);
|
257 |
-
$config->setReturnValue('getValue', 'primary', array('db_host'));
|
258 |
-
$config->setReturnValue('getValue', 'admin', array('db_user'));
|
259 |
-
$config->setReturnValue('getValue', 'secret', array('db_password'));</strong>
|
260 |
-
</pre>
|
261 |
-
Le paramètre en plus est une liste d'arguments
|
262 |
-
à faire correspondre. Dans ce cas nous essayons
|
263 |
-
de faire correspondre un unique argument :
|
264 |
-
en l'occurrence la clef recherchée.
|
265 |
-
Maintenant que la méthode <span class="new_code">getValue()</span>
|
266 |
-
est invoquée sur l'objet fantaisie...
|
267 |
-
<pre>
|
268 |
-
$config->getValue('db_user')
|
269 |
-
</pre>
|
270 |
-
...elle renverra "admin".
|
271 |
-
Elle le trouve en essayant de faire correspondre
|
272 |
-
les arguments entrants dans sa liste
|
273 |
-
d'arguments sortants les uns après les autres
|
274 |
-
jusqu'au moment où une correspondance exacte est atteinte.
|
275 |
-
</p>
|
276 |
-
<p>
|
277 |
-
Il y a des fois où vous souhaitez
|
278 |
-
qu'un objet spécifique soit servi par la fantaisie
|
279 |
-
plutôt qu'une copie.
|
280 |
-
De nouveau c'est identique au mécanisme des bouchons serveur...
|
281 |
-
<pre>
|
282 |
-
class Thing {
|
283 |
-
}
|
284 |
-
|
285 |
-
class Vector {
|
286 |
-
function Vector() {
|
287 |
-
}
|
288 |
-
|
289 |
-
function get($index) {
|
290 |
-
}
|
291 |
-
}
|
292 |
-
</pre>
|
293 |
-
Dans ce cas vous pouvez placer une référence
|
294 |
-
dans la liste renvoyée par l'objet fantaisie...
|
295 |
-
<pre>
|
296 |
-
$thing = new Thing();<strong>
|
297 |
-
$vector = &new MockVector($this);
|
298 |
-
$vector->setReturnReference('get', $thing, array(12));</strong>
|
299 |
-
</pre>
|
300 |
-
Avec cet arrangement vous savez qu'à chaque appel
|
301 |
-
de <span class="new_code">$vector->get(12)</span>
|
302 |
-
le même <span class="new_code">$thing</span> sera renvoyé.
|
303 |
-
</p>
|
304 |
-
|
305 |
-
<h2>
|
306 |
-
<a class="target" name="attentes"></a>Objets fantaisie en critique</h2>
|
307 |
-
<p>
|
308 |
-
Même si les bouchons serveur vous isolent
|
309 |
-
du désordre du monde réel, il ne s'agit là que
|
310 |
-
de la moitié du bénéfice potentiel.
|
311 |
-
Vous pouvez avoir une classe de test recevant
|
312 |
-
les messages ad hoc, mais est-ce que votre nouvelle classe
|
313 |
-
renvoie bien les bons ?
|
314 |
-
Le tester peut devenir cafouillis sans une librairie d'objets fantaisie.
|
315 |
-
</p>
|
316 |
-
<p>
|
317 |
-
Pour l'exemple, prenons une classe <span class="new_code">SessionPool</span>
|
318 |
-
à laquelle nous allons ajouter une fonction de log.
|
319 |
-
Plutôt que de complexifier la classe originale,
|
320 |
-
nous souhaitons ajouter ce comportement avec un décorateur (GOF).
|
321 |
-
Pour l'instant le code de <span class="new_code">SessionPool</span> ressemble à...
|
322 |
-
<pre>
|
323 |
-
<strong>class SessionPool {
|
324 |
-
function SessionPool() {
|
325 |
-
...
|
326 |
-
}
|
327 |
-
|
328 |
-
function &findSession($cookie) {
|
329 |
-
...
|
330 |
-
}
|
331 |
-
...
|
332 |
-
}
|
333 |
-
|
334 |
-
class Session {
|
335 |
-
...
|
336 |
-
}</strong>
|
337 |
-
|
338 |
-
</pre>
|
339 |
-
Alors que pour notre code de log, nous avons...
|
340 |
-
<pre><strong>
|
341 |
-
class Log {
|
342 |
-
function Log() {
|
343 |
-
...
|
344 |
-
}
|
345 |
-
|
346 |
-
function message() {
|
347 |
-
...
|
348 |
-
}
|
349 |
-
}
|
350 |
-
|
351 |
-
class LoggingSessionPool {
|
352 |
-
function LoggingSessionPool(&$session_pool, &$log) {
|
353 |
-
...
|
354 |
-
}
|
355 |
-
|
356 |
-
function &findSession($cookie) {
|
357 |
-
...
|
358 |
-
}
|
359 |
-
...
|
360 |
-
}</strong>
|
361 |
-
</pre>
|
362 |
-
Dans tout ceci, la seule classe à tester est
|
363 |
-
<span class="new_code">LoggingSessionPool</span>. En particulier,
|
364 |
-
nous voulons vérifier que la méthode <span class="new_code">findSession()</span>
|
365 |
-
est appelée avec le bon identifiant de session au sein du cookie
|
366 |
-
et qu'elle renvoie bien le message "Starting session $cookie"
|
367 |
-
au loggueur.
|
368 |
-
</p>
|
369 |
-
<p>
|
370 |
-
Bien que nous ne testions que quelques lignes
|
371 |
-
de code de production, voici la liste des choses
|
372 |
-
à faire dans un scénario de test conventionnel :
|
373 |
-
<ol>
|
374 |
-
<li>Créer un objet de log.</li>
|
375 |
-
<li>Indiquer le répertoire d'écriture du fichier de log.</li>
|
376 |
-
<li>Modifier les droits sur le répertoire pour pouvoir y écrire le fichier.</li>
|
377 |
-
<li>Créer un objet <span class="new_code">SessionPool</span>.</li>
|
378 |
-
<li>Lancer une session, ce qui demande probablement pas mal de choses.</li>
|
379 |
-
<li>Invoquer <span class="new_code">findSession()</span>.</li>
|
380 |
-
<li>Lire le nouvel identifiant de session (en espérant qu'il existe un accesseur !).</li>
|
381 |
-
<li>Lever une assertion de test pour vérifier que cet identifiant correspond bien au cookie.</li>
|
382 |
-
<li>Lire la dernière ligne du fichier de log.</li>
|
383 |
-
<li>Supprimer avec une (ou plusieurs) expression rationnelle les timestamps de log en trop, etc.</li>
|
384 |
-
<li>Vérifier que le message de session est bien dans le texte.</li>
|
385 |
-
</ol>
|
386 |
-
Pas étonnant que les développeurs détestent
|
387 |
-
écrire des tests quand ils sont aussi ingrats.
|
388 |
-
Pour rendre les choses encore pire, à chaque fois que
|
389 |
-
le format de log change ou bien que la méthode de création
|
390 |
-
des sessions change, nous devons réécrire une partie
|
391 |
-
des tests alors même qu'ils ne testent pas ces parties
|
392 |
-
du système. Nous sommes en train de préparer
|
393 |
-
le cauchemar pour les développeurs de ces autres classes.
|
394 |
-
</p>
|
395 |
-
<p>
|
396 |
-
A la place, voici la méthode complète pour le test
|
397 |
-
avec un peu de magie via les objets fantaisie...
|
398 |
-
<pre>
|
399 |
-
Mock::generate('Session');
|
400 |
-
Mock::generate('SessionPool');
|
401 |
-
Mock::generate('Log');
|
402 |
-
|
403 |
-
class LoggingSessionPoolTest extends UnitTestCase {
|
404 |
-
...
|
405 |
-
function testFindSessionLogging() {<strong>
|
406 |
-
$session = &new MockSession($this);
|
407 |
-
$pool = &new MockSessionPool($this);
|
408 |
-
$pool->setReturnReference('findSession', $session);
|
409 |
-
$pool->expectOnce('findSession', array('abc'));
|
410 |
-
|
411 |
-
$log = &new MockLog($this);
|
412 |
-
$log->expectOnce('message', array('Starting session abc'));
|
413 |
-
|
414 |
-
$logging_pool = &new LoggingSessionPool($pool, $log);
|
415 |
-
$this->assertReference($logging_pool->findSession('abc'), $session);
|
416 |
-
$pool->tally();
|
417 |
-
$log->tally();</strong>
|
418 |
-
}
|
419 |
-
}
|
420 |
-
</pre>
|
421 |
-
Commençons par écrire une session simulacre.
|
422 |
-
Pas la peine d'être trop pointilleux avec
|
423 |
-
celle-ci puisque la vérification de la session
|
424 |
-
désirée est effectuée ailleurs. Nous avons
|
425 |
-
juste besoin de vérifier qu'il s'agit de
|
426 |
-
la même que celle qui vient du groupe commun des sessions.
|
427 |
-
</p>
|
428 |
-
<p>
|
429 |
-
<span class="new_code">findSession()</span> est un méthode fabrique
|
430 |
-
dont la simulation est décrite <a href="#stub">plus haut</a>.
|
431 |
-
Le point de départ vient avec le premier appel
|
432 |
-
<span class="new_code">expectOnce()</span>. Cette ligne indique
|
433 |
-
qu'à chaque fois que <span class="new_code">findSession()</span>
|
434 |
-
est invoqué sur l'objet fantaisie, il vérifiera
|
435 |
-
les arguments entrant. S'il ne reçoit
|
436 |
-
que la chaîne "abc" en tant qu'argument
|
437 |
-
alors un succès est envoyé au testeur unitaire,
|
438 |
-
sinon c'est un échec qui est généré.
|
439 |
-
Il s'agit là de la partie qui teste si nous avons bien
|
440 |
-
la bonne session. La liste des arguments suit
|
441 |
-
une format identique à celui qui précise les valeurs renvoyées.
|
442 |
-
Vous pouvez avoir des jokers et des séquences
|
443 |
-
et l'ordre de l'évaluation restera le même.
|
444 |
-
</p>
|
445 |
-
<p>
|
446 |
-
Si l'appel n'est jamais effectué alors n'est généré
|
447 |
-
ni le succès, ni l'échec. Pour contourner cette limitation,
|
448 |
-
nous devons dire à l'objet fantaisie que le test est terminé :
|
449 |
-
il pourra alors décider si les attentes ont été répondues.
|
450 |
-
L'assertion du testeur unitaire de ceci est déclenchée
|
451 |
-
par l'appel <span class="new_code">tally()</span> à la fin du test.
|
452 |
-
</p>
|
453 |
-
<p>
|
454 |
-
Nous utilisons le même modèle pour mettre sur pied
|
455 |
-
le loggueur fantaisie. Nous lui indiquons que <span class="new_code">message()</span>
|
456 |
-
devrait être invoqué une fois et une fois seulement
|
457 |
-
avec l'argument "Starting session abc".
|
458 |
-
En testant les arguments d'appel, plutôt que ceux de sortie du loggueur,
|
459 |
-
nous isolons le test de tout modification dans le loggueur.
|
460 |
-
</p>
|
461 |
-
<p>
|
462 |
-
Nous commençons le lancement nos tests à la création
|
463 |
-
du nouveau <span class="new_code">LoggingSessionPool</span>
|
464 |
-
et nous l'alimentons avec nos objets fantaisie juste créés.
|
465 |
-
Désormais tout est sous contrôle. Au final nous confirmons
|
466 |
-
que le <span class="new_code">$session</span> donné au décorateur est bien
|
467 |
-
celui reçu et prions les objets fantaisie de lancer leurs
|
468 |
-
tests de comptage d'appel interne avec les appels <span class="new_code">tally()</span>.
|
469 |
-
</p>
|
470 |
-
<p>
|
471 |
-
Il y a encore pas mal de code de test, mais ce code est très strict.
|
472 |
-
S'il vous semble encore terrifiant il l'est bien moins
|
473 |
-
que si nous avions essayé sans les objets fantaisie
|
474 |
-
et ce test en particulier, interactions plutôt que résultat,
|
475 |
-
est toujours plus difficile à mettre en place.
|
476 |
-
Le plus souvent vous aurez besoin de tester des situations
|
477 |
-
plus complexes sans ce niveau ni cette précision.
|
478 |
-
En outre une partie peut être remaniée avec la méthode
|
479 |
-
de scénario de test <span class="new_code">setUp()</span>.
|
480 |
-
</p>
|
481 |
-
<p>
|
482 |
-
Voici la liste complète des attentes que vous pouvez
|
483 |
-
placer sur un objet fantaisie avec
|
484 |
-
<a href="http://www.lastcraft.com/simple_test.php">SimpleTest</a>...
|
485 |
-
<table>
|
486 |
-
<thead>
|
487 |
-
<tr>
|
488 |
-
<th>Attente</th>
|
489 |
-
<th>Nécessite <span class="new_code">tally()</span>
|
490 |
-
</th>
|
491 |
-
</tr>
|
492 |
-
</thead>
|
493 |
-
<tbody>
|
494 |
-
<tr>
|
495 |
-
<td><span class="new_code">expectArguments($method, $args)</span></td>
|
496 |
-
<td style="text-align: center">Non</td>
|
497 |
-
</tr>
|
498 |
-
<tr>
|
499 |
-
<td><span class="new_code">expectArgumentsAt($timing, $method, $args)</span></td>
|
500 |
-
<td style="text-align: center">Non</td>
|
501 |
-
</tr>
|
502 |
-
<tr>
|
503 |
-
<td><span class="new_code">expectCallCount($method, $count)</span></td>
|
504 |
-
<td style="text-align: center">Oui</td>
|
505 |
-
</tr>
|
506 |
-
<tr>
|
507 |
-
<td><span class="new_code">expectMaximumCallCount($method, $count)</span></td>
|
508 |
-
<td style="text-align: center">Non</td>
|
509 |
-
</tr>
|
510 |
-
<tr>
|
511 |
-
<td><span class="new_code">expectMinimumCallCount($method, $count)</span></td>
|
512 |
-
<td style="text-align: center">Oui</td>
|
513 |
-
</tr>
|
514 |
-
<tr>
|
515 |
-
<td><span class="new_code">expectNever($method)</span></td>
|
516 |
-
<td style="text-align: center">Non</td>
|
517 |
-
</tr>
|
518 |
-
<tr>
|
519 |
-
<td><span class="new_code">expectOnce($method, $args)</span></td>
|
520 |
-
<td style="text-align: center">Oui</td>
|
521 |
-
</tr>
|
522 |
-
<tr>
|
523 |
-
<td><span class="new_code">expectAtLeastOnce($method, $args)</span></td>
|
524 |
-
<td style="text-align: center">Oui</td>
|
525 |
-
</tr>
|
526 |
-
</tbody>
|
527 |
-
</table>
|
528 |
-
Où les paramètres sont...
|
529 |
-
<dl>
|
530 |
-
<dt class="new_code">$method</dt>
|
531 |
-
<dd>Le nom de la méthode, sous la forme d'une chaîne,
|
532 |
-
à laquelle la condition doit être appliquée.</dd>
|
533 |
-
<dt class="new_code">$args</dt>
|
534 |
-
<dd>
|
535 |
-
Les arguments sous la forme d'une liste.
|
536 |
-
Les jokers peuvent être inclus de la même manière
|
537 |
-
qu'avec <span class="new_code">setReturn()</span>.
|
538 |
-
Cet argument est optionnel pour <span class="new_code">expectOnce()</span>
|
539 |
-
et <span class="new_code">expectAtLeastOnce()</span>.
|
540 |
-
</dd>
|
541 |
-
<dt class="new_code">$timing</dt>
|
542 |
-
<dd>
|
543 |
-
Le seul point dans le temps pour tester
|
544 |
-
la condition. Le premier appel commence à zéro.
|
545 |
-
</dd>
|
546 |
-
<dt class="new_code">$count</dt>
|
547 |
-
<dd>Le nombre d'appels attendu.</dd>
|
548 |
-
</dl>
|
549 |
-
La méthode <span class="new_code">expectMaximumCallCount()</span>
|
550 |
-
est légèrement différente dans le sens où elle ne pourra
|
551 |
-
générer qu'un échec. Elle reste silencieuse
|
552 |
-
si la limite n'est jamais atteinte.
|
553 |
-
</p>
|
554 |
-
<p>
|
555 |
-
Par ailleurs si vous avez just un appel dans votre test,
|
556 |
-
vérifiez bien que vous utiliser
|
557 |
-
<span class="new_code">expectOnce</span>.<br>
|
558 |
-
Utiliser <span class="new_code">$mocked->expectAt(0, 'method', 'args);</span>
|
559 |
-
tout seul ne sera pas pris en compte :
|
560 |
-
la vérification des arguments et le comptage total
|
561 |
-
sont pour l'instant encore indépendant.
|
562 |
-
</p>
|
563 |
-
<p>
|
564 |
-
Comme avec les assertions dans les scénarios de test,
|
565 |
-
toutes ces attentes peuvent accepter une surcharge de
|
566 |
-
message sous la forme d'un paramètre supplémentaire.
|
567 |
-
Par ailleurs le message d'échec original peut être inclus
|
568 |
-
dans le résultat avec "%s".
|
569 |
-
</p>
|
570 |
-
|
571 |
-
<h2>
|
572 |
-
<a class="target" name="approches"></a>D'autres approches</h2>
|
573 |
-
<p>
|
574 |
-
Il existe trois approches pour créer des objets
|
575 |
-
fantaisie en comprenant celle utilisée par SimpleTest.
|
576 |
-
Les coder à la main en utilisant une classe de base,
|
577 |
-
les générer dans un fichier ou les générer dynamiquement à la volée.
|
578 |
-
</p>
|
579 |
-
<p>
|
580 |
-
Les objets fantaisie générés avec
|
581 |
-
<a href="simple_test.html">SimpleTest</a> sont dynamiques.
|
582 |
-
Ils sont créés à l'exécution dans la mémoire,
|
583 |
-
grâce à <span class="new_code">eval()</span>, plutôt qu'écrits dans un fichier.
|
584 |
-
Cette opération les rend facile à créer,
|
585 |
-
en une seule ligne, surtout par rapport à leur création
|
586 |
-
à la main dans une hiérarchie de classe parallèle.
|
587 |
-
Le problème avec ce comportement tient généralement
|
588 |
-
dans la mise en place des tests proprement dits.
|
589 |
-
Si les objets originaux changent les versions fantaisie
|
590 |
-
sur lesquels reposent les tests, une désynchronisation peut subvenir.
|
591 |
-
Cela peut aussi arriver avec l'approche en hiérarchie parallèle,
|
592 |
-
mais c'est détecté beaucoup plus vite.
|
593 |
-
</p>
|
594 |
-
<p>
|
595 |
-
Bien sûr, la solution est d'ajouter de véritables tests d'intégration.
|
596 |
-
Vous n'en avez pas besoin de beaucoup
|
597 |
-
et le côté pratique des objets fantaisie fait plus
|
598 |
-
que compenser la petite dose de test supplémentaire.
|
599 |
-
Vous ne pouvez pas avoir confiance dans du code qui
|
600 |
-
ne serait testé que par des objets fantaisie.
|
601 |
-
</p>
|
602 |
-
<p>
|
603 |
-
Si vous restez déterminé de construire des librairies
|
604 |
-
statiques d'objets fantaisie parce que vous souhaitez
|
605 |
-
émuler un comportement très spécifique,
|
606 |
-
vous pouvez y parvenir grâce au générateur de classe de SimpleTest.
|
607 |
-
Dans votre fichier librairie, par exemple
|
608 |
-
<em>mocks/connection.php</em> pour une connexion à une base de données,
|
609 |
-
créer un objet fantaisie et provoquer l'héritage
|
610 |
-
pour hériter pour surcharger des méthodes spéciales
|
611 |
-
ou ajouter des préréglages...
|
612 |
-
<pre>
|
613 |
-
<?php
|
614 |
-
require_once('simpletest/mock_objects.php');
|
615 |
-
require_once('../classes/connection.php');
|
616 |
-
<strong>
|
617 |
-
Mock::generate('Connection', 'BasicMockConnection');
|
618 |
-
class MockConnection extends BasicMockConnection {
|
619 |
-
function MockConnection(&$test, $wildcard = '*') {
|
620 |
-
$this->BasicMockConnection($test, $wildcard);
|
621 |
-
$this->setReturn('query', false);
|
622 |
-
}
|
623 |
-
}</strong>
|
624 |
-
?>
|
625 |
-
</pre>
|
626 |
-
L'appel <span class="new_code">generate</span> dit au générateur de classe
|
627 |
-
d'en créer une appelée <span class="new_code">BasicMockConnection</span>
|
628 |
-
plutôt que la plus courante <span class="new_code">MockConnection</span>.
|
629 |
-
Ensuite nous héritons à partir de celle-ci pour obtenir
|
630 |
-
notre version de <span class="new_code">MockConnection</span>.
|
631 |
-
En interceptant de cette manière nous pouvons ajouter
|
632 |
-
un comportement, ici transformer la valeur par défaut de
|
633 |
-
<span class="new_code">query()</span> en "false".
|
634 |
-
En utilisant le nom par défaut nous garantissons
|
635 |
-
que le générateur de classe fantaisie n'en recréera
|
636 |
-
pas une autre différente si il est invoqué ailleurs
|
637 |
-
dans les tests. Il ne créera jamais de classe
|
638 |
-
si elle existe déjà. Aussi longtemps que le fichier
|
639 |
-
ci-dessus est inclus avant alors tous les tests qui
|
640 |
-
généraient <span class="new_code">MockConnection</span> devraient
|
641 |
-
utiliser notre version à présent. Par contre si
|
642 |
-
nous avons une erreur dans l'ordre et que la librairie
|
643 |
-
de fantaisie en crée une d'abord alors la création
|
644 |
-
de la classe échouera tout simplement.
|
645 |
-
</p>
|
646 |
-
<p>
|
647 |
-
Utiliser cette astuce si vous vous trouvez avec beaucoup
|
648 |
-
de comportement en commun sur les objets fantaisie
|
649 |
-
ou si vous avez de fréquents problèmes d'intégration
|
650 |
-
plus tard dans les étapes de test.
|
651 |
-
</p>
|
652 |
-
|
653 |
-
<h2>
|
654 |
-
<a class="target" name="autres_testeurs"></a>Je pense que SimpleTest pue !</h2>
|
655 |
-
<p>
|
656 |
-
Mais au moment d'écrire ces lignes c'est le seul
|
657 |
-
à gérer les objets fantaisie, donc vous êtes bloqué avec lui ?
|
658 |
-
</p>
|
659 |
-
<p>
|
660 |
-
Non, pas du tout.
|
661 |
-
<a href="simple_test.html">SimpleTest</a> est une boîte à outils
|
662 |
-
et parmi ceux-ci on trouve les objets fantaisie
|
663 |
-
qui peuvent être utilisés indépendamment.
|
664 |
-
Supposons que vous avez votre propre testeur unitaire favori
|
665 |
-
et que tous vos tests actuels l'utilisent.
|
666 |
-
Prétendez que vous avez appelé votre tester unitaire PHPUnit
|
667 |
-
(c'est ce que tout le monde a fait) et que la classe principale
|
668 |
-
de test ressemble à...
|
669 |
-
<pre>
|
670 |
-
class PHPUnit {
|
671 |
-
function PHPUnit() {
|
672 |
-
}
|
673 |
-
|
674 |
-
function assertion($message, $assertion) {
|
675 |
-
}
|
676 |
-
...
|
677 |
-
}
|
678 |
-
</pre>
|
679 |
-
La seule chose que la méthode <span class="new_code">assertion()</span> réalise,
|
680 |
-
c'est de préparer une sortie embellie alors le paramètre boolien
|
681 |
-
de l'assertion sert à déterminer s'il s'agit d'une erreur ou d'un succès.
|
682 |
-
Supposons qu'elle est utilisée de la manière suivante...
|
683 |
-
<pre>
|
684 |
-
$unit_test = new PHPUnit();
|
685 |
-
$unit_test>assertion('I hope this file exists', file_exists('my_file'));
|
686 |
-
</pre>
|
687 |
-
Comment utiliser les objets fantaisie avec ceci ?
|
688 |
-
</p>
|
689 |
-
<p>
|
690 |
-
Il y a une méthode protégée sur la classe de base
|
691 |
-
des objets fantaisie : elle s'appelle <span class="new_code">_assertTrue()</span>.
|
692 |
-
En surchargeant cette méthode nous pouvons utiliser
|
693 |
-
notre propre format d'assertion.
|
694 |
-
Nous commençons avec une sous-classe, dans <em>my_mock.php</em>...
|
695 |
-
<pre>
|
696 |
-
<strong><?php
|
697 |
-
require_once('simpletest/mock_objects.php');
|
698 |
-
|
699 |
-
class MyMock extends SimpleMock() {
|
700 |
-
function MyMock(&$test, $wildcard) {
|
701 |
-
$this->SimpleMock($test, $wildcard);
|
702 |
-
}
|
703 |
-
|
704 |
-
function _assertTrue($assertion, $message) {
|
705 |
-
$test = &$this->getTest();
|
706 |
-
$test->assertion($message, $assertion);
|
707 |
-
}
|
708 |
-
}
|
709 |
-
?></strong>
|
710 |
-
</pre>
|
711 |
-
Maintenant une instance de <span class="new_code">MyMock</span>
|
712 |
-
créera un objet qui parle le même langage que votre testeur.
|
713 |
-
Bien sûr le truc c'est que nous créons jamais un tel objet :
|
714 |
-
le générateur s'en chargera. Nous avons juste besoin
|
715 |
-
d'une ligne de code supplémentaire pour dire au générateur
|
716 |
-
d'utiliser vos nouveaux objets fantaisie...
|
717 |
-
<pre>
|
718 |
-
<?php
|
719 |
-
require_once('simpletst/mock_objects.php');
|
720 |
-
|
721 |
-
class MyMock extends SimpleMock() {
|
722 |
-
function MyMock($test, $wildcard) {
|
723 |
-
$this->SimpleMock(&$test, $wildcard);
|
724 |
-
}
|
725 |
-
|
726 |
-
function _assertTrue($assertion, $message , &$test) {
|
727 |
-
$test->assertion($message, $assertion);
|
728 |
-
}
|
729 |
-
}<strong>
|
730 |
-
SimpleTestOptions::setMockBaseClass('MyMock');</strong>
|
731 |
-
?>
|
732 |
-
</pre>
|
733 |
-
A partir de maintenant vous avez juste à inclure
|
734 |
-
<em>my_mock.php</em> à la place de la version par défaut
|
735 |
-
<em>simple_mock.php</em> et vous pouvez introduire
|
736 |
-
des objets fantaisie dans votre suite de tests existants.
|
737 |
-
</p>
|
738 |
-
|
739 |
-
</div>
|
740 |
-
References and related information...
|
741 |
-
<ul>
|
742 |
-
<li>
|
743 |
-
L'article originel sur
|
744 |
-
<a href="http://www.mockobjects.com/">les objets fantaisie</a>.
|
745 |
-
</li>
|
746 |
-
<li>
|
747 |
-
La page du projet SimpleTest sur
|
748 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
749 |
-
</li>
|
750 |
-
<li>
|
751 |
-
La page d'accueil de SimpleTest sur
|
752 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
753 |
-
</li>
|
754 |
-
</ul>
|
755 |
-
<div class="menu_back"><div class="menu">
|
756 |
-
<a href="index.html">SimpleTest</a>
|
757 |
-
|
|
758 |
-
<a href="overview.html">Overview</a>
|
759 |
-
|
|
760 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
761 |
-
|
|
762 |
-
<a href="group_test_documentation.html">Group tests</a>
|
763 |
-
|
|
764 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
765 |
-
|
|
766 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
767 |
-
|
|
768 |
-
<a href="reporter_documentation.html">Reporting</a>
|
769 |
-
|
|
770 |
-
<a href="expectation_documentation.html">Expectations</a>
|
771 |
-
|
|
772 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
773 |
-
|
|
774 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
775 |
-
|
|
776 |
-
<a href="authentication_documentation.html">Authentication</a>
|
777 |
-
|
|
778 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
779 |
-
</div></div>
|
780 |
-
<div class="copyright">
|
781 |
-
Copyright<br>Marcus Baker 2006
|
782 |
-
</div>
|
783 |
-
</body>
|
784 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/overview.html
DELETED
@@ -1,321 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>
|
5 |
-
Aperçu et liste des fonctionnalités des testeurs unitaires PHP et web de SimpleTest PHP
|
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 |
-
<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>Apercu de SimpleTest</h1>
|
36 |
-
This page...
|
37 |
-
<ul>
|
38 |
-
<li>
|
39 |
-
<a href="#resume">Résumé rapide</a> de l'outil SimpleTest pour PHP.
|
40 |
-
</li>
|
41 |
-
<li>
|
42 |
-
<a href="#fonctionnalites">La liste des fonctionnalites</a>, à la fois présentes et à venir.
|
43 |
-
</li>
|
44 |
-
<li>
|
45 |
-
Il y a beaucoup de <a href="#ressources">ressources sur les tests unitaires</a> sur le web.
|
46 |
-
</li>
|
47 |
-
</ul>
|
48 |
-
<div class="content">
|
49 |
-
<h2>
|
50 |
-
<a class="target" name="resume"></a>Qu'est-ce que SimpleTest ?</h2>
|
51 |
-
<p>
|
52 |
-
Le coeur de SimpleTest est un framework de test construit autour de classes de scénarios de test. Celles-ci sont écrites comme des extensions des classes premières de scénarios de test, chacune élargie avec des méthodes qui contiennent le code de test effectif. Les scripts de test de haut niveau invoque la méthode <span class="new_code">run()</span> à chaque scénario de test successivement. Chaque méthode de test est écrite pour appeler des assertions diverses que le développeur suppose être vraies, <span class="new_code">assertEqual()</span> par exemple. Si l'assertion est correcte, alors un succès est expédié au rapporteur observant le test, mais toute erreur déclenche une alerte et une description de la dissension.
|
53 |
-
</p>
|
54 |
-
<p>
|
55 |
-
Un <a href="unit_test_documentation.html">scénario de test</a> ressemble à...
|
56 |
-
<pre>
|
57 |
-
class <strong>MyTestCase</strong> extends UnitTestCase {
|
58 |
-
<strong>
|
59 |
-
function testLog() {
|
60 |
-
$log = &new Log('my.log');
|
61 |
-
$log->message('Hello');
|
62 |
-
$this->assertTrue(file_exists('my.log'));
|
63 |
-
}</strong>
|
64 |
-
}
|
65 |
-
</pre>
|
66 |
-
</p>
|
67 |
-
<p>
|
68 |
-
Ces outils sont conçus pour le développeur. Les tests sont écrits en PHP directement, plus ou moins simultanément avec la construction de l'application elle-même. L'avantage d'utiliser PHP lui-même comme langage de test est qu'il n'y a pas de nouveau langage à apprendre, les tests peuvent commencer directement et le développeur peut tester n'importe quelle partie du code. Plus simplement, toutes les parties qui peuvent être accédées par le code de l'application peuvent aussi être accédées par le code de test si ils sont tous les deux dans le même langage.
|
69 |
-
</p>
|
70 |
-
<p>
|
71 |
-
Le type de scénario de test le plus simple est le <span class="new_code">UnitTestCase</span>. Cette classe de scénario de test inclut les tests standards pour l'égalité, les références et l'appariement de motifs (via les expressions rationnelles). Ceux-ci testent ce que vous seriez en droit d'attendre du résultat d'une fonction ou d'une méthode. Il s'agit du type de test le plus commun pendant le quotidien du développeur, peut-être 95% des scénarios de test.
|
72 |
-
</p>
|
73 |
-
<p>
|
74 |
-
La tâche ultime d'une application web n'est cependant pas de produire une sortie correcte à partir de méthodes ou d'objets, mais plutôt de produire des pages web. La classe <span class="new_code">WebTestCase</span> teste des pages web. Elle simule un navigateur web demandant une page, de façon exhaustive : cookies, proxies, connexions sécurisées, authentification, formulaires, cadres et la plupart des éléments de navigation. Avec ce type de scénario de test, le développeur peut garantir que telle ou telle information est présente dans la page et que les formulaires ainsi que les sessions sont gérés comme il faut.
|
75 |
-
</p>
|
76 |
-
<p>
|
77 |
-
Un <a href="web_tester_documentation.html">scénario de test web</a> ressemble à...
|
78 |
-
<pre>
|
79 |
-
class <strong>MySiteTest</strong> extends WebTestCase {
|
80 |
-
<strong>
|
81 |
-
function testHomePage() {
|
82 |
-
$this->get('http://www.my-site.com/index.php');
|
83 |
-
$this->assertTitle('My Home Page');
|
84 |
-
$this->clickLink('Contact');
|
85 |
-
$this->assertTitle('Contact me');
|
86 |
-
$this->assertWantedPattern('/Email me at/');
|
87 |
-
}</strong>
|
88 |
-
}
|
89 |
-
</pre>
|
90 |
-
</p>
|
91 |
-
|
92 |
-
<h2>
|
93 |
-
<a class="target" name="fonctionnalites"></a>Liste des fonctionnalites</h2>
|
94 |
-
<p>
|
95 |
-
Ci-dessous vous trouverez un canevas assez brut des fonctionnalités à aujourd'hui et pour demain, sans oublier leur date approximative de publication. J'ai bien peur qu'il soit modifiable sans pré-avis étant donné que les jalons dépendent beaucoup sur le temps disponible. Les trucs en vert ont été codés, mais pas forcément déjà rendus public. Si vous avez une besoin pressant pour une fonctionnalité verte mais pas encore publique alors vous devriez retirer le code directement sur le CVS chez SourceFourge. Une fonctionnalitée publiée est indiqué par "Fini".
|
96 |
-
<table>
|
97 |
-
<thead>
|
98 |
-
<tr>
|
99 |
-
<th>Fonctionnalité</th>
|
100 |
-
<th>Description</th>
|
101 |
-
<th>Publication</th>
|
102 |
-
</tr>
|
103 |
-
</thead>
|
104 |
-
<tbody>
|
105 |
-
<tr>
|
106 |
-
<td>Scénariot de test unitaire</td>
|
107 |
-
<td>Les classes de test et assertions de base</td>
|
108 |
-
<td style="color: green;">Fini</td>
|
109 |
-
</tr>
|
110 |
-
<tr>
|
111 |
-
<td>Affichage HTML</td>
|
112 |
-
<td>L'affichage le plus simple possible</td>
|
113 |
-
<td style="color: green;">Fini</td>
|
114 |
-
</tr>
|
115 |
-
<tr>
|
116 |
-
<td>Autochargement des scénarios de test</td>
|
117 |
-
<td>Lire un fichier avec des scénarios de test et les charger dans un groupe de tests automatiquement</td>
|
118 |
-
<td style="color: green;">Fini</td>
|
119 |
-
</tr>
|
120 |
-
<tr>
|
121 |
-
<td>Générateur de code d'objets fantaisie</td>
|
122 |
-
<td>Des objets capable de simuler d'autres objets, supprimant les dépendances dans les tests</td>
|
123 |
-
<td style="color: green;">Fini</td>
|
124 |
-
</tr>
|
125 |
-
<tr>
|
126 |
-
<td>Bouchons serveur</td>
|
127 |
-
<td>Des objets fantaisie sans résultat attendu à utiliser à l'extérieur des scénarios de test, pour le prototypage par exemple.</td>
|
128 |
-
<td style="color: green;">Fini</td>
|
129 |
-
</tr>
|
130 |
-
<tr>
|
131 |
-
<td>Intégration d'autres testeurs unitaires</td>
|
132 |
-
<td>
|
133 |
-
La capacité de lire et simuler d'autres scénarios de test en provenance de PHPUnit et de PEAR::Phpunit.</td>
|
134 |
-
<td style="color: green;">Fini</td>
|
135 |
-
</tr>
|
136 |
-
<tr>
|
137 |
-
<td>Scénario de test web</td>
|
138 |
-
<td>Appariement basique de motifs dans une page téléchargée.</td>
|
139 |
-
<td style="color: green;">Fini</td>
|
140 |
-
</tr>
|
141 |
-
<tr>
|
142 |
-
<td>Analyse de page HTML</td>
|
143 |
-
<td>Permet de suivre les liens et de trouver la balise de titre</td>
|
144 |
-
<td style="color: green;">Fini</td>
|
145 |
-
</tr>
|
146 |
-
<tr>
|
147 |
-
<td>Simulacre partiel</td>
|
148 |
-
<td>Simuler des parties d'une classe pour tester moins qu'une classe ou dans des cas complexes.</td>
|
149 |
-
<td style="color: green;">Fini</td>
|
150 |
-
</tr>
|
151 |
-
<tr>
|
152 |
-
<td>Gestion des cookies Web</td>
|
153 |
-
<td>Gestion correcte des cookies au téléchargement d'une page.</td>
|
154 |
-
<td style="color: green;">Fini</td>
|
155 |
-
</tr>
|
156 |
-
<tr>
|
157 |
-
<td>Suivi des redirections</td>
|
158 |
-
<td>Le téléchargement d'une page suit automatiquement une redirection 300.</td>
|
159 |
-
<td style="color: green;">Fini</td>
|
160 |
-
</tr>
|
161 |
-
<tr>
|
162 |
-
<td>Analyse d'un formulaire</td>
|
163 |
-
<td>La capacité de valider un formulaire simple et d'en lire les valeurs par défaut.</td>
|
164 |
-
<td style="color: green;">Fini</td>
|
165 |
-
</tr>
|
166 |
-
<tr>
|
167 |
-
<td>Interface en ligne de commande</td>
|
168 |
-
<td>Affiche le résultat des tests sans navigateur web.</td>
|
169 |
-
<td style="color: green;">Fini</td>
|
170 |
-
</tr>
|
171 |
-
<tr>
|
172 |
-
<td>Mise à nu des attentes d'une classe</td>
|
173 |
-
<td>Peut créer des tests précis avec des simulacres ainsi que des scénarios de test.</td>
|
174 |
-
<td style="color: green;">Fini</td>
|
175 |
-
</tr>
|
176 |
-
<tr>
|
177 |
-
<td>Sortie et analyse XML</td>
|
178 |
-
<td>Permet de tester sur plusieurs hôtes et d'intégrer des extensions d'acceptation de test.</td>
|
179 |
-
<td style="color: green;">Fini</td>
|
180 |
-
</tr>
|
181 |
-
<tr>
|
182 |
-
<td>Scénario de test en ligne de commande</td>
|
183 |
-
<td>Permet de tester des outils ou scripts en ligne de commande et de manier des fichiers.</td>
|
184 |
-
<td style="color: green;">Fini</td>
|
185 |
-
</tr>
|
186 |
-
<tr>
|
187 |
-
<td>Compatibilité avec PHP Documentor</td>
|
188 |
-
<td>Génération automatique et complète de la documentation au niveau des classes.</td>
|
189 |
-
<td style="color: green;">Fini</td>
|
190 |
-
</tr>
|
191 |
-
<tr>
|
192 |
-
<td>Interface navigateur</td>
|
193 |
-
<td>Mise à nu des niveaux bas de l'interface du navigateur web pour des scénarios de test plus précis.</td>
|
194 |
-
<td style="color: green;">Fini</td>
|
195 |
-
</tr>
|
196 |
-
<tr>
|
197 |
-
<td>Authentification HTTP</td>
|
198 |
-
<td>Téléchargement des pages web protégées avec une authentification basique seulement.</td>
|
199 |
-
<td style="color: green;">Fini</td>
|
200 |
-
</tr>
|
201 |
-
<tr>
|
202 |
-
<td>Boutons de navigation d'un navigateur</td>
|
203 |
-
<td>Arrière, avant et recommencer</td>
|
204 |
-
<td style="color: green;">Fini</td>
|
205 |
-
</tr>
|
206 |
-
<tr>
|
207 |
-
<td>Support de SSL</td>
|
208 |
-
<td>Peut se connecter à des pages de type https.</td>
|
209 |
-
<td style="color: green;">Fini</td>
|
210 |
-
</tr>
|
211 |
-
<tr>
|
212 |
-
<td>Support de proxy</td>
|
213 |
-
<td>Peut se connecter via des proxys communs</td>
|
214 |
-
<td style="color: green;">Fini</td>
|
215 |
-
</tr>
|
216 |
-
<tr>
|
217 |
-
<td>Support des cadres</td>
|
218 |
-
<td>Gère les cadres dans les scénarios de test web.</td>
|
219 |
-
<td style="color: green;">Fini</td>
|
220 |
-
</tr>
|
221 |
-
<tr>
|
222 |
-
<td>Test de l'upload de fichier</td>
|
223 |
-
<td>Peut simuler la balise input de type file</td>
|
224 |
-
<td style="color: red;">1.0.1</td>
|
225 |
-
</tr>
|
226 |
-
<tr>
|
227 |
-
<td>Amélioration sur la machinerie des rapports</td>
|
228 |
-
<td>Retouche sur la transmission des messages pour une meilleur coopération avec les IDEs</td>
|
229 |
-
<td style="color: red;">1.1</td>
|
230 |
-
</tr>
|
231 |
-
<tr>
|
232 |
-
<td>Amélioration de l'affichage des tests</td>
|
233 |
-
<td>Une meilleure interface graphique web, avec un arbre des scénarios de test.</td>
|
234 |
-
<td style="color: red;">1.1</td>
|
235 |
-
</tr>
|
236 |
-
<tr>
|
237 |
-
<td>Localisation</td>
|
238 |
-
<td>Abstraction des messages et génration du code à partir de fichiers XML.</td>
|
239 |
-
<td style="color: red;">1.1</td>
|
240 |
-
</tr>
|
241 |
-
<tr>
|
242 |
-
<td>Simulation d'interface</td>
|
243 |
-
<td>Peut générer des objets fantaisie tant vers des interfaces que vers des classes.</td>
|
244 |
-
<td style="color: red;">2.0</td>
|
245 |
-
</tr>
|
246 |
-
<tr>
|
247 |
-
<td>Test sur es exceptions</td>
|
248 |
-
<td>Dans le même esprit que sur les tests des erreurs PHP.</td>
|
249 |
-
<td style="color: red;">2.0</td>
|
250 |
-
</tr>
|
251 |
-
<tr>
|
252 |
-
<td>Rercherche d'éléments avec XPath</td>
|
253 |
-
<td>Peut utiliser Tidy HTML pour un appariement plus rapide et plus souple.</td>
|
254 |
-
<td style="color: red;">2.0</td>
|
255 |
-
</tr>
|
256 |
-
</tbody>
|
257 |
-
</table>
|
258 |
-
La migration vers PHP5 commencera juste après la série des 1.0, à partir de là PHP4 ne sera plus supporté. SimpleTest est actuellement compatible avec PHP5 mais n'utilisera aucune des nouvelles fonctionnalités avant la version 2.
|
259 |
-
</p>
|
260 |
-
|
261 |
-
<h2>
|
262 |
-
<a class="target" name="ressources"></a>Ressources sur le web pour les tests</h2>
|
263 |
-
<p>
|
264 |
-
Le processus est au moins aussi important que les outils. Le type de procédure que fait un usage le plus intensif des outils de test pour développeur est bien sûr l'<a href="http://www.extremeprogramming.org/">Extreme Programming</a>. Il s'agit là d'une des <a href="http://www.agilealliance.com/articles/index">méthodes agiles</a> qui combinent plusieurs pratiques pour "lisser la courbe de coût" du développement logiciel. La plus extrème reste le <a href="http://www.testdriven.com/modules/news/">développement piloté par les tests</a>, où vous devez adhérer à la règle du <cite>pas de code avant d'avoir un test</cite>. Si vous êtes plutôt du genre planninficateur ou que vous estimez que l'expérience compte plus que l'évolution, vous préférerez peut-être l'approche <a href="http://www.therationaledge.com/content/dec_01/f_spiritOfTheRUP_pk.html">RUP</a>. Je ne l'ai pas testé mais je peux voir où vous aurez besoin d'outils de test (cf. illustration 9).
|
265 |
-
</p>
|
266 |
-
<p>
|
267 |
-
La plupart des testeurs unitaires sont dans une certaine mesure un clone de <a href="http://www.junit.org/">JUnit</a>, au moins dans l'interface. Il y a énormément d'information sur le site de JUnit, à commencer par la <a href="http://junit.sourceforge.net/doc/faq/faq.htm">FAQ</a> quie contient pas mal de conseils généraux sur les tests. Une fois mordu par le bogue vous apprécierez sûrement la phrase <a href="http://junit.sourceforge.net/doc/testinfected/testing.htm">infecté par les tests</a> trouvée par Eric Gamma. Si vous êtes encore en train de tergiverser sur un testeur unitaire, sachez que les choix principaux sont <a href="http://phpunit.sourceforge.net/">PHPUnit</a> et <a href="http://pear.php.net/manual/en/package.php.phpunit.php">Pear PHP::PHPUnit</a>. De nombreuses fonctionnalités de SimpleTest leurs font défaut, mais la version PEAR a d'ores et déjà été mise à jour pour PHP5. Elle est aussi recommandée si vous portez des scénarios de test existant depuis <a href="http://www.junit.org/">JUnit</a>.
|
268 |
-
</p>
|
269 |
-
<p>
|
270 |
-
Les développeurs de bibliothèque n'ont pas l'air de livrer très souvent des tests avec leur code : c'est bien dommage. Le code d'une bibliothèque qui inclut des tests peut être remanié avec plus de sécurité et le code de test sert de documentation additionnelle dans un format assez standard. Ceci peut épargner la pêche aux indices dans le code source lorsque qu'un problème survient, en particulier lors de la mise à jour d'une telle bibliothèque. Parmi les bibliothèques utilisant SimpleTest comme testeur unitaire on retrouve <a href="http://wact.sourceforge.net/">WACT</a> et <a href="http://sourceforge.net/projects/htmlsax">PEAR::XML_HTMLSax</a>.
|
271 |
-
</p>
|
272 |
-
<p>
|
273 |
-
Au jour d'aujourd'hui il manque tristement beaucoup de matière sur les objets fantaisie : dommage, surtout que tester unitairement sans eux représente pas mal de travail en plus. L'<a href="http://www.sidewize.com/company/mockobjects.pdf">article original sur les objets fantaisie</a> est très orienté Java, mais reste intéressant à lire. Etant donné qu'il s'agit d'une nouvelle technologie il y a beaucoup de discussions et de débats sur comment les utiliser, souvent sur des wikis comme <a href="http://xpdeveloper.com/cgi-bin/oldwiki.cgi?MockObjects">Extreme Tuesday</a> ou <a href="http://www.mockobjects.com/MocksObjectsPaper.html">www.mockobjects.com</a>ou <a href="http://c2.com/cgi/wiki?MockObject">the original C2 Wiki</a>. Injecter des objets fantaisie dans une classe est un des champs principaux du débat : cet <a href="http://www-106.ibm.com/developerworks/java/library/j-mocktest.html">article chez IBM</a> en est un bon point de départ.
|
274 |
-
</p>
|
275 |
-
<p>
|
276 |
-
Il y a énormement d'outils de test web mais la plupart sont écrits en Java. De plus les tutoriels et autres conseils sont plutôt rares. Votre seul espoir est de regarder directement la documentation pour <a href="http://httpunit.sourceforge.net/">HTTPUnit</a>, <a href="http://htmlunit.sourceforge.net/">HTMLUnit</a> ou <a href="http://jwebunit.sourceforge.net/">JWebUnit</a> et d'espérer y trouver pour des indices. Il y a aussi des frameworks basés sur XML, mais de nouveau la plupart ont besoin de Java pour tourner.
|
277 |
-
</p>
|
278 |
-
|
279 |
-
</div>
|
280 |
-
References and related information...
|
281 |
-
<ul>
|
282 |
-
<li>
|
283 |
-
<a href="unit_test_documentation.html">Documentation pour SimpleTest</a>.
|
284 |
-
</li>
|
285 |
-
<li>
|
286 |
-
<a href="http://www.lastcraft.com/first_test_tutorial.php">Comment écrire des scénarios de test en PHP</a> est un tutoriel plutôt avancé.
|
287 |
-
</li>
|
288 |
-
<li>
|
289 |
-
<a href="http://simpletest.org/api/">L'API de SimpleTest</a> par phpdoc.
|
290 |
-
</li>
|
291 |
-
</ul>
|
292 |
-
<div class="menu_back"><div class="menu">
|
293 |
-
<a href="index.html">SimpleTest</a>
|
294 |
-
|
|
295 |
-
<a href="overview.html">Overview</a>
|
296 |
-
|
|
297 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
298 |
-
|
|
299 |
-
<a href="group_test_documentation.html">Group tests</a>
|
300 |
-
|
|
301 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
302 |
-
|
|
303 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
304 |
-
|
|
305 |
-
<a href="reporter_documentation.html">Reporting</a>
|
306 |
-
|
|
307 |
-
<a href="expectation_documentation.html">Expectations</a>
|
308 |
-
|
|
309 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
310 |
-
|
|
311 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
312 |
-
|
|
313 |
-
<a href="authentication_documentation.html">Authentication</a>
|
314 |
-
|
|
315 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
316 |
-
</div></div>
|
317 |
-
<div class="copyright">
|
318 |
-
Copyright<br>Marcus Baker 2006
|
319 |
-
</div>
|
320 |
-
</body>
|
321 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/partial_mocks_documentation.html
DELETED
@@ -1,464 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : les objets fantaisie partiels</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 les objets fantaisie partiels</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
<a href="#injection">Le problème de l'injection d'un objet fantaisie</a>.
|
38 |
-
</li>
|
39 |
-
<li>
|
40 |
-
Déplacer la création vers une méthode <a href="#creation">fabrique protégée</a>.
|
41 |
-
</li>
|
42 |
-
<li>
|
43 |
-
<a href="#partiel">L'objet fantaisie partiel</a> génère une sous-classe.
|
44 |
-
</li>
|
45 |
-
<li>
|
46 |
-
Les objets fantaisie partiels <a href="#moins">testent moins qu'une classe</a>.
|
47 |
-
</li>
|
48 |
-
</ul>
|
49 |
-
<div class="content">
|
50 |
-
|
51 |
-
<p>
|
52 |
-
Un objet fantaisie partiel n'est ni plus ni moins
|
53 |
-
qu'un modèle de conception pour soulager un problème spécifique
|
54 |
-
du test avec des objets fantaisie, celui de placer
|
55 |
-
des objets fantaisie dans des coins serrés.
|
56 |
-
Il s'agit d'un outil assez limité et peut-être même
|
57 |
-
une idée pas si bonne que ça. Elle est incluse dans SimpleTest
|
58 |
-
pour la simple raison que je l'ai trouvée utile
|
59 |
-
à plus d'une occasion et qu'elle m'a épargnée
|
60 |
-
pas mal de travail dans ces moments-là.
|
61 |
-
</p>
|
62 |
-
|
63 |
-
<h2>
|
64 |
-
<a class="target" name="injection"></a>Le problème de l'injection dans un objet fantaisie</h2>
|
65 |
-
<p>
|
66 |
-
Quand un objet en utilise un autre il est très simple
|
67 |
-
d'y faire circuler une version fantaisie déjà prête
|
68 |
-
avec ses attentes. Les choses deviennent un peu plus délicates
|
69 |
-
si un objet en crée un autre et que le créateur est celui
|
70 |
-
que l'on souhaite tester. Cela revient à dire que l'objet
|
71 |
-
créé devrait être une fantaisie, mais nous pouvons
|
72 |
-
difficilement dire à notre classe sous test de créer
|
73 |
-
un objet fantaisie plutôt qu'un "vrai" objet.
|
74 |
-
La classe testée ne sait même pas qu'elle travaille dans un environnement de test.
|
75 |
-
</p>
|
76 |
-
<p>
|
77 |
-
Par exemple, supposons que nous sommes en train
|
78 |
-
de construire un client telnet et qu'il a besoin
|
79 |
-
de créer une socket réseau pour envoyer ses messages.
|
80 |
-
La méthode de connexion pourrait ressemble à quelque chose comme...
|
81 |
-
<pre>
|
82 |
-
<strong><?php
|
83 |
-
require_once('socket.php');
|
84 |
-
|
85 |
-
class Telnet {
|
86 |
-
...
|
87 |
-
function &connect($ip, $port, $username, $password) {
|
88 |
-
$socket = &new Socket($ip, $port);
|
89 |
-
$socket->read( ... );
|
90 |
-
...
|
91 |
-
}
|
92 |
-
}
|
93 |
-
?></strong>
|
94 |
-
</pre>
|
95 |
-
Nous voudrions vraiment avoir une version fantaisie
|
96 |
-
de l'objet socket, que pouvons nous faire ?
|
97 |
-
</p>
|
98 |
-
<p>
|
99 |
-
La première solution est de passer la socket en
|
100 |
-
tant que paramètre, ce qui force la création
|
101 |
-
au niveau inférieur. Charger le client de cette tâche
|
102 |
-
est effectivement une bonne approche si c'est possible
|
103 |
-
et devrait conduire à un remaniement -- de la création
|
104 |
-
à partir de l'action. En fait, c'est là une des manières
|
105 |
-
avec lesquels tester en s'appuyant sur des objets fantaisie
|
106 |
-
vous force à coder des solutions plus resserrées sur leur objectif.
|
107 |
-
Ils améliorent votre programmation.
|
108 |
-
</p>
|
109 |
-
<p>
|
110 |
-
Voici ce que ça devrait être...
|
111 |
-
<pre>
|
112 |
-
<?php
|
113 |
-
require_once('socket.php');
|
114 |
-
|
115 |
-
class Telnet {
|
116 |
-
...
|
117 |
-
<strong>function &connect(&$socket, $username, $password) {
|
118 |
-
$socket->read( ... );
|
119 |
-
...
|
120 |
-
}</strong>
|
121 |
-
}
|
122 |
-
?>
|
123 |
-
</pre>
|
124 |
-
Sous-entendu, votre code de test est typique d'un cas
|
125 |
-
de test avec un objet fantaisie.
|
126 |
-
<pre>
|
127 |
-
class TelnetTest extends UnitTestCase {
|
128 |
-
...
|
129 |
-
function testConnection() {<strong>
|
130 |
-
$socket = &new MockSocket($this);
|
131 |
-
...
|
132 |
-
$telnet = &new Telnet();
|
133 |
-
$telnet->connect($socket, 'Me', 'Secret');
|
134 |
-
...</strong>
|
135 |
-
}
|
136 |
-
}
|
137 |
-
</pre>
|
138 |
-
C'est assez évident que vous ne pouvez descendre que d'un niveau.
|
139 |
-
Vous ne voudriez pas que votre application de haut niveau
|
140 |
-
crée tous les fichiers de bas niveau, sockets et autres connexions
|
141 |
-
à la base de données dont elle aurait besoin.
|
142 |
-
Elle ne connaîtrait pas les paramètres du constructeur de toute façon.
|
143 |
-
</p>
|
144 |
-
<p>
|
145 |
-
La solution suivante est de passer l'objet créé sous la forme
|
146 |
-
d'un paramètre optionnel...
|
147 |
-
<pre>
|
148 |
-
<?php
|
149 |
-
require_once('socket.php');
|
150 |
-
|
151 |
-
class Telnet {
|
152 |
-
...<strong>
|
153 |
-
function &connect($ip, $port, $username, $password, $socket = false) {
|
154 |
-
if (!$socket) {
|
155 |
-
$socket = &new Socket($ip, $port);
|
156 |
-
}
|
157 |
-
$socket->read( ... );</strong>
|
158 |
-
...
|
159 |
-
return $socket;
|
160 |
-
}
|
161 |
-
}
|
162 |
-
?>
|
163 |
-
</pre>
|
164 |
-
Pour une solution rapide, c'est généralement suffisant.
|
165 |
-
Ensuite le test est très similaire : comme si le paramètre
|
166 |
-
était transmis formellement...
|
167 |
-
<pre>
|
168 |
-
class TelnetTest extends UnitTestCase {
|
169 |
-
...
|
170 |
-
function testConnection() {<strong>
|
171 |
-
$socket = &new MockSocket($this);
|
172 |
-
...
|
173 |
-
$telnet = &new Telnet();
|
174 |
-
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret', &$socket);
|
175 |
-
...</strong>
|
176 |
-
}
|
177 |
-
}
|
178 |
-
</pre>
|
179 |
-
Le problème de cette approche tient dans son manque de netteté.
|
180 |
-
Il y a du code de test dans la classe principale et aussi
|
181 |
-
des paramètres transmis dans le scénario de test
|
182 |
-
qui ne sont jamais utilisés. Il s'agit là d'une approche
|
183 |
-
rapide et sale, mais qui ne reste pas moins efficace
|
184 |
-
dans la plupart des situations.
|
185 |
-
</p>
|
186 |
-
<p>
|
187 |
-
Une autre solution encore est de laisser un objet fabrique
|
188 |
-
s'occuper de la création...
|
189 |
-
<pre>
|
190 |
-
<?php
|
191 |
-
require_once('socket.php');
|
192 |
-
|
193 |
-
class Telnet {<strong>
|
194 |
-
function Telnet(&$network) {
|
195 |
-
$this->_network = &$network;
|
196 |
-
}</strong>
|
197 |
-
...
|
198 |
-
function &connect($ip, $port, $username, $password) {<strong>
|
199 |
-
$socket = &$this->_network->createSocket($ip, $port);
|
200 |
-
$socket->read( ... );</strong>
|
201 |
-
...
|
202 |
-
return $socket;
|
203 |
-
}
|
204 |
-
}
|
205 |
-
?>
|
206 |
-
</pre>
|
207 |
-
Il s'agit là probablement de la réponse la plus travaillée
|
208 |
-
étant donné que la création est maintenant située
|
209 |
-
dans une petite classe spécialisée. La fabrique réseau
|
210 |
-
peut être testée séparément et utilisée en tant que fantaisie
|
211 |
-
quand nous testons la classe telnet...
|
212 |
-
<pre>
|
213 |
-
class TelnetTest extends UnitTestCase {
|
214 |
-
...
|
215 |
-
function testConnection() {<strong>
|
216 |
-
$socket = &new MockSocket($this);
|
217 |
-
...
|
218 |
-
$network = &new MockNetwork($this);
|
219 |
-
$network->setReturnReference('createSocket', $socket);
|
220 |
-
$telnet = &new Telnet($network);
|
221 |
-
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');
|
222 |
-
...</strong>
|
223 |
-
}
|
224 |
-
}
|
225 |
-
</pre>
|
226 |
-
Le problème reste que nous ajoutons beaucoup de classes
|
227 |
-
à la bibliothèque. Et aussi que nous utilisons beaucoup
|
228 |
-
de fabriques ce qui rend notre code un peu moins intuitif.
|
229 |
-
La solution la plus flexible, mais aussi la plus complexe.
|
230 |
-
</p>
|
231 |
-
<p>
|
232 |
-
Peut-on trouver un juste milieu ?
|
233 |
-
</p>
|
234 |
-
|
235 |
-
<h2>
|
236 |
-
<a class="target" name="creation"></a>Méthode fabrique protégée</h2>
|
237 |
-
<p>
|
238 |
-
Il existe une technique pour palier à ce problème
|
239 |
-
sans créer de nouvelle classe dans l'application;
|
240 |
-
par contre elle induit la création d'une sous-classe au moment du test.
|
241 |
-
Premièrement nous déplaçons la création de la socket dans sa propre méthode...
|
242 |
-
<pre>
|
243 |
-
<?php
|
244 |
-
require_once('socket.php');
|
245 |
-
|
246 |
-
class Telnet {
|
247 |
-
...
|
248 |
-
function &connect($ip, $port, $username, $password) {<strong>
|
249 |
-
$socket = &$this->_createSocket($ip, $port);</strong>
|
250 |
-
$socket->read( ... );
|
251 |
-
...
|
252 |
-
}<strong>
|
253 |
-
|
254 |
-
function &_createSocket($ip, $port) {
|
255 |
-
return new Socket($ip, $port);
|
256 |
-
}</strong>
|
257 |
-
}
|
258 |
-
?>
|
259 |
-
</pre>
|
260 |
-
Il s'agit là de la seule modification dans le code de l'application.
|
261 |
-
</p>
|
262 |
-
<p>
|
263 |
-
Pour le scénario de test, nous devons créer
|
264 |
-
une sous-classe de manière à intercepter la création de la socket...
|
265 |
-
<pre>
|
266 |
-
<strong>class TelnetTestVersion extends Telnet {
|
267 |
-
var $_mock;
|
268 |
-
|
269 |
-
function TelnetTestVersion(&$mock) {
|
270 |
-
$this->_mock = &$mock;
|
271 |
-
$this->Telnet();
|
272 |
-
}
|
273 |
-
|
274 |
-
function &_createSocket() {
|
275 |
-
return $this->_mock;
|
276 |
-
}
|
277 |
-
}</strong>
|
278 |
-
</pre>
|
279 |
-
Ici j'ai déplacé la fantaisie dans le constructeur,
|
280 |
-
mais un setter aurait fonctionné tout aussi bien.
|
281 |
-
Notez bien que la fantaisie est placée dans une variable
|
282 |
-
d'objet avant que le constructeur ne soit attaché.
|
283 |
-
C'est nécessaire dans le cas où le constructeur appelle
|
284 |
-
<span class="new_code">connect()</span>.
|
285 |
-
Autrement il pourrait donner un valeur nulle à partir de
|
286 |
-
<span class="new_code">_createSocket()</span>.
|
287 |
-
</p>
|
288 |
-
<p>
|
289 |
-
Après la réalisation de tout ce travail supplémentaire
|
290 |
-
le scénario de test est assez simple.
|
291 |
-
Nous avons juste besoin de tester notre nouvelle classe à la place...
|
292 |
-
<pre>
|
293 |
-
class TelnetTest extends UnitTestCase {
|
294 |
-
...
|
295 |
-
function testConnection() {<strong>
|
296 |
-
$socket = &new MockSocket($this);
|
297 |
-
...
|
298 |
-
$telnet = &new TelnetTestVersion($socket);
|
299 |
-
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');
|
300 |
-
...</strong>
|
301 |
-
}
|
302 |
-
}
|
303 |
-
</pre>
|
304 |
-
Cette nouvelle classe est très simple bien sûr.
|
305 |
-
Elle ne fait qu'initier une valeur renvoyée, à la manière
|
306 |
-
d'une fantaisie. Ce serait pas mal non plus si elle pouvait
|
307 |
-
vérifier les paramètres entrants.
|
308 |
-
Exactement comme un objet fantaisie.
|
309 |
-
Il se pourrait bien que nous ayons à réaliser cette astuce régulièrement :
|
310 |
-
serait-il possible d'automatiser la création de cette sous-classe ?
|
311 |
-
</p>
|
312 |
-
|
313 |
-
<h2>
|
314 |
-
<a class="target" name="partiel"></a>Un objet fantaisie partiel</h2>
|
315 |
-
<p>
|
316 |
-
Bien sûr la réponse est "oui"
|
317 |
-
ou alors j'aurais arrêté d'écrire depuis quelques temps déjà !
|
318 |
-
Le test précédent a représenté beaucoup de travail,
|
319 |
-
mais nous pouvons générer la sous-classe en utilisant
|
320 |
-
une approche à celle des objets fantaisie.
|
321 |
-
</p>
|
322 |
-
<p>
|
323 |
-
Voici donc une version avec objet fantaisie partiel du test...
|
324 |
-
<pre>
|
325 |
-
<strong>Mock::generatePartial(
|
326 |
-
'Telnet',
|
327 |
-
'TelnetTestVersion',
|
328 |
-
array('_createSocket'));</strong>
|
329 |
-
|
330 |
-
class TelnetTest extends UnitTestCase {
|
331 |
-
...
|
332 |
-
function testConnection() {<strong>
|
333 |
-
$socket = &new MockSocket($this);
|
334 |
-
...
|
335 |
-
$telnet = &new TelnetTestVersion($this);
|
336 |
-
$telnet->setReturnReference('_createSocket', $socket);
|
337 |
-
$telnet->Telnet();
|
338 |
-
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');
|
339 |
-
...</strong>
|
340 |
-
}
|
341 |
-
}
|
342 |
-
</pre>
|
343 |
-
La fantaisie partielle est une sous-classe de l'original
|
344 |
-
dont on aurait "remplacé" les méthodes sélectionnées
|
345 |
-
avec des versions de test. L'appel à <span class="new_code">generatePartial()</span>
|
346 |
-
nécessite trois paramètres : la classe à sous classer,
|
347 |
-
le nom de la nouvelle classe et une liste des méthodes à simuler.
|
348 |
-
</p>
|
349 |
-
<p>
|
350 |
-
Instancier les objets qui en résultent est plutôt délicat.
|
351 |
-
L'unique paramètre du constructeur d'un objet fantaisie partiel
|
352 |
-
est la référence du testeur unitaire.
|
353 |
-
Comme avec les objets fantaisie classiques c'est nécessaire
|
354 |
-
pour l'envoi des résultats de test en réponse à la vérification des attentes.
|
355 |
-
</p>
|
356 |
-
<p>
|
357 |
-
Une nouvelle fois le constructeur original n'est pas lancé.
|
358 |
-
Indispensable dans le cas où le constructeur aurait besoin
|
359 |
-
des méthodes fantaisie : elles n'ont pas encore été initiées !
|
360 |
-
Nous initions les valeurs retournées à cet instant et
|
361 |
-
ensuite lançons le constructeur avec ses paramètres normaux.
|
362 |
-
Cette construction en trois étapes de "new",
|
363 |
-
suivie par la mise en place des méthodes et ensuite
|
364 |
-
par la lancement du constructeur proprement dit est
|
365 |
-
ce qui distingue le code d'un objet fantaisie partiel.
|
366 |
-
</p>
|
367 |
-
<p>
|
368 |
-
A part pour leur construction, toutes ces méthodes
|
369 |
-
fantaisie ont les mêmes fonctionnalités que dans
|
370 |
-
le cas des objets fantaisie et toutes les méthodes
|
371 |
-
non fantaisie se comportent comme avant.
|
372 |
-
Nous pouvons mettre en place des attentes très facilement...
|
373 |
-
<pre>
|
374 |
-
class TelnetTest extends UnitTestCase {
|
375 |
-
...
|
376 |
-
function testConnection() {
|
377 |
-
$socket = &new MockSocket($this);
|
378 |
-
...
|
379 |
-
$telnet = &new TelnetTestVersion($this);
|
380 |
-
$telnet->setReturnReference('_createSocket', $socket);<strong>
|
381 |
-
$telnet->expectOnce('_createSocket', array('127.0.0.1', 21));</strong>
|
382 |
-
$telnet->Telnet();
|
383 |
-
$telnet->connect('127.0.0.1', 21, 'Me', 'Secret');
|
384 |
-
...<strong>
|
385 |
-
$telnet->tally();</strong>
|
386 |
-
}
|
387 |
-
}
|
388 |
-
</pre>
|
389 |
-
</p>
|
390 |
-
|
391 |
-
<h2>
|
392 |
-
<a class="target" name="moins"></a>Tester moins qu'une classe</h2>
|
393 |
-
<p>
|
394 |
-
Les méthodes issues d'un objet fantaisie n'ont pas
|
395 |
-
besoin d'être des méthodes fabrique, Il peut s'agir
|
396 |
-
de n'importe quelle sorte de méthode.
|
397 |
-
Ainsi les objets fantaisie partiels nous permettent
|
398 |
-
de prendre le contrôle de n'importe quelle partie d'une classe,
|
399 |
-
le constructeur excepté. Nous pourrions même aller jusqu'à
|
400 |
-
créer des fantaisies sur toutes les méthodes à part celle
|
401 |
-
que nous voulons effectivement tester.
|
402 |
-
</p>
|
403 |
-
<p>
|
404 |
-
Cette situation est assez hypothétique, étant donné
|
405 |
-
que je ne l'ai jamais essayée. Je suis ouvert à cette possibilité,
|
406 |
-
mais je crains qu'en forçant la granularité d'un objet
|
407 |
-
on n'obtienne pas forcément un code de meilleur qualité.
|
408 |
-
Personnellement j'utilise les objets fantaisie partiels
|
409 |
-
comme moyen de passer outre la création ou alors
|
410 |
-
de temps en temps pour tester le modèle de conception TemplateMethod.
|
411 |
-
</p>
|
412 |
-
<p>
|
413 |
-
Pour choisir le mécanisme à utiliser, on en revient
|
414 |
-
toujours aux standards de code de votre projet.
|
415 |
-
</p>
|
416 |
-
|
417 |
-
</div>
|
418 |
-
References and related information...
|
419 |
-
<ul>
|
420 |
-
<li>
|
421 |
-
La page du projet SimpleTest sur
|
422 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
423 |
-
</li>
|
424 |
-
<li>
|
425 |
-
<a href="http://simpletest.org/api/">L'API complète pour SimpleTest</a>
|
426 |
-
à partir de PHPDoc.
|
427 |
-
</li>
|
428 |
-
<li>
|
429 |
-
La méthode fabrique protégée est décrite dans
|
430 |
-
<a href="http://www-106.ibm.com/developerworks/java/library/j-mocktest.html">
|
431 |
-
cet article d'IBM</a>. Il s'agit de l'unique papier
|
432 |
-
formel que j'ai vu sur ce problème.
|
433 |
-
</li>
|
434 |
-
</ul>
|
435 |
-
<div class="menu_back"><div class="menu">
|
436 |
-
<a href="index.html">SimpleTest</a>
|
437 |
-
|
|
438 |
-
<a href="overview.html">Overview</a>
|
439 |
-
|
|
440 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
441 |
-
|
|
442 |
-
<a href="group_test_documentation.html">Group tests</a>
|
443 |
-
|
|
444 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
445 |
-
|
|
446 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
447 |
-
|
|
448 |
-
<a href="reporter_documentation.html">Reporting</a>
|
449 |
-
|
|
450 |
-
<a href="expectation_documentation.html">Expectations</a>
|
451 |
-
|
|
452 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
453 |
-
|
|
454 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
455 |
-
|
|
456 |
-
<a href="authentication_documentation.html">Authentication</a>
|
457 |
-
|
|
458 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
459 |
-
</div></div>
|
460 |
-
<div class="copyright">
|
461 |
-
Copyright<br>Marcus Baker 2006
|
462 |
-
</div>
|
463 |
-
</body>
|
464 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/reporter_documentation.html
DELETED
@@ -1,538 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : le rapporteur de test</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 le rapporteur de test</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
Afficher <a href="#html">les résultats en HTML</a>
|
38 |
-
</li>
|
39 |
-
<li>
|
40 |
-
Afficher et <a href="#autres">rapporter les résultats</a>
|
41 |
-
dans d'autres formats
|
42 |
-
</li>
|
43 |
-
<li>
|
44 |
-
Utilisé <a href="#cli">SimpleTest depuis la ligne de commande</a>
|
45 |
-
</li>
|
46 |
-
<li>
|
47 |
-
<a href="#xml">Utiliser XML</a> pour des tests distants
|
48 |
-
</li>
|
49 |
-
</ul>
|
50 |
-
<div class="content">
|
51 |
-
|
52 |
-
<p>
|
53 |
-
SimpleTest suit plutôt plus que moins le modèle MVC (Modèle-Vue-Contrôleur).
|
54 |
-
Les classes "reporter" sont les vues et les modèles
|
55 |
-
sont vos scénarios de test et leur hiérarchie.
|
56 |
-
Le contrôleur est le plus souvent masqué à l'utilisateur
|
57 |
-
de SimpleTest à moins de vouloir changer la façon
|
58 |
-
dont les tests sont effectivement exécutés,
|
59 |
-
auquel cas il est possible de surcharger les objets
|
60 |
-
"runner" (ceux de l'exécuteur) depuis l'intérieur
|
61 |
-
d'un scénario de test. Comme d'habitude avec MVC,
|
62 |
-
le contrôleur est plutôt indéfini et il existe d'autres endroits
|
63 |
-
pour contrôler l'exécution des tests.
|
64 |
-
</p>
|
65 |
-
|
66 |
-
<h2>
|
67 |
-
<a class="target" name="html"></a>Les résultats rapportés au format HTML</h2>
|
68 |
-
<p>
|
69 |
-
L'affichage par défaut est minimal à l'extrême.
|
70 |
-
Il renvoie le succès ou l'échec avec les barres conventionnelles
|
71 |
-
- rouge et verte - et affichent une trace d'arborescence
|
72 |
-
des groupes de test pour chaque assertion erronée. Voici un tel échec...
|
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 |
-
Alors qu'ici tous les tests passent...
|
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 |
-
La bonne nouvelle, c'est qu'il existe pas mal de points
|
86 |
-
dans la hiérarchie de l'affichage pour créer des sous-classes.
|
87 |
-
</p>
|
88 |
-
<p>
|
89 |
-
Pour l'affichage basé sur des pages web,
|
90 |
-
il y a la classe <span class="new_code">HtmlReporter</span> avec la signature suivante...
|
91 |
-
<pre>
|
92 |
-
class HtmlReporter extends SimpleReporter {
|
93 |
-
public HtmlReporter($encoding) { ... }
|
94 |
-
public makeDry(boolean $is_dry) { ... }
|
95 |
-
public void paintHeader(string $test_name) { ... }
|
96 |
-
public void sendNoCacheHeaders() { ... }
|
97 |
-
public void paintFooter(string $test_name) { ... }
|
98 |
-
public void paintGroupStart(string $test_name, integer $size) { ... }
|
99 |
-
public void paintGroupEnd(string $test_name) { ... }
|
100 |
-
public void paintCaseStart(string $test_name) { ... }
|
101 |
-
public void paintCaseEnd(string $test_name) { ... }
|
102 |
-
public void paintMethodStart(string $test_name) { ... }
|
103 |
-
public void paintMethodEnd(string $test_name) { ... }
|
104 |
-
public void paintFail(string $message) { ... }
|
105 |
-
public void paintPass(string $message) { ... }
|
106 |
-
public void paintError(string $message) { ... }
|
107 |
-
public void paintException(string $message) { ... }
|
108 |
-
public void paintMessage(string $message) { ... }
|
109 |
-
public void paintFormattedMessage(string $message) { ... }
|
110 |
-
protected string getCss() { ... }
|
111 |
-
public array getTestList() { ... }
|
112 |
-
public integer getPassCount() { ... }
|
113 |
-
public integer getFailCount() { ... }
|
114 |
-
public integer getExceptionCount() { ... }
|
115 |
-
public integer getTestCaseCount() { ... }
|
116 |
-
public integer getTestCaseProgress() { ... }
|
117 |
-
}
|
118 |
-
</pre>
|
119 |
-
Voici ce que certaines de ces méthodes veulent dire.
|
120 |
-
Premièrement les méthodes d'affichage que vous voudrez probablement surcharger...
|
121 |
-
<ul class="api">
|
122 |
-
<li>
|
123 |
-
<span class="new_code">HtmlReporter(string $encoding)</span><br>
|
124 |
-
est le constructeur. Notez que le test unitaire initie
|
125 |
-
le lien à l'affichage plutôt que l'opposé.
|
126 |
-
L'affichage est principalement un receveur passif
|
127 |
-
des évènements de tests. Cela permet d'adapter
|
128 |
-
facilement l'affichage pour d'autres systèmes
|
129 |
-
en dehors des tests unitaires, tel le suivi
|
130 |
-
de la charge de serveurs.
|
131 |
-
L'"encoding" est le type d'encodage
|
132 |
-
que vous souhaitez utiliser pour l'affichage du test.
|
133 |
-
Pour pouvoir effectuer un rendu correct de la sortie
|
134 |
-
de débogage quand on utilise le testeur web,
|
135 |
-
il doit correspondre à l'encodage du site testé.
|
136 |
-
Les chaînes de caractères disponibles
|
137 |
-
sont indiquées dans la fonction PHP
|
138 |
-
<a href="http://www.php.net/manual/fr/function.htmlentities.php">html_entities()</a>.
|
139 |
-
</li>
|
140 |
-
<li>
|
141 |
-
<span class="new_code">void paintHeader(string $test_name)</span><br>
|
142 |
-
est appelé une fois, au début du test quand l'évènement
|
143 |
-
de démarrage survient. Le premier évènement de démarrage
|
144 |
-
est souvent délivré par le groupe de tests du niveau
|
145 |
-
le plus haut et donc c'est de là que le
|
146 |
-
<span class="new_code">$test_name</span> arrive.
|
147 |
-
Il peint les titres de la page, CSS, la balise "body", etc.
|
148 |
-
Il ne renvoie rien du tout (<span class="new_code">void</span>).
|
149 |
-
</li>
|
150 |
-
<li>
|
151 |
-
<span class="new_code">void paintFooter(string $test_name)</span><br>
|
152 |
-
est appelé à la toute fin du test pour fermer
|
153 |
-
les balises ouvertes par l'entête de la page.
|
154 |
-
Par défaut il affiche aussi la barre rouge ou verte
|
155 |
-
et le décompte final des résultats.
|
156 |
-
En fait la fin des tests arrive quand l'évènement
|
157 |
-
de fin de test arrive avec le même nom
|
158 |
-
que celui qui l'a initié au même niveau.
|
159 |
-
Le nid des tests en quelque sorte.
|
160 |
-
Fermer le dernier test finit l'affichage.
|
161 |
-
</li>
|
162 |
-
<li>
|
163 |
-
<span class="new_code">void paintMethodStart(string $test_name)</span><br>
|
164 |
-
est appelé au début de chaque méthode de test.
|
165 |
-
Normalement le nom vient de celui de la méthode.
|
166 |
-
Les autres évènements de départ de test
|
167 |
-
se comportent de la même manière sauf que
|
168 |
-
celui du groupe de tests indique au rapporteur
|
169 |
-
le nombre de scénarios de test qu'il contient.
|
170 |
-
De la sorte le rapporteur peut afficher une barre
|
171 |
-
de progrès au fur et à mesure que l'exécuteur
|
172 |
-
passe en revue les scénarios de test.
|
173 |
-
</li>
|
174 |
-
<li>
|
175 |
-
<span class="new_code">void paintMethodEnd(string $test_name)</span><br>
|
176 |
-
clôt le test lancé avec le même nom.
|
177 |
-
</li>
|
178 |
-
<li>
|
179 |
-
<span class="new_code">void paintFail(string $message)</span><br>
|
180 |
-
peint un échec. Par défaut il ne fait qu'afficher
|
181 |
-
le mot "fail", une trace d'arborescence
|
182 |
-
affichant la position du test en cours
|
183 |
-
et le message transmis par l'assertion.
|
184 |
-
</li>
|
185 |
-
<li>
|
186 |
-
<span class="new_code">void paintPass(string $message)</span><br>
|
187 |
-
ne fait rien, par défaut.
|
188 |
-
</li>
|
189 |
-
<li>
|
190 |
-
<span class="new_code">string getCss()</span><br>
|
191 |
-
renvoie les styles CSS sous la forme d'une chaîne
|
192 |
-
à l'attention de la méthode d'entêtes d'une page.
|
193 |
-
Des styles additionnels peuvent être ajoutés ici
|
194 |
-
si vous ne surchargez pas les entêtes de la page.
|
195 |
-
Vous ne voudrez pas utiliser cette méthode dans
|
196 |
-
des entêtes d'une page surchargée si vous souhaitez
|
197 |
-
inclure le feuille de style CSS d'origine.
|
198 |
-
</li>
|
199 |
-
</ul>
|
200 |
-
Il y a aussi des accesseurs pour aller chercher l'information
|
201 |
-
sur l'état courant de la suite de test. Vous les utiliserez
|
202 |
-
pour enrichir l'affichage...
|
203 |
-
<ul class="api">
|
204 |
-
<li>
|
205 |
-
<span class="new_code">array getTestList()</span><br>
|
206 |
-
est la première méthode très commode pour les sous-classes.
|
207 |
-
Elle liste l'arborescence courante des tests
|
208 |
-
sous la forme d'une liste de noms de tests.
|
209 |
-
Le premier test -- celui le plus proche du coeur --
|
210 |
-
sera le premier dans la liste et la méthode de test
|
211 |
-
en cours sera la dernière.
|
212 |
-
</li>
|
213 |
-
<li>
|
214 |
-
<span class="new_code">integer getPassCount()</span><br>
|
215 |
-
renvoie le nombre de succès atteint. Il est nécessaire
|
216 |
-
pour l'affichage à la fin.
|
217 |
-
</li>
|
218 |
-
<li>
|
219 |
-
<span class="new_code">integer getFailCount()</span><br>
|
220 |
-
renvoie de la même manière le nombre d'échecs.
|
221 |
-
</li>
|
222 |
-
<li>
|
223 |
-
<span class="new_code">integer getExceptionCount()</span><br>
|
224 |
-
renvoie quant à lui le nombre d'erreurs.
|
225 |
-
</li>
|
226 |
-
<li>
|
227 |
-
<span class="new_code">integer getTestCaseCount()</span><br>
|
228 |
-
est le nombre total de scénarios lors de l'exécution des tests.
|
229 |
-
Il comprend aussi les tests groupés.
|
230 |
-
</li>
|
231 |
-
<li>
|
232 |
-
<span class="new_code">integer getTestCaseProgress()</span><br>
|
233 |
-
est le nombre de scénarios réalisés jusqu'à présent.
|
234 |
-
</li>
|
235 |
-
</ul>
|
236 |
-
Une modification simple : demander à l'HtmlReporter d'afficher
|
237 |
-
aussi bien les succès que les échecs et les erreurs...
|
238 |
-
<pre><strong>
|
239 |
-
class ShowPasses extends HtmlReporter {
|
240 |
-
|
241 |
-
function paintPass($message) {
|
242 |
-
parent::paintPass($message);
|
243 |
-
print "&<span class=\"pass\">Pass</span>: ";
|
244 |
-
$breadcrumb = $this->getTestList();
|
245 |
-
array_shift($breadcrumb);
|
246 |
-
print implode("-&gt;", $breadcrumb);
|
247 |
-
print "-&gt;$message<br />\n";
|
248 |
-
}
|
249 |
-
|
250 |
-
protected function getCss() {
|
251 |
-
return parent::getCss() . ' .pass { color: green; }';
|
252 |
-
}
|
253 |
-
}</strong>
|
254 |
-
</pre>
|
255 |
-
</p>
|
256 |
-
<p>
|
257 |
-
Une méthode qui a beaucoup fait jaser reste la méthode <span class="new_code">makeDry()</span>.
|
258 |
-
Si vous lancez cette méthode, sans paramètre,
|
259 |
-
sur le rapporteur avant que la suite de test
|
260 |
-
ne soit exécutée alors aucune méthode de test
|
261 |
-
ne sera appelée. Vous continuerez à avoir
|
262 |
-
les évènements entrants et sortants des méthodes
|
263 |
-
et scénarios de test, mais aucun succès ni échec ou erreur,
|
264 |
-
parce que le code de test ne sera pas exécuté.
|
265 |
-
</p>
|
266 |
-
<p>
|
267 |
-
La raison ? Pour permettre un affichage complexe
|
268 |
-
d'une IHM (ou GUI) qui permettrait la sélection
|
269 |
-
de scénarios de test individuels.
|
270 |
-
Afin de construire une liste de tests possibles,
|
271 |
-
ils ont besoin d'un rapport sur la structure du test
|
272 |
-
pour l'affichage, par exemple, d'une vue en arbre
|
273 |
-
de la suite de test. Avec un rapporteur lancé
|
274 |
-
sur une exécution sèche qui ne renverrait
|
275 |
-
que les évènements d'affichage, cela devient
|
276 |
-
facilement réalisable.
|
277 |
-
</p>
|
278 |
-
|
279 |
-
<h2>
|
280 |
-
<a class="target" name="autre"></a>Etendre le rapporteur</h2>
|
281 |
-
<p>
|
282 |
-
Plutôt que de modifier l'affichage existant,
|
283 |
-
vous voudrez peut-être produire une présentation HTML
|
284 |
-
complètement différente, ou même générer une version texte ou XML.
|
285 |
-
Plutôt que de surcharger chaque méthode dans
|
286 |
-
<span class="new_code">HtmlReporter</span> nous pouvons nous rendre
|
287 |
-
une étape plus haut dans la hiérarchie de classe vers
|
288 |
-
<span class="new_code">SimpleReporter</span> dans le fichier source <em>simple_test.php</em>.
|
289 |
-
</p>
|
290 |
-
<p>
|
291 |
-
Un affichage sans rien, un canevas vierge
|
292 |
-
pour votre propre création, serait...
|
293 |
-
<pre><strong>
|
294 |
-
require_once('simpletest/simple_test.php');</strong>
|
295 |
-
|
296 |
-
class MyDisplay extends SimpleReporter {<strong>
|
297 |
-
</strong>
|
298 |
-
function paintHeader($test_name) {
|
299 |
-
}
|
300 |
-
|
301 |
-
function paintFooter($test_name) {
|
302 |
-
}
|
303 |
-
|
304 |
-
function paintStart($test_name, $size) {<strong>
|
305 |
-
parent::paintStart($test_name, $size);</strong>
|
306 |
-
}
|
307 |
-
|
308 |
-
function paintEnd($test_name, $size) {<strong>
|
309 |
-
parent::paintEnd($test_name, $size);</strong>
|
310 |
-
}
|
311 |
-
|
312 |
-
function paintPass($message) {<strong>
|
313 |
-
parent::paintPass($message);</strong>
|
314 |
-
}
|
315 |
-
|
316 |
-
function paintFail($message) {<strong>
|
317 |
-
parent::paintFail($message);</strong>
|
318 |
-
}
|
319 |
-
}
|
320 |
-
</pre>
|
321 |
-
Aucune sortie ne viendrait de cette classe jusqu'à un ajout de votre part.
|
322 |
-
</p>
|
323 |
-
|
324 |
-
<h2>
|
325 |
-
<a class="target" name="cli"></a>Le rapporteur en ligne de commande</h2>
|
326 |
-
<p>
|
327 |
-
SimpleTest est aussi livré avec un rapporteur
|
328 |
-
en ligne de commande, minime lui aussi.
|
329 |
-
L'interface imite celle de JUnit,
|
330 |
-
sauf qu'elle envoie les messages d'erreur au fur
|
331 |
-
et à mesure de leur arrivée.
|
332 |
-
Pour utiliser le rapporteur en ligne de commande,
|
333 |
-
il suffit de l'intervertir avec celui de la version HTML...
|
334 |
-
<pre>
|
335 |
-
<?php
|
336 |
-
require_once('simpletest/unit_tester.php');
|
337 |
-
require_once('simpletest/reporter.php');
|
338 |
-
|
339 |
-
$test = &new GroupTest('File test');
|
340 |
-
$test->addTestFile('tests/file_test.php');
|
341 |
-
$test->run(<strong>new TextReporter()</strong>);
|
342 |
-
?>
|
343 |
-
</pre>
|
344 |
-
Et ensuite d'invoquer la suite de test à partir d'une ligne de commande...
|
345 |
-
<pre class="shell">
|
346 |
-
php file_test.php
|
347 |
-
</pre>
|
348 |
-
Bien sûr vous aurez besoin d'installer PHP
|
349 |
-
en ligne de commande. Une suite de test qui
|
350 |
-
passerait toutes ses assertions ressemble à...
|
351 |
-
<pre class="shell">
|
352 |
-
File test
|
353 |
-
OK
|
354 |
-
Test cases run: 1/1, Failures: 0, Exceptions: 0
|
355 |
-
</pre>
|
356 |
-
Un échec déclenche un affichage comme...
|
357 |
-
<pre class="shell">
|
358 |
-
File test
|
359 |
-
1) True assertion failed.
|
360 |
-
in createnewfile
|
361 |
-
FAILURES!!!
|
362 |
-
Test cases run: 1/1, Failures: 1, Exceptions: 0
|
363 |
-
</pre>
|
364 |
-
</p>
|
365 |
-
<p>
|
366 |
-
Une des principales raisons pour utiliser
|
367 |
-
une suite de test en ligne de commande tient
|
368 |
-
dans l'utilisation possible du testeur avec
|
369 |
-
un processus automatisé. Pour fonctionner comme
|
370 |
-
il faut dans des scripts shell le script de test
|
371 |
-
devrait renvoyer un code de sortie non-nul suite à un échec.
|
372 |
-
Si une suite de test échoue la valeur <span class="new_code">false</span>
|
373 |
-
est renvoyée par la méthode <span class="new_code">SimpleTest::run()</span>.
|
374 |
-
Nous pouvons utiliser ce résultat pour terminer le script
|
375 |
-
avec la bonne valeur renvoyée...
|
376 |
-
<pre>
|
377 |
-
<?php
|
378 |
-
require_once('simpletest/unit_tester.php');
|
379 |
-
require_once('simpletest/reporter.php');
|
380 |
-
|
381 |
-
$test = &new GroupTest('File test');
|
382 |
-
$test->addTestFile('tests/file_test.php');<strong>
|
383 |
-
exit ($test->run(new TextReporter()) ? 0 : 1);</strong>
|
384 |
-
?>
|
385 |
-
</pre>
|
386 |
-
Bien sûr l'objectif n'est pas de créer deux scripts de test,
|
387 |
-
l'un en ligne de commande et l'autre pour un navigateur web,
|
388 |
-
pour chaque suite de test.
|
389 |
-
Le rapporteur en ligne de commande inclut
|
390 |
-
une méthode pour déterminer l'environnement d'exécution...
|
391 |
-
<pre>
|
392 |
-
<?php
|
393 |
-
require_once('simpletest/unit_tester.php');
|
394 |
-
require_once('simpletest/reporter.php');
|
395 |
-
|
396 |
-
$test = &new GroupTest('File test');
|
397 |
-
$test->addTestFile('tests/file_test.php');<strong>
|
398 |
-
if (TextReporter::inCli()) {</strong>
|
399 |
-
exit ($test->run(new TextReporter()) ? 0 : 1);<strong>
|
400 |
-
}</strong>
|
401 |
-
$test->run(new HtmlReporter());
|
402 |
-
?>
|
403 |
-
</pre>
|
404 |
-
Il s'agit là de la forme utilisée par SimpleTest lui-même.
|
405 |
-
</p>
|
406 |
-
|
407 |
-
<h2>
|
408 |
-
<a class="target" name="xml"></a>Test distant</h2>
|
409 |
-
<p>
|
410 |
-
SimpleTest est livré avec une classe <span class="new_code">XmlReporter</span>
|
411 |
-
utilisée pour de la communication interne.
|
412 |
-
Lors de son exécution, le résultat ressemble à...
|
413 |
-
<pre class="shell">
|
414 |
-
<?xml version="1.0"?>
|
415 |
-
<run>
|
416 |
-
<group size="4">
|
417 |
-
<name>Remote tests</name>
|
418 |
-
<group size="4">
|
419 |
-
<name>Visual test with 48 passes, 48 fails and 4 exceptions</name>
|
420 |
-
<case>
|
421 |
-
<name>testofunittestcaseoutput</name>
|
422 |
-
<test>
|
423 |
-
<name>testofresults</name>
|
424 |
-
<pass>This assertion passed</pass>
|
425 |
-
<fail>This assertion failed</fail>
|
426 |
-
</test>
|
427 |
-
<test>
|
428 |
-
...
|
429 |
-
</test>
|
430 |
-
</case>
|
431 |
-
</group>
|
432 |
-
</group>
|
433 |
-
</run>
|
434 |
-
</pre>
|
435 |
-
Vous pouvez utiliser ce format avec le parseur
|
436 |
-
fourni dans SimpleTest lui-même.
|
437 |
-
Il s'agit de <span class="new_code">SimpleTestXmlParser</span>
|
438 |
-
et se trouve <em>xml.php</em> à l'intérieur du paquet SimpleTest...
|
439 |
-
<pre>
|
440 |
-
<?php
|
441 |
-
require_once('simpletest/xml.php');
|
442 |
-
|
443 |
-
...
|
444 |
-
$parser = &new SimpleTestXmlParser(new HtmlReporter());
|
445 |
-
$parser->parse($test_output);
|
446 |
-
?>
|
447 |
-
</pre>
|
448 |
-
<span class="new_code">$test_output</span> devrait être au format XML,
|
449 |
-
à partir du rapporteur XML, et pourrait venir
|
450 |
-
d'une exécution en ligne de commande d'un scénario de test.
|
451 |
-
Le parseur envoie des évènements au rapporteur exactement
|
452 |
-
comme tout autre exécution de test.
|
453 |
-
Il y a des occasions bizarres dans lesquelles c'est en fait très utile.
|
454 |
-
</p>
|
455 |
-
<p>
|
456 |
-
Un problème des très grandes suites de test,
|
457 |
-
c'est qu'elles peuvent venir à bout de la limite de mémoire
|
458 |
-
par défaut d'un process PHP - 8Mb.
|
459 |
-
En plaçant la sortie des groupes de test dans du XML
|
460 |
-
et leur exécution dans des process différents,
|
461 |
-
le résultat peut être parsé à nouveau pour agréger
|
462 |
-
les résultats avec moins d'impact sur le test au premier niveau.
|
463 |
-
</p>
|
464 |
-
<p>
|
465 |
-
Parce que la sortie XML peut venir de n'importe où,
|
466 |
-
ça ouvre des possibilités d'agrégation d'exécutions de test
|
467 |
-
depuis des serveur distants.
|
468 |
-
Un scénario de test pour le réaliser existe déjà
|
469 |
-
à l'intérieur du framework SimpleTest, mais il est encore expérimental...
|
470 |
-
<pre>
|
471 |
-
<?php<strong>
|
472 |
-
require_once('../remote.php');</strong>
|
473 |
-
require_once('../reporter.php');
|
474 |
-
|
475 |
-
$test_url = ...;
|
476 |
-
$dry_url = ...;
|
477 |
-
|
478 |
-
$test = &new GroupTest('Remote tests');
|
479 |
-
$test->addTestCase(<strong>new RemoteTestCase($test_url, $dry_url)</strong>);
|
480 |
-
$test->run(new HtmlReporter());
|
481 |
-
?>
|
482 |
-
</pre>
|
483 |
-
<span class="new_code">RemoteTestCase</span> prend la localisation réelle
|
484 |
-
du lanceur de test, tout simplement un page web au format XML.
|
485 |
-
Il prend aussi l'URL d'un rapporteur initié
|
486 |
-
pour effectuer une exécution sèche.
|
487 |
-
Cette technique est employée pour que les progrès
|
488 |
-
soient correctement rapportés vers le haut.
|
489 |
-
<span class="new_code">RemoteTestCase</span> peut être ajouté à
|
490 |
-
une suite de test comme n'importe quel autre groupe de tests.
|
491 |
-
</p>
|
492 |
-
|
493 |
-
</div>
|
494 |
-
References and related information...
|
495 |
-
<ul>
|
496 |
-
<li>
|
497 |
-
La page du projet SimpleTest sur
|
498 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
499 |
-
</li>
|
500 |
-
<li>
|
501 |
-
La page de téléchargement de SimpleTest sur
|
502 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
503 |
-
</li>
|
504 |
-
<li>
|
505 |
-
L'<a href="http://simpletest.org/api/">API pour développeur de SimpleTest</a>
|
506 |
-
donne tous les détails sur les classes et les assertions disponibles.
|
507 |
-
</li>
|
508 |
-
</ul>
|
509 |
-
<div class="menu_back"><div class="menu">
|
510 |
-
<a href="index.html">SimpleTest</a>
|
511 |
-
|
|
512 |
-
<a href="overview.html">Overview</a>
|
513 |
-
|
|
514 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
515 |
-
|
|
516 |
-
<a href="group_test_documentation.html">Group tests</a>
|
517 |
-
|
|
518 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
519 |
-
|
|
520 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
521 |
-
|
|
522 |
-
<a href="reporter_documentation.html">Reporting</a>
|
523 |
-
|
|
524 |
-
<a href="expectation_documentation.html">Expectations</a>
|
525 |
-
|
|
526 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
527 |
-
|
|
528 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
529 |
-
|
|
530 |
-
<a href="authentication_documentation.html">Authentication</a>
|
531 |
-
|
|
532 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
533 |
-
</div></div>
|
534 |
-
<div class="copyright">
|
535 |
-
Copyright<br>Marcus Baker 2006
|
536 |
-
</div>
|
537 |
-
</body>
|
538 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/unit_test_documentation.html
DELETED
@@ -1,450 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest pour les tests de régression en PHP</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 les tests unitaires en PHP</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
<a href="#unitaire">Scénarios de test unitaire</a>
|
38 |
-
et opérations basiques.
|
39 |
-
</li>
|
40 |
-
<li>
|
41 |
-
<a href="#extension_unitaire">Étendre des scénarios de test</a>
|
42 |
-
pour les personnaliser à votre propre projet.
|
43 |
-
</li>
|
44 |
-
<li>
|
45 |
-
<a href="#lancement_unitaire">Lancer un scénario seul</a>
|
46 |
-
comme un script unique.
|
47 |
-
</li>
|
48 |
-
</ul>
|
49 |
-
<div class="content">
|
50 |
-
<h2>
|
51 |
-
<a class="target" name="unitaire"></a>Scénarios de tests unitaires</h2>
|
52 |
-
<p>
|
53 |
-
Le coeur du système est un framework de tests de régression
|
54 |
-
construit autour des scénarios de test.
|
55 |
-
Un exemple de scénario de test ressemble à...
|
56 |
-
<pre>
|
57 |
-
<strong>class FileTestCase extends UnitTestCase {
|
58 |
-
}</strong>
|
59 |
-
</pre>
|
60 |
-
Si aucun nom de test n'est fourni au moment
|
61 |
-
de la liaison avec le constructeur alors
|
62 |
-
le nom de la classe sera utilisé.
|
63 |
-
Il s'agit du nom qui sera affiché dans les résultats du test.
|
64 |
-
</p>
|
65 |
-
<p>
|
66 |
-
Les véritables tests sont ajoutés en tant que méthode
|
67 |
-
dans le scénario de test dont le nom par défaut
|
68 |
-
commence par la chaîne "test"
|
69 |
-
et quand le scénario de test est appelé toutes les méthodes
|
70 |
-
de ce type sont exécutées dans l'ordre utilisé
|
71 |
-
par l'introspection de PHP pour les trouver.
|
72 |
-
Peuvent être ajoutées autant de méthodes de test que nécessaires.
|
73 |
-
Par exemple...
|
74 |
-
<pre>
|
75 |
-
require_once('simpletest/autorun.php');
|
76 |
-
require_once('../classes/writer.php');
|
77 |
-
|
78 |
-
class FileTestCase extends UnitTestCase {
|
79 |
-
function FileTestCase() {
|
80 |
-
$this->UnitTestCase('File test');
|
81 |
-
}<strong>
|
82 |
-
|
83 |
-
function setUp() {
|
84 |
-
@unlink('../temp/test.txt');
|
85 |
-
}
|
86 |
-
|
87 |
-
function tearDown() {
|
88 |
-
@unlink('../temp/test.txt');
|
89 |
-
}
|
90 |
-
|
91 |
-
function testCreation() {
|
92 |
-
$writer = &new FileWriter('../temp/test.txt');
|
93 |
-
$writer->write('Hello');
|
94 |
-
$this->assertTrue(file_exists('../temp/test.txt'), 'File created');
|
95 |
-
}</strong>
|
96 |
-
}
|
97 |
-
</pre>
|
98 |
-
Le constructeur est optionnel et souvent omis. Sans nom,
|
99 |
-
le nom de la classe est utilisé comme nom pour le scénario de test.
|
100 |
-
</p>
|
101 |
-
<p>
|
102 |
-
Notre unique méthode de test pour le moment est
|
103 |
-
<span class="new_code">testCreation()</span> où nous vérifions
|
104 |
-
qu'un fichier a bien été créé par notre objet
|
105 |
-
<span class="new_code">Writer</span>. Nous pourrions avoir mis
|
106 |
-
le code <span class="new_code">unlink()</span> dans cette méthode,
|
107 |
-
mais en la plaçant dans <span class="new_code">setUp()</span>
|
108 |
-
et <span class="new_code">tearDown()</span> nous pouvons l'utiliser
|
109 |
-
pour nos autres méthodes de test que nous ajouterons.
|
110 |
-
</p>
|
111 |
-
<p>
|
112 |
-
La méthode <span class="new_code">setUp()</span> est lancé
|
113 |
-
juste avant chaque méthode de test.
|
114 |
-
<span class="new_code">tearDown()</span> est lancé après chaque méthode de test.
|
115 |
-
</p>
|
116 |
-
<p>
|
117 |
-
Vous pouvez placer une initialisation de
|
118 |
-
scénario de test dans le constructeur afin qu'elle soit lancée
|
119 |
-
pour toutes les méthodes dans le scénario de test
|
120 |
-
mais dans un tel cas vous vous exposeriez à des interférences.
|
121 |
-
Cette façon de faire est légèrement moins rapide,
|
122 |
-
mais elle est plus sûre.
|
123 |
-
Notez que si vous arrivez avec des notions de JUnit,
|
124 |
-
il ne s'agit pas du comportement auquel vous êtes habitués.
|
125 |
-
Bizarrement JUnit re-instancie le scénario de test
|
126 |
-
pour chaque méthode de test pour se prévenir
|
127 |
-
d'une telle interférence.
|
128 |
-
SimpleTest demande à l'utilisateur final d'utiliser
|
129 |
-
<span class="new_code">setUp()</span>, mais fournit aux codeurs de bibliothèque d'autres crochets.
|
130 |
-
</p>
|
131 |
-
<p>
|
132 |
-
Pour rapporter les résultats de test,
|
133 |
-
le passage par une classe d'affichage - notifiée par
|
134 |
-
les différentes méthodes de type <span class="new_code">assert...()</span> -
|
135 |
-
est utilisée. En voici la liste complète pour
|
136 |
-
la classe <span class="new_code">UnitTestCase</span>,
|
137 |
-
celle par défaut dans SimpleTest...
|
138 |
-
<table><tbody>
|
139 |
-
<tr>
|
140 |
-
<td><span class="new_code">assertTrue($x)</span></td>
|
141 |
-
<td>Echoue si $x est faux</td>
|
142 |
-
</tr>
|
143 |
-
<tr>
|
144 |
-
<td><span class="new_code">assertFalse($x)</span></td>
|
145 |
-
<td>Echoue si $x est vrai</td>
|
146 |
-
</tr>
|
147 |
-
<tr>
|
148 |
-
<td><span class="new_code">assertNull($x)</span></td>
|
149 |
-
<td>Echoue si $x est initialisé</td>
|
150 |
-
</tr>
|
151 |
-
<tr>
|
152 |
-
<td><span class="new_code">assertNotNull($x)</span></td>
|
153 |
-
<td>Echoue si $x n'est pas initialisé</td>
|
154 |
-
</tr>
|
155 |
-
<tr>
|
156 |
-
<td><span class="new_code">assertIsA($x, $t)</span></td>
|
157 |
-
<td>Echoue si $x n'est pas de la classe ou du type $t</td>
|
158 |
-
</tr>
|
159 |
-
<tr>
|
160 |
-
<td><span class="new_code">assertEqual($x, $y)</span></td>
|
161 |
-
<td>Echoue si $x == $y est faux</td>
|
162 |
-
</tr>
|
163 |
-
<tr>
|
164 |
-
<td><span class="new_code">assertNotEqual($x, $y)</span></td>
|
165 |
-
<td>Echoue si $x == $y est vrai</td>
|
166 |
-
</tr>
|
167 |
-
<tr>
|
168 |
-
<td><span class="new_code">assertIdentical($x, $y)</span></td>
|
169 |
-
<td>Echoue si $x === $y est faux</td>
|
170 |
-
</tr>
|
171 |
-
<tr>
|
172 |
-
<td><span class="new_code">assertNotIdentical($x, $y)</span></td>
|
173 |
-
<td>Echoue si $x === $y est vrai</td>
|
174 |
-
</tr>
|
175 |
-
<tr>
|
176 |
-
<td><span class="new_code">assertReference($x, $y)</span></td>
|
177 |
-
<td>Echoue sauf si $x et $y sont la même variable</td>
|
178 |
-
</tr>
|
179 |
-
<tr>
|
180 |
-
<td><span class="new_code">assertCopy($x, $y)</span></td>
|
181 |
-
<td>Echoue si $x et $y sont la même variable</td>
|
182 |
-
</tr>
|
183 |
-
<tr>
|
184 |
-
<td><span class="new_code">assertWantedPattern($p, $x)</span></td>
|
185 |
-
<td>Echoue sauf si l'expression rationnelle $p capture $x</td>
|
186 |
-
</tr>
|
187 |
-
<tr>
|
188 |
-
<td><span class="new_code">assertNoUnwantedPattern($p, $x)</span></td>
|
189 |
-
<td>Echoue si l'expression rationnelle $p capture $x</td>
|
190 |
-
</tr>
|
191 |
-
<tr>
|
192 |
-
<td><span class="new_code">assertNoErrors()</span></td>
|
193 |
-
<td>Echoue si une erreur PHP arrive</td>
|
194 |
-
</tr>
|
195 |
-
<tr>
|
196 |
-
<td><span class="new_code">assertError($x)</span></td>
|
197 |
-
<td>Echoue si aucune erreur ou message incorrect de PHP n'arrive</td>
|
198 |
-
</tr>
|
199 |
-
</tbody></table>
|
200 |
-
Toutes les méthodes d'assertion peuvent recevoir
|
201 |
-
une description optionnelle :
|
202 |
-
cette description sert pour étiqueter le résultat.
|
203 |
-
Sans elle, une message par défaut est envoyée à la place :
|
204 |
-
il est généralement suffisant.
|
205 |
-
Ce message par défaut peut encore être encadré
|
206 |
-
dans votre propre message si vous incluez "%s"
|
207 |
-
dans la chaîne.
|
208 |
-
Toutes les assertions renvoient vrai / true en cas de succès
|
209 |
-
et faux / false en cas d'échec.
|
210 |
-
</p>
|
211 |
-
<p>
|
212 |
-
D'autres exemples...
|
213 |
-
<pre>
|
214 |
-
<strong>$variable = null;
|
215 |
-
$this->assertNull($variable, 'Should be cleared');</strong>
|
216 |
-
</pre>
|
217 |
-
...passera et normalement n'affichera aucun message.
|
218 |
-
Si vous avez <a href="http://www.lastcraft.com/display_subclass_tutorial.php">
|
219 |
-
configuré le testeur pour afficher aussi les succès</a>
|
220 |
-
alors le message sera affiché comme tel.
|
221 |
-
<pre>
|
222 |
-
<strong>$this->assertIdentical(0, false, 'Zero is not false [%s]');</strong>
|
223 |
-
</pre>
|
224 |
-
Ceci échouera étant donné qu'il effectue une vérification
|
225 |
-
sur le type en plus d'une comparaison sur les deux valeurs.
|
226 |
-
La partie "%s" est remplacée par le message d'erreur
|
227 |
-
par défaut qui aurait été affiché si nous n'avions pas fourni le nôtre.
|
228 |
-
Cela nous permet d'emboîter les messages de test.
|
229 |
-
<pre>
|
230 |
-
<strong>$a = 1;
|
231 |
-
$b = $a;
|
232 |
-
$this->assertReference($a, $b);</strong>
|
233 |
-
</pre>
|
234 |
-
Échouera étant donné que la variable <span class="new_code">$b</span>
|
235 |
-
est une copie de <span class="new_code">$a</span>.
|
236 |
-
<pre>
|
237 |
-
<strong>$this->assertWantedPattern('/hello/i', 'Hello world');</strong>
|
238 |
-
</pre>
|
239 |
-
Là, ça passe puisque la recherche est insensible
|
240 |
-
à la casse et que donc <span class="new_code">hello</span>
|
241 |
-
est bien repérable dans <span class="new_code">Hello world</span>.
|
242 |
-
<pre>
|
243 |
-
<strong>trigger_error('Disaster');
|
244 |
-
trigger_error('Catastrophe');
|
245 |
-
$this->assertError();
|
246 |
-
$this->assertError('Catastrophe');
|
247 |
-
$this->assertNoErrors();</strong>
|
248 |
-
</pre>
|
249 |
-
Ici, il y a besoin d'une petite explication :
|
250 |
-
toutes passent !
|
251 |
-
</p>
|
252 |
-
<p>
|
253 |
-
Les erreurs PHP dans SimpleTest sont piégées et
|
254 |
-
placées dans une queue. Ici la première vérification
|
255 |
-
d'erreur attrape le message "Disaster"
|
256 |
-
sans vérifier le texte et passe. Résultat :
|
257 |
-
l'erreur est supprimée de la queue.
|
258 |
-
La vérification suivante teste non seulement l'existence
|
259 |
-
de l'erreur mais aussi le texte qui correspond :
|
260 |
-
un autre succès. Désormais la queue est vide
|
261 |
-
et le dernier test passe aussi.
|
262 |
-
Si une autre erreur non vérifiée est encore
|
263 |
-
dans la queue à la fin de notre méthode de test
|
264 |
-
alors une exception sera rapportée dans le test.
|
265 |
-
Notez que SimpleTest ne peut pas attraper les erreurs PHP à la compilation.
|
266 |
-
</p>
|
267 |
-
<p>
|
268 |
-
Les scénarios de test peuvent utiliser des méthodes
|
269 |
-
bien pratiques pour déboguer le code ou pour étendre la suite...
|
270 |
-
<table><tbody>
|
271 |
-
<tr>
|
272 |
-
<td><span class="new_code">setUp()</span></td>
|
273 |
-
<td>Est lancée avant chaque méthode de test</td>
|
274 |
-
</tr>
|
275 |
-
<tr>
|
276 |
-
<td><span class="new_code">tearDown()</span></td>
|
277 |
-
<td>Est lancée après chaque méthode de test</td>
|
278 |
-
</tr>
|
279 |
-
<tr>
|
280 |
-
<td><span class="new_code">pass()</span></td>
|
281 |
-
<td>Envoie un succès</td>
|
282 |
-
</tr>
|
283 |
-
<tr>
|
284 |
-
<td><span class="new_code">fail()</span></td>
|
285 |
-
<td>Envoie un échec</td>
|
286 |
-
</tr>
|
287 |
-
<tr>
|
288 |
-
<td><span class="new_code">error()</span></td>
|
289 |
-
<td>Envoi un évènement exception</td>
|
290 |
-
</tr>
|
291 |
-
<tr>
|
292 |
-
<td><span class="new_code">sendMessage()</span></td>
|
293 |
-
<td>Envoie un message d'état aux systèmes d'affichage qui le supporte</td>
|
294 |
-
</tr>
|
295 |
-
<tr>
|
296 |
-
<td><span class="new_code">signal($type, $payload)</span></td>
|
297 |
-
<td>Envoie un message défini par l'utilisateur au rapporteur du test</td>
|
298 |
-
</tr>
|
299 |
-
<tr>
|
300 |
-
<td><span class="new_code">dump($var)</span></td>
|
301 |
-
<td>Effectue un <span class="new_code">print_r()</span> formaté pour du déboguage rapide et grossier</td>
|
302 |
-
</tr>
|
303 |
-
<tr>
|
304 |
-
<td><span class="new_code">swallowErrors()</span></td>
|
305 |
-
<td>Vide les erreurs de la queue</td>
|
306 |
-
</tr>
|
307 |
-
</tbody></table>
|
308 |
-
</p>
|
309 |
-
|
310 |
-
<h2>
|
311 |
-
<a class="target" name="extension_unitaire"></a>Etendre les scénarios de test</h2>
|
312 |
-
<p>
|
313 |
-
Bien sûr des méthodes supplémentaires de test
|
314 |
-
peuvent être ajoutées pour créer d'autres types
|
315 |
-
de scénario de test afin d'étendre le framework...
|
316 |
-
<pre>
|
317 |
-
require_once('simpletest/autorun.php');
|
318 |
-
<strong>
|
319 |
-
class FileTester extends UnitTestCase {
|
320 |
-
function FileTester($name = false) {
|
321 |
-
$this->UnitTestCase($name);
|
322 |
-
}
|
323 |
-
|
324 |
-
function assertFileExists($filename, $message = '%s') {
|
325 |
-
$this->assertTrue(
|
326 |
-
file_exists($filename),
|
327 |
-
sprintf($message, 'File [$filename] existence check'));
|
328 |
-
}</strong>
|
329 |
-
}
|
330 |
-
</pre>
|
331 |
-
Ici la bibliothèque SimpleTest est localisée
|
332 |
-
dans un répertoire local appelé <em>simpletest</em>.
|
333 |
-
Pensez à le modifier pour votre propre environnement.
|
334 |
-
</p>
|
335 |
-
<p>
|
336 |
-
Alternativement vous pourriez utiliser dans votre code
|
337 |
-
un directive <span class="new_code">SimpleTestOptions::ignore('FileTester');</span>.
|
338 |
-
</p>
|
339 |
-
<p>
|
340 |
-
Ce nouveau scénario peut être hérité exactement
|
341 |
-
comme un scénario de test classique...
|
342 |
-
<pre>
|
343 |
-
class FileTestCase extends <strong>FileTester</strong> {
|
344 |
-
|
345 |
-
function setUp() {
|
346 |
-
@unlink('../temp/test.txt');
|
347 |
-
}
|
348 |
-
|
349 |
-
function tearDown() {
|
350 |
-
@unlink('../temp/test.txt');
|
351 |
-
}
|
352 |
-
|
353 |
-
function testCreation() {
|
354 |
-
$writer = &new FileWriter('../temp/test.txt');
|
355 |
-
$writer->write('Hello');<strong>
|
356 |
-
$this->assertFileExists('../temp/test.txt');</strong>
|
357 |
-
}
|
358 |
-
}
|
359 |
-
</pre>
|
360 |
-
</p>
|
361 |
-
<p>
|
362 |
-
Si vous souhaitez un scénario de test sans
|
363 |
-
toutes les assertions de <span class="new_code">UnitTestCase</span>
|
364 |
-
mais uniquement avec les vôtres propres,
|
365 |
-
vous aurez besoin d'étendre la classe
|
366 |
-
<span class="new_code">SimpleTestCase</span> à la place.
|
367 |
-
Elle se trouve dans <em>simple_test.php</em>
|
368 |
-
en lieu et place de <em>unit_tester.php</em>.
|
369 |
-
A consulter <a href="group_test_documentation.html">plus tard</a>
|
370 |
-
si vous souhaitez incorporer les scénarios
|
371 |
-
d'autres testeurs unitaires dans votre suite de test.
|
372 |
-
</p>
|
373 |
-
|
374 |
-
<h2>
|
375 |
-
<a class="target" name="lancement_unitaire"></a>Lancer un unique scénario de test</h2>
|
376 |
-
<p>
|
377 |
-
Ce n'est pas souvent qu'il faille lancer des scénarios
|
378 |
-
avec un unique test. Sauf lorsqu'il s'agit de s'arracher
|
379 |
-
les cheveux sur un module à problème sans pour
|
380 |
-
autant désorganiser la suite de test principale.
|
381 |
-
Avec <em>autorun</em> aucun échafaudage particulier
|
382 |
-
n'est nécessaire, il suffit de lancer votre test et
|
383 |
-
vous y êtes.
|
384 |
-
</p>
|
385 |
-
<p>
|
386 |
-
Vous pouvez même décider quel rapporteur
|
387 |
-
(par exemple, <span class="new_code">TextReporter</span> ou <span class="new_code">HtmlReporter</span>)
|
388 |
-
vous préférez pour un fichier spécifique quand il est lancé
|
389 |
-
tout seul...
|
390 |
-
<pre>
|
391 |
-
<?php
|
392 |
-
require_once('simpletest/autorun.php');<strong>
|
393 |
-
SimpleTest :: prefer(new TextReporter());</strong>
|
394 |
-
require_once('../classes/writer.php');
|
395 |
-
|
396 |
-
class FileTestCase extends UnitTestCase {
|
397 |
-
...
|
398 |
-
}
|
399 |
-
?>
|
400 |
-
</pre>
|
401 |
-
Ce script sera lancé tel que mais il n'y aura
|
402 |
-
aucun succès ou échec avant que des méthodes de test soient ajoutées.
|
403 |
-
</p>
|
404 |
-
|
405 |
-
</div>
|
406 |
-
References and related information...
|
407 |
-
<ul>
|
408 |
-
<li>
|
409 |
-
La page de SimpleTest sur
|
410 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
411 |
-
</li>
|
412 |
-
<li>
|
413 |
-
La page de téléchargement de SimpleTest sur
|
414 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
415 |
-
</li>
|
416 |
-
<li>
|
417 |
-
<a href="http://simpletest.org/api/">L'API complète de SimpleTest</a>
|
418 |
-
à partir de PHPDoc.
|
419 |
-
</li>
|
420 |
-
</ul>
|
421 |
-
<div class="menu_back"><div class="menu">
|
422 |
-
<a href="index.html">SimpleTest</a>
|
423 |
-
|
|
424 |
-
<a href="overview.html">Overview</a>
|
425 |
-
|
|
426 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
427 |
-
|
|
428 |
-
<a href="group_test_documentation.html">Group tests</a>
|
429 |
-
|
|
430 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
431 |
-
|
|
432 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
433 |
-
|
|
434 |
-
<a href="reporter_documentation.html">Reporting</a>
|
435 |
-
|
|
436 |
-
<a href="expectation_documentation.html">Expectations</a>
|
437 |
-
|
|
438 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
439 |
-
|
|
440 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
441 |
-
|
|
442 |
-
<a href="authentication_documentation.html">Authentication</a>
|
443 |
-
|
|
444 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
445 |
-
</div></div>
|
446 |
-
<div class="copyright">
|
447 |
-
Copyright<br>Marcus Baker 2006
|
448 |
-
</div>
|
449 |
-
</body>
|
450 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/docs/fr/web_tester_documentation.html
DELETED
@@ -1,570 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head>
|
3 |
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4 |
-
<title>Documentation SimpleTest : tester des scripts web</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 le testeur web</h1>
|
34 |
-
This page...
|
35 |
-
<ul>
|
36 |
-
<li>
|
37 |
-
Réussir à <a href="#telecharger">télécharger une page web</a>
|
38 |
-
</li>
|
39 |
-
<li>
|
40 |
-
Tester le <a href="#contenu">contenu de la page</a>
|
41 |
-
</li>
|
42 |
-
<li>
|
43 |
-
<a href="#navigation">Naviguer sur un site web</a> pendant le test
|
44 |
-
</li>
|
45 |
-
<li>
|
46 |
-
Méthodes pour <a href="#requete">modifier une requête</a> et pour déboguer
|
47 |
-
</li>
|
48 |
-
</ul>
|
49 |
-
<div class="content">
|
50 |
-
<h2>
|
51 |
-
<a class="target" name="telecharger"></a>Télécharger une page</h2>
|
52 |
-
<p>
|
53 |
-
Tester des classes c'est très bien.
|
54 |
-
Reste que PHP est avant tout un langage
|
55 |
-
pour créer des fonctionnalités à l'intérieur de pages web.
|
56 |
-
Comment pouvons tester la partie de devant
|
57 |
-
-- celle de l'interface -- dans nos applications en PHP ?
|
58 |
-
Etant donné qu'une page web n'est constituée que de texte,
|
59 |
-
nous devrions pouvoir les examiner exactement
|
60 |
-
comme n'importe quelle autre donnée de test.
|
61 |
-
</p>
|
62 |
-
<p>
|
63 |
-
Cela nous amène à une situation délicate.
|
64 |
-
Si nous testons dans un niveau trop bas,
|
65 |
-
vérifier des balises avec un motif ad hoc par exemple,
|
66 |
-
nos tests seront trop fragiles. Le moindre changement
|
67 |
-
dans la présentation pourrait casser un grand nombre de test.
|
68 |
-
Si nos tests sont situés trop haut, en utilisant
|
69 |
-
une version fantaisie du moteur de template pour
|
70 |
-
donner un cas précis, alors nous perdons complètement
|
71 |
-
la capacité à automatiser certaines classes de test.
|
72 |
-
Par exemple, l'interaction entre des formulaires
|
73 |
-
et la navigation devra être testé manuellement.
|
74 |
-
Ces types de test sont extrêmement fastidieux
|
75 |
-
et plutôt sensibles aux erreurs.
|
76 |
-
</p>
|
77 |
-
<p>
|
78 |
-
SimpleTest comprend une forme spéciale de scénario
|
79 |
-
de test pour tester les actions d'une page web.
|
80 |
-
<span class="new_code">WebTestCase</span> inclut des facilités pour la navigation,
|
81 |
-
des vérifications sur le contenu
|
82 |
-
et les cookies ainsi que la gestion des formulaires.
|
83 |
-
Utiliser ces scénarios de test ressemble
|
84 |
-
fortement à <span class="new_code">UnitTestCase</span>...
|
85 |
-
<pre>
|
86 |
-
<strong>class TestOfLastcraft extends WebTestCase {
|
87 |
-
}</strong>
|
88 |
-
</pre>
|
89 |
-
Ici nous sommes sur le point de tester
|
90 |
-
le site de <a href="http://www.lastcraft.com/">Last Craft</a>.
|
91 |
-
Si ce scénario de test est situé dans un fichier appelé
|
92 |
-
<em>lastcraft_test.php</em> alors il peut être chargé
|
93 |
-
dans un script de lancement tout comme des tests unitaires...
|
94 |
-
<pre>
|
95 |
-
<?php
|
96 |
-
require_once('simpletest/autorun.php');<strong>
|
97 |
-
require_once('simpletest/web_tester.php');</strong>
|
98 |
-
SimpleTest::prefer(new TextReporter());
|
99 |
-
|
100 |
-
class WebTests extends TestSuite {
|
101 |
-
function WebTests() {
|
102 |
-
$this->TestSuite('Web site tests');<strong>
|
103 |
-
$this->addFile('lastcraft_test.php');</strong>
|
104 |
-
}
|
105 |
-
}
|
106 |
-
?>
|
107 |
-
</pre>
|
108 |
-
J'utilise ici le rapporteur en mode texte
|
109 |
-
pour mieux distinguer le contenu au format HTML
|
110 |
-
du résultat du test proprement dit.
|
111 |
-
</p>
|
112 |
-
<p>
|
113 |
-
Rien n'est encore testé. Nous pouvons télécharger
|
114 |
-
la page d'accueil en utilisant la méthode <span class="new_code">get()</span>...
|
115 |
-
<pre>
|
116 |
-
class TestOfLastcraft extends WebTestCase {
|
117 |
-
<strong>
|
118 |
-
function testHomepage() {
|
119 |
-
$this->assertTrue($this->get('http://www.lastcraft.com/'));
|
120 |
-
}</strong>
|
121 |
-
}
|
122 |
-
</pre>
|
123 |
-
La méthode <span class="new_code">get()</span> renverra "true"
|
124 |
-
uniquement si le contenu de la page a bien été téléchargé.
|
125 |
-
C'est un moyen simple, mais efficace pour vérifier
|
126 |
-
qu'une page web a bien été délivré par le serveur web.
|
127 |
-
Cependant le contenu peut révéler être une erreur 404
|
128 |
-
et dans ce cas notre méthode <span class="new_code">get()</span> renverrait encore un succès.
|
129 |
-
</p>
|
130 |
-
<p>
|
131 |
-
En supposant que le serveur web pour le site Last Craft
|
132 |
-
soit opérationnel (malheureusement ce n'est pas toujours le cas),
|
133 |
-
nous devrions voir...
|
134 |
-
<pre class="shell">
|
135 |
-
Web site tests
|
136 |
-
OK
|
137 |
-
Test cases run: 1/1, Failures: 0, Exceptions: 0
|
138 |
-
</pre>
|
139 |
-
Nous avons vérifié qu'une page, de n'importe quel type,
|
140 |
-
a bien été renvoyée. Nous ne savons pas encore
|
141 |
-
s'il s'agit de celle que nous souhaitions.
|
142 |
-
</p>
|
143 |
-
|
144 |
-
<h2>
|
145 |
-
<a class="target" name="contenu"></a>Tester le contenu d'une page</h2>
|
146 |
-
<p>
|
147 |
-
Pour obtenir la confirmation que la page téléchargée
|
148 |
-
est bien celle que nous attendions,
|
149 |
-
nous devons vérifier son contenu.
|
150 |
-
<pre>
|
151 |
-
class TestOfLastcraft extends WebTestCase {
|
152 |
-
|
153 |
-
function testHomepage() {<strong>
|
154 |
-
$this->get('http://www.lastcraft.com/');
|
155 |
-
$this->assertWantedPattern('/why the last craft/i');</strong>
|
156 |
-
}
|
157 |
-
}
|
158 |
-
</pre>
|
159 |
-
La page obtenue par le dernier téléchargement est
|
160 |
-
placée dans un buffer au sein même du scénario de test.
|
161 |
-
Il n'est donc pas nécessaire de s'y référer directement.
|
162 |
-
La correspondance du motif est toujours effectuée
|
163 |
-
par rapport à ce buffer.
|
164 |
-
</p>
|
165 |
-
<p>
|
166 |
-
Voici une liste possible d'assertions sur le contenu...
|
167 |
-
<table><tbody>
|
168 |
-
<tr>
|
169 |
-
<td><span class="new_code">assertWantedPattern($pattern)</span></td>
|
170 |
-
<td>Vérifier une correspondance sur le contenu via une expression rationnelle Perl</td>
|
171 |
-
</tr>
|
172 |
-
<tr>
|
173 |
-
<td><span class="new_code">assertNoUnwantedPattern($pattern)</span></td>
|
174 |
-
<td>Une expression rationnelle Perl pour vérifier une absence</td>
|
175 |
-
</tr>
|
176 |
-
<tr>
|
177 |
-
<td><span class="new_code">assertTitle($title)</span></td>
|
178 |
-
<td>Passe si le titre de la page correspond exactement</td>
|
179 |
-
</tr>
|
180 |
-
<tr>
|
181 |
-
<td><span class="new_code">assertLink($label)</span></td>
|
182 |
-
<td>Passe si un lien avec ce texte est présent</td>
|
183 |
-
</tr>
|
184 |
-
<tr>
|
185 |
-
<td><span class="new_code">assertNoLink($label)</span></td>
|
186 |
-
<td>Passe si aucun lien avec ce texte est présent</td>
|
187 |
-
</tr>
|
188 |
-
<tr>
|
189 |
-
<td><span class="new_code">assertLinkById($id)</span></td>
|
190 |
-
<td>Passe si un lien avec cet attribut d'identification est présent</td>
|
191 |
-
</tr>
|
192 |
-
<tr>
|
193 |
-
<td><span class="new_code">assertField($name, $value)</span></td>
|
194 |
-
<td>Passe si une balise input avec ce nom contient cette valeur</td>
|
195 |
-
</tr>
|
196 |
-
<tr>
|
197 |
-
<td><span class="new_code">assertFieldById($id, $value)</span></td>
|
198 |
-
<td>Passe si une balise input avec cet identifiant contient cette valeur</td>
|
199 |
-
</tr>
|
200 |
-
<tr>
|
201 |
-
<td><span class="new_code">assertResponse($codes)</span></td>
|
202 |
-
<td>Passe si la réponse HTTP trouve une correspondance dans la liste</td>
|
203 |
-
</tr>
|
204 |
-
<tr>
|
205 |
-
<td><span class="new_code">assertMime($types)</span></td>
|
206 |
-
<td>Passe si le type MIME se retrouve dans cette liste</td>
|
207 |
-
</tr>
|
208 |
-
<tr>
|
209 |
-
<td><span class="new_code">assertAuthentication($protocol)</span></td>
|
210 |
-
<td>Passe si l'authentification provoquée est de ce type de protocole</td>
|
211 |
-
</tr>
|
212 |
-
<tr>
|
213 |
-
<td><span class="new_code">assertNoAuthentication()</span></td>
|
214 |
-
<td>Passe s'il n'y pas d'authentification provoquée en cours</td>
|
215 |
-
</tr>
|
216 |
-
<tr>
|
217 |
-
<td><span class="new_code">assertRealm($name)</span></td>
|
218 |
-
<td>Passe si le domaine provoqué correspond</td>
|
219 |
-
</tr>
|
220 |
-
<tr>
|
221 |
-
<td><span class="new_code">assertHeader($header, $content)</span></td>
|
222 |
-
<td>Passe si une entête téléchargée correspond à cette valeur</td>
|
223 |
-
</tr>
|
224 |
-
<tr>
|
225 |
-
<td><span class="new_code">assertNoUnwantedHeader($header)</span></td>
|
226 |
-
<td>Passe si une entête n'a pas été téléchargé</td>
|
227 |
-
</tr>
|
228 |
-
<tr>
|
229 |
-
<td><span class="new_code">assertHeaderPattern($header, $pattern)</span></td>
|
230 |
-
<td>Passe si une entête téléchargée correspond à cette expression rationnelle Perl</td>
|
231 |
-
</tr>
|
232 |
-
<tr>
|
233 |
-
<td><span class="new_code">assertCookie($name, $value)</span></td>
|
234 |
-
<td>Passe s'il existe un cookie correspondant</td>
|
235 |
-
</tr>
|
236 |
-
<tr>
|
237 |
-
<td><span class="new_code">assertNoCookie($name)</span></td>
|
238 |
-
<td>Passe s'il n'y a pas de cookie avec un tel nom</td>
|
239 |
-
</tr>
|
240 |
-
</tbody></table>
|
241 |
-
Comme d'habitude avec les assertions de SimpleTest,
|
242 |
-
elles renvoient toutes "false" en cas d'échec
|
243 |
-
et "true" si c'est un succès.
|
244 |
-
Elles renvoient aussi un message de test optionnel :
|
245 |
-
vous pouvez l'ajouter dans votre propre message en utilisant "%s".
|
246 |
-
</p>
|
247 |
-
<p>
|
248 |
-
A présent nous pourrions effectué le test sur le titre uniquement...
|
249 |
-
<pre>
|
250 |
-
<strong>$this->assertTitle('The Last Craft?');</strong>
|
251 |
-
</pre>
|
252 |
-
En plus d'une simple vérification sur le contenu HTML,
|
253 |
-
nous pouvons aussi vérifier que le type MIME est bien d'un type acceptable...
|
254 |
-
<pre>
|
255 |
-
<strong>$this->assertMime(array('text/plain', 'text/html'));</strong>
|
256 |
-
</pre>
|
257 |
-
Plus intéressant encore est la vérification sur
|
258 |
-
le code de la réponse HTTP. Pareillement au type MIME,
|
259 |
-
nous pouvons nous assurer que le code renvoyé se trouve
|
260 |
-
bien dans un liste de valeurs possibles...
|
261 |
-
<pre>
|
262 |
-
class TestOfLastcraft extends WebTestCase {
|
263 |
-
|
264 |
-
function testHomepage() {
|
265 |
-
$this->get('http://simpletest.sourceforge.net/');<strong>
|
266 |
-
$this->assertResponse(200);</strong>
|
267 |
-
}
|
268 |
-
}
|
269 |
-
</pre>
|
270 |
-
Ici nous vérifions que le téléchargement s'est
|
271 |
-
bien terminé en ne permettant qu'une réponse HTTP 200.
|
272 |
-
Ce test passera, mais ce n'est pas la meilleure façon de procéder.
|
273 |
-
Il n'existe aucune page sur <em>http://simpletest.sourceforge.net/</em>,
|
274 |
-
à la place le serveur renverra une redirection vers
|
275 |
-
<em>http://www.lastcraft.com/simple_test.php</em>.
|
276 |
-
<span class="new_code">WebTestCase</span> suit automatiquement trois
|
277 |
-
de ces redirections. Les tests sont quelque peu plus
|
278 |
-
robustes de la sorte. Surtout qu'on est souvent plus intéressé
|
279 |
-
par l'interaction entre les pages que de leur simple livraison.
|
280 |
-
Si les redirections se révèlent être digne d'intérêt,
|
281 |
-
il reste possible de les supprimer...
|
282 |
-
<pre>
|
283 |
-
class TestOfLastcraft extends WebTestCase {
|
284 |
-
|
285 |
-
function testHomepage() {<strong>
|
286 |
-
$this->setMaximumRedirects(0);</strong>
|
287 |
-
$this->get('http://simpletest.sourceforge.net/');
|
288 |
-
$this->assertResponse(200);
|
289 |
-
}
|
290 |
-
}
|
291 |
-
</pre>
|
292 |
-
Alors l'assertion échoue comme prévue...
|
293 |
-
<pre class="shell">
|
294 |
-
Web site tests
|
295 |
-
1) Expecting response in [200] got [302]
|
296 |
-
in testhomepage
|
297 |
-
in testoflastcraft
|
298 |
-
in lastcraft_test.php
|
299 |
-
FAILURES!!!
|
300 |
-
Test cases run: 1/1, Failures: 1, Exceptions: 0
|
301 |
-
</pre>
|
302 |
-
Nous pouvons modifier le test pour accepter les redirections...
|
303 |
-
<pre>
|
304 |
-
class TestOfLastcraft extends WebTestCase {
|
305 |
-
|
306 |
-
function testHomepage() {
|
307 |
-
$this->setMaximumRedirects(0);
|
308 |
-
$this->get('http://simpletest.sourceforge.net/');
|
309 |
-
$this->assertResponse(<strong>array(301, 302, 303, 307)</strong>);
|
310 |
-
}
|
311 |
-
}
|
312 |
-
</pre>
|
313 |
-
Maitenant ça passe.
|
314 |
-
</p>
|
315 |
-
|
316 |
-
<h2>
|
317 |
-
<a class="target" name="navigation"></a>Navigeur dans un site web</h2>
|
318 |
-
<p>
|
319 |
-
Les utilisateurs ne naviguent pas souvent en tapant les URLs,
|
320 |
-
mais surtout en cliquant sur des liens et des boutons.
|
321 |
-
Ici nous confirmons que les informations sur le contact
|
322 |
-
peuvent être atteintes depuis la page d'accueil...
|
323 |
-
<pre>
|
324 |
-
class TestOfLastcraft extends WebTestCase {
|
325 |
-
...
|
326 |
-
function testContact() {
|
327 |
-
$this->get('http://www.lastcraft.com/');<strong>
|
328 |
-
$this->clickLink('About');
|
329 |
-
$this->assertTitle('About Last Craft');</strong>
|
330 |
-
}
|
331 |
-
}
|
332 |
-
</pre>
|
333 |
-
Le paramètre est le texte du lien.
|
334 |
-
</p>
|
335 |
-
<p>
|
336 |
-
Il l'objectif est un bouton plutôt qu'une balise ancre,
|
337 |
-
alors <span class="new_code">clickSubmit()</span> doit être utilisé avec
|
338 |
-
le titre du bouton...
|
339 |
-
<pre>
|
340 |
-
<strong>$this->clickSubmit('Go!');</strong>
|
341 |
-
</pre>
|
342 |
-
</p>
|
343 |
-
<p>
|
344 |
-
La liste des méthodes de navigation est...
|
345 |
-
<table><tbody>
|
346 |
-
<tr>
|
347 |
-
<td><span class="new_code">get($url, $parameters)</span></td>
|
348 |
-
<td>Envoie une requête GET avec ces paramètres</td>
|
349 |
-
</tr>
|
350 |
-
<tr>
|
351 |
-
<td><span class="new_code">post($url, $parameters)</span></td>
|
352 |
-
<td>Envoie une requête POST avec ces paramètres</td>
|
353 |
-
</tr>
|
354 |
-
<tr>
|
355 |
-
<td><span class="new_code">head($url, $parameters)</span></td>
|
356 |
-
<td>Envoie une requête HEAD sans remplacer le contenu de la page</td>
|
357 |
-
</tr>
|
358 |
-
<tr>
|
359 |
-
<td><span class="new_code">retry()</span></td>
|
360 |
-
<td>Relance la dernière requête</td>
|
361 |
-
</tr>
|
362 |
-
<tr>
|
363 |
-
<td><span class="new_code">back()</span></td>
|
364 |
-
<td>Identique au bouton "Précédent" du navigateur</td>
|
365 |
-
</tr>
|
366 |
-
<tr>
|
367 |
-
<td><span class="new_code">forward()</span></td>
|
368 |
-
<td>Identique au bouton "Suivant" du navigateur</td>
|
369 |
-
</tr>
|
370 |
-
<tr>
|
371 |
-
<td><span class="new_code">authenticate($name, $password)</span></td>
|
372 |
-
<td>Re-essaye avec une tentative d'authentification</td>
|
373 |
-
</tr>
|
374 |
-
<tr>
|
375 |
-
<td><span class="new_code">getFrameFocus()</span></td>
|
376 |
-
<td>Le nom de la fenêtre en cours d'utilisation</td>
|
377 |
-
</tr>
|
378 |
-
<tr>
|
379 |
-
<td><span class="new_code">setFrameFocusByIndex($choice)</span></td>
|
380 |
-
<td>Change le focus d'une fenêtre en commençant par 1</td>
|
381 |
-
</tr>
|
382 |
-
<tr>
|
383 |
-
<td><span class="new_code">setFrameFocus($name)</span></td>
|
384 |
-
<td>Change le focus d'une fenêtre en utilisant son nom</td>
|
385 |
-
</tr>
|
386 |
-
<tr>
|
387 |
-
<td><span class="new_code">clearFrameFocus()</span></td>
|
388 |
-
<td>Revient à un traitement de toutes les fenêtres comme une seule</td>
|
389 |
-
</tr>
|
390 |
-
<tr>
|
391 |
-
<td><span class="new_code">clickSubmit($label)</span></td>
|
392 |
-
<td>Clique sur le premier bouton avec cette étiquette</td>
|
393 |
-
</tr>
|
394 |
-
<tr>
|
395 |
-
<td><span class="new_code">clickSubmitByName($name)</span></td>
|
396 |
-
<td>Clique sur le bouton avec cet attribut de nom</td>
|
397 |
-
</tr>
|
398 |
-
<tr>
|
399 |
-
<td><span class="new_code">clickSubmitById($id)</span></td>
|
400 |
-
<td>Clique sur le bouton avec cet attribut d'identification</td>
|
401 |
-
</tr>
|
402 |
-
<tr>
|
403 |
-
<td><span class="new_code">clickImage($label, $x, $y)</span></td>
|
404 |
-
<td>Clique sur une balise input de type image par son titre (title="*") our son texte alternatif (alt="*")</td>
|
405 |
-
</tr>
|
406 |
-
<tr>
|
407 |
-
<td><span class="new_code">clickImageByName($name, $x, $y)</span></td>
|
408 |
-
<td>Clique sur une balise input de type image par son attribut (name="*")</td>
|
409 |
-
</tr>
|
410 |
-
<tr>
|
411 |
-
<td><span class="new_code">clickImageById($id, $x, $y)</span></td>
|
412 |
-
<td>Clique sur une balise input de type image par son identifiant (id="*")</td>
|
413 |
-
</tr>
|
414 |
-
<tr>
|
415 |
-
<td><span class="new_code">submitFormById($id)</span></td>
|
416 |
-
<td>Soumet un formulaire sans valeur de soumission</td>
|
417 |
-
</tr>
|
418 |
-
<tr>
|
419 |
-
<td><span class="new_code">clickLink($label, $index)</span></td>
|
420 |
-
<td>Clique sur une ancre avec ce texte d'étiquette visible</td>
|
421 |
-
</tr>
|
422 |
-
<tr>
|
423 |
-
<td><span class="new_code">clickLinkById($id)</span></td>
|
424 |
-
<td>Clique sur une ancre avec cet attribut d'identification</td>
|
425 |
-
</tr>
|
426 |
-
</tbody></table>
|
427 |
-
</p>
|
428 |
-
<p>
|
429 |
-
Les paramètres dans les méthodes <span class="new_code">get()</span>,
|
430 |
-
<span class="new_code">post()</span> et <span class="new_code">head()</span> sont optionnels.
|
431 |
-
Le téléchargement via HTTP HEAD ne modifie pas
|
432 |
-
le contexte du navigateur, il se limite au chargement des cookies.
|
433 |
-
Cela peut être utilise lorsqu'une image ou une feuille de style
|
434 |
-
initie un cookie pour bloquer un robot trop entreprenant.
|
435 |
-
</p>
|
436 |
-
<p>
|
437 |
-
Les commandes <span class="new_code">retry()</span>, <span class="new_code">back()</span>
|
438 |
-
et <span class="new_code">forward()</span> fonctionnent exactement comme
|
439 |
-
dans un navigateur. Elles utilisent l'historique pour
|
440 |
-
relancer les pages. Une technique bien pratique pour
|
441 |
-
vérifier les effets d'un bouton retour sur vos formulaires.
|
442 |
-
</p>
|
443 |
-
<p>
|
444 |
-
Les méthodes sur les fenêtres méritent une petite explication.
|
445 |
-
Par défaut, une page avec des fenêtres est traitée comme toutes
|
446 |
-
les autres. Le contenu sera vérifié à travers l'ensemble de
|
447 |
-
la "frameset", par conséquent un lien fonctionnera,
|
448 |
-
peu importe la fenêtre qui contient la balise ancre.
|
449 |
-
Vous pouvez outrepassé ce comportement en exigeant
|
450 |
-
le focus sur une unique fenêtre. Si vous réalisez cela,
|
451 |
-
toutes les recherches et toutes les actions se limiteront
|
452 |
-
à cette unique fenêtre, y compris les demandes d'authentification.
|
453 |
-
Si un lien ou un bouton n'est pas dans la fenêtre en focus alors
|
454 |
-
il ne peut pas être cliqué.
|
455 |
-
</p>
|
456 |
-
<p>
|
457 |
-
Tester la navigation sur des pages fixes ne vous alerte que
|
458 |
-
quand vous avez cassé un script entier.
|
459 |
-
Pour des pages fortement dynamiques,
|
460 |
-
un forum de discussion par exemple,
|
461 |
-
ça peut être crucial pour vérifier l'état de l'application.
|
462 |
-
Pour la plupart des applications cependant,
|
463 |
-
la logique vraiment délicate se situe dans la gestion
|
464 |
-
des formulaires et des sessions.
|
465 |
-
Heureusement SimpleTest aussi inclut
|
466 |
-
<a href="form_testing_documentation.html">
|
467 |
-
des outils pour tester des formulaires web</a>.
|
468 |
-
</p>
|
469 |
-
|
470 |
-
<h2>
|
471 |
-
<a class="target" name="requete"></a>Modifier la requête</h2>
|
472 |
-
<p>
|
473 |
-
Bien que SimpleTest n'ait pas comme objectif
|
474 |
-
de contrôler des erreurs réseau, il contient quand même
|
475 |
-
des méthodes pour modifier et déboguer les requêtes qu'il lance.
|
476 |
-
Voici une autre liste de méthode...
|
477 |
-
<table><tbody>
|
478 |
-
<tr>
|
479 |
-
<td><span class="new_code">getTransportError()</span></td>
|
480 |
-
<td>La dernière erreur de socket</td>
|
481 |
-
</tr>
|
482 |
-
<tr>
|
483 |
-
<td><span class="new_code">getUrl()</span></td>
|
484 |
-
<td>La localisation courante</td>
|
485 |
-
</tr>
|
486 |
-
<tr>
|
487 |
-
<td><span class="new_code">showRequest()</span></td>
|
488 |
-
<td>Déverse la requête sortante</td>
|
489 |
-
</tr>
|
490 |
-
<tr>
|
491 |
-
<td><span class="new_code">showHeaders()</span></td>
|
492 |
-
<td>Déverse les entêtes d'entrée</td>
|
493 |
-
</tr>
|
494 |
-
<tr>
|
495 |
-
<td><span class="new_code">showSource()</span></td>
|
496 |
-
<td>Déverse le contenu brut de la page HTML</td>
|
497 |
-
</tr>
|
498 |
-
<tr>
|
499 |
-
<td><span class="new_code">ignoreFrames()</span></td>
|
500 |
-
<td>Ne recharge pas les framesets</td>
|
501 |
-
</tr>
|
502 |
-
<tr>
|
503 |
-
<td><span class="new_code">setCookie($name, $value)</span></td>
|
504 |
-
<td>Initie un cookie à partir de maintenant</td>
|
505 |
-
</tr>
|
506 |
-
<tr>
|
507 |
-
<td><span class="new_code">addHeader($header)</span></td>
|
508 |
-
<td>Ajoute toujours cette entête à la requête</td>
|
509 |
-
</tr>
|
510 |
-
<tr>
|
511 |
-
<td><span class="new_code">setMaximumRedirects($max)</span></td>
|
512 |
-
<td>S'arrête après autant de redirections</td>
|
513 |
-
</tr>
|
514 |
-
<tr>
|
515 |
-
<td><span class="new_code">setConnectionTimeout($timeout)</span></td>
|
516 |
-
<td>Termine la connexion après autant de temps entre les bytes</td>
|
517 |
-
</tr>
|
518 |
-
<tr>
|
519 |
-
<td><span class="new_code">useProxy($proxy, $name, $password)</span></td>
|
520 |
-
<td>Effectue les requêtes à travers ce proxy d'URL</td>
|
521 |
-
</tr>
|
522 |
-
</tbody></table>
|
523 |
-
</p>
|
524 |
-
|
525 |
-
</div>
|
526 |
-
References and related information...
|
527 |
-
<ul>
|
528 |
-
<li>
|
529 |
-
La page du projet SimpleTest sur
|
530 |
-
<a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>.
|
531 |
-
</li>
|
532 |
-
<li>
|
533 |
-
La page de téléchargement de SimpleTest sur
|
534 |
-
<a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>.
|
535 |
-
</li>
|
536 |
-
<li>
|
537 |
-
<a href="http://simpletest.org/api/">L'API du développeur pour SimpleTest</a>
|
538 |
-
donne tous les détails sur les classes et les assertions disponibles.
|
539 |
-
</li>
|
540 |
-
</ul>
|
541 |
-
<div class="menu_back"><div class="menu">
|
542 |
-
<a href="index.html">SimpleTest</a>
|
543 |
-
|
|
544 |
-
<a href="overview.html">Overview</a>
|
545 |
-
|
|
546 |
-
<a href="unit_test_documentation.html">Unit tester</a>
|
547 |
-
|
|
548 |
-
<a href="group_test_documentation.html">Group tests</a>
|
549 |
-
|
|
550 |
-
<a href="mock_objects_documentation.html">Mock objects</a>
|
551 |
-
|
|
552 |
-
<a href="partial_mocks_documentation.html">Partial mocks</a>
|
553 |
-
|
|
554 |
-
<a href="reporter_documentation.html">Reporting</a>
|
555 |
-
|
|
556 |
-
<a href="expectation_documentation.html">Expectations</a>
|
557 |
-
|
|
558 |
-
<a href="web_tester_documentation.html">Web tester</a>
|
559 |
-
|
|
560 |
-
<a href="form_testing_documentation.html">Testing forms</a>
|
561 |
-
|
|
562 |
-
<a href="authentication_documentation.html">Authentication</a>
|
563 |
-
|
|
564 |
-
<a href="browser_documentation.html">Scriptable browser</a>
|
565 |
-
</div></div>
|
566 |
-
<div class="copyright">
|
567 |
-
Copyright<br>Marcus Baker 2006
|
568 |
-
</div>
|
569 |
-
</body>
|
570 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/dumper.php
DELETED
@@ -1,407 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* base include file for SimpleTest
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage UnitTester
|
6 |
-
* @version $Id: dumper.php 1909 2009-07-29 15:58:11Z dgheath $
|
7 |
-
*/
|
8 |
-
/**
|
9 |
-
* does type matter
|
10 |
-
*/
|
11 |
-
if (! defined('TYPE_MATTERS')) {
|
12 |
-
define('TYPE_MATTERS', true);
|
13 |
-
}
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Displays variables as text and does diffs.
|
17 |
-
* @package SimpleTest
|
18 |
-
* @subpackage UnitTester
|
19 |
-
*/
|
20 |
-
class SimpleDumper {
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Renders a variable in a shorter form than print_r().
|
24 |
-
* @param mixed $value Variable to render as a string.
|
25 |
-
* @return string Human readable string form.
|
26 |
-
* @access public
|
27 |
-
*/
|
28 |
-
function describeValue($value) {
|
29 |
-
$type = $this->getType($value);
|
30 |
-
switch($type) {
|
31 |
-
case "Null":
|
32 |
-
return "NULL";
|
33 |
-
case "Boolean":
|
34 |
-
return "Boolean: " . ($value ? "true" : "false");
|
35 |
-
case "Array":
|
36 |
-
return "Array: " . count($value) . " items";
|
37 |
-
case "Object":
|
38 |
-
return "Object: of " . get_class($value);
|
39 |
-
case "String":
|
40 |
-
return "String: " . $this->clipString($value, 200);
|
41 |
-
default:
|
42 |
-
return "$type: $value";
|
43 |
-
}
|
44 |
-
return "Unknown";
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Gets the string representation of a type.
|
49 |
-
* @param mixed $value Variable to check against.
|
50 |
-
* @return string Type.
|
51 |
-
* @access public
|
52 |
-
*/
|
53 |
-
function getType($value) {
|
54 |
-
if (! isset($value)) {
|
55 |
-
return "Null";
|
56 |
-
} elseif (is_bool($value)) {
|
57 |
-
return "Boolean";
|
58 |
-
} elseif (is_string($value)) {
|
59 |
-
return "String";
|
60 |
-
} elseif (is_integer($value)) {
|
61 |
-
return "Integer";
|
62 |
-
} elseif (is_float($value)) {
|
63 |
-
return "Float";
|
64 |
-
} elseif (is_array($value)) {
|
65 |
-
return "Array";
|
66 |
-
} elseif (is_resource($value)) {
|
67 |
-
return "Resource";
|
68 |
-
} elseif (is_object($value)) {
|
69 |
-
return "Object";
|
70 |
-
}
|
71 |
-
return "Unknown";
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Creates a human readable description of the
|
76 |
-
* difference between two variables. Uses a
|
77 |
-
* dynamic call.
|
78 |
-
* @param mixed $first First variable.
|
79 |
-
* @param mixed $second Value to compare with.
|
80 |
-
* @param boolean $identical If true then type anomolies count.
|
81 |
-
* @return string Description of difference.
|
82 |
-
* @access public
|
83 |
-
*/
|
84 |
-
function describeDifference($first, $second, $identical = false) {
|
85 |
-
if ($identical) {
|
86 |
-
if (! $this->isTypeMatch($first, $second)) {
|
87 |
-
return "with type mismatch as [" . $this->describeValue($first) .
|
88 |
-
"] does not match [" . $this->describeValue($second) . "]";
|
89 |
-
}
|
90 |
-
}
|
91 |
-
$type = $this->getType($first);
|
92 |
-
if ($type == "Unknown") {
|
93 |
-
return "with unknown type";
|
94 |
-
}
|
95 |
-
$method = 'describe' . $type . 'Difference';
|
96 |
-
return $this->$method($first, $second, $identical);
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Tests to see if types match.
|
101 |
-
* @param mixed $first First variable.
|
102 |
-
* @param mixed $second Value to compare with.
|
103 |
-
* @return boolean True if matches.
|
104 |
-
* @access private
|
105 |
-
*/
|
106 |
-
protected function isTypeMatch($first, $second) {
|
107 |
-
return ($this->getType($first) == $this->getType($second));
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Clips a string to a maximum length.
|
112 |
-
* @param string $value String to truncate.
|
113 |
-
* @param integer $size Minimum string size to show.
|
114 |
-
* @param integer $position Centre of string section.
|
115 |
-
* @return string Shortened version.
|
116 |
-
* @access public
|
117 |
-
*/
|
118 |
-
function clipString($value, $size, $position = 0) {
|
119 |
-
$length = strlen($value);
|
120 |
-
if ($length <= $size) {
|
121 |
-
return $value;
|
122 |
-
}
|
123 |
-
$position = min($position, $length);
|
124 |
-
$start = ($size/2 > $position ? 0 : $position - $size/2);
|
125 |
-
if ($start + $size > $length) {
|
126 |
-
$start = $length - $size;
|
127 |
-
}
|
128 |
-
$value = substr($value, $start, $size);
|
129 |
-
return ($start > 0 ? "..." : "") . $value . ($start + $size < $length ? "..." : "");
|
130 |
-
}
|
131 |
-
|
132 |
-
/**
|
133 |
-
* Creates a human readable description of the
|
134 |
-
* difference between two variables. The minimal
|
135 |
-
* version.
|
136 |
-
* @param null $first First value.
|
137 |
-
* @param mixed $second Value to compare with.
|
138 |
-
* @return string Human readable description.
|
139 |
-
* @access private
|
140 |
-
*/
|
141 |
-
protected function describeGenericDifference($first, $second) {
|
142 |
-
return "as [" . $this->describeValue($first) .
|
143 |
-
"] does not match [" .
|
144 |
-
$this->describeValue($second) . "]";
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Creates a human readable description of the
|
149 |
-
* difference between a null and another variable.
|
150 |
-
* @param null $first First null.
|
151 |
-
* @param mixed $second Null to compare with.
|
152 |
-
* @param boolean $identical If true then type anomolies count.
|
153 |
-
* @return string Human readable description.
|
154 |
-
* @access private
|
155 |
-
*/
|
156 |
-
protected function describeNullDifference($first, $second, $identical) {
|
157 |
-
return $this->describeGenericDifference($first, $second);
|
158 |
-
}
|
159 |
-
|
160 |
-
/**
|
161 |
-
* Creates a human readable description of the
|
162 |
-
* difference between a boolean and another variable.
|
163 |
-
* @param boolean $first First boolean.
|
164 |
-
* @param mixed $second Boolean to compare with.
|
165 |
-
* @param boolean $identical If true then type anomolies count.
|
166 |
-
* @return string Human readable description.
|
167 |
-
* @access private
|
168 |
-
*/
|
169 |
-
protected function describeBooleanDifference($first, $second, $identical) {
|
170 |
-
return $this->describeGenericDifference($first, $second);
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Creates a human readable description of the
|
175 |
-
* difference between a string and another variable.
|
176 |
-
* @param string $first First string.
|
177 |
-
* @param mixed $second String to compare with.
|
178 |
-
* @param boolean $identical If true then type anomolies count.
|
179 |
-
* @return string Human readable description.
|
180 |
-
* @access private
|
181 |
-
*/
|
182 |
-
protected function describeStringDifference($first, $second, $identical) {
|
183 |
-
if (is_object($second) || is_array($second)) {
|
184 |
-
return $this->describeGenericDifference($first, $second);
|
185 |
-
}
|
186 |
-
$position = $this->stringDiffersAt($first, $second);
|
187 |
-
$message = "at character $position";
|
188 |
-
$message .= " with [" .
|
189 |
-
$this->clipString($first, 200, $position) . "] and [" .
|
190 |
-
$this->clipString($second, 200, $position) . "]";
|
191 |
-
return $message;
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Creates a human readable description of the
|
196 |
-
* difference between an integer and another variable.
|
197 |
-
* @param integer $first First number.
|
198 |
-
* @param mixed $second Number to compare with.
|
199 |
-
* @param boolean $identical If true then type anomolies count.
|
200 |
-
* @return string Human readable description.
|
201 |
-
* @access private
|
202 |
-
*/
|
203 |
-
protected function describeIntegerDifference($first, $second, $identical) {
|
204 |
-
if (is_object($second) || is_array($second)) {
|
205 |
-
return $this->describeGenericDifference($first, $second);
|
206 |
-
}
|
207 |
-
return "because [" . $this->describeValue($first) .
|
208 |
-
"] differs from [" .
|
209 |
-
$this->describeValue($second) . "] by " .
|
210 |
-
abs($first - $second);
|
211 |
-
}
|
212 |
-
|
213 |
-
/**
|
214 |
-
* Creates a human readable description of the
|
215 |
-
* difference between two floating point numbers.
|
216 |
-
* @param float $first First float.
|
217 |
-
* @param mixed $second Float to compare with.
|
218 |
-
* @param boolean $identical If true then type anomolies count.
|
219 |
-
* @return string Human readable description.
|
220 |
-
* @access private
|
221 |
-
*/
|
222 |
-
protected function describeFloatDifference($first, $second, $identical) {
|
223 |
-
if (is_object($second) || is_array($second)) {
|
224 |
-
return $this->describeGenericDifference($first, $second);
|
225 |
-
}
|
226 |
-
return "because [" . $this->describeValue($first) .
|
227 |
-
"] differs from [" .
|
228 |
-
$this->describeValue($second) . "] by " .
|
229 |
-
abs($first - $second);
|
230 |
-
}
|
231 |
-
|
232 |
-
/**
|
233 |
-
* Creates a human readable description of the
|
234 |
-
* difference between two arrays.
|
235 |
-
* @param array $first First array.
|
236 |
-
* @param mixed $second Array to compare with.
|
237 |
-
* @param boolean $identical If true then type anomolies count.
|
238 |
-
* @return string Human readable description.
|
239 |
-
* @access private
|
240 |
-
*/
|
241 |
-
protected function describeArrayDifference($first, $second, $identical) {
|
242 |
-
if (! is_array($second)) {
|
243 |
-
return $this->describeGenericDifference($first, $second);
|
244 |
-
}
|
245 |
-
if (! $this->isMatchingKeys($first, $second, $identical)) {
|
246 |
-
return "as key list [" .
|
247 |
-
implode(", ", array_keys($first)) . "] does not match key list [" .
|
248 |
-
implode(", ", array_keys($second)) . "]";
|
249 |
-
}
|
250 |
-
foreach (array_keys($first) as $key) {
|
251 |
-
if ($identical && ($first[$key] === $second[$key])) {
|
252 |
-
continue;
|
253 |
-
}
|
254 |
-
if (! $identical && ($first[$key] == $second[$key])) {
|
255 |
-
continue;
|
256 |
-
}
|
257 |
-
return "with member [$key] " . $this->describeDifference(
|
258 |
-
$first[$key],
|
259 |
-
$second[$key],
|
260 |
-
$identical);
|
261 |
-
}
|
262 |
-
return "";
|
263 |
-
}
|
264 |
-
|
265 |
-
/**
|
266 |
-
* Compares two arrays to see if their key lists match.
|
267 |
-
* For an identical match, the ordering and types of the keys
|
268 |
-
* is significant.
|
269 |
-
* @param array $first First array.
|
270 |
-
* @param array $second Array to compare with.
|
271 |
-
* @param boolean $identical If true then type anomolies count.
|
272 |
-
* @return boolean True if matching.
|
273 |
-
* @access private
|
274 |
-
*/
|
275 |
-
protected function isMatchingKeys($first, $second, $identical) {
|
276 |
-
$first_keys = array_keys($first);
|
277 |
-
$second_keys = array_keys($second);
|
278 |
-
if ($identical) {
|
279 |
-
return ($first_keys === $second_keys);
|
280 |
-
}
|
281 |
-
sort($first_keys);
|
282 |
-
sort($second_keys);
|
283 |
-
return ($first_keys == $second_keys);
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* Creates a human readable description of the
|
288 |
-
* difference between a resource and another variable.
|
289 |
-
* @param resource $first First resource.
|
290 |
-
* @param mixed $second Resource to compare with.
|
291 |
-
* @param boolean $identical If true then type anomolies count.
|
292 |
-
* @return string Human readable description.
|
293 |
-
* @access private
|
294 |
-
*/
|
295 |
-
protected function describeResourceDifference($first, $second, $identical) {
|
296 |
-
return $this->describeGenericDifference($first, $second);
|
297 |
-
}
|
298 |
-
|
299 |
-
/**
|
300 |
-
* Creates a human readable description of the
|
301 |
-
* difference between two objects.
|
302 |
-
* @param object $first First object.
|
303 |
-
* @param mixed $second Object to compare with.
|
304 |
-
* @param boolean $identical If true then type anomolies count.
|
305 |
-
* @return string Human readable description.
|
306 |
-
*/
|
307 |
-
protected function describeObjectDifference($first, $second, $identical) {
|
308 |
-
if (! is_object($second)) {
|
309 |
-
return $this->describeGenericDifference($first, $second);
|
310 |
-
}
|
311 |
-
return $this->describeArrayDifference(
|
312 |
-
$this->getMembers($first),
|
313 |
-
$this->getMembers($second),
|
314 |
-
$identical);
|
315 |
-
}
|
316 |
-
|
317 |
-
/**
|
318 |
-
* Get all members of an object including private and protected ones.
|
319 |
-
* A safer form of casting to an array.
|
320 |
-
* @param object $object Object to list members of,
|
321 |
-
* including private ones.
|
322 |
-
* @return array Names and values in the object.
|
323 |
-
*/
|
324 |
-
protected function getMembers($object) {
|
325 |
-
$reflection = new ReflectionObject($object);
|
326 |
-
$members = array();
|
327 |
-
foreach ($reflection->getProperties() as $property) {
|
328 |
-
if (method_exists($property, 'setAccessible')) {
|
329 |
-
$property->setAccessible(true);
|
330 |
-
}
|
331 |
-
try {
|
332 |
-
$members[$property->getName()] = $property->getValue($object);
|
333 |
-
} catch (ReflectionException $e) {
|
334 |
-
$members[$property->getName()] =
|
335 |
-
$this->getPrivatePropertyNoMatterWhat($property->getName(), $object);
|
336 |
-
}
|
337 |
-
}
|
338 |
-
return $members;
|
339 |
-
}
|
340 |
-
|
341 |
-
/**
|
342 |
-
* Extracts a private member's value when reflection won't play ball.
|
343 |
-
* @param string $name Property name.
|
344 |
-
* @param object $object Object to read.
|
345 |
-
* @return mixed Value of property.
|
346 |
-
*/
|
347 |
-
private function getPrivatePropertyNoMatterWhat($name, $object) {
|
348 |
-
foreach ((array)$object as $mangled_name => $value) {
|
349 |
-
if ($this->unmangle($mangled_name) == $name) {
|
350 |
-
return $value;
|
351 |
-
}
|
352 |
-
}
|
353 |
-
}
|
354 |
-
|
355 |
-
/**
|
356 |
-
* Removes crud from property name after it's been converted
|
357 |
-
* to an array.
|
358 |
-
* @param string $mangled Name from array cast.
|
359 |
-
* @return string Cleaned up name.
|
360 |
-
*/
|
361 |
-
function unmangle($mangled) {
|
362 |
-
$parts = preg_split('/[^a-zA-Z0-9_\x7f-\xff]+/', $mangled);
|
363 |
-
return array_pop($parts);
|
364 |
-
}
|
365 |
-
|
366 |
-
/**
|
367 |
-
* Find the first character position that differs
|
368 |
-
* in two strings by binary chop.
|
369 |
-
* @param string $first First string.
|
370 |
-
* @param string $second String to compare with.
|
371 |
-
* @return integer Position of first differing
|
372 |
-
* character.
|
373 |
-
* @access private
|
374 |
-
*/
|
375 |
-
protected function stringDiffersAt($first, $second) {
|
376 |
-
if (! $first || ! $second) {
|
377 |
-
return 0;
|
378 |
-
}
|
379 |
-
if (strlen($first) < strlen($second)) {
|
380 |
-
list($first, $second) = array($second, $first);
|
381 |
-
}
|
382 |
-
$position = 0;
|
383 |
-
$step = strlen($first);
|
384 |
-
while ($step > 1) {
|
385 |
-
$step = (integer)(($step + 1) / 2);
|
386 |
-
if (strncmp($first, $second, $position + $step) == 0) {
|
387 |
-
$position += $step;
|
388 |
-
}
|
389 |
-
}
|
390 |
-
return $position;
|
391 |
-
}
|
392 |
-
|
393 |
-
/**
|
394 |
-
* Sends a formatted dump of a variable to a string.
|
395 |
-
* @param mixed $variable Variable to display.
|
396 |
-
* @return string Output from print_r().
|
397 |
-
* @access public
|
398 |
-
*/
|
399 |
-
function dump($variable) {
|
400 |
-
ob_start();
|
401 |
-
print_r($variable);
|
402 |
-
$formatted = ob_get_contents();
|
403 |
-
ob_end_clean();
|
404 |
-
return $formatted;
|
405 |
-
}
|
406 |
-
}
|
407 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/eclipse.php
DELETED
@@ -1,307 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* base include file for eclipse plugin
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage Eclipse
|
6 |
-
* @version $Id: eclipse.php 2011 2011-04-29 08:22:48Z pp11 $
|
7 |
-
*/
|
8 |
-
/**#@+
|
9 |
-
* simpletest include files
|
10 |
-
*/
|
11 |
-
include_once 'unit_tester.php';
|
12 |
-
include_once 'test_case.php';
|
13 |
-
include_once 'invoker.php';
|
14 |
-
include_once 'socket.php';
|
15 |
-
include_once 'mock_objects.php';
|
16 |
-
/**#@-*/
|
17 |
-
|
18 |
-
/**
|
19 |
-
* base reported class for eclipse plugin
|
20 |
-
* @package SimpleTest
|
21 |
-
* @subpackage Eclipse
|
22 |
-
*/
|
23 |
-
class EclipseReporter extends SimpleScorer {
|
24 |
-
|
25 |
-
/**
|
26 |
-
* Reporter to be run inside of Eclipse interface.
|
27 |
-
* @param object $listener Eclipse listener (?).
|
28 |
-
* @param boolean $cc Whether to include test coverage.
|
29 |
-
*/
|
30 |
-
function __construct(&$listener, $cc=false){
|
31 |
-
$this->listener = &$listener;
|
32 |
-
$this->SimpleScorer();
|
33 |
-
$this->case = "";
|
34 |
-
$this->group = "";
|
35 |
-
$this->method = "";
|
36 |
-
$this->cc = $cc;
|
37 |
-
$this->error = false;
|
38 |
-
$this->fail = false;
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Means to display human readable object comparisons.
|
43 |
-
* @return SimpleDumper Visual comparer.
|
44 |
-
*/
|
45 |
-
function getDumper() {
|
46 |
-
return new SimpleDumper();
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Localhost connection from Eclipse.
|
51 |
-
* @param integer $port Port to connect to Eclipse.
|
52 |
-
* @param string $host Normally localhost.
|
53 |
-
* @return SimpleSocket Connection to Eclipse.
|
54 |
-
*/
|
55 |
-
function &createListener($port, $host="127.0.0.1"){
|
56 |
-
$tmplistener = &new SimpleSocket($host, $port, 5);
|
57 |
-
return $tmplistener;
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Wraps the test in an output buffer.
|
62 |
-
* @param SimpleInvoker $invoker Current test runner.
|
63 |
-
* @return EclipseInvoker Decorator with output buffering.
|
64 |
-
* @access public
|
65 |
-
*/
|
66 |
-
function &createInvoker(&$invoker){
|
67 |
-
$eclinvoker = &new EclipseInvoker($invoker, $this->listener);
|
68 |
-
return $eclinvoker;
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* C style escaping.
|
73 |
-
* @param string $raw String with backslashes, quotes and whitespace.
|
74 |
-
* @return string Replaced with C backslashed tokens.
|
75 |
-
*/
|
76 |
-
function escapeVal($raw){
|
77 |
-
$needle = array("\\","\"","/","\b","\f","\n","\r","\t");
|
78 |
-
$replace = array('\\\\','\"','\/','\b','\f','\n','\r','\t');
|
79 |
-
return str_replace($needle, $replace, $raw);
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Stash the first passing item. Clicking the test
|
84 |
-
* item goes to first pass.
|
85 |
-
* @param string $message Test message, but we only wnat the first.
|
86 |
-
* @access public
|
87 |
-
*/
|
88 |
-
function paintPass($message){
|
89 |
-
if (! $this->pass){
|
90 |
-
$this->message = $this->escapeVal($message);
|
91 |
-
}
|
92 |
-
$this->pass = true;
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Stash the first failing item. Clicking the test
|
97 |
-
* item goes to first fail.
|
98 |
-
* @param string $message Test message, but we only wnat the first.
|
99 |
-
* @access public
|
100 |
-
*/
|
101 |
-
function paintFail($message){
|
102 |
-
//only get the first failure or error
|
103 |
-
if (! $this->fail && ! $this->error){
|
104 |
-
$this->fail = true;
|
105 |
-
$this->message = $this->escapeVal($message);
|
106 |
-
$this->listener->write('{status:"fail",message:"'.$this->message.'",group:"'.$this->group.'",case:"'.$this->case.'",method:"'.$this->method.'"}');
|
107 |
-
}
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Stash the first error. Clicking the test
|
112 |
-
* item goes to first error.
|
113 |
-
* @param string $message Test message, but we only wnat the first.
|
114 |
-
* @access public
|
115 |
-
*/
|
116 |
-
function paintError($message){
|
117 |
-
if (! $this->fail && ! $this->error){
|
118 |
-
$this->error = true;
|
119 |
-
$this->message = $this->escapeVal($message);
|
120 |
-
$this->listener->write('{status:"error",message:"'.$this->message.'",group:"'.$this->group.'",case:"'.$this->case.'",method:"'.$this->method.'"}');
|
121 |
-
}
|
122 |
-
}
|
123 |
-
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Stash the first exception. Clicking the test
|
127 |
-
* item goes to first message.
|
128 |
-
* @param string $message Test message, but we only wnat the first.
|
129 |
-
* @access public
|
130 |
-
*/
|
131 |
-
function paintException($exception){
|
132 |
-
if (! $this->fail && ! $this->error){
|
133 |
-
$this->error = true;
|
134 |
-
$message = 'Unexpected exception of type[' . get_class($exception) .
|
135 |
-
'] with message [' . $exception->getMessage() . '] in [' .
|
136 |
-
$exception->getFile() .' line '. $exception->getLine() . ']';
|
137 |
-
$this->message = $this->escapeVal($message);
|
138 |
-
$this->listener->write(
|
139 |
-
'{status:"error",message:"' . $this->message . '",group:"' .
|
140 |
-
$this->group . '",case:"' . $this->case . '",method:"' . $this->method
|
141 |
-
. '"}');
|
142 |
-
}
|
143 |
-
}
|
144 |
-
|
145 |
-
|
146 |
-
/**
|
147 |
-
* We don't display any special header.
|
148 |
-
* @param string $test_name First test top level
|
149 |
-
* to start.
|
150 |
-
* @access public
|
151 |
-
*/
|
152 |
-
function paintHeader($test_name) {
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* We don't display any special footer.
|
157 |
-
* @param string $test_name The top level test.
|
158 |
-
* @access public
|
159 |
-
*/
|
160 |
-
function paintFooter($test_name) {
|
161 |
-
}
|
162 |
-
|
163 |
-
/**
|
164 |
-
* Paints nothing at the start of a test method, but stash
|
165 |
-
* the method name for later.
|
166 |
-
* @param string $test_name Name of test that is starting.
|
167 |
-
* @access public
|
168 |
-
*/
|
169 |
-
function paintMethodStart($method) {
|
170 |
-
$this->pass = false;
|
171 |
-
$this->fail = false;
|
172 |
-
$this->error = false;
|
173 |
-
$this->method = $this->escapeVal($method);
|
174 |
-
}
|
175 |
-
|
176 |
-
/**
|
177 |
-
* Only send one message if the test passes, after that
|
178 |
-
* suppress the message.
|
179 |
-
* @param string $test_name Name of test that is ending.
|
180 |
-
* @access public
|
181 |
-
*/
|
182 |
-
function paintMethodEnd($method){
|
183 |
-
if ($this->fail || $this->error || ! $this->pass){
|
184 |
-
} else {
|
185 |
-
$this->listener->write(
|
186 |
-
'{status:"pass",message:"' . $this->message . '",group:"' .
|
187 |
-
$this->group . '",case:"' . $this->case . '",method:"' .
|
188 |
-
$this->method . '"}');
|
189 |
-
}
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Stashes the test case name for the later failure message.
|
194 |
-
* @param string $test_name Name of test or other label.
|
195 |
-
* @access public
|
196 |
-
*/
|
197 |
-
function paintCaseStart($case){
|
198 |
-
$this->case = $this->escapeVal($case);
|
199 |
-
}
|
200 |
-
|
201 |
-
/**
|
202 |
-
* Drops the name.
|
203 |
-
* @param string $test_name Name of test or other label.
|
204 |
-
* @access public
|
205 |
-
*/
|
206 |
-
function paintCaseEnd($case){
|
207 |
-
$this->case = "";
|
208 |
-
}
|
209 |
-
|
210 |
-
/**
|
211 |
-
* Stashes the name of the test suite. Starts test coverage
|
212 |
-
* if enabled.
|
213 |
-
* @param string $group Name of test or other label.
|
214 |
-
* @param integer $size Number of test cases starting.
|
215 |
-
* @access public
|
216 |
-
*/
|
217 |
-
function paintGroupStart($group, $size){
|
218 |
-
$this->group = $this->escapeVal($group);
|
219 |
-
if ($this->cc){
|
220 |
-
if (extension_loaded('xdebug')){
|
221 |
-
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
|
222 |
-
}
|
223 |
-
}
|
224 |
-
}
|
225 |
-
|
226 |
-
/**
|
227 |
-
* Paints coverage report if enabled.
|
228 |
-
* @param string $group Name of test or other label.
|
229 |
-
* @access public
|
230 |
-
*/
|
231 |
-
function paintGroupEnd($group){
|
232 |
-
$this->group = "";
|
233 |
-
$cc = "";
|
234 |
-
if ($this->cc){
|
235 |
-
if (extension_loaded('xdebug')){
|
236 |
-
$arrfiles = xdebug_get_code_coverage();
|
237 |
-
xdebug_stop_code_coverage();
|
238 |
-
$thisdir = dirname(__FILE__);
|
239 |
-
$thisdirlen = strlen($thisdir);
|
240 |
-
foreach ($arrfiles as $index=>$file){
|
241 |
-
if (substr($index, 0, $thisdirlen)===$thisdir){
|
242 |
-
continue;
|
243 |
-
}
|
244 |
-
$lcnt = 0;
|
245 |
-
$ccnt = 0;
|
246 |
-
foreach ($file as $line){
|
247 |
-
if ($line == -2){
|
248 |
-
continue;
|
249 |
-
}
|
250 |
-
$lcnt++;
|
251 |
-
if ($line==1){
|
252 |
-
$ccnt++;
|
253 |
-
}
|
254 |
-
}
|
255 |
-
if ($lcnt > 0){
|
256 |
-
$cc .= round(($ccnt/$lcnt) * 100, 2) . '%';
|
257 |
-
}else{
|
258 |
-
$cc .= "0.00%";
|
259 |
-
}
|
260 |
-
$cc.= "\t". $index . "\n";
|
261 |
-
}
|
262 |
-
}
|
263 |
-
}
|
264 |
-
$this->listener->write('{status:"coverage",message:"' .
|
265 |
-
EclipseReporter::escapeVal($cc) . '"}');
|
266 |
-
}
|
267 |
-
}
|
268 |
-
|
269 |
-
/**
|
270 |
-
* Invoker decorator for Eclipse. Captures output until
|
271 |
-
* the end of the test.
|
272 |
-
* @package SimpleTest
|
273 |
-
* @subpackage Eclipse
|
274 |
-
*/
|
275 |
-
class EclipseInvoker extends SimpleInvokerDecorator{
|
276 |
-
function __construct(&$invoker, &$listener) {
|
277 |
-
$this->listener = &$listener;
|
278 |
-
$this->SimpleInvokerDecorator($invoker);
|
279 |
-
}
|
280 |
-
|
281 |
-
/**
|
282 |
-
* Starts output buffering.
|
283 |
-
* @param string $method Test method to call.
|
284 |
-
* @access public
|
285 |
-
*/
|
286 |
-
function before($method){
|
287 |
-
ob_start();
|
288 |
-
$this->invoker->before($method);
|
289 |
-
}
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Stops output buffering and send the captured output
|
293 |
-
* to the listener.
|
294 |
-
* @param string $method Test method to call.
|
295 |
-
* @access public
|
296 |
-
*/
|
297 |
-
function after($method) {
|
298 |
-
$this->invoker->after($method);
|
299 |
-
$output = ob_get_contents();
|
300 |
-
ob_end_clean();
|
301 |
-
if ($output !== ""){
|
302 |
-
$result = $this->listener->write('{status:"info",message:"' .
|
303 |
-
EclipseReporter::escapeVal($output) . '"}');
|
304 |
-
}
|
305 |
-
}
|
306 |
-
}
|
307 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/encoding.php
DELETED
@@ -1,649 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* base include file for SimpleTest
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage WebTester
|
6 |
-
* @version $Id: encoding.php 2011 2011-04-29 08:22:48Z pp11 $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**#@+
|
10 |
-
* include other SimpleTest class files
|
11 |
-
*/
|
12 |
-
require_once(dirname(__FILE__) . '/socket.php');
|
13 |
-
/**#@-*/
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Single post parameter.
|
17 |
-
* @package SimpleTest
|
18 |
-
* @subpackage WebTester
|
19 |
-
*/
|
20 |
-
class SimpleEncodedPair {
|
21 |
-
private $key;
|
22 |
-
private $value;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Stashes the data for rendering later.
|
26 |
-
* @param string $key Form element name.
|
27 |
-
* @param string $value Data to send.
|
28 |
-
*/
|
29 |
-
function __construct($key, $value) {
|
30 |
-
$this->key = $key;
|
31 |
-
$this->value = $value;
|
32 |
-
}
|
33 |
-
|
34 |
-
/**
|
35 |
-
* The pair as a single string.
|
36 |
-
* @return string Encoded pair.
|
37 |
-
* @access public
|
38 |
-
*/
|
39 |
-
function asRequest() {
|
40 |
-
return urlencode($this->key) . '=' . urlencode($this->value);
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* The MIME part as a string.
|
45 |
-
* @return string MIME part encoding.
|
46 |
-
* @access public
|
47 |
-
*/
|
48 |
-
function asMime() {
|
49 |
-
$part = 'Content-Disposition: form-data; ';
|
50 |
-
$part .= "name=\"" . $this->key . "\"\r\n";
|
51 |
-
$part .= "\r\n" . $this->value;
|
52 |
-
return $part;
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Is this the value we are looking for?
|
57 |
-
* @param string $key Identifier.
|
58 |
-
* @return boolean True if matched.
|
59 |
-
* @access public
|
60 |
-
*/
|
61 |
-
function isKey($key) {
|
62 |
-
return $key == $this->key;
|
63 |
-
}
|
64 |
-
|
65 |
-
/**
|
66 |
-
* Is this the value we are looking for?
|
67 |
-
* @return string Identifier.
|
68 |
-
* @access public
|
69 |
-
*/
|
70 |
-
function getKey() {
|
71 |
-
return $this->key;
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Is this the value we are looking for?
|
76 |
-
* @return string Content.
|
77 |
-
* @access public
|
78 |
-
*/
|
79 |
-
function getValue() {
|
80 |
-
return $this->value;
|
81 |
-
}
|
82 |
-
}
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Single post parameter.
|
86 |
-
* @package SimpleTest
|
87 |
-
* @subpackage WebTester
|
88 |
-
*/
|
89 |
-
class SimpleAttachment {
|
90 |
-
private $key;
|
91 |
-
private $content;
|
92 |
-
private $filename;
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Stashes the data for rendering later.
|
96 |
-
* @param string $key Key to add value to.
|
97 |
-
* @param string $content Raw data.
|
98 |
-
* @param hash $filename Original filename.
|
99 |
-
*/
|
100 |
-
function __construct($key, $content, $filename) {
|
101 |
-
$this->key = $key;
|
102 |
-
$this->content = $content;
|
103 |
-
$this->filename = $filename;
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* The pair as a single string.
|
108 |
-
* @return string Encoded pair.
|
109 |
-
* @access public
|
110 |
-
*/
|
111 |
-
function asRequest() {
|
112 |
-
return '';
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* The MIME part as a string.
|
117 |
-
* @return string MIME part encoding.
|
118 |
-
* @access public
|
119 |
-
*/
|
120 |
-
function asMime() {
|
121 |
-
$part = 'Content-Disposition: form-data; ';
|
122 |
-
$part .= 'name="' . $this->key . '"; ';
|
123 |
-
$part .= 'filename="' . $this->filename . '"';
|
124 |
-
$part .= "\r\nContent-Type: " . $this->deduceMimeType();
|
125 |
-
$part .= "\r\n\r\n" . $this->content;
|
126 |
-
return $part;
|
127 |
-
}
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Attempts to figure out the MIME type from the
|
131 |
-
* file extension and the content.
|
132 |
-
* @return string MIME type.
|
133 |
-
* @access private
|
134 |
-
*/
|
135 |
-
protected function deduceMimeType() {
|
136 |
-
if ($this->isOnlyAscii($this->content)) {
|
137 |
-
return 'text/plain';
|
138 |
-
}
|
139 |
-
return 'application/octet-stream';
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Tests each character is in the range 0-127.
|
144 |
-
* @param string $ascii String to test.
|
145 |
-
* @access private
|
146 |
-
*/
|
147 |
-
protected function isOnlyAscii($ascii) {
|
148 |
-
for ($i = 0, $length = strlen($ascii); $i < $length; $i++) {
|
149 |
-
if (ord($ascii[$i]) > 127) {
|
150 |
-
return false;
|
151 |
-
}
|
152 |
-
}
|
153 |
-
return true;
|
154 |
-
}
|
155 |
-
|
156 |
-
/**
|
157 |
-
* Is this the value we are looking for?
|
158 |
-
* @param string $key Identifier.
|
159 |
-
* @return boolean True if matched.
|
160 |
-
* @access public
|
161 |
-
*/
|
162 |
-
function isKey($key) {
|
163 |
-
return $key == $this->key;
|
164 |
-
}
|
165 |
-
|
166 |
-
/**
|
167 |
-
* Is this the value we are looking for?
|
168 |
-
* @return string Identifier.
|
169 |
-
* @access public
|
170 |
-
*/
|
171 |
-
function getKey() {
|
172 |
-
return $this->key;
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Is this the value we are looking for?
|
177 |
-
* @return string Content.
|
178 |
-
* @access public
|
179 |
-
*/
|
180 |
-
function getValue() {
|
181 |
-
return $this->filename;
|
182 |
-
}
|
183 |
-
}
|
184 |
-
|
185 |
-
/**
|
186 |
-
* Bundle of GET/POST parameters. Can include
|
187 |
-
* repeated parameters.
|
188 |
-
* @package SimpleTest
|
189 |
-
* @subpackage WebTester
|
190 |
-
*/
|
191 |
-
class SimpleEncoding {
|
192 |
-
private $request;
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Starts empty.
|
196 |
-
* @param array $query Hash of parameters.
|
197 |
-
* Multiple values are
|
198 |
-
* as lists on a single key.
|
199 |
-
* @access public
|
200 |
-
*/
|
201 |
-
function __construct($query = false) {
|
202 |
-
if (! $query) {
|
203 |
-
$query = array();
|
204 |
-
}
|
205 |
-
$this->clear();
|
206 |
-
$this->merge($query);
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Empties the request of parameters.
|
211 |
-
* @access public
|
212 |
-
*/
|
213 |
-
function clear() {
|
214 |
-
$this->request = array();
|
215 |
-
}
|
216 |
-
|
217 |
-
/**
|
218 |
-
* Adds a parameter to the query.
|
219 |
-
* @param string $key Key to add value to.
|
220 |
-
* @param string/array $value New data.
|
221 |
-
* @access public
|
222 |
-
*/
|
223 |
-
function add($key, $value) {
|
224 |
-
if ($value === false) {
|
225 |
-
return;
|
226 |
-
}
|
227 |
-
if (is_array($value)) {
|
228 |
-
foreach ($value as $item) {
|
229 |
-
$this->addPair($key, $item);
|
230 |
-
}
|
231 |
-
} else {
|
232 |
-
$this->addPair($key, $value);
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
/**
|
237 |
-
* Adds a new value into the request.
|
238 |
-
* @param string $key Key to add value to.
|
239 |
-
* @param string/array $value New data.
|
240 |
-
* @access private
|
241 |
-
*/
|
242 |
-
protected function addPair($key, $value) {
|
243 |
-
$this->request[] = new SimpleEncodedPair($key, $value);
|
244 |
-
}
|
245 |
-
|
246 |
-
/**
|
247 |
-
* Adds a MIME part to the query. Does nothing for a
|
248 |
-
* form encoded packet.
|
249 |
-
* @param string $key Key to add value to.
|
250 |
-
* @param string $content Raw data.
|
251 |
-
* @param hash $filename Original filename.
|
252 |
-
* @access public
|
253 |
-
*/
|
254 |
-
function attach($key, $content, $filename) {
|
255 |
-
$this->request[] = new SimpleAttachment($key, $content, $filename);
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* Adds a set of parameters to this query.
|
260 |
-
* @param array/SimpleQueryString $query Multiple values are
|
261 |
-
* as lists on a single key.
|
262 |
-
* @access public
|
263 |
-
*/
|
264 |
-
function merge($query) {
|
265 |
-
if (is_object($query)) {
|
266 |
-
$this->request = array_merge($this->request, $query->getAll());
|
267 |
-
} elseif (is_array($query)) {
|
268 |
-
foreach ($query as $key => $value) {
|
269 |
-
$this->add($key, $value);
|
270 |
-
}
|
271 |
-
}
|
272 |
-
}
|
273 |
-
|
274 |
-
/**
|
275 |
-
* Accessor for single value.
|
276 |
-
* @return string/array False if missing, string
|
277 |
-
* if present and array if
|
278 |
-
* multiple entries.
|
279 |
-
* @access public
|
280 |
-
*/
|
281 |
-
function getValue($key) {
|
282 |
-
$values = array();
|
283 |
-
foreach ($this->request as $pair) {
|
284 |
-
if ($pair->isKey($key)) {
|
285 |
-
$values[] = $pair->getValue();
|
286 |
-
}
|
287 |
-
}
|
288 |
-
if (count($values) == 0) {
|
289 |
-
return false;
|
290 |
-
} elseif (count($values) == 1) {
|
291 |
-
return $values[0];
|
292 |
-
} else {
|
293 |
-
return $values;
|
294 |
-
}
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* Accessor for listing of pairs.
|
299 |
-
* @return array All pair objects.
|
300 |
-
* @access public
|
301 |
-
*/
|
302 |
-
function getAll() {
|
303 |
-
return $this->request;
|
304 |
-
}
|
305 |
-
|
306 |
-
/**
|
307 |
-
* Renders the query string as a URL encoded
|
308 |
-
* request part.
|
309 |
-
* @return string Part of URL.
|
310 |
-
* @access protected
|
311 |
-
*/
|
312 |
-
protected function encode() {
|
313 |
-
$statements = array();
|
314 |
-
foreach ($this->request as $pair) {
|
315 |
-
if ($statement = $pair->asRequest()) {
|
316 |
-
$statements[] = $statement;
|
317 |
-
}
|
318 |
-
}
|
319 |
-
return implode('&', $statements);
|
320 |
-
}
|
321 |
-
}
|
322 |
-
|
323 |
-
/**
|
324 |
-
* Bundle of GET parameters. Can include
|
325 |
-
* repeated parameters.
|
326 |
-
* @package SimpleTest
|
327 |
-
* @subpackage WebTester
|
328 |
-
*/
|
329 |
-
class SimpleGetEncoding extends SimpleEncoding {
|
330 |
-
|
331 |
-
/**
|
332 |
-
* Starts empty.
|
333 |
-
* @param array $query Hash of parameters.
|
334 |
-
* Multiple values are
|
335 |
-
* as lists on a single key.
|
336 |
-
* @access public
|
337 |
-
*/
|
338 |
-
function __construct($query = false) {
|
339 |
-
parent::__construct($query);
|
340 |
-
}
|
341 |
-
|
342 |
-
/**
|
343 |
-
* HTTP request method.
|
344 |
-
* @return string Always GET.
|
345 |
-
* @access public
|
346 |
-
*/
|
347 |
-
function getMethod() {
|
348 |
-
return 'GET';
|
349 |
-
}
|
350 |
-
|
351 |
-
/**
|
352 |
-
* Writes no extra headers.
|
353 |
-
* @param SimpleSocket $socket Socket to write to.
|
354 |
-
* @access public
|
355 |
-
*/
|
356 |
-
function writeHeadersTo(&$socket) {
|
357 |
-
}
|
358 |
-
|
359 |
-
/**
|
360 |
-
* No data is sent to the socket as the data is encoded into
|
361 |
-
* the URL.
|
362 |
-
* @param SimpleSocket $socket Socket to write to.
|
363 |
-
* @access public
|
364 |
-
*/
|
365 |
-
function writeTo(&$socket) {
|
366 |
-
}
|
367 |
-
|
368 |
-
/**
|
369 |
-
* Renders the query string as a URL encoded
|
370 |
-
* request part for attaching to a URL.
|
371 |
-
* @return string Part of URL.
|
372 |
-
* @access public
|
373 |
-
*/
|
374 |
-
function asUrlRequest() {
|
375 |
-
return $this->encode();
|
376 |
-
}
|
377 |
-
}
|
378 |
-
|
379 |
-
/**
|
380 |
-
* Bundle of URL parameters for a HEAD request.
|
381 |
-
* @package SimpleTest
|
382 |
-
* @subpackage WebTester
|
383 |
-
*/
|
384 |
-
class SimpleHeadEncoding extends SimpleGetEncoding {
|
385 |
-
|
386 |
-
/**
|
387 |
-
* Starts empty.
|
388 |
-
* @param array $query Hash of parameters.
|
389 |
-
* Multiple values are
|
390 |
-
* as lists on a single key.
|
391 |
-
* @access public
|
392 |
-
*/
|
393 |
-
function __construct($query = false) {
|
394 |
-
parent::__construct($query);
|
395 |
-
}
|
396 |
-
|
397 |
-
/**
|
398 |
-
* HTTP request method.
|
399 |
-
* @return string Always HEAD.
|
400 |
-
* @access public
|
401 |
-
*/
|
402 |
-
function getMethod() {
|
403 |
-
return 'HEAD';
|
404 |
-
}
|
405 |
-
}
|
406 |
-
|
407 |
-
/**
|
408 |
-
* Bundle of URL parameters for a DELETE request.
|
409 |
-
* @package SimpleTest
|
410 |
-
* @subpackage WebTester
|
411 |
-
*/
|
412 |
-
class SimpleDeleteEncoding extends SimpleGetEncoding {
|
413 |
-
|
414 |
-
/**
|
415 |
-
* Starts empty.
|
416 |
-
* @param array $query Hash of parameters.
|
417 |
-
* Multiple values are
|
418 |
-
* as lists on a single key.
|
419 |
-
* @access public
|
420 |
-
*/
|
421 |
-
function __construct($query = false) {
|
422 |
-
parent::__construct($query);
|
423 |
-
}
|
424 |
-
|
425 |
-
/**
|
426 |
-
* HTTP request method.
|
427 |
-
* @return string Always DELETE.
|
428 |
-
* @access public
|
429 |
-
*/
|
430 |
-
function getMethod() {
|
431 |
-
return 'DELETE';
|
432 |
-
}
|
433 |
-
}
|
434 |
-
|
435 |
-
/**
|
436 |
-
* Bundles an entity-body for transporting
|
437 |
-
* a raw content payload with the request.
|
438 |
-
* @package SimpleTest
|
439 |
-
* @subpackage WebTester
|
440 |
-
*/
|
441 |
-
class SimpleEntityEncoding extends SimpleEncoding {
|
442 |
-
private $content_type;
|
443 |
-
private $body;
|
444 |
-
|
445 |
-
function __construct($query = false, $content_type = false) {
|
446 |
-
$this->content_type = $content_type;
|
447 |
-
if (is_string($query)) {
|
448 |
-
$this->body = $query;
|
449 |
-
parent::__construct();
|
450 |
-
} else {
|
451 |
-
parent::__construct($query);
|
452 |
-
}
|
453 |
-
}
|
454 |
-
|
455 |
-
/**
|
456 |
-
* Returns the media type of the entity body
|
457 |
-
* @return string
|
458 |
-
* @access public
|
459 |
-
*/
|
460 |
-
function getContentType() {
|
461 |
-
if (!$this->content_type) {
|
462 |
-
return ($this->body) ? 'text/plain' : 'application/x-www-form-urlencoded';
|
463 |
-
}
|
464 |
-
return $this->content_type;
|
465 |
-
}
|
466 |
-
|
467 |
-
/**
|
468 |
-
* Dispatches the form headers down the socket.
|
469 |
-
* @param SimpleSocket $socket Socket to write to.
|
470 |
-
* @access public
|
471 |
-
*/
|
472 |
-
function writeHeadersTo(&$socket) {
|
473 |
-
$socket->write("Content-Length: " . (integer)strlen($this->encode()) . "\r\n");
|
474 |
-
$socket->write("Content-Type: " . $this->getContentType() . "\r\n");
|
475 |
-
}
|
476 |
-
|
477 |
-
/**
|
478 |
-
* Dispatches the form data down the socket.
|
479 |
-
* @param SimpleSocket $socket Socket to write to.
|
480 |
-
* @access public
|
481 |
-
*/
|
482 |
-
function writeTo(&$socket) {
|
483 |
-
$socket->write($this->encode());
|
484 |
-
}
|
485 |
-
|
486 |
-
/**
|
487 |
-
* Renders the request body
|
488 |
-
* @return Encoded entity body
|
489 |
-
* @access protected
|
490 |
-
*/
|
491 |
-
protected function encode() {
|
492 |
-
return ($this->body) ? $this->body : parent::encode();
|
493 |
-
}
|
494 |
-
}
|
495 |
-
|
496 |
-
/**
|
497 |
-
* Bundle of POST parameters. Can include
|
498 |
-
* repeated parameters.
|
499 |
-
* @package SimpleTest
|
500 |
-
* @subpackage WebTester
|
501 |
-
*/
|
502 |
-
class SimplePostEncoding extends SimpleEntityEncoding {
|
503 |
-
|
504 |
-
/**
|
505 |
-
* Starts empty.
|
506 |
-
* @param array $query Hash of parameters.
|
507 |
-
* Multiple values are
|
508 |
-
* as lists on a single key.
|
509 |
-
* @access public
|
510 |
-
*/
|
511 |
-
function __construct($query = false, $content_type = false) {
|
512 |
-
if (is_array($query) and $this->hasMoreThanOneLevel($query)) {
|
513 |
-
$query = $this->rewriteArrayWithMultipleLevels($query);
|
514 |
-
}
|
515 |
-
parent::__construct($query, $content_type);
|
516 |
-
}
|
517 |
-
|
518 |
-
function hasMoreThanOneLevel($query) {
|
519 |
-
foreach ($query as $key => $value) {
|
520 |
-
if (is_array($value)) {
|
521 |
-
return true;
|
522 |
-
}
|
523 |
-
}
|
524 |
-
return false;
|
525 |
-
}
|
526 |
-
|
527 |
-
function rewriteArrayWithMultipleLevels($query) {
|
528 |
-
$query_ = array();
|
529 |
-
foreach ($query as $key => $value) {
|
530 |
-
if (is_array($value)) {
|
531 |
-
foreach ($value as $sub_key => $sub_value) {
|
532 |
-
$query_[$key."[".$sub_key."]"] = $sub_value;
|
533 |
-
}
|
534 |
-
} else {
|
535 |
-
$query_[$key] = $value;
|
536 |
-
}
|
537 |
-
}
|
538 |
-
if ($this->hasMoreThanOneLevel($query_)) {
|
539 |
-
$query_ = $this->rewriteArrayWithMultipleLevels($query_);
|
540 |
-
}
|
541 |
-
|
542 |
-
return $query_;
|
543 |
-
}
|
544 |
-
|
545 |
-
/**
|
546 |
-
* HTTP request method.
|
547 |
-
* @return string Always POST.
|
548 |
-
* @access public
|
549 |
-
*/
|
550 |
-
function getMethod() {
|
551 |
-
return 'POST';
|
552 |
-
}
|
553 |
-
|
554 |
-
/**
|
555 |
-
* Renders the query string as a URL encoded
|
556 |
-
* request part for attaching to a URL.
|
557 |
-
* @return string Part of URL.
|
558 |
-
* @access public
|
559 |
-
*/
|
560 |
-
function asUrlRequest() {
|
561 |
-
return '';
|
562 |
-
}
|
563 |
-
}
|
564 |
-
|
565 |
-
/**
|
566 |
-
* Encoded entity body for a PUT request.
|
567 |
-
* @package SimpleTest
|
568 |
-
* @subpackage WebTester
|
569 |
-
*/
|
570 |
-
class SimplePutEncoding extends SimpleEntityEncoding {
|
571 |
-
|
572 |
-
/**
|
573 |
-
* Starts empty.
|
574 |
-
* @param array $query Hash of parameters.
|
575 |
-
* Multiple values are
|
576 |
-
* as lists on a single key.
|
577 |
-
* @access public
|
578 |
-
*/
|
579 |
-
function __construct($query = false, $content_type = false) {
|
580 |
-
parent::__construct($query, $content_type);
|
581 |
-
}
|
582 |
-
|
583 |
-
/**
|
584 |
-
* HTTP request method.
|
585 |
-
* @return string Always PUT.
|
586 |
-
* @access public
|
587 |
-
*/
|
588 |
-
function getMethod() {
|
589 |
-
return 'PUT';
|
590 |
-
}
|
591 |
-
}
|
592 |
-
|
593 |
-
/**
|
594 |
-
* Bundle of POST parameters in the multipart
|
595 |
-
* format. Can include file uploads.
|
596 |
-
* @package SimpleTest
|
597 |
-
* @subpackage WebTester
|
598 |
-
*/
|
599 |
-
class SimpleMultipartEncoding extends SimplePostEncoding {
|
600 |
-
private $boundary;
|
601 |
-
|
602 |
-
/**
|
603 |
-
* Starts empty.
|
604 |
-
* @param array $query Hash of parameters.
|
605 |
-
* Multiple values are
|
606 |
-
* as lists on a single key.
|
607 |
-
* @access public
|
608 |
-
*/
|
609 |
-
function __construct($query = false, $boundary = false) {
|
610 |
-
parent::__construct($query);
|
611 |
-
$this->boundary = ($boundary === false ? uniqid('st') : $boundary);
|
612 |
-
}
|
613 |
-
|
614 |
-
/**
|
615 |
-
* Dispatches the form headers down the socket.
|
616 |
-
* @param SimpleSocket $socket Socket to write to.
|
617 |
-
* @access public
|
618 |
-
*/
|
619 |
-
function writeHeadersTo(&$socket) {
|
620 |
-
$socket->write("Content-Length: " . (integer)strlen($this->encode()) . "\r\n");
|
621 |
-
$socket->write("Content-Type: multipart/form-data; boundary=" . $this->boundary . "\r\n");
|
622 |
-
}
|
623 |
-
|
624 |
-
/**
|
625 |
-
* Dispatches the form data down the socket.
|
626 |
-
* @param SimpleSocket $socket Socket to write to.
|
627 |
-
* @access public
|
628 |
-
*/
|
629 |
-
function writeTo(&$socket) {
|
630 |
-
$socket->write($this->encode());
|
631 |
-
}
|
632 |
-
|
633 |
-
/**
|
634 |
-
* Renders the query string as a URL encoded
|
635 |
-
* request part.
|
636 |
-
* @return string Part of URL.
|
637 |
-
* @access public
|
638 |
-
*/
|
639 |
-
function encode() {
|
640 |
-
$stream = '';
|
641 |
-
foreach ($this->getAll() as $pair) {
|
642 |
-
$stream .= "--" . $this->boundary . "\r\n";
|
643 |
-
$stream .= $pair->asMime() . "\r\n";
|
644 |
-
}
|
645 |
-
$stream .= "--" . $this->boundary . "--\r\n";
|
646 |
-
return $stream;
|
647 |
-
}
|
648 |
-
}
|
649 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/errors.php
DELETED
@@ -1,267 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* base include file for SimpleTest
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage UnitTester
|
6 |
-
* @version $Id: errors.php 2011 2011-04-29 08:22:48Z pp11 $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**#@+
|
10 |
-
* Includes SimpleTest files.
|
11 |
-
*/
|
12 |
-
require_once dirname(__FILE__) . '/invoker.php';
|
13 |
-
require_once dirname(__FILE__) . '/test_case.php';
|
14 |
-
require_once dirname(__FILE__) . '/expectation.php';
|
15 |
-
/**#@-*/
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Extension that traps errors into an error queue.
|
19 |
-
* @package SimpleTest
|
20 |
-
* @subpackage UnitTester
|
21 |
-
*/
|
22 |
-
class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator {
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Stores the invoker to wrap.
|
26 |
-
* @param SimpleInvoker $invoker Test method runner.
|
27 |
-
*/
|
28 |
-
function __construct($invoker) {
|
29 |
-
parent::__construct($invoker);
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Invokes a test method and dispatches any
|
34 |
-
* untrapped errors. Called back from
|
35 |
-
* the visiting runner.
|
36 |
-
* @param string $method Test method to call.
|
37 |
-
* @access public
|
38 |
-
*/
|
39 |
-
function invoke($method) {
|
40 |
-
$queue = $this->createErrorQueue();
|
41 |
-
set_error_handler('SimpleTestErrorHandler');
|
42 |
-
parent::invoke($method);
|
43 |
-
restore_error_handler();
|
44 |
-
$queue->tally();
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Wires up the error queue for a single test.
|
49 |
-
* @return SimpleErrorQueue Queue connected to the test.
|
50 |
-
* @access private
|
51 |
-
*/
|
52 |
-
protected function createErrorQueue() {
|
53 |
-
$context = SimpleTest::getContext();
|
54 |
-
$test = $this->getTestCase();
|
55 |
-
$queue = $context->get('SimpleErrorQueue');
|
56 |
-
$queue->setTestCase($test);
|
57 |
-
return $queue;
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Error queue used to record trapped
|
63 |
-
* errors.
|
64 |
-
* @package SimpleTest
|
65 |
-
* @subpackage UnitTester
|
66 |
-
*/
|
67 |
-
class SimpleErrorQueue {
|
68 |
-
private $queue;
|
69 |
-
private $expectation_queue;
|
70 |
-
private $test;
|
71 |
-
private $using_expect_style = false;
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Starts with an empty queue.
|
75 |
-
*/
|
76 |
-
function __construct() {
|
77 |
-
$this->clear();
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Discards the contents of the error queue.
|
82 |
-
* @access public
|
83 |
-
*/
|
84 |
-
function clear() {
|
85 |
-
$this->queue = array();
|
86 |
-
$this->expectation_queue = array();
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Sets the currently running test case.
|
91 |
-
* @param SimpleTestCase $test Test case to send messages to.
|
92 |
-
* @access public
|
93 |
-
*/
|
94 |
-
function setTestCase($test) {
|
95 |
-
$this->test = $test;
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Sets up an expectation of an error. If this is
|
100 |
-
* not fulfilled at the end of the test, a failure
|
101 |
-
* will occour. If the error does happen, then this
|
102 |
-
* will cancel it out and send a pass message.
|
103 |
-
* @param SimpleExpectation $expected Expected error match.
|
104 |
-
* @param string $message Message to display.
|
105 |
-
* @access public
|
106 |
-
*/
|
107 |
-
function expectError($expected, $message) {
|
108 |
-
array_push($this->expectation_queue, array($expected, $message));
|
109 |
-
}
|
110 |
-
|
111 |
-
/**
|
112 |
-
* Adds an error to the front of the queue.
|
113 |
-
* @param integer $severity PHP error code.
|
114 |
-
* @param string $content Text of error.
|
115 |
-
* @param string $filename File error occoured in.
|
116 |
-
* @param integer $line Line number of error.
|
117 |
-
* @access public
|
118 |
-
*/
|
119 |
-
function add($severity, $content, $filename, $line) {
|
120 |
-
$content = str_replace('%', '%%', $content);
|
121 |
-
$this->testLatestError($severity, $content, $filename, $line);
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Any errors still in the queue are sent to the test
|
126 |
-
* case. Any unfulfilled expectations trigger failures.
|
127 |
-
* @access public
|
128 |
-
*/
|
129 |
-
function tally() {
|
130 |
-
while (list($severity, $message, $file, $line) = $this->extract()) {
|
131 |
-
$severity = $this->getSeverityAsString($severity);
|
132 |
-
$this->test->error($severity, $message, $file, $line);
|
133 |
-
}
|
134 |
-
while (list($expected, $message) = $this->extractExpectation()) {
|
135 |
-
$this->test->assert($expected, false, "%s -> Expected error not caught");
|
136 |
-
}
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Tests the error against the most recent expected
|
141 |
-
* error.
|
142 |
-
* @param integer $severity PHP error code.
|
143 |
-
* @param string $content Text of error.
|
144 |
-
* @param string $filename File error occoured in.
|
145 |
-
* @param integer $line Line number of error.
|
146 |
-
* @access private
|
147 |
-
*/
|
148 |
-
protected function testLatestError($severity, $content, $filename, $line) {
|
149 |
-
if ($expectation = $this->extractExpectation()) {
|
150 |
-
list($expected, $message) = $expectation;
|
151 |
-
$this->test->assert($expected, $content, sprintf(
|
152 |
-
$message,
|
153 |
-
"%s -> PHP error [$content] severity [" .
|
154 |
-
$this->getSeverityAsString($severity) .
|
155 |
-
"] in [$filename] line [$line]"));
|
156 |
-
} else {
|
157 |
-
$this->test->error($severity, $content, $filename, $line);
|
158 |
-
}
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* Pulls the earliest error from the queue.
|
163 |
-
* @return mixed False if none, or a list of error
|
164 |
-
* information. Elements are: severity
|
165 |
-
* as the PHP error code, the error message,
|
166 |
-
* the file with the error, the line number
|
167 |
-
* and a list of PHP super global arrays.
|
168 |
-
* @access public
|
169 |
-
*/
|
170 |
-
function extract() {
|
171 |
-
if (count($this->queue)) {
|
172 |
-
return array_shift($this->queue);
|
173 |
-
}
|
174 |
-
return false;
|
175 |
-
}
|
176 |
-
|
177 |
-
/**
|
178 |
-
* Pulls the earliest expectation from the queue.
|
179 |
-
* @return SimpleExpectation False if none.
|
180 |
-
* @access private
|
181 |
-
*/
|
182 |
-
protected function extractExpectation() {
|
183 |
-
if (count($this->expectation_queue)) {
|
184 |
-
return array_shift($this->expectation_queue);
|
185 |
-
}
|
186 |
-
return false;
|
187 |
-
}
|
188 |
-
|
189 |
-
/**
|
190 |
-
* Converts an error code into it's string
|
191 |
-
* representation.
|
192 |
-
* @param $severity PHP integer error code.
|
193 |
-
* @return String version of error code.
|
194 |
-
* @access public
|
195 |
-
*/
|
196 |
-
static function getSeverityAsString($severity) {
|
197 |
-
static $map = array(
|
198 |
-
E_STRICT => 'E_STRICT',
|
199 |
-
E_ERROR => 'E_ERROR',
|
200 |
-
E_WARNING => 'E_WARNING',
|
201 |
-
E_PARSE => 'E_PARSE',
|
202 |
-
E_NOTICE => 'E_NOTICE',
|
203 |
-
E_CORE_ERROR => 'E_CORE_ERROR',
|
204 |
-
E_CORE_WARNING => 'E_CORE_WARNING',
|
205 |
-
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
|
206 |
-
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
|
207 |
-
E_USER_ERROR => 'E_USER_ERROR',
|
208 |
-
E_USER_WARNING => 'E_USER_WARNING',
|
209 |
-
E_USER_NOTICE => 'E_USER_NOTICE');
|
210 |
-
if (defined('E_RECOVERABLE_ERROR')) {
|
211 |
-
$map[E_RECOVERABLE_ERROR] = 'E_RECOVERABLE_ERROR';
|
212 |
-
}
|
213 |
-
if (defined('E_DEPRECATED')) {
|
214 |
-
$map[E_DEPRECATED] = 'E_DEPRECATED';
|
215 |
-
}
|
216 |
-
return $map[$severity];
|
217 |
-
}
|
218 |
-
}
|
219 |
-
|
220 |
-
/**
|
221 |
-
* Error handler that simply stashes any errors into the global
|
222 |
-
* error queue. Simulates the existing behaviour with respect to
|
223 |
-
* logging errors, but this feature may be removed in future.
|
224 |
-
* @param $severity PHP error code.
|
225 |
-
* @param $message Text of error.
|
226 |
-
* @param $filename File error occoured in.
|
227 |
-
* @param $line Line number of error.
|
228 |
-
* @param $super_globals Hash of PHP super global arrays.
|
229 |
-
* @access public
|
230 |
-
*/
|
231 |
-
function SimpleTestErrorHandler($severity, $message, $filename = null, $line = null, $super_globals = null, $mask = null) {
|
232 |
-
$severity = $severity & error_reporting();
|
233 |
-
if ($severity) {
|
234 |
-
restore_error_handler();
|
235 |
-
if (IsNotCausedBySimpleTest($message) && IsNotTimeZoneNag($message)) {
|
236 |
-
if (ini_get('log_errors')) {
|
237 |
-
$label = SimpleErrorQueue::getSeverityAsString($severity);
|
238 |
-
error_log("$label: $message in $filename on line $line");
|
239 |
-
}
|
240 |
-
$queue = SimpleTest::getContext()->get('SimpleErrorQueue');
|
241 |
-
$queue->add($severity, $message, $filename, $line);
|
242 |
-
}
|
243 |
-
set_error_handler('SimpleTestErrorHandler');
|
244 |
-
}
|
245 |
-
return true;
|
246 |
-
}
|
247 |
-
|
248 |
-
/**
|
249 |
-
* Certain messages can be caused by the unit tester itself.
|
250 |
-
* These have to be filtered.
|
251 |
-
* @param string $message Message to filter.
|
252 |
-
* @return boolean True if genuine failure.
|
253 |
-
*/
|
254 |
-
function IsNotCausedBySimpleTest($message) {
|
255 |
-
return ! preg_match('/returned by reference/', $message);
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* Certain messages caused by PHP are just noise.
|
260 |
-
* These have to be filtered.
|
261 |
-
* @param string $message Message to filter.
|
262 |
-
* @return boolean True if genuine failure.
|
263 |
-
*/
|
264 |
-
function IsNotTimeZoneNag($message) {
|
265 |
-
return ! preg_match('/not safe to rely .* timezone settings/', $message);
|
266 |
-
}
|
267 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/exceptions.php
DELETED
@@ -1,226 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* base include file for SimpleTest
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage UnitTester
|
6 |
-
* @version $Id: exceptions.php 1882 2009-07-01 14:30:05Z lastcraft $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**#@+
|
10 |
-
* Include required SimpleTest files
|
11 |
-
*/
|
12 |
-
require_once dirname(__FILE__) . '/invoker.php';
|
13 |
-
require_once dirname(__FILE__) . '/expectation.php';
|
14 |
-
/**#@-*/
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Extension that traps exceptions and turns them into
|
18 |
-
* an error message. PHP5 only.
|
19 |
-
* @package SimpleTest
|
20 |
-
* @subpackage UnitTester
|
21 |
-
*/
|
22 |
-
class SimpleExceptionTrappingInvoker extends SimpleInvokerDecorator {
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Stores the invoker to be wrapped.
|
26 |
-
* @param SimpleInvoker $invoker Test method runner.
|
27 |
-
*/
|
28 |
-
function __construct($invoker) {
|
29 |
-
parent::__construct($invoker);
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Invokes a test method whilst trapping expected
|
34 |
-
* exceptions. Any left over unthrown exceptions
|
35 |
-
* are then reported as failures.
|
36 |
-
* @param string $method Test method to call.
|
37 |
-
*/
|
38 |
-
function invoke($method) {
|
39 |
-
$trap = SimpleTest::getContext()->get('SimpleExceptionTrap');
|
40 |
-
$trap->clear();
|
41 |
-
try {
|
42 |
-
$has_thrown = false;
|
43 |
-
parent::invoke($method);
|
44 |
-
} catch (Exception $exception) {
|
45 |
-
$has_thrown = true;
|
46 |
-
if (! $trap->isExpected($this->getTestCase(), $exception)) {
|
47 |
-
$this->getTestCase()->exception($exception);
|
48 |
-
}
|
49 |
-
$trap->clear();
|
50 |
-
}
|
51 |
-
if ($message = $trap->getOutstanding()) {
|
52 |
-
$this->getTestCase()->fail($message);
|
53 |
-
}
|
54 |
-
if ($has_thrown) {
|
55 |
-
try {
|
56 |
-
parent::getTestCase()->tearDown();
|
57 |
-
} catch (Exception $e) { }
|
58 |
-
}
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Tests exceptions either by type or the exact
|
64 |
-
* exception. This could be improved to accept
|
65 |
-
* a pattern expectation to test the error
|
66 |
-
* message, but that will have to come later.
|
67 |
-
* @package SimpleTest
|
68 |
-
* @subpackage UnitTester
|
69 |
-
*/
|
70 |
-
class ExceptionExpectation extends SimpleExpectation {
|
71 |
-
private $expected;
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Sets up the conditions to test against.
|
75 |
-
* If the expected value is a string, then
|
76 |
-
* it will act as a test of the class name.
|
77 |
-
* An exception as the comparison will
|
78 |
-
* trigger an identical match. Writing this
|
79 |
-
* down now makes it look doubly dumb. I hope
|
80 |
-
* come up with a better scheme later.
|
81 |
-
* @param mixed $expected A class name or an actual
|
82 |
-
* exception to compare with.
|
83 |
-
* @param string $message Message to display.
|
84 |
-
*/
|
85 |
-
function __construct($expected, $message = '%s') {
|
86 |
-
$this->expected = $expected;
|
87 |
-
parent::__construct($message);
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Carry out the test.
|
92 |
-
* @param Exception $compare Value to check.
|
93 |
-
* @return boolean True if matched.
|
94 |
-
*/
|
95 |
-
function test($compare) {
|
96 |
-
if (is_string($this->expected)) {
|
97 |
-
return ($compare instanceof $this->expected);
|
98 |
-
}
|
99 |
-
if (get_class($compare) != get_class($this->expected)) {
|
100 |
-
return false;
|
101 |
-
}
|
102 |
-
return $compare->getMessage() == $this->expected->getMessage();
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Create the message to display describing the test.
|
107 |
-
* @param Exception $compare Exception to match.
|
108 |
-
* @return string Final message.
|
109 |
-
*/
|
110 |
-
function testMessage($compare) {
|
111 |
-
if (is_string($this->expected)) {
|
112 |
-
return "Exception [" . $this->describeException($compare) .
|
113 |
-
"] should be type [" . $this->expected . "]";
|
114 |
-
}
|
115 |
-
return "Exception [" . $this->describeException($compare) .
|
116 |
-
"] should match [" .
|
117 |
-
$this->describeException($this->expected) . "]";
|
118 |
-
}
|
119 |
-
|
120 |
-
/**
|
121 |
-
* Summary of an Exception object.
|
122 |
-
* @param Exception $compare Exception to describe.
|
123 |
-
* @return string Text description.
|
124 |
-
*/
|
125 |
-
protected function describeException($exception) {
|
126 |
-
return get_class($exception) . ": " . $exception->getMessage();
|
127 |
-
}
|
128 |
-
}
|
129 |
-
|
130 |
-
/**
|
131 |
-
* Stores expected exceptions for when they
|
132 |
-
* get thrown. Saves the irritating try...catch
|
133 |
-
* block.
|
134 |
-
* @package SimpleTest
|
135 |
-
* @subpackage UnitTester
|
136 |
-
*/
|
137 |
-
class SimpleExceptionTrap {
|
138 |
-
private $expected;
|
139 |
-
private $ignored;
|
140 |
-
private $message;
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Clears down the queue ready for action.
|
144 |
-
*/
|
145 |
-
function __construct() {
|
146 |
-
$this->clear();
|
147 |
-
}
|
148 |
-
|
149 |
-
/**
|
150 |
-
* Sets up an expectation of an exception.
|
151 |
-
* This has the effect of intercepting an
|
152 |
-
* exception that matches.
|
153 |
-
* @param SimpleExpectation $expected Expected exception to match.
|
154 |
-
* @param string $message Message to display.
|
155 |
-
* @access public
|
156 |
-
*/
|
157 |
-
function expectException($expected = false, $message = '%s') {
|
158 |
-
$this->expected = $this->coerceToExpectation($expected);
|
159 |
-
$this->message = $message;
|
160 |
-
}
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Adds an exception to the ignore list. This is the list
|
164 |
-
* of exceptions that when thrown do not affect the test.
|
165 |
-
* @param SimpleExpectation $ignored Exception to skip.
|
166 |
-
* @access public
|
167 |
-
*/
|
168 |
-
function ignoreException($ignored) {
|
169 |
-
$this->ignored[] = $this->coerceToExpectation($ignored);
|
170 |
-
}
|
171 |
-
|
172 |
-
/**
|
173 |
-
* Compares the expected exception with any
|
174 |
-
* in the queue. Issues a pass or fail and
|
175 |
-
* returns the state of the test.
|
176 |
-
* @param SimpleTestCase $test Test case to send messages to.
|
177 |
-
* @param Exception $exception Exception to compare.
|
178 |
-
* @return boolean False on no match.
|
179 |
-
*/
|
180 |
-
function isExpected($test, $exception) {
|
181 |
-
if ($this->expected) {
|
182 |
-
return $test->assert($this->expected, $exception, $this->message);
|
183 |
-
}
|
184 |
-
foreach ($this->ignored as $ignored) {
|
185 |
-
if ($ignored->test($exception)) {
|
186 |
-
return true;
|
187 |
-
}
|
188 |
-
}
|
189 |
-
return false;
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Turns an expected exception into a SimpleExpectation object.
|
194 |
-
* @param mixed $exception Exception, expectation or
|
195 |
-
* class name of exception.
|
196 |
-
* @return SimpleExpectation Expectation that will match the
|
197 |
-
* exception.
|
198 |
-
*/
|
199 |
-
private function coerceToExpectation($exception) {
|
200 |
-
if ($exception === false) {
|
201 |
-
return new AnythingExpectation();
|
202 |
-
}
|
203 |
-
if (! SimpleExpectation::isExpectation($exception)) {
|
204 |
-
return new ExceptionExpectation($exception);
|
205 |
-
}
|
206 |
-
return $exception;
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Tests for any left over exception.
|
211 |
-
* @return string/false The failure message or false if none.
|
212 |
-
*/
|
213 |
-
function getOutstanding() {
|
214 |
-
return sprintf($this->message, 'Failed to trap exception');
|
215 |
-
}
|
216 |
-
|
217 |
-
/**
|
218 |
-
* Discards the contents of the error queue.
|
219 |
-
*/
|
220 |
-
function clear() {
|
221 |
-
$this->expected = false;
|
222 |
-
$this->message = false;
|
223 |
-
$this->ignored = array();
|
224 |
-
}
|
225 |
-
}
|
226 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/expectation.php
DELETED
@@ -1,984 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* base include file for SimpleTest
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage UnitTester
|
6 |
-
* @version $Id: expectation.php 2009 2011-04-28 08:57:25Z pp11 $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**#@+
|
10 |
-
* include other SimpleTest class files
|
11 |
-
*/
|
12 |
-
require_once(dirname(__FILE__) . '/dumper.php');
|
13 |
-
require_once(dirname(__FILE__) . '/compatibility.php');
|
14 |
-
/**#@-*/
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Assertion that can display failure information.
|
18 |
-
* Also includes various helper methods.
|
19 |
-
* @package SimpleTest
|
20 |
-
* @subpackage UnitTester
|
21 |
-
* @abstract
|
22 |
-
*/
|
23 |
-
class SimpleExpectation {
|
24 |
-
protected $dumper = false;
|
25 |
-
private $message;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Creates a dumper for displaying values and sets
|
29 |
-
* the test message.
|
30 |
-
* @param string $message Customised message on failure.
|
31 |
-
*/
|
32 |
-
function __construct($message = '%s') {
|
33 |
-
$this->message = $message;
|
34 |
-
}
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Tests the expectation. True if correct.
|
38 |
-
* @param mixed $compare Comparison value.
|
39 |
-
* @return boolean True if correct.
|
40 |
-
* @access public
|
41 |
-
* @abstract
|
42 |
-
*/
|
43 |
-
function test($compare) {
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Returns a human readable test message.
|
48 |
-
* @param mixed $compare Comparison value.
|
49 |
-
* @return string Description of success
|
50 |
-
* or failure.
|
51 |
-
* @access public
|
52 |
-
* @abstract
|
53 |
-
*/
|
54 |
-
function testMessage($compare) {
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Overlays the generated message onto the stored user
|
59 |
-
* message. An additional message can be interjected.
|
60 |
-
* @param mixed $compare Comparison value.
|
61 |
-
* @param SimpleDumper $dumper For formatting the results.
|
62 |
-
* @return string Description of success
|
63 |
-
* or failure.
|
64 |
-
* @access public
|
65 |
-
*/
|
66 |
-
function overlayMessage($compare, $dumper) {
|
67 |
-
$this->dumper = $dumper;
|
68 |
-
return sprintf($this->message, $this->testMessage($compare));
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Accessor for the dumper.
|
73 |
-
* @return SimpleDumper Current value dumper.
|
74 |
-
* @access protected
|
75 |
-
*/
|
76 |
-
protected function getDumper() {
|
77 |
-
if (! $this->dumper) {
|
78 |
-
$dumper = new SimpleDumper();
|
79 |
-
return $dumper;
|
80 |
-
}
|
81 |
-
return $this->dumper;
|
82 |
-
}
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Test to see if a value is an expectation object.
|
86 |
-
* A useful utility method.
|
87 |
-
* @param mixed $expectation Hopefully an Expectation
|
88 |
-
* class.
|
89 |
-
* @return boolean True if descended from
|
90 |
-
* this class.
|
91 |
-
* @access public
|
92 |
-
*/
|
93 |
-
static function isExpectation($expectation) {
|
94 |
-
return is_object($expectation) &&
|
95 |
-
SimpleTestCompatibility::isA($expectation, 'SimpleExpectation');
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* A wildcard expectation always matches.
|
101 |
-
* @package SimpleTest
|
102 |
-
* @subpackage MockObjects
|
103 |
-
*/
|
104 |
-
class AnythingExpectation extends SimpleExpectation {
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Tests the expectation. Always true.
|
108 |
-
* @param mixed $compare Ignored.
|
109 |
-
* @return boolean True.
|
110 |
-
* @access public
|
111 |
-
*/
|
112 |
-
function test($compare) {
|
113 |
-
return true;
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Returns a human readable test message.
|
118 |
-
* @param mixed $compare Comparison value.
|
119 |
-
* @return string Description of success
|
120 |
-
* or failure.
|
121 |
-
* @access public
|
122 |
-
*/
|
123 |
-
function testMessage($compare) {
|
124 |
-
$dumper = $this->getDumper();
|
125 |
-
return 'Anything always matches [' . $dumper->describeValue($compare) . ']';
|
126 |
-
}
|
127 |
-
}
|
128 |
-
|
129 |
-
/**
|
130 |
-
* An expectation that never matches.
|
131 |
-
* @package SimpleTest
|
132 |
-
* @subpackage MockObjects
|
133 |
-
*/
|
134 |
-
class FailedExpectation extends SimpleExpectation {
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Tests the expectation. Always false.
|
138 |
-
* @param mixed $compare Ignored.
|
139 |
-
* @return boolean True.
|
140 |
-
* @access public
|
141 |
-
*/
|
142 |
-
function test($compare) {
|
143 |
-
return false;
|
144 |
-
}
|
145 |
-
|
146 |
-
/**
|
147 |
-
* Returns a human readable test message.
|
148 |
-
* @param mixed $compare Comparison value.
|
149 |
-
* @return string Description of failure.
|
150 |
-
* @access public
|
151 |
-
*/
|
152 |
-
function testMessage($compare) {
|
153 |
-
$dumper = $this->getDumper();
|
154 |
-
return 'Failed expectation never matches [' . $dumper->describeValue($compare) . ']';
|
155 |
-
}
|
156 |
-
}
|
157 |
-
|
158 |
-
/**
|
159 |
-
* An expectation that passes on boolean true.
|
160 |
-
* @package SimpleTest
|
161 |
-
* @subpackage MockObjects
|
162 |
-
*/
|
163 |
-
class TrueExpectation extends SimpleExpectation {
|
164 |
-
|
165 |
-
/**
|
166 |
-
* Tests the expectation.
|
167 |
-
* @param mixed $compare Should be true.
|
168 |
-
* @return boolean True on match.
|
169 |
-
* @access public
|
170 |
-
*/
|
171 |
-
function test($compare) {
|
172 |
-
return (boolean)$compare;
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Returns a human readable test message.
|
177 |
-
* @param mixed $compare Comparison value.
|
178 |
-
* @return string Description of success
|
179 |
-
* or failure.
|
180 |
-
* @access public
|
181 |
-
*/
|
182 |
-
function testMessage($compare) {
|
183 |
-
$dumper = $this->getDumper();
|
184 |
-
return 'Expected true, got [' . $dumper->describeValue($compare) . ']';
|
185 |
-
}
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* An expectation that passes on boolean false.
|
190 |
-
* @package SimpleTest
|
191 |
-
* @subpackage MockObjects
|
192 |
-
*/
|
193 |
-
class FalseExpectation extends SimpleExpectation {
|
194 |
-
|
195 |
-
/**
|
196 |
-
* Tests the expectation.
|
197 |
-
* @param mixed $compare Should be false.
|
198 |
-
* @return boolean True on match.
|
199 |
-
* @access public
|
200 |
-
*/
|
201 |
-
function test($compare) {
|
202 |
-
return ! (boolean)$compare;
|
203 |
-
}
|
204 |
-
|
205 |
-
/**
|
206 |
-
* Returns a human readable test message.
|
207 |
-
* @param mixed $compare Comparison value.
|
208 |
-
* @return string Description of success
|
209 |
-
* or failure.
|
210 |
-
* @access public
|
211 |
-
*/
|
212 |
-
function testMessage($compare) {
|
213 |
-
$dumper = $this->getDumper();
|
214 |
-
return 'Expected false, got [' . $dumper->describeValue($compare) . ']';
|
215 |
-
}
|
216 |
-
}
|
217 |
-
|
218 |
-
/**
|
219 |
-
* Test for equality.
|
220 |
-
* @package SimpleTest
|
221 |
-
* @subpackage UnitTester
|
222 |
-
*/
|
223 |
-
class EqualExpectation extends SimpleExpectation {
|
224 |
-
private $value;
|
225 |
-
|
226 |
-
/**
|
227 |
-
* Sets the value to compare against.
|
228 |
-
* @param mixed $value Test value to match.
|
229 |
-
* @param string $message Customised message on failure.
|
230 |
-
* @access public
|
231 |
-
*/
|
232 |
-
function __construct($value, $message = '%s') {
|
233 |
-
parent::__construct($message);
|
234 |
-
$this->value = $value;
|
235 |
-
}
|
236 |
-
|
237 |
-
/**
|
238 |
-
* Tests the expectation. True if it matches the
|
239 |
-
* held value.
|
240 |
-
* @param mixed $compare Comparison value.
|
241 |
-
* @return boolean True if correct.
|
242 |
-
* @access public
|
243 |
-
*/
|
244 |
-
function test($compare) {
|
245 |
-
return (($this->value == $compare) && ($compare == $this->value));
|
246 |
-
}
|
247 |
-
|
248 |
-
/**
|
249 |
-
* Returns a human readable test message.
|
250 |
-
* @param mixed $compare Comparison value.
|
251 |
-
* @return string Description of success
|
252 |
-
* or failure.
|
253 |
-
* @access public
|
254 |
-
*/
|
255 |
-
function testMessage($compare) {
|
256 |
-
if ($this->test($compare)) {
|
257 |
-
return "Equal expectation [" . $this->dumper->describeValue($this->value) . "]";
|
258 |
-
} else {
|
259 |
-
return "Equal expectation fails " .
|
260 |
-
$this->dumper->describeDifference($this->value, $compare);
|
261 |
-
}
|
262 |
-
}
|
263 |
-
|
264 |
-
/**
|
265 |
-
* Accessor for comparison value.
|
266 |
-
* @return mixed Held value to compare with.
|
267 |
-
* @access protected
|
268 |
-
*/
|
269 |
-
protected function getValue() {
|
270 |
-
return $this->value;
|
271 |
-
}
|
272 |
-
}
|
273 |
-
|
274 |
-
/**
|
275 |
-
* Test for inequality.
|
276 |
-
* @package SimpleTest
|
277 |
-
* @subpackage UnitTester
|
278 |
-
*/
|
279 |
-
class NotEqualExpectation extends EqualExpectation {
|
280 |
-
|
281 |
-
/**
|
282 |
-
* Sets the value to compare against.
|
283 |
-
* @param mixed $value Test value to match.
|
284 |
-
* @param string $message Customised message on failure.
|
285 |
-
* @access public
|
286 |
-
*/
|
287 |
-
function __construct($value, $message = '%s') {
|
288 |
-
parent::__construct($value, $message);
|
289 |
-
}
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Tests the expectation. True if it differs from the
|
293 |
-
* held value.
|
294 |
-
* @param mixed $compare Comparison value.
|
295 |
-
* @return boolean True if correct.
|
296 |
-
* @access public
|
297 |
-
*/
|
298 |
-
function test($compare) {
|
299 |
-
return ! parent::test($compare);
|
300 |
-
}
|
301 |
-
|
302 |
-
/**
|
303 |
-
* Returns a human readable test message.
|
304 |
-
* @param mixed $compare Comparison value.
|
305 |
-
* @return string Description of success
|
306 |
-
* or failure.
|
307 |
-
* @access public
|
308 |
-
*/
|
309 |
-
function testMessage($compare) {
|
310 |
-
$dumper = $this->getDumper();
|
311 |
-
if ($this->test($compare)) {
|
312 |
-
return "Not equal expectation passes " .
|
313 |
-
$dumper->describeDifference($this->getValue(), $compare);
|
314 |
-
} else {
|
315 |
-
return "Not equal expectation fails [" .
|
316 |
-
$dumper->describeValue($this->getValue()) .
|
317 |
-
"] matches";
|
318 |
-
}
|
319 |
-
}
|
320 |
-
}
|
321 |
-
|
322 |
-
/**
|
323 |
-
* Test for being within a range.
|
324 |
-
* @package SimpleTest
|
325 |
-
* @subpackage UnitTester
|
326 |
-
*/
|
327 |
-
class WithinMarginExpectation extends SimpleExpectation {
|
328 |
-
private $upper;
|
329 |
-
private $lower;
|
330 |
-
|
331 |
-
/**
|
332 |
-
* Sets the value to compare against and the fuzziness of
|
333 |
-
* the match. Used for comparing floating point values.
|
334 |
-
* @param mixed $value Test value to match.
|
335 |
-
* @param mixed $margin Fuzziness of match.
|
336 |
-
* @param string $message Customised message on failure.
|
337 |
-
* @access public
|
338 |
-
*/
|
339 |
-
function __construct($value, $margin, $message = '%s') {
|
340 |
-
parent::__construct($message);
|
341 |
-
$this->upper = $value + $margin;
|
342 |
-
$this->lower = $value - $margin;
|
343 |
-
}
|
344 |
-
|
345 |
-
/**
|
346 |
-
* Tests the expectation. True if it matches the
|
347 |
-
* held value.
|
348 |
-
* @param mixed $compare Comparison value.
|
349 |
-
* @return boolean True if correct.
|
350 |
-
* @access public
|
351 |
-
*/
|
352 |
-
function test($compare) {
|
353 |
-
return (($compare <= $this->upper) && ($compare >= $this->lower));
|
354 |
-
}
|
355 |
-
|
356 |
-
/**
|
357 |
-
* Returns a human readable test message.
|
358 |
-
* @param mixed $compare Comparison value.
|
359 |
-
* @return string Description of success
|
360 |
-
* or failure.
|
361 |
-
* @access public
|
362 |
-
*/
|
363 |
-
function testMessage($compare) {
|
364 |
-
if ($this->test($compare)) {
|
365 |
-
return $this->withinMessage($compare);
|
366 |
-
} else {
|
367 |
-
return $this->outsideMessage($compare);
|
368 |
-
}
|
369 |
-
}
|
370 |
-
|
371 |
-
/**
|
372 |
-
* Creates a the message for being within the range.
|
373 |
-
* @param mixed $compare Value being tested.
|
374 |
-
* @access private
|
375 |
-
*/
|
376 |
-
protected function withinMessage($compare) {
|
377 |
-
return "Within expectation [" . $this->dumper->describeValue($this->lower) . "] and [" .
|
378 |
-
$this->dumper->describeValue($this->upper) . "]";
|
379 |
-
}
|
380 |
-
|
381 |
-
/**
|
382 |
-
* Creates a the message for being within the range.
|
383 |
-
* @param mixed $compare Value being tested.
|
384 |
-
* @access private
|
385 |
-
*/
|
386 |
-
protected function outsideMessage($compare) {
|
387 |
-
if ($compare > $this->upper) {
|
388 |
-
return "Outside expectation " .
|
389 |
-
$this->dumper->describeDifference($compare, $this->upper);
|
390 |
-
} else {
|
391 |
-
return "Outside expectation " .
|
392 |
-
$this->dumper->describeDifference($compare, $this->lower);
|
393 |
-
}
|
394 |
-
}
|
395 |
-
}
|
396 |
-
|
397 |
-
/**
|
398 |
-
* Test for being outside of a range.
|
399 |
-
* @package SimpleTest
|
400 |
-
* @subpackage UnitTester
|
401 |
-
*/
|
402 |
-
class OutsideMarginExpectation extends WithinMarginExpectation {
|
403 |
-
|
404 |
-
/**
|
405 |
-
* Sets the value to compare against and the fuzziness of
|
406 |
-
* the match. Used for comparing floating point values.
|
407 |
-
* @param mixed $value Test value to not match.
|
408 |
-
* @param mixed $margin Fuzziness of match.
|
409 |
-
* @param string $message Customised message on failure.
|
410 |
-
* @access public
|
411 |
-
*/
|
412 |
-
function __construct($value, $margin, $message = '%s') {
|
413 |
-
parent::__construct($value, $margin, $message);
|
414 |
-
}
|
415 |
-
|
416 |
-
/**
|
417 |
-
* Tests the expectation. True if it matches the
|
418 |
-
* held value.
|
419 |
-
* @param mixed $compare Comparison value.
|
420 |
-
* @return boolean True if correct.
|
421 |
-
* @access public
|
422 |
-
*/
|
423 |
-
function test($compare) {
|
424 |
-
return ! parent::test($compare);
|
425 |
-
}
|
426 |
-
|
427 |
-
/**
|
428 |
-
* Returns a human readable test message.
|
429 |
-
* @param mixed $compare Comparison value.
|
430 |
-
* @return string Description of success
|
431 |
-
* or failure.
|
432 |
-
* @access public
|
433 |
-
*/
|
434 |
-
function testMessage($compare) {
|
435 |
-
if (! $this->test($compare)) {
|
436 |
-
return $this->withinMessage($compare);
|
437 |
-
} else {
|
438 |
-
return $this->outsideMessage($compare);
|
439 |
-
}
|
440 |
-
}
|
441 |
-
}
|
442 |
-
|
443 |
-
/**
|
444 |
-
* Test for reference.
|
445 |
-
* @package SimpleTest
|
446 |
-
* @subpackage UnitTester
|
447 |
-
*/
|
448 |
-
class ReferenceExpectation {
|
449 |
-
private $value;
|
450 |
-
|
451 |
-
/**
|
452 |
-
* Sets the reference value to compare against.
|
453 |
-
* @param mixed $value Test reference to match.
|
454 |
-
* @param string $message Customised message on failure.
|
455 |
-
* @access public
|
456 |
-
*/
|
457 |
-
function __construct(&$value, $message = '%s') {
|
458 |
-
$this->message = $message;
|
459 |
-
$this->value = &$value;
|
460 |
-
}
|
461 |
-
|
462 |
-
/**
|
463 |
-
* Tests the expectation. True if it exactly
|
464 |
-
* references the held value.
|
465 |
-
* @param mixed $compare Comparison reference.
|
466 |
-
* @return boolean True if correct.
|
467 |
-
* @access public
|
468 |
-
*/
|
469 |
-
function test(&$compare) {
|
470 |
-
return SimpleTestCompatibility::isReference($this->value, $compare);
|
471 |
-
}
|
472 |
-
|
473 |
-
/**
|
474 |
-
* Returns a human readable test message.
|
475 |
-
* @param mixed $compare Comparison value.
|
476 |
-
* @return string Description of success
|
477 |
-
* or failure.
|
478 |
-
* @access public
|
479 |
-
*/
|
480 |
-
function testMessage($compare) {
|
481 |
-
if ($this->test($compare)) {
|
482 |
-
return "Reference expectation [" . $this->dumper->describeValue($this->value) . "]";
|
483 |
-
} else {
|
484 |
-
return "Reference expectation fails " .
|
485 |
-
$this->dumper->describeDifference($this->value, $compare);
|
486 |
-
}
|
487 |
-
}
|
488 |
-
|
489 |
-
/**
|
490 |
-
* Overlays the generated message onto the stored user
|
491 |
-
* message. An additional message can be interjected.
|
492 |
-
* @param mixed $compare Comparison value.
|
493 |
-
* @param SimpleDumper $dumper For formatting the results.
|
494 |
-
* @return string Description of success
|
495 |
-
* or failure.
|
496 |
-
* @access public
|
497 |
-
*/
|
498 |
-
function overlayMessage($compare, $dumper) {
|
499 |
-
$this->dumper = $dumper;
|
500 |
-
return sprintf($this->message, $this->testMessage($compare));
|
501 |
-
}
|
502 |
-
|
503 |
-
/**
|
504 |
-
* Accessor for the dumper.
|
505 |
-
* @return SimpleDumper Current value dumper.
|
506 |
-
* @access protected
|
507 |
-
*/
|
508 |
-
protected function getDumper() {
|
509 |
-
if (! $this->dumper) {
|
510 |
-
$dumper = new SimpleDumper();
|
511 |
-
return $dumper;
|
512 |
-
}
|
513 |
-
return $this->dumper;
|
514 |
-
}
|
515 |
-
}
|
516 |
-
|
517 |
-
/**
|
518 |
-
* Test for identity.
|
519 |
-
* @package SimpleTest
|
520 |
-
* @subpackage UnitTester
|
521 |
-
*/
|
522 |
-
class IdenticalExpectation extends EqualExpectation {
|
523 |
-
|
524 |
-
/**
|
525 |
-
* Sets the value to compare against.
|
526 |
-
* @param mixed $value Test value to match.
|
527 |
-
* @param string $message Customised message on failure.
|
528 |
-
* @access public
|
529 |
-
*/
|
530 |
-
function __construct($value, $message = '%s') {
|
531 |
-
parent::__construct($value, $message);
|
532 |
-
}
|
533 |
-
|
534 |
-
/**
|
535 |
-
* Tests the expectation. True if it exactly
|
536 |
-
* matches the held value.
|
537 |
-
* @param mixed $compare Comparison value.
|
538 |
-
* @return boolean True if correct.
|
539 |
-
* @access public
|
540 |
-
*/
|
541 |
-
function test($compare) {
|
542 |
-
return SimpleTestCompatibility::isIdentical($this->getValue(), $compare);
|
543 |
-
}
|
544 |
-
|
545 |
-
/**
|
546 |
-
* Returns a human readable test message.
|
547 |
-
* @param mixed $compare Comparison value.
|
548 |
-
* @return string Description of success
|
549 |
-
* or failure.
|
550 |
-
* @access public
|
551 |
-
*/
|
552 |
-
function testMessage($compare) {
|
553 |
-
$dumper = $this->getDumper();
|
554 |
-
if ($this->test($compare)) {
|
555 |
-
return "Identical expectation [" . $dumper->describeValue($this->getValue()) . "]";
|
556 |
-
} else {
|
557 |
-
return "Identical expectation [" . $dumper->describeValue($this->getValue()) .
|
558 |
-
"] fails with [" .
|
559 |
-
$dumper->describeValue($compare) . "] " .
|
560 |
-
$dumper->describeDifference($this->getValue(), $compare, TYPE_MATTERS);
|
561 |
-
}
|
562 |
-
}
|
563 |
-
}
|
564 |
-
|
565 |
-
/**
|
566 |
-
* Test for non-identity.
|
567 |
-
* @package SimpleTest
|
568 |
-
* @subpackage UnitTester
|
569 |
-
*/
|
570 |
-
class NotIdenticalExpectation extends IdenticalExpectation {
|
571 |
-
|
572 |
-
/**
|
573 |
-
* Sets the value to compare against.
|
574 |
-
* @param mixed $value Test value to match.
|
575 |
-
* @param string $message Customised message on failure.
|
576 |
-
* @access public
|
577 |
-
*/
|
578 |
-
function __construct($value, $message = '%s') {
|
579 |
-
parent::__construct($value, $message);
|
580 |
-
}
|
581 |
-
|
582 |
-
/**
|
583 |
-
* Tests the expectation. True if it differs from the
|
584 |
-
* held value.
|
585 |
-
* @param mixed $compare Comparison value.
|
586 |
-
* @return boolean True if correct.
|
587 |
-
* @access public
|
588 |
-
*/
|
589 |
-
function test($compare) {
|
590 |
-
return ! parent::test($compare);
|
591 |
-
}
|
592 |
-
|
593 |
-
/**
|
594 |
-
* Returns a human readable test message.
|
595 |
-
* @param mixed $compare Comparison value.
|
596 |
-
* @return string Description of success
|
597 |
-
* or failure.
|
598 |
-
* @access public
|
599 |
-
*/
|
600 |
-
function testMessage($compare) {
|
601 |
-
$dumper = $this->getDumper();
|
602 |
-
if ($this->test($compare)) {
|
603 |
-
return "Not identical expectation passes " .
|
604 |
-
$dumper->describeDifference($this->getValue(), $compare, TYPE_MATTERS);
|
605 |
-
} else {
|
606 |
-
return "Not identical expectation [" . $dumper->describeValue($this->getValue()) . "] matches";
|
607 |
-
}
|
608 |
-
}
|
609 |
-
}
|
610 |
-
|
611 |
-
/**
|
612 |
-
* Test for a pattern using Perl regex rules.
|
613 |
-
* @package SimpleTest
|
614 |
-
* @subpackage UnitTester
|
615 |
-
*/
|
616 |
-
class PatternExpectation extends SimpleExpectation {
|
617 |
-
private $pattern;
|
618 |
-
|
619 |
-
/**
|
620 |
-
* Sets the value to compare against.
|
621 |
-
* @param string $pattern Pattern to search for.
|
622 |
-
* @param string $message Customised message on failure.
|
623 |
-
* @access public
|
624 |
-
*/
|
625 |
-
function __construct($pattern, $message = '%s') {
|
626 |
-
parent::__construct($message);
|
627 |
-
$this->pattern = $pattern;
|
628 |
-
}
|
629 |
-
|
630 |
-
/**
|
631 |
-
* Accessor for the pattern.
|
632 |
-
* @return string Perl regex as string.
|
633 |
-
* @access protected
|
634 |
-
*/
|
635 |
-
protected function getPattern() {
|
636 |
-
return $this->pattern;
|
637 |
-
}
|
638 |
-
|
639 |
-
/**
|
640 |
-
* Tests the expectation. True if the Perl regex
|
641 |
-
* matches the comparison value.
|
642 |
-
* @param string $compare Comparison value.
|
643 |
-
* @return boolean True if correct.
|
644 |
-
* @access public
|
645 |
-
*/
|
646 |
-
function test($compare) {
|
647 |
-
return (boolean)preg_match($this->getPattern(), $compare);
|
648 |
-
}
|
649 |
-
|
650 |
-
/**
|
651 |
-
* Returns a human readable test message.
|
652 |
-
* @param mixed $compare Comparison value.
|
653 |
-
* @return string Description of success
|
654 |
-
* or failure.
|
655 |
-
* @access public
|
656 |
-
*/
|
657 |
-
function testMessage($compare) {
|
658 |
-
if ($this->test($compare)) {
|
659 |
-
return $this->describePatternMatch($this->getPattern(), $compare);
|
660 |
-
} else {
|
661 |
-
$dumper = $this->getDumper();
|
662 |
-
return "Pattern [" . $this->getPattern() .
|
663 |
-
"] not detected in [" .
|
664 |
-
$dumper->describeValue($compare) . "]";
|
665 |
-
}
|
666 |
-
}
|
667 |
-
|
668 |
-
/**
|
669 |
-
* Describes a pattern match including the string
|
670 |
-
* found and it's position.
|
671 |
-
* @param string $pattern Regex to match against.
|
672 |
-
* @param string $subject Subject to search.
|
673 |
-
* @access protected
|
674 |
-
*/
|
675 |
-
protected function describePatternMatch($pattern, $subject) {
|
676 |
-
preg_match($pattern, $subject, $matches);
|
677 |
-
$position = strpos($subject, $matches[0]);
|
678 |
-
$dumper = $this->getDumper();
|
679 |
-
return "Pattern [$pattern] detected at character [$position] in [" .
|
680 |
-
$dumper->describeValue($subject) . "] as [" .
|
681 |
-
$matches[0] . "] in region [" .
|
682 |
-
$dumper->clipString($subject, 100, $position) . "]";
|
683 |
-
}
|
684 |
-
}
|
685 |
-
|
686 |
-
/**
|
687 |
-
* Fail if a pattern is detected within the
|
688 |
-
* comparison.
|
689 |
-
* @package SimpleTest
|
690 |
-
* @subpackage UnitTester
|
691 |
-
*/
|
692 |
-
class NoPatternExpectation extends PatternExpectation {
|
693 |
-
|
694 |
-
/**
|
695 |
-
* Sets the reject pattern
|
696 |
-
* @param string $pattern Pattern to search for.
|
697 |
-
* @param string $message Customised message on failure.
|
698 |
-
* @access public
|
699 |
-
*/
|
700 |
-
function __construct($pattern, $message = '%s') {
|
701 |
-
parent::__construct($pattern, $message);
|
702 |
-
}
|
703 |
-
|
704 |
-
/**
|
705 |
-
* Tests the expectation. False if the Perl regex
|
706 |
-
* matches the comparison value.
|
707 |
-
* @param string $compare Comparison value.
|
708 |
-
* @return boolean True if correct.
|
709 |
-
* @access public
|
710 |
-
*/
|
711 |
-
function test($compare) {
|
712 |
-
return ! parent::test($compare);
|
713 |
-
}
|
714 |
-
|
715 |
-
/**
|
716 |
-
* Returns a human readable test message.
|
717 |
-
* @param string $compare Comparison value.
|
718 |
-
* @return string Description of success
|
719 |
-
* or failure.
|
720 |
-
* @access public
|
721 |
-
*/
|
722 |
-
function testMessage($compare) {
|
723 |
-
if ($this->test($compare)) {
|
724 |
-
$dumper = $this->getDumper();
|
725 |
-
return "Pattern [" . $this->getPattern() .
|
726 |
-
"] not detected in [" .
|
727 |
-
$dumper->describeValue($compare) . "]";
|
728 |
-
} else {
|
729 |
-
return $this->describePatternMatch($this->getPattern(), $compare);
|
730 |
-
}
|
731 |
-
}
|
732 |
-
}
|
733 |
-
|
734 |
-
/**
|
735 |
-
* Tests either type or class name if it's an object.
|
736 |
-
* @package SimpleTest
|
737 |
-
* @subpackage UnitTester
|
738 |
-
*/
|
739 |
-
class IsAExpectation extends SimpleExpectation {
|
740 |
-
private $type;
|
741 |
-
|
742 |
-
/**
|
743 |
-
* Sets the type to compare with.
|
744 |
-
* @param string $type Type or class name.
|
745 |
-
* @param string $message Customised message on failure.
|
746 |
-
* @access public
|
747 |
-
*/
|
748 |
-
function __construct($type, $message = '%s') {
|
749 |
-
parent::__construct($message);
|
750 |
-
$this->type = $type;
|
751 |
-
}
|
752 |
-
|
753 |
-
/**
|
754 |
-
* Accessor for type to check against.
|
755 |
-
* @return string Type or class name.
|
756 |
-
* @access protected
|
757 |
-
*/
|
758 |
-
protected function getType() {
|
759 |
-
return $this->type;
|
760 |
-
}
|
761 |
-
|
762 |
-
/**
|
763 |
-
* Tests the expectation. True if the type or
|
764 |
-
* class matches the string value.
|
765 |
-
* @param string $compare Comparison value.
|
766 |
-
* @return boolean True if correct.
|
767 |
-
* @access public
|
768 |
-
*/
|
769 |
-
function test($compare) {
|
770 |
-
if (is_object($compare)) {
|
771 |
-
return SimpleTestCompatibility::isA($compare, $this->type);
|
772 |
-
} else {
|
773 |
-
$function = 'is_'.$this->canonicalType($this->type);
|
774 |
-
if (is_callable($function)) {
|
775 |
-
return $function($compare);
|
776 |
-
}
|
777 |
-
return false;
|
778 |
-
}
|
779 |
-
}
|
780 |
-
|
781 |
-
/**
|
782 |
-
* Coerces type name into a is_*() match.
|
783 |
-
* @param string $type User type.
|
784 |
-
* @return string Simpler type.
|
785 |
-
* @access private
|
786 |
-
*/
|
787 |
-
protected function canonicalType($type) {
|
788 |
-
$type = strtolower($type);
|
789 |
-
$map = array('boolean' => 'bool');
|
790 |
-
if (isset($map[$type])) {
|
791 |
-
$type = $map[$type];
|
792 |
-
}
|
793 |
-
return $type;
|
794 |
-
}
|
795 |
-
|
796 |
-
/**
|
797 |
-
* Returns a human readable test message.
|
798 |
-
* @param mixed $compare Comparison value.
|
799 |
-
* @return string Description of success
|
800 |
-
* or failure.
|
801 |
-
* @access public
|
802 |
-
*/
|
803 |
-
function testMessage($compare) {
|
804 |
-
$dumper = $this->getDumper();
|
805 |
-
return "Value [" . $dumper->describeValue($compare) .
|
806 |
-
"] should be type [" . $this->type . "]";
|
807 |
-
}
|
808 |
-
}
|
809 |
-
|
810 |
-
/**
|
811 |
-
* Tests either type or class name if it's an object.
|
812 |
-
* Will succeed if the type does not match.
|
813 |
-
* @package SimpleTest
|
814 |
-
* @subpackage UnitTester
|
815 |
-
*/
|
816 |
-
class NotAExpectation extends IsAExpectation {
|
817 |
-
private $type;
|
818 |
-
|
819 |
-
/**
|
820 |
-
* Sets the type to compare with.
|
821 |
-
* @param string $type Type or class name.
|
822 |
-
* @param string $message Customised message on failure.
|
823 |
-
* @access public
|
824 |
-
*/
|
825 |
-
function __construct($type, $message = '%s') {
|
826 |
-
parent::__construct($type, $message);
|
827 |
-
}
|
828 |
-
|
829 |
-
/**
|
830 |
-
* Tests the expectation. False if the type or
|
831 |
-
* class matches the string value.
|
832 |
-
* @param string $compare Comparison value.
|
833 |
-
* @return boolean True if different.
|
834 |
-
* @access public
|
835 |
-
*/
|
836 |
-
function test($compare) {
|
837 |
-
return ! parent::test($compare);
|
838 |
-
}
|
839 |
-
|
840 |
-
/**
|
841 |
-
* Returns a human readable test message.
|
842 |
-
* @param mixed $compare Comparison value.
|
843 |
-
* @return string Description of success
|
844 |
-
* or failure.
|
845 |
-
* @access public
|
846 |
-
*/
|
847 |
-
function testMessage($compare) {
|
848 |
-
$dumper = $this->getDumper();
|
849 |
-
return "Value [" . $dumper->describeValue($compare) .
|
850 |
-
"] should not be type [" . $this->getType() . "]";
|
851 |
-
}
|
852 |
-
}
|
853 |
-
|
854 |
-
/**
|
855 |
-
* Tests for existance of a method in an object
|
856 |
-
* @package SimpleTest
|
857 |
-
* @subpackage UnitTester
|
858 |
-
*/
|
859 |
-
class MethodExistsExpectation extends SimpleExpectation {
|
860 |
-
private $method;
|
861 |
-
|
862 |
-
/**
|
863 |
-
* Sets the value to compare against.
|
864 |
-
* @param string $method Method to check.
|
865 |
-
* @param string $message Customised message on failure.
|
866 |
-
* @return void
|
867 |
-
*/
|
868 |
-
function __construct($method, $message = '%s') {
|
869 |
-
parent::__construct($message);
|
870 |
-
$this->method = &$method;
|
871 |
-
}
|
872 |
-
|
873 |
-
/**
|
874 |
-
* Tests the expectation. True if the method exists in the test object.
|
875 |
-
* @param string $compare Comparison method name.
|
876 |
-
* @return boolean True if correct.
|
877 |
-
*/
|
878 |
-
function test($compare) {
|
879 |
-
return (boolean)(is_object($compare) && method_exists($compare, $this->method));
|
880 |
-
}
|
881 |
-
|
882 |
-
/**
|
883 |
-
* Returns a human readable test message.
|
884 |
-
* @param mixed $compare Comparison value.
|
885 |
-
* @return string Description of success
|
886 |
-
* or failure.
|
887 |
-
*/
|
888 |
-
function testMessage($compare) {
|
889 |
-
$dumper = $this->getDumper();
|
890 |
-
if (! is_object($compare)) {
|
891 |
-
return 'No method on non-object [' . $dumper->describeValue($compare) . ']';
|
892 |
-
}
|
893 |
-
$method = $this->method;
|
894 |
-
return "Object [" . $dumper->describeValue($compare) .
|
895 |
-
"] should contain method [$method]";
|
896 |
-
}
|
897 |
-
}
|
898 |
-
|
899 |
-
/**
|
900 |
-
* Compares an object member's value even if private.
|
901 |
-
* @package SimpleTest
|
902 |
-
* @subpackage UnitTester
|
903 |
-
*/
|
904 |
-
class MemberExpectation extends IdenticalExpectation {
|
905 |
-
private $name;
|
906 |
-
|
907 |
-
/**
|
908 |
-
* Sets the value to compare against.
|
909 |
-
* @param string $method Method to check.
|
910 |
-
* @param string $message Customised message on failure.
|
911 |
-
* @return void
|
912 |
-
*/
|
913 |
-
function __construct($name, $expected) {
|
914 |
-
$this->name = $name;
|
915 |
-
parent::__construct($expected);
|
916 |
-
}
|
917 |
-
|
918 |
-
/**
|
919 |
-
* Tests the expectation. True if the property value is identical.
|
920 |
-
* @param object $actual Comparison object.
|
921 |
-
* @return boolean True if identical.
|
922 |
-
*/
|
923 |
-
function test($actual) {
|
924 |
-
if (! is_object($actual)) {
|
925 |
-
return false;
|
926 |
-
}
|
927 |
-
return parent::test($this->getProperty($this->name, $actual));
|
928 |
-
}
|
929 |
-
|
930 |
-
/**
|
931 |
-
* Returns a human readable test message.
|
932 |
-
* @param mixed $compare Comparison value.
|
933 |
-
* @return string Description of success
|
934 |
-
* or failure.
|
935 |
-
*/
|
936 |
-
function testMessage($actual) {
|
937 |
-
return parent::testMessage($this->getProperty($this->name, $actual));
|
938 |
-
}
|
939 |
-
|
940 |
-
/**
|
941 |
-
* Extracts the member value even if private using reflection.
|
942 |
-
* @param string $name Property name.
|
943 |
-
* @param object $object Object to read.
|
944 |
-
* @return mixed Value of property.
|
945 |
-
*/
|
946 |
-
private function getProperty($name, $object) {
|
947 |
-
$reflection = new ReflectionObject($object);
|
948 |
-
$property = $reflection->getProperty($name);
|
949 |
-
if (method_exists($property, 'setAccessible')) {
|
950 |
-
$property->setAccessible(true);
|
951 |
-
}
|
952 |
-
try {
|
953 |
-
return $property->getValue($object);
|
954 |
-
} catch (ReflectionException $e) {
|
955 |
-
return $this->getPrivatePropertyNoMatterWhat($name, $object);
|
956 |
-
}
|
957 |
-
}
|
958 |
-
|
959 |
-
/**
|
960 |
-
* Extracts a private member's value when reflection won't play ball.
|
961 |
-
* @param string $name Property name.
|
962 |
-
* @param object $object Object to read.
|
963 |
-
* @return mixed Value of property.
|
964 |
-
*/
|
965 |
-
private function getPrivatePropertyNoMatterWhat($name, $object) {
|
966 |
-
foreach ((array)$object as $mangled_name => $value) {
|
967 |
-
if ($this->unmangle($mangled_name) == $name) {
|
968 |
-
return $value;
|
969 |
-
}
|
970 |
-
}
|
971 |
-
}
|
972 |
-
|
973 |
-
/**
|
974 |
-
* Removes crud from property name after it's been converted
|
975 |
-
* to an array.
|
976 |
-
* @param string $mangled Name from array cast.
|
977 |
-
* @return string Cleaned up name.
|
978 |
-
*/
|
979 |
-
function unmangle($mangled) {
|
980 |
-
$parts = preg_split('/[^a-zA-Z0-9_\x7f-\xff]+/', $mangled);
|
981 |
-
return array_pop($parts);
|
982 |
-
}
|
983 |
-
}
|
984 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/extensions/pear_test_case.php
DELETED
@@ -1,196 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* adapter for SimpleTest to use PEAR PHPUnit test cases
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage Extensions
|
6 |
-
* @version $Id: pear_test_case.php 1836 2008-12-21 00:02:26Z edwardzyang $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**#@+
|
10 |
-
* include SimpleTest files
|
11 |
-
*/
|
12 |
-
require_once(dirname(__FILE__) . '/../dumper.php');
|
13 |
-
require_once(dirname(__FILE__) . '/../compatibility.php');
|
14 |
-
require_once(dirname(__FILE__) . '/../test_case.php');
|
15 |
-
require_once(dirname(__FILE__) . '/../expectation.php');
|
16 |
-
/**#@-*/
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Adapter for PEAR PHPUnit test case to allow
|
20 |
-
* legacy PEAR test cases to be used with SimpleTest.
|
21 |
-
* @package SimpleTest
|
22 |
-
* @subpackage Extensions
|
23 |
-
*/
|
24 |
-
class PHPUnit_TestCase extends SimpleTestCase {
|
25 |
-
private $_loosely_typed;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Constructor. Sets the test name.
|
29 |
-
* @param $label Test name to display.
|
30 |
-
* @public
|
31 |
-
*/
|
32 |
-
function __construct($label = false) {
|
33 |
-
parent::__construct($label);
|
34 |
-
$this->_loosely_typed = false;
|
35 |
-
}
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Will test straight equality if set to loose
|
39 |
-
* typing, or identity if not.
|
40 |
-
* @param $first First value.
|
41 |
-
* @param $second Comparison value.
|
42 |
-
* @param $message Message to display.
|
43 |
-
* @public
|
44 |
-
*/
|
45 |
-
function assertEquals($first, $second, $message = "%s", $delta = 0) {
|
46 |
-
if ($this->_loosely_typed) {
|
47 |
-
$expectation = new EqualExpectation($first);
|
48 |
-
} else {
|
49 |
-
$expectation = new IdenticalExpectation($first);
|
50 |
-
}
|
51 |
-
$this->assert($expectation, $second, $message);
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Passes if the value tested is not null.
|
56 |
-
* @param $value Value to test against.
|
57 |
-
* @param $message Message to display.
|
58 |
-
* @public
|
59 |
-
*/
|
60 |
-
function assertNotNull($value, $message = "%s") {
|
61 |
-
parent::assert(new TrueExpectation(), isset($value), $message);
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Passes if the value tested is null.
|
66 |
-
* @param $value Value to test against.
|
67 |
-
* @param $message Message to display.
|
68 |
-
* @public
|
69 |
-
*/
|
70 |
-
function assertNull($value, $message = "%s") {
|
71 |
-
parent::assert(new TrueExpectation(), !isset($value), $message);
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Identity test tests for the same object.
|
76 |
-
* @param $first First object handle.
|
77 |
-
* @param $second Hopefully the same handle.
|
78 |
-
* @param $message Message to display.
|
79 |
-
* @public
|
80 |
-
*/
|
81 |
-
function assertSame($first, $second, $message = "%s") {
|
82 |
-
$dumper = new SimpleDumper();
|
83 |
-
$message = sprintf(
|
84 |
-
$message,
|
85 |
-
"[" . $dumper->describeValue($first) .
|
86 |
-
"] and [" . $dumper->describeValue($second) .
|
87 |
-
"] should reference the same object");
|
88 |
-
return $this->assert(
|
89 |
-
new TrueExpectation(),
|
90 |
-
SimpleTestCompatibility::isReference($first, $second),
|
91 |
-
$message);
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Inverted identity test.
|
96 |
-
* @param $first First object handle.
|
97 |
-
* @param $second Hopefully a different handle.
|
98 |
-
* @param $message Message to display.
|
99 |
-
* @public
|
100 |
-
*/
|
101 |
-
function assertNotSame($first, $second, $message = "%s") {
|
102 |
-
$dumper = new SimpleDumper();
|
103 |
-
$message = sprintf(
|
104 |
-
$message,
|
105 |
-
"[" . $dumper->describeValue($first) .
|
106 |
-
"] and [" . $dumper->describeValue($second) .
|
107 |
-
"] should not be the same object");
|
108 |
-
return $this->assert(
|
109 |
-
new falseExpectation(),
|
110 |
-
SimpleTestCompatibility::isReference($first, $second),
|
111 |
-
$message);
|
112 |
-
}
|
113 |
-
|
114 |
-
/**
|
115 |
-
* Sends pass if the test condition resolves true,
|
116 |
-
* a fail otherwise.
|
117 |
-
* @param $condition Condition to test true.
|
118 |
-
* @param $message Message to display.
|
119 |
-
* @public
|
120 |
-
*/
|
121 |
-
function assertTrue($condition, $message = "%s") {
|
122 |
-
parent::assert(new TrueExpectation(), $condition, $message);
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Sends pass if the test condition resolves false,
|
127 |
-
* a fail otherwise.
|
128 |
-
* @param $condition Condition to test false.
|
129 |
-
* @param $message Message to display.
|
130 |
-
* @public
|
131 |
-
*/
|
132 |
-
function assertFalse($condition, $message = "%s") {
|
133 |
-
parent::assert(new FalseExpectation(), $condition, $message);
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Tests a regex match. Needs refactoring.
|
138 |
-
* @param $pattern Regex to match.
|
139 |
-
* @param $subject String to search in.
|
140 |
-
* @param $message Message to display.
|
141 |
-
* @public
|
142 |
-
*/
|
143 |
-
function assertRegExp($pattern, $subject, $message = "%s") {
|
144 |
-
$this->assert(new PatternExpectation($pattern), $subject, $message);
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Tests the type of a value.
|
149 |
-
* @param $value Value to take type of.
|
150 |
-
* @param $type Hoped for type.
|
151 |
-
* @param $message Message to display.
|
152 |
-
* @public
|
153 |
-
*/
|
154 |
-
function assertType($value, $type, $message = "%s") {
|
155 |
-
parent::assert(new TrueExpectation(), gettype($value) == strtolower($type), $message);
|
156 |
-
}
|
157 |
-
|
158 |
-
/**
|
159 |
-
* Sets equality operation to act as a simple equal
|
160 |
-
* comparison only, allowing a broader range of
|
161 |
-
* matches.
|
162 |
-
* @param $loosely_typed True for broader comparison.
|
163 |
-
* @public
|
164 |
-
*/
|
165 |
-
function setLooselyTyped($loosely_typed) {
|
166 |
-
$this->_loosely_typed = $loosely_typed;
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* For progress indication during
|
171 |
-
* a test amongst other things.
|
172 |
-
* @return Usually one.
|
173 |
-
* @public
|
174 |
-
*/
|
175 |
-
function countTestCases() {
|
176 |
-
return $this->getSize();
|
177 |
-
}
|
178 |
-
|
179 |
-
/**
|
180 |
-
* Accessor for name, normally just the class
|
181 |
-
* name.
|
182 |
-
* @public
|
183 |
-
*/
|
184 |
-
function getName() {
|
185 |
-
return $this->getLabel();
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Does nothing. For compatibility only.
|
190 |
-
* @param $name Dummy
|
191 |
-
* @public
|
192 |
-
*/
|
193 |
-
function setName($name) {
|
194 |
-
}
|
195 |
-
}
|
196 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/extensions/testdox.php
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Extension for a TestDox reporter
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage Extensions
|
6 |
-
* @version $Id: testdox.php 2004 2010-10-31 13:44:14Z jsweat $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**
|
10 |
-
* TestDox reporter
|
11 |
-
* @package SimpleTest
|
12 |
-
* @subpackage Extensions
|
13 |
-
*/
|
14 |
-
class TestDoxReporter extends SimpleReporter
|
15 |
-
{
|
16 |
-
var $_test_case_pattern = '/^TestOf(.*)$/';
|
17 |
-
|
18 |
-
function __construct($test_case_pattern = '/^TestOf(.*)$/') {
|
19 |
-
parent::__construct();
|
20 |
-
$this->_test_case_pattern = empty($test_case_pattern) ? '/^(.*)$/' : $test_case_pattern;
|
21 |
-
}
|
22 |
-
|
23 |
-
function paintCaseStart($test_name) {
|
24 |
-
preg_match($this->_test_case_pattern, $test_name, $matches);
|
25 |
-
if (!empty($matches[1])) {
|
26 |
-
echo $matches[1] . "\n";
|
27 |
-
} else {
|
28 |
-
echo $test_name . "\n";
|
29 |
-
}
|
30 |
-
}
|
31 |
-
|
32 |
-
function paintCaseEnd($test_name) {
|
33 |
-
echo "\n";
|
34 |
-
}
|
35 |
-
|
36 |
-
function paintMethodStart($test_name) {
|
37 |
-
if (!preg_match('/^test(.*)$/i', $test_name, $matches)) {
|
38 |
-
return;
|
39 |
-
}
|
40 |
-
$test_name = $matches[1];
|
41 |
-
$test_name = preg_replace('/([A-Z])([A-Z])/', '$1 $2', $test_name);
|
42 |
-
echo '- ' . strtolower(preg_replace('/([a-zA-Z])([A-Z0-9])/', '$1 $2', $test_name));
|
43 |
-
}
|
44 |
-
|
45 |
-
function paintMethodEnd($test_name) {
|
46 |
-
echo "\n";
|
47 |
-
}
|
48 |
-
|
49 |
-
function paintFail($message) {
|
50 |
-
echo " [FAILED]";
|
51 |
-
}
|
52 |
-
}
|
53 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/extensions/testdox/test.php
DELETED
@@ -1,107 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
// $Id: test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
3 |
-
require_once dirname(__FILE__) . '/../../autorun.php';
|
4 |
-
require_once dirname(__FILE__) . '/../testdox.php';
|
5 |
-
|
6 |
-
// uncomment to see test dox in action
|
7 |
-
//SimpleTest::prefer(new TestDoxReporter());
|
8 |
-
|
9 |
-
class TestOfTestDoxReporter extends UnitTestCase
|
10 |
-
{
|
11 |
-
function testIsAnInstanceOfSimpleScorerAndReporter() {
|
12 |
-
$dox = new TestDoxReporter();
|
13 |
-
$this->assertIsA($dox, 'SimpleScorer');
|
14 |
-
$this->assertIsA($dox, 'SimpleReporter');
|
15 |
-
}
|
16 |
-
|
17 |
-
function testOutputsNameOfTestCase() {
|
18 |
-
$dox = new TestDoxReporter();
|
19 |
-
ob_start();
|
20 |
-
$dox->paintCaseStart('TestOfTestDoxReporter');
|
21 |
-
$buffer = ob_get_clean();
|
22 |
-
$this->assertPattern('/^TestDoxReporter/', $buffer);
|
23 |
-
}
|
24 |
-
|
25 |
-
function testOutputOfTestCaseNameFilteredByConstructParameter() {
|
26 |
-
$dox = new TestDoxReporter('/^(.*)Test$/');
|
27 |
-
ob_start();
|
28 |
-
$dox->paintCaseStart('SomeGreatWidgetTest');
|
29 |
-
$buffer = ob_get_clean();
|
30 |
-
$this->assertPattern('/^SomeGreatWidget/', $buffer);
|
31 |
-
}
|
32 |
-
|
33 |
-
function testIfTest_case_patternIsEmptyAssumeEverythingMatches() {
|
34 |
-
$dox = new TestDoxReporter('');
|
35 |
-
ob_start();
|
36 |
-
$dox->paintCaseStart('TestOfTestDoxReporter');
|
37 |
-
$buffer = ob_get_clean();
|
38 |
-
$this->assertPattern('/^TestOfTestDoxReporter/', $buffer);
|
39 |
-
}
|
40 |
-
|
41 |
-
function testEmptyLineInsertedWhenCaseEnds() {
|
42 |
-
$dox = new TestDoxReporter();
|
43 |
-
ob_start();
|
44 |
-
$dox->paintCaseEnd('TestOfTestDoxReporter');
|
45 |
-
$buffer = ob_get_clean();
|
46 |
-
$this->assertEqual("\n", $buffer);
|
47 |
-
}
|
48 |
-
|
49 |
-
function testPaintsTestMethodInTestDoxFormat() {
|
50 |
-
$dox = new TestDoxReporter();
|
51 |
-
ob_start();
|
52 |
-
$dox->paintMethodStart('testSomeGreatTestCase');
|
53 |
-
$buffer = ob_get_clean();
|
54 |
-
$this->assertEqual("- some great test case", $buffer);
|
55 |
-
unset($buffer);
|
56 |
-
|
57 |
-
$random = rand(100, 200);
|
58 |
-
ob_start();
|
59 |
-
$dox->paintMethodStart("testRandomNumberIs{$random}");
|
60 |
-
$buffer = ob_get_clean();
|
61 |
-
$this->assertEqual("- random number is {$random}", $buffer);
|
62 |
-
}
|
63 |
-
|
64 |
-
function testDoesNotOutputAnythingOnNoneTestMethods() {
|
65 |
-
$dox = new TestDoxReporter();
|
66 |
-
ob_start();
|
67 |
-
$dox->paintMethodStart('nonMatchingMethod');
|
68 |
-
$buffer = ob_get_clean();
|
69 |
-
$this->assertEqual('', $buffer);
|
70 |
-
}
|
71 |
-
|
72 |
-
function testPaintMethodAddLineBreak() {
|
73 |
-
$dox = new TestDoxReporter();
|
74 |
-
ob_start();
|
75 |
-
$dox->paintMethodEnd('someMethod');
|
76 |
-
$buffer = ob_get_clean();
|
77 |
-
$this->assertEqual("\n", $buffer);
|
78 |
-
}
|
79 |
-
|
80 |
-
function testProperlySpacesSingleLettersInMethodName() {
|
81 |
-
$dox = new TestDoxReporter();
|
82 |
-
ob_start();
|
83 |
-
$dox->paintMethodStart('testAVerySimpleAgainAVerySimpleMethod');
|
84 |
-
$buffer = ob_get_clean();
|
85 |
-
$this->assertEqual('- a very simple again a very simple method', $buffer);
|
86 |
-
}
|
87 |
-
|
88 |
-
function testOnFailureThisPrintsFailureNotice() {
|
89 |
-
$dox = new TestDoxReporter();
|
90 |
-
ob_start();
|
91 |
-
$dox->paintFail('');
|
92 |
-
$buffer = ob_get_clean();
|
93 |
-
$this->assertEqual(' [FAILED]', $buffer);
|
94 |
-
}
|
95 |
-
|
96 |
-
function testWhenMatchingMethodNamesTestPrefixIsCaseInsensitive() {
|
97 |
-
$dox = new TestDoxReporter();
|
98 |
-
ob_start();
|
99 |
-
$dox->paintMethodStart('TESTSupportsAllUppercaseTestPrefixEvenThoughIDoNotKnowWhyYouWouldDoThat');
|
100 |
-
$buffer = ob_get_clean();
|
101 |
-
$this->assertEqual(
|
102 |
-
'- supports all uppercase test prefix even though i do not know why you would do that',
|
103 |
-
$buffer
|
104 |
-
);
|
105 |
-
}
|
106 |
-
}
|
107 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/form.php
DELETED
@@ -1,361 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Base include file for SimpleTest.
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage WebTester
|
6 |
-
* @version $Id: form.php 2013 2011-04-29 09:29:45Z pp11 $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**#@+
|
10 |
-
* include SimpleTest files
|
11 |
-
*/
|
12 |
-
require_once(dirname(__FILE__) . '/tag.php');
|
13 |
-
require_once(dirname(__FILE__) . '/encoding.php');
|
14 |
-
require_once(dirname(__FILE__) . '/selector.php');
|
15 |
-
/**#@-*/
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Form tag class to hold widget values.
|
19 |
-
* @package SimpleTest
|
20 |
-
* @subpackage WebTester
|
21 |
-
*/
|
22 |
-
class SimpleForm {
|
23 |
-
private $method;
|
24 |
-
private $action;
|
25 |
-
private $encoding;
|
26 |
-
private $default_target;
|
27 |
-
private $id;
|
28 |
-
private $buttons;
|
29 |
-
private $images;
|
30 |
-
private $widgets;
|
31 |
-
private $radios;
|
32 |
-
private $checkboxes;
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Starts with no held controls/widgets.
|
36 |
-
* @param SimpleTag $tag Form tag to read.
|
37 |
-
* @param SimplePage $page Holding page.
|
38 |
-
*/
|
39 |
-
function __construct($tag, $page) {
|
40 |
-
$this->method = $tag->getAttribute('method');
|
41 |
-
$this->action = $this->createAction($tag->getAttribute('action'), $page);
|
42 |
-
$this->encoding = $this->setEncodingClass($tag);
|
43 |
-
$this->default_target = false;
|
44 |
-
$this->id = $tag->getAttribute('id');
|
45 |
-
$this->buttons = array();
|
46 |
-
$this->images = array();
|
47 |
-
$this->widgets = array();
|
48 |
-
$this->radios = array();
|
49 |
-
$this->checkboxes = array();
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Creates the request packet to be sent by the form.
|
54 |
-
* @param SimpleTag $tag Form tag to read.
|
55 |
-
* @return string Packet class.
|
56 |
-
* @access private
|
57 |
-
*/
|
58 |
-
protected function setEncodingClass($tag) {
|
59 |
-
if (strtolower($tag->getAttribute('method')) == 'post') {
|
60 |
-
if (strtolower($tag->getAttribute('enctype')) == 'multipart/form-data') {
|
61 |
-
return 'SimpleMultipartEncoding';
|
62 |
-
}
|
63 |
-
return 'SimplePostEncoding';
|
64 |
-
}
|
65 |
-
return 'SimpleGetEncoding';
|
66 |
-
}
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Sets the frame target within a frameset.
|
70 |
-
* @param string $frame Name of frame.
|
71 |
-
* @access public
|
72 |
-
*/
|
73 |
-
function setDefaultTarget($frame) {
|
74 |
-
$this->default_target = $frame;
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Accessor for method of form submission.
|
79 |
-
* @return string Either get or post.
|
80 |
-
* @access public
|
81 |
-
*/
|
82 |
-
function getMethod() {
|
83 |
-
return ($this->method ? strtolower($this->method) : 'get');
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Combined action attribute with current location
|
88 |
-
* to get an absolute form target.
|
89 |
-
* @param string $action Action attribute from form tag.
|
90 |
-
* @param SimpleUrl $base Page location.
|
91 |
-
* @return SimpleUrl Absolute form target.
|
92 |
-
*/
|
93 |
-
protected function createAction($action, $page) {
|
94 |
-
if (($action === '') || ($action === false)) {
|
95 |
-
return $page->expandUrl($page->getUrl());
|
96 |
-
}
|
97 |
-
return $page->expandUrl(new SimpleUrl($action));;
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Absolute URL of the target.
|
102 |
-
* @return SimpleUrl URL target.
|
103 |
-
* @access public
|
104 |
-
*/
|
105 |
-
function getAction() {
|
106 |
-
$url = $this->action;
|
107 |
-
if ($this->default_target && ! $url->getTarget()) {
|
108 |
-
$url->setTarget($this->default_target);
|
109 |
-
}
|
110 |
-
if ($this->getMethod() == 'get') {
|
111 |
-
$url->clearRequest();
|
112 |
-
}
|
113 |
-
return $url;
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Creates the encoding for the current values in the
|
118 |
-
* form.
|
119 |
-
* @return SimpleFormEncoding Request to submit.
|
120 |
-
* @access private
|
121 |
-
*/
|
122 |
-
protected function encode() {
|
123 |
-
$class = $this->encoding;
|
124 |
-
$encoding = new $class();
|
125 |
-
for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {
|
126 |
-
$this->widgets[$i]->write($encoding);
|
127 |
-
}
|
128 |
-
return $encoding;
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* ID field of form for unique identification.
|
133 |
-
* @return string Unique tag ID.
|
134 |
-
* @access public
|
135 |
-
*/
|
136 |
-
function getId() {
|
137 |
-
return $this->id;
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Adds a tag contents to the form.
|
142 |
-
* @param SimpleWidget $tag Input tag to add.
|
143 |
-
*/
|
144 |
-
function addWidget($tag) {
|
145 |
-
if (strtolower($tag->getAttribute('type')) == 'submit') {
|
146 |
-
$this->buttons[] = $tag;
|
147 |
-
} elseif (strtolower($tag->getAttribute('type')) == 'image') {
|
148 |
-
$this->images[] = $tag;
|
149 |
-
} elseif ($tag->getName()) {
|
150 |
-
$this->setWidget($tag);
|
151 |
-
}
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* Sets the widget into the form, grouping radio
|
156 |
-
* buttons if any.
|
157 |
-
* @param SimpleWidget $tag Incoming form control.
|
158 |
-
* @access private
|
159 |
-
*/
|
160 |
-
protected function setWidget($tag) {
|
161 |
-
if (strtolower($tag->getAttribute('type')) == 'radio') {
|
162 |
-
$this->addRadioButton($tag);
|
163 |
-
} elseif (strtolower($tag->getAttribute('type')) == 'checkbox') {
|
164 |
-
$this->addCheckbox($tag);
|
165 |
-
} else {
|
166 |
-
$this->widgets[] = &$tag;
|
167 |
-
}
|
168 |
-
}
|
169 |
-
|
170 |
-
/**
|
171 |
-
* Adds a radio button, building a group if necessary.
|
172 |
-
* @param SimpleRadioButtonTag $tag Incoming form control.
|
173 |
-
* @access private
|
174 |
-
*/
|
175 |
-
protected function addRadioButton($tag) {
|
176 |
-
if (! isset($this->radios[$tag->getName()])) {
|
177 |
-
$this->widgets[] = new SimpleRadioGroup();
|
178 |
-
$this->radios[$tag->getName()] = count($this->widgets) - 1;
|
179 |
-
}
|
180 |
-
$this->widgets[$this->radios[$tag->getName()]]->addWidget($tag);
|
181 |
-
}
|
182 |
-
|
183 |
-
/**
|
184 |
-
* Adds a checkbox, making it a group on a repeated name.
|
185 |
-
* @param SimpleCheckboxTag $tag Incoming form control.
|
186 |
-
* @access private
|
187 |
-
*/
|
188 |
-
protected function addCheckbox($tag) {
|
189 |
-
if (! isset($this->checkboxes[$tag->getName()])) {
|
190 |
-
$this->widgets[] = $tag;
|
191 |
-
$this->checkboxes[$tag->getName()] = count($this->widgets) - 1;
|
192 |
-
} else {
|
193 |
-
$index = $this->checkboxes[$tag->getName()];
|
194 |
-
if (! SimpleTestCompatibility::isA($this->widgets[$index], 'SimpleCheckboxGroup')) {
|
195 |
-
$previous = $this->widgets[$index];
|
196 |
-
$this->widgets[$index] = new SimpleCheckboxGroup();
|
197 |
-
$this->widgets[$index]->addWidget($previous);
|
198 |
-
}
|
199 |
-
$this->widgets[$index]->addWidget($tag);
|
200 |
-
}
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Extracts current value from form.
|
205 |
-
* @param SimpleSelector $selector Criteria to apply.
|
206 |
-
* @return string/array Value(s) as string or null
|
207 |
-
* if not set.
|
208 |
-
* @access public
|
209 |
-
*/
|
210 |
-
function getValue($selector) {
|
211 |
-
for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {
|
212 |
-
if ($selector->isMatch($this->widgets[$i])) {
|
213 |
-
return $this->widgets[$i]->getValue();
|
214 |
-
}
|
215 |
-
}
|
216 |
-
foreach ($this->buttons as $button) {
|
217 |
-
if ($selector->isMatch($button)) {
|
218 |
-
return $button->getValue();
|
219 |
-
}
|
220 |
-
}
|
221 |
-
return null;
|
222 |
-
}
|
223 |
-
|
224 |
-
/**
|
225 |
-
* Sets a widget value within the form.
|
226 |
-
* @param SimpleSelector $selector Criteria to apply.
|
227 |
-
* @param string $value Value to input into the widget.
|
228 |
-
* @return boolean True if value is legal, false
|
229 |
-
* otherwise. If the field is not
|
230 |
-
* present, nothing will be set.
|
231 |
-
* @access public
|
232 |
-
*/
|
233 |
-
function setField($selector, $value, $position=false) {
|
234 |
-
$success = false;
|
235 |
-
$_position = 0;
|
236 |
-
for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {
|
237 |
-
if ($selector->isMatch($this->widgets[$i])) {
|
238 |
-
$_position++;
|
239 |
-
if ($position === false or $_position === (int)$position) {
|
240 |
-
if ($this->widgets[$i]->setValue($value)) {
|
241 |
-
$success = true;
|
242 |
-
}
|
243 |
-
}
|
244 |
-
}
|
245 |
-
}
|
246 |
-
return $success;
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* Used by the page object to set widgets labels to
|
251 |
-
* external label tags.
|
252 |
-
* @param SimpleSelector $selector Criteria to apply.
|
253 |
-
* @access public
|
254 |
-
*/
|
255 |
-
function attachLabelBySelector($selector, $label) {
|
256 |
-
for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {
|
257 |
-
if ($selector->isMatch($this->widgets[$i])) {
|
258 |
-
if (method_exists($this->widgets[$i], 'setLabel')) {
|
259 |
-
$this->widgets[$i]->setLabel($label);
|
260 |
-
return;
|
261 |
-
}
|
262 |
-
}
|
263 |
-
}
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* Test to see if a form has a submit button.
|
268 |
-
* @param SimpleSelector $selector Criteria to apply.
|
269 |
-
* @return boolean True if present.
|
270 |
-
* @access public
|
271 |
-
*/
|
272 |
-
function hasSubmit($selector) {
|
273 |
-
foreach ($this->buttons as $button) {
|
274 |
-
if ($selector->isMatch($button)) {
|
275 |
-
return true;
|
276 |
-
}
|
277 |
-
}
|
278 |
-
return false;
|
279 |
-
}
|
280 |
-
|
281 |
-
/**
|
282 |
-
* Test to see if a form has an image control.
|
283 |
-
* @param SimpleSelector $selector Criteria to apply.
|
284 |
-
* @return boolean True if present.
|
285 |
-
* @access public
|
286 |
-
*/
|
287 |
-
function hasImage($selector) {
|
288 |
-
foreach ($this->images as $image) {
|
289 |
-
if ($selector->isMatch($image)) {
|
290 |
-
return true;
|
291 |
-
}
|
292 |
-
}
|
293 |
-
return false;
|
294 |
-
}
|
295 |
-
|
296 |
-
/**
|
297 |
-
* Gets the submit values for a selected button.
|
298 |
-
* @param SimpleSelector $selector Criteria to apply.
|
299 |
-
* @param hash $additional Additional data for the form.
|
300 |
-
* @return SimpleEncoding Submitted values or false
|
301 |
-
* if there is no such button
|
302 |
-
* in the form.
|
303 |
-
* @access public
|
304 |
-
*/
|
305 |
-
function submitButton($selector, $additional = false) {
|
306 |
-
$additional = $additional ? $additional : array();
|
307 |
-
foreach ($this->buttons as $button) {
|
308 |
-
if ($selector->isMatch($button)) {
|
309 |
-
$encoding = $this->encode();
|
310 |
-
$button->write($encoding);
|
311 |
-
if ($additional) {
|
312 |
-
$encoding->merge($additional);
|
313 |
-
}
|
314 |
-
return $encoding;
|
315 |
-
}
|
316 |
-
}
|
317 |
-
return false;
|
318 |
-
}
|
319 |
-
|
320 |
-
/**
|
321 |
-
* Gets the submit values for an image.
|
322 |
-
* @param SimpleSelector $selector Criteria to apply.
|
323 |
-
* @param integer $x X-coordinate of click.
|
324 |
-
* @param integer $y Y-coordinate of click.
|
325 |
-
* @param hash $additional Additional data for the form.
|
326 |
-
* @return SimpleEncoding Submitted values or false
|
327 |
-
* if there is no such button in the
|
328 |
-
* form.
|
329 |
-
* @access public
|
330 |
-
*/
|
331 |
-
function submitImage($selector, $x, $y, $additional = false) {
|
332 |
-
$additional = $additional ? $additional : array();
|
333 |
-
foreach ($this->images as $image) {
|
334 |
-
if ($selector->isMatch($image)) {
|
335 |
-
$encoding = $this->encode();
|
336 |
-
$image->write($encoding, $x, $y);
|
337 |
-
if ($additional) {
|
338 |
-
$encoding->merge($additional);
|
339 |
-
}
|
340 |
-
return $encoding;
|
341 |
-
}
|
342 |
-
}
|
343 |
-
return false;
|
344 |
-
}
|
345 |
-
|
346 |
-
/**
|
347 |
-
* Simply submits the form without the submit button
|
348 |
-
* value. Used when there is only one button or it
|
349 |
-
* is unimportant.
|
350 |
-
* @return hash Submitted values.
|
351 |
-
* @access public
|
352 |
-
*/
|
353 |
-
function submit($additional = false) {
|
354 |
-
$encoding = $this->encode();
|
355 |
-
if ($additional) {
|
356 |
-
$encoding->merge($additional);
|
357 |
-
}
|
358 |
-
return $encoding;
|
359 |
-
}
|
360 |
-
}
|
361 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpsc-components/merchant-core-v3/gateways/php-merchant/tests/simpletest/frames.php
DELETED
@@ -1,592 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Base include file for SimpleTest
|
4 |
-
* @package SimpleTest
|
5 |
-
* @subpackage WebTester
|
6 |
-
* @version $Id: frames.php 1784 2008-04-26 13:07:14Z pp11 $
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**#@+
|
10 |
-
* include other SimpleTest class files
|
11 |
-
*/
|
12 |
-
require_once(dirname(__FILE__) . '/page.php');
|
13 |
-
require_once(dirname(__FILE__) . '/user_agent.php');
|
14 |
-
/**#@-*/
|
15 |
-
|
16 |
-
/**
|
17 |
-
* A composite page. Wraps a frameset page and
|
18 |
-
* adds subframes. The original page will be
|
19 |
-
* mostly ignored. Implements the SimplePage
|
20 |
-
* interface so as to be interchangeable.
|
21 |
-
* @package SimpleTest
|
22 |
-
* @subpackage WebTester
|
23 |
-
*/
|
24 |
-
class SimpleFrameset {
|
25 |
-
private $frameset;
|
26 |
-
private $frames;
|
27 |
-
private $focus;
|
28 |
-
private $names;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Stashes the frameset page. Will make use of the
|
32 |
-
* browser to fetch the sub frames recursively.
|
33 |
-
* @param SimplePage $page Frameset page.
|
34 |
-
*/
|
35 |
-
function __construct($page) {
|
36 |
-
$this->frameset = $page;
|
37 |
-
$this->frames = array();
|
38 |
-
$this->focus = false;
|
39 |
-
$this->names = array();
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Adds a parsed page to the frameset.
|
44 |
-
* @param SimplePage $page Frame page.
|
45 |
-
* @param string $name Name of frame in frameset.
|
46 |
-
* @access public
|
47 |
-
*/
|
48 |
-
function addFrame($page, $name = false) {
|
49 |
-
$this->frames[] = $page;
|
50 |
-
if ($name) {
|
51 |
-
$this->names[$name] = count($this->frames) - 1;
|
52 |
-
}
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Replaces existing frame with another. If the
|
57 |
-
* frame is nested, then the call is passed down
|
58 |
-
* one level.
|
59 |
-
* @param array $path Path of frame in frameset.
|
60 |
-
* @param SimplePage $page Frame source.
|
61 |
-
* @access public
|
62 |
-
*/
|
63 |
-
function setFrame($path, $page) {
|
64 |
-
$name = array_shift($path);
|
65 |
-
if (isset($this->names[$name])) {
|
66 |
-
$index = $this->names[$name];
|
67 |
-
} else {
|
68 |
-
$index = $name - 1;
|
69 |
-
}
|
70 |
-
if (count($path) == 0) {
|
71 |
-
$this->frames[$index] = &$page;
|
72 |
-
return;
|
73 |
-
}
|
74 |
-
$this->frames[$index]->setFrame($path, $page);
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Accessor for current frame focus. Will be
|
79 |
-
* false if no frame has focus. Will have the nested
|
80 |
-
* frame focus if any.
|
81 |
-
* @return array Labels or indexes of nested frames.
|
82 |
-
* @access public
|
83 |
-
*/
|
84 |
-
function getFrameFocus() {
|
85 |
-
if ($this->focus === false) {
|
86 |
-
return array();
|
87 |
-
}
|
88 |
-
return array_merge(
|
89 |
-
array($this->getPublicNameFromIndex($this->focus)),
|
90 |
-
$this->frames[$this->focus]->getFrameFocus());
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Turns an internal array index into the frames list
|
95 |
-
* into a public name, or if none, then a one offset
|
96 |
-
* index.
|
97 |
-
* @param integer $subject Internal index.
|
98 |
-
* @return integer/string Public name.
|
99 |
-
* @access private
|
100 |
-
*/
|
101 |
-
protected function getPublicNameFromIndex($subject) {
|
102 |
-
foreach ($this->names as $name => $index) {
|
103 |
-
if ($subject == $index) {
|
104 |
-
return $name;
|
105 |
-
}
|
106 |
-
}
|
107 |
-
return $subject + 1;
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Sets the focus by index. The integer index starts from 1.
|
112 |
-
* If already focused and the target frame also has frames,
|
113 |
-
* then the nested frame will be focused.
|
114 |
-
* @param integer $choice Chosen frame.
|
115 |
-
* @return boolean True if frame exists.
|
116 |
-
* @access public
|
117 |
-
*/
|
118 |
-
function setFrameFocusByIndex($choice) {
|
119 |
-
if (is_integer($this->focus)) {
|
120 |
-
if ($this->frames[$this->focus]->hasFrames()) {
|
121 |
-
return $this->frames[$this->focus]->setFrameFocusByIndex($choice);
|
122 |
-
}
|
123 |
-
}
|
124 |
-
if (($choice < 1) || ($choice > count($this->frames))) {
|
125 |
-
return false;
|
126 |
-
}
|
127 |
-
$this->focus = $choice - 1;
|
128 |
-
return true;
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Sets the focus by name. If already focused and the
|
133 |
-
* target frame also has frames, then the nested frame
|
134 |
-
* will be focused.
|
135 |
-
* @param string $name Chosen frame.
|
136 |
-
* @return boolean True if frame exists.
|
137 |
-
* @access public
|
138 |
-
*/
|
139 |
-
function setFrameFocus($name) {
|
140 |
-
if (is_integer($this->focus)) {
|
141 |
-
if ($this->frames[$this->focus]->hasFrames()) {
|
142 |
-
return $this->frames[$this->focus]->setFrameFocus($name);
|
143 |
-
}
|
144 |
-
}
|
145 |
-
if (in_array($name, array_keys($this->names))) {
|
146 |
-
$this->focus = $this->names[$name];
|
147 |
-
return true;
|
148 |
-
}
|
149 |
-
return false;
|
150 |
-
}
|
151 |
-
|
152 |
-
/**
|
153 |
-
* Clears the frame focus.
|
154 |
-
* @access public
|
155 |
-
*/
|
156 |
-
function clearFrameFocus() {
|
157 |
-
$this->focus = false;
|
158 |
-
$this->clearNestedFramesFocus();
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* Clears the frame focus for any nested frames.
|
163 |
-
* @access private
|
164 |
-
*/
|
165 |
-
protected function clearNestedFramesFocus() {
|
166 |
-
for ($i = 0; $i < count($this->frames); $i++) {
|
167 |
-
$this->frames[$i]->clearFrameFocus();
|
168 |
-
}
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Test for the presence of a frameset.
|
173 |
-
* @return boolean Always true.
|
174 |
-
* @access public
|
175 |
-
*/
|
176 |
-
function hasFrames() {
|
177 |
-
return true;
|
178 |
-
}
|
179 |
-
|
180 |
-
/**
|
181 |
-
* Accessor for frames information.
|
182 |
-
* @return array/string Recursive hash of frame URL strings.
|
183 |
-
* The key is either a numerical
|
184 |
-
* index or the name attribute.
|
185 |
-
* @access public
|
186 |
-
*/
|
187 |
-
function getFrames() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|