Loading src/Plugin/metatag/Tag/MetaNameBase.php +2 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,8 @@ abstract class MetaNameBase extends PluginBase { * The meta tag value after processing. */ protected function tidy($value) { $value = str_replace(["\r\n", "\n", "\r", "\t"], ' ', $value); $value = preg_replace('/\s+/', ' ', $value); return trim($value); } Loading tests/src/Unit/MetaNameBaseTest.php 0 → 100644 +65 −0 Original line number Diff line number Diff line <?php namespace Drupal\metatag\Unit; use Drupal\metatag\Plugin\metatag\Tag\MetaNameBase; use Drupal\Tests\UnitTestCase; /** * This class provides methods for testing the MetaNameBase class. * * @group metatag */ class MetaNameBaseTest extends UnitTestCase { /** * The MetaNameBase Mocked Object. * * @var \Drupal\metatag\Plugin\metatag\Tag\MetaNameBase|\PHPUnit\Framework\MockObject\MockObject */ protected $metaNameBase; /** * {@inheritDoc} */ protected function setUp(): void { parent::setUp(); // Mocking cause it's an abstract class. $this->metaNameBase = $this->getMockBuilder(MetaNameBase::class) ->setConstructorArgs([[], 'test', []]) ->disableOriginalConstructor() ->getMockForAbstractClass(); } /** * Tests the tidy method. */ public function testTidy() { $method = "tidy"; $class = new \ReflectionClass(get_class($this->metaNameBase)); $method = $class->getMethod($method); // Set the protected method tidy to be accessible. $method->setAccessible(TRUE); $filterResult1 = $method->invoke($this->metaNameBase, " Test 123 "); $this->assertEquals('Test 123', $filterResult1); $filterResult2 = $method->invoke($this->metaNameBase, ' Test 123 Test'); $this->assertEquals('Test 123 Test', $filterResult2); $filterResult3 = $method->invoke( $this->metaNameBase, "Test \n\n123\n Test \n " ); $this->assertEquals('Test 123 Test', $filterResult3); $filterResult4 = $method->invoke( $this->metaNameBase, "Test \r\n\r\n 123 \r\n " ); $this->assertEquals('Test 123', $filterResult4); $filterResult5 = $method->invoke( $this->metaNameBase, "Test \t\t123 \tTest" ); $this->assertEquals('Test 123 Test', $filterResult5); } } Loading
src/Plugin/metatag/Tag/MetaNameBase.php +2 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,8 @@ abstract class MetaNameBase extends PluginBase { * The meta tag value after processing. */ protected function tidy($value) { $value = str_replace(["\r\n", "\n", "\r", "\t"], ' ', $value); $value = preg_replace('/\s+/', ' ', $value); return trim($value); } Loading
tests/src/Unit/MetaNameBaseTest.php 0 → 100644 +65 −0 Original line number Diff line number Diff line <?php namespace Drupal\metatag\Unit; use Drupal\metatag\Plugin\metatag\Tag\MetaNameBase; use Drupal\Tests\UnitTestCase; /** * This class provides methods for testing the MetaNameBase class. * * @group metatag */ class MetaNameBaseTest extends UnitTestCase { /** * The MetaNameBase Mocked Object. * * @var \Drupal\metatag\Plugin\metatag\Tag\MetaNameBase|\PHPUnit\Framework\MockObject\MockObject */ protected $metaNameBase; /** * {@inheritDoc} */ protected function setUp(): void { parent::setUp(); // Mocking cause it's an abstract class. $this->metaNameBase = $this->getMockBuilder(MetaNameBase::class) ->setConstructorArgs([[], 'test', []]) ->disableOriginalConstructor() ->getMockForAbstractClass(); } /** * Tests the tidy method. */ public function testTidy() { $method = "tidy"; $class = new \ReflectionClass(get_class($this->metaNameBase)); $method = $class->getMethod($method); // Set the protected method tidy to be accessible. $method->setAccessible(TRUE); $filterResult1 = $method->invoke($this->metaNameBase, " Test 123 "); $this->assertEquals('Test 123', $filterResult1); $filterResult2 = $method->invoke($this->metaNameBase, ' Test 123 Test'); $this->assertEquals('Test 123 Test', $filterResult2); $filterResult3 = $method->invoke( $this->metaNameBase, "Test \n\n123\n Test \n " ); $this->assertEquals('Test 123 Test', $filterResult3); $filterResult4 = $method->invoke( $this->metaNameBase, "Test \r\n\r\n 123 \r\n " ); $this->assertEquals('Test 123', $filterResult4); $filterResult5 = $method->invoke( $this->metaNameBase, "Test \t\t123 \tTest" ); $this->assertEquals('Test 123 Test', $filterResult5); } }