diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php index 64173fe..eb40df6 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Plugin\PluginFormInterface; +use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\system\SystemConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -21,13 +22,6 @@ class SettingsForm extends SystemConfigFormBase { /** - * The configuration object factory. - * - * @var \Drupal\Core\Config\ConfigFactory - */ - protected $configFactory; - - /** * The aggregator plugin managers. * * @var array @@ -65,10 +59,12 @@ class SettingsForm extends SystemConfigFormBase { * The aggregator parser plugin manager. * @param \Drupal\aggregator\Plugin\AggregatorPluginManager $processor_manager * The aggregator processor plugin manager. + * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * The string translation manager. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager) { + public function __construct(ConfigFactory $config_factory, ContextInterface $context, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager, TranslationInterface $translation_manager) { parent::__construct($config_factory, $context); - + $this->translationManager = $translation_manager; $this->managers = array( 'fetcher' => $fetcher_manager, 'parser' => $parser_manager, @@ -91,7 +87,8 @@ public static function create(ContainerInterface $container) { $container->get('config.context.free'), $container->get('plugin.manager.aggregator.fetcher'), $container->get('plugin.manager.aggregator.parser'), - $container->get('plugin.manager.aggregator.processor') + $container->get('plugin.manager.aggregator.processor'), + $container->get('string_translation') ); } @@ -111,11 +108,11 @@ public function buildForm(array $form, array &$form_state) { // Global aggregator settings. $form['aggregator_allowed_html_tags'] = array( '#type' => 'textfield', - '#title' => t('Allowed HTML tags'), + '#title' => $this->t('Allowed HTML tags'), '#size' => 80, '#maxlength' => 255, '#default_value' => $config->get('items.allowed_html'), - '#description' => t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'), + '#description' => $this->t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'), ); // Only show basic configuration if there are actually options. @@ -123,8 +120,8 @@ public function buildForm(array $form, array &$form_state) { if (count($this->definitions['fetcher']) > 1) { $basic_conf['aggregator_fetcher'] = array( '#type' => 'radios', - '#title' => t('Fetcher'), - '#description' => t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'), + '#title' => $this->t('Fetcher'), + '#description' => $this->t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'), '#options' => $this->definitions['fetcher'], '#default_value' => $config->get('fetcher'), ); @@ -132,8 +129,8 @@ public function buildForm(array $form, array &$form_state) { if (count($this->definitions['parser']) > 1) { $basic_conf['aggregator_parser'] = array( '#type' => 'radios', - '#title' => t('Parser'), - '#description' => t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'), + '#title' => $this->t('Parser'), + '#description' => $this->t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'), '#options' => $this->definitions['parser'], '#default_value' => $config->get('parser'), ); @@ -141,8 +138,8 @@ public function buildForm(array $form, array &$form_state) { if (count($this->definitions['processor']) > 1) { $basic_conf['aggregator_processors'] = array( '#type' => 'checkboxes', - '#title' => t('Processors'), - '#description' => t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'), + '#title' => $this->t('Processors'), + '#description' => $this->t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'), '#options' => $this->definitions['processor'], '#default_value' => $config->get('processors'), ); @@ -150,8 +147,8 @@ public function buildForm(array $form, array &$form_state) { if (count($basic_conf)) { $form['basic_conf'] = array( '#type' => 'details', - '#title' => t('Basic configuration'), - '#description' => t('For most aggregation tasks, the default settings are fine.'), + '#title' => $this->t('Basic configuration'), + '#description' => $this->t('For most aggregation tasks, the default settings are fine.'), '#collapsed' => FALSE, ); $form['basic_conf'] += $basic_conf; diff --git a/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php b/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php index 9ebb408..9c120c3 100644 --- a/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php +++ b/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php @@ -13,6 +13,7 @@ /** * Tests plugins settings on aggregator plugins. * + * @group Drupal * @group Aggregator */ class AggregatorPluginSettingsBaseTest extends UnitTestCase { @@ -66,9 +67,11 @@ public function setUp() { $this->settingsForm = new SettingsForm( $this->configFactory, + $this->getMock('Drupal\Core\Config\Context\ContextInterface'), $this->managers['fetcher'], $this->managers['parser'], - $this->managers['processor'] + $this->managers['processor'], + $this->getStringTranslationStub() ); } @@ -117,10 +120,4 @@ public function testSettingsForm() { if (!function_exists('drupal_set_message')) { function drupal_set_message() {} } - // @todo remove in https://drupal.org/node/2018411 or after its in. - if (!function_exists('t')) { - function t($string) { - return $string; - } - } } diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index c8f32a6..576c015 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -147,4 +147,20 @@ protected function getBlockMockWithMachineName($machine_name) { return $block; } + /** + * Returns a stub translation manager that just returns the passed string. + * + * @return \PHPUnit_Framework_MockObject_MockBuilder + * A MockBuilder of \Drupal\Core\StringTranslation\TranslationInterface + */ + public function getStringTranslationStub() { + $translation = $this->getMockBuilder('Drupal\Core\StringTranslation\TranslationManager') + ->disableOriginalConstructor() + ->getMock(); + $translation->expects($this->any()) + ->method('translate') + ->will($this->returnArgument(0)); + return $translation; + } + }