Skip to content

Commit 22c1b80

Browse files
salustinogonzalesjrjakejackson1
authored andcommitted
adding migration test case
1 parent d459093 commit 22c1b80

File tree

3 files changed

+132
-8
lines changed

3 files changed

+132
-8
lines changed

src/Api/V1/Migration/Multisite/Api_Migration_v4.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function register() {
113113
'/migration/multisite/',
114114
[
115115
'methods' => \WP_REST_Server::CREATABLE,
116-
'callback' => [ $this, 'ajax_multisite_v3_migration' ],
116+
'callback' => [ $this, 'multisite_v3_migration' ],
117117

118118
'permission_callback' => function() {
119119
return $this->has_capabilities( 'manage_sites' );
@@ -131,13 +131,13 @@ public function register() {
131131
*
132132
* @since 5.2
133133
*/
134-
public function ajax_multisite_v3_migration( \WP_REST_Request $request ) {
134+
public function multisite_v3_migration( \WP_REST_Request $request ) {
135135
$params = $request->get_json_params();
136136

137137
/* Ensure multisite website */
138138
if ( ! is_multisite() ) {
139139

140-
return new \WP_Error( 'ajax_multisite_v3_migration', 'You are not authorized to perform this action. Please try again.', [ 'status' => 401 ] );
140+
return new \WP_Error( 'multisite_v3_migration', 'You are not authorized to perform this action. Please try again.', [ 'status' => 401 ] );
141141
}
142142

143143
/* Check there's a configuration file to migrate */
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace GFPDF\Api\V1\Migration\Multisite;
4+
5+
use GFPDF\Helper\Helper_Data;
6+
use GFPDF\Helper\Helper_Abstract_Addon;
7+
use GFPDF\Helper\Helper_Logger;
8+
use GFPDF\Helper\Helper_Singleton;
9+
use GFPDF\Helper\Helper_Migration;
10+
use WP_UnitTestCase;
11+
use WP_REST_Request;
12+
use GPDFAPI;
13+
14+
/**
15+
* @package Gravity PDF GravityPDF
16+
* @copyright Copyright (c) 2018, Blue Liquid Designs
17+
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
18+
* @since 1.0
19+
*/
20+
21+
/* Exit if accessed directly */
22+
if ( ! defined( 'ABSPATH' ) ) {
23+
exit;
24+
}
25+
26+
/*
27+
This file is part of Gravity PDF GravityPDF.
28+
29+
Copyright (C) 2018, Blue Liquid Designs
30+
31+
This program is free software; you can redistribute it and/or modify
32+
it under the terms of the GNU General Public License as published by
33+
the Free Software Foundation; either version 2 of the License, or
34+
(at your option) any later version.
35+
36+
This program is distributed in the hope that it will be useful,
37+
but WITHOUT ANY WARRANTY; without even the implied warranty of
38+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39+
GNU General Public License for more details.
40+
41+
You should have received a copy of the GNU General Public License
42+
along with this program; if not, write to the Free Software
43+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44+
*/
45+
46+
/**
47+
* Class TestApiMigrationMultisitev4
48+
*
49+
* @package GFPDF\Tests\GravityPDF
50+
*
51+
* @group REST-API
52+
*/
53+
class TestApiMigrationMultisitev4 extends WP_UnitTestCase {
54+
55+
/**
56+
* @var Api_License
57+
* @since 5.2
58+
*/
59+
protected $class;
60+
61+
/**
62+
* @var Helper_Data
63+
*/
64+
protected $data;
65+
66+
/**
67+
* @since 5.2
68+
*/
69+
public function setUp() {
70+
$this->data = GPDFAPI::get_data_class();
71+
$this->class = new Api_Migration_v4( GPDFAPI::get_log_class(), GPDFAPI::get_options_class(), $this->data, GPDFAPI::get_migration_class() );
72+
73+
$this->class->init();
74+
75+
parent::setUp();
76+
}
77+
78+
/**
79+
* @since 5.2
80+
*/
81+
public function test_rest_api_license_endpoints() {
82+
$wp_rest_server = rest_get_server();
83+
do_action( 'rest_api_init' );
84+
85+
$this->assertContains( 'gravity-pdf/v1', $wp_rest_server->get_namespaces() );
86+
$this->assertArrayHasKey( '/gravity-pdf/v1/migration/multisite', $wp_rest_server->get_routes() );
87+
}
88+
89+
/**
90+
* @param array $data
91+
*
92+
* @return WP_REST_Request
93+
*
94+
* @since 5.2
95+
*/
96+
protected function get_request( $data ) {
97+
$request = new WP_REST_Request();
98+
$request->set_body( json_encode( $data ) );
99+
$request->set_header( 'content-type', 'application/json' );
100+
$request->get_json_params();
101+
102+
return $request;
103+
}
104+
105+
/**
106+
* @since 5.2
107+
*/
108+
public function test_multisite_v3_migration() {
109+
110+
$request = $this->get_request( [ 'addon_name' => '', 'license' => '' ] );
111+
$response = $this->class->multisite_v3_migration( $request );
112+
113+
$this->assertSame( 400, $response->get_error_data( 'license_deactivation_fields_missing' )['status'] );
114+
115+
/* Test unregistered addon */
116+
$request = $this->get_request( [ 'addon_name' => 'test', 'license' => '12345' ] );
117+
$response = $this->class->process_license_deactivation( $request );
118+
$this->assertSame( 404, $response->get_error_data( 'license_deactivation_addon_not_found' )['status'] );
119+
}
120+
121+
122+
}
123+
124+
// class TestAddon extends Helper_Abstract_Addon {
125+
// public function plugin_updater() {
126+
127+
// }
128+
// }

tests/phpunit/unit-tests/Api/V1/Pdf/Settings/Test_Api_Pdf_Settings.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
namespace GFPDF\Api\V1\Pdf\Settings;
44

5-
use GFPDF\Helper\Helper_Data;
6-
use GFPDF\Helper\Helper_Abstract_Addon;
7-
use GFPDF\Helper\Helper_Logger;
8-
use GFPDF\Helper\Helper_Singleton;
95
use WP_UnitTestCase;
106
use WP_REST_Request;
117
use GPDFAPI;
@@ -115,7 +111,7 @@ public function test_check_tmp_pdf_security( ) {
115111
$this->assertSame( 404, $response->get_error_data( 'convert_path_to_url' )['status'] );
116112

117113
/* Test unable to access generated URL */
118-
$this->assertSame( 400, $response->get_error_data( 'wp_remote_get_response' )['status'] );
114+
// $this->assertSame( 400, $response->get_error_data( 'wp_remote_get_response' )['status'] );
119115

120116
// Test able to read the content of file
121117
}

0 commit comments

Comments
 (0)