@@ 1135-1150 (lines=16) @@ | ||
1132 | * |
|
1133 | * @since 9.9.0 |
|
1134 | */ |
|
1135 | public function test_get_purchase_token() { |
|
1136 | $purchase_token = '1ApurchaseToken1'; |
|
1137 | Jetpack_Options::update_option( 'id', 1234 ); |
|
1138 | Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
|
1139 | ||
1140 | // Create a user and set it up as current. |
|
1141 | $user = $this->create_and_get_user( 'administrator' ); |
|
1142 | wp_set_current_user( $user->ID ); |
|
1143 | ||
1144 | // Fetch purchase token. |
|
1145 | $response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
|
1146 | ||
1147 | // Confirm purchase token exists. |
|
1148 | $this->assertResponseStatus( 200, $response ); |
|
1149 | $this->assertEquals( $purchase_token, $response->get_data() ); |
|
1150 | } |
|
1151 | ||
1152 | /** |
|
1153 | * Test fetching a site's purchase token with a non-administrator user. |
|
@@ 1157-1172 (lines=16) @@ | ||
1154 | * |
|
1155 | * @since 9.9.0 |
|
1156 | */ |
|
1157 | public function test_get_purchase_token_non_admin_user() { |
|
1158 | $purchase_token = '1ApurchaseToken1'; |
|
1159 | Jetpack_Options::update_option( 'id', 1234 ); |
|
1160 | Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
|
1161 | ||
1162 | // Create a user and set it up as current. |
|
1163 | $user = $this->create_and_get_user(); |
|
1164 | wp_set_current_user( $user->ID ); |
|
1165 | ||
1166 | // Fetch purchase token. |
|
1167 | $response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
|
1168 | ||
1169 | // Request fails because the user doesn't have the `manage_options` permission. |
|
1170 | $this->assertResponseStatus( 403, $response ); |
|
1171 | $this->assertResponseData( array( 'code' => 'invalid_permission_manage_purchase_token' ), $response ); |
|
1172 | } |
|
1173 | ||
1174 | /** |
|
1175 | * Test fetching a site's purchase token when no site is registered. |
|
@@ 1179-1193 (lines=15) @@ | ||
1176 | * |
|
1177 | * @since 9.9.0 |
|
1178 | */ |
|
1179 | public function test_get_purchase_token_no_site_registered() { |
|
1180 | $purchase_token = '1ApurchaseToken1'; |
|
1181 | Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
|
1182 | ||
1183 | // Create a user and set it up as current. |
|
1184 | $user = $this->create_and_get_user( 'administrator' ); |
|
1185 | wp_set_current_user( $user->ID ); |
|
1186 | ||
1187 | // Fetch purchase token. |
|
1188 | $response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
|
1189 | ||
1190 | // Confirm that the request failed. |
|
1191 | $this->assertResponseStatus( 500, $response ); |
|
1192 | $this->assertResponseData( array( 'code' => 'site_not_registered' ), $response ); |
|
1193 | } |
|
1194 | ||
1195 | /** |
|
1196 | * Test deleting a site's purchase token. |
|
@@ 1235-1250 (lines=16) @@ | ||
1232 | * |
|
1233 | * @since 9.9.0 |
|
1234 | */ |
|
1235 | public function test_delete_purchase_token_non_admin_user() { |
|
1236 | $purchase_token = '1ApurchaseToken1'; |
|
1237 | Jetpack_Options::update_option( 'id', 1234 ); |
|
1238 | Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
|
1239 | ||
1240 | // Create a user and set it up as current. |
|
1241 | $user = $this->create_and_get_user(); |
|
1242 | wp_set_current_user( $user->ID ); |
|
1243 | ||
1244 | // Fetch the purchase token. |
|
1245 | $response = $this->create_and_get_request( 'purchase-token', array(), 'GET' ); |
|
1246 | ||
1247 | // Request fails because the user doesn't have the `manage_options` permission. |
|
1248 | $this->assertResponseStatus( 403, $response ); |
|
1249 | $this->assertResponseData( array( 'code' => 'invalid_permission_manage_purchase_token' ), $response ); |
|
1250 | } |
|
1251 | ||
1252 | /** |
|
1253 | * Test deleting a site's purchase token when no site is registered. |
|
@@ 1257-1271 (lines=15) @@ | ||
1254 | * |
|
1255 | * @since 9.9.0 |
|
1256 | */ |
|
1257 | public function test_delete_purchase_token_no_site_registered() { |
|
1258 | $purchase_token = '1ApurchaseToken1'; |
|
1259 | Jetpack_Options::update_option( 'purchase_token', $purchase_token ); |
|
1260 | ||
1261 | // Create a user and set it up as current. |
|
1262 | $user = $this->create_and_get_user( 'administrator' ); |
|
1263 | wp_set_current_user( $user->ID ); |
|
1264 | ||
1265 | // Fetch purchase token. |
|
1266 | $response = $this->create_and_get_request( 'purchase-token', array(), 'POST' ); |
|
1267 | ||
1268 | // Confirm that the request failed. |
|
1269 | $this->assertResponseStatus( 500, $response ); |
|
1270 | $this->assertResponseData( array( 'code' => 'site_not_registered' ), $response ); |
|
1271 | } |
|
1272 | } // class end |
|
1273 |