testFilesDir = dirname( __FILE__ ) . '/testfiles/'; } public function testCanNotFindDefinitionFile() { $m = new ezcSearchXmlManager( $this->testFilesDir ); try { $d = $m->fetchDefinition( 'doesNotExist' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchDefinitionNotFoundException $e ) { self::assertEquals( "Could not find the XML definition file for 'doesNotExist' at '{$this->testFilesDir}doesnotexist.xml'.", $e->getMessage() ); } } public function testBrokenXml() { $m = new ezcSearchXmlManager( $this->testFilesDir ); try { $d = $m->fetchDefinition( 'Invalid' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchDefinitionInvalidException $e ) { self::assertEquals( "The XML definition file for 'Invalid' at '{$this->testFilesDir}invalid.xml' is invalid (Invalid XML).", $e->getMessage() ); } } public function testMissingIdProperty() { $m = new ezcSearchXmlManager( $this->testFilesDir ); try { $d = $m->fetchDefinition( 'MissingID' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchDefinitionInvalidException $e ) { self::assertEquals( "The XML definition file for 'MissingID' at '{$this->testFilesDir}missingid.xml' is invalid (Missing ID property).", $e->getMessage() ); } } public function testDuplicateIdProperty() { $m = new ezcSearchXmlManager( $this->testFilesDir ); try { $d = $m->fetchDefinition( 'DuplicateID' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchDefinitionInvalidException $e ) { self::assertEquals( "The XML definition file for 'DuplicateID' at '{$this->testFilesDir}duplicateid.xml' is invalid (Duplicate ID property).", $e->getMessage() ); } } public function testUnknownType() { $m = new ezcSearchXmlManager( $this->testFilesDir ); try { $d = $m->fetchDefinition( 'UnknownType' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchDefinitionInvalidException $e ) { self::assertEquals( "The XML definition file for 'UnknownType' at '{$this->testFilesDir}unknowntype.xml' is invalid (Unknown type: unknown).", $e->getMessage() ); } } public function testReadDefinition() { $m = new ezcSearchXmlManager( $this->testFilesDir ); $d = $m->fetchDefinition( 'Article' ); self::assertEquals( 'id', $d->idProperty ); self::assertEquals( array( 'id', 'title', 'summary', 'body', 'published' ), $d->getFieldNames() ); self::assertEquals( ezcSearchDocumentDefinition::STRING, $d->fields['id']->type ); self::assertEquals( ezcSearchDocumentDefinition::STRING, $d->fields['title']->type ); self::assertEquals( ezcSearchDocumentDefinition::TEXT, $d->fields['summary']->type ); self::assertEquals( ezcSearchDocumentDefinition::HTML, $d->fields['body']->type ); self::assertEquals( ezcSearchDocumentDefinition::DATE, $d->fields['published']->type ); self::assertEquals( 2, $d->fields['title']->boost ); self::assertEquals( false, $d->fields['body']->inResult ); self::assertEquals( true, $d->fields['summary']->inResult ); self::assertEquals( true, $d->fields['title']->inResult ); } public static function suite() { return new PHPUnit_Framework_TestSuite( "ezcSearchXmlDefinitionManager" ); } } ?>