Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Mar 4, 2022
1 parent 551e0cc commit 3201d04
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 146 deletions.
4 changes: 2 additions & 2 deletions src/MShop/Customer/Manager/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
}
}

$sitestr = $this->getSiteString( 'mcusli."siteid"', $level );
$sitestr = $this->siteString( 'mcusli."siteid"', $level );
$keystr = $this->toExpression( 'mcusli."key"', $keys, ( $params[2] ?? null ) ? '==' : '=~' );
$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source );

Expand All @@ -303,7 +303,7 @@ public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
}
}

$sitestr = $this->getSiteString( 'mcuspr."siteid"', $level );
$sitestr = $this->siteString( 'mcuspr."siteid"', $level );
$keystr = $this->toExpression( 'mcuspr."key"', $keys, '=~' );
$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source );

Expand Down
47 changes: 13 additions & 34 deletions tests/MShop/Customer/Manager/Address/LaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,17 @@

class LaravelTest extends \PHPUnit\Framework\TestCase
{
private $fixture = null;
private $object = null;
private $editor = '';
private $fixture;
private $object;


protected function setUp() : void
{
$context = \TestHelper::context();
$this->editor = $context->editor();
$customer = new \Aimeos\MShop\Customer\Manager\Laravel( $context );

$search = $customer->filter();
$conditions = array(
$search->compare( '==', 'customer.code', 'test@example.com' ),
$search->compare( '==', 'customer.editor', $this->editor )
);
$search->setConditions( $search->and( $conditions ) );

if( ( $item = $customer->search( $search )->first() ) === null ) {
throw new \RuntimeException( sprintf( 'No customer item found for code "%1$s"', 'test@example.com' ) );
}
$manager = new \Aimeos\MShop\Customer\Manager\Laravel( $context );

$this->fixture = array(
'customer.address.parentid' => $item->getId(),
'customer.address.parentid' => $manager->find( 'test@example.com' )->getId(),
'customer.address.company' => 'ABC GmbH',
'customer.address.vatid' => 'DE999999999',
'customer.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR,
Expand All @@ -60,7 +47,7 @@ protected function setUp() : void
'customer.address.siteid' => $context->locale()->getSiteId(),
);

$this->object = $customer->getSubManager( 'address', 'Laravel' );
$this->object = $manager->getSubManager( 'address', 'Laravel' );
}


Expand Down Expand Up @@ -102,9 +89,7 @@ public function testGetItem()
$search = $this->object->filter()->slice( 0, 1 );
$search->setConditions( $search->compare( '~=', 'customer.address.company', 'Example company' ) );

if( ( $item = $this->object->search( $search )->first() ) === null ) {
throw new \RuntimeException( 'No address item found' );
}
$item = $this->object->search( $search )->first( new \RuntimeException( 'No address item found' ) );

$this->assertEquals( $item, $this->object->get( $item->getId() ) );
}
Expand All @@ -126,6 +111,7 @@ public function testSaveUpdateDeleteItem()

$this->object->delete( $itemSaved->getId() );

$context = \TestHelper::context();

$this->assertTrue( $item->getId() !== null );
$this->assertEquals( $item->getId(), $itemSaved->getId() );
Expand Down Expand Up @@ -153,7 +139,7 @@ public function testSaveUpdateDeleteItem()
$this->assertEquals( $item->getLatitude(), $itemSaved->getLatitude() );
$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() );

$this->assertEquals( $this->editor, $itemSaved->editor() );
$this->assertEquals( $context->editor(), $itemSaved->editor() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );

Expand Down Expand Up @@ -182,7 +168,7 @@ public function testSaveUpdateDeleteItem()
$this->assertEquals( $itemExp->getLatitude(), $itemUpd->getLatitude() );
$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() );

$this->assertEquals( $this->editor, $itemUpd->editor() );
$this->assertEquals( $context->editor(), $itemUpd->editor() );
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );

Expand All @@ -200,7 +186,7 @@ public function testCreateSearch()
}


