/** * Builds a page listing all configuration keys to inspect. * * @return array * A render array representing the list. */ public function overview() { $page['#title'] = $this->t('Inspect'); $page['#attached']['library'][] = 'system/drupal.system.modules'; $page['filters'] = array('#type' => 'container', '#attributes' => array('class' => array('table-filter', 'js-show'))); $page['filters']['text'] = array('#type' => 'search', '#title' => $this->t('Search'), '#size' => 30, '#placeholder' => $this->t('Search for a configuration key'), '#attributes' => array('class' => array('table-filter-text'), 'data-table' => '.config-inspector-list', 'autocomplete' => 'off', 'title' => $this->t('Enter a part of the configuration key to filter by.'))); $page['table'] = array('#type' => 'table', '#header' => array('name' => t('Configuration key'), 'schema' => t('Schema'), 'list' => t('List'), 'tree' => t('Tree'), 'form' => t('Form'), 'raw' => t('Raw data')), '#attributes' => array('class' => array('config-inspector-list'))); foreach ($this->storage->listAll() as $name) { $label = '<span class="table-filter-text-source">' . $name . '</span>'; // Elements without a schema are displayed to help debugging. if (!$this->configInspectorManager->hasSchema($name)) { $page['table'][] = array('name' => array('#markup' => $label), 'schema' => array('#markup' => t('None')), 'list' => array('#markup' => t('N/A')), 'tree' => array('#markup' => t('N/A')), 'form' => array('#markup' => t('N/A')), 'raw' => array('#markup' => $this->l($this->t('Raw data'), new Url('config_inspector.raw_page', array('name' => $name))))); } else { $schema = t('Correct'); $result = $this->configInspectorManager->checkValues($name); if (is_array($result)) { // The no-schema case is covered above already, if we got errors, the // schema is partial. $schema = $this->translationManager->formatPlural(count($result), '@count error', '@count errors'); } $page['table'][] = array('name' => array('#markup' => $label), 'schema' => array('#markup' => $schema), 'list' => array('#markup' => $this->l($this->t('List'), new Url('config_inspector.list_page', array('name' => $name)))), 'tree' => array('#markup' => $this->l($this->t('Tree'), new Url('config_inspector.tree_page', array('name' => $name)))), 'form' => array('#markup' => $this->l($this->t('Form'), new Url('config_inspector.form_page', array('name' => $name)))), 'raw' => array('#markup' => $this->l($this->t('Raw data'), new Url('config_inspector.raw_page', array('name' => $name))))); } } return $page; }
/** * @dataProvider providerTestFormatPlural */ public function testFormatPlural($count, $singular, $plural, array $args = array(), array $options = array(), $expected) { $translator = $this->getMock('\\Drupal\\Core\\StringTranslation\\Translator\\TranslatorInterface'); $translator->expects($this->once())->method('getStringTranslation')->will($this->returnCallback(function ($langcode, $string) { return $string; })); $this->translationManager->addTranslator($translator); $result = $this->translationManager->formatPlural($count, $singular, $plural, $args, $options); $this->assertEquals($expected, $result); }
/** * @dataProvider providerTestFormatPlural */ public function testFormatPlural($count, $singular, $plural, array $args = array(), array $options = array(), $expected) { $langcode = empty($options['langcode']) ? 'fr' : $options['langcode']; $translator = $this->getMock('\\Drupal\\Core\\StringTranslation\\Translator\\TranslatorInterface'); $translator->expects($this->once())->method('getStringTranslation')->with($langcode, $this->anything(), $this->anything())->will($this->returnCallback(function ($langcode, $string, $context) { return $string; })); $this->translationManager->setDefaultLangcode('fr'); $this->translationManager->addTranslator($translator); $result = $this->translationManager->formatPlural($count, $singular, $plural, $args, $options); $this->assertEquals($expected, $result); $this->assertInstanceOf(MarkupInterface::class, $result); }