|
@@ 1093-1108 (lines=16) @@
|
| 1090 |
|
* |
| 1091 |
|
* @since 9.9.0 |
| 1092 |
|
*/ |
| 1093 |
|
public function test_get_purchase_token() { |
| 1094 |
|
$purchase_token = '1ApurchaseToken1'; |
| 1095 |
|
Jetpack_Options::update_option( 'id', 1234 ); |
| 1096 |
|
Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
| 1097 |
|
|
| 1098 |
|
// Create a user and set it up as current. |
| 1099 |
|
$user = $this->create_and_get_user( 'administrator' ); |
| 1100 |
|
wp_set_current_user( $user->ID ); |
| 1101 |
|
|
| 1102 |
|
// Fetch purchase token. |
| 1103 |
|
$response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
| 1104 |
|
|
| 1105 |
|
// Confirm purchase token exists. |
| 1106 |
|
$this->assertResponseStatus( 200, $response ); |
| 1107 |
|
$this->assertEquals( $purchase_token, $response->get_data() ); |
| 1108 |
|
} |
| 1109 |
|
|
| 1110 |
|
/** |
| 1111 |
|
* Test fetching a site's purchase token with a non-administrator user. |
|
@@ 1115-1130 (lines=16) @@
|
| 1112 |
|
* |
| 1113 |
|
* @since 9.9.0 |
| 1114 |
|
*/ |
| 1115 |
|
public function test_get_purchase_token_non_admin_user() { |
| 1116 |
|
$purchase_token = '1ApurchaseToken1'; |
| 1117 |
|
Jetpack_Options::update_option( 'id', 1234 ); |
| 1118 |
|
Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
| 1119 |
|
|
| 1120 |
|
// Create a user and set it up as current. |
| 1121 |
|
$user = $this->create_and_get_user(); |
| 1122 |
|
wp_set_current_user( $user->ID ); |
| 1123 |
|
|
| 1124 |
|
// Fetch purchase token. |
| 1125 |
|
$response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
| 1126 |
|
|
| 1127 |
|
// Request fails because the user doesn't have the `manage_options` permission. |
| 1128 |
|
$this->assertResponseStatus( 403, $response ); |
| 1129 |
|
$this->assertResponseData( array( 'code' => 'invalid_permission_manage_purchase_token' ), $response ); |
| 1130 |
|
} |
| 1131 |
|
|
| 1132 |
|
/** |
| 1133 |
|
* Test fetching a site's purchase token when no site is registered. |
|
@@ 1137-1151 (lines=15) @@
|
| 1134 |
|
* |
| 1135 |
|
* @since 9.9.0 |
| 1136 |
|
*/ |
| 1137 |
|
public function test_get_purchase_token_no_site_registered() { |
| 1138 |
|
$purchase_token = '1ApurchaseToken1'; |
| 1139 |
|
Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
| 1140 |
|
|
| 1141 |
|
// Create a user and set it up as current. |
| 1142 |
|
$user = $this->create_and_get_user( 'administrator' ); |
| 1143 |
|
wp_set_current_user( $user->ID ); |
| 1144 |
|
|
| 1145 |
|
// Fetch purchase token. |
| 1146 |
|
$response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
| 1147 |
|
|
| 1148 |
|
// Confirm that the request failed. |
| 1149 |
|
$this->assertResponseStatus( 500, $response ); |
| 1150 |
|
$this->assertResponseData( array( 'code' => 'site_not_registered' ), $response ); |
| 1151 |
|
} |
| 1152 |
|
|
| 1153 |
|
/** |
| 1154 |
|
* Test deleting a site's purchase token. |
|
@@ 1193-1208 (lines=16) @@
|
| 1190 |
|
* |
| 1191 |
|
* @since 9.9.0 |
| 1192 |
|
*/ |
| 1193 |
|
public function test_delete_purchase_token_non_admin_user() { |
| 1194 |
|
$purchase_token = '1ApurchaseToken1'; |
| 1195 |
|
Jetpack_Options::update_option( 'id', 1234 ); |
| 1196 |
|
Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
| 1197 |
|
|
| 1198 |
|
// Create a user and set it up as current. |
| 1199 |
|
$user = $this->create_and_get_user(); |
| 1200 |
|
wp_set_current_user( $user->ID ); |
| 1201 |
|
|
| 1202 |
|
// Fetch the purchase token. |
| 1203 |
|
$response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
| 1204 |
|
|
| 1205 |
|
// Request fails because the user doesn't have the `manage_options` permission. |
| 1206 |
|
$this->assertResponseStatus( 403, $response ); |
| 1207 |
|
$this->assertResponseData( array( 'code' => 'invalid_permission_manage_purchase_token' ), $response ); |
| 1208 |
|
} |
| 1209 |
|
|
| 1210 |
|
/** |
| 1211 |
|
* Test deleting a site's purchase token when no site is registered. |
|
@@ 1215-1229 (lines=15) @@
|
| 1212 |
|
* |
| 1213 |
|
* @since 9.9.0 |
| 1214 |
|
*/ |
| 1215 |
|
public function test_delete_purchase_token_no_site_registered() { |
| 1216 |
|
$purchase_token = '1ApurchaseToken1'; |
| 1217 |
|
Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
| 1218 |
|
|
| 1219 |
|
// Create a user and set it up as current. |
| 1220 |
|
$user = $this->create_and_get_user( 'administrator' ); |
| 1221 |
|
wp_set_current_user( $user->ID ); |
| 1222 |
|
|
| 1223 |
|
// Fetch purchase token. |
| 1224 |
|
$response = $this->create_and_get_request( 'purchase-token', array(), 'POST' ); |
| 1225 |
|
|
| 1226 |
|
// Confirm that the request failed. |
| 1227 |
|
$this->assertResponseStatus( 500, $response ); |
| 1228 |
|
$this->assertResponseData( array( 'code' => 'site_not_registered' ), $response ); |
| 1229 |
|
} |
| 1230 |
|
} // class end |
| 1231 |
|
|