/**
  * Tests the get() method with a configurable plugin.
  */
 public function testGetWithConfigurablePlugin()
 {
     $plugin = $this->getMock('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->searchPluginBag->get('banana'));
 }
 /**
  * @covers ::createInstance
  */
 public function testCreateInstance()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_a = $this->getMock(PluginInspectionInterface::class);
     $plugin_id_b = $this->randomMachineName();
     $plugin_b = $this->getMock(PaymentAwarePluginFilteredPluginManagerUnitTestPaymentAwarePlugin::class);
     $plugin_b->expects($this->atLeastOnce())->method('setPayment')->with($this->payment);
     $map = [[$plugin_id_a, [], $plugin_a], [$plugin_id_b, [], $plugin_b]];
     $this->pluginManager->expects($this->atLeast(count($map)))->method('createInstance')->willReturnMap($map);
     $this->assertSame($plugin_a, $this->sut->createInstance($plugin_id_a));
     $this->assertSame($plugin_b, $this->sut->createInstance($plugin_id_b));
 }
 /**
  * Sets up the default plugin collection.
  *
  * @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder|null $create_count
  *   (optional) The number of times that createInstance() is expected to be
  *   called. For example, $this->any(), $this->once(), $this->exactly(6).
  *   Defaults to $this->never().
  */
 protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL)
 {
     $this->pluginInstances = array();
     $map = array();
     foreach ($this->getPluginDefinitions() as $plugin_id => $definition) {
         // Create a mock plugin instance.
         $this->pluginInstances[$plugin_id] = $this->getPluginMock($plugin_id, $definition);
         $map[] = array($plugin_id, $this->config[$plugin_id], $this->pluginInstances[$plugin_id]);
     }
     $create_count = $create_count ?: $this->never();
     $this->pluginManager->expects($create_count)->method('createInstance')->will($this->returnCallback(array($this, 'returnPluginMap')));
     $this->defaultPluginCollection = new DefaultLazyPluginCollection($this->pluginManager, $this->config);
 }
 /**
  * @covers ::getDefinitions
  * @covers ::processDecoratedDefinitions
  * @covers ::setDiscoveryLimit
  * @covers ::resetDiscoveryLimit
  */
 public function testGetDefinitionsWithoutAllowedPlugins()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_definition_a = ['id' => $plugin_id_a];
     $plugin_id_b = $this->randomMachineName();
     $plugin_definition_b = ['id' => $plugin_id_b];
     $plugin_id_c = $this->randomMachineName();
     $plugin_definition_c = ['id' => $plugin_id_c];
     $plugin_definitions = [$plugin_id_a => $plugin_definition_a, $plugin_id_b => $plugin_definition_b, $plugin_id_c => $plugin_definition_c];
     $this->pluginManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($plugin_definitions);
     $this->sut->setDiscoveryLimit([]);
     $this->assertEquals([], $this->sut->getDefinitions());
 }
 /**
  * @covers ::getPermissions
  */
 public function testInvoke()
 {
     $payment_method_configuration_plugin_id = $this->randomMachineName();
     $payment_method_configuration_label = $this->randomMachineName();
     $payment_method_configuration_definitions = array($payment_method_configuration_plugin_id => array('label' => $payment_method_configuration_label));
     $this->paymentMethodConfigurationManager->expects($this->once())->method('getDefinitions')->willReturn($payment_method_configuration_definitions);
     $permissions = $this->sut->getPermissions();
     $this->assertInternalType('array', $permissions);
     foreach ($permissions as $permission) {
         $this->assertInternalType('array', $permission);
         $this->assertArrayHasKey('title', $permission);
     }
     $this->arrayHasKey('payment.payment_method_configuration.create.' . $payment_method_configuration_plugin_id, $permissions);
 }
 /**
  * @covers ::getDefinitions
  * @covers ::processDecoratedDefinitions
  */
 public function testGetDefinitions()
 {
     $decorated_plugin_id_a = $this->randomMachineName();
     $decorated_plugin_definition_a = ['id' => $decorated_plugin_id_a];
     $decorated_plugin_id_b = $this->randomMachineName();
     $decorated_plugin_definition_b = ['id' => $decorated_plugin_id_b];
     $decorated_plugin_definitions = [$decorated_plugin_id_a => $decorated_plugin_definition_a, $decorated_plugin_id_b => $decorated_plugin_definition_b];
     $this->pluginManager->expects($this->once())->method('getDefinitions')->willReturn($decorated_plugin_definitions);
     $typed_plugin_definition_a = $this->getMock(PluginDefinitionInterface::class);
     $typed_plugin_definition_b = $this->getMock(PluginDefinitionInterface::class);
     $map = [[$decorated_plugin_definition_a, $typed_plugin_definition_a], [$decorated_plugin_definition_b, $typed_plugin_definition_b]];
     $this->pluginType->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnMap($map);
     $expected_plugin_definitions = [$decorated_plugin_id_a => $typed_plugin_definition_a, $decorated_plugin_id_b => $typed_plugin_definition_b];
     $this->assertSame($expected_plugin_definitions, $this->sut->getDefinitions());
 }
 /**
  * @covers ::invoke
  */
 public function testInvoke()
 {
     $payment_type_plugin_id = $this->randomMachineName();
     $payment_type_label = $this->randomMachineName();
     $payment_type_definitions = array($payment_type_plugin_id => array('label' => $payment_type_label));
     $this->paymentTypeManager->expects($this->once())->method('getDefinitions')->willReturn($payment_type_definitions);
     $payment_method_configuration_plugin_id = $this->randomMachineName();
     $payment_method_configuration_label = $this->randomMachineName();
     $payment_method_configuration_definitions = array($payment_method_configuration_plugin_id => array('label' => $payment_method_configuration_label));
     $this->paymentMethodConfigurationManager->expects($this->once())->method('getDefinitions')->willReturn($payment_method_configuration_definitions);
     $entity_types = array('payment' => $payment_type_definitions, 'payment_method_configuration' => $payment_method_configuration_definitions);
     $entity_types_bundles_info = $this->sut->invoke();
     $this->assertSame(count($entity_types), count($entity_types_bundles_info));
     foreach ($entity_types as $entity_type => $plugin_definitions) {
         $entity_type_bundles_info = $entity_types_bundles_info[$entity_type];
         $this->assertInternalType('array', $entity_type_bundles_info);
         foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
             $this->assertArrayHasKey('label', $entity_type_bundles_info[$plugin_id]);
             $this->assertSame($plugin_definition['label'], $entity_type_bundles_info[$plugin_id]['label']);
         }
     }
 }
 /**
  * @covers ::load
  */
 public function testLoad()
 {
     $currency_code_from = 'EUR';
     $currency_code_to = 'NLG';
     $rate = new ExchangeRate($currency_code_from, $currency_code_to, '2.20371');
     $exchange_rate_provider_id_a = $this->randomMachineName();
     $exchange_rate_provider_id_b = $this->randomMachineName();
     $exchange_rate_provider_b = $this->getMock('\\Commercie\\CurrencyExchange\\ExchangeRateProviderInterface');
     $exchange_rate_provider_b->expects($this->once())->method('load')->with($currency_code_from, $currency_code_to)->willReturn($rate);
     $plugin_definitions = [$exchange_rate_provider_id_a => ['id' => $exchange_rate_provider_id_a], $exchange_rate_provider_id_b => ['id' => $exchange_rate_provider_id_b]];
     $this->currencyExchangeRateProviderManager->expects($this->once())->method('createInstance')->with($exchange_rate_provider_id_b)->willReturn($exchange_rate_provider_b);
     $this->currencyExchangeRateProviderManager->expects($this->once())->method('getDefinitions')->willReturn($plugin_definitions);
     $config_value = [['plugin_id' => $exchange_rate_provider_id_a, 'status' => FALSE], ['plugin_id' => $exchange_rate_provider_id_b, 'status' => TRUE]];
     $config = $this->getMockBuilder('\\Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
     $config->expects($this->once())->method('get')->with('plugins')->will($this->returnValue($config_value));
     $this->configFactory->expects($this->once())->method('get')->with('currency.exchange_rate_provider')->will($this->returnValue($config));
     $this->assertSame($rate, $this->sut->load($currency_code_from, $currency_code_to));
 }