diff --git a/core/modules/views/src/Plugin/views/style/StylePluginBase.php b/core/modules/views/src/Plugin/views/style/StylePluginBase.php index 5bfc0d1..542aaf3 100644 --- a/core/modules/views/src/Plugin/views/style/StylePluginBase.php +++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php @@ -245,7 +245,7 @@ public function hasArgToken($value) { return FALSE; } // Otherwise, scan for valid token patterns. - return (preg_match('/[!%]\d*/', $value) !== FALSE); + return preg_match('/[!%]\d+/', $value); } /** @@ -264,9 +264,8 @@ public function hasRowToken($value) { return FALSE; } // Otherwise, scan for valid token patterns. - $tokens = \Drupal::token()->scan($value); // Match any non-empty string between [ and ] that does not contain [ or ]. - return (preg_match('/\[[^\[\]]+\]/', $value) !== FALSE); + return preg_match('/\[[^\[\]]+\]/', $value); } /** diff --git a/core/modules/views/tests/src/Unit/Plugin/style/StylePluginBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/style/StylePluginBaseTest.php new file mode 100644 index 0000000..c16025a --- /dev/null +++ b/core/modules/views/tests/src/Unit/Plugin/style/StylePluginBaseTest.php @@ -0,0 +1,132 @@ +stylePlugin = new TestStylePlugin(array(), 'default', array()); + } + + /** + * @covers ::hasArgToken + * @dataProvider providerHasArgToken + */ + public function testHasArgToken($value, $return) { + $this->assertEquals($this->stylePlugin->hasArgToken($value), $return); + } + + /** + * Data provider for testHasArgToken(). + * + * @return array + */ + public function providerHasArgToken() { + return array( + array('%', FALSE), + array('!', FALSE), + array('!', FALSE), + array('% 1', FALSE), + array('! 1', FALSE), + array('!1', TRUE), + array('%1', TRUE), + array(' !12345 ', TRUE), + array(' %54321 ', TRUE), + array('%elephant', FALSE), + array('!elephant', FALSE), + array('[other_token]', FALSE), + ); + } + + /** + * @covers ::hasRowToken + * @dataProvider providerHasRowToken + */ + public function testHasRowToken($value, $return) { + $this->assertEquals($this->stylePlugin->hasRowToken($value), $return); + } + + /** + * Data provider for testHasRowToken(). + * + * @return array + */ + public function providerHasRowToken() { + return array( + array('%1', FALSE), + array('!1', FALSE), + array('[', FALSE), + array(']', FALSE), + array('[]', FALSE), + array('[[]', FALSE), + array('[elephant]', TRUE), + array(' [elephant_row_token_1] ', TRUE), + ); + } + + /** + * @covers ::hasGlobalToken + * @dataProvider providerHasGlobalToken + * + * @see \Drupal\system\Tests\System\TokenScanTest + */ + public function testHasGlobalToken($value, $return) { + // @todo This needs to have Token available, and atm the whole bleeping + // Drupal class and service container as well. + //$this->assertEquals($this->stylePlugin->hasGlobalToken($value), $return); + } + + /** + * Data provider for testHasGlobalToken(). + * + * @return array + * + * @see \Drupal\system\Tests\System\TokenScanTest + */ + public function providerHasGlobalToken() { + return array( + array('%1', FALSE), + array('!1', FALSE), + array('[', FALSE), + array(']', FALSE), + array('[]', FALSE), + array('[[]', FALSE), + array('[elephant]', FALSE), + // We don't need to test too many valid patterns because the token tests + // cover that already. + array(' [some:token] ', TRUE) + ); + } + + /** + * @covers ::hasToken + */ + public function testHasToken() { + } + +} + +class TestStylePlugin extends StylePluginBase {}