DIContainerTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @author Morris Jobke
  7. * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
  8. * @copyright 2013 Morris Jobke <morris.jobke@gmail.com>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\AppFramework\DependencyInjection;
  25. use \OC\AppFramework\Http\Request;
  26. class DIContainerTest extends \Test\TestCase {
  27. private $container;
  28. private $api;
  29. protected function setUp(){
  30. parent::setUp();
  31. $this->container = new DIContainer('name');
  32. $this->api = $this->getMock('OC\AppFramework\Core\API', array(), array('hi'));
  33. }
  34. public function testProvidesAPI(){
  35. $this->assertTrue(isset($this->container['API']));
  36. }
  37. public function testProvidesRequest(){
  38. $this->assertTrue(isset($this->container['Request']));
  39. }
  40. public function testProvidesSecurityMiddleware(){
  41. $this->assertTrue(isset($this->container['SecurityMiddleware']));
  42. }
  43. public function testProvidesMiddlewareDispatcher(){
  44. $this->assertTrue(isset($this->container['MiddlewareDispatcher']));
  45. }
  46. public function testProvidesAppName(){
  47. $this->assertTrue(isset($this->container['AppName']));
  48. }
  49. public function testAppNameIsSetCorrectly(){
  50. $this->assertEquals('name', $this->container['AppName']);
  51. }
  52. public function testMiddlewareDispatcherIncludesSecurityMiddleware(){
  53. $this->container['Request'] = new Request(
  54. ['method' => 'GET'],
  55. $this->getMock('\OCP\Security\ISecureRandom'),
  56. $this->getMock('\OCP\IConfig')
  57. );
  58. $security = $this->container['SecurityMiddleware'];
  59. $dispatcher = $this->container['MiddlewareDispatcher'];
  60. $this->assertContains($security, $dispatcher->getMiddlewares());
  61. }
  62. }