]> git.mxchange.org Git - friendica.git/blob - tests/src/Model/FileTagTest.php
Add yet another case to DateTimeFormat::fix
[friendica.git] / tests / src / Model / FileTagTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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  */
21
22 namespace Friendica\Test\src\Model;
23
24 use Friendica\Model\FileTag;
25 use PHPUnit\Framework\TestCase;
26
27 class FileTagTest extends TestCase
28 {
29     public function dataArrayToFile()
30     {
31         return [
32             'list-category' => [
33                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
34                 'type' => 'category',
35                 'file' => '<1><2><3><a><b><c>',
36             ],
37             'list-file' => [
38                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
39                 'type' => 'file',
40                 'file' => '[1][2][3][a][b][c]',
41             ],
42             'chevron-category' => [
43                 'array' => ['Left < Center > Right'],
44                 'type' => 'category',
45                 'file' => '<Left %3c Center %3e Right>',
46             ],
47             'bracket-file' => [
48                 'array' => ['Glass [half-full]'],
49                 'type' => 'file',
50                 'file' => '[Glass %5bhalf-full%5d]',
51             ],
52             /** @see https://github.com/friendica/friendica/issues/7171 */
53             'bug-7171-category' => [
54                 'array' => ['Science, Health, Medicine'],
55                 'type' => 'category',
56                 'file' => '<Science, Health, Medicine>',
57             ],
58             'bug-7171-file' => [
59                 'array' => ['Science, Health, Medicine'],
60                 'type' => 'file',
61                 'file' => '[Science, Health, Medicine]',
62             ],
63         ];
64     }
65
66     /**
67      * Test convert saved folders arrays to a file/category field
68      * @dataProvider dataArrayToFile
69      *
70      * @param array  $array
71      * @param string $type
72      * @param string $file
73      */
74     public function testArrayToFile(array $array, string $type, string $file)
75     {
76         self::assertEquals($file, FileTag::arrayToFile($array, $type));
77     }
78
79     public function dataFileToArray()
80     {
81         return [
82             'list-category' => [
83                 'file' => '<1><2><3><a><b><c>',
84                 'type' => 'category',
85                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
86             ],
87             'list-file' => [
88                 'file' => '[1][2][3][a][b][c]',
89                 'type' => 'file',
90                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
91             ],
92             'combinedlist-category' => [
93                 'file' => '[1][2][3]<a><b><c>',
94                 'type' => 'category',
95                 'array' => ['a', 'b', 'c'],
96             ],
97             'combinedlist-file' => [
98                 'file' => '[1][2][3]<a><b><c>',
99                 'type' => 'file',
100                 'array' => ['1', '2', '3'],
101             ],
102             'chevron-category' => [
103                 'file' => '<Left %3c Center %3e Right>',
104                 'type' => 'category',
105                 'array' => ['Left < Center > Right'],
106             ],
107             'bracket-file' => [
108                 'file' => '[Glass %5bhalf-full%5d]',
109                 'type' => 'file',
110                 'array' => ['Glass [half-full]'],
111             ],
112             /** @see https://github.com/friendica/friendica/issues/7171 */
113             'bug-7171-category' => [
114                 'file' => '<Science, Health, Medicine>',
115                 'type' => 'category',
116                 'array' => ['Science, Health, Medicine'],
117             ],
118             'bug-7171-file' => [
119                 'file' => '[Science, Health, Medicine]',
120                 'type' => 'file',
121                 'array' => ['Science, Health, Medicine'],
122             ],
123         ];
124     }
125
126     /**
127      * Test convert different saved folders to a file/category field
128      * @dataProvider dataFileToArray
129      *
130      * @param string $file
131      * @param string $type
132      * @param array  $array
133      */
134     public function testFileToArray(string $file, string $type, array $array)
135     {
136         self::assertEquals($array, FileTag::fileToArray($file, $type));
137     }
138 }