blob: b1928d682370024f40581a41da6c4347f6e07aae [file] [log] [blame]
<?php
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @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__ ) . DIRECTORY_SEPARATOR . 'testfiles' . DIRECTORY_SEPARATOR;
}
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 testCanNotFindDefinitionFileWithoutDirSlash()
{
$m = new ezcSearchXmlManager( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'testfiles' );
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', 'author' ), $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( true, $d->fields['body']->highlight );
self::assertEquals( false, $d->fields['summary']->highlight );
self::assertEquals( true, $d->fields['author']->multi );
self::assertEquals( false, $d->fields['summary']->multi );
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 ezcSearchXmlManager( $this->testFilesDir );
$e = $m->fetchDefinition( 'Article' );
$d = $m->fetchDefinition( 'Article' );
self::assertEquals( 'id', $d->idProperty );
self::assertEquals( array( 'id', 'title', 'summary', 'body', 'published', 'author' ), $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( true, $d->fields['body']->highlight );
self::assertEquals( false, $d->fields['summary']->highlight );
self::assertEquals( true, $d->fields['author']->multi );
self::assertEquals( false, $d->fields['summary']->multi );
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( "ezcSearchXmlDefinitionManager" );
}
}
?>