1
0

DIContainerTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Test\AppFramework\DependencyInjection;
  25. use \OC\AppFramework\Http\Request;
  26. /**
  27. * @group DB
  28. */
  29. class DIContainerTest extends \Test\TestCase {
  30. private $container;
  31. private $api;
  32. protected function setUp(){
  33. parent::setUp();
  34. $this->container = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
  35. ->setMethods(['isAdminUser'])
  36. ->setConstructorArgs(['name'])
  37. ->getMock();
  38. $this->api = $this->getMockBuilder('OC\AppFramework\Core\API')
  39. ->setConstructorArgs(['hi'])
  40. ->getMock();
  41. }
  42. public function testProvidesAPI(){
  43. $this->assertTrue(isset($this->container['API']));
  44. }
  45. public function testProvidesRequest(){
  46. $this->assertTrue(isset($this->container['Request']));
  47. }
  48. public function testProvidesSecurityMiddleware(){
  49. $this->assertTrue(isset($this->container['SecurityMiddleware']));
  50. }
  51. public function testProvidesMiddlewareDispatcher(){
  52. $this->assertTrue(isset($this->container['MiddlewareDispatcher']));
  53. }
  54. public function testProvidesAppName(){
  55. $this->assertTrue(isset($this->container['AppName']));
  56. }
  57. public function testAppNameIsSetCorrectly(){
  58. $this->assertEquals('name', $this->container['AppName']);
  59. }
  60. public function testMiddlewareDispatcherIncludesSecurityMiddleware(){
  61. $this->container['Request'] = new Request(
  62. ['method' => 'GET'],
  63. $this->getMockBuilder('\OCP\Security\ISecureRandom')
  64. ->disableOriginalConstructor()
  65. ->getMock(),
  66. $this->getMockBuilder('\OCP\IConfig')
  67. ->disableOriginalConstructor()
  68. ->getMock()
  69. );
  70. $security = $this->container['SecurityMiddleware'];
  71. $dispatcher = $this->container['MiddlewareDispatcher'];
  72. $this->assertContains($security, $dispatcher->getMiddlewares());
  73. }
  74. }