/**
  * @covers ::getLabel
  */
 public function testGetLabel()
 {
     $this->pluginDefinition['label'] = 'Test label';
     $this->stringTranslation->expects($this->once())->method('translate')->with($this->pluginDefinition['label'], array(), array('context' => 'breakpoint'))->will($this->returnValue('Test label translated'));
     $this->setupBreakpoint();
     $this->assertEquals('Test label translated', $this->breakpoint->getLabel());
 }
 /**
  * @covers ::buildSelector
  */
 public function testBuildSelector()
 {
     $this->stringTranslation->expects($this->any())->method('translate')->willReturnArgument(0);
     $method = new \ReflectionMethod($this->sut, 'buildSelector');
     $method->setAccessible(TRUE);
     $plugin_id = $this->randomMachineName();
     $plugin_label = $this->randomMachineName();
     $plugin_definition = $this->getMock(PluginLabelDefinitionInterface::class);
     $plugin_definition->expects($this->atLeastOnce())->method('getLabel')->willReturn($plugin_label);
     $plugin = $this->getMock(PluginInspectionInterface::class);
     $plugin->expects($this->atLeastOnce())->method('getPluginDefinition')->willReturn($plugin_definition);
     $plugin->expects($this->atLeastOnce())->method('getPluginId')->willReturn($plugin_id);
     $this->selectablePluginType->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnArgument(0);
     $this->sut->setSelectedPlugin($plugin);
     $selector_title = $this->randomMachineName();
     $this->sut->setLabel($selector_title);
     $selector_description = $this->randomMachineName();
     $this->sut->setDescription($selector_description);
     $element = array('#parents' => array('foo', 'bar'), '#title' => $selector_title);
     $form_state = $this->getMock(FormStateInterface::class);
     $available_plugins = array($plugin);
     $expected_build_plugin_id = array('#ajax' => array('callback' => array(Radios::class, 'ajaxRebuildForm'), 'effect' => 'fade', 'event' => 'change', 'progress' => 'none', 'trigger_as' => array('name' => 'foo[bar][select][container][change]')), '#attached' => ['library' => ['plugin/plugin_selector.plugin_radios']], '#default_value' => $plugin_id, '#empty_value' => 'select', '#options' => array($plugin_id => $plugin_label), '#required' => FALSE, '#title' => $selector_title, '#description' => $selector_description, '#type' => 'radios');
     $expected_build_change = array('#ajax' => array('callback' => array(AdvancedPluginSelectorBase::class, 'ajaxRebuildForm')), '#attributes' => array('class' => array('js-hide')), '#limit_validation_errors' => array(array('foo', 'bar', 'select', 'plugin_id')), '#name' => 'foo[bar][select][container][change]', '#submit' => [[AdvancedPluginSelectorBase::class, 'rebuildForm']], '#type' => 'submit', '#value' => 'Choose');
     $build = $method->invokeArgs($this->sut, array($element, $form_state, $available_plugins));
     $this->assertEquals($expected_build_plugin_id, $build['container']['plugin_id']);
     $this->assertEquals($expected_build_change, $build['container']['change']);
     $this->assertSame('container', $build['container']['#type']);
 }
 /**
  * @covers ::getTitle
  */
 public function testGetTitleWithTitleArguments()
 {
     $title = 'Example @test';
     $this->pluginDefinition['title'] = new TranslatableMarkup($title, array('@test' => 'value'), [], $this->stringTranslation);
     $this->stringTranslation->expects($this->once())->method('translateString')->with($this->pluginDefinition['title'])->will($this->returnValue('Example value'));
     $this->setupContextualLinkDefault();
     $request = new Request();
     $this->assertEquals('Example value', $this->contextualLinkDefault->getTitle($request));
 }
 /**
  * Tests a static title with a parameter.
  *
  * @see \Drupal\Core\Controller\TitleResolver::getTitle()
  *
  * @dataProvider providerTestStaticTitleWithParameter
  */
 public function testStaticTitleWithParameter($title, $expected_title)
 {
     $raw_variables = new ParameterBag(array('test' => 'value', 'test2' => 'value2'));
     $request = new Request();
     $request->attributes->set('_raw_variables', $raw_variables);
     $route = new Route('/test-route', array('_title' => $title));
     $this->translationManager->expects($this->once())->method('translate')->with($title, $this->logicalOr($this->arrayHasKey('@test'), $this->arrayHasKey('%test'), $this->arrayHasKey('!test')), array())->will($this->returnValue('static title value'));
     $this->assertEquals($expected_title, $this->titleResolver->getTitle($request, $route));
 }
