Passed
Push — master ( 54ca64...d44c58 )
by Aimeos
04:37
created

StandardTest::testSaveException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Product\Supplier;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->view = \TestHelperJqadm::getView();
22
		$this->context = \TestHelperJqadm::getContext();
23
24
		$this->object = new \Aimeos\Admin\JQAdm\Product\Supplier\Standard( $this->context );
25
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
26
		$this->object->setAimeos( \TestHelperJqadm::getAimeos() );
27
		$this->object->setView( $this->view );
28
	}
29
30
31
	protected function tearDown() : void
32
	{
33
		unset( $this->object, $this->view, $this->context );
34
	}
35
36
37
	public function testCreate()
38
	{
39
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
40
41
		$this->view->item = $manager->createItem();
42
		$result = $this->object->create();
43
44
		$this->assertStringContainsString( 'item-supplier', $result );
45
		$this->assertEmpty( $this->view->get( 'errors' ) );
46
	}
47
48
49
	public function testCopy()
50
	{
51
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
52
53
		$this->view->item = $manager->findItem( 'CNC' );
54
		$result = $this->object->copy();
55
56
		$this->assertEmpty( $this->view->get( 'errors' ) );
57
		$this->assertRegexp( '/&quot;supplier.label&quot;:&quot;unitSupplier001&quot;/', $result );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$result = $this->object->delete();
64
65
		$this->assertEmpty( $this->view->get( 'errors' ) );
66
		$this->assertEmpty( $result );
67
	}
68
69
70
	public function testGet()
71
	{
72
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
73
74
		$this->view->item = $manager->findItem( 'CNC' );
75
		$result = $this->object->get();
76
77
		$this->assertEmpty( $this->view->get( 'errors' ) );
78
		$this->assertRegexp( '/&quot;supplier.label&quot;:&quot;unitSupplier001&quot;/', $result );
79
	}
80
81
82
	public function testSave()
83
	{
84
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
85
		$productManager = \Aimeos\MShop::create( $this->context, 'product' );
86
87
		$item = $manager->findItem( 'unitCode001' );
88
		$item->setCode( 'jqadm-test-supplier' );
89
		$item->setId( null );
90
91
		$item = $manager->saveItem( $item );
0 ignored issues
show
Bug introduced by
The method saveItem() does not exist on Aimeos\MShop\Common\Manager\Iface. Did you maybe mean saveItems()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
		/** @scrutinizer ignore-call */ 
92
  $item = $manager->saveItem( $item );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
93
94
		$param = array(
95
			'site' => 'unittest',
96
			'supplier' => [[
97
				'supplier.lists.id' => '',
98
				'supplier.lists.type' => 'default',
99
				'supplier.id' => $item->getId(),
100
			]]
101
		);
102
103
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
104
		$this->view->addHelper( 'param', $helper );
105
		$this->view->item = $productManager->createItem()->setId( -1 );
106
107
		$result = $this->object->save();
108
109
		$item = $manager->getItem( $item->getId(), array( 'product' ) );
110
		$manager->deleteItem( $item->getId() );
111
112
		$this->assertEmpty( $this->view->get( 'errors' ) );
113
		$this->assertEmpty( $result );
114
		$this->assertEquals( 1, count( $item->getListItems( 'product' ) ) );
115
	}
116
117
118
	public function testSaveException()
119
	{
120
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Supplier\Standard::class )
121
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
122
			->setMethods( array( 'fromArray' ) )
123
			->getMock();
124
125
		$object->expects( $this->once() )->method( 'fromArray' )
126
			->will( $this->throwException( new \RuntimeException() ) );
127
128
		$this->view = \TestHelperJqadm::getView();
129
		$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
130
131
		$object->setView( $this->view );
132
133
		$this->expectException( \RuntimeException::class );
134
		$object->save();
135
	}
136
137
138
	public function testSearch()
139
	{
140
		$this->assertEmpty( $this->object->search() );
141
	}
142
143
144
	public function testGetSubClient()
145
	{
146
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
147
		$this->object->getSubClient( 'unknown' );
148
	}
149
}
150