Skip to content

Commit

Permalink
Added files test and corrected some names
Browse files Browse the repository at this point in the history
  • Loading branch information
MekDrop committed Nov 4, 2015
1 parent 92d309c commit 6ec998f
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 2 deletions.
Expand Up @@ -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
Expand Down
122 changes: 122 additions & 0 deletions tests/libraries/icms/FilesTest.php
@@ -0,0 +1,122 @@
<?php

namespace ImpressCMS\Tests\Libraries\ICMS;

class FilesTest extends \PHPUnit_Framework_TestCase {

/**
* Test if is available
*/
public function testAvailability() {
foreach ([
'icms_file_DownloadHandler' => 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);
}
}
}

}
2 changes: 1 addition & 1 deletion tests/libraries/icms/VersionCheckerTest.php
Expand Up @@ -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");
Expand Down

0 comments on commit 6ec998f

Please sign in to comment.