Skip to content

Commit

Permalink
Update tests for Main class.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Sep 7, 2021
1 parent f07f1c6 commit 774a018
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 71 deletions.
23 changes: 0 additions & 23 deletions src/php/class-request.php
Expand Up @@ -14,15 +14,6 @@
*/
class Request {

/**
* Is allowed request for plugin to work.
*
* @return bool
*/
public function is_allowed() {
return ! $this->is_frontend() || ( $this->is_frontend() && $this->is_post() );
}

/**
* Is frontend.
*
Expand Down Expand Up @@ -97,18 +88,4 @@ protected function get_rest_route() {

return $is_rest ? substr( $current_path, strlen( $rest_path ) ) : '';
}

/**
* If current request is POST.
*
* @return bool
*/
public function is_post() {
$request_method = filter_var(
isset( $_SERVER['REQUEST_METHOD'] ) ? wp_unslash( $_SERVER['REQUEST_METHOD'] ) : '',
FILTER_SANITIZE_STRING
);

return 'POST' === $request_method;
}
}
48 changes: 0 additions & 48 deletions tests/phpunit/tests/class-test-request.php
Expand Up @@ -33,38 +33,6 @@ public function tearDown(): void {
parent::tearDown();
}

/**
* Test is_allowed().
*
* @param bool $frontend Is frontend.
* @param bool $post Is POST.
* @param bool $expected Expected.
*
* @dataProvider dp_test_is_allowed
* @noinspection PhpUndefinedMethodInspection
*/
public function test_is_allowed( $frontend, $post, $expected ) {
$subject = Mockery::mock( Request::class )->makePartial()->shouldAllowMockingProtectedMethods();
$subject->shouldReceive( 'is_frontend' )->with()->andReturn( $frontend );
$subject->shouldReceive( 'is_post' )->with()->andReturn( $post );

self::assertSame( $expected, $subject->is_allowed() );
}

/**
* Data provider for test_is_allowed().
*
* @return array
*/
public function dp_test_is_allowed() {
return [
[ false, false, true ],
[ false, true, true ],
[ true, false, false ],
[ true, true, true ],
];
}

/**
* Test is_frontend().
*
Expand Down Expand Up @@ -271,20 +239,4 @@ public function dp_test_get_rest_route() {
'some request' => [ '/some-request', '' ],
];
}

/**
* Test is_post().
*/
public function test_is_post() {
WP_Mock::passthruFunction( 'wp_unslash' );

$subject = new Request();
self::assertFalse( $subject->is_post() );

$_SERVER['REQUEST_METHOD'] = 'some';
self::assertFalse( $subject->is_post() );

$_SERVER['REQUEST_METHOD'] = 'POST';
self::assertTrue( $subject->is_post() );
}
}

0 comments on commit 774a018

Please sign in to comment.