3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Model;
24 use Friendica\Model\FileTag;
25 use PHPUnit\Framework\TestCase;
27 class FileTagTest extends TestCase
29 public function dataArrayToFile()
33 'array' => ['1', '2', '3', 'a', 'b', 'c'],
35 'file' => '<1><2><3><a><b><c>',
38 'array' => ['1', '2', '3', 'a', 'b', 'c'],
40 'file' => '[1][2][3][a][b][c]',
42 'chevron-category' => [
43 'array' => ['Left < Center > Right'],
45 'file' => '<Left %3c Center %3e Right>',
48 'array' => ['Glass [half-full]'],
50 'file' => '[Glass %5bhalf-full%5d]',
52 /** @see https://github.com/friendica/friendica/issues/7171 */
53 'bug-7171-category' => [
54 'array' => ['Science, Health, Medicine'],
56 'file' => '<Science, Health, Medicine>',
59 'array' => ['Science, Health, Medicine'],
61 'file' => '[Science, Health, Medicine]',
67 * Test convert saved folders arrays to a file/category field
68 * @dataProvider dataArrayToFile
74 public function testArrayToFile(array $array, string $type, string $file)
76 self::assertEquals($file, FileTag::arrayToFile($array, $type));
79 public function dataFileToArray()
83 'file' => '<1><2><3><a><b><c>',
85 'array' => ['1', '2', '3', 'a', 'b', 'c'],
88 'file' => '[1][2][3][a][b][c]',
90 'array' => ['1', '2', '3', 'a', 'b', 'c'],
92 'combinedlist-category' => [
93 'file' => '[1][2][3]<a><b><c>',
95 'array' => ['a', 'b', 'c'],
97 'combinedlist-file' => [
98 'file' => '[1][2][3]<a><b><c>',
100 'array' => ['1', '2', '3'],
102 'chevron-category' => [
103 'file' => '<Left %3c Center %3e Right>',
104 'type' => 'category',
105 'array' => ['Left < Center > Right'],
108 'file' => '[Glass %5bhalf-full%5d]',
110 'array' => ['Glass [half-full]'],
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'],
119 'file' => '[Science, Health, Medicine]',
121 'array' => ['Science, Health, Medicine'],
127 * Test convert different saved folders to a file/category field
128 * @dataProvider dataFileToArray
130 * @param string $file
131 * @param string $type
132 * @param array $array
134 public function testFileToArray(string $file, string $type, array $array)
136 self::assertEquals($array, FileTag::fileToArray($file, $type));