This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
/
StandardTest.php
123 lines (97 loc) · 4.07 KB
/
StandardTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Aimeos\Controller\ExtJS\Product;
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Metaways Infosystems GmbH, 2011
* @copyright Aimeos (aimeos.org), 2015-2017
*/
class StandardTest extends \PHPUnit\Framework\TestCase
{
private $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
$this->object = new \Aimeos\Controller\ExtJS\Product\Standard( \TestHelperExtjs::getContext() );
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
*/
protected function tearDown()
{
$this->object = null;
}
public function testSearchItems()
{
$params = (object) array(
'site' => 'unittest',
'condition' => (object) array( '&&' => array( 0 => array( '~=' => (object) array( 'product.label' => 'Cafe' ) ) ) ),
'sort' => 'product.label',
'dir' => 'ASC',
'start' => 0,
'limit' => 1,
);
$result = $this->object->searchItems( $params );
$this->assertEquals( 1, count( $result['items'] ) );
$this->assertEquals( 2, $result['total'] );
}
public function testSaveDeleteItem()
{
$productManager = \Aimeos\MShop\Product\Manager\Factory::createManager( \TestHelperExtjs::getContext() );
$typeManager = $productManager->getSubManager( 'type' );
$search = $typeManager->createSearch();
$search->setConditions( $search->compare( '==', 'product.type.code', 'default' ) );
$result = $typeManager->searchItems( $search );
if( ( $type = reset( $result ) ) === false ) {
throw new \RuntimeException( 'No product type found' );
}
$saveParams = (object) array(
'site' => 'unittest',
'items' => (object) array(
'product.code' => 'test',
'product.label' => 'test product',
'product.status' => 1,
'product.datestart' => '2000-01-01 00:00:00',
'product.dateend' => '2001-01-01 00:00:00',
'product.typeid' => $type->getId(),
'product.config' => (object) array( 'key' => 'value' ),
),
);
$searchParams = (object) array(
'site' => 'unittest',
'condition' => (object) array( '&&' => array( 0 => array( '==' => (object) array( 'product.code' => 'test' ) ) ) )
);
$saved = $this->object->saveItems( $saveParams );
$searched = $this->object->searchItems( $searchParams );
$deleteParams = (object) array( 'site' => 'unittest', 'items' => $saved['items']->{'product.id'} );
$this->object->deleteItems( $deleteParams );
$result = $this->object->searchItems( $searchParams );
$this->assertInternalType( 'object', $saved['items'] );
$this->assertNotNull( $saved['items']->{'product.id'} );
$this->assertEquals( $saved['items']->{'product.id'}, $searched['items'][0]->{'product.id'} );
$this->assertEquals( $saved['items']->{'product.code'}, $searched['items'][0]->{'product.code'} );
$this->assertEquals( $saved['items']->{'product.label'}, $searched['items'][0]->{'product.label'} );
$this->assertEquals( $saved['items']->{'product.status'}, $searched['items'][0]->{'product.status'} );
$this->assertEquals( $saved['items']->{'product.datestart'}, $searched['items'][0]->{'product.datestart'} );
$this->assertEquals( $saved['items']->{'product.dateend'}, $searched['items'][0]->{'product.dateend'} );
$this->assertEquals( $saved['items']->{'product.typeid'}, $searched['items'][0]->{'product.typeid'} );
$this->assertEquals( $saved['items']->{'product.config'}, $searched['items'][0]->{'product.config'} );
$this->assertEquals( 1, count( $searched['items'] ) );
$this->assertEquals( 0, count( $result['items'] ) );
}
public function testFinish()
{
$productManager = \Aimeos\MShop\Product\Manager\Factory::createManager( \TestHelperExtjs::getContext() );
$search = $productManager->createSearch();
$search->setConditions( $search->compare( '==', 'product.code', array( 'CNC', 'CNE' ) ) );
$result = $productManager->searchItems( $search );
$this->object->finish( (object) array( 'site' => 'unittest', 'items' => array_keys( $result ) ) );
}
}