Skip to content

Commit

Permalink
added config test
Browse files Browse the repository at this point in the history
  • Loading branch information
MekDrop committed Oct 30, 2015
1 parent da9ce6f commit 309e63b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/libraries/icms/ConfigTest.php
@@ -0,0 +1,59 @@
<?php

namespace ImpressCMS\Tests\Libraries\ICMS;

class ConfigTest extends \PHPUnit_Framework_TestCase {

/**
* Tests availability
*/
public function testAvailability() {
foreach (['category', 'Item', 'option'] as $name) {
foreach (['Handler' => 'icms_ipf_Handler', 'Object' => 'icms_ipf_Object'] as $type => $instanecOfType) {
$class = 'icms_config_' . $name . '_' . $type;
$this->assertTrue(class_exists($class, true), $class . " class doesn't exist");

$instance = $this->getMockBuilder($class)
->disableOriginalConstructor()
->getMock();
$this->assertInternalType('object', $instance, $class. " is not an object");
$this->assertTrue($instance instanceof $instanecOfType, $class . ' doesn\'t extend ' . $instanecOfType);
}
}

$this->assertTrue(class_exists('icms_config_Handler', true), "icms_config_Handler auth method doesn't exists");
$instance = $this->getMockBuilder('icms_config_Handler')
->disableOriginalConstructor()
->getMock();
$this->assertInternalType('object', $instance, "icms_config_Handler auth method doesn't exists");
}

/**
* Tests if config category is ok
*/
public function testConfigHandler() {
$this->assertTrue(method_exists('icms_config_Handler', 'service'), 'service() method for config handler doesn\'t exist');
$service = \icms_config_Handler::service();
$this->assertTrue($service instanceof \icms_config_Handler, 'service method can\'t create good instance');
foreach ([ 'createConfig', 'getConfig', 'insertConfig', 'deleteConfig', 'getConfigs', 'getConfigCount', 'getConfigsByCat', 'createConfigOption', 'getConfigOption', 'getConfigOptions', 'getConfigOptionsCount', 'getConfigList' ] as $method) {
$this->assertTrue(method_exists($service, $method), $method . ' doesm\'t exists');
}
}

/**
* Tests if config category is ok
*/
public function testConfigCategoryConstants() {
$class = new \ReflectionClass('icms_config_Handler');
$cat_constants_count = 0;
foreach ($class->getConstants() as $name => $value) {
if (substr($name, 0, 4) != 'CAT_') {
continue;
}
$cat_constants_count++;
$this->assertInternalType('int', $value, $name . ' constant value is not of int type');
}
$this->assertGreaterThan(1, $cat_constants_count, 'No CATEGORY_* constants found in icms_config_category_Handler');
}

}

0 comments on commit 309e63b

Please sign in to comment.