]> git.mxchange.org Git - friendica.git/blob - tests/src/Protocol/WebFingerUriTest.php
Use "author_handle" for the author handle extracted from Diaspora XML messages
[friendica.git] / tests / src / Protocol / WebFingerUriTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * Main database structure configuration file.
21  *
22  * Here are described all the tables, fields and indexes Friendica needs to work.
23  * The entry order is mostly alphabetic - with the exception of tables that are used in foreign keys.
24  *
25  * Syntax (braces indicate optionale values):
26  * "<table name>" => [
27  *    "comment" => "Description of the table",
28  *    "fields" => [
29  *        "<field name>" => [
30  *            "type" => "<field type>{(<field size>)} <unsigned>",
31  *            "not null" => 0|1,
32  *            {"extra" => "auto_increment",}
33  *            {"default" => "<default value>",}
34  *            {"default" => NULL_DATE,} (for datetime fields)
35  *            {"primary" => "1",}
36  *            {"foreign|relation" => ["<foreign key table name>" => "<foreign key field name>"],}
37  *            "comment" => "Description of the fields"
38  *        ],
39  *        ...
40  *    ],
41  *    "indexes" => [
42  *        "PRIMARY" => ["<primary key field name>", ...],
43  *        "<index name>" => [{"UNIQUE",} "<field name>{(<key size>)}", ...]
44  *        ...
45  *    ],
46  * ],
47  *
48  * Whenever possible prefer "foreign" before "relation" with the foreign keys.
49  * "foreign" adds true foreign keys on the database level, while "relation" is just an indicator of a table relation without any consequences
50  *
51  * If you need to make any change, make sure to increment the DB_UPDATE_VERSION constant value below.
52  *
53  */
54
55 namespace Friendica\Test\src\Protocol;
56
57 use Friendica\Protocol\WebFingerUri;
58 use PHPUnit\Framework\TestCase;
59
60 class WebFingerUriTest extends TestCase
61 {
62         public function dataFromString(): array
63         {
64                 return [
65                         'long' => [
66                                 'expectedLong'  => 'acct:selma@www.example.com:8080/friend',
67                                 'expectedShort' => 'selma@www.example.com:8080/friend',
68                                 'input'         => 'acct:selma@www.example.com:8080/friend',
69                         ],
70                         'short' => [
71                                 'expectedLong'  => 'acct:selma@www.example.com:8080/friend',
72                                 'expectedShort' => 'selma@www.example.com:8080/friend',
73                                 'input'         => 'selma@www.example.com:8080/friend',
74                         ],
75                         'minimal' => [
76                                 'expectedLong'  => 'acct:bob@example.com',
77                                 'expectedShort' => 'bob@example.com',
78                                 'input'         => 'bob@example.com',
79                         ],
80                         'acct:' => [
81                                 'expectedLong'  => 'acct:alice@example.acct:90',
82                                 'expectedShort' => 'alice@example.acct:90',
83                                 'input'         => 'alice@example.acct:90',
84                         ],
85                 ];
86         }
87
88         /**
89          * @dataProvider dataFromString
90          * @param string $expectedLong
91          * @param string $expectedShort
92          * @param string $input
93          * @return void
94          */
95         public function testFromString(string $expectedLong, string $expectedShort, string $input)
96         {
97                 $uri = WebFingerUri::fromString($input);
98
99                 $this->assertEquals($expectedLong, $uri->getLongForm());
100                 $this->assertEquals($expectedShort, $uri->getShortForm());
101         }
102
103         public function dataFromStringFailure()
104         {
105                 return [
106                         'missing user' => [
107                                 'input' => 'example.com',
108                         ],
109                         'missing user @' => [
110                                 'input' => '@example.com',
111                         ],
112                         'missing host' => [
113                                 'input' => 'alice',
114                         ],
115                         'missing host @' => [
116                                 'input' => 'alice@',
117                         ],
118                         'missing everything' => [
119                                 'input' => '',
120                         ],
121                 ];
122         }
123
124         /**
125          * @dataProvider dataFromStringFailure
126          * @param string $input
127          * @return void
128          */
129         public function testFromStringFailure(string $input)
130         {
131                 $this->expectException(\InvalidArgumentException::class);
132
133                 WebFingerUri::fromString($input);
134         }
135 }