Passed
Push — master ( 84367b...2c80aa )
by Aimeos
03:28
created

StandardTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Settings;
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
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
25
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' );
26
		$this->view ->addHelper( 'request', $helper );
27
28
		$this->object = new \Aimeos\Admin\JQAdm\Settings\Standard( $this->context );
29
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
30
		$this->object->setAimeos( \TestHelperJqadm::getAimeos() );
31
		$this->object->setView( $this->view );
32
	}
33
34
35
	protected function tearDown() : void
36
	{
37
		unset( $this->object, $this->view, $this->context );
38
	}
39
40
41
	public function testSave()
42
	{
43
		$param = array(
44
			'site' => 'unittest',
45
			'item' => array(
46
				'key' => [
47
					'subkey' => 'value',
48
				],
49
			),
50
		);
51
52
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
53
		$this->view->addHelper( 'param', $helper );
54
55
		$mock = $this->getMockBuilder( \Aimeos\MShop\Locale\Manager\Site\Standard::class )
56
			->setConstructorArgs( [$this->context] )
57
			->getMock();
58
59
		\Aimeos\MShop::inject( \Aimeos\MShop\Locale\Manager\Site\Standard::class, $mock );
60
61
		$this->object->save();
62
63
		\Aimeos\MShop::inject( \Aimeos\MShop\Locale\Manager\Site\Standard::class, null );
64
65
		$this->assertEquals( ['key' => ['subkey' => 'value']], $this->context->getLocale()->getSiteItem()->getConfig() );
66
	}
67
68
69
	public function testSaveException()
70
	{
71
		$object = $this->getClientMock( 'fromArray' );
72
73
		$object->expects( $this->once() )->method( 'fromArray' )
74
			->will( $this->throwException( new \RuntimeException() ) );
75
76
		$object->save();
77
	}
78
79
80
	public function testSearch()
81
	{
82
		$param = array( 'site' => 'unittest' );
83
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
84
		$this->view->addHelper( 'param', $helper );
85
86
		$result = $this->object->search();
87
88
		$this->assertStringContainsString( 'from-email', $result );
89
	}
90
91
92
	public function testGetSubClientInvalid()
93
	{
94
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
95
		$this->object->getSubClient( '$unknown$' );
96
	}
97
98
99
	public function testGetSubClientUnknown()
100
	{
101
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
102
		$this->object->getSubClient( 'unknown' );
103
	}
104
105
106
	public function getClientMock( $methods, $real = true )
107
	{
108
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Settings\Standard::class )
109
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
110
			->setMethods( (array) $methods )
111
			->getMock();
112
113
		$object->setAimeos( \TestHelperJqadm::getAimeos() );
114
		$object->setView( $this->getViewNoRender( $real ) );
115
116
		return $object;
117
	}
118
119
120
	protected function getViewNoRender( $real = true )
121
	{
122
		$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class )
123
			->setConstructorArgs( array( [] ) )
124
			->setMethods( array( 'render' ) )
125
			->getMock();
126
127
		$param = ['site' => 'unittest'];
128
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
129
		$view->addHelper( 'param', $helper );
130
131
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $this->context->getConfig() );
132
		$view->addHelper( 'config', $helper );
133
134
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, [] );
135
		$view->addHelper( 'access', $helper );
136
137
		return $view;
138
	}
139
}
140