2022-12-09 11:59:24 +01:00
|
|
|
<?php
|
|
|
|
class Test_Functions extends ActivityPub_TestCase_Cache_HTTP {
|
2022-12-13 10:59:17 +01:00
|
|
|
public function invalid_http_response() {
|
|
|
|
return $this->assertTrue( false ); // should not be called.
|
|
|
|
}
|
|
|
|
|
2022-12-09 11:59:24 +01:00
|
|
|
public function test_get_remote_metadata_by_actor() {
|
|
|
|
$metadata = \ActivityPub\get_remote_metadata_by_actor( 'pfefferle@notiz.blog' );
|
2022-12-09 12:02:55 +01:00
|
|
|
$this->assertEquals( 'https://notiz.blog/author/matthias-pfefferle/', $metadata['url'] );
|
|
|
|
$this->assertEquals( 'pfefferle', $metadata['preferredUsername'] );
|
|
|
|
$this->assertEquals( 'Matthias Pfefferle', $metadata['name'] );
|
2022-12-13 11:09:45 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @dataProvider example_actors
|
|
|
|
*/
|
|
|
|
public function test_get_example_metadata_by_actor( $actor, $domain, $username ) {
|
2022-12-13 10:59:17 +01:00
|
|
|
add_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8, 3 );
|
2022-12-13 11:09:45 +01:00
|
|
|
$metadata = \ActivityPub\get_remote_metadata_by_actor( $actor );
|
|
|
|
$this->assertEquals( sprintf( 'https://%s/users/%s/', $domain, $username ), $metadata['url'], $actor );
|
|
|
|
$this->assertEquals( $username, $metadata['name'], $actor );
|
|
|
|
remove_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function example_actors() {
|
|
|
|
$actors = array();
|
2022-12-13 10:59:17 +01:00
|
|
|
foreach ( array( 'user', 'test' ) as $username ) {
|
2022-12-13 11:01:17 +01:00
|
|
|
foreach ( array( 'example.org', 'example.net', 'example2.com' ) as $domain ) {
|
2022-12-13 10:59:17 +01:00
|
|
|
foreach ( array( '@', '' ) as $leading_at ) {
|
2022-12-13 11:09:45 +01:00
|
|
|
$actors[] = array( $leading_at . $username . '@' . $domain, $domain, $username );
|
2022-12-13 10:59:17 +01:00
|
|
|
}
|
2022-12-13 11:09:45 +01:00
|
|
|
$actors[] = array( sprintf( 'https://%s/users/%s/', $domain, $username ), $domain, $username );
|
|
|
|
$actors[] = array( sprintf( 'https://%s/users/%s', $domain, $username ), $domain, $username );
|
|
|
|
$actors[] = array( sprintf( 'https://%s/@%s', $domain, $username ), $domain, $username );
|
2022-12-13 10:59:17 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-13 11:09:45 +01:00
|
|
|
return $actors;
|
2022-12-09 11:59:24 +01:00
|
|
|
}
|
|
|
|
}
|