From 6ec998f4edd44fbb829d7855cbc095895778520f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimondas=20Rimkevi=C4=8Dius?= Date: Wed, 4 Nov 2015 12:01:06 +0200 Subject: [PATCH] Added files test and corrected some names --- .../icms/{FileTest.php => DataFileTest.php} | 2 +- tests/libraries/icms/FilesTest.php | 122 ++++++++++++++++++ tests/libraries/icms/VersionCheckerTest.php | 2 +- 3 files changed, 124 insertions(+), 2 deletions(-) rename tests/libraries/icms/{FileTest.php => DataFileTest.php} (96%) create mode 100644 tests/libraries/icms/FilesTest.php diff --git a/tests/libraries/icms/FileTest.php b/tests/libraries/icms/DataFileTest.php similarity index 96% rename from tests/libraries/icms/FileTest.php rename to tests/libraries/icms/DataFileTest.php index 2e900cbccef4..83d17cacf01d 100644 --- a/tests/libraries/icms/FileTest.php +++ b/tests/libraries/icms/DataFileTest.php @@ -2,7 +2,7 @@ namespace ImpressCMS\Tests\Libraries\ICMS; -class FileTest extends \PHPUnit_Framework_TestCase { +class DataFileTest extends \PHPUnit_Framework_TestCase { /** * Test if icms_core_DataFilter is available diff --git a/tests/libraries/icms/FilesTest.php b/tests/libraries/icms/FilesTest.php new file mode 100644 index 000000000000..1c38d731fc24 --- /dev/null +++ b/tests/libraries/icms/FilesTest.php @@ -0,0 +1,122 @@ + null, + 'icms_file_MediaUploadHandler' => null, + 'icms_file_TarDownloader' => 'icms_file_DownloadHandler', + 'icms_file_TarFileHandler' => null, + 'icms_file_ZipDownloader' => 'icms_file_DownloadHandler', + 'icms_file_ZipFileHandler' => null + ] as $class => $must_be_instance_of) { + $this->assertTrue(class_exists($class, true), $class . " class doesn't exist"); + if ($must_be_instance_of !== null) { + $instance = $this->getClassInstance($class); + $this->assertTrue( $instance instanceof $must_be_instance_of, $class . " is not instanceof " . $must_be_instance_of); + } + } + } + + /** + * Gets instance of class from classname + * + * @param string $class ClassName + * + * @return object + */ + private function getClassInstance($class) { + $reflection = new \ReflectionClass($class); + if ($reflection->isAbstract()) { + $instance = $this->getMockForAbstractClass($class); + } else { + $instance = $this->getMockBuilder($class) + ->disableOriginalConstructor() + ->getMock(); + } + return $instance; + } + + /** + * Test methods availability + */ + public function testMethodsAvailability() { + foreach ([ + 'icms_file_DownloadHandler' => [ + 'addFile', + 'addBinaryFile', + 'addFileData', + 'addBinaryFileData', + 'download' + ], + 'icms_file_MediaUploadHandler' => [ + 'fetchFromURL', + 'fetchMedia', + 'getUploadErrorText', + 'setTargetFileName', + 'getMediaName', + 'getMediaType', + 'getMediaSize', + 'getMediaTmpName', + 'getSavedFileName', + 'getSavedDestination', + 'upload', + 'checkMaxFileSize', + 'checkMaxWidth', + 'checkMaxHeight', + 'checkMimeType', + 'checkImageType', + 'sanitizeMultipleExtensions', + 'setErrors', + 'getErrors' + ], + 'icms_file_TarFileHandler' => [ + 'openTAR', + 'appendTar', + 'getFile', + 'getDirectory', + 'containsFile', + 'containsDirectory', + 'addDirectory', + 'addFile', + 'removeFile', + 'removeDirectory', + 'saveTar', + 'toTar', + 'toTarOutput' + ], + 'icms_file_ZipFileHandler' => [ + 'addFile', + 'file' + ] + ] as $class => $methods) { + foreach ($methods as $method) { + $this->assertTrue(method_exists($class, $method), 'Static method ' . $method . ' doesn\'t exists for class ' . $class); + } + } + } + + /** + * Tests variables availability and types + */ + public function testVariables() { + foreach ([ + 'icms_file_TarFileHandler' => [ + 'numFiles' => 'null', // int + 'files' => 'null' // array + ] + ] as $class => $variables) { + $instance = $this->getClassInstance($class); + foreach ($variables as $variable => $type) { + $this->assertInternalType($type, $instance->$variable, '$' . $variable . ' is not of type ' . $type . ' in instance of ' . $class); + } + } + } + +} \ No newline at end of file diff --git a/tests/libraries/icms/VersionCheckerTest.php b/tests/libraries/icms/VersionCheckerTest.php index dc5d7bcb1134..075ac6fa56f9 100644 --- a/tests/libraries/icms/VersionCheckerTest.php +++ b/tests/libraries/icms/VersionCheckerTest.php @@ -5,7 +5,7 @@ class VersionCheckerTest extends \PHPUnit_Framework_TestCase { /** - * Test if icms_core_DataFilter is available + * Test if is available */ public function testAvailability() { $this->assertTrue(class_exists('icms_core_Versionchecker', true), "icms_core_Versionchecker class doesn't exist");