-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Check response body for tombstone type (#1209) * some small improvements * fix PHPCS --------- Co-authored-by: Matthew Exon <[email protected]> Co-authored-by: Matthias Pfefferle <[email protected]>
- Loading branch information
1 parent
5f73af8
commit e0c3b67
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Test file for Activitypub HTTP Class | ||
* | ||
* @package Activitypub | ||
*/ | ||
|
||
namespace Activitypub\Tests; | ||
|
||
use Activitypub\Http; | ||
|
||
/** | ||
* Test class for ActivityPub HTTP Class | ||
* | ||
* @coversDefaultClass \Activitypub\Http | ||
*/ | ||
class Test_Http extends \WP_UnitTestCase { | ||
|
||
/** | ||
* Response code is 404 -> is_tombstone returns true | ||
* | ||
* @covers ::is_tombstone | ||
* | ||
* @dataProvider data_is_tombstone | ||
* | ||
* @param array $request The request array. | ||
* @param bool $result The expected result. | ||
*/ | ||
public function test_is_tombstone( $request, $result ) { | ||
$fake_request = function () use ( $request ) { | ||
return $request; | ||
}; | ||
add_filter( 'pre_http_request', $fake_request, 10, 3 ); | ||
$response = Http::is_tombstone( 'https://fake.test/object/123' ); | ||
$this->assertEquals( $result, $response ); | ||
remove_filter( 'pre_http_request', $fake_request, 10 ); | ||
} | ||
|
||
/** | ||
* Data provider for test_is_tombstone. | ||
* | ||
* @return array | ||
*/ | ||
public function data_is_tombstone() { | ||
return array( | ||
array( array( 'response' => array( 'code' => 404 ) ), true ), | ||
array( array( 'response' => array( 'code' => 410 ) ), true ), | ||
array( | ||
array( | ||
'response' => array( 'code' => 200 ), | ||
'body' => '', | ||
), | ||
false, | ||
), | ||
array( | ||
array( | ||
'response' => array( 'code' => 200 ), | ||
'body' => '{}', | ||
), | ||
false, | ||
), | ||
array( | ||
array( | ||
'response' => array( 'code' => 200 ), | ||
'body' => '{"type": "Note"}', | ||
), | ||
false, | ||
), | ||
array( | ||
array( | ||
'response' => array( 'code' => 200 ), | ||
'body' => '{"type": "Tombstone"}', | ||
), | ||
true, | ||
), | ||
array( | ||
array( | ||
'response' => array( 'code' => 200 ), | ||
'body' => '{"foo": "bar"}', | ||
), | ||
false, | ||
), | ||
); | ||
} | ||
} |