annotate core/modules/search/tests/src/Unit/SearchPluginCollectionTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\search\Unit;
Chris@0 4
Chris@0 5 use Drupal\search\Plugin\SearchPluginCollection;
Chris@0 6 use Drupal\Tests\UnitTestCase;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * @coversDefaultClass \Drupal\search\Plugin\SearchPluginCollection
Chris@0 10 * @group search
Chris@0 11 */
Chris@0 12 class SearchPluginCollectionTest extends UnitTestCase {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * The mocked plugin manager.
Chris@0 16 *
Chris@0 17 * @var \Drupal\Component\Plugin\PluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject
Chris@0 18 */
Chris@0 19 protected $pluginManager;
Chris@0 20
Chris@0 21 /**
Chris@0 22 * The tested plugin collection.
Chris@0 23 *
Chris@0 24 * @var \Drupal\search\Plugin\SearchPluginCollection
Chris@0 25 */
Chris@0 26 protected $searchPluginCollection;
Chris@0 27
Chris@0 28 /**
Chris@0 29 * Stores all setup plugin instances.
Chris@0 30 *
Chris@0 31 * @var \Drupal\search\Plugin\SearchInterface[]
Chris@0 32 */
Chris@0 33 protected $pluginInstances;
Chris@0 34
Chris@0 35 /**
Chris@0 36 * {@inheritdoc}
Chris@0 37 */
Chris@0 38 protected function setUp() {
Chris@0 39 $this->pluginManager = $this->getMock('Drupal\Component\Plugin\PluginManagerInterface');
Chris@0 40 $this->searchPluginCollection = new SearchPluginCollection($this->pluginManager, 'banana', ['id' => 'banana', 'color' => 'yellow'], 'fruit_stand');
Chris@0 41 }
Chris@0 42
Chris@0 43 /**
Chris@0 44 * Tests the get() method.
Chris@0 45 */
Chris@0 46 public function testGet() {
Chris@0 47 $plugin = $this->getMock('Drupal\search\Plugin\SearchInterface');
Chris@0 48 $this->pluginManager->expects($this->once())
Chris@0 49 ->method('createInstance')
Chris@0 50 ->will($this->returnValue($plugin));
Chris@0 51 $this->assertSame($plugin, $this->searchPluginCollection->get('banana'));
Chris@0 52 }
Chris@0 53
Chris@0 54 /**
Chris@0 55 * Tests the get() method with a configurable plugin.
Chris@0 56 */
Chris@0 57 public function testGetWithConfigurablePlugin() {
Chris@0 58 $plugin = $this->getMock('Drupal\search\Plugin\ConfigurableSearchPluginInterface');
Chris@0 59 $plugin->expects($this->once())
Chris@0 60 ->method('setSearchPageId')
Chris@0 61 ->with('fruit_stand')
Chris@0 62 ->will($this->returnValue($plugin));
Chris@0 63
Chris@0 64 $this->pluginManager->expects($this->once())
Chris@0 65 ->method('createInstance')
Chris@0 66 ->will($this->returnValue($plugin));
Chris@0 67
Chris@0 68 $this->assertSame($plugin, $this->searchPluginCollection->get('banana'));
Chris@0 69 }
Chris@0 70
Chris@0 71 }