Commit 0414f401 authored by alexpott's avatar alexpott

Issue #2661542 by Mile23, Mixologic: Isolate...

Issue #2661542 by Mile23, Mixologic: Isolate Drupal\Tests\Component\Plugin\DefaultFactoryTest from core test module
parent 15393165
......@@ -5,9 +5,9 @@
use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry;
use Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface;
use Drupal\plugin_test\Plugin\plugin_test\fruit\Kale;
use Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli;
use Drupal\Tests\Component\Plugin\Fixtures\vegetable\Corn;
use Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface;
use PHPUnit\Framework\TestCase;
/**
......@@ -22,8 +22,8 @@ class DefaultFactoryTest extends TestCase {
* @covers ::getPluginClass
*/
public function testGetPluginClassWithValidArrayPluginDefinition() {
$plugin_class = Cherry::class;
$class = DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class]);
$plugin_class = Corn::class;
$class = DefaultFactory::getPluginClass('corn', ['class' => $plugin_class]);
$this->assertEquals($plugin_class, $class);
}
......@@ -34,12 +34,12 @@ public function testGetPluginClassWithValidArrayPluginDefinition() {
* @covers ::getPluginClass
*/
public function testGetPluginClassWithValidObjectPluginDefinition() {
$plugin_class = Cherry::class;
$plugin_class = Corn::class;
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce())
->method('getClass')
->willReturn($plugin_class);
$class = DefaultFactory::getPluginClass('cherry', $plugin_definition);
$class = DefaultFactory::getPluginClass('corn', $plugin_definition);
$this->assertEquals($plugin_class, $class);
}
......@@ -52,12 +52,12 @@ public function testGetPluginClassWithValidObjectPluginDefinition() {
public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class);
$this->expectExceptionMessage('The plugin (cherry) did not specify an instance class.');
$this->expectExceptionMessage('The plugin (corn) did not specify an instance class.');
}
else {
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
$this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.');
}
DefaultFactory::getPluginClass('cherry', []);
DefaultFactory::getPluginClass('corn', []);
}
/**
......@@ -69,12 +69,12 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class);
$this->expectExceptionMessage('The plugin (cherry) did not specify an instance class.');
$this->expectExceptionMessage('The plugin (corn) did not specify an instance class.');
}
else {
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
$this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.');
}
DefaultFactory::getPluginClass('cherry', $plugin_definition);
DefaultFactory::getPluginClass('corn', $plugin_definition);
}
/**
......@@ -85,12 +85,12 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() {
if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class);
$this->expectExceptionMessage('Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
$this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.');
}
else {
$this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
$this->setExpectedException(PluginException::class, 'Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.');
}
DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']);
DefaultFactory::getPluginClass('carrot', ['class' => 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot']);
}
/**
......@@ -99,7 +99,7 @@ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition(
* @covers ::getPluginClass
*/
public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() {
$plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit';
$plugin_class = 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot';
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce())
->method('getClass')
......@@ -110,7 +110,7 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition
else {
$this->setExpectedException(PluginException::class);
}
DefaultFactory::getPluginClass('kiwifruit', $plugin_definition);
DefaultFactory::getPluginClass('carrot', $plugin_definition);
}
/**
......@@ -119,8 +119,8 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition
* @covers ::getPluginClass
*/
public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() {
$plugin_class = Cherry::class;
$class = DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class], FruitInterface::class);
$plugin_class = Corn::class;
$class = DefaultFactory::getPluginClass('corn', ['class' => $plugin_class], VegetableInterface::class);
$this->assertEquals($plugin_class, $class);
}
......@@ -131,12 +131,12 @@ public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() {
* @covers ::getPluginClass
*/
public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() {
$plugin_class = Cherry::class;
$plugin_class = Corn::class;
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce())
->method('getClass')
->willReturn($plugin_class);
$class = DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
$class = DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class);
$this->assertEquals($plugin_class, $class);
}
......@@ -147,15 +147,14 @@ public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() {
* @covers ::getPluginClass
*/
public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() {
$plugin_class = Kale::class;
if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class);
$this->expectExceptionMessage('Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
$this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.');
}
else {
$this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
$this->setExpectedException(PluginException::class, 'Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.');
}
DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class);
DefaultFactory::getPluginClass('corn', ['class' => Broccoli::class], VegetableInterface::class);
}
/**
......@@ -164,7 +163,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDef
* @covers ::getPluginClass
*/
public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() {
$plugin_class = Kale::class;
$plugin_class = Broccoli::class;
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce())
->method('getClass')
......@@ -175,7 +174,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDe
else {
$this->setExpectedException(PluginException::class);
}
DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class);
}
}
<?php
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
/**
* @Plugin(
* id = "broccoli",
* label = "Broccoli",
* color = "green"
* )
*/
class Broccoli {}
<?php
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
/**
* @Plugin(
* id = "corn",
* label = "Corn",
* color = "yellow"
* )
*/
class Corn implements VegetableInterface {}
<?php
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
/**
* Provides an interface for test plugins.
*/
interface VegetableInterface {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment