StandardTest::testSearchException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2026
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Dashboard;
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 = \TestHelper::view();
22
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
23
		$helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' );
24
		$this->view ->addHelper( 'request', $helper );
25
26
		$this->context = \TestHelper::context();
27
28
		$this->object = new \Aimeos\Admin\JQAdm\Dashboard\Standard( $this->context );
29
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
30
		$this->object->setAimeos( \TestHelper::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 testSearch()
42
	{
43
		$result = $this->object->search();
44
45
		$this->assertStringContainsString( '<div class="dashboard', $result );
46
	}
47
48
49
	public function testSearchException()
50
	{
51
		$object = $this->getClientMock( 'getSubClients' );
52
53
		$object->expects( $this->once() )->method( 'getSubClients' )
54
			->will( $this->throwException( new \RuntimeException() ) );
55
56
		$object->search();
57
	}
58
59
60
	public function testGetSubClient()
61
	{
62
		$result = $this->object->getSubClient( 'order' );
63
		$this->assertInstanceOf( \Aimeos\Admin\JQAdm\Iface::class, $result );
64
	}
65
66
67
	public function getClientMock( $method )
68
	{
69
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Dashboard\Standard::class )
70
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
71
			->onlyMethods( [$method] )
72
			->getMock();
73
74
		$object->setAimeos( \TestHelper::getAimeos() );
75
		$object->setView( $this->getViewNoRender() );
76
77
		return $object;
78
	}
79
80
81
	protected function getViewNoRender()
82
	{
83
		return $this->getMockBuilder( \Aimeos\Base\View\Standard::class )
84
			->setConstructorArgs( array( [] ) )
85
			->onlyMethods( ['render'] )->addMethods( ['config'] )
86
			->getMock();
87
	}
88
}
89