From 2487c4085d13dd14e1935f496f3f339c6d1ebcc0 Mon Sep 17 00:00:00 2001 From: Finlay Metcalfe <43369124+Ofthemasses@users.noreply.github.com> Date: Fri, 22 Dec 2023 12:00:33 +1300 Subject: [PATCH] ENH Create Requirements::customScriptWithAttributes (#11076) * ENH Create Requirements::customScriptWithAttributes * MNT PHP Lint failures corrected * ENH Refactored attribute handling to avoid API changes, auto lowercase, strong typing * FIX Updated default value handling for type in customScriptWithAttributes * DOC Removed white space * MNT PHP Lint Failures Corrected * Update src/View/Requirements_Backend.php Co-authored-by: Steve Boyd * Update src/View/Requirements_Backend.php Co-authored-by: Steve Boyd * Update tests/php/View/RequirementsTest.php Co-authored-by: Steve Boyd * FIX Removed extra closing brace in customScriptWithAttributes * Update src/View/Requirements_Backend.php Co-authored-by: Steve Boyd * Update src/View/Requirements.php Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> * MNT Fixed left over content definition and created tests for uniquenessIDs * MNT Fixed PHP Lint Error * MNT Fix PHP Lint Error * FIX Remove attribute when calling customScript with the same uniquenessID --------- Co-authored-by: Steve Boyd Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> --- src/View/Requirements.php | 15 ++++++ src/View/Requirements_Backend.php | 50 +++++++++++++++++- tests/php/View/RequirementsTest.php | 81 +++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/src/View/Requirements.php b/src/View/Requirements.php index f95607145ae..c757f2ba2d9 100644 --- a/src/View/Requirements.php +++ b/src/View/Requirements.php @@ -142,6 +142,21 @@ public static function customScript($script, $uniquenessID = null) self::backend()->customScript($script, $uniquenessID); } + /** + * Register the given Javascript code into the list of requirements with optional tag + * attributes. + * + * @param string $script The script content as a string (without enclosing `#s", + $html, + 'customScript is displaying latest write' + ); + + $this->assertDoesNotMatchRegularExpression( + "##s", + $html, + 'customScript is correctly not displaying original write' + ); + + /* customScriptWithAttributes is overwritten by customScript */ + $this->assertMatchesRegularExpression( + "##s", + $html, + 'customScript is displaying latest write and clearing attributes' + ); + + $this->assertDoesNotMatchRegularExpression( + "##s", + $html, + 'customScript is displaying latest write' + ); + + /* customCSS is overwritten */ + $this->assertMatchesRegularExpression( + "##", + $html, + 'customCSS is displaying latest write' + ); + + $this->assertDoesNotMatchRegularExpression( + "##", + $html, + 'customCSS is correctly not displaying original write' + ); + + /* Head Tags is overwritten */ + $this->assertMatchesRegularExpression( + '#Override#', + $html, + 'Head Tag is displaying latest write' + ); + + $this->assertDoesNotMatchRegularExpression( + '#Do Not Display#', + $html, + 'Head Tag is correctly not displaying original write' + ); + } }