wordpress-activitypub/tests/test-functions.php

42 lines
1.8 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'] );
2022-12-13 11:09:45 +01:00
}
/**
* @dataProvider example_actors
*/
public function test_get_example_metadata_by_actor( $actor, $domain, $username ) {
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();
foreach ( array( 'user', 'test' ) as $username ) {
2022-12-13 11:24:30 +01:00
foreach ( array( 'example.org', 'example.net', 'example2.com', 'my-domain.com', 'your-domain.org', 'test.net' ) as $domain ) {
foreach ( array( '@', '' ) as $leading_at ) {
2022-12-13 11:09:45 +01:00
$actors[] = array( $leading_at . $username . '@' . $domain, $domain, $username );
}
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 11:24:30 +01:00
$actors[] = array( 'example@abc.org', 'abc.org', 'example' );
2022-12-13 11:09:45 +01:00
return $actors;
2022-12-09 11:59:24 +01:00
}
}