SearchPluginCollectionTest.php in Drupal 9
File
core/modules/search/tests/src/Unit/SearchPluginCollectionTest.php
View source
<?php
namespace Drupal\Tests\search\Unit;
use Drupal\search\Plugin\SearchPluginCollection;
use Drupal\Tests\UnitTestCase;
class SearchPluginCollectionTest extends UnitTestCase {
protected $pluginManager;
protected $searchPluginCollection;
protected $pluginInstances;
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');
}
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'));
}
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'));
}
}