public function testSearchItem()
public function testSearch()
{
$search = $this->object->filter();

Expand Down Expand Up @@ -230,25 +216,18 @@ public function testSearchItem()
$search->compare( '==', 'customer.address.birthday', '2000-01-01' ),
$search->compare( '>=', 'customer.address.mtime', '1970-01-01 00:00:00' ),
$search->compare( '>=', 'customer.address.ctime', '1970-01-01 00:00:00' ),
$search->compare( '==', 'customer.address.editor', $this->editor ),
$search->compare( '!=', 'customer.address.editor', '' ),
);
$search->setConditions( $search->and( $conditions ) );
$this->assertEquals( 1, count( $this->object->search( $search ) ) );
}


public function testSearchItemTotal()
public function testSearchTotal()
{
$total = 0;
$search = $this->object->filter();

$conditions = array(
$search->compare( '~=', 'customer.address.company', 'Example company' ),
$search->compare( '==', 'customer.address.editor', $this->editor )
);

$search->setConditions( $search->and( $conditions ) );
$search->slice( 0, 2 );
$search->add( $search->compare( '~=', 'customer.address.company', 'Example company' ) )->slice( 0, 2 );

$results = $this->object->search( $search, [], $total );

Expand Down
25 changes: 8 additions & 17 deletions tests/MShop/Customer/Manager/LaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ class LaravelTest extends \PHPUnit\Framework\TestCase
private $object;
private $fixture;
private $address;
private $editor = '';


protected function setUp() : void
{
$context = \TestHelper::context();
$this->editor = $context->editor();
$this->object = new \Aimeos\MShop\Customer\Manager\Laravel( $context );

$this->fixture = array(
Expand Down Expand Up @@ -110,6 +108,7 @@ public function testSaveUpdateDeleteItem()

$this->object->delete( $item->getId() );

$context = \TestHelper::context();

$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $item );
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $itemExp );
Expand All @@ -122,7 +121,7 @@ public function testSaveUpdateDeleteItem()
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() );

$this->assertEquals( $this->editor, $itemSaved->editor() );
$this->assertEquals( $context->editor(), $itemSaved->editor() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );

Expand All @@ -133,7 +132,7 @@ public function testSaveUpdateDeleteItem()
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() );

$this->assertEquals( $this->editor, $itemUpd->editor() );
$this->assertEquals( $context->editor(), $itemUpd->editor() );
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );

Expand Down Expand Up @@ -199,7 +198,7 @@ public function testSearchItems()
$expr[] = $search->compare( '==', 'customer.status', 1 );
$expr[] = $search->compare( '>', 'customer.mtime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '>', 'customer.ctime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '==', 'customer.editor', $this->editor );
$expr[] = $search->compare( '!=', 'customer.editor', '' );

