Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing unit tests #76

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion classes/ezfezpsolrquerybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
if ( !$contentClassAttributeID )
{
$queryFields[] = eZSolr::getMetaFieldName( 'name' );
$queryFields[] = eZSolr::getMetaFieldName( 'owner_name' );
if ( !self::$FindINI->hasVariable( 'SearchFilters', 'ExcludeOwnerName' ) || self::$FindINI->variable( 'SearchFilters', 'ExcludeOwnerName' ) !== 'enabled' )
{
$queryFields[] = eZSolr::getMetaFieldName( 'owner_name' );
}
}


Expand Down
14 changes: 13 additions & 1 deletion classes/ezfsearchresultinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function attributes()
// spellcheck dictionary/index -- Solr php response writer "bug"
'spellcheck_collation',
'interestingTerms',
'clusters'
'clusters',
'highlighting'
);
}

Expand Down Expand Up @@ -327,6 +328,17 @@ public function attribute( $attr )
return false;
}
} break;
case 'highlighting':
{
if ( isset( $this->ResultArray['highlighting'] ) )
{
return $this->ResultArray['highlighting'];
}
else
{
return false;
}
} break;

default:
{
Expand Down
5 changes: 5 additions & 0 deletions search/plugins/ezsolr/ezsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ static function getFieldName( $baseName, $includingClassID = false, $context = '
return null;
}
$contentClassAttribute = eZContentClassAttribute::fetch( $contentClassAttributeID );
if ( ! $contentClassAttribute instanceof eZContentClassAttribute )
{
eZDebug::writeNotice( "Can not find field name for classattribute, id: $contentClassAttributeID, basename: $baseName", __METHOD__ );
return null;
}
$fieldName = ezfSolrDocumentFieldBase::getFieldName( $contentClassAttribute, $subattribute, $context );

if ( $includingClassID )
Expand Down
3 changes: 3 additions & 0 deletions settings/ezfind.ini
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ ClassIdentifierList[]
#Set to enabled if this is the case
FilterHiddenFromDB=disabled

# Option to exclude owner name from being used as a query field in searches (default: disabled )
# ExcludeOwnerName=enabled

[MoreLikeThis]
#Experimental!!
#fields to use for query term extraction: proper fields "native",
Expand Down
16 changes: 8 additions & 8 deletions tests/classes/ezfezpsolrquerybuilder_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ public function testBuildLanguageFilterQuery()

// test with searchMainLanguageOnly = disabled
self::$findINI->setVariable( 'LanguageSearch', 'SearchMainLanguageOnly', 'disabled' );
$expectedValue = "meta_language_code_s:eng-GB OR ( meta_language_code_s:fre-FR AND -meta_available_language_codes_s:eng-GB ) OR ( meta_language_code_s:nor-NO AND -meta_available_language_codes_s:eng-GB AND -meta_available_language_codes_s:fre-FR )";
$expectedValue = 'meta_language_code_ms:eng-GB OR ( meta_language_code_ms:fre-FR AND -meta_available_language_codes_ms:eng-GB ) OR ( meta_language_code_ms:nor-NO AND -meta_available_language_codes_ms:eng-GB AND -meta_available_language_codes_ms:fre-FR ) OR ( meta_always_available_b:true AND -meta_available_language_codes_ms:eng-GB AND -meta_available_language_codes_ms:fre-FR AND -meta_available_language_codes_ms:nor-NO)';
$value = self::$qb->buildLanguageFilterQuery();
self::assertEquals( $expectedValue, $value, "SearchMainLanguageOnly=disabled" );

// test with searchMainLanguageOnly = enabled
self::$findINI->setVariable( 'LanguageSearch', 'SearchMainLanguageOnly', 'enabled' );
$expectedValue = "meta_language_code_s:eng-GB";
$expectedValue = "meta_language_code_ms:eng-GB";
$value = self::$qb->buildLanguageFilterQuery();
self::assertEquals( $expectedValue, $value, "SearchMainLanguageOnly=enabled" );
}
Expand All @@ -145,16 +145,16 @@ public static function providerTestBuildSortParameter()

array( array( 'published' => 'asc' ), 'meta_published_dt asc' ),
array( array( 'modified' => 'asc' ), 'meta_modified_dt asc' ),
array( array( 'class_name' => 'asc' ), 'meta_class_name_t asc' ),
array( array( 'class_identifier' => 'asc' ), 'meta_class_identifier_s asc' ),
array( array( 'name' => 'asc' ), 'meta_name_t asc' ),
array( array( 'path' => 'asc' ), 'meta_path_si asc' ),
array( array( 'class_name' => 'asc' ), 'meta_class_name_ms asc' ),
array( array( 'class_identifier' => 'asc' ), 'meta_class_identifier_ms asc' ),
array( array( 'name' => 'asc' ), 'meta_sort_name_ms asc' ),
array( array( 'path' => 'asc' ), 'meta_main_path_string_ms asc' ),
array( array( 'section_id' => 'asc' ), 'meta_section_id_si asc' ),
array( array( 'author' => 'asc' ), 'meta_owner_name_t asc' ),