Exemple #5
0
 /**
  * @covers ::get
  *
  * @dataProvider providerTestGet
  */
 public function testGet(array $values, $expected)
 {
     $container = new ContainerBuilder();
     $container->set('string_translation', $this->translationManager);
     \Drupal::setContainer($container);
     $arguments = isset($values['arguments']) ? $values['arguments'] : array();
     $options = isset($values['context']) ? array('context' => $values['context']) : array();
     $this->translationManager->expects($this->once())->method('translate')->with($values['value'], $arguments, $options);
     $annotation = new Translation($values);
     $this->assertSame($expected, (string) $annotation->get());
 }
 /**
  * Prepares mocks for the test.
  */
 protected function setUp()
 {
     $this->commentManager = $this->getMock('\\Drupal\\comment\\CommentManagerInterface');
     $this->stringTranslation = $this->getStringTranslationStub();
     $this->moduleHandler = $this->getMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->currentUser = $this->getMock('\\Drupal\\Core\\Session\\AccountProxyInterface');
     $this->commentLinkBuilder = new CommentLinkBuilder($this->currentUser, $this->commentManager, $this->moduleHandler, $this->stringTranslation);
     $this->commentManager->expects($this->any())->method('getFields')->with('node')->willReturn(array('comment' => array()));
     $this->commentManager->expects($this->any())->method('forbiddenMessage')->willReturn("Can't let you do that Dave.");
     $this->stringTranslation->expects($this->any())->method('formatPlural')->willReturnArgument(1);
 }
 /**
  * @covers ::settingsSummary
  */
 public function testSettingsSummaryWithMultipleLineItems()
 {
     $line_items_data = [['plugin_id' => $this->randomMachineName(), 'plugin_configuration' => []], ['plugin_id' => $this->randomMachineName(), 'plugin_configuration' => []]];
     $this->sut->setSetting('line_items', $line_items_data);
     $this->stringTranslation->expects($this->any())->method('formatPlural')->with(2);
     $this->sut->settingsSummary();
 }
 /**
  * @covers ::getTitle
  */
 public function testGetTitleWithTitleArguments()
 {
     $this->pluginDefinition['title'] = new TranslatableMarkup('Example @test', array('@test' => 'value'), [], $this->stringTranslation);
     $this->stringTranslation->expects($this->once())->method('translateString')->with($this->pluginDefinition['title'])->will($this->returnValue('Example value'));
     $this->setupLocalTaskDefault();
     $this->assertEquals('Example value', $this->localTaskBase->getTitle());
 }
 /**
  * Tests the getTitle method with title arguments.
  */
 public function testGetTitleWithTitleArguments()
 {
     $this->pluginDefinition['title'] = (new TranslationWrapper('Example @test', array('@test' => 'value')))->setStringTranslation($this->stringTranslation);
     $this->stringTranslation->expects($this->once())->method('translate')->with('Example @test', array('@test' => 'value'), array())->will($this->returnValue('Example value'));
     $this->setupLocalActionDefault();
     $request = new Request();
     $this->assertEquals('Example value', $this->localActionDefault->getTitle($request));
 }
 /**
  * @covers ::getTitle
  */
 public function testGetTitleWithTitleArguments()
 {
     $this->pluginDefinition['title'] = 'Example @test';
     $this->pluginDefinition['title_arguments'] = array('@test' => 'value');
     $this->stringTranslation->expects($this->once())->method('translate')->with($this->pluginDefinition['title'], $this->arrayHasKey('@test'), array())->will($this->returnValue('Example value'));
     $this->setupLocalTaskDefault();
     $request = new Request();
     $this->assertEquals('Example value', $this->localTaskBase->getTitle($request));
 }
