Skip to content

Commit 0f9114c

Browse files
add test case for api pdf settings
1 parent daa0bdd commit 0f9114c

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/Api/V1/Pdf/Settings/Api_Pdf_Settings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function check_tmp_pdf_security() {
134134
$site_url = $this->misc->convert_path_to_url( $this->template_font_location );
135135

136136
/* file found */
137-
if ( $site_url !== false ) {
137+
if ( $site_url !== null ) {
138138
$response = wp_remote_get( $site_url . $this->tmp_test_file );
139139

140140
/* Cleanup our test file */
@@ -166,7 +166,7 @@ public function check_tmp_pdf_security() {
166166
// return [ 'message' => 'Tmp file successfully created and not publicly accessible', 'has_access' => false ];
167167
return false;
168168
}
169-
/* Unable to get url */
169+
/* Unable to access url */
170170
return new WP_Error( 'wp_remote_get_response', 'Response Error', [ 'status' => 400 ] );
171171
}
172172
/* Unable to convert path to url */
@@ -195,7 +195,7 @@ public function create_public_tmp_directory_test_file() {
195195
return true;
196196
}
197197

198-
return new \WP_Error( 'test_public_tmp_directory_access', 'Unable to create tmp Directory', [ 'status' => 401 ] );
198+
return new \WP_Error( 'test_public_tmp_directortest_public_tmp_directory_accessy_access', 'Unable to create tmp Directory', [ 'status' => 401 ] );
199199

200200
}
201201

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class TestApiPdfSettings extends WP_UnitTestCase {
7676
*/
7777
public function setUp() {
7878

79-
$this->template_font_location = plugin_dir_path(__FILE__) . 'tmp/gravityforms/fonts/';
79+
// $this->template_font_location = 'tmp/gravityforms/fonts/';
8080

8181
// $this->data = GPDFAPI::get_data_class();
8282
$this->class = new Api_Pdf_Settings( GPDFAPI::get_log_class(), GPDFAPI::get_misc_class(), $this->template_font_location );
@@ -96,21 +96,35 @@ public function test_rest_api_license_endpoints() {
9696
$this->assertArrayHasKey( '/gravity-pdf/v1/pdf/settings', $wp_rest_server->get_routes() );
9797
}
9898

99+
99100
/**
100101
* @since 5.2
101102
*/
102-
public function test_check_tmp_pdf_security() {
103-
104-
/* Test unable to access directory */
105-
$response = $this->class->check_tmp_pdf_security();
103+
public function test_create_public_tmp_directory_test_file() {
104+
/* Test able to write to directory */
105+
$response = $this->class->create_public_tmp_directory_test_file();
106+
$this->assertTrue( $response );
106107

107-
$this->assertSame( 401, $response->get_error_data( 'test_public_tmp_directory_access' )['status'] );
108+
/* Test unable to write to directory */
109+
// $this->assertFileExists( $this->template_font_location . $this->tmp_test_file );
108110

109-
/* Test successful access on directory */
110-
// $request = $this->get_request( [ 'addon_name' => 'test', 'license' => '12345' ] );
111-
$response = $this->class->test_public_tmp_directory_access();
112-
$this->assertSame( 200, $response->get_error_data( 'test_public_tmp_directory_access' )['status'] );
113111
}
114112

113+
/**
114+
* @since 5.2
115+
*/
116+
public function test_check_tmp_pdf_security( ) {
117+
118+
$response = $this->class->check_tmp_pdf_security();
119+
120+
/* Test unable to conver path to URL */
121+
$this->assertSame( 404, $response->get_error_data( 'convert_path_to_url' )['status'] );
122+
123+
/* Test unable to access generated URL */
124+
$this->assertSame( 400, $response->get_error_data( 'wp_remote_get_response' )['status'] );
125+
126+
// Test able to read the content of file
127+
128+
}
115129

116130
}

tests/phpunit/unit-tests/Api/V1/Pdf/Settings/public_tmp_directory_test.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)