Skip to content

Commit

Permalink
Update tests to use plugin folder structure (#1049)
Browse files Browse the repository at this point in the history
* Update tests to use plugin folder structure

* Remove unused imports

* Update latest test file

* Bring back error silencer.

* Move test file in correct folder
  • Loading branch information
obenland authored Dec 9, 2024
1 parent f0ebe33 commit f07cb12
Show file tree
Hide file tree
Showing 31 changed files with 606 additions and 429 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<testsuites>
<testsuite name="ActivityPub">
<directory prefix="class-test-" suffix=".php">./tests/</directory>
<directory prefix="class-test-" suffix=".php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 3 additions & 1 deletion tests/class-activitypub-testcase-cache-http.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package Activitypub
*/

namespace Activitypub\Tests;

/**
* Test class for Activitypub Cache HTTP.
*/
Expand Down Expand Up @@ -59,7 +61,7 @@ public function tear_down() {
* @type string $body Request body.
* }
* @param string $url The request URL.
* @return array|bool|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance. A boolean false value.
* @return array|bool|\WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance. A boolean false value.
*/
public static function pre_http_request( $preempt, $request, $url ) {
$p = wp_parse_url( $url );
Expand Down
191 changes: 0 additions & 191 deletions tests/class-test-activitypub-post.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php
/**
* Test file for Activitypub Activity.
* Test file for Activity.
*
* @package Activitypub
*/

namespace Activitypub\Tests\Activity;

use Activitypub\Activity\Activity;
use DMS\PHPUnitExtensions\ArraySubset\Assert;

/**
* Test class for Activitypub Activity.
* Test class for Activity.
*
* @coversDefaultClass \Activitypub\Activity\Activity
*/
class Test_Activitypub_Activity extends WP_UnitTestCase {
class Test_Activity extends \WP_UnitTestCase {

/**
* Test activity mentions.
Expand All @@ -35,7 +38,7 @@ function ( $mentions ) {

$activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();

$activitypub_activity = new \Activitypub\Activity\Activity();
$activitypub_activity = new Activity();
$activitypub_activity->set_type( 'Create' );
$activitypub_activity->set_object( $activitypub_post );

Expand Down Expand Up @@ -81,7 +84,7 @@ public function test_activity_object() {
),
);

$activity = \Activitypub\Activity\Activity::init_from_array( $test_array );
$activity = Activity::init_from_array( $test_array );

$this->assertEquals( 'Hello world!', $activity->get_object()->get_content() );
Assert::assertArraySubset( $test_array, $activity->to_array() );
Expand All @@ -94,7 +97,7 @@ public function test_activity_object_url() {
$id = 'https://example.com/author/123';

// Build the update.
$activity = new \Activitypub\Activity\Activity();
$activity = new Activity();
$activity->set_type( 'Update' );
$activity->set_actor( $id );
$activity->set_object( $id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
* @package Activitypub
*/

namespace Activitypub\Tests;

use Activitypub\Activity_Dispatcher;

/**
* Test class for Activitypub Activity Dispatcher.
*
* @coversDefaultClass \Activitypub\Activity_Dispatcher
*/
class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HTTP {
class Test_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HTTP {

/**
* Users.
Expand Down Expand Up @@ -70,10 +74,10 @@ public function test_dispatch_activity() {
)
);

$pre_http_request = new MockAction();
$pre_http_request = new \MockAction();
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );

\Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );

$this->assertSame( 2, $pre_http_request->get_call_count() );
$all_args = $pre_http_request->get_args();
Expand Down Expand Up @@ -120,10 +124,10 @@ function ( $mentions ) {
}
);

$pre_http_request = new MockAction();
$pre_http_request = new \MockAction();
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );

\Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );

$this->assertSame( 1, $pre_http_request->get_call_count() );
$all_args = $pre_http_request->get_args();
Expand Down Expand Up @@ -158,10 +162,10 @@ public function test_dispatch_announce() {
)
);

$pre_http_request = new MockAction();
$pre_http_request = new \MockAction();
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );

\Activitypub\Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );

$all_args = $pre_http_request->get_args();
$first_call_args = $all_args[0];
Expand Down Expand Up @@ -211,10 +215,10 @@ function ( $value, $type ) {
)
);

$pre_http_request = new MockAction();
$pre_http_request = new \MockAction();
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );

\Activitypub\Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );

$all_args = $pre_http_request->get_args();
$first_call_args = $all_args[0];
Expand Down Expand Up @@ -268,10 +272,10 @@ function ( $disabled, $user_id ) {
)
);

$pre_http_request = new MockAction();
$pre_http_request = new \MockAction();
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );

\Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );

$all_args = $pre_http_request->get_args();
$first_call_args = $all_args[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @package Activitypub
*/

namespace Activitypub\Tests;

/**
* Test class for Activitypub.
*
* @coversDefaultClass \Activitypub\Activitypub
*/
class Test_Activitypub extends WP_UnitTestCase {
class Test_Activitypub extends \WP_UnitTestCase {

/**
* Test post type support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @package Activitypub
*/

namespace Activitypub\Tests;

/**
* Test class for Admin.
*
* @coversDefaultClass \Activitypub\Admin
*/
class Test_Admin extends WP_UnitTestCase {
class Test_Admin extends \WP_UnitTestCase {

/**
* Test the admin notice for missing permalink structure.
Expand Down
Loading

0 comments on commit f07cb12

Please sign in to comment.