-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathtest-class-activitypub-users-collection.php
60 lines (54 loc) · 2.41 KB
/
test-class-activitypub-users-collection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class Test_Activitypub_Users_Collection extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
add_option( 'activitypub_blog_identifier', 'blog' );
add_user_meta( 1, 'activitypub_identifier', 'admin' );
}
/**
* @dataProvider the_resource_provider
*/
public function test_get_by_various( $resource, $expected ) {
$path = wp_parse_url( $resource, PHP_URL_PATH );
if ( str_starts_with( $path, '/blog/' ) ) {
add_filter(
'home_url',
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable, Generic.CodeAnalysis.UnusedFunctionParameter.Found
function ( $url ) {
return 'http://example.org/blog/';
}
);
}
$user = Activitypub\Collection\Users::get_by_resource( $resource );
$this->assertInstanceOf( $expected, $user );
}
public function the_resource_provider() {
return array(
array( 'http://example.org/?author=1', 'Activitypub\Model\User' ),
array( 'https://example.org/?author=1', 'Activitypub\Model\User' ),
array( 'https://example.org?author=1', 'Activitypub\Model\User' ),
array( 'http://example.org/?author=7', 'WP_Error' ),
array( 'acct:*@example.org', 'Activitypub\Model\Blog' ),
array( 'http://example.org/@admin', 'Activitypub\Model\User' ),
array( 'http://example.org/@blog', 'Activitypub\Model\Blog' ),
array( 'https://example.org/@blog', 'Activitypub\Model\Blog' ),
array( 'http://example.org/@blog/', 'Activitypub\Model\Blog' ),
array( 'http://example.org/blog/@blog', 'Activitypub\Model\Blog' ),
array( 'http://example.org/blog/@blog/', 'Activitypub\Model\Blog' ),
array( 'http://example.org/error/@blog', 'WP_Error' ),
array( 'http://example.org/error/@blog/', 'WP_Error' ),
array( 'http://example.org/', 'Activitypub\Model\Blog' ),
array( 'http://example.org', 'Activitypub\Model\Blog' ),
array( 'https://example.org/', 'Activitypub\Model\Blog' ),
array( 'https://example.org', 'Activitypub\Model\Blog' ),
array( 'http://example.org/@blog/s', 'WP_Error' ),
array( 'http://example.org/@blogs/', 'WP_Error' ),
);
}
}