class SearchPluginCollectionTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/search/tests/src/Unit/SearchPluginCollectionTest.php \Drupal\Tests\search\Unit\SearchPluginCollectionTest
- 9 core/modules/search/tests/src/Unit/SearchPluginCollectionTest.php \Drupal\Tests\search\Unit\SearchPluginCollectionTest
@coversDefaultClass \Drupal\search\Plugin\SearchPluginCollection @group search
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitWarnings
- class \Drupal\Tests\search\Unit\SearchPluginCollectionTest
Expanded class hierarchy of SearchPluginCollectionTest
File
- core/
modules/ search/ tests/ src/ Unit/ SearchPluginCollectionTest.php, line 12
Namespace
Drupal\Tests\search\UnitView source
class SearchPluginCollectionTest extends UnitTestCase {
/**
* The mocked plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $pluginManager;
/**
* The tested plugin collection.
*
* @var \Drupal\search\Plugin\SearchPluginCollection
*/
protected $searchPluginCollection;
/**
* Stores all setup plugin instances.
*
* @var \Drupal\search\Plugin\SearchInterface[]
*/
protected $pluginInstances;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->pluginManager = $this
->createMock('Drupal\\Component\\Plugin\\PluginManagerInterface');
$this->searchPluginCollection = new SearchPluginCollection($this->pluginManager, 'banana', [
'id' => 'banana',
'color' => 'yellow',
], 'fruit_stand');
}
/**
* Tests the get() method.
*/
public function testGet() {
$plugin = $this
->createMock('Drupal\\search\\Plugin\\SearchInterface');
$this->pluginManager
->expects($this
->once())
->method('createInstance')
->will($this
->returnValue($plugin));
$this
->assertSame($plugin, $this->searchPluginCollection
->get('banana'));
}
/**
* Tests the get() method with a configurable plugin.
*/
public function testGetWithConfigurablePlugin() {
$plugin = $this
->createMock('Drupal\\search\\Plugin\\ConfigurableSearchPluginInterface');
$plugin
->expects($this
->once())
->method('setSearchPageId')
->with('fruit_stand')
->will($this
->returnValue($plugin));
$this->pluginManager
->expects($this
->once())
->method('createInstance')
->will($this
->returnValue($plugin));
$this
->assertSame($plugin, $this->searchPluginCollection
->get('banana'));
}
}