1
0
Fork 0
Dieser Commit ist enthalten in:
DSB 2011-06-10 21:55:32 +00:00
Ursprung 2b21070b1a
Commit f7a7c71f86
1583 geänderte Dateien mit 454759 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,53 @@
<?php
/**
* @group Auth
*/
class Msd_Auth_Adapter_IniTest extends PHPUnit_Framework_TestCase
{
public $iniPath = null;
public $userIni = null;
public function setUp()
{
$this->iniPath = APPLICATION_PATH . DS .'configs';
$this->userIni = $this->iniPath . DS . 'users.ini';
}
public function testThrowsExceptionIfInvokedWithNonExistantIniFile()
{
try {
new Msd_Auth_Adapter_Ini(
$this->iniPath . '/I_dont_exist.ini'
);
} catch (Msd_Exception $e) {
$res = 'INI file with authentication information doesn\'t exists!';
$this->assertEquals($res, $e->getMessage());
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testThrowsExceptionIfUsernameIsNull()
{
$authAdapter = new Msd_Auth_Adapter_Ini($this->userIni);
$authAdapter->setUsername(null);
try {
$authAdapter->authenticate();
} catch (Msd_Exception $e) {
$res = 'You must set the username and password first!';
$this->assertEquals($res, $e->getMessage());
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCanFailAuthIfCredentialsAreWrong()
{
$authAdapter = new Msd_Auth_Adapter_Ini($this->userIni);
$authAdapter->setUsername('iDontExist');
$authAdapter->setPassword('iAmWrong');
$authResult = $authAdapter->authenticate();
$res = $authResult->getCode();
$this->assertEquals($res, Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID);
}
}

Datei anzeigen

@ -0,0 +1,23 @@
<?php
/**
* @group configuration
*/
class Msd_ConfigurationPhpValuesTest extends PHPUnit_Framework_TestCase
{
public function testCanFallbackTo30SecondsExecutionTime()
{
ini_set('max_execution_time', 31);
$dynamicValues = Msd_ConfigurationPhpValues::getDynamicValues();
$this->assertEquals(30, $dynamicValues->maxExecutionTime);
}
public function testCanFallbackTo16MbRam()
{
$activeValue = ini_get('memory_limit');
ini_set('memory_limit', '15M');
$dynamicValues = Msd_ConfigurationPhpValues::getDynamicValues();
// reset value to not break tests
ini_set('memory_limit', $activeValue);
$this->assertEquals(16, $dynamicValues->phpRam);
}
}

Datei anzeigen

@ -0,0 +1,237 @@
<?php
/**
* @group configuration
*/
class Msd_ConfigurationTest extends ControllerTestCase
{
public static function setUpBeforeClass()
{
Testhelper::copyFile('mysqldumper.ini', CONFIG_PATH . DS .'mysqldumper.ini');
Testhelper::copyFile('mysqldumper2.ini', CONFIG_PATH . DS .'mysqldumper2.ini');
}
public static function tearDownAfterClass()
{
Testhelper::removeFile(CONFIG_PATH . DS . 'mysqldumper2.ini');
}
public function setUp()
{
$this->loginUser();
}
public function testThrowsExceptionOnCloning()
{
$config = Msd_Configuration::getInstance();
try {
clone($config);
} catch (Exception $e) {
$this->assertInstanceof('Msd_Exception', $e);
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCanSetValues()
{
$config = Msd_Configuration::getInstance();
$config->set('config.testval', 999);
$this->assertEquals(999, $config->get('config.testval'));
$config->set('config.interface.testval2', 999);
$this->assertEquals(999, $config->get('config.interface.testval2'));
}
/**
* @expectedException Msd_Exception
*/
public function testCanThrowExceptionOnSettingIllegalValue()
{
$config = Msd_Configuration::getInstance();
$config->set('config.t.r.t.v', 999);
}
public function testCanReloadConfig()
{
$config = Msd_Configuration::getInstance();
$config->set('config.general.dbDelete', 'y'); //defaults to 'n'
$this->assertEquals('y', $config->get('config.general.dbDelete'));
$config->reloadConfig();
$this->assertEquals('n', $config->get('config.general.dbDelete'));
}
public function testCanGetValuesFromConfiguration()
{
$config = Msd_Configuration::getInstance();
// get complete config-array
$values = $config->get('config');
$this->assertArrayHasKey('interface', $values);
$this->assertArrayHasKey('dbuser', $values);
$this->assertArrayHasKey('cronscript', $values);
$this->assertArrayHasKey('cronscript', $values);
$this->assertArrayHasKey('ftp', $values);
$this->assertArrayHasKey('email', $values);
$this->assertArrayHasKey('autodelete', $values);
$this->assertArrayHasKey('general', $values);
//check some nested keys in different levels
$values = $config->get('config.general');
$this->assertArrayHasKey('mode', $values);
$this->assertArrayHasKey('title', $values);
$this->assertArrayHasKey('optimize', $values);
$value = $config->get('config.general.dbDelete');
$this->assertEquals('n', $value);
$values = $config->get('config.ftp.0');
$this->assertArrayHasKey('use', $values);
$this->assertArrayHasKey('server', $values);
$this->assertArrayHasKey('user', $values);
$value = $config->get('config.ftp.0.timeout');
$this->assertEquals(10, $value);
}
public function testCanReturnNullOnNonExistantConfigKey()
{
$config = Msd_Configuration::getInstance();
$value = $config->get('config.IDont.Exist');
$this->assertEquals(null, $value);
}
public function testCanThrowExceptionOnSettingIncorrectValue()
{
$config = Msd_Configuration::getInstance();
try {
$config->set('testval', 999);
} catch (Exception $e) {
$this->assertInstanceof('Msd_Exception', $e);
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCanThrowExceptionOnGettingIncorrectValue()
{
$config = Msd_Configuration::getInstance();
try {
$config->get('testval', 999);
} catch (Exception $e) {
$this->assertInstanceof('Msd_Exception', $e);
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCanLoadConfigFromSessionOnSameRequest()
{
$config = Msd_Configuration::getInstance();
$config->set('config.testval', 888);
$config->saveConfigToSession();
unset($config);
$config = Msd_Configuration::getInstance();
$config->loadConfigFromSession();
$this->assertEquals(888, $config->get('config.testval'));
// test constructor; should get filename and data from session
Msd_Configuration::getInstance();
}
public function testCanLoadConfiguration()
{
$config = Msd_Configuration::getInstance('mysqldumper', true);
$this->assertEquals('mysqldumper', $config->get('dynamic.configFile'));
// load another configuration and set values to actual session
$config->loadConfiguration('mysqldumper2', true);
$this->assertEquals('mysqldumper2', $config->get('dynamic.configFile'));
}
public function testCanLoadConfigWithoutApplying()
{
$config = Msd_Configuration::getInstance('mysqldumper', true);
$this->assertEquals('mysqldumper', $config->get('dynamic.configFile'));
// load data from another config file but without using it
$configData = $config->loadConfiguration('mysqldumper2', false);
$this->assertInstanceOf('Zend_Config_Ini', $configData);
$this->assertEquals(
'MySQLDumper2',
$configData->general->title
);
$this->assertEquals(
'pl',
$configData->cronscript->perlExtension
);
// make sure the actual config didn't change
$this->assertEquals('mysqldumper', $config->get('dynamic.configFile'));
}
public function testThrowsExceptionOnLoadNonExistantConfigfile()
{
$config = Msd_Configuration::getInstance();
try {
$config->loadConfiguration('IDontExist');
} catch (Exception $e) {
$this->assertInstanceof('Msd_Exception', $e);
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCanGetConfigTitle()
{
$config = Msd_Configuration::getInstance();
$config->loadConfiguration('mysqldumper');
$title = $config->getTitle();
$this->assertEquals('MySQLDumper', $title);
$config->loadConfiguration('mysqldumper2');
$title = $config->getTitle();
$this->assertEquals('MySQLDumper2', $title);
}
/**
* @depends testCanLoadConfiguration
*/
public function testCanSaveConfiguration()
{
$config = Msd_Configuration::getInstance();
$config->loadConfiguration('mysqldumper2');
// change a value
$config->set('config.cronscript.Path', 'IAmAPath');
$config->save('mysqldumper2');
// reload it and check changed val
$config->loadConfiguration('mysqldumper2');
$this->assertEquals('IAmAPath', $config->get('config.cronscript.Path'));
// change val again
$config->set('config.cronscript.Path', 'IDiffer');
// now save without giving the filename; should be taken from session
$config->save();
// reload it and again check changed val
$config->loadConfiguration('mysqldumper2');
$this->assertEquals('IDiffer', $config->get('config.cronscript.Path'));
// reset val for further tests
$config->set('config.cronscript.Path', '');
$config->save();
}
/**
* @depends testCanSaveConfiguration
*/
public function testCanSaveConfigFromArray()
{
$config = Msd_Configuration::getInstance();
$config->loadConfiguration('mysqldumper2');
// change title and save as new file
$config->set('config.general.title', 'MySQLDumper3');
$configData =$config->get('config');
$this->assertTrue(is_array($configData));
$config->save('mysqldumper3', $configData);
$configFile = $config->get('paths.config').'/mysqldumper3.ini';
$this->assertFileExists($configFile);
$config->loadConfiguration('mysqldumper3');
$title = $config->get('config.general.title');
$this->assertEquals('MySQLDumper3', $title);
Testhelper::removeFile(CONFIG_PATH . DS . 'mysqldumper3.ini');
}
}

Datei anzeigen

@ -0,0 +1,36 @@
<?php
/**
* @group database
*/
class Msd_DbTest extends ControllerTestCase
{
public function setUp()
{
$this->loginUser();
}
public function testCanGetMysqliInstance()
{
$dbo = Msd_Db::getAdapter();
$this->assertInstanceOf('Msd_Db_Mysqli', $dbo);
}
public function testCanGetMysqlInstance()
{
$dbo = Msd_Db::getAdapter(null, true);
$this->assertInstanceOf('Msd_Db_Mysql', $dbo);
}
public function testThrowsExceptionOnInvalidQuery()
{
$dbo = Msd_Db::getAdapter();
try {
$dbo->query('I am not a valid query');
} catch (Exception $e) {
$this->assertInstanceOf('Msd_Exception', $e);
$this->assertEquals(1064, $e->getCode());
return;
}
$this->fail('An expected exception has not been raised.');
}
}

Datei anzeigen

@ -0,0 +1,32 @@
<?php
/**
* @group Files
*/
class Msd_FileTest extends PHPUnit_Framework_TestCase
{
public function testCanGetChmodValueOfFile()
{
$valid = array('0644', '664', '666', '0755', '0777');
$res = Msd_File::getChmod(CONFIG_PATH . '/mysqldumper.ini');
$this->assertTrue(in_array($res, $valid));
}
public function testCanGetConfigurationNames()
{
$configNames = Msd_File::getConfigNames();
$this->assertNotEmpty($configNames);
$this->assertTrue(in_array('mysqldumper', $configNames));
}
public function testRetrunsEmptyArrayIfPathIsNotReadable()
{
$config = Msd_Configuration::getInstance();
$oldPath = $config->get('paths.config');
$config->set('paths.config', '/I/Dont/Exist');
$configNames = Msd_File::getConfigNames();
$config->set('paths.config', $oldPath);
$this->assertTrue(is_array($configNames));
$this->assertEmpty($configNames);
}
}

Datei anzeigen

@ -0,0 +1,86 @@
<?php
/**
* @group html
*/
class Msd_HtmlTest extends PHPUnit_Framework_TestCase
{
public function testCanConvertNewLines()
{
$expected = 'alert("hello");\nalert("hello2");';
$res = Msd_Html::getJsQuote("alert(\"hello\");\nalert(\"hello2\");", false);
$this->assertEquals($expected, $res);
}
public function testCanBuildJsQuotedStringAndEscapesSlashes()
{
$expected = 'alert(\"hello\/\");';
$res = Msd_Html::getJsQuote('alert("hello/");', true);
$this->assertEquals($expected, $res);
}
public function testCanCreatePrefixArray()
{
$array = array(
'name_one' => 1,
'name_two' => 1,
'name_three' => 1,
'name2_one' => 1,
'name2_two' => 1,
'name2_three' => 1,
'name3' => 1,
'name4_one' => 1,
'name4_two' => 1
);
$res = Msd_Html::getPrefixArray($array);
$expected = array(
'name' => 'name',
'name2' => 'name2',
'name4' => 'name4'
);
$this->assertSame($expected, $res);
}
public function testCanBuildHtmlOptions()
{
$options = array(
'first' => 0,
'second' => 1,
'third' => 2
);
$res = Msd_Html::getHtmlOptions($options, '', false);
$expected = "<option value=\"first\">0</option>\n"
. "<option value=\"second\">1</option>\n"
."<option value=\"third\">2</option>\n";
$this->assertSame($expected, $res);
}
public function testCanBuildHtmlOptionsWithSeletedOption()
{
$options = array(
'first' => 0,
'second' => 1,
'third' => 2
);
$res = Msd_Html::getHtmlOptions($options, 'second', false);
$expected = "<option value=\"first\">0</option>\n"
. "<option value=\"second\" selected=\"selected\">1</option>\n"
. "<option value=\"third\">2</option>\n";
$this->assertSame($expected, $res);
}
public function testCanBuildHtmlOptionsAndShowAllOption()
{
$options = array(
'first' => 0,
'second' => 1,
'third' => 2
);
$res = Msd_Html::getHtmlOptions($options, 'second', true);
$expected = "<option value=\"\">---</option>\n"
. "<option value=\"first\">0</option>\n"
. "<option value=\"second\" selected=\"selected\">1</option>\n"
. "<option value=\"third\">2</option>\n";
$this->assertSame($expected, $res);
}
}

Datei anzeigen

@ -0,0 +1,121 @@
<?php
/**
* @group language
*/
class Msd_LanguageTest extends ControllerTestCase
{
private $_lang = null;
private $_translator = null;
private $_languages = array();
public function setUp()
{
$this->_lang = Msd_Language::getInstance();
$this->_translator = $this->_lang->getTranslator();
$this->_languages = $this->_lang->getAvailableLanguages();
}
public function testCanGetInstance()
{
$this->assertInstanceOf('Msd_Language', $this->_lang);
}
public function testCanGetTranslator()
{
$this->assertInstanceOf('Zend_Translate', $this->_translator);
}
public function testCanLoadLanguageEn()
{
$this->_lang->loadLanguage('en');
$this->assertEquals('yes', $this->_translator->translate('L_YES'));
}
public function testCanLoadLanguageDe()
{
$this->_lang->loadLanguage('de');
$this->assertEquals('ja', $this->_translator->translate('L_YES'));
}
public function testCanLoadAndTranslateAllLanguageFiles()
{
$languages = array_keys($this->_languages);
foreach ($languages as $language) {
$this->_lang->loadLanguage($language);
$this->assertNotEquals(
'L_YES',
$this->_translator->translate('L_YES')
);
}
}
public function testCanUseMagicGetter()
{
$this->_lang->loadLanguage('de');
$this->assertEquals('ja', $this->_lang->L_YES);
}
public function testCanLoadLanguageList()
{
$isArray = is_array($this->_languages);
$this->assertEquals(true, $isArray);
}
public function testLanguageKeyExists()
{
$languages = array('ar', 'bg_BG', 'cs', 'da', 'de', 'de_CH', 'de_LU',
'el', 'en', 'es', 'fa', 'fr', 'it', 'nl', 'pl', 'pt_BR', 'ro', 'ru',
'sk', 'sl', 'sv_SE', 'tr', 'vi_VN'
);
foreach ($languages as $language) {
$this->assertArrayHasKey($language, $this->_languages);
}
}
public function testReturnsOriginalInputForUnsetValues()
{
$this->assertEquals(
'No Translation',
$this->_translator->translate('No Translation')
);
}
public function testCanTranslateZendIds()
{
$this->_lang->loadLanguage("de");
$zendmessageId = 'emailAddressInvalidFormat';
$translation = $this->_lang->translateZendId($zendmessageId);
$this->assertEquals(
"Das Format der E-Mail-Adresse ist ungültig.",
$translation
);
}
public function testWontTranslateAlreadyTranslatedZendIds()
{
$this->_lang->loadLanguage("de");
$zendmessageId = 'accessFilter';
$translation = $this->_lang->translateZendId($zendmessageId, 'accessFilter');
$this->assertEquals("accessFilter", $translation
);
}
public function testReturnsUntranslatedStringWithoutPrefixIfMessageIsUnknown()
{
$this->_lang->loadLanguage("de");
$res = $this->_lang->L_IDONTEXIST;
$this->assertEquals("IDONTEXIST", $res);
}
public function testForbidsCloning()
{
try {
clone($this->_lang);
} catch (Msd_Exception $e) {
$res = 'Cloning of Msd_Language is not allowed!';
$this->assertEquals($res, $e->getMessage());
return;
}
$this->fail('An expected exception has not been raised.');
}
}

Datei anzeigen

@ -0,0 +1,71 @@
<?php
/**
* @group Log
*/
class Msd_LogTest extends PHPUnit_Framework_TestCase
{
public function testCanGetLogger()
{
$logger = new Msd_Log();
$this->assertInstanceof('Msd_Log', $logger);
}
public function testCanGetFilePathOfLoggerType()
{
$logger = new Msd_Log();
$this->assertInstanceof('Msd_Log', $logger);
$logPath = $logger->getFile(Msd_Log::PHP);
$this->assertEquals(WORK_PATH . '/log/php.log', $logPath);
$logPath = $logger->getFile(Msd_Log::PERL);
$this->assertEquals(WORK_PATH . '/log/perl.log', $logPath);
$logPath = $logger->getFile(Msd_Log::PERL_COMPLETE);
$this->assertEquals(WORK_PATH . '/log/perlComplete.log', $logPath);
$logPath = $logger->getFile(Msd_Log::ERROR);
$this->assertEquals(WORK_PATH . '/log/phpError.log', $logPath);
}
public function testCanGetLoggerOfGivenType()
{
$logger = new Msd_Log();
$this->assertInstanceof('Msd_Log', $logger);
$loggerTypes = array(
Msd_Log::PHP => WORK_PATH . '/log/php.log',
Msd_Log::PERL => WORK_PATH . '/log/perl.log',
Msd_Log::PERL_COMPLETE => WORK_PATH . '/log/perlComplete.log',
Msd_Log::ERROR => WORK_PATH . '/log/phpError.log',
);
foreach ($loggerTypes as $logType => $logPath) {
$this->assertInstanceof('Zend_Log', $logger->getLogInstance($logType));
$this->assertEquals($logger->getFile($logType), $logPath);
}
}
public function testClosesFileHandlesOnDestroy()
{
$logger = new Msd_Log();
$this->assertInstanceof('Msd_Log', $logger);
$loggerTypes = array(
Msd_Log::PHP => WORK_PATH . '/log/php.log',
Msd_Log::PERL => WORK_PATH . '/log/perl.log',
Msd_Log::PERL_COMPLETE => WORK_PATH . '/log/perlComplete.log',
Msd_Log::ERROR => WORK_PATH . '/log/phpError.log',
);
foreach ($loggerTypes as $logType => $logPath) {
$this->assertInstanceof('Zend_Log', $logger->getLogInstance($logType));
$this->assertEquals($logger->getFile($logType), $logPath);
}
unset($logger);
}
public function testCanWriteToLogFile()
{
$res = Msd_Log::write(Msd_Log::PHP, 'test message');
print_r($res);
}
}

Datei anzeigen

@ -0,0 +1,68 @@
<?php
if (get_current_user() != 'root') {
include_once(TEST_PATH . '/unit/library/Msd/Validate/File/AccessibleTest.php');
// Exclude this test if called via cli.
// phpunit seems to always run as user "root", no matter how we call it.
// If we call phpunti from Jenkins (which has its own user) via Ant phpunit
// is executed as root. If we call it from the shell as user "msd", phpunit is
// run as root. I didn't find a way to let phpunit run as another user.
//
// Of course the user root can always set chmod values, so these tests
// wouldn't make sense. To get rid of the nasty "skipped test"
// messages if working in the shell, I only let phpunit execute these tests
// if it is not running as root.
// After excluding and/or blacklisting this file in phpunit.xml didn't work either
// I am upset and simply want to get rid of this.
// S. Bergmann, you have taken away hours of my time because things
// doesn't work the way they are described in your documentation.
// Better hope we will not meet again in real life. ;)
class Msd_Validate_File_NonRootAccessibleTest extends Msd_Validate_File_AccessibleTest
{
public function testCanDetectIfFileIsNotReadable()
{
if (get_current_user() == 'root') {
$this->markTestIncomplete('This test can not be run as user root.');
return;
}
$this->chmod(0100);
$this->validator->setOptions(array('accessTypes' => "read"));
$this->assertEquals(false, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileIsNotWritable()
{
if (get_current_user() == 'root') {
$this->markTestIncomplete('This test can not be run as user root.');
return;
}
$this->chmod(0400);
$this->validator->setOptions(array('accessTypes' => "write"));
$this->assertEquals(false, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfDirIsNotReadable()
{
if (get_current_user() == 'root') {
$this->markTestIncomplete('This test can not be run as user root.');
return;
}
$this->chmod(0100, $this->_testDir);
$this->validator->setOptions(array('accessTypes' => "dir,read"));
$this->assertEquals(false, $this->validator->isValid($this->_testDir));
$this->chmod(0700, $this->_testDir);
}
public function testCanDetectIfDirIsNotWritable()
{
if (get_current_user() == 'root') {
$this->markTestIncomplete('This test can not be run as user root.');
return;
}
$this->chmod(0400, $this->_testDir);
$this->validator->setOptions(array('accessTypes' => "dir,write"));
$this->assertEquals(false, $this->validator->isValid($this->_testDir));
$this->chmod(0700, $this->_testDir);
}
}
}

Datei anzeigen

@ -0,0 +1,236 @@
<?php
/**
* @group validate
*/
class Msd_Validate_File_AccessibleTest extends PHPUnit_Framework_TestCase
{
/**
* @var string Path to test files
*/
protected $_testFile = '';
/**
* @var string Path to test files
*/
protected $_testDir = '';
/**
* @var Msd_Validate_File_Accessible
*/
protected $validator = null;
public function setUp()
{
parent::setUp();
$this->_testDir = TEST_PATH . DS . 'fixtures' . DS . 'tmp';
if (!file_exists($this->_testDir)) {
mkdir($this->_testDir, 0777);
$this->chmod(0777, $this->_testDir);
}
$this->_testFile = $this->_testDir . '/testFile.sh';
if (!file_exists($this->_testFile)) {
file_put_contents($this->_testFile, "#!/bin/sh\necho 'Executed'\n");
$this->chmod(0777);
}
$this->validator = new Msd_Validate_File_Accessible();
}
/**
* Chmod _testFile to given value
*
* @param string $rights Octal rights
* @param bool $file FileName
* @return void
*/
public function chmod($rights, $file = false)
{
if ($file === false) {
$file = $this->_testFile;
}
$chmod = chmod($file, $rights);
clearstatcache();
if ($chmod === false) {
$this->fail('Couldn\'t chmod ' . $file . ' to ' . $rights);
}
}
public function testCanDetectIfFileExists()
{
$this->chmod(0400);
$this->assertEquals(true, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileDoesNotExists()
{
$file = $this->_testDir . '/IDontExist.txt';
$this->assertEquals(false, $this->validator->isValid($file));
}
public function testCanDetectIfFileIsReadable()
{
$this->chmod(0400);
$this->validator->setOptions(array('accessTypes' => "read"));
$this->assertEquals(true, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileIsWritable()
{
$this->chmod(0200);
$this->validator->setOptions(array('accessTypes' => "write"));
$this->assertEquals(true, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileIsExecutable()
{
$this->chmod(0100);
$this->validator->setOptions(array('accessTypes' => "execute"));
$this->assertEquals(true, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileIsNotExecutable()
{
$this->chmod(0400);
$this->validator->setOptions(array('accessTypes' => "execute"));
$this->assertEquals(false, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileIsDir()
{
$this->chmod(0777, $this->_testDir);
$this->validator->setOptions(array('accessTypes' => "dir"));
$this->assertEquals(true, $this->validator->isValid($this->_testDir));
}
public function testCanDetectIfFileIsNotDir()
{
$this->validator->setOptions(array('accessTypes' => "dir"));
$this->assertEquals(false, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileIsFile()
{
$this->chmod(0700);
$this->validator->setOptions(array('accessTypes' => "file"));
$this->assertEquals(true, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfFileIsNotAFile()
{
$this->chmod(0700, $this->_testDir);
$this->validator->setOptions(array('accessTypes' => "file"));
$this->assertEquals(false, $this->validator->isValid($this->_testDir));
}
public function testCanDetectIfFileIsNotUploaded()
{
$this->chmod(0700);
$this->validator->setOptions(array('accessTypes' => "uploaded"));
$this->assertEquals(false, $this->validator->isValid($this->_testFile));
}
public function testCanDetectIfDirIsReadable()
{
$this->chmod(0400, $this->_testDir);
$this->validator->setOptions(array('accessTypes' => "dir,read"));
$this->assertEquals(true, $this->validator->isValid($this->_testDir));
$this->chmod(0700, $this->_testDir);
}
public function testCanDetectIfDirIsWritable()
{
$this->chmod(0200, $this->_testDir);
$this->validator->setOptions(array('accessTypes' => "dir,write"));
$this->assertEquals(true, $this->validator->isValid($this->_testDir));
$this->chmod(0700, $this->_testDir);
}
public function testCanSetOptionsWithAccessTypesAsString()
{
$this->validator->setOptions(
array(
'pathPrefix' => './',
'accessTypes' => 'read,write'
)
);
$options = $this->validator->getOptions();
$this->assertInternalType('array', $options);
$this->assertArrayHasKey('pathPrefix', $options);
$this->assertEquals('./', $options['pathPrefix']);
$this->assertInternalType('array', $options['accessTypes']);
$this->assertTrue($options['accessTypes']['read']);
$this->assertTrue($options['accessTypes']['write']);
}
public function testCanSetOptionsWithAccessTypesAsZendConfig()
{
$this->validator->setOptions(
array(
'pathPrefix' => './',
'accessTypes' => new Zend_Config(array('read', 'write')),
)
);
$options = $this->validator->getOptions();
$this->assertInternalType('array', $options);
$this->assertArrayHasKey('pathPrefix', $options);
$this->assertEquals('./', $options['pathPrefix']);
$this->assertInternalType('array', $options['accessTypes']);
$this->assertTrue($options['accessTypes']['read']);
$this->assertTrue($options['accessTypes']['write']);
}
public function testCanSetOptionsWithAccessTypesAsArray()
{
$this->validator->setOptions(
array(
'pathPrefix' => './',
'accessTypes' => array('read', 'write'),
)
);
$options = $this->validator->getOptions();
$this->assertInternalType('array', $options);
$this->assertArrayHasKey('pathPrefix', $options);
$this->assertEquals('./', $options['pathPrefix']);
$this->assertInternalType('array', $options['accessTypes']);
$this->assertTrue($options['accessTypes']['read']);
$this->assertTrue($options['accessTypes']['write']);
}
public function testClassConstructorSetsOptions()
{
$validator = new Msd_Validate_File_Accessible(
array(
'pathPrefix' => './',
'accessTypes' => array('read', 'write'),
)
);
$options = $validator->getOptions();
$this->assertInternalType('array', $options);
$this->assertArrayHasKey('pathPrefix', $options);
$this->assertEquals('./', $options['pathPrefix']);
$this->assertInternalType('array', $options['accessTypes']);
$this->assertTrue($options['accessTypes']['read']);
$this->assertTrue($options['accessTypes']['write']);
}
/**
* @expectedException Msd_Validate_Exception
*/
public function testThrowsExceptionIfOptionsArgumentIsNotAnArray()
{
$this->validator->setOptions('Go test and throw the exception.');
}
/**
* @expectedException Msd_Validate_Exception
*/
public function testThrowsExceptionIfAccessTypesOptionIsAnInvalidVariableType()
{
$this->validator->setOptions(array('accessTypes' => new stdClass()));
}
}

Datei anzeigen

@ -0,0 +1,38 @@
<?php
/**
* @group configuration
*/
class Msd_VersionTest extends PHPUnit_Framework_TestCase
{
public $version = null;
public function setUp()
{
$this->version = new Msd_Version();
$options = array(
'requiredPhpVersion' => '99.99.99',
'requiredMysqlVersion' => '99.99.99'
);
$this->oldVersion = new Msd_Version($options);
}
public function testCanGetRequiredPhpVersion()
{
$this->assertEquals('5.2.0', $this->version->getRequiredPhpVersion());
}
public function testCanDetectOldPhpVersion()
{
$this->assertEquals(false, $this->oldVersion->checkPhpVersion());
}
public function testCanGetRequiredMysqlVersion()
{
$this->assertEquals('4.1.2', $this->version->getRequiredMysqlVersion());
}
public function testCanDetectOldMysqlVersion()
{
$this->assertEquals(false, $this->oldVersion->checkMysqlVersion());
}
}