mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
EZ-Components
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
require_once 'init/base_init_callback.php';
|
||||
require_once 'init/base_init_class.php';
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseInitTest extends ezcTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
testBaseInitClass::$instance = null;
|
||||
}
|
||||
|
||||
public function testCallbackWithClassThatDoesNotExists()
|
||||
{
|
||||
try
|
||||
{
|
||||
ezcBaseInit::setCallback( 'testBaseInit', 'classDoesNotExist' );
|
||||
$this->fail( "Expected exception not thrown." );
|
||||
}
|
||||
catch ( ezcBaseInitInvalidCallbackClassException $e )
|
||||
{
|
||||
$this->assertEquals( "Class 'classDoesNotExist' does not exist, or does not implement the 'ezcBaseConfigurationInitializer' interface.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testCallbackWithClassThatDoesNotImplementTheInterface()
|
||||
{
|
||||
try
|
||||
{
|
||||
ezcBaseInit::setCallback( 'testBaseInit', 'ezcBaseFeatures' );
|
||||
$this->fail( "Expected exception not thrown." );
|
||||
}
|
||||
catch ( ezcBaseInitInvalidCallbackClassException $e )
|
||||
{
|
||||
$this->assertEquals( "Class 'ezcBaseFeatures' does not exist, or does not implement the 'ezcBaseConfigurationInitializer' interface.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testCallback1()
|
||||
{
|
||||
$obj = testBaseInitClass::getInstance();
|
||||
$this->assertEquals( false, $obj->configured );
|
||||
}
|
||||
|
||||
public function testCallback2()
|
||||
{
|
||||
ezcBaseInit::setCallback( 'testBaseInit', 'testBaseInitCallback' );
|
||||
$obj = testBaseInitClass::getInstance();
|
||||
$this->assertEquals( true, $obj->configured );
|
||||
}
|
||||
|
||||
public function testCallback3()
|
||||
{
|
||||
try
|
||||
{
|
||||
ezcBaseInit::setCallback( 'testBaseInit', 'testBaseInitCallback' );
|
||||
$this->fail( "Expected exception not thrown." );
|
||||
}
|
||||
catch ( ezcBaseInitCallbackConfiguredException $e )
|
||||
{
|
||||
$this->assertEquals( "The 'testBaseInit' is already configured with callback class 'testBaseInitCallback'.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite("ezcBaseInitTest");
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/test_options.php';
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseOptionsTest extends ezcTestCase
|
||||
{
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite("ezcBaseOptionsTest");
|
||||
}
|
||||
|
||||
public function testGetAccessFailure()
|
||||
{
|
||||
$opt = new ezcBaseTestOptions();
|
||||
try
|
||||
{
|
||||
echo $opt->properties;
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->fail( "ezcBasePropertyNotFoundException not thrown on access to forbidden property \$properties" );
|
||||
}
|
||||
|
||||
public function testGetOffsetAccessFailure()
|
||||
{
|
||||
$opt = new ezcBaseTestOptions();
|
||||
try
|
||||
{
|
||||
echo $opt["properties"];
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->fail( "ezcBasePropertyNotFoundException not thrown on access to forbidden property \$properties" );
|
||||
}
|
||||
|
||||
public function testSetOffsetAccessFailure()
|
||||
{
|
||||
$opt = new ezcBaseTestOptions();
|
||||
try
|
||||
{
|
||||
$opt["properties"] = "foo";
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->fail( "ezcBasePropertyNotFoundException not thrown on access to forbidden property \$properties" );
|
||||
}
|
||||
|
||||
public function testConstructorWithParameters()
|
||||
{
|
||||
$options = new ezcBaseTestOptions( array( 'foo' => 'xxx' ) );
|
||||
$this->assertEquals( 'xxx', $options->foo );
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
{
|
||||
$options = new ezcBaseTestOptions();
|
||||
$this->assertEquals( 'bar', $options->foo );
|
||||
$options->merge( array( 'foo' => 'xxx' ) );
|
||||
$this->assertEquals( 'xxx', $options->foo );
|
||||
}
|
||||
|
||||
public function testOffsetExists()
|
||||
{
|
||||
$options = new ezcBaseTestOptions();
|
||||
$this->assertEquals( true, $options->offsetExists( 'foo' ) );
|
||||
$this->assertEquals( false, $options->offsetExists( 'bar' ) );
|
||||
}
|
||||
|
||||
public function testOffsetSet()
|
||||
{
|
||||
$options = new ezcBaseTestOptions();
|
||||
$this->assertEquals( 'bar', $options->foo );
|
||||
$options->offsetSet( 'foo', 'xxx' );
|
||||
$this->assertEquals( 'xxx', $options->foo );
|
||||
}
|
||||
|
||||
public function testOffsetUnset()
|
||||
{
|
||||
$options = new ezcBaseTestOptions();
|
||||
$this->assertEquals( 'bar', $options->foo );
|
||||
$options->offsetUnset( 'foo' );
|
||||
$this->assertEquals( null, $options->foo );
|
||||
$this->assertEquals( true, $options->offsetExists( 'foo' ) );
|
||||
}
|
||||
|
||||
public function testAutoloadOptions()
|
||||
{
|
||||
$options = new ezcBaseAutoloadOptions();
|
||||
|
||||
try
|
||||
{
|
||||
$options->no_such_property = 'value';
|
||||
$this->fail( 'Expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "No such property name 'no_such_property'.", $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$options->preload = 'wrong value';
|
||||
$this->fail( 'Expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBaseValueException $e )
|
||||
{
|
||||
$this->assertEquals( "The value 'wrong value' that you were trying to assign to setting 'preload' is invalid. Allowed values are: bool.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,497 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseTest extends ezcTestCase
|
||||
{
|
||||
/*
|
||||
* For use with the method testInvalidClass().
|
||||
*/
|
||||
private $errorMessage = null;
|
||||
|
||||
public function testConfigExceptionUnknownSetting()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseSettingNotFoundException( 'broken' );
|
||||
}
|
||||
catch ( ezcBaseSettingNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The setting 'broken' is not a valid configuration setting.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testConfigExceptionOutOfRange1()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseSettingValueException( 'broken', 42 );
|
||||
}
|
||||
catch ( ezcBaseSettingValueException $e )
|
||||
{
|
||||
$this->assertEquals( "The value '42' that you were trying to assign to setting 'broken' is invalid.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testConfigExceptionOutOfRange2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseSettingValueException( 'broken', 42, "int, 40 - 48" );
|
||||
}
|
||||
catch ( ezcBaseSettingValueException $e )
|
||||
{
|
||||
$this->assertEquals( "The value '42' that you were trying to assign to setting 'broken' is invalid. Allowed values are: int, 40 - 48", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testConfigExceptionOutOfRange3()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseSettingValueException( 'broken', array(1, 1, 3, 4, 5), 'int' );
|
||||
}
|
||||
catch ( ezcBaseSettingValueException $e )
|
||||
{
|
||||
$this->assertEquals( "The value 'a:5:{i:0;i:1;i:1;i:1;i:2;i:3;i:3;i:4;i:4;i:5;}' that you were trying to assign to setting 'broken' is invalid. Allowed values are: int", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileIoException1()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::READ );
|
||||
}
|
||||
catch ( ezcBaseFileIoException $e )
|
||||
{
|
||||
$this->assertEquals( "An error occurred while reading from 'testfile.php'.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileIoException2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::WRITE );
|
||||
}
|
||||
catch ( ezcBaseFileIoException $e )
|
||||
{
|
||||
$this->assertEquals( "An error occurred while writing to 'testfile.php'.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileIoException3()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::WRITE, "Extra extra" );
|
||||
}
|
||||
catch ( ezcBaseFileIoException $e )
|
||||
{
|
||||
$this->assertEquals( "An error occurred while writing to 'testfile.php'. (Extra extra)", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileNotFoundException1()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFileNotFoundException( 'testfile.php' );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The file 'testfile.php' could not be found.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileNotFoundException2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFileNotFoundException( 'testfile.php', 'INI' );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The INI file 'testfile.php' could not be found.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileNotFoundException3()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFileNotFoundException( 'testfile.php', 'INI', "Extra extra" );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The INI file 'testfile.php' could not be found. (Extra extra)", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFilePermissionException1()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFileException::READ );
|
||||
}
|
||||
catch ( ezcBaseFilePermissionException $e )
|
||||
{
|
||||
$this->assertEquals( "The file 'testfile.php' can not be opened for reading.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFilePermissionException2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFileException::WRITE );
|
||||
}
|
||||
catch ( ezcBaseFileException $e )
|
||||
{
|
||||
$this->assertEquals( "The file 'testfile.php' can not be opened for writing.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFilePermissionException3()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFileException::EXECUTE );
|
||||
}
|
||||
catch ( ezcBaseException $e )
|
||||
{
|
||||
$this->assertEquals( "The file 'testfile.php' can not be executed.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFilePermissionException4()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFilePermissionException::CHANGE, "Extra extra" );
|
||||
}
|
||||
catch ( ezcBaseException $e )
|
||||
{
|
||||
$this->assertEquals( "The permissions for 'testfile.php' can not be changed. (Extra extra)", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFilePermissionException5()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFilePermissionException::READ | ezcBaseFilePermissionException::WRITE, "Extra extra" );
|
||||
}
|
||||
catch ( ezcBaseException $e )
|
||||
{
|
||||
$this->assertEquals( "The file 'testfile.php' can not be opened for reading and writing. (Extra extra)", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testFilePermissionException6()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFilePermissionException::REMOVE, "Extra extra" );
|
||||
}
|
||||
catch ( ezcBaseException $e )
|
||||
{
|
||||
$this->assertEquals( "The file 'testfile.php' can not be removed. (Extra extra)", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testPropertyNotFoundException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBasePropertyNotFoundException( 'broken' );
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "No such property name 'broken'.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testPropertyPermissionException1()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBasePropertyPermissionException( 'broken', ezcBasePropertyPermissionException::READ );
|
||||
}
|
||||
catch ( ezcBaseException $e )
|
||||
{
|
||||
$this->assertEquals( "The property 'broken' is read-only.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testPropertyPermissionException2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBasePropertyPermissionException( 'broken', ezcBasePropertyPermissionException::WRITE );
|
||||
}
|
||||
catch ( ezcBaseException $e )
|
||||
{
|
||||
$this->assertEquals( "The property 'broken' is write-only.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testBaseValue1()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseValueException( 'broken', array( 42 ) );
|
||||
}
|
||||
catch ( ezcBaseValueException $e )
|
||||
{
|
||||
$this->assertEquals( "The value 'a:1:{i:0;i:42;}' that you were trying to assign to setting 'broken' is invalid.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testBaseValue2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new ezcBaseValueException( 'broken', "string", "strings" );
|
||||
}
|
||||
catch ( ezcBaseValueException $e )
|
||||
{
|
||||
$this->assertEquals( "The value 'string' that you were trying to assign to setting 'broken' is invalid. Allowed values are: strings.", $e->getMessage() );
|
||||
$this->assertEquals( "The value 'string' that you were trying to assign to setting 'broken' is invalid. Allowed values are: strings.", $e->originalMessage );
|
||||
}
|
||||
}
|
||||
|
||||
public function testExtraDirNotFoundException()
|
||||
{
|
||||
try
|
||||
{
|
||||
ezcBase::addClassRepository( 'wrongDir' );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The base directory file 'wrongDir' could not be found.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testExtraDirBaseNotFoundException()
|
||||
{
|
||||
try
|
||||
{
|
||||
ezcBase::addClassRepository( '.', './wrongAutoloadDir' );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The autoload directory file './wrongAutoloadDir' could not be found.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testBaseAddAndGetAutoloadDirs1()
|
||||
{
|
||||
ezcBase::addClassRepository( '.' );
|
||||
$resultArray = ezcBase::getRepositoryDirectories();
|
||||
|
||||
if ( count( $resultArray ) != 2 )
|
||||
{
|
||||
$this->fail( "Duplicating or missing extra autoload dirs while adding." );
|
||||
}
|
||||
|
||||
if ( !isset( $resultArray['ezc'] ) )
|
||||
{
|
||||
$this->fail( "No packageDir found in result of getRepositoryDirectories()" );
|
||||
}
|
||||
|
||||
if ( !isset( $resultArray[0] ) || $resultArray[0]->basePath != getcwd() )
|
||||
{
|
||||
$this->fail( "Extra base dir '{$resultArray[0]->basePath}' is added incorrectly" );
|
||||
}
|
||||
|
||||
if ( !isset( $resultArray[0] ) || $resultArray[0]->autoloadPath != getcwd() . '/autoload' )
|
||||
{
|
||||
$this->fail( "Extra autoload dir '{$resultArray[0]->autoloadPath}' is added incorrectly" );
|
||||
}
|
||||
}
|
||||
|
||||
// this test is sorta obsolete, but we keep it around for good measure
|
||||
public function testBaseAddAndGetAutoloadDirs2()
|
||||
{
|
||||
ezcBase::addClassRepository( '.', './autoload' );
|
||||
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files' );
|
||||
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files' );
|
||||
$resultArray = ezcBase::getRepositoryDirectories();
|
||||
|
||||
if ( count( $resultArray ) != 5 )
|
||||
{
|
||||
$this->fail( "Duplicating or missing extra autoload dirs while adding." );
|
||||
}
|
||||
|
||||
if ( !isset( $resultArray['ezc'] ) )
|
||||
{
|
||||
$this->fail( "No packageDir found in result of getRepositoryDirectories()" );
|
||||
}
|
||||
|
||||
if ( !isset( $resultArray[2] ) || $resultArray[2]->autoloadPath != getcwd() . '/Base/tests/test_repository/autoload_files' )
|
||||
{
|
||||
$this->fail( "Extra autoload dir '{$resultArray[2]->autoloadPath}' is added incorrectly" );
|
||||
}
|
||||
|
||||
self::assertEquals( true, class_exists( 'trBasetestClass', true ) );
|
||||
self::assertEquals( true, class_exists( 'trBasetestClass2', true ) );
|
||||
|
||||
try
|
||||
{
|
||||
self::assertEquals( false, class_exists( 'trBasetestClass3', true ) );
|
||||
self::fail( 'The expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBaseAutoloadException $e )
|
||||
{
|
||||
$cwd = getcwd();
|
||||
self::assertEquals( "Could not find a class to file mapping for 'trBasetestClass3'. Searched for basetest_class3_autoload.php, basetest_autoload.php, autoload.php in: $cwd/autoload, $cwd/autoload, $cwd/autoload, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/test_repository/autoload_files", $e->getMessage() );
|
||||
}
|
||||
|
||||
self::assertEquals( true, class_exists( 'trBasetestLongClass', true ) );
|
||||
|
||||
try
|
||||
{
|
||||
class_exists( 'trBasetestClass4', true );
|
||||
self::fail( 'The expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
self::assertEquals( "The file './Base/tests/test_repository/TestClasses/base_test_class_number_four.php' could not be found.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testBaseAddAndGetAutoloadDirs3()
|
||||
{
|
||||
ezcBase::addClassRepository( './Base/tests/extra_repository', null, 'ext' );
|
||||
|
||||
$resultArray = ezcBase::getRepositoryDirectories();
|
||||
self::assertEquals( true, array_key_exists( 'ezc', $resultArray ) );
|
||||
self::assertEquals( true, array_key_exists( 'ext', $resultArray ) );
|
||||
|
||||
self::assertEquals( true, class_exists( 'extTranslationTest', true ) );
|
||||
self::assertEquals( true, class_exists( 'ezcTranslationTsBackend', true ) );
|
||||
}
|
||||
|
||||
public function testBaseAddAndGetAutoloadDirs4()
|
||||
{
|
||||
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files', 'tr' );
|
||||
|
||||
try
|
||||
{
|
||||
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files', 'tr' );
|
||||
}
|
||||
catch ( ezcBaseDoubleClassRepositoryPrefixException $e )
|
||||
{
|
||||
self::assertEquals( "The class repository in './Base/tests/test_repository' (with autoload dir './Base/tests/test_repository/autoload_files') can not be added because another class repository already uses the prefix 'tr'.", $e->getMessage() );
|
||||
}
|
||||
|
||||
$resultArray = ezcBase::getRepositoryDirectories();
|
||||
self::assertEquals( 7, count( $resultArray ) );
|
||||
|
||||
self::assertEquals( true, array_key_exists( 'ezc', $resultArray ) );
|
||||
self::assertEquals( true, array_key_exists( 'tr', $resultArray ) );
|
||||
|
||||
self::assertEquals( getcwd() . '/Base/tests/test_repository', $resultArray['tr']->basePath );
|
||||
self::assertEquals( getcwd() . '/Base/tests/test_repository/autoload_files', $resultArray['tr']->autoloadPath );
|
||||
}
|
||||
|
||||
public function testNoPrefixAutoload()
|
||||
{
|
||||
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files' );
|
||||
__autoload( 'Object' );
|
||||
if ( !class_exists( 'Object' ) )
|
||||
{
|
||||
$this->fail( "Autoload does not handle classes with no prefix" );
|
||||
}
|
||||
}
|
||||
|
||||
public function testCheckDependencyExtension()
|
||||
{
|
||||
ezcBase::checkDependency( 'Tester', ezcBase::DEP_PHP_EXTENSION, 'standard' );
|
||||
}
|
||||
|
||||
public function testCheckDependencyVersion()
|
||||
{
|
||||
ezcBase::checkDependency( 'Tester', ezcBase::DEP_PHP_VERSION, '5.1.1' );
|
||||
}
|
||||
|
||||
public function testInvalidClass()
|
||||
{
|
||||
try
|
||||
{
|
||||
self::assertEquals( false, class_exists( 'ezcNoSuchClass', true ) );
|
||||
self::fail( 'The expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBaseAutoloadException $e )
|
||||
{
|
||||
$cwd = getcwd();
|
||||
self::assertEquals( "Could not find a class to file mapping for 'ezcNoSuchClass'. Searched for no_such_autoload.php, no_autoload.php, autoload.php in: $cwd/autoload, $cwd/autoload, $cwd/autoload, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/extra_repository/autoload, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/test_repository/autoload_files", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testDebug()
|
||||
{
|
||||
try
|
||||
{
|
||||
class_exists( 'ezcTestingOne' );
|
||||
self::fail( "There should have been an exception" );
|
||||
}
|
||||
catch ( ezcBaseAutoloadException $e )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public function testNoDebug()
|
||||
{
|
||||
try
|
||||
{
|
||||
$options = new ezcBaseAutoloadOptions;
|
||||
$options->debug = false;
|
||||
ezcBase::setOptions( $options );
|
||||
|
||||
class_exists( 'ezcTestingOne' );
|
||||
}
|
||||
catch ( Exception $e )
|
||||
{
|
||||
self::fail( "There should not have been an exception" );
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetInstallationPath()
|
||||
{
|
||||
$path = ezcBase::getInstallationPath();
|
||||
$pathParts = explode( DIRECTORY_SEPARATOR, $path );
|
||||
self::assertEquals( array( 'trunk', '' ), array_splice( $pathParts, -2 ) );
|
||||
self::assertEquals( DIRECTORY_SEPARATOR, substr( $path, -1 ) );
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$options = new ezcBaseAutoloadOptions;
|
||||
$options->debug = true;
|
||||
ezcBase::setOptions( $options );
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$options = new ezcBaseAutoloadOptions;
|
||||
$options->debug = true;
|
||||
ezcBase::setOptions( $options );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite("ezcBaseTest");
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
class extTranslationTest
|
||||
{
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return array(
|
||||
'extTranslationTest' => 'Translation/test.php',
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseFeaturesTest extends ezcTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$uname = php_uname( 's' );
|
||||
if ( substr( $uname, 0, 7 ) == 'Windows' )
|
||||
{
|
||||
$this->markTestSkipped( 'Unix tests' );
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupportsLink()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::supportsLink() );
|
||||
}
|
||||
|
||||
public function testSupportsSymLink()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::supportsSymLink() );
|
||||
}
|
||||
|
||||
public function testSupportsUserId()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::supportsUserId() );
|
||||
}
|
||||
|
||||
/* // Need to find a way to make this test work, as setting global enviroment variables
|
||||
// is not working (putenv( "PATH=" ) doesn't unset $_ENV["PATH"])
|
||||
// One solution would be to use in the ezcBaseFeatures::getPath():
|
||||
// getenv( 'PATH' ) instead of $_ENV['PATH'] (but that won't work under IIS).
|
||||
public function testHasImageIdentifyNoPath()
|
||||
{
|
||||
$envPath = getenv( 'PATH' );
|
||||
putenv( "PATH=" );
|
||||
$this->assertEquals( false, ezcBaseFeatures::hasImageIdentify() );
|
||||
putenv( "PATH={$envPath}" );
|
||||
}
|
||||
*/
|
||||
|
||||
public function testHasImageConvert()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::hasImageConvert() );
|
||||
}
|
||||
|
||||
public function testGetImageConvertExecutable()
|
||||
{
|
||||
$this->assertEquals( '/usr/bin/convert', ezcBaseFeatures::getImageConvertExecutable() );
|
||||
}
|
||||
|
||||
public function testGetImageIdentifyExecutable()
|
||||
{
|
||||
$this->assertEquals( '/usr/bin/identify', ezcBaseFeatures::getImageIdentifyExecutable() );
|
||||
}
|
||||
|
||||
public function testHasImageIdentify()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::hasImageIdentify() );
|
||||
}
|
||||
|
||||
public function testHasExtensionSupport1()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::hasExtensionSupport( 'standard' ) );
|
||||
}
|
||||
|
||||
public function testHasExtensionSupportNotFound1()
|
||||
{
|
||||
$this->assertEquals( false, ezcBaseFeatures::hasExtensionSupport( 'non_existent_extension' ) );
|
||||
try
|
||||
{
|
||||
throw new ezcBaseExtensionNotFoundException( 'non_existent_extension', null, 'This is just a test.' );
|
||||
}
|
||||
catch ( ezcBaseExtensionNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The extension 'non_existent_extension' could not be found. This is just a test.",
|
||||
$e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasExtensionSupportNotFound2()
|
||||
{
|
||||
$this->assertEquals( false, ezcBaseFeatures::hasExtensionSupport( 'non_existent_extension' ) );
|
||||
try
|
||||
{
|
||||
throw new ezcBaseExtensionNotFoundException( 'non_existent_extension', '1.2', 'This is just a test.' );
|
||||
}
|
||||
catch ( ezcBaseExtensionNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "The extension 'non_existent_extension' with version '1.2' could not be found. This is just a test.",
|
||||
$e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasFunction1()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::hasFunction( 'function_exists' ) );
|
||||
}
|
||||
|
||||
public function testHasFunction2()
|
||||
{
|
||||
$this->assertEquals( false, ezcBaseFeatures::hasFunction( 'non_existent_function_in_php' ) );
|
||||
}
|
||||
|
||||
public function testHasExtensionSupport2()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::hasExtensionSupport( 'date', '5.1.0' ) );
|
||||
}
|
||||
|
||||
public function testClassExists()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::classExists( 'Exception', false ) );
|
||||
}
|
||||
|
||||
public function testClassExistsAutoload()
|
||||
{
|
||||
$this->assertEquals( true, ezcBaseFeatures::classExists( 'ezcBaseFeatures' ) );
|
||||
}
|
||||
|
||||
public function testClassExistsNotFound()
|
||||
{
|
||||
$this->assertEquals( false, ezcBaseFeatures::classExists( 'ezcBaseNonExistingClass', false ) );
|
||||
}
|
||||
|
||||
public function testClassExistsNotFoundAutoload()
|
||||
{
|
||||
$this->assertEquals( false, ezcBaseFeatures::classExists( 'ezcBaseNonExistingClass' ) );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite("ezcBaseFeaturesTest");
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @version 1.5
|
||||
* @filesource
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseFileCalculateRelativePathTest extends ezcTestCase
|
||||
{
|
||||
public function testRelative1()
|
||||
{
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:/foo/1/2/php.php', 'C:/foo/bar' );
|
||||
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:/foo/bar/php.php', 'C:/foo/bar' );
|
||||
self::assertEquals( 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:/php.php', 'C:/foo/bar/1/2');
|
||||
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:/bar/php.php', 'C:/foo/bar/1/2');
|
||||
self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'php.php', $result);
|
||||
}
|
||||
|
||||
public function testRelative2()
|
||||
{
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:\\foo\\1\\2\\php.php', 'C:\\foo\\bar' );
|
||||
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:\\foo\\bar\\php.php', 'C:\\foo\\bar' );
|
||||
self::assertEquals( 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:\\php.php', 'C:\\foo\\bar\\1\\2');
|
||||
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( 'C:\\bar\\php.php', 'C:\\foo\\bar\\1\\2');
|
||||
self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'php.php', $result);
|
||||
}
|
||||
|
||||
public function testRelative3()
|
||||
{
|
||||
$result = ezcBaseFile::calculateRelativePath( '/foo/1/2/php.php', '/foo/bar' );
|
||||
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( '/foo/bar/php.php', '/foo/bar' );
|
||||
self::assertEquals( 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( '/php.php', '/foo/bar/1/2');
|
||||
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php.php', $result );
|
||||
|
||||
$result = ezcBaseFile::calculateRelativePath( '/bar/php.php', '/foo/bar/1/2');
|
||||
self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'php.php', $result);
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( "ezcBaseFileCalculateRelativePathTest" );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @version 1.5
|
||||
* @filesource
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseFileCopyRecursiveTest extends ezcTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->tempDir = $this->createTempDir( __CLASS__ );
|
||||
mkdir( $this->tempDir . '/dir1' );
|
||||
mkdir( $this->tempDir . '/dir2' );
|
||||
mkdir( $this->tempDir . '/dir2/dir1' );
|
||||
mkdir( $this->tempDir . '/dir2/dir1/dir1' );
|
||||
mkdir( $this->tempDir . '/dir2/dir2' );
|
||||
mkdir( $this->tempDir . '/dir4' );
|
||||
mkdir( $this->tempDir . '/dir5' );
|
||||
mkdir( $this->tempDir . '/dir6' );
|
||||
file_put_contents( $this->tempDir . '/dir1/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir1/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir1/.file3.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir1/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir2/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir4/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir4/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir5/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir5/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir6/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir6/file2.txt', 'test' );
|
||||
chmod( $this->tempDir . '/dir4/file1.txt', 0 );
|
||||
chmod( $this->tempDir . '/dir5', 0 );
|
||||
chmod( $this->tempDir . '/dir6', 0400 );
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
chmod( $this->tempDir . '/dir5', 0700 );
|
||||
chmod( $this->tempDir . '/dir6', 0700 );
|
||||
$this->removeTempDir();
|
||||
}
|
||||
|
||||
public function testRecursiveCopyEmptyDir()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir1',
|
||||
$this->tempDir . '/dest'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dir1' ) ),
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
0775,
|
||||
fileperms( $this->tempDir . '/dest' ) & 0777,
|
||||
'Directory mode should equal 0775.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFile()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir1/file1.txt',
|
||||
$this->tempDir . '/dest'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
is_file( $this->tempDir . '/dest' )
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
0664,
|
||||
fileperms( $this->tempDir . '/dest' ) & 0777,
|
||||
'File mode should equal 0664.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyEmptyDirMode()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir1',
|
||||
$this->tempDir . '/dest',
|
||||
-1,
|
||||
0777,
|
||||
0777
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dir1' ) ),
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
0777,
|
||||
fileperms( $this->tempDir . '/dest' ) & 0777,
|
||||
'Directory mode should equal 0777.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFileMode()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir1/file1.txt',
|
||||
$this->tempDir . '/dest',
|
||||
-1,
|
||||
0777,
|
||||
0777
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
is_file( $this->tempDir . '/dest' )
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
0777,
|
||||
fileperms( $this->tempDir . '/dest' ) & 0777,
|
||||
'File mode should equal 0777.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFullDir()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir2',
|
||||
$this->tempDir . '/dest'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dir2' ) ),
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFullDirDepthZero()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir2',
|
||||
$this->tempDir . '/dest',
|
||||
0
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
0,
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
is_dir( $this->tempDir . '/dest' )
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFullDirLimitedDepth()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir2',
|
||||
$this->tempDir . '/dest',
|
||||
2
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
3,
|
||||
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFailureNotExisting()
|
||||
{
|
||||
try
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/not_existing',
|
||||
$this->tempDir . '/dest'
|
||||
);
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fail( 'Expected ezcBaseFileNotFoundException.' );
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFailureNotReadable()
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir5',
|
||||
$this->tempDir . '/dest'
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
is_dir( $this->tempDir . '/dest' )
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
is_file( $this->tempDir . '/dest' )
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveCopyFailureNotWriteable()
|
||||
{
|
||||
try
|
||||
{
|
||||
ezcBaseFile::copyRecursive(
|
||||
$this->tempDir . '/dir2',
|
||||
$this->tempDir . '/dir4'
|
||||
);
|
||||
}
|
||||
catch ( ezcBaseFilePermissionException $e )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fail( 'Expected ezcBaseFilePermissionException.' );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( __CLASS__ );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @version 1.5
|
||||
* @filesource
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseFileFindRecursiveTest extends ezcTestCase
|
||||
{
|
||||
public function testRecursive1()
|
||||
{
|
||||
$expected = array (
|
||||
0 => 'File/CREDITS',
|
||||
1 => 'File/ChangeLog',
|
||||
2 => 'File/DESCRIPTION',
|
||||
3 => 'File/design/class_diagram.png',
|
||||
4 => 'File/design/design.txt',
|
||||
5 => 'File/design/file.xml',
|
||||
6 => 'File/design/file_operations.png',
|
||||
7 => 'File/design/md5.png',
|
||||
8 => 'File/design/requirements.txt',
|
||||
9 => 'File/src/file.php',
|
||||
10 => 'File/src/file_autoload.php',
|
||||
11 => 'File/tests/file_calculate_relative_path_test.php',
|
||||
12 => 'File/tests/file_find_recursive_test.php',
|
||||
13 => 'File/tests/file_remove_recursive_test.php',
|
||||
14 => 'File/tests/suite.php',
|
||||
);
|
||||
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array(), array( '@/docs/@', '@svn@', '@\.swp$@' ), $stats ) );
|
||||
self::assertEquals( array( 'size' => 130984, 'count' => 15 ), $stats );
|
||||
}
|
||||
|
||||
public function testRecursive2()
|
||||
{
|
||||
$expected = array (
|
||||
0 => './File/CREDITS',
|
||||
1 => './File/ChangeLog',
|
||||
2 => './File/DESCRIPTION',
|
||||
3 => './File/design/class_diagram.png',
|
||||
4 => './File/design/design.txt',
|
||||
5 => './File/design/file.xml',
|
||||
6 => './File/design/file_operations.png',
|
||||
7 => './File/design/md5.png',
|
||||
8 => './File/design/requirements.txt',
|
||||
9 => './File/src/file.php',
|
||||
10 => './File/src/file_autoload.php',
|
||||
11 => './File/tests/file_calculate_relative_path_test.php',
|
||||
12 => './File/tests/file_find_recursive_test.php',
|
||||
13 => './File/tests/file_remove_recursive_test.php',
|
||||
14 => './File/tests/suite.php',
|
||||
);
|
||||
self::assertEquals( $expected, ezcBaseFile::findRecursive( ".", array( '@^\./File/@' ), array( '@/docs/@', '@\.svn@', '@\.swp$@' ), $stats ) );
|
||||
self::assertEquals( array( 'size' => 130984, 'count' => 15 ), $stats );
|
||||
}
|
||||
|
||||
public function testRecursive3()
|
||||
{
|
||||
$expected = array (
|
||||
0 => 'File/design/class_diagram.png',
|
||||
1 => 'File/design/file_operations.png',
|
||||
2 => 'File/design/md5.png',
|
||||
);
|
||||
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@\.png$@' ), array( '@\.svn@' ), $stats ) );
|
||||
self::assertEquals( array( 'size' => 17642, 'count' => 3 ), $stats );
|
||||
}
|
||||
|
||||
public function testRecursive4()
|
||||
{
|
||||
$expected = array (
|
||||
0 => 'File/design/class_diagram.png',
|
||||
1 => 'File/design/design.txt',
|
||||
2 => 'File/design/file.xml',
|
||||
3 => 'File/design/file_operations.png',
|
||||
4 => 'File/design/md5.png',
|
||||
5 => 'File/design/requirements.txt',
|
||||
);
|
||||
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@/design/@' ), array( '@\.svn@' ), $stats ) );
|
||||
self::assertEquals( array( 'size' => 114282, 'count' => 6 ), $stats );
|
||||
}
|
||||
|
||||
public function testRecursive5()
|
||||
{
|
||||
$expected = array (
|
||||
0 => 'File/design/design.txt',
|
||||
1 => 'File/design/requirements.txt',
|
||||
2 => 'File/src/file.php',
|
||||
3 => 'File/src/file_autoload.php',
|
||||
4 => 'File/tests/file_calculate_relative_path_test.php',
|
||||
5 => 'File/tests/file_find_recursive_test.php',
|
||||
6 => 'File/tests/file_remove_recursive_test.php',
|
||||
7 => 'File/tests/suite.php',
|
||||
);
|
||||
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@\.(php|txt)$@' ), array( '@/docs/@', '@\.svn@' ) ) );
|
||||
}
|
||||
|
||||
public function testRecursive6()
|
||||
{
|
||||
$expected = array();
|
||||
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@xxx@' ) ) );
|
||||
}
|
||||
|
||||
public function testNonExistingDirectory()
|
||||
{
|
||||
$expected = array();
|
||||
try
|
||||
{
|
||||
ezcBaseFile::findRecursive( "NotHere", array( '@xxx@' ) );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
self::assertEquals( "The directory file 'NotHere' could not be found.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testStatsEmptyArray()
|
||||
{
|
||||
$expected = array (
|
||||
0 => 'File/design/class_diagram.png',
|
||||
1 => 'File/design/design.txt',
|
||||
2 => 'File/design/file.xml',
|
||||
3 => 'File/design/file_operations.png',
|
||||
4 => 'File/design/md5.png',
|
||||
5 => 'File/design/requirements.txt',
|
||||
);
|
||||
$stats = array();
|
||||
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@/design/@' ), array( '@\.svn@' ), $stats ) );
|
||||
self::assertEquals( array( 'size' => 114282, 'count' => 6 ), $stats );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( "ezcBaseFileFindRecursiveTest" );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @version 1.5
|
||||
* @filesource
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseFileIsAbsoluteTest extends ezcTestCase
|
||||
{
|
||||
public static function testAbsoluteWindows1()
|
||||
{
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt\\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\winnt\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\table.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c\\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Windows' ) );
|
||||
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\server\share\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\share\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\share\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\share\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\thare\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\thare\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\server\\share\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\\share\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\\share\foo.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\\share\foo.sys', 'Windows' ) );
|
||||
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\etc\init.d\apache', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\etc\\init.d\\apache', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\init.d\apache', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\\init.d\\apache', 'Windows' ) );
|
||||
}
|
||||
|
||||
public static function testAbsoluteWindows2()
|
||||
{
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/table.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/winnt.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Windows' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys', 'Windows' ) );
|
||||
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache', 'Windows' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache', 'Windows' ) );
|
||||
}
|
||||
|
||||
public static function testAbsoluteWindows3()
|
||||
{
|
||||
if ( ezcBaseFeatures::os() !== 'Windows' )
|
||||
{
|
||||
self::markTestSkipped( 'Test is for Windows only' );
|
||||
}
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/table.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys' ) );
|
||||
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache' ) );
|
||||
}
|
||||
|
||||
public static function testAbsoluteLinux1()
|
||||
{
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt\\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\winnt\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\table.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c\\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Linux' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\server\share\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\share\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\share\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\share\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\thare\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\thare\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\server\\share\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\\share\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\\share\foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\\share\foo.sys', 'Linux' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\etc\init.d\apache', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\etc\\init.d\\apache', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\init.d\apache', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\\init.d\\apache', 'Linux' ) );
|
||||
}
|
||||
|
||||
public static function testAbsoluteLinux2()
|
||||
{
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/table.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/winnt.sys', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Linux' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys', 'Linux' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache', 'Linux' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache', 'Linux' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache', 'Linux' ) );
|
||||
}
|
||||
|
||||
public static function testAbsoluteLinux3()
|
||||
{
|
||||
if ( ezcBaseFeatures::os() === 'Windows' )
|
||||
{
|
||||
self::markTestSkipped( 'Test is for unix-like systems only' );
|
||||
}
|
||||
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/table.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//winnt.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/winnt.sys' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys' ) );
|
||||
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache' ) );
|
||||
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache' ) );
|
||||
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache' ) );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( "ezcBaseFileIsAbsoluteTest" );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @version 1.5
|
||||
* @filesource
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseFileRemoveRecursiveTest extends ezcTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->tempDir = $this->createTempDir( 'ezcBaseFileRemoveFileRecursiveTest' );
|
||||
mkdir( $this->tempDir . '/dir1' );
|
||||
mkdir( $this->tempDir . '/dir2' );
|
||||
mkdir( $this->tempDir . '/dir2/dir1' );
|
||||
mkdir( $this->tempDir . '/dir2/dir1/dir1' );
|
||||
mkdir( $this->tempDir . '/dir2/dir2' );
|
||||
mkdir( $this->tempDir . '/dir4' );
|
||||
mkdir( $this->tempDir . '/dir5' );
|
||||
mkdir( $this->tempDir . '/dir6' );
|
||||
file_put_contents( $this->tempDir . '/dir1/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir1/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir1/.file3.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir1/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir2/dir2/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir4/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir4/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir5/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir5/file2.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir6/file1.txt', 'test' );
|
||||
file_put_contents( $this->tempDir . '/dir6/file2.txt', 'test' );
|
||||
chmod( $this->tempDir . '/dir4/file1.txt', 0 );
|
||||
chmod( $this->tempDir . '/dir5', 0 );
|
||||
chmod( $this->tempDir . '/dir6', 0400 );
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
chmod( $this->tempDir . '/dir5', 0700 );
|
||||
chmod( $this->tempDir . '/dir6', 0700 );
|
||||
$this->removeTempDir();
|
||||
}
|
||||
|
||||
public function testRecursive1()
|
||||
{
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
ezcBaseFile::removeRecursive( $this->tempDir . '/dir1' );
|
||||
self::assertEquals( 9, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
ezcBaseFile::removeRecursive( $this->tempDir . '/dir2' );
|
||||
self::assertEquals( 4, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
}
|
||||
|
||||
public function testRecursive2()
|
||||
{
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
try
|
||||
{
|
||||
ezcBaseFile::removeRecursive( $this->tempDir . '/dir3' );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
self::assertEquals( "The directory file '{$this->tempDir}/dir3' could not be found.", $e->getMessage() );
|
||||
}
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
}
|
||||
|
||||
public function testRecursive3()
|
||||
{
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
try
|
||||
{
|
||||
ezcBaseFile::removeRecursive( $this->tempDir . '/dir4' );
|
||||
}
|
||||
catch ( ezcBaseFilePermissionException $e )
|
||||
{
|
||||
self::assertEquals( "The file '{$this->tempDir}/dir5' can not be opened for reading.", $e->getMessage() );
|
||||
}
|
||||
self::assertEquals( 10, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
}
|
||||
|
||||
public function testRecursive4()
|
||||
{
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
try
|
||||
{
|
||||
ezcBaseFile::removeRecursive( $this->tempDir . '/dir5' );
|
||||
}
|
||||
catch ( ezcBaseFilePermissionException $e )
|
||||
{
|
||||
self::assertEquals( "The file '{$this->tempDir}/dir5' can not be opened for reading.", $e->getMessage() );
|
||||
}
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
}
|
||||
|
||||
public function testRecursive5()
|
||||
{
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
try
|
||||
{
|
||||
ezcBaseFile::removeRecursive( $this->tempDir . '/dir6' );
|
||||
}
|
||||
catch ( ezcBaseFilePermissionException $e )
|
||||
{
|
||||
// Make no asumption on which file is tryed to be removed first
|
||||
self::assertEquals(
|
||||
1,
|
||||
preg_match(
|
||||
"(The file '{$this->tempDir}/dir6/file[12].txt' can not be removed.)",
|
||||
$e->getMessage()
|
||||
)
|
||||
);
|
||||
}
|
||||
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( "ezcBaseFileRemoveRecursiveTest" );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for ezcBaseInitTest.
|
||||
*
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class testBaseInitCallback implements ezcBaseConfigurationInitializer
|
||||
{
|
||||
static public function configureObject( $objectToConfigure )
|
||||
{
|
||||
$objectToConfigure->configured = true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for ezcBaseInitTest.
|
||||
*
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class testBaseInitClass
|
||||
{
|
||||
public $configured = false;
|
||||
public static $instance;
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if ( is_null( self::$instance ) )
|
||||
{
|
||||
self::$instance = new testBaseInitClass();
|
||||
ezcBaseInit::fetchConfig( 'testBaseInit', self::$instance );
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseStructTest extends ezcTestCase
|
||||
{
|
||||
public function testBaseStructGetSet()
|
||||
{
|
||||
$struct = new ezcBaseStruct();
|
||||
|
||||
try
|
||||
{
|
||||
$struct->no_such_property = 'value';
|
||||
$this->fail( 'Expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "No such property name 'no_such_property'.", $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$value = $struct->no_such_property;
|
||||
$this->fail( 'Expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
$this->assertEquals( "No such property name 'no_such_property'.", $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testBaseRepositoryDirectorySetState()
|
||||
{
|
||||
$dir = ezcBaseRepositoryDirectory::__set_state( array( 'type' => ezcBaseRepositoryDirectory::TYPE_EXTERNAL, 'basePath' => '/tmp', 'autoloadPath' => '/tmp/autoload' ) );
|
||||
$this->assertEquals( ezcBaseRepositoryDirectory::TYPE_EXTERNAL, $dir->type );
|
||||
$this->assertEquals( '/tmp', $dir->basePath );
|
||||
$this->assertEquals( '/tmp/autoload', $dir->autoloadPath );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( "ezcBaseStructTest" );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
* @version 1.5
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
require_once( "base_test.php");
|
||||
require_once( "base_init_test.php");
|
||||
require_once( "features_test.php");
|
||||
require_once( "base_options_test.php");
|
||||
require_once( "struct_test.php");
|
||||
require_once 'file_find_recursive_test.php';
|
||||
require_once 'file_is_absolute_path.php';
|
||||
require_once 'file_copy_recursive_test.php';
|
||||
require_once 'file_remove_recursive_test.php';
|
||||
require_once 'file_calculate_relative_path_test.php';
|
||||
|
||||
/**
|
||||
* @package Base
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcBaseSuite extends PHPUnit_Framework_TestSuite
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setName("Base");
|
||||
|
||||
$this->addTest( ezcBaseTest::suite() );
|
||||
$this->addTest( ezcBaseInitTest::suite() );
|
||||
$this->addTest( ezcBaseFeaturesTest::suite() );
|
||||
$this->addTest( ezcBaseOptionsTest::suite() );
|
||||
$this->addTest( ezcBaseStructTest::suite() );
|
||||
$this->addTest( ezcBaseFileCalculateRelativePathTest::suite() );
|
||||
$this->addTest( ezcBaseFileFindRecursiveTest::suite() );
|
||||
$this->addTest( ezcBaseFileIsAbsoluteTest::suite() );
|
||||
$this->addTest( ezcBaseFileCopyRecursiveTest::suite() );
|
||||
$this->addTest( ezcBaseFileRemoveRecursiveTest::suite() );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new ezcBaseSuite();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
class ezcBaseTestOptions extends ezcBaseOptions
|
||||
{
|
||||
protected $properties = array( "foo" => "bar" );
|
||||
|
||||
public function __set( $propertyName, $propertyValue )
|
||||
{
|
||||
if ( $this->__isset( $propertyName ) )
|
||||
{
|
||||
$this->properties[$propertyName] = $propertyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcBasePropertyNotFoundException( $propertyName );
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
class trBasetestClass {
|
||||
}
|
||||
?>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
class trBasetestClass2 {
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
class trBasetestLongClass {
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
return array(
|
||||
'trBasetestClass' => 'TestClasses/base_test_class.php',
|
||||
'trBasetestClass2' => 'TestClasses/base_test_class_number_two.php',
|
||||
'trBasetestClass4' => 'TestClasses/base_test_class_number_four.php',
|
||||
);
|
||||
?>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return array(
|
||||
'trBasetestLongClass' => 'TestClasses/base_test_long_class.php',
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return array(
|
||||
'Object' => 'object/object.php',
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
class Object{
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user