您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DIContainerTest.php 2.5KB

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