wordpress-activitypub/tests/test-functions.php
2023-01-27 15:48:28 +01:00

28 lines
1.5 KiB
PHP

<?php
class Test_Functions extends ActivityPub_TestCase_Cache_HTTP {
public function invalid_http_response() {
return $this->assertTrue( false ); // should not be called.
}
public function test_get_remote_metadata_by_actor() {
$metadata = \ActivityPub\get_remote_metadata_by_actor( 'pfefferle@notiz.blog' );
$this->assertEquals( 'https://notiz.blog/author/matthias-pfefferle/', $metadata['url'] );
$this->assertEquals( 'pfefferle', $metadata['preferredUsername'] );
$this->assertEquals( 'Matthias Pfefferle', $metadata['name'] );
add_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8, 3 );
foreach ( array( 'user', 'test' ) as $username ) {
foreach ( array( 'example.org', 'example.net', 'example2.com' ) as $domain ) {
foreach ( array( '@', '' ) as $leading_at ) {
$metadata = \ActivityPub\get_remote_metadata_by_actor( $leading_at . $username . '@' . $domain );
$this->assertEquals( sprintf( 'https://%s/users/%s/', $domain, $username ), $metadata['url'], $username . '@' . $domain );
$this->assertEquals( $username, $metadata['name'], $username . '@' . $domain );
}
$metadata = \ActivityPub\get_remote_metadata_by_actor( sprintf( 'https://%s/users/%s/', $domain, $username ) );
$this->assertEquals( sprintf( 'https://%s/users/%s/', $domain, $username ), $metadata['url'], $username . '@' . $domain );
$this->assertEquals( $username, $metadata['name'], $username . '@' . $domain );
}
}
remove_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8 );
}
}