JqadmControllerTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 72
c 1
b 0
f 0
dl 0
loc 152
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testFileCss() 0 11 1
A testCopyAction() 0 12 1
A testCreateAction() 0 12 1
A testFileJs() 0 11 1
A testSearchAction() 0 12 1
A testSearchActionSite() 0 11 1
A testExportAction() 0 12 1
A testGetAction() 0 12 1
A testSaveAction() 0 15 1
A testDeleteAction() 0 15 1
1
<?php
2
3
namespace Aimeos\ShopBundle\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
8
class JqadmControllerTest extends WebTestCase
9
{
10
	public function testFileCss()
11
	{
12
		$client = static::createClient( array(), array(
13
			'PHP_AUTH_USER' => 'admin',
14
			'PHP_AUTH_PW'   => 'adminpass',
15
		) );
16
17
		$client->request( 'GET', '/unittest/jqadm/file/index-css/en' );
18
19
		$this->assertEquals( 200, $client->getResponse()->getStatusCode() );
20
		$this->assertStringContainsString( '.aimeos', $client->getResponse()->getContent() );
21
	}
22
23
24
	public function testFileJs()
25
	{
26
		$client = static::createClient( array(), array(
27
			'PHP_AUTH_USER' => 'admin',
28
			'PHP_AUTH_PW'   => 'adminpass',
29
		) );
30
31
		$client->request( 'GET', '/unittest/jqadm/file/index-js/en' );
32
33
		$this->assertEquals( 200, $client->getResponse()->getStatusCode() );
34
		$this->assertStringContainsString( 'Aimeos = {', $client->getResponse()->getContent() );
35
	}
36
37
38
	public function testCopyAction()
39
	{
40
		$client = static::createClient( array(), array(
41
			'PHP_AUTH_USER' => 'admin',
42
			'PHP_AUTH_PW'   => 'adminpass',
43
		) );
44
45
		$client->request( 'GET', '/unittest/jqadm/copy/product/1' );
46
		$response = $client->getResponse();
47
48
		$this->assertEquals( 200, $response->getStatusCode() );
49
		$this->assertStringContainsString( 'item-product', $response->getContent() );
50
	}
51
52
53
	public function testCreateAction()
54
	{
55
		$client = static::createClient( array(), array(
56
			'PHP_AUTH_USER' => 'admin',
57
			'PHP_AUTH_PW'   => 'adminpass',
58
		) );
59
60
		$client->request( 'GET', '/unittest/jqadm/create/product' );
61
		$response = $client->getResponse();
62
63
		$this->assertEquals( 200, $response->getStatusCode() );
64
		$this->assertStringContainsString( 'item-product', $response->getContent() );
65
	}
66
67
68
	public function testDeleteAction()
69
	{
70
		$client = static::createClient( array(), array(
71
			'PHP_AUTH_USER' => 'admin',
72
			'PHP_AUTH_PW'   => 'adminpass',
73
		) );
74
75
		$client->request( 'OPTIONS', '/unittest/jsonadm' );
76
		$json = json_decode( $client->getResponse()->getContent(), true );
77
		$token = $json['meta']['csrf']['value'];
78
79
		$client->request( 'POST', '/unittest/jqadm/delete/product/0', ['_token' => $token] );
80
		$response = $client->getResponse();
81
82
		$this->assertEquals( 302, $response->getStatusCode() );
83
	}
84
85
86
	public function testExportAction()
87
	{
88
		$client = static::createClient( array(), array(
89
			'PHP_AUTH_USER' => 'admin',
90
			'PHP_AUTH_PW'   => 'adminpass',
91
		) );
92
93
		$client->request( 'GET', '/unittest/jqadm/export/order' );
94
		$response = $client->getResponse();
95
96
		$this->assertEquals( 200, $response->getStatusCode() );
97
		$this->assertStringContainsString( 'list-items', $response->getContent() );
98
	}
99
100
101
	public function testGetAction()
102
	{
103
		$client = static::createClient( array(), array(
104
			'PHP_AUTH_USER' => 'admin',
105
			'PHP_AUTH_PW'   => 'adminpass',
106
		) );
107
108
		$client->request( 'GET', '/unittest/jqadm/get/product/1' );
109
		$response = $client->getResponse();
110
111
		$this->assertEquals( 200, $response->getStatusCode() );
112
		$this->assertStringContainsString( 'item-product', $response->getContent() );
113
	}
114
115
116
	public function testSaveAction()
117
	{
118
		$client = static::createClient( array(), array(
119
			'PHP_AUTH_USER' => 'admin',
120
			'PHP_AUTH_PW'   => 'adminpass',
121
		) );
122
123
		$client->request( 'OPTIONS', '/unittest/jsonadm' );
124
		$json = json_decode( $client->getResponse()->getContent(), true );
125
		$token = $json['meta']['csrf']['value'];
126
127
		$client->request( 'POST', '/unittest/jqadm/save/product', ['item' => ['product.type' => 'default'], '_token' => $token] );
128
		$response = $client->getResponse();
129
130
		$this->assertEquals( 302, $response->getStatusCode() );
131
	}
132
133
134
	public function testSearchAction()
135
	{
136
		$client = static::createClient( array(), array(
137
			'PHP_AUTH_USER' => 'admin',
138
			'PHP_AUTH_PW'   => 'adminpass',
139
		) );
140
141
		$client->request( 'GET', '/unittest/jqadm/search/product' );
142
		$response = $client->getResponse();
143
144
		$this->assertEquals( 200, $response->getStatusCode() );
145
		$this->assertStringContainsString( 'list-items', $response->getContent() );
146
	}
147
148
149
	public function testSearchActionSite()
150
	{
151
		$client = static::createClient( array(), array(
152
			'PHP_AUTH_USER' => 'admin',
153
			'PHP_AUTH_PW'   => 'adminpass',
154
		) );
155
156
		$client->request( 'GET', '/invalid/jqadm/search/product' );
157
		$response = $client->getResponse();
158
159
		$this->assertEquals( 500, $response->getStatusCode() );
160
	}
161
}
162