Author: dr Date: Wed Feb 20 10:38:05 2008 New Revision: 7417 Log: - Added the XML definition reader.
Added: trunk/Search/design/class_diagram.png (with props) trunk/Search/src/exceptions/definition_invalid.php (with props) trunk/Search/src/exceptions/definition_not_found.php (with props) trunk/Search/src/exceptions/missing_id.php (with props) trunk/Search/src/managers/xml_manager.php (with props) trunk/Search/src/structs/document_definition.php (with props) trunk/Search/src/structs/document_field_definition.php (with props) trunk/Search/tests/handlers/ trunk/Search/tests/handlers/solr_test.php (with props) trunk/Search/tests/managers/ trunk/Search/tests/managers/testfiles/ trunk/Search/tests/managers/testfiles/article.xml trunk/Search/tests/managers/testfiles/duplicateid.xml trunk/Search/tests/managers/testfiles/invalid.xml trunk/Search/tests/managers/testfiles/mail.xml trunk/Search/tests/managers/testfiles/missingid.xml trunk/Search/tests/managers/testfiles/unknowntype.xml trunk/Search/tests/managers/xml_test.php (with props) trunk/Search/tests/suite.php (with props) Modified: trunk/Search/src/interfaces/definition_manager.php trunk/Search/src/search_autoload.php Added: trunk/Search/design/class_diagram.png ============================================================================== Binary file - no diff available. Propchange: trunk/Search/design/class_diagram.png ------------------------------------------------------------------------------ svn:mime-type = image/png Added: trunk/Search/src/exceptions/definition_invalid.php ============================================================================== --- trunk/Search/src/exceptions/definition_invalid.php (added) +++ trunk/Search/src/exceptions/definition_invalid.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,37 @@ +<?php +/** + * File containing the ezcSearchDefinitionInvalidException class. + * + * @package Search + * @version //autogentag// + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * This exception is thrown when a definition file for a class can not be found. + * + * @package Search + * @version //autogentag// + */ +class ezcSearchDefinitionInvalidException extends ezcSearchException +{ + /** + * Constructs an ezcSearchDefinitionInvalidException + * + * @param string $type + * @param string $class + * @param string $location + * @return void + */ + public function __construct( $type, $class, $location, $extraMsg = false ) + { + if ( $extraMsg ) + { + $extraMsg = " ($extraMsg)"; + } + $message = "The $type definition file for '$class' at '$location' is invalid{$extraMsg}."; + parent::__construct( $message ); + } +} +?> Propchange: trunk/Search/src/exceptions/definition_invalid.php ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/Search/src/exceptions/definition_not_found.php ============================================================================== --- trunk/Search/src/exceptions/definition_not_found.php (added) +++ trunk/Search/src/exceptions/definition_not_found.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,33 @@ +<?php +/** + * File containing the ezcSearchDefinitionNotFoundException class. + * + * @package Search + * @version //autogentag// + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * This exception is thrown when a definition file for a class can not be found. + * + * @package Search + * @version //autogentag// + */ +class ezcSearchDefinitionNotFoundException extends ezcSearchException +{ + /** + * Constructs an ezcSearchDefinitionNotFoundException + * + * @param string $type + * @param string $class + * @param string $location + * @return void + */ + public function __construct( $type, $class, $location ) + { + $message = "Could not find the $type definition file for '$class' at '$location'."; + parent::__construct( $message ); + } +} +?> Propchange: trunk/Search/src/exceptions/definition_not_found.php ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/Search/src/exceptions/missing_id.php ============================================================================== --- trunk/Search/src/exceptions/missing_id.php (added) +++ trunk/Search/src/exceptions/missing_id.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,37 @@ +<?php +/** + * File containing the ezcSearchDefinitionMissingIdPropertyException class. + * + * @package Search + * @version //autogentag// + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * This exception is thrown when a definition file for a class can not be found. + * + * @package Search + * @version //autogentag// + */ +class ezcSearchDefinitionMissingIdPropertyException extends ezcSearchException +{ + /** + * Constructs an ezcSearchDefinitionMissingIdPropertyException + * + * @param string $type + * @param string $class + * @param string $location + * @return void + */ + public function __construct( $type, $location ) + { + if ( $extraMsg ) + { + $extraMsg = " ($extraMsg)"; + } + $message = "The $type definition file for '$class' at '$location' is invalid{$extraMsg}."; + parent::__construct( $message ); + } +} +?> Propchange: trunk/Search/src/exceptions/missing_id.php ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/Search/src/interfaces/definition_manager.php ============================================================================== --- trunk/Search/src/interfaces/definition_manager.php [iso-8859-1] (original) +++ trunk/Search/src/interfaces/definition_manager.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -18,7 +18,7 @@ * @version //autogen// * @package Search */ -interface ezcPersistentDefinitionManager +interface ezcSearchDefinitionManager { /** * Returns the definition of the document type $type. Added: trunk/Search/src/managers/xml_manager.php ============================================================================== --- trunk/Search/src/managers/xml_manager.php (added) +++ trunk/Search/src/managers/xml_manager.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,144 @@ +<?php +/** + * File containing the ezcSearchXmlManager class + * + * @package Search + * @version //autogen// + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * Handles document type definitions in XML format. + * + * Each definition must be in a separate file in the directory specified to the + * constructor. The filename must be the same as the lowercase name of the + * document type with .xml appended. Each file should return the definition of + * one document type. + * + * Example exampleclass.xml: + * <code> + * <?xml version="1.0" charset="utf-8"?> + * <document> + * <field type="id">id</field> + * <field type="string" boost="2">title</field> + * <field type="text">description</field> + * </document> + * </code> + * + * @version //autogen// + * @package Search + */ +class ezcSearchXmlManager implements ezcSearchDefinitionManager +{ + /** + * Holds the path to the directory where the definitions are stored. + * + * @var string + */ + private $dir; + + /** + * Holds the search document definitions that are currently cached. + * + * @var array(string=>ezcSearchDocumentDefinition) + */ + private $cache = array(); + + private $typeMap = array( + 'id' => ezcSearchDocumentDefinition::STRING, + 'string' => ezcSearchDocumentDefinition::STRING, + 'text' => ezcSearchDocumentDefinition::TEXT, + 'html' => ezcSearchDocumentDefinition::HTML, + 'date' => ezcSearchDocumentDefinition::DATE, + ); + + /** + * Constructs a new XML manager that will look for search document definitions in the directory $dir. + * + * @param string $dir + */ + public function __construct( $dir ) + { + // append trailing / to $dir if it does not exist. + if ( substr( $dir, -1 ) != DIRECTORY_SEPARATOR ) + { + $dir .= DIRECTORY_SEPARATOR; + } + $this->dir = $dir; + } + + private function parseDefinitionXml( $documentType, $path, SimpleXMLElement $s ) + { + $def = new ezcSearchDocumentDefinition; + + foreach ( $s->field as $field ) + { + if ( $field['type'] == 'id' ) + { + if ( $def->idProperty !== null ) + { + throw new ezcSearchDefinitionInvalidException( 'XML', $documentType, $path, 'Duplicate ID property' ); + } + $def->idProperty = (string) $field; + } + $type = (string) $field['type']; + if ( !isset( $this->typeMap[$type] ) ) + { + throw new ezcSearchDefinitionInvalidException( 'XML', $documentType, $path, "Unknown type: {$type}" ); + } + $type = $this->typeMap[$type]; + $fields[(string) $field] = new ezcSearchDefinitionDocumentField( (string) $field, $type, (float) $field['boost'] ); + } + $def->fields = $fields; + + return $def; + } + + /** + * Returns the definition of the search document with the type $type. + * + * @throws ezcSearchDefinitionNotFoundException if no such definition can be found. + * @throws ezcSearchDefinitionMissingIdPropertyException + * if the definition does not have an "idProperty" attribute. + * @param string $type + * @return ezcSearchDocumentDefinition + */ + public function fetchDefinition( $type ) + { + // check the cache + if ( isset( $this->cache[$type] ) ) + { + return $this->cache[$type]; + } + + // load definition + $definition = null; + $path = $this->dir . strtolower( $type ) . '.xml'; + if ( !file_exists( $path ) ) + { + throw new ezcSearchDefinitionNotFoundException( 'XML', $type, $path ); + } + + $definition = simplexml_load_file( $path, null, LIBXML_NOWARNING | LIBXML_NOERROR ); + if ( !( $definition instanceof SimpleXMLElement ) ) + { + throw new ezcSearchDefinitionInvalidException( 'XML', $type, $path, 'Invalid XML' ); + } + + $definition = self::parseDefinitionXml( $type, $path, $definition ); + + if ( $definition->idProperty === null ) + { + throw new ezcSearchDefinitionInvalidException( 'XML', $type, $path, 'Missing ID property' ); + } + + // store in cache + $this->cache[$type] = $definition; + + // return + return $definition; + } +} + +?> Propchange: trunk/Search/src/managers/xml_manager.php ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/Search/src/search_autoload.php ============================================================================== --- trunk/Search/src/search_autoload.php [iso-8859-1] (original) +++ trunk/Search/src/search_autoload.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -10,17 +10,23 @@ */ return array( - 'ezcSearchException' => 'Search/exceptions/exception.php', - 'ezcSearchCanNotConnectException' => 'Search/exceptions/can_not_connect.php', - 'ezcSearchHandler' => 'Search/interfaces/handler.php', - 'ezcSearchIndexHandler' => 'Search/interfaces/index_handler.php', - 'ezcSearchQuery' => 'Search/abstraction/query.php', - 'ezcSearchCodeManager' => 'Search/managers/code_manager.php', - 'ezcSearchFindQuery' => 'Search/abstraction/query_find.php', - 'ezcSearchQueryInsert' => 'Search/abstraction/query_index.php', - 'ezcSearchResult' => 'Search/search_result.php', - 'ezcSearchSession' => 'Search/search_session.php', - 'ezcSearchSessionInstance' => 'Search/search_session_instance.php', - 'ezcSearchSolrHandler' => 'Search/handlers/solr.php', + 'ezcSearchException' => 'Search/exceptions/exception.php', + 'ezcSearchCanNotConnectException' => 'Search/exceptions/can_not_connect.php', + 'ezcSearchDefinitionInvalidException' => 'Search/exceptions/definition_invalid.php', + 'ezcSearchDefinitionNotFoundException' => 'Search/exceptions/definition_not_found.php', + 'ezcSearchDefinitionManager' => 'Search/interfaces/definition_manager.php', + 'ezcSearchHandler' => 'Search/interfaces/handler.php', + 'ezcSearchIndexHandler' => 'Search/interfaces/index_handler.php', + 'ezcSearchQuery' => 'Search/abstraction/query.php', + 'ezcSearchCodeManager' => 'Search/managers/code_manager.php', + 'ezcSearchDefinitionDocumentField' => 'Search/structs/document_field_definition.php', + 'ezcSearchDocumentDefinition' => 'Search/structs/document_definition.php', + 'ezcSearchFindQuery' => 'Search/abstraction/query_find.php', + 'ezcSearchQueryInsert' => 'Search/abstraction/query_index.php', + 'ezcSearchResult' => 'Search/search_result.php', + 'ezcSearchSession' => 'Search/search_session.php', + 'ezcSearchSessionInstance' => 'Search/search_session_instance.php', + 'ezcSearchSolrHandler' => 'Search/handlers/solr.php', + 'ezcSearchXmlManager' => 'Search/managers/xml_manager.php', ); ?> Added: trunk/Search/src/structs/document_definition.php ============================================================================== --- trunk/Search/src/structs/document_definition.php (added) +++ trunk/Search/src/structs/document_definition.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,17 @@ +<?php +class ezcSearchDocumentDefinition +{ + const STRING = 1; + const TEXT = 2; + const HTML = 3; + const DATE = 4; + + public $idProperty = null; + public $fields = array(); + + public function getFieldNames() + { + return array_keys( $this->fields ); + } +} +?> Propchange: trunk/Search/src/structs/document_definition.php ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/Search/src/structs/document_field_definition.php ============================================================================== --- trunk/Search/src/structs/document_field_definition.php (added) +++ trunk/Search/src/structs/document_field_definition.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,16 @@ +<?php +class ezcSearchDefinitionDocumentField +{ + public $type; + public $field; + public $boost; + + public function __construct( $field, $type, $boost ) + { + $this->field = $field; + $this->type = $type; + $this->boost = $boost; + } + +} +?> Propchange: trunk/Search/src/structs/document_field_definition.php ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/Search/tests/handlers/solr_test.php ============================================================================== --- trunk/Search/tests/handlers/solr_test.php (added) +++ trunk/Search/tests/handlers/solr_test.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,105 @@ +<?php +/** + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version //autogentag// + * @filesource + * @package Search + * @subpackage Tests + */ + +/** + * Test the handler classes. + * + * @package Search + * @subpackage Tests + */ +class ezcSearchHandlerSolrTest extends ezcTestCase +{ + public static function suite() + { + return new PHPUnit_Framework_TestSuite( "ezcSearchHandlerSolrTest" ); + } + + function setUp() + { + $this->solr = new ezcSearchSolrHandler; + } + + function testUnableToConnect() + { + try + { + $s = new ezcSearchSolrHandler( 'localhost', 58983 ); + $r = $s->sendRawGetCommand( 'admin/ping' ); + self::fail( 'Expected exception not thrown.' ); + } + catch ( ezcSearchCanNotConnectException $e ) + { + self::assertEquals( "Could not connect to 'solr' at 'http://localhost:58983//solr'.", $e->getMessage() ); + } + } + + function testConnectAndPing() + { + $r = $this->solr->sendRawGetCommand( 'admin/ping' ); + self::assertContains( "<ping", $r ); + } + + function testSearchEmptyResultsSimple() + { + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + } + + function testSearchEmptyResults() + { + $r = $this->solr->search( 'solr', 'name_s' ); + self::assertType( 'ezcSearchResult', $r ); + self::assertEquals( 0, $r->resultCount ); + self::assertEquals( 0, $r->start ); + self::assertEquals( 0, $r->status ); + } + + function testSimpleIndex() + { + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<add><doc><field name="id">cfe5cc06-9b07-4e4b-930e-7e99f5202570</field><field name="name_s">solr</field></doc></add>' ); + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<commit/>' ); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 1, $r->response->numFound ); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<delete><id>cfe5cc06-9b07-4e4b-930e-7e99f5202570</id></delete>' ); + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<commit/>' ); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + } + + function testSimpleIndexWithSearch() + { + $r = $this->solr->search( 'solr', 'name_s' ); + self::assertEquals( 0, $r->resultCount ); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<add><doc><field name="id">cfe5cc06-9b07-4e4b-930e-7e99f5202570</field><field name="name_s">solr</field></doc></add>' ); + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<commit/>' ); + + $r = $this->solr->search( 'solr', 'name_s', array( 'id', 'name_s', 'score' ) ); + self::assertEquals( 1, $r->resultCount ); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<delete><id>cfe5cc06-9b07-4e4b-930e-7e99f5202570</id></delete>' ); + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<commit/>' ); + + $r = $this->solr->search( 'solr', 'name_s' ); + self::assertEquals( 0, $r->resultCount ); + } +} + +?> Propchange: trunk/Search/tests/handlers/solr_test.php ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/Search/tests/managers/testfiles/article.xml ============================================================================== --- trunk/Search/tests/managers/testfiles/article.xml (added) +++ trunk/Search/tests/managers/testfiles/article.xml [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,8 @@ +<?xml version="1.0"?> +<document> + <field type="id">id</field> + <field type="string" boost="2">title</field> + <field type="text">summary</field> + <field type="html">body</field> + <field type="date">published</field> +</document> Added: trunk/Search/tests/managers/testfiles/duplicateid.xml ============================================================================== --- trunk/Search/tests/managers/testfiles/duplicateid.xml (added) +++ trunk/Search/tests/managers/testfiles/duplicateid.xml [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,9 @@ +<?xml version="1.0"?> +<document> + <field type="id">id</field> + <field type="id">id2</field> + <field type="string" boost="2">title</field> + <field type="text">summary</field> + <field type="html">body</field> + <field type="date">published</field> +</document> Added: trunk/Search/tests/managers/testfiles/invalid.xml ============================================================================== --- trunk/Search/tests/managers/testfiles/invalid.xml (added) +++ trunk/Search/tests/managers/testfiles/invalid.xml [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,3 @@ +<?xml version="1.0"?> +<documen> +</document> Added: trunk/Search/tests/managers/testfiles/mail.xml ============================================================================== --- trunk/Search/tests/managers/testfiles/mail.xml (added) +++ trunk/Search/tests/managers/testfiles/mail.xml [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,8 @@ +<?xml version="1.0"?> +<document> + <field type="id">id</field> + <field type="string" boost="2">title</field> + <field type="text">summary</field> + <field type="html">body</field> + <field type="date">published</field> +</document> Added: trunk/Search/tests/managers/testfiles/missingid.xml ============================================================================== --- trunk/Search/tests/managers/testfiles/missingid.xml (added) +++ trunk/Search/tests/managers/testfiles/missingid.xml [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,7 @@ +<?xml version="1.0"?> +<document> + <field type="string" boost="2">title</field> + <field type="text">summary</field> + <field type="html">body</field> + <field type="date">published</field> +</document> Added: trunk/Search/tests/managers/testfiles/unknowntype.xml ============================================================================== --- trunk/Search/tests/managers/testfiles/unknowntype.xml (added) +++ trunk/Search/tests/managers/testfiles/unknowntype.xml [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,8 @@ +<?xml version="1.0"?> +<document> + <field type="id">id</field> + <field type="unknown" boost="2">title</field> + <field type="text">summary</field> + <field type="html">body</field> + <field type="date">published</field> +</document> Added: trunk/Search/tests/managers/xml_test.php ============================================================================== --- trunk/Search/tests/managers/xml_test.php (added) +++ trunk/Search/tests/managers/xml_test.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,114 @@ +<?php +/** + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version //autogentag// + * @filesource + * @package Search + * @subpackage Tests + */ + +/** + * Test the XML definition reader. + * + * @package Search + * @subpackage Tests + */ +class ezcSearchXmlDefinitionManager extends ezcTestCase +{ + public function setUp() + { + $this->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 ); + } + + public static function suite() + { + return new PHPUnit_Framework_TestSuite( "ezcSearchXmlDefinitionManager" ); + } +} +?> Propchange: trunk/Search/tests/managers/xml_test.php ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/Search/tests/suite.php ============================================================================== --- trunk/Search/tests/suite.php (added) +++ trunk/Search/tests/suite.php [iso-8859-1] Wed Feb 20 10:38:05 2008 @@ -1,0 +1,38 @@ +<?php +/** + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version //autogentag// + * @filesource + * @package Search + * @subpackage Tests + */ + +/** + * Including the tests + */ +require_once 'handlers/solr_test.php'; +require_once 'managers/xml_test.php'; + +/** + * @package Search + * @subpackage Tests + */ +class ezcSearchSuite extends PHPUnit_Framework_TestSuite +{ + public function __construct() + { + parent::__construct(); + $this->setName("Search"); + + $this->addTest( ezcSearchXmlDefinitionManager::suite() ); + $this->addTest( ezcSearchHandlerSolrTest::suite() ); + } + + public static function suite() + { + return new ezcSearchSuite(); + } +} + +?> Propchange: trunk/Search/tests/suite.php ------------------------------------------------------------------------------ svn:eol-style = native -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components