Exemple #11
0
 /**
  * Tests the formatDiff method.
  *
  * @dataProvider providerTestFormatDiff
  *
  * @covers ::formatDiff
  */
 public function testformatDiff($expected, $timestamp1, $timestamp2, $options = array())
 {
     // Mocks a simple formatPlural implementation.
     $this->stringTranslation->expects($this->any())->method('formatPlural')->with($this->anything(), $this->anything(), $this->anything(), array(), array('langcode' => isset($options['langcode']) ? $options['langcode'] : NULL))->will($this->returnCallback(function ($count, $one, $multiple) {
         return $count == 1 ? $one : str_replace('@count', $count, $multiple);
     }));
     // Mocks a simple translate implementation.
     $this->stringTranslation->expects($this->any())->method('translate')->with($this->anything())->will($this->returnCallback(function ($string, $args, $options) {
         return $string;
     }));
     $this->assertEquals($expected, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
 }
Exemple #12
0
 /**
  * Tests the formatDiff method.
  *
  * @dataProvider providerTestFormatDiff
  *
  * @covers ::formatDiff
  */
 public function testformatDiff($expected, $max_age, $timestamp1, $timestamp2, $options = array())
 {
     // Mocks a simple translateString implementation.
     $this->stringTranslation->expects($this->any())->method('translateString')->willReturnCallback(function (TranslatableMarkup $arg) {
         return $arg->getUntranslatedString();
     });
     if (isset($options['langcode'])) {
         $expected_markup = new TranslatableMarkup($expected, [], ['langcode' => $options['langcode']], $this->stringTranslation);
     } else {
         $expected_markup = new TranslatableMarkup($expected, [], [], $this->stringTranslation);
     }
     $this->assertEquals($expected_markup, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
     $options['return_as_object'] = TRUE;
     $expected_object = new FormattedDateDiff($expected, $max_age);
     $this->assertEquals($expected_object, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
 }
 /**
  * @covers ::buildForm
  */
 public function testBuildForm()
 {
     $form = array();
     $form_state = $this->getMock(FormStateInterface::class);
     $definitions = array('foo' => array('label' => $this->randomMachineName()));
     $plugin_id = $this->randomMachineName();
     $this->currencyAmountFormatterManager->expects($this->once())->method('getDefinitions')->willReturn($definitions);
     $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $config->expects($this->once())->method('get')->with('plugin_id')->willReturn($plugin_id);
     $this->configFactory->expects($this->once())->method('getEditable')->with('currency.amount_formatting')->willReturn($config);
     $this->stringTranslation->expects($this->any())->method('translate')->will($this->returnArgument(0));
     $expected = array('#default_value' => $plugin_id, '#options' => array('foo' => $definitions['foo']['label']), '#process' => [[Radios::class, 'processRadios'], [$this->controller, 'processPluginOptions']], '#type' => 'radios');
     $build = $this->controller->buildForm($form, $form_state);
     unset($build['default_plugin_id']['#title']);
     $this->assertSame($expected, $build['default_plugin_id']);
 }
 /**
  * @covers ::buildSelector
  */
 public function testBuildSelector()
 {
     $this->stringTranslation->expects($this->any())->method('translate')->willReturnArgument(0);
     $method = new \ReflectionMethod($this->sut, 'buildSelector');
     $method->setAccessible(TRUE);
     $plugin_id = $this->randomMachineName();
     $plugin_label = $this->randomMachineName();
     $plugin = $this->getMock(PluginInspectionInterface::class);
     $plugin->expects($this->any())->method('getPluginId')->willReturn($plugin_id);
     $plugin->expects($this->any())->method('getPluginLabel')->willReturn($plugin_label);
     $this->sut->setSelectedPlugin($plugin);
     $element = array('#parents' => array('foo', 'bar'));
     $form_state = $this->getMock(FormStateInterface::class);
     $available_plugins = array($plugin);
     $expected_build_change = array('#ajax' => array('callback' => array(AdvancedPluginSelectorBase::class, 'ajaxRebuildForm')), '#attributes' => array('class' => array('js-hide')), '#limit_validation_errors' => array(array('foo', 'bar', 'select', 'plugin_id')), '#name' => 'foo[bar][select][container][change]', '#submit' => [[AdvancedPluginSelectorBase::class, 'rebuildForm']], '#type' => 'submit', '#value' => 'Choose');
     $build = $method->invokeArgs($this->sut, array($element, $form_state, $available_plugins));
     $this->assertArrayHasKey('plugin_id', $build['container']);
     $this->assertEquals($expected_build_change, $build['container']['change']);
     $this->assertSame('container', $build['container']['#type']);
 }
 /**
  * @covers ::execute
  * @covers ::buildListingLevel
  * @covers ::buildHierarchy
  * @covers ::buildHierarchyLevel
  * @covers ::sort
  */
 function testListing()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_id_b = $this->randomMachineName();
     $definitions = [$plugin_id_a => ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName()], $plugin_id_b => ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'parent_id' => $plugin_id_a]];
     $operations_a = ['title' => $this->randomMachineName()];
     $operations_provider_a = $this->getMock(PluginOperationsProviderInterface::class);
     $operations_provider_a->expects($this->once())->method('getOperations')->with($plugin_id_a)->willReturn($operations_a);
     $map = [[$plugin_id_a, TRUE, $definitions[$plugin_id_a]], [$plugin_id_b, TRUE, $definitions[$plugin_id_b]]];
     $this->paymentStatusManager->expects($this->exactly(count($map)))->method('getDefinition')->willReturnMap($map);
     $this->paymentStatusManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($definitions);
     $map = [[$plugin_id_a, $operations_provider_a], [$plugin_id_b, NULL]];
     $this->paymentStatusManager->expects($this->exactly(2))->method('getOperationsProvider')->willReturnMap($map);
     $this->stringTranslation->expects($this->any())->method('translate')->will($this->returnArgument(0));
     $build = $this->sut->execute();
     foreach ($build['#header'] as $key => $label) {
         $build['#header'][$key] = (string) $label;
     }
     $expected = ['#header' => ['Title', 'Description', 'Operations'], '#type' => 'table', $plugin_id_a => ['label' => ['#markup' => $definitions[$plugin_id_a]['label']], 'description' => ['#markup' => $definitions[$plugin_id_a]['description']], 'operations' => ['#type' => 'operations', '#links' => $operations_a]], $plugin_id_b => ['label' => ['#markup' => $definitions[$plugin_id_b]['label']], 'description' => ['#markup' => $definitions[$plugin_id_b]['description']], 'operations' => ['#type' => 'operations', '#links' => []]]];
     $this->assertSame($expected, $build);
 }
Exemple #16
0
 /**
  * Tests the formatInterval method for 0 second.
  */
 public function testFormatIntervalZeroSecond()
 {
     $this->stringTranslation->expects($this->once())->method('translate')->with('0 sec', array(), array('langcode' => 'xxx-lolspeak'))->will($this->returnValue('0 sec'));
     $result = $this->dateFormatter->formatInterval(0, 1, 'xxx-lolspeak');
     $this->assertEquals('0 sec', $result);
 }