// a few attributes
array( array( 'article/title' => 'asc' ), ezfSolrDocumentFieldBase::ATTR_FIELD_PREFIX . 'title_t asc' ),
array( array( 'folder/name' => 'asc' ), ezfSolrDocumentFieldBase::ATTR_FIELD_PREFIX . 'name_t asc' ),
array( array( 'article/title' => 'asc' ), ezfSolrDocumentFieldBase::ATTR_FIELD_PREFIX . 'title_s asc' ),
array( array( 'folder/name' => 'asc' ), ezfSolrDocumentFieldBase::ATTR_FIELD_PREFIX . 'name_s asc' ),
array( array( 'article/body' => 'asc' ), ezfSolrDocumentFieldBase::ATTR_FIELD_PREFIX . 'body_t asc' ),
);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/classes/ezfezpsolrquerybuilder_tester.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class ezfeZPSolrQueryBuilderTester extends ezfeZPSolrQueryBuilder
public function __construct()
{
parent::__construct( new eZSolr() );

eZINI::instance( 'ezfind.ini' )->loadCache( true );
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/classes/ezfindelevateconfiguration_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
/**
* Test suite for eZFindElevateConfiguration
**/
class eZFindElevateConfigurationTest extends ezpDatabaseTestCase
class eZFindElevateConfigurationTest extends ezFindTestCase
{
protected $backupGlobals = false;

protected $sqlFiles = array( 'extension/ezfind/sql/mysql/mysql.sql' );

public function setUp()
{
parent::setUp();
ezpTestDatabaseHelper::insertSqlData( $this->sharedFixture, $this->sqlFiles );
}

/**
* Data provider for testGetRuntimeQueryParameters
*/
Expand Down
117 changes: 117 additions & 0 deletions tests/classes/ezfindfetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
* File containing eZFindFetchRegression class
*
* @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/gnu_gpl GNU GPLv2
* @package ezfind
*/
class eZFindFetch extends ezFindTestCase
{
protected $fetchParams;

/**
* @var eZContentObject
*/
protected $testObj;

/**
* @var eZSolr
*/
protected $solrSearch;

public function setUp()
{
parent::setUp();

eZINI::instance( 'ezfind.ini' )->loadCache( true );
eZINI::instance( 'solr.ini' )->loadCache( true );
ezpINIHelper::setINISetting( 'site.ini', 'SearchSettings', 'AllowEmptySearch', 'enabled' );
ezpINIHelper::setINISetting( 'site.ini', 'RegionalSettings', 'SiteLanguageList', array( 'eng-GB' ) );
$this->solrSearch = new eZSolr();
$this->testObj = eZContentObject::fetchByNodeID( 2 );
$this->solrSearch->addObject( $this->testObj );

$this->fetchParams = array(
'SearchOffset' => 0,
'SearchLimit' => 10,
'Facet' => null,
'SortBy' => null,
'Filter' => null,
'SearchContentClassID' => null,
'SearchSectionID' => null,
'SearchSubTreeArray' => null,
'AsObjects' => null,
'SpellCheck' => null,
'IgnoreVisibility' => null,
'Limitation' => null,
'BoostFunctions' => null,
'QueryHandler' => 'ezpublish',
'EnableElevation' => null,
'ForceElevation' => null,
'SearchDate' => null,
'DistributedSearch' => null,
'FieldsToReturn' => null
);
}

public function tearDown()
{
$this->solrSearch->removeObject( $this->testObj );
ezpINIHelper::restoreINISettings();
parent::tearDown();
}

/**
*/
public function testSearch()
{
$res = $this->solrSearch->search( '', array( 'Filter' => 'meta_node_id_si:2' ) );

self::assertInternalType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res['SearchResult'] );
self::assertCount( 1, $res[ 'SearchResult' ] );
self::assertEquals( 1, $res[ 'SearchCount' ] );

$rootNode = $res['SearchResult'][0];

self::assertTrue( $rootNode instanceof eZFindResultNode );
}

public function testNonObjectSearch()
{
$res = $this->solrSearch->search( '', array( 'Filter' => 'meta_node_id_si:2',
'AsObjects' => false ) );

self::assertInternalType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res['SearchResult'] );
self::assertCount( 1, $res[ 'SearchResult' ] );
self::assertEquals( 1, $res[ 'SearchCount' ] );
self::assertTrue( $res['SearchResult'][0][ 'main_node_id' ] == 2 );
}

public function testMoreLikeThis()
{
$res = $this->solrSearch->moreLikeThis( 'text', 'ez publish' );

self::assertInternalType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res['SearchResult'] );
self::assertCount( 1, $res[ 'SearchResult' ] );
self::assertEquals( 1, $res[ 'SearchCount' ] );

$rootNode = $res['SearchResult'][0];

self::assertTrue( $rootNode instanceof eZFindResultNode );
}

public function testNonObjectMoreLikeThis()
{
$res = $this->solrSearch->moreLikeThis( 'text', 'ez publish', array( 'AsObjects' => false ) );

self::assertInternalType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res['SearchResult'] );
self::assertCount( 1, $res[ 'SearchResult' ] );
self::assertEquals( 1, $res[ 'SearchCount' ] );

self::assertTrue( $res['SearchResult'][0][ 'main_node_id' ] == 2 );
}

}

?>
22 changes: 22 additions & 0 deletions tests/classes/ezfindtestcase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

class ezFindTestCase extends ezpDatabaseTestCase
{
/*
* SharedFixture == db connection (strange name?)
*
* Lazy init
*/
protected function getSharedFixture()
{
if( !$this->sharedFixture )
{
$dsn = ezpTestRunner::dsn();
$this->sharedFixture = ezpDatabaseHelper::useDatabase( $dsn );
}

return $this->sharedFixture;
}
}

?>
Loading