PluginAppTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @since 3.6.0
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\Core;
  15. use Cake\Console\CommandCollection;
  16. use Cake\Core\Plugin;
  17. use Cake\Core\PluginApp;
  18. use Cake\Http\MiddlewareQueue;
  19. use Cake\TestSuite\TestCase;
  20. use Company\TestPluginThree\Plugin as TestPluginThree;
  21. use TestPlugin\Plugin as TestPlugin;
  22. /**
  23. * PluginAppTest class
  24. */
  25. class PluginAppTest extends TestCase
  26. {
  27. /**
  28. * tearDown method
  29. *
  30. * @return void
  31. */
  32. public function tearDown()
  33. {
  34. parent::tearDown();
  35. Plugin::unload();
  36. }
  37. /**
  38. * testConfigForRoutesAndBootstrap
  39. *
  40. * @return void
  41. */
  42. public function testConfigForRoutesAndBootstrap()
  43. {
  44. $plugin = new PluginApp([
  45. 'bootstrap' => false,
  46. 'routes' => false
  47. ]);
  48. $this->assertFalse($plugin->isBootstrapEnabled());
  49. $this->assertFalse($plugin->isRoutesEnabled());
  50. }
  51. public function testGetName()
  52. {
  53. $plugin = new TestPlugin();
  54. $this->assertSame('TestPlugin', $plugin->getName());
  55. $plugin = new TestPluginThree();
  56. $this->assertSame('Company/TestPluginThree', $plugin->getName());
  57. }
  58. public function testMiddleware()
  59. {
  60. $plugin = new PluginApp();
  61. $middleware = new MiddlewareQueue();
  62. $this->assertSame($middleware, $plugin->middleware($middleware));
  63. }
  64. public function testConsole()
  65. {
  66. $plugin = new PluginApp();
  67. $commands = new CommandCollection();
  68. $this->assertSame($commands, $plugin->console($commands));
  69. }
  70. public function testConstructorArguments()
  71. {
  72. $plugin = new PluginApp([
  73. 'routes' => false,
  74. 'bootstrap' => false,
  75. 'console' => false,
  76. 'middleware' => false
  77. ]);
  78. $this->assertFalse($plugin->isRoutesEnabled());
  79. $this->assertFalse($plugin->isBootstrapEnabled());
  80. $this->assertFalse($plugin->isConsoleEnabled());
  81. $this->assertFalse($plugin->isMiddlewareEnabled());
  82. }
  83. public function testGetPathBaseClass()
  84. {
  85. $plugin = new PluginApp();
  86. $expected = CAKE . 'Core' . DS;
  87. $this->assertSame($expected, $plugin->getPath());
  88. $this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
  89. $this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
  90. }
  91. public function testGetPathOptionValue()
  92. {
  93. $plugin = new PluginApp(['path' => '/some/path']);
  94. $expected = '/some/path';
  95. $this->assertSame($expected, $plugin->getPath());
  96. $this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
  97. $this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
  98. }
  99. public function testGetPathSubclass()
  100. {
  101. $plugin = new TestPlugin();
  102. $expected = TEST_APP . 'Plugin/TestPlugin' . DS;
  103. $this->assertSame($expected, $plugin->getPath());
  104. $this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
  105. $this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
  106. }
  107. }