2013-08-17 13:16:48 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud - App Framework
|
|
|
|
*
|
|
|
|
* @author Bernhard Posselt
|
|
|
|
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace Test\AppFramework\Controller;
|
|
|
|
|
|
|
|
use OC\AppFramework\Http\Request;
|
2013-10-07 13:25:50 +04:00
|
|
|
use OCP\AppFramework\Controller\Controller;
|
2013-08-21 02:41:20 +04:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
|
|
|
|
class ChildController extends Controller {};
|
|
|
|
|
|
|
|
class ControllerTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Controller
|
|
|
|
*/
|
|
|
|
private $controller;
|
2013-10-07 13:25:50 +04:00
|
|
|
private $app;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
protected function setUp(){
|
|
|
|
$request = new Request(
|
|
|
|
array(
|
|
|
|
'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'),
|
|
|
|
'post' => array('name' => 'Jane Doe', 'nickname' => 'Janey'),
|
|
|
|
'urlParams' => array('name' => 'Johnny Weissmüller'),
|
|
|
|
'files' => array('file' => 'filevalue'),
|
|
|
|
'env' => array('PATH' => 'daheim'),
|
|
|
|
'session' => array('sezession' => 'kein'),
|
|
|
|
'method' => 'hi',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-10-07 13:25:50 +04:00
|
|
|
$this->app = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
|
2013-08-17 13:16:48 +04:00
|
|
|
array('getAppName'), array('test'));
|
2013-10-07 13:25:50 +04:00
|
|
|
$this->app->expects($this->any())
|
2013-08-17 13:16:48 +04:00
|
|
|
->method('getAppName')
|
|
|
|
->will($this->returnValue('apptemplate_advanced'));
|
|
|
|
|
2013-10-07 13:25:50 +04:00
|
|
|
$this->controller = new ChildController($this->app, $request);
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testParamsGet(){
|
|
|
|
$this->assertEquals('Johnny Weissmüller', $this->controller->params('name', 'Tarzan'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testParamsGetDefault(){
|
|
|
|
$this->assertEquals('Tarzan', $this->controller->params('Ape Man', 'Tarzan'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testParamsFile(){
|
|
|
|
$this->assertEquals('filevalue', $this->controller->params('file', 'filevalue'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetUploadedFile(){
|
|
|
|
$this->assertEquals('filevalue', $this->controller->getUploadedFile('file'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetUploadedFileDefault(){
|
|
|
|
$this->assertEquals('default', $this->controller->params('files', 'default'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetParams(){
|
|
|
|
$params = array(
|
|
|
|
'name' => 'Johnny Weissmüller',
|
|
|
|
'nickname' => 'Janey',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($params, $this->controller->getParams());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRender(){
|
|
|
|
$this->assertTrue($this->controller->render('') instanceof TemplateResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testSetParams(){
|
|
|
|
$params = array('john' => 'foo');
|
|
|
|
$response = $this->controller->render('home', $params);
|
|
|
|
|
|
|
|
$this->assertEquals($params, $response->getParams());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRenderHeaders(){
|
|
|
|
$headers = array('one', 'two');
|
|
|
|
$response = $this->controller->render('', array(), '', $headers);
|
|
|
|
|
|
|
|
$this->assertTrue(in_array($headers[0], $response->getHeaders()));
|
|
|
|
$this->assertTrue(in_array($headers[1], $response->getHeaders()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetRequestMethod(){
|
|
|
|
$this->assertEquals('hi', $this->controller->method());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetEnvVariable(){
|
|
|
|
$this->assertEquals('daheim', $this->controller->env('PATH'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|