mirror of
https://github.com/Automattic/wordpress-activitypub
synced 2024-10-18 20:23:31 +00:00
3fde5bbe96
* improve lemmy compatibility * simplify code * fix tests * use string instead of array * use `actors` instead of `users` * optimize ID generation * update ID * the #threadiverse needs Announces for everything! :) * change to full Announce Object * fix indents
60 lines
2.4 KiB
PHP
60 lines
2.4 KiB
PHP
<?php
|
|
class Test_Activitypub_Users_Collection extends WP_UnitTestCase {
|
|
|
|
public function set_up() {
|
|
parent::set_up();
|
|
|
|
add_option( 'activitypub_blog_user_identifier', 'blog' );
|
|
add_user_meta( 1, 'activitypub_user_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:admin@example.org', 'Activitypub\Model\User' ),
|
|
array( 'acct:blog@example.org', 'Activitypub\Model\Blog' ),
|
|
array( 'acct:*@example.org', 'Activitypub\Model\Blog' ),
|
|
array( 'acct:_@example.org', 'Activitypub\Model\Blog' ),
|
|
array( 'acct:aksd@example.org', 'WP_Error' ),
|
|
array( 'admin@example.org', 'Activitypub\Model\User' ),
|
|
array( 'acct:application@example.org', 'Activitypub\Model\Application' ),
|
|
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' ),
|
|
);
|
|
}
|
|
}
|