Browse Source

Add tests for addOptionalPlugin()

Marc Würth 6 years ago
parent
commit
a78d43b7fe
1 changed files with 33 additions and 0 deletions
  1. 33 0
      tests/TestCase/Http/BaseApplicationTest.php

+ 33 - 0
tests/TestCase/Http/BaseApplicationTest.php

@@ -29,6 +29,8 @@ use TestPlugin\Plugin as TestPlugin;
 
 /**
  * Base application test.
+ *
+ * @coversDefaultClass \Cake\Http\BaseApplication
  */
 class BaseApplicationTest extends TestCase
 {
@@ -193,4 +195,35 @@ class BaseApplicationTest extends TestCase
             'Nested plugin should have bootstrap run'
         );
     }
+
+    /**
+     * Tests that loading a non existing plugin through addOptionalPlugin() does not throw an exception
+     *
+     * @return void
+     * @covers ::addOptionalPlugin
+     */
+    public function testAddOptionalPluginLoadingNonExistingPlugin()
+    {
+        $app = $this->getMockForAbstractClass(BaseApplication::class, [$this->path]);
+        $pluginCountBefore = count($app->getPlugins());
+        $nonExistingPlugin = 'NonExistingPlugin';
+        $app->addOptionalPlugin($nonExistingPlugin);
+        $pluginCountAfter = count($app->getPlugins());
+        $this->assertSame($pluginCountBefore, $pluginCountAfter);
+    }
+
+    /**
+     * Tests that loading an existing plugin through addOptionalPlugin() works
+     *
+     * @return void
+     * @covers ::addOptionalPlugin
+     */
+    public function testAddOptionalPluginLoadingNonExistingPluginValid()
+    {
+        $app = $this->getMockForAbstractClass(BaseApplication::class, [$this->path]);
+        $app->addOptionalPlugin(TestPlugin::class);
+
+        $this->assertCount(1, $app->getPlugins());
+        $this->assertTrue($app->getPlugins()->has('TestPlugin'));
+    }
 }