wordpress-activitypub/tests/test-functions.php

29 lines
1.5 KiB
PHP
Raw Normal View History

2022-12-09 11:59:24 +01:00
<?php
class Test_Functions extends ActivityPub_TestCase_Cache_HTTP {
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'] );
add_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8, 3 );
foreach ( array( 'user', 'test' ) as $username ) {
2022-12-13 11:01:17 +01:00
foreach ( array( 'example.org', 'example.net', 'example2.com' ) as $domain ) {
foreach ( array( '@', '' ) as $leading_at ) {
2022-12-13 11:02:14 +01:00
$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 );
2022-12-09 11:59:24 +01:00
}
}