1
0

DIContainerTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\DependencyInjection\DIContainer;
  26. use \OC\AppFramework\Http\Request;
  27. use OC\AppFramework\Middleware\Security\SecurityMiddleware;
  28. use OCP\AppFramework\QueryException;
  29. use OCP\IConfig;
  30. use OCP\Security\ISecureRandom;
  31. /**
  32. * @group DB
  33. */
  34. class DIContainerTest extends \Test\TestCase {
  35. /** @var DIContainer|\PHPUnit_Framework_MockObject_MockObject */
  36. private $container;
  37. protected function setUp(){
  38. parent::setUp();
  39. $this->container = $this->getMockBuilder(DIContainer::class)
  40. ->setMethods(['isAdminUser'])
  41. ->setConstructorArgs(['name'])
  42. ->getMock();
  43. }
  44. public function testProvidesRequest(){
  45. $this->assertTrue(isset($this->container['Request']));
  46. }
  47. public function testProvidesMiddlewareDispatcher(){
  48. $this->assertTrue(isset($this->container['MiddlewareDispatcher']));
  49. }
  50. public function testProvidesAppName(){
  51. $this->assertTrue(isset($this->container['AppName']));
  52. }
  53. public function testAppNameIsSetCorrectly(){
  54. $this->assertEquals('name', $this->container['AppName']);
  55. }
  56. public function testMiddlewareDispatcherIncludesSecurityMiddleware(){
  57. $this->container['Request'] = new Request(
  58. ['method' => 'GET'],
  59. $this->createMock(ISecureRandom::class),
  60. $this->createMock(IConfig::class)
  61. );
  62. $dispatcher = $this->container['MiddlewareDispatcher'];
  63. $middlewares = $dispatcher->getMiddlewares();
  64. $found = false;
  65. foreach ($middlewares as $middleware) {
  66. if ($middleware instanceof SecurityMiddleware) {
  67. $found = true;
  68. }
  69. }
  70. $this->assertTrue($found);
  71. }
  72. public function testInvalidAppClass() {
  73. $this->expectException(QueryException::class);
  74. $this->container->query('\OCA\Name\Foo');
  75. }
  76. }