diff --git a/core/lib/Drupal/Core/Field/FieldFilteredString.php b/core/lib/Drupal/Core/Field/FieldFilteredString.php index c3fca4d..d41c366 100644 --- a/core/lib/Drupal/Core/Field/FieldFilteredString.php +++ b/core/lib/Drupal/Core/Field/FieldFilteredString.php @@ -78,8 +78,16 @@ public static function displayAllowedTags() { } /** - * @param $option - * @return $this|static + * Transforms the string given an option. + * + * @param string $option + * One of the following: + * - upper: makes the string uppercase. + * - lower: makes the string lowercase. + * - ucfirst: makes the string's first character uppercase. + * - ucwords: uppercase the first character of each word in the string. + * + * @return static * If the case transformation does not affect the string the same object is * returned. If it does, then a new object is returned, preserving * immutability. diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 5c9bd68..a80a4bd 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -10,7 +10,6 @@ use Drupal\Core\Field\FieldFilteredString; use Drupal\Core\Render\Element; - /** * Returns HTML for an individual file upload widget. * diff --git a/core/tests/Drupal/Tests/Core/Field/FieldFilteredStringTest.php b/core/tests/Drupal/Tests/Core/Field/FieldFilteredStringTest.php new file mode 100644 index 0000000..9546b08 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Field/FieldFilteredStringTest.php @@ -0,0 +1,101 @@ +assertInstanceOf(FieldFilteredString::class, $filtered_string); + } + $this->assertSame($expected, (string) $filtered_string); + } + + /** + * Provides data for testCreate(). + */ + public function providerTestCreate() { + $data = []; + $data[] = [ + '', '', + ]; + $data[] = [ + 'teststring', 'teststring', TRUE + ]; + + $safe_string = $this->prophesize(SafeStringInterface::class); + $safe_string->__toString()->willReturn('teststring'); + + $data[] = [ + $safe_string->reveal(), 'teststring', TRUE + ]; + return $data; + } + + /** + * @covers: ::allowedTags + */ + public function testAllowedTags() { + $expected = ['a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img']; + + $this->assertSame($expected, FieldFilteredString::allowedTags()); + } + + /** + * @covers: ::displayAllowedTags + */ + public function testdisplayAllowedTags() { + $expected = '
        

    • '; + + $this->assertSame($expected, FieldFilteredString::displayAllowedTags()); + } + + /** + * @covers ::caseTransform + * @dataProvider providertestCaseTransform + */ + public function testCaseTransform($option, $test_string, $expected) { + $filtered_string = FieldFilteredString::create($test_string); + $this->assertEquals($expected, $filtered_string->caseTransform($option)); + } + + /** + * Provides data for testCaseTransform(). + */ + public function providertestCaseTransform() { + $data = []; + $data[] = [ + 'upper', 'teststring', 'TESTSTRING' + ]; + $data[] = [ + 'lower', 'TESTSTRING', 'teststring' + ]; + $data[] = [ + 'ucfirst', 'teststring', 'Teststring' + ]; + $data[] = [ + 'ucwords', 'teststring and teststring', 'Teststring And Teststring' + ]; + return $data; + } + +}