From 1e90d8efce602231b53b5605793b31c9ba3ba77d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 28 May 2019 17:05:29 -0400 Subject: [PATCH] Add tests for Model\FileTag fileToArray and arrayToFile methods. --- tests/src/Model/FileTagTest.php | 119 ++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 tests/src/Model/FileTagTest.php diff --git a/tests/src/Model/FileTagTest.php b/tests/src/Model/FileTagTest.php new file mode 100644 index 0000000000..f74bec3639 --- /dev/null +++ b/tests/src/Model/FileTagTest.php @@ -0,0 +1,119 @@ + [ + 'array' => ['1', '2', '3', 'a', 'b', 'c'], + 'type' => 'category', + 'file' => '<1><2><3>', + ], + 'list-file' => [ + 'array' => ['1', '2', '3', 'a', 'b', 'c'], + 'type' => 'file', + 'file' => '[1][2][3][a][b][c]', + ], + 'chevron-category' => [ + 'array' => ['Left < Center > Right'], + 'type' => 'category', + 'file' => '', + ], + 'bracket-file' => [ + 'array' => ['Glass [half-full]'], + 'type' => 'file', + 'file' => '[Glass %5bhalf-full%5d]', + ], + /** @see https://github.com/friendica/friendica/issues/7171 */ + 'bug-7171-category' => [ + 'array' => ['Science, Health, Medicine'], + 'type' => 'category', + 'file' => '', + ], + 'bug-7171-file' => [ + 'array' => ['Science, Health, Medicine'], + 'type' => 'file', + 'file' => '[Science, Health, Medicine]', + ], + ]; + } + + /** + * Test convert saved folders arrays to a file/category field + * @dataProvider dataArrayToFile + * + * @param array $array + * @param string $type + * @param string $file + */ + public function testArrayToFile(array $array, string $type, string $file) + { + $this->assertEquals($file, FileTag::arrayToFile($array, $type)); + } + + public function dataFileToArray() + { + return [ + 'list-category' => [ + 'file' => '<1><2><3>', + 'type' => 'category', + 'array' => ['1', '2', '3', 'a', 'b', 'c'], + ], + 'list-file' => [ + 'file' => '[1][2][3][a][b][c]', + 'type' => 'file', + 'array' => ['1', '2', '3', 'a', 'b', 'c'], + ], + 'combinedlist-category' => [ + 'file' => '[1][2][3]', + 'type' => 'category', + 'array' => ['a', 'b', 'c'], + ], + 'combinedlist-file' => [ + 'file' => '[1][2][3]', + 'type' => 'file', + 'array' => ['1', '2', '3'], + ], + 'chevron-category' => [ + 'file' => '', + 'type' => 'category', + 'array' => ['Left < Center > Right'], + ], + 'bracket-file' => [ + 'file' => '[Glass %5bhalf-full%5d]', + 'type' => 'file', + 'array' => ['Glass [half-full]'], + ], + /** @see https://github.com/friendica/friendica/issues/7171 */ + 'bug-7171-category' => [ + 'file' => '', + 'type' => 'category', + 'array' => ['Science, Health, Medicine'], + ], + 'bug-7171-file' => [ + 'file' => '[Science, Health, Medicine]', + 'type' => 'file', + 'array' => ['Science, Health, Medicine'], + ], + ]; + } + + /** + * Test convert different saved folders to a file/category field + * @dataProvider dataFileToArray + * + * @param string $file + * @param string $type + * @param array $array + */ + public function testFileToArray(string $file, string $type, array $array) + { + $this->assertEquals($array, FileTag::fileToArray($file, $type)); + } +}