|
| 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 | +// } |
0 commit comments