diff --git a/src/FreelinkingManager.php b/src/FreelinkingManager.php index f288afa..478b6ca 100644 --- a/src/FreelinkingManager.php +++ b/src/FreelinkingManager.php @@ -106,12 +106,7 @@ class FreelinkingManager extends DefaultPluginManager implements FreelinkingMana // The first three unnamed arguments are dest, text, and tooltip. $index = 0; foreach ($items as $key => $item) { - // Set argument with INI-style configuration. - if (strpos($item, '=')) { - list($name, $value) = explode('=', $item); - $args[$name] = $value; - } - elseif ($index < 3) { + if ($index < 3) { switch ($index) { case 0: $args['dest'] = $item; @@ -127,6 +122,11 @@ class FreelinkingManager extends DefaultPluginManager implements FreelinkingMana } $index++; } + // Set argument with INI-style configuration. + elseif (strpos($item, '=')) { + list($name, $value) = explode('=', $item); + $args[$name] = $value; + } else { $args['other'][] = $item; } diff --git a/tests/src/Unit/FreelinkingManagerTest.php b/tests/src/Unit/FreelinkingManagerTest.php new file mode 100644 index 0000000..005a48e --- /dev/null +++ b/tests/src/Unit/FreelinkingManagerTest.php @@ -0,0 +1,90 @@ +prophesize('\Drupal\Core\Extension\ModuleHandlerInterface'); + $moduleHandler = $moduleProphet->reveal(); + $languageProphet = $this->prophesize('\Drupal\Core\Language\LanguageInterface'); + $this->language = $languageProphet->reveal(); + $languageManagerProphet = $this->prophesize('\Drupal\Core\Language\LanguageManagerInterface'); + $languageManagerProphet->getLanguage('en')->willReturn($this->language); + $languageManager = $languageManagerProphet->reveal(); + + $namespaces = new \ArrayObject(); + + $this->pluginManager = new FreelinkingManager($namespaces, $cacheBackend, $moduleHandler, $languageManager); + } + + /** + * Tests parseTarget method. + * + * @param array $expected + * The expected destination string. + * @param string $target + * + * @dataProvider parseTargetProvider + */ + public function testParseTarget($expected, $target) { + $expected['target'] = $target; + $expected['language'] = $this->language; + + $this->assertEquals($expected, $this->pluginManager->parseTarget($target, 'en')); + } + + /** + * Provide test parameters and expected values for testParseTarget(). + * + * @return array + * An array of test parameters and expected values. + */ + public function parseTargetProvider() { + return [ + [ + [ + 'dest' => 'nid:2', + 'text' => 'Special title', + 'tooltip' => 'tooltip', + 'other' => [], + ], + 'nid:2|Special title|tooltip', + ], + [ + [ + 'dest' => 'nid:2', + 'text' => null, + 'tooltip' => null, + 'other' => [], + ], + 'nid:2', + ], + ]; + } +}