$expr[] = $search->compare( '==', 'customer.salutation', 'mr' );
$expr[] = $search->compare( '==', 'customer.company', 'Example company' );
Expand Down Expand Up @@ -267,7 +266,7 @@ public function testSearchItems()
$expr[] = $search->compare( '==', 'customer.address.birthday', '2000-01-01' );
$expr[] = $search->compare( '>=', 'customer.address.mtime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '>=', 'customer.address.ctime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
$expr[] = $search->compare( '!=', 'customer.address.editor', '' );

$search->setConditions( $search->and( $expr ) );
$result = $this->object->search( $search );
Expand All @@ -278,12 +277,10 @@ public function testSearchItems()
public function testSearchItemsTotal()
{
$total = 0;

$search = $this->object->filter();
$search->setConditions( $search->compare( '==', 'customer.address.editor', $this->editor ) );
$search->slice( 0, 2 );
$search = $this->object->filter()->slice( 0, 2 );

$results = $this->object->search( $search, [], $total );

$this->assertEquals( 2, count( $results ) );
$this->assertEquals( 3, $total );

Expand All @@ -295,13 +292,7 @@ public function testSearchItemsTotal()

public function testSearchItemsCriteria()
{
$search = $this->object->filter( true );
$conditions = array(
$search->compare( '==', 'customer.address.editor', $this->editor ),
$search->getConditions()
);
$search->setConditions( $search->and( $conditions ) );
$this->assertEquals( 2, count( $this->object->search( $search, [], $total ) ) );
$this->assertEquals( 2, count( $this->object->search( $this->object->filter( true ) ) ) );
}


Expand Down
37 changes: 12 additions & 25 deletions tests/MShop/Customer/Manager/Lists/LaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ class LaravelTest extends \PHPUnit\Framework\TestCase
{
private $object;
private $context;
private $editor = 'ai-laravel:lib/custom';


protected function setUp() : void
{
$this->context = \TestHelper::context();
$this->editor = $this->context->editor();
$manager = \Aimeos\MShop\Customer\Manager\Factory::create( $this->context, 'Laravel' );

$this->object = $manager->getSubManager( 'lists', 'Laravel' );
}

Expand All @@ -40,11 +39,6 @@ public function testClear()
public function testAggregate()
{
$search = $this->object->filter( true );
$expr = array(
$search->getConditions(),
$search->compare( '==', 'customer.lists.editor', 'ai-laravel:lib/custom' ),
);
$search->setConditions( $search->and( $expr ) );

$result = $this->object->aggregate( $search, 'customer.lists.domain' )->toArray();

Expand All @@ -63,10 +57,7 @@ public function testCreateItem()
public function testGetItem()
{
$search = $this->object->filter()->slice( 0, 1 );

if( ( $item = $this->object->search( $search )->first() ) === null ) {
throw new \RuntimeException( 'No item found' );
}
$item = $this->object->search( $search )->first( new \RuntimeException( 'No item found' ) );

$this->assertEquals( $item, $this->object->get( $item->getId() ) );
}
Expand All @@ -75,10 +66,7 @@ public function testGetItem()
public function testSaveUpdateDeleteItem()
{
$search = $this->object->filter()->slice( 0, 1 );

if( ( $item = $this->object->search( $search )->first() ) === null ) {
throw new \RuntimeException( 'No item found' );
}
$item = $this->object->search( $search )->first( new \RuntimeException( 'No item found' ) );

$item->setId( null );
$item->setDomain( 'unittest' );
Expand All @@ -92,6 +80,7 @@ public function testSaveUpdateDeleteItem()

$this->object->delete( $itemSaved->getId() );

$context = \TestHelper::context();

$this->assertTrue( $item->getId() !== null );
$this->assertEquals( $item->getId(), $itemSaved->getId() );
Expand All @@ -103,11 +92,11 @@ public function testSaveUpdateDeleteItem()
$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() );
$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() );
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() );
$this->assertEquals( $this->editor, $itemSaved->editor() );
$this->assertEquals( $context->editor(), $itemSaved->editor() );
$this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeCreated() );
$this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeModified() );

$this->assertEquals( $this->editor, $itemSaved->editor() );
$this->assertEquals( $context->editor(), $itemSaved->editor() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );

Expand All @@ -121,7 +110,7 @@ public function testSaveUpdateDeleteItem()
$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() );
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() );

$this->assertEquals( $this->editor, $itemUpd->editor() );
$this->assertEquals( $context->editor(), $itemUpd->editor() );
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );

Expand Down Expand Up @@ -153,11 +142,12 @@ public function testSearchItems()
$expr[] = $search->compare( '==', 'customer.lists.status', 1 );
$expr[] = $search->compare( '>=', 'customer.lists.mtime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '>=', 'customer.lists.ctime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '==', 'customer.lists.editor', $this->editor );
$expr[] = $search->compare( '!=', 'customer.lists.editor', '' );

$search->setConditions( $search->and( $expr ) );
$search->slice( 0, 2 );
$results = $this->object->search( $search, [], $total );

$this->assertEquals( 2, count( $results ) );
$this->assertEquals( 3, $total );

Expand All @@ -169,18 +159,15 @@ public function testSearchItems()

public function testSearchItemsAll()
{
//search without base criteria
$search = $this->object->filter()->add( ['customer.lists.editor' => $this->editor] );
$result = $this->object->search( $search );
$result = $this->object->search( $this->object->filter() );
$this->assertGreaterThanOrEqual( 5, count( $result ) );
}


public function testSearchItemsBase()
{
//search with base criteria
$search = $this->object->filter( true )->add( ['customer.lists.editor' => $this->editor] );
$this->assertGreaterThanOrEqual( 5, count( $this->object->search( $search ) ) );
$result = $this->object->search( $this->object->filter( true ) );
$this->assertGreaterThanOrEqual( 5, count( $result ) );
}


Expand Down

0 comments on commit 3201d04

Please sign in to comment.