+ public function fileNames() {
+ $cases = [];
+ $cases[] = ['helloworld.txt', TRUE];
+ $cases[] = ['../helloworld.txt', FALSE];
+ // Test case seems to be failing for a strange reason
+ // $cases[] = ['\helloworld.txt', FALSE];
+ $cases[] = ['.helloworld', FALSE];
+ $cases[] = ['smartwatch_1736683_1280_9af3657015e8660cc234eb1601da871.jpg', TRUE];
+ return $cases;
+ }
+
+ /**
+ * Test if the fileName is valid or not
+ * @dataProvider fileNames
+ * @param string $fileName
+ * @param bool $expectedResult
+ */
+ public function testFileNameValid($fileName, $expectedResult) {
+ $this->assertEquals($expectedResult, CRM_Utils_File::isValidFileName($fileName));
+ }
+
+ public function pathToFileExtension() {
+ $cases = [];
+ $cases[] = ['/evil.pdf', 'pdf'];
+ $cases[] = ['/helloworld.jpg', 'jpg'];
+ $cases[] = ['/smartwatch_1736683_1280_9af3657015e8660cc234eb1601da871.jpg', 'jpg'];
+ return $cases;
+ }
+
+ /**
+ * Test returning appropriate file extension
+ * @dataProvider pathToFileExtension
+ * @param string $path
+ * @param string $expectedExtension
+ */
+ public function testPathToExtension($path, $expectedExtension) {
+ $this->assertEquals($expectedExtension, CRM_Utils_File::getExtensionFromPath($path));
+ }
+
+ public function mimeTypeToExtension() {
+ $cases = [];
+ $cases[] = ['text/plain', ['txt', 'text', 'conf', 'def', 'list', 'log', 'in']];
+ $cases[] = ['image/jpeg', ['jpeg', 'jpg', 'jpe']];
+ $cases[] = ['image/png', ['png']];
+ return $cases;
+ }
+
+ /**
+ * @dataProvider mimeTypeToExtension
+ * @param stirng $mimeType
+ * @param array $expectedExtensions
+ */
+ public function testMimeTypeToExtension($mimeType, $expectedExtensions) {
+ $this->assertEquals($expectedExtensions, CRM_Utils_File::getAcceptableExtensionsForMimeType($mimeType));
+ }
+