From 9dd3d0ff6f3bbc49456bb7bb9cff0fb98988c5cc Mon Sep 17 00:00:00 2001 From: Aimeos Date: Thu, 20 Jun 2019 21:29:45 +0200 Subject: [PATCH] Streamlined index manager tests for MySQL and PostgreSQL --- .../tests/MShop/Index/Manager/MySQLTest.php | 80 +++--------------- .../tests/MShop/Index/Manager/PgSQLTest.php | 84 +++---------------- 2 files changed, 22 insertions(+), 142 deletions(-) diff --git a/lib/mshoplib/tests/MShop/Index/Manager/MySQLTest.php b/lib/mshoplib/tests/MShop/Index/Manager/MySQLTest.php index fe8d905f9d..97bf9d576a 100644 --- a/lib/mshoplib/tests/MShop/Index/Manager/MySQLTest.php +++ b/lib/mshoplib/tests/MShop/Index/Manager/MySQLTest.php @@ -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(); @@ -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(); - } } diff --git a/lib/mshoplib/tests/MShop/Index/Manager/PgSQLTest.php b/lib/mshoplib/tests/MShop/Index/Manager/PgSQLTest.php index 7019c0025b..25b67fe781 100644 --- a/lib/mshoplib/tests/MShop/Index/Manager/PgSQLTest.php +++ b/lib/mshoplib/tests/MShop/Index/Manager/PgSQLTest.php @@ -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(); @@ -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(); } }