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
|
|
|
function rrmdir($directory) { |
28
|
|
|
$files = array_diff(scandir($directory), array('.','..')); |
29
|
|
|
foreach ($files as $file) { |
30
|
|
|
if (is_dir($directory . '/' . $file)) { |
31
|
|
|
rrmdir($directory . '/' . $file); |
32
|
|
|
} else { |
33
|
|
|
unlink($directory . '/' . $file); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
return rmdir($directory); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
class AppTest extends \Test\TestCase { |
40
|
|
|
|
41
|
|
|
private $container; |
42
|
|
|
private $api; |
43
|
|
|
private $controller; |
44
|
|
|
private $dispatcher; |
45
|
|
|
private $params; |
46
|
|
|
private $headers; |
47
|
|
|
private $output; |
48
|
|
|
private $controllerName; |
49
|
|
|
private $controllerMethod; |
50
|
|
|
private $appPath; |
51
|
|
|
|
52
|
|
|
protected function setUp() { |
53
|
|
|
parent::setUp(); |
54
|
|
|
|
55
|
|
|
$this->container = new \OC\AppFramework\DependencyInjection\DIContainer('test', array()); |
56
|
|
|
$this->controller = $this->getMockBuilder( |
57
|
|
|
'OCP\AppFramework\Controller') |
58
|
|
|
->disableOriginalConstructor() |
59
|
|
|
->getMock(); |
60
|
|
|
$this->dispatcher = $this->getMockBuilder( |
61
|
|
|
'OC\AppFramework\Http\Dispatcher') |
62
|
|
|
->disableOriginalConstructor() |
63
|
|
|
->getMock(); |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->headers = array('key' => 'value'); |
67
|
|
|
$this->output = 'hi'; |
68
|
|
|
$this->controllerName = 'Controller'; |
69
|
|
|
$this->controllerMethod = 'method'; |
70
|
|
|
|
71
|
|
|
$this->container[$this->controllerName] = $this->controller; |
72
|
|
|
$this->container['Dispatcher'] = $this->dispatcher; |
73
|
|
|
$this->container['urlParams'] = array(); |
74
|
|
|
|
75
|
|
|
$this->appPath = __DIR__ . '/../../../apps/namespacetestapp/appinfo'; |
76
|
|
|
$infoXmlPath = $this->appPath . '/info.xml'; |
77
|
|
|
mkdir($this->appPath, 0777, true); |
78
|
|
|
|
79
|
|
|
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . |
80
|
|
|
'<info>' . |
81
|
|
|
'<id>namespacetestapp</id>' . |
82
|
|
|
'<namespace>NameSpaceTestApp</namespace>' . |
83
|
|
|
'</info>'; |
84
|
|
|
file_put_contents($infoXmlPath, $xml); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testControllerNameAndMethodAreBeingPassed(){ |
89
|
|
|
$return = array(null, array(), array(), null); |
90
|
|
|
$this->dispatcher->expects($this->once()) |
91
|
|
|
->method('dispatch') |
92
|
|
|
->with($this->equalTo($this->controller), |
93
|
|
|
$this->equalTo($this->controllerMethod)) |
94
|
|
|
->will($this->returnValue($return)); |
95
|
|
|
|
96
|
|
|
$this->expectOutputString(''); |
97
|
|
|
|
98
|
|
|
App::main($this->controllerName, $this->controllerMethod, |
99
|
|
|
$this->container); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testBuildAppNamespace() { |
104
|
|
|
$ns = App::buildAppNamespace('someapp'); |
105
|
|
|
$this->assertEquals('OCA\Someapp', $ns); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
public function testBuildAppNamespaceCore() { |
110
|
|
|
$ns = App::buildAppNamespace('someapp', 'OC\\'); |
111
|
|
|
$this->assertEquals('OC\Someapp', $ns); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testBuildAppNamespaceInfoXml() { |
116
|
|
|
$ns = App::buildAppNamespace('namespacetestapp', 'OCA\\'); |
117
|
|
|
$this->assertEquals('OCA\NameSpaceTestApp', $ns); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
protected function tearDown() { |
122
|
|
|
rrmdir($this->appPath); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/* |
126
|
|
|
FIXME: this complains about shit headers which are already sent because |
127
|
|
|
of the content length. Would be cool if someone could fix this |
128
|
|
|
|
129
|
|
|
public function testOutputIsPrinted(){ |
130
|
|
|
$return = array(null, array(), $this->output); |
131
|
|
|
$this->dispatcher->expects($this->once()) |
132
|
|
|
->method('dispatch') |
133
|
|
|
->with($this->equalTo($this->controller), |
134
|
|
|
$this->equalTo($this->controllerMethod)) |
135
|
|
|
->will($this->returnValue($return)); |
136
|
|
|
|
137
|
|
|
$this->expectOutputString($this->output); |
138
|
|
|
|
139
|
|
|
App::main($this->controllerName, $this->controllerMethod, array(), |
140
|
|
|
$this->container); |
141
|
|
|
} |
142
|
|
|
*/ |
143
|
|
|
|
144
|
|
|
// FIXME: if someone manages to test the headers output, I'd be grateful |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
} |
148
|
|
|
|