testFilesDir = dirname( __FILE__ ) . '/testfiles/'; } public function testCanNotFindClass() { $baseDir = realpath( dirname( __FILE__ ) . '/../../../' ); $m = new ezcSearchEmbeddedManager(); try { $d = $m->fetchDefinition( 'doesNotExist' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcBaseAutoloadException $e ) { self::assertEquals( "Could not find a class to file mapping for 'doesNotExist'. Searched for not_exist_autoload.php, not_autoload.php, autoload.php in: $baseDir/autoload", $e->getMessage() ); } } public function testMissingIdProperty() { $m = new ezcSearchEmbeddedManager(); try { $d = $m->fetchDefinition( 'MissingID' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchDefinitionInvalidException $e ) { self::assertEquals( "The embedded definition file for 'MissingID' is invalid (Missing ID property).", $e->getMessage() ); } } public function testDefinitionProviderNotImplemented() { $m = new ezcSearchEmbeddedManager(); try { $d = $m->fetchDefinition( 'UnknownType' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchDoesNotProvideDefinitionException $e ) { self::assertEquals( "The class 'UnknownType' does not implement the ezcSearchDefinitionProvider interface.", $e->getMessage() ); } } public function testReadDefinition() { $m = new ezcSearchEmbeddedManager(); $d = $m->fetchDefinition( 'EmbeddedArticle' ); 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 function testReadDefinitionFromCache() { $m = new ezcSearchEmbeddedManager(); $e = $m->fetchDefinition( 'EmbeddedArticle' ); $d = $m->fetchDefinition( 'EmbeddedArticle' ); 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 ); self::assertSame( $e, $d ); } public static function suite() { return new PHPUnit_Framework_TestSuite( "ezcSearchEmbeddedDefinitionManager" ); } } ?>