Skip to content
Snippets Groups Projects
Commit 3ab8c46b authored by Ankitha Shetty's avatar Ankitha Shetty Committed by Vladimir Roudakov
Browse files

Issue #3200610 by ankithashetty, xurizaemon, VladimirAus: Fix Drupal Coding Standard Errors

parent e117136b
No related branches found
No related tags found
No related merge requests found
<?php <?php
/**
* @file
* Contains \Drupal\toc_filter\Plugin\Block\TocFilterBlock.
*/
namespace Drupal\toc_filter\Plugin\Block; namespace Drupal\toc_filter\Plugin\Block;
......
<?php <?php
/**
* @file
* Contains \Drupal\toc_filter\Plugin\Filter\TocFilter.
*/
namespace Drupal\toc_filter\Plugin\Filter; namespace Drupal\toc_filter\Plugin\Filter;
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
...@@ -190,7 +185,7 @@ class TocFilter extends FilterBase { ...@@ -190,7 +185,7 @@ class TocFilter extends FilterBase {
* @return array * @return array
* An associative array of parsed name/value pairs. * An associative array of parsed name/value pairs.
*/ */
static public function parseOptions($text) { public static function parseOptions($text) {
// Decode special characters. // Decode special characters.
$text = html_entity_decode($text); $text = html_entity_decode($text);
...@@ -248,7 +243,7 @@ class TocFilter extends FilterBase { ...@@ -248,7 +243,7 @@ class TocFilter extends FilterBase {
* @param mixed $value * @param mixed $value
* Option value. * Option value.
*/ */
static protected function setOption(array &$options, $name, $value) { protected static function setOption(array &$options, $name, $value) {
$keys = explode('.', $name); $keys = explode('.', $name);
while ($key = array_shift($keys)) { while ($key = array_shift($keys)) {
$options =& $options[$key]; $options =& $options[$key];
......
<?php <?php
/**
* @file
* Definition of Drupal\toc_filter\Tests\TocFilterBlockTest.
*/
namespace Drupal\toc_filter\Tests; namespace Drupal\toc_filter\Tests;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
...@@ -21,7 +16,14 @@ class TocFilterBlockTest extends WebTestBase { ...@@ -21,7 +16,14 @@ class TocFilterBlockTest extends WebTestBase {
* *
* @var array * @var array
*/ */
public static $modules = ['system', 'node', 'block', 'filter', 'toc_api', 'toc_filter']; public static $modules = [
'system',
'node',
'block',
'filter',
'toc_api',
'toc_filter',
];
/** /**
* An authenticated user. * An authenticated user.
......
<?php <?php
/**
* @file
* Definition of Drupal\toc_filter\Tests\TocFilterTest.
*
* Copied from \Drupal\filter\Tests\FilterUnitTest.
*/
namespace Drupal\toc_filter\Tests; namespace Drupal\toc_filter\Tests;
use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RenderContext;
use Drupal\filter\FilterPluginCollection;
use Drupal\filter\Plugin\FilterInterface; use Drupal\filter\Plugin\FilterInterface;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\filter\FilterPluginCollection;
/** /**
* Tests TOC filter. * Tests TOC filter.
...@@ -28,7 +21,13 @@ class TocFilterTest extends WebTestBase { ...@@ -28,7 +21,13 @@ class TocFilterTest extends WebTestBase {
* *
* @var array * @var array
*/ */
public static $modules = ['system', 'filter', 'toc_api', 'toc_filter', 'toc_filter_test']; public static $modules = [
'system',
'filter',
'toc_api',
'toc_filter',
'toc_filter_test',
];
/** /**
* The TOC filter. * The TOC filter.
...@@ -83,14 +82,12 @@ class TocFilterTest extends WebTestBase { ...@@ -83,14 +82,12 @@ class TocFilterTest extends WebTestBase {
$this->assertFilteredString($this->filter, $tests); $this->assertFilteredString($this->filter, $tests);
} }
/****************************************************************************/
// Copied from: Drupal\filter\Tests\FilterUnitTest
/****************************************************************************/
/** /**
* Asserts multiple filter output expectations for multiple input strings. * Asserts multiple filter output expectations for multiple input strings.
* *
* @param FilterInterface $filter * Copied from: Drupal\filter\Tests\FilterUnitTest.
*
* @param \Drupal\filter\Plugin\FilterInterface $filter
* A input filter object. * A input filter object.
* @param array $tests * @param array $tests
* An associative array, whereas each key is an arbitrary input string and * An associative array, whereas each key is an arbitrary input string and
...@@ -98,15 +95,15 @@ class TocFilterTest extends WebTestBase { ...@@ -98,15 +95,15 @@ class TocFilterTest extends WebTestBase {
* strings and whose values are Booleans indicating whether the output is * strings and whose values are Booleans indicating whether the output is
* expected or not. * expected or not.
* *
* For example: * For example:
* *
* @code * @code
* $tests = [ * $tests = [
* 'Input string' => [ * 'Input string' => [
* '<p>Input string</p>' => TRUE, * '<p>Input string</p>' => TRUE,
* 'Input string<br' => FALSE, * 'Input string<br' => FALSE,
* ], * ],
* ]; * ];
* @endcode * @endcode
*/ */
protected function assertFilteredString(FilterInterface $filter, array $tests) { protected function assertFilteredString(FilterInterface $filter, array $tests) {
......
<?php <?php
/**
* @file
* Contains \Drupal\Tests\toc_filter\Unit\TocFilterOptionsTest.
*/
namespace Drupal\Tests\toc_filter\Unit; namespace Drupal\Tests\toc_filter\Unit;
use Drupal\toc_filter\Plugin\Filter\TocFilter; use Drupal\toc_filter\Plugin\Filter\TocFilter;
...@@ -42,13 +37,52 @@ class TocFilterOptionsTest extends UnitTestCase { ...@@ -42,13 +37,52 @@ class TocFilterOptionsTest extends UnitTestCase {
* @see testParseOptions() * @see testParseOptions()
*/ */
public function providerParseOptions() { public function providerParseOptions() {
$tests[] = ['value name=\'value\'', ['value' => TRUE, 'name' => 'value']]; $tests[] = ['value name=\'value\'',
$tests[] = ['one=\'value\' two=value three="value" &nbsp; four=&quot;value&quot;', ['one' => 'value', 'two' => 'value', 'three' => 'value', 'four' => 'value']]; [
$tests[] = ['one=\'value\' two=value three="value" &nbsp; four=&quot;value&quot;', ['one' => 'value', 'two' => 'value', 'three' => 'value', 'four' => 'value']]; 'value' => TRUE,
$tests[] = ['one=1 two=2.0 three="3.3"', ['one' => 1, 'two' => 2, 'three' => 3.3]]; 'name' => 'value',
$tests[] = ['one=TRUE two=False three', ['one' => TRUE, 'two' => FALSE, 'three' => TRUE]]; ],
$tests[] = ['parent_option.child_option=value', ['parent_option' => ['child_option' => 'value']]]; ];
$tests[] = ['h2.number_type=decimal', ['headers' => ['h2' => ['number_type' => 'decimal']]]]; $tests[] = ['one=\'value\' two=value three="value" &nbsp; four=&quot;value&quot;',
[
'one' => 'value',
'two' => 'value',
'three' => 'value',
'four' => 'value',
],
];
$tests[] = ['one=\'value\' two=value three="value" &nbsp; four=&quot;value&quot;',
[
'one' => 'value',
'two' => 'value',
'three' => 'value',
'four' => 'value',
],
];
$tests[] = ['one=1 two=2.0 three="3.3"',
[
'one' => 1,
'two' => 2,
'three' => 3.3,
],
];
$tests[] = ['one=TRUE two=False three',
[
'one' => TRUE,
'two' => FALSE,
'three' => TRUE,
],
];
$tests[] = ['parent_option.child_option=value',
[
'parent_option' => ['child_option' => 'value'],
],
];
$tests[] = ['h2.number_type=decimal',
[
'headers' => ['h2' => ['number_type' => 'decimal']],
],
];
return $tests; return $tests;
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* *
* @ingroup toc_filter_api * @ingroup toc_filter_api
*/ */
function hook_toc_filter_alter(&$options, &$content) { function hook_toc_filter_alter(array &$options, &$content) {
// If there is less than five <h2> tags don't generate a table of contents. // If there is less than five <h2> tags don't generate a table of contents.
if (substr_count($content, '<h2') < 5) { if (substr_count($content, '<h2') < 5) {
$options = FALSE; $options = FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment