Unverified Commit d5841b09 authored by alexpott's avatar alexpott

Issue #2918643 by eyilmaz, alexpott: TipPluginText's ariaId is not unique

parent fb4c9034
......@@ -39,6 +39,13 @@ class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInter
*/
protected $location;
/**
* Unique aria-id.
*
* @var string
*/
protected $ariaId;
/**
* Constructs a \Drupal\tour\Plugin\tour\tip\TipPluginText object.
*
......@@ -70,11 +77,10 @@ public static function create(ContainerInterface $container, array $configuratio
* A unique id to be used to generate aria attributes.
*/
public function getAriaId() {
static $id;
if (!isset($id)) {
$id = Html::getUniqueId($this->get('id'));
if (!$this->ariaId) {
$this->ariaId = Html::getUniqueId($this->get('id'));
}
return $id;
return $this->ariaId;
}
/**
......
<?php
namespace Drupal\Tests\tour\Unit\Plugin\tour\tip;
use Drupal\Tests\UnitTestCase;
use Drupal\tour\Plugin\tour\tip\TipPluginText;
/**
* @coversDefaultClass \Drupal\tour\Plugin\tour\tip\TipPluginText
* @group tour
*/
class TipPluginTextTest extends UnitTestCase {
/**
* Tests that getAriaId returns unique id per plugin instance.
*
* @see \Drupal\tour\Plugin\tour\tip\TipPluginText::getAriaId()
*/
public function testGetAriaId() {
$id_instance_one = $this->getRandomGenerator()->word(4, TRUE);
$id_instance_two = $this->getRandomGenerator()->word(4, TRUE);
$config_instance_one = [
'id' => $id_instance_one,
];
$config_instance_two = [
'id' => $id_instance_two,
];
$definition = [];
$plugin_id = 'text';
$token = $this->createMock('\Drupal\Core\Utility\Token');
$instance_one = new TipPluginText($config_instance_one, $plugin_id, $definition, $token);
$instance_two = new TipPluginText($config_instance_two, $plugin_id, $definition, $token);
$instance_three = new TipPluginText($config_instance_one, $plugin_id, $definition, $token);
$this->assertEquals($id_instance_one, $instance_one->getAriaId());
$this->assertEquals($id_instance_two, $instance_two->getAriaId());
$this->assertNotEquals($instance_one->getAriaId(), $instance_two->getAriaId());
$this->assertNotEquals($instance_one->getAriaId(), $instance_three->getAriaId());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment