Completed
Push — master ( 52d06b...ee11f0 )
by Aimeos
04:53
created

CacheTest::testSave()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 9
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 15
rs 9.9666
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2020
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Common\Decorator;
10
11
12
class CacheTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $mock;
17
	private $cache;
18
19
20
	protected function setUp() : void
21
	{
22
		$this->cache = $this->getMockBuilder( 'Aimeos\MW\Cache\None' )
23
			->setMethods( array( 'deleteByTags' ) )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->mock = $this->getMockBuilder( 'Aimeos\Admin\JQAdm\Product\Standard' )
28
			->setMethods( array( 'delete', 'save' ) )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->context = \TestHelperJqadm::getContext();
33
		$this->context->setCache( $this->cache );
34
35
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Cache( $this->mock, $this->context );
36
		$this->object->setAimeos( \TestHelperJqadm::getAimeos() );
37
		$this->object->setView( \TestHelperJqadm::getView() );
38
	}
39
40
41
	protected function tearDown() : void
42
	{
43
		unset( $this->object, $this->mock, $this->context, $this->cache );
44
	}
45
46
47
	public function testDelete()
48
	{
49
		$view = \TestHelperJqadm::getView();
50
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'id' => 1 ) );
51
		$view->addHelper( 'param', $helper );
52
53
		$tags = array( 'product', 'product-1' );
54
		$this->cache->expects( $this->once() )->method( 'deleteByTags' )->with( $this->equalTo( $tags ) );
55
		$this->mock->expects( $this->once() )->method( 'delete' )->will( $this->returnValue( 'test' ) );
56
57
		$this->object->setView( $view );
58
		$result = $this->object->delete();
59
60
		$this->assertEquals( 'test', $result );
61
	}
62
63
64
	public function testSave()
65
	{
66
		$item = \Aimeos\MShop::create( $this->context, 'product' )->findItem( 'CNC' );
67
68
		$tags = array( 'product', 'product-' . $item->getId() );
69
		$view = \TestHelperJqadm::getView();
70
		$view->item = $item;
71
72
		$this->cache->expects( $this->once() )->method( 'deleteByTags' )->with( $this->equalTo( $tags ) );
73
		$this->mock->expects( $this->once() )->method( 'save' )->will( $this->returnValue( 'test' ) );
74
75
		$this->object->setView( $view );
76
		$result = $this->object->save();
77
78
		$this->assertEquals( 'test', $result );
79
	}
80
}
81