Skip to content

Commit f07cb12

Browse files
authored
Update tests to use plugin folder structure (#1049)
* Update tests to use plugin folder structure * Remove unused imports * Update latest test file * Bring back error silencer. * Move test file in correct folder
1 parent f0ebe33 commit f07cb12

31 files changed

+606
-429
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
>
99
<testsuites>
1010
<testsuite name="ActivityPub">
11-
<directory prefix="class-test-" suffix=".php">./tests/</directory>
11+
<directory prefix="class-test-" suffix=".php">./tests</directory>
1212
</testsuite>
1313
</testsuites>
1414
</phpunit>

tests/class-activitypub-testcase-cache-http.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @package Activitypub
66
*/
77

8+
namespace Activitypub\Tests;
9+
810
/**
911
* Test class for Activitypub Cache HTTP.
1012
*/
@@ -59,7 +61,7 @@ public function tear_down() {
5961
* @type string $body Request body.
6062
* }
6163
* @param string $url The request URL.
62-
* @return array|bool|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance. A boolean false value.
64+
* @return array|bool|\WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance. A boolean false value.
6365
*/
6466
public static function pre_http_request( $preempt, $request, $url ) {
6567
$p = wp_parse_url( $url );

tests/class-test-activitypub-post.php

Lines changed: 0 additions & 191 deletions
This file was deleted.

tests/class-test-activitypub-activity.php renamed to tests/includes/activity/class-test-activity.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<?php
22
/**
3-
* Test file for Activitypub Activity.
3+
* Test file for Activity.
44
*
55
* @package Activitypub
66
*/
77

8+
namespace Activitypub\Tests\Activity;
9+
10+
use Activitypub\Activity\Activity;
811
use DMS\PHPUnitExtensions\ArraySubset\Assert;
912

1013
/**
11-
* Test class for Activitypub Activity.
14+
* Test class for Activity.
1215
*
1316
* @coversDefaultClass \Activitypub\Activity\Activity
1417
*/
15-
class Test_Activitypub_Activity extends WP_UnitTestCase {
18+
class Test_Activity extends \WP_UnitTestCase {
1619

1720
/**
1821
* Test activity mentions.
@@ -35,7 +38,7 @@ function ( $mentions ) {
3538

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

38-
$activitypub_activity = new \Activitypub\Activity\Activity();
41+
$activitypub_activity = new Activity();
3942
$activitypub_activity->set_type( 'Create' );
4043
$activitypub_activity->set_object( $activitypub_post );
4144

@@ -81,7 +84,7 @@ public function test_activity_object() {
8184
),
8285
);
8386

84-
$activity = \Activitypub\Activity\Activity::init_from_array( $test_array );
87+
$activity = Activity::init_from_array( $test_array );
8588

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

9699
// Build the update.
97-
$activity = new \Activitypub\Activity\Activity();
100+
$activity = new Activity();
98101
$activity->set_type( 'Update' );
99102
$activity->set_actor( $id );
100103
$activity->set_object( $id );

tests/class-test-activitypub-activity-dispatcher.php renamed to tests/includes/class-test-activity-dispatcher.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
* @package Activitypub
66
*/
77

8+
namespace Activitypub\Tests;
9+
10+
use Activitypub\Activity_Dispatcher;
11+
812
/**
913
* Test class for Activitypub Activity Dispatcher.
1014
*
1115
* @coversDefaultClass \Activitypub\Activity_Dispatcher
1216
*/
13-
class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HTTP {
17+
class Test_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HTTP {
1418

1519
/**
1620
* Users.
@@ -70,10 +74,10 @@ public function test_dispatch_activity() {
7074
)
7175
);
7276

73-
$pre_http_request = new MockAction();
77+
$pre_http_request = new \MockAction();
7478
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
7579

76-
\Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
80+
Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
7781

7882
$this->assertSame( 2, $pre_http_request->get_call_count() );
7983
$all_args = $pre_http_request->get_args();
@@ -120,10 +124,10 @@ function ( $mentions ) {
120124
}
121125
);
122126

123-
$pre_http_request = new MockAction();
127+
$pre_http_request = new \MockAction();
124128
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
125129

126-
\Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
130+
Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
127131

128132
$this->assertSame( 1, $pre_http_request->get_call_count() );
129133
$all_args = $pre_http_request->get_args();
@@ -158,10 +162,10 @@ public function test_dispatch_announce() {
158162
)
159163
);
160164

161-
$pre_http_request = new MockAction();
165+
$pre_http_request = new \MockAction();
162166
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
163167

164-
\Activitypub\Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
168+
Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
165169

166170
$all_args = $pre_http_request->get_args();
167171
$first_call_args = $all_args[0];
@@ -211,10 +215,10 @@ function ( $value, $type ) {
211215
)
212216
);
213217

214-
$pre_http_request = new MockAction();
218+
$pre_http_request = new \MockAction();
215219
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
216220

217-
\Activitypub\Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
221+
Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
218222

219223
$all_args = $pre_http_request->get_args();
220224
$first_call_args = $all_args[0];
@@ -268,10 +272,10 @@ function ( $disabled, $user_id ) {
268272
)
269273
);
270274

271-
$pre_http_request = new MockAction();
275+
$pre_http_request = new \MockAction();
272276
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
273277

274-
\Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
278+
Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
275279

276280
$all_args = $pre_http_request->get_args();
277281
$first_call_args = $all_args[0];
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
* @package Activitypub
66
*/
77

8+
namespace Activitypub\Tests;
9+
810
/**
911
* Test class for Activitypub.
1012
*
1113
* @coversDefaultClass \Activitypub\Activitypub
1214
*/
13-
class Test_Activitypub extends WP_UnitTestCase {
15+
class Test_Activitypub extends \WP_UnitTestCase {
1416

1517
/**
1618
* Test post type support.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
* @package Activitypub
66
*/
77

8+
namespace Activitypub\Tests;
9+
810
/**
911
* Test class for Admin.
1012
*
1113
* @coversDefaultClass \Activitypub\Admin
1214
*/
13-
class Test_Admin extends WP_UnitTestCase {
15+
class Test_Admin extends \WP_UnitTestCase {
1416

1517
/**
1618
* Test the admin notice for missing permalink structure.

0 commit comments

Comments
 (0)