Skip to content

Commit

Permalink
Streamlined index manager tests for MySQL and PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jun 20, 2019
1 parent b794311 commit 9dd3d0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 142 deletions.
80 changes: 11 additions & 69 deletions lib/mshoplib/tests/MShop/Index/Manager/MySQLTest.php
Expand Up @@ -16,33 +16,6 @@ class MySQLTest extends \PHPUnit\Framework\TestCase
private $editor;


public static function setUpBeforeClass()
{
$context = clone \TestHelperMShop::getContext();
$config = $context->getConfig();
$dbadapter = $config->get( 'resource/db-index/adapter', $config->get( 'resource/db/adapter' ) );

if( $dbadapter === 'mysql' )
{
$context->getConfig()->set( 'mshop/index/manager/text/name', 'MySQL' );
$manager = new \Aimeos\MShop\Index\Manager\MySQL( $context );
$productManager = \Aimeos\MShop\Product\Manager\Factory::create( $context );

$search = $productManager->createSearch();
$conditions = array(
$search->compare( '==', 'product.code', array( 'CNC', 'CNE' ) ),
$search->compare( '==', 'product.editor', $context->getEditor() )
);
$search->setConditions( $search->combine( '&&', $conditions ) );
$result = $productManager->searchItems( $search, array( 'attribute', 'price', 'text', 'product' ) );

foreach( $result as $item ) {
$manager->saveItem( $item );
}
}
}


protected function setUp()
{
$context = clone \TestHelperMShop::getContext();
Expand All @@ -66,56 +39,25 @@ protected function tearDown()
}


public function testGetSearchAttributes()
{
$list = $this->object->getSearchAttributes();

foreach( $list as $attribute ) {
$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute );
}
}


public function testSearchItemsRelevance()
public function testSearchItemsSub()
{
$total = 0;
$search = $this->object->createSearch()->setSlice( 0, 1 );

$func = $search->createFunction( 'index.text:relevance', array( 'de', 'Cafe' ) );
$conditions = array(
$search->compare( '>', $func, 0 ), // text relevance
$search = $this->object->createSearch();
$search->setSlice( 0, 1 );

$expr = array(
$search->compare( '!=', 'index.attribute.id', null ),
$search->compare( '!=', 'index.catalog.id', null ),
$search->compare( '!=', 'index.supplier.id', null ),
$search->compare( '>=', $search->createFunction( 'index.price:value', ['EUR'] ), 0 ),
$search->compare( '>=', $search->createFunction( 'index.text:name', ['de'] ), '' ),
$search->compare( '==', 'product.editor', $this->editor )
);
$search->setConditions( $search->combine( '&&', $conditions ) );
$result = $this->object->searchItems( $search, [], $total );

$this->assertEquals( 1, count( $result ) );
$this->assertEquals( 2, $total );
}


public function testSearchItemsName()
{
$total = 0;
$search = $this->object->createSearch()->setSlice( 0, 1 );

$func = $search->createFunction( 'index.text:name', array( 'de' ) );
$conditions = array(
$search->compare( '~=', $func, 'Noir' ), // text value
$search->compare( '==', 'product.editor', $this->editor )
);
$search->setConditions( $search->combine( '&&', $conditions ) );
$sortfunc = $search->createFunction( 'sort:index.text:name', array( 'de' ) );
$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
$search->setConditions( $search->combine( '&&', $expr ) );
$result = $this->object->searchItems( $search, [], $total );

$this->assertEquals( 1, count( $result ) );
$this->assertEquals( 2, $total );
}


public function testOptimize()
{
$this->object->optimize();
}
}
84 changes: 11 additions & 73 deletions lib/mshoplib/tests/MShop/Index/Manager/PgSQLTest.php
Expand Up @@ -15,33 +15,6 @@ class PgSQLTest extends \PHPUnit\Framework\TestCase
private $editor;


public static function setUpBeforeClass()
{
$context = clone \TestHelperMShop::getContext();
$config = $context->getConfig();
$dbadapter = $config->get( 'resource/db-index/adapter', $config->get( 'resource/db/adapter' ) );

if( $dbadapter === 'pgsql' )
{
$context->getConfig()->set( 'mshop/index/manager/text/name', 'PgSQL' );
$manager = new \Aimeos\MShop\Index\Manager\MySQL( $context );
$productManager = \Aimeos\MShop\Product\Manager\Factory::create( $context );

$search = $productManager->createSearch();
$conditions = array(
$search->compare( '==', 'product.code', array( 'CNC', 'CNE' ) ),
$search->compare( '==', 'product.editor', $context->getEditor() )
);
$search->setConditions( $search->combine( '&&', $conditions ) );
$result = $productManager->searchItems( $search, array( 'attribute', 'price', 'text', 'product' ) );

foreach( $result as $item ) {
$manager->saveItem( $item );
}
}
}


protected function setUp()
{
$context = clone \TestHelperMShop::getContext();
Expand All @@ -65,60 +38,25 @@ protected function tearDown()
}


public function testGetSearchAttributes()
{
$list = $this->object->getSearchAttributes();

foreach( $list as $attribute ) {
$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute );
}
}


public function testSearchItemsRelevance()
public function testSearchItemsSub()
{
$total = 0;
$search = $this->object->createSearch()->setSlice( 0, 1 );

$func = $search->createFunction( 'index.text:relevance', array( 'de', 'Expr' ) );
$conditions = array(
$search->compare( '>', $func, 0 ), // text relevance
$search = $this->object->createSearch();
$search->setSlice( 0, 1 );

$expr = array(
$search->compare( '!=', 'index.attribute.id', null ),
$search->compare( '!=', 'index.catalog.id', null ),
$search->compare( '!=', 'index.supplier.id', null ),
$search->compare( '>=', $search->createFunction( 'index.price:value', ['EUR'] ), 0 ),
$search->compare( '>=', $search->createFunction( 'index.text:name', ['de'] ), '' ),
$search->compare( '==', 'product.editor', $this->editor )
);
$search->setConditions( $search->combine( '&&', $conditions ) );
$result = $this->object->searchItems( $search, [], $total );

$this->assertEquals( 1, count( $result ) );
$this->assertEquals( 2, $total );
}


public function testSearchItemsName()
{
$total = 0;
$search = $this->object->createSearch()->setSlice( 0, 1 );

$func = $search->createFunction( 'index.text:name', array( 'de' ) );
$conditions = array(
$search->compare( '~=', $func, 'Noir' ), // text name
$search->compare( '==', 'product.editor', $this->editor )
);
$search->setConditions( $search->combine( '&&', $conditions ) );
$sortfunc = $search->createFunction( 'sort:index.text:name', array( 'de' ) );
$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
$search->setConditions( $search->combine( '&&', $expr ) );
$result = $this->object->searchItems( $search, [], $total );

$this->assertEquals( 1, count( $result ) );
$this->assertEquals( 2, $total );

foreach( $result as $itemId => $item ) {
$this->assertEquals( $itemId, $item->getId() );
}
}


public function testOptimize()
{
$this->object->optimize();
}
}

0 comments on commit 9dd3d0f

Please sign in to comment.