assertEquals( "The setting 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 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 is invalid. Allowed values are: int, 40 - 48", $e->getMessage() ); } } public function testFileIoException1() { try { throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::READ ); } catch ( ezcBaseFileIoException $e ) { $this->assertEquals( "An error occurred while reading from .", $e->getMessage() ); } } public function testFileIoException2() { try { throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::WRITE ); } catch ( ezcBaseFileIoException $e ) { $this->assertEquals( "An error occurred while writing to .", $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 . (Extra extra)", $e->getMessage() ); } } public function testFileNotFoundException1() { try { throw new ezcBaseFileNotFoundException( 'testfile.php' ); } catch ( ezcBaseFileNotFoundException $e ) { $this->assertEquals( "The file could not be found.", $e->getMessage() ); } } public function testFileNotFoundException2() { try { throw new ezcBaseFileNotFoundException( 'testfile.php', 'INI' ); } catch ( ezcBaseFileNotFoundException $e ) { $this->assertEquals( "The INI file 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 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 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 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 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 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 can not be opened for reading and writing. (Extra extra)", $e->getMessage() ); } } public function testPropertyNotFoundException() { try { throw new ezcBasePropertyNotFoundException( 'broken' ); } catch ( ezcBasePropertyNotFoundException $e ) { $this->assertEquals( "No such property name .", $e->getMessage() ); } } public function testPropertyPermissionException1() { try { throw new ezcBasePropertyPermissionException( 'broken', ezcBasePropertyPermissionException::READ ); } catch ( ezcBaseException $e ) { $this->assertEquals( "The property is read-only.", $e->getMessage() ); } } public function testPropertyPermissionException2() { try { throw new ezcBasePropertyPermissionException( 'broken', ezcBasePropertyPermissionException::WRITE ); } catch ( ezcBaseException $e ) { $this->assertEquals( "The property is write-only.", $e->getMessage() ); } } public function testBaseValue1() { try { throw new ezcBaseValueException( 'broken', array( 42 ) ); } catch ( ezcBaseValueException $e ) { $this->assertEquals( "The value that you were trying to assign to setting is invalid.", $e->getMessage() ); } } public function testBaseValue2() { try { throw new ezcBaseValueException( 'broken', "string", "strings" ); } catch ( ezcBaseValueException $e ) { $this->assertEquals( "The value that you were trying to assign to setting is invalid. Allowed values are: strings.", $e->getMessage() ); $this->assertEquals( "The value that you were trying to assign to setting is invalid. Allowed values are: strings.", $e->originalMessage ); } } public function testExtraDirNotFoundException() { try { ezcBase::addClassRepository( 'wrongDir' ); } catch ( ezcBaseFileNotFoundException $e ) { $this->assertEquals( "The base directory file 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." ); } $packageDir = realpath( dirname( __FILE__ ) . '/../..' ); if ( !isset( $resultArray[$packageDir] ) ) { $this->fail( "No packageDir found in result of getRepositoryDirectories()" ); } if ( !isset( $resultArray['.'] ) || $resultArray['.'][1] != './autoload' ) { $this->fail( "Extra autoload dir <{$resultArray['.'][1]}> is added incorrectly" ); } } 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 ) != 3 ) { $this->fail( "Duplicating or missing extra autoload dirs while adding." ); } $packageDir = realpath( dirname( __FILE__ ) . '/../..' ); if ( !isset( $resultArray[$packageDir] ) ) { $this->fail( "No packageDir found in result of getRepositoryDirectories()" ); } if ( !isset( $resultArray['./Base/tests/test_repository'] ) || $resultArray['./Base/tests/test_repository'][1] != './Base/tests/test_repository/autoload_files' ) { $this->fail( "Extra autoload dir <{$resultArray['./Base/tests/test_repository'][1]}> is added incorrectly" ); } self::assertEquals( true, class_exists( 'trBasetestClass', true ) ); self::assertEquals( true, class_exists( 'trBasetestClass2', true ) ); self::assertEquals( false, @class_exists( 'trBasetestClass3', true ) ); } 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 static function suite() { return new ezcTestSuite("ezcBaseTest"); } } ?>