You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.4 KiB

  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\AppFramework\Controller;
  23. use OC\AppFramework\Http\Request;
  24. use OCP\AppFramework\Controller;
  25. use OCP\AppFramework\Http\TemplateResponse;
  26. class ChildController extends Controller {};
  27. class ControllerTest extends \PHPUnit_Framework_TestCase {
  28. /**
  29. * @var Controller
  30. */
  31. private $controller;
  32. private $app;
  33. protected function setUp(){
  34. $request = new Request(
  35. array(
  36. 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'),
  37. 'post' => array('name' => 'Jane Doe', 'nickname' => 'Janey'),
  38. 'urlParams' => array('name' => 'Johnny Weissmüller'),
  39. 'files' => array('file' => 'filevalue'),
  40. 'env' => array('PATH' => 'daheim'),
  41. 'session' => array('sezession' => 'kein'),
  42. 'method' => 'hi',
  43. )
  44. );
  45. $this->app = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
  46. array('getAppName'), array('test'));
  47. $this->app->expects($this->any())
  48. ->method('getAppName')
  49. ->will($this->returnValue('apptemplate_advanced'));
  50. $this->controller = new ChildController($this->app, $request);
  51. }
  52. public function testParamsGet(){
  53. $this->assertEquals('Johnny Weissmüller', $this->controller->params('name', 'Tarzan'));
  54. }
  55. public function testParamsGetDefault(){
  56. $this->assertEquals('Tarzan', $this->controller->params('Ape Man', 'Tarzan'));
  57. }
  58. public function testParamsFile(){
  59. $this->assertEquals('filevalue', $this->controller->params('file', 'filevalue'));
  60. }
  61. public function testGetUploadedFile(){
  62. $this->assertEquals('filevalue', $this->controller->getUploadedFile('file'));
  63. }
  64. public function testGetUploadedFileDefault(){
  65. $this->assertEquals('default', $this->controller->params('files', 'default'));
  66. }
  67. public function testGetParams(){
  68. $params = array(
  69. 'name' => 'Johnny Weissmüller',
  70. 'nickname' => 'Janey',
  71. );
  72. $this->assertEquals($params, $this->controller->getParams());
  73. }
  74. public function testRender(){
  75. $this->assertTrue($this->controller->render('') instanceof TemplateResponse);
  76. }
  77. public function testSetParams(){
  78. $params = array('john' => 'foo');
  79. $response = $this->controller->render('home', $params);
  80. $this->assertEquals($params, $response->getParams());
  81. }
  82. public function testRenderHeaders(){
  83. $headers = array('one', 'two');
  84. $response = $this->controller->render('', array(), '', $headers);
  85. $this->assertTrue(in_array($headers[0], $response->getHeaders()));
  86. $this->assertTrue(in_array($headers[1], $response->getHeaders()));
  87. }
  88. public function testGetRequestMethod(){
  89. $this->assertEquals('hi', $this->controller->method());
  90. }
  91. public function testGetEnvVariable(){
  92. $this->assertEquals('daheim', $this->controller->env('PATH'));
  93. }
  94. }