mirror of https://github.com/friendica/friendica
parent
9e94e8b48c
commit
52c42491c4
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Protocol;
|
||||
|
||||
/**
|
||||
* Base class for the Activity namespace
|
||||
*/
|
||||
final class Activity
|
||||
{
|
||||
/**
|
||||
* Compare activity uri. Knows about activity namespace.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function match(string $haystack, string $needle) {
|
||||
return (($haystack === $needle) ||
|
||||
((basename($needle) === $haystack) &&
|
||||
strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Test\Protocol;
|
||||
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ActivityTest extends MockedTest
|
||||
{
|
||||
public function dataMatch()
|
||||
{
|
||||
return [
|
||||
'empty' => [
|
||||
'haystack' => '',
|
||||
'needle' => '',
|
||||
'assert' => true,
|
||||
],
|
||||
'simple' => [
|
||||
'haystack' => ACTIVITY_OBJ_TAGTERM,
|
||||
'needle' => ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => true,
|
||||
],
|
||||
'withNamespace' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => NAMESPACE_ACTIVITY_SCHEMA . ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => true,
|
||||
],
|
||||
'invalidSimple' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => '',
|
||||
'assert' => false,
|
||||
],
|
||||
'invalidWithOutNamespace' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => false,
|
||||
],
|
||||
'withSubPath' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => NAMESPACE_ACTIVITY_SCHEMA . '/bla/' . ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the different, possible matchings
|
||||
*
|
||||
* @dataProvider dataMatch
|
||||
*/
|
||||
public function testMatch(string $haystack, string $needle, bool $assert)
|
||||
{
|
||||
$activity = new Activity();
|
||||
|
||||
$this->assertEquals($assert, $activity->match($haystack, $needle));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue