1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - App Framework |
5
|
|
|
* |
6
|
|
|
* @author Bernhard Posselt |
7
|
|
|
* @copyright 2012 Bernhard Posselt <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This library is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
11
|
|
|
* License as published by the Free Software Foundation; either |
12
|
|
|
* version 3 of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* This library is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public |
20
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace OC\AppFramework; |
26
|
|
|
|
27
|
|
|
use OCP\AppFramework\Http\Response; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
function rrmdir($directory) { |
31
|
|
|
$files = array_diff(scandir($directory), array('.','..')); |
32
|
|
|
foreach ($files as $file) { |
33
|
|
|
if (is_dir($directory . '/' . $file)) { |
34
|
|
|
rrmdir($directory . '/' . $file); |
35
|
|
|
} else { |
36
|
|
|
unlink($directory . '/' . $file); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
return rmdir($directory); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
class AppTest extends \Test\TestCase { |
44
|
|
|
|
45
|
|
|
private $container; |
46
|
|
|
private $io; |
47
|
|
|
private $api; |
48
|
|
|
private $controller; |
49
|
|
|
private $dispatcher; |
50
|
|
|
private $params; |
51
|
|
|
private $headers; |
52
|
|
|
private $output; |
53
|
|
|
private $controllerName; |
54
|
|
|
private $controllerMethod; |
55
|
|
|
private $appPath; |
56
|
|
|
|
57
|
|
|
protected function setUp() { |
58
|
|
|
parent::setUp(); |
59
|
|
|
|
60
|
|
|
$this->container = new \OC\AppFramework\DependencyInjection\DIContainer('test', array()); |
61
|
|
|
$this->controller = $this->getMockBuilder( |
62
|
|
|
'OCP\AppFramework\Controller') |
63
|
|
|
->disableOriginalConstructor() |
64
|
|
|
->getMock(); |
65
|
|
|
$this->dispatcher = $this->getMockBuilder( |
66
|
|
|
'OC\AppFramework\Http\Dispatcher') |
67
|
|
|
->disableOriginalConstructor() |
68
|
|
|
->getMock(); |
69
|
|
|
|
70
|
|
|
$this->io = $this->getMockBuilder('OCP\\AppFramework\\Http\\IOutput')->getMock(); |
71
|
|
|
|
72
|
|
|
$this->headers = array('key' => 'value'); |
73
|
|
|
$this->output = 'hi'; |
74
|
|
|
$this->controllerName = 'Controller'; |
75
|
|
|
$this->controllerMethod = 'method'; |
76
|
|
|
|
77
|
|
|
$this->container[$this->controllerName] = $this->controller; |
78
|
|
|
$this->container['Dispatcher'] = $this->dispatcher; |
79
|
|
|
$this->container['OCP\\AppFramework\\Http\\IOutput'] = $this->io; |
80
|
|
|
$this->container['urlParams'] = array(); |
81
|
|
|
|
82
|
|
|
$this->appPath = __DIR__ . '/../../../apps/namespacetestapp/appinfo'; |
83
|
|
|
$infoXmlPath = $this->appPath . '/info.xml'; |
84
|
|
|
mkdir($this->appPath, 0777, true); |
85
|
|
|
|
86
|
|
|
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . |
87
|
|
|
'<info>' . |
88
|
|
|
'<id>namespacetestapp</id>' . |
89
|
|
|
'<namespace>NameSpaceTestApp</namespace>' . |
90
|
|
|
'</info>'; |
91
|
|
|
file_put_contents($infoXmlPath, $xml); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
public function testControllerNameAndMethodAreBeingPassed(){ |
96
|
|
|
$return = array(null, array(), array(), null, new Response()); |
97
|
|
|
$this->dispatcher->expects($this->once()) |
98
|
|
|
->method('dispatch') |
99
|
|
|
->with($this->equalTo($this->controller), |
100
|
|
|
$this->equalTo($this->controllerMethod)) |
101
|
|
|
->will($this->returnValue($return)); |
102
|
|
|
|
103
|
|
|
$this->io->expects($this->never()) |
104
|
|
|
->method('setOutput'); |
105
|
|
|
|
106
|
|
|
App::main($this->controllerName, $this->controllerMethod, |
107
|
|
|
$this->container); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testBuildAppNamespace() { |
112
|
|
|
$ns = App::buildAppNamespace('someapp'); |
113
|
|
|
$this->assertEquals('OCA\Someapp', $ns); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
public function testBuildAppNamespaceCore() { |
118
|
|
|
$ns = App::buildAppNamespace('someapp', 'OC\\'); |
119
|
|
|
$this->assertEquals('OC\Someapp', $ns); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
public function testBuildAppNamespaceInfoXml() { |
124
|
|
|
$ns = App::buildAppNamespace('namespacetestapp', 'OCA\\'); |
125
|
|
|
$this->assertEquals('OCA\NameSpaceTestApp', $ns); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
protected function tearDown() { |
130
|
|
|
rrmdir($this->appPath); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testOutputIsPrinted(){ |
135
|
|
|
$return = [null, [], [], $this->output, new Response()]; |
136
|
|
|
$this->dispatcher->expects($this->once()) |
137
|
|
|
->method('dispatch') |
138
|
|
|
->with($this->equalTo($this->controller), |
139
|
|
|
$this->equalTo($this->controllerMethod)) |
140
|
|
|
->will($this->returnValue($return)); |
141
|
|
|
$this->io->expects($this->once()) |
142
|
|
|
->method('setOutput') |
143
|
|
|
->with($this->equalTo($this->output)); |
144
|
|
|
App::main($this->controllerName, $this->controllerMethod, $this->container, []); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
public function testCallbackIsCalled(){ |
149
|
|
|
$mock = $this->getMockBuilder('OCP\AppFramework\Http\ICallbackResponse') |
150
|
|
|
->getMock(); |
151
|
|
|
|
152
|
|
|
$return = [null, [], [], $this->output, $mock]; |
153
|
|
|
$this->dispatcher->expects($this->once()) |
154
|
|
|
->method('dispatch') |
155
|
|
|
->with($this->equalTo($this->controller), |
156
|
|
|
$this->equalTo($this->controllerMethod)) |
157
|
|
|
->will($this->returnValue($return)); |
158
|
|
|
$mock->expects($this->once()) |
159
|
|
|
->method('callback'); |
160
|
|
|
App::main($this->controllerName, $this->controllerMethod, $this->container, []); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
} |
164
|
|
|
|