Completed
Push — master ( a13539...bd1b6d )
by Aimeos
04:27
created

StandardTest::testGetMAdminException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.9666
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), 2017-2020
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Dashboard\Job;
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\Dashboard\Job\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 testDelete()
38
	{
39
		$manager = \Aimeos\MAdmin::create( $this->context, 'job' );
40
		$item = $manager->createItem();
41
		$item->setLabel( 'jobdeletetest.csv' );
42
		$item->setResult( ['file' => 'jobdeletetest.csv'] );
43
		$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

43
		$manager->/** @scrutinizer ignore-call */ 
44
            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...
44
45
		$param = ['site' => 'unittest', 'id' => $item->getId()];
46
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
47
		$this->view->addHelper( 'param', $helper );
48
49
		$result = $this->object->delete();
50
51
		$this->assertStringContainsString( 'dashboard-job', $result );
52
		$this->assertStringNotContainsString( 'jobdeletetest.csv', $result );
53
	}
54
55
56
	public function testGet()
57
	{
58
		$dir = dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . '/tmp';
59
		$path = $dir . '/jobtest.csv';
60
61
		if( file_exists( $dir ) === false && mkdir( $dir, 0755, true ) === false ) {
62
			throw new \Exception( 'Cannot create temp directory' );
63
		}
64
65
		if( touch( $path ) === false ) {
66
			throw new \Exception( 'Cannot create test file' );
67
		}
68
69
		$manager = \Aimeos\MAdmin::create( $this->context, 'job' );
70
		$item = $manager->createItem();
71
		$item->setLabel( 'jobtest.csv' );
72
		$item->setResult( ['file' => 'jobtest.csv'] );
73
		$manager->saveItem( $item );
74
75
		$param = ['site' => 'unittest', 'id' => $item->getId()];
76
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
77
		$this->view->addHelper( 'param', $helper );
78
79
		$result = $this->object->get();
80
81
		$this->assertEmpty( $result );
82
83
		$manager->deleteItem( $item->getId() );
84
		unlink( $path );
85
	}
86
87
88
	public function testSearch()
89
	{
90
		$result = $this->object->search();
91
92
		$this->assertStringContainsString( 'dashboard-job', $result );
93
		$this->assertStringContainsString( 'unittest job', $result );
94
	}
95
96
97
	protected function getViewNoRender()
98
	{
99
		$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class )
100
			->setConstructorArgs( array( [] ) )
101
			->setMethods( array( 'render', 'config' ) )
102
			->getMock();
103
104
		$param = ['site' => 'unittest', 'id' => -1];
105
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
106
		$view->addHelper( 'param', $helper );
107
108
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, [] );
109
		$view->addHelper( 'access', $helper );
110
111
		return $view;
112
	}
113
}
114