]> git.mxchange.org Git - friendica.git/blob - tests/src/Model/FileTagTest.php
Refactor Cache/Lock to DICE
[friendica.git] / tests / src / Model / FileTagTest.php
1 <?php
2
3 namespace Friendica\Test\src\Model;
4
5 use Friendica\Model\FileTag;
6 use PHPUnit\Framework\TestCase;
7
8 class FileTagTest extends TestCase
9 {
10     public function dataArrayToFile()
11     {
12         return [
13             'list-category' => [
14                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
15                 'type' => 'category',
16                 'file' => '<1><2><3><a><b><c>',
17             ],
18             'list-file' => [
19                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
20                 'type' => 'file',
21                 'file' => '[1][2][3][a][b][c]',
22             ],
23             'chevron-category' => [
24                 'array' => ['Left < Center > Right'],
25                 'type' => 'category',
26                 'file' => '<Left %3c Center %3e Right>',
27             ],
28             'bracket-file' => [
29                 'array' => ['Glass [half-full]'],
30                 'type' => 'file',
31                 'file' => '[Glass %5bhalf-full%5d]',
32             ],
33             /** @see https://github.com/friendica/friendica/issues/7171 */
34             'bug-7171-category' => [
35                 'array' => ['Science, Health, Medicine'],
36                 'type' => 'category',
37                 'file' => '<Science, Health, Medicine>',
38             ],
39             'bug-7171-file' => [
40                 'array' => ['Science, Health, Medicine'],
41                 'type' => 'file',
42                 'file' => '[Science, Health, Medicine]',
43             ],
44         ];
45     }
46
47     /**
48      * Test convert saved folders arrays to a file/category field
49      * @dataProvider dataArrayToFile
50      *
51      * @param array  $array
52      * @param string $type
53      * @param string $file
54      */
55     public function testArrayToFile(array $array, string $type, string $file)
56     {
57         $this->assertEquals($file, FileTag::arrayToFile($array, $type));
58     }
59
60     public function dataFileToArray()
61     {
62         return [
63             'list-category' => [
64                 'file' => '<1><2><3><a><b><c>',
65                 'type' => 'category',
66                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
67             ],
68             'list-file' => [
69                 'file' => '[1][2][3][a][b][c]',
70                 'type' => 'file',
71                 'array' => ['1', '2', '3', 'a', 'b', 'c'],
72             ],
73             'combinedlist-category' => [
74                 'file' => '[1][2][3]<a><b><c>',
75                 'type' => 'category',
76                 'array' => ['a', 'b', 'c'],
77             ],
78             'combinedlist-file' => [
79                 'file' => '[1][2][3]<a><b><c>',
80                 'type' => 'file',
81                 'array' => ['1', '2', '3'],
82             ],
83             'chevron-category' => [
84                 'file' => '<Left %3c Center %3e Right>',
85                 'type' => 'category',
86                 'array' => ['Left < Center > Right'],
87             ],
88             'bracket-file' => [
89                 'file' => '[Glass %5bhalf-full%5d]',
90                 'type' => 'file',
91                 'array' => ['Glass [half-full]'],
92             ],
93             /** @see https://github.com/friendica/friendica/issues/7171 */
94             'bug-7171-category' => [
95                 'file' => '<Science, Health, Medicine>',
96                 'type' => 'category',
97                 'array' => ['Science, Health, Medicine'],
98             ],
99             'bug-7171-file' => [
100                 'file' => '[Science, Health, Medicine]',
101                 'type' => 'file',
102                 'array' => ['Science, Health, Medicine'],
103             ],
104         ];
105     }
106
107     /**
108      * Test convert different saved folders to a file/category field
109      * @dataProvider dataFileToArray
110      *
111      * @param string $file
112      * @param string $type
113      * @param array  $array
114      */
115     public function testFileToArray(string $file, string $type, array $array)
116     {
117         $this->assertEquals($array, FileTag::fileToArray($file, $type));
118     }
119 }