|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | + |
| 7 | +class ActivityPubTagObjectTest extends TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * A basic unit test example. |
| 11 | + */ |
| 12 | + public function test_gotosocial(): void |
| 13 | + { |
| 14 | + $res = [ |
| 15 | + "tag" => [ |
| 16 | + "href" => "https://gotosocial.example.org/users/GotosocialUser", |
| 17 | + "name" => "@GotosocialUser@gotosocial.example.org", |
| 18 | + "type" => "Mention" |
| 19 | + ] |
| 20 | + ]; |
| 21 | + |
| 22 | + if(isset($res['tag']['type'], $res['tag']['name'])) { |
| 23 | + $res['tag'] = [$res['tag']]; |
| 24 | + } |
| 25 | + |
| 26 | + $tags = collect($res['tag']) |
| 27 | + ->filter(function($tag) { |
| 28 | + return $tag && |
| 29 | + $tag['type'] == 'Mention' && |
| 30 | + isset($tag['href']) && |
| 31 | + substr($tag['href'], 0, 8) === 'https://'; |
| 32 | + }); |
| 33 | + $this->assertTrue($tags->count() === 1); |
| 34 | + } |
| 35 | + |
| 36 | + public function test_pixelfed_hashtags(): void |
| 37 | + { |
| 38 | + $res = [ |
| 39 | + "tag" => [ |
| 40 | + [ |
| 41 | + "type" => "Mention", |
| 42 | + "href" => "https://pixelfed.social/dansup", |
| 43 | + "name" => "@dansup@pixelfed.social" |
| 44 | + ], |
| 45 | + [ |
| 46 | + "type" => "Hashtag", |
| 47 | + "href" => "https://pixelfed.social/discover/tags/dogsofpixelfed", |
| 48 | + "name" => "#dogsOfPixelFed" |
| 49 | + ], |
| 50 | + [ |
| 51 | + "type" => "Hashtag", |
| 52 | + "href" => "https://pixelfed.social/discover/tags/doggo", |
| 53 | + "name" => "#doggo" |
| 54 | + ], |
| 55 | + [ |
| 56 | + "type" => "Hashtag", |
| 57 | + "href" => "https://pixelfed.social/discover/tags/dog", |
| 58 | + "name" => "#dog" |
| 59 | + ], |
| 60 | + [ |
| 61 | + "type" => "Hashtag", |
| 62 | + "href" => "https://pixelfed.social/discover/tags/drake", |
| 63 | + "name" => "#drake" |
| 64 | + ], |
| 65 | + [ |
| 66 | + "type" => "Hashtag", |
| 67 | + "href" => "https://pixelfed.social/discover/tags/blacklab", |
| 68 | + "name" => "#blacklab" |
| 69 | + ], |
| 70 | + [ |
| 71 | + "type" => "Hashtag", |
| 72 | + "href" => "https://pixelfed.social/discover/tags/iconic", |
| 73 | + "name" => "#Iconic" |
| 74 | + ], |
| 75 | + [ |
| 76 | + "type" => "Hashtag", |
| 77 | + "href" => "https://pixelfed.social/discover/tags/majestic", |
| 78 | + "name" => "#majestic" |
| 79 | + ] |
| 80 | + ] |
| 81 | + ]; |
| 82 | + |
| 83 | + if(isset($res['tag']['type'], $res['tag']['name'])) { |
| 84 | + $res['tag'] = [$res['tag']]; |
| 85 | + } |
| 86 | + |
| 87 | + $tags = collect($res['tag']) |
| 88 | + ->filter(function($tag) { |
| 89 | + return $tag && |
| 90 | + $tag['type'] == 'Hashtag' && |
| 91 | + isset($tag['href']) && |
| 92 | + substr($tag['href'], 0, 8) === 'https://'; |
| 93 | + }); |
| 94 | + $this->assertTrue($tags->count() === 7); |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | + public function test_pixelfed_mentions(): void |
| 99 | + { |
| 100 | + $res = [ |
| 101 | + "tag" => [ |
| 102 | + [ |
| 103 | + "type" => "Mention", |
| 104 | + "href" => "https://pixelfed.social/dansup", |
| 105 | + "name" => "@dansup@pixelfed.social" |
| 106 | + ], |
| 107 | + [ |
| 108 | + "type" => "Hashtag", |
| 109 | + "href" => "https://pixelfed.social/discover/tags/dogsofpixelfed", |
| 110 | + "name" => "#dogsOfPixelFed" |
| 111 | + ], |
| 112 | + [ |
| 113 | + "type" => "Hashtag", |
| 114 | + "href" => "https://pixelfed.social/discover/tags/doggo", |
| 115 | + "name" => "#doggo" |
| 116 | + ], |
| 117 | + ] |
| 118 | + ]; |
| 119 | + |
| 120 | + if(isset($res['tag']['type'], $res['tag']['name'])) { |
| 121 | + $res['tag'] = [$res['tag']]; |
| 122 | + } |
| 123 | + |
| 124 | + $tags = collect($res['tag']) |
| 125 | + ->filter(function($tag) { |
| 126 | + return $tag && |
| 127 | + $tag['type'] == 'Mention' && |
| 128 | + isset($tag['href']) && |
| 129 | + substr($tag['href'], 0, 8) === 'https://'; |
| 130 | + }); |
| 131 | + $this->assertTrue($tags->count() === 1); |
| 132 | + } |
| 133 | +} |
0 commit comments