Commit 6dc5310a authored by alexpott's avatar alexpott

Issue #2505937 by JeroenT: Remove usage of @deprecated methods on BubbleableMetadata class

parent e5d87b1e
...@@ -80,7 +80,7 @@ public function process($text, $langcode) { ...@@ -80,7 +80,7 @@ public function process($text, $langcode) {
} }
$result->setProcessedText(Html::serialize($dom)) $result->setProcessedText(Html::serialize($dom))
->addAssets(array( ->addAttachments(array(
'library' => array( 'library' => array(
'filter/caption', 'filter/caption',
), ),
......
...@@ -123,7 +123,7 @@ function testCaptionFilter() { ...@@ -123,7 +123,7 @@ function testCaptionFilter() {
$expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// Empty data-caption attribute. // Empty data-caption attribute.
$input = '<img src="llama.jpg" data-caption="" />'; $input = '<img src="llama.jpg" data-caption="" />';
...@@ -135,14 +135,14 @@ function testCaptionFilter() { ...@@ -135,14 +135,14 @@ function testCaptionFilter() {
$expected = '<figure><img src="llama.jpg" /><figcaption>“Loquacious llama!”</figcaption></figure>'; $expected = '<figure><img src="llama.jpg" /><figcaption>“Loquacious llama!”</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// HTML encoded as HTML entities in data-caption attribute. // HTML encoded as HTML entities in data-caption attribute.
$input = '<img src="llama.jpg" data-caption="&lt;em&gt;Loquacious llama!&lt;/em&gt;" />'; $input = '<img src="llama.jpg" data-caption="&lt;em&gt;Loquacious llama!&lt;/em&gt;" />';
$expected = '<figure><img src="llama.jpg" /><figcaption><em>Loquacious llama!</em></figcaption></figure>'; $expected = '<figure><img src="llama.jpg" /><figcaption><em>Loquacious llama!</em></figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// HTML (not encoded as HTML entities) in data-caption attribute, which is // HTML (not encoded as HTML entities) in data-caption attribute, which is
// not allowed by the HTML spec, but may happen when people manually write // not allowed by the HTML spec, but may happen when people manually write
...@@ -151,33 +151,33 @@ function testCaptionFilter() { ...@@ -151,33 +151,33 @@ function testCaptionFilter() {
$expected = '<figure><img src="llama.jpg" /><figcaption><em>Loquacious llama!</em></figcaption></figure>'; $expected = '<figure><img src="llama.jpg" /><figcaption><em>Loquacious llama!</em></figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// Security test: attempt an XSS. // Security test: attempt an XSS.
$input = '<img src="llama.jpg" data-caption="<script>alert(\'Loquacious llama!\')</script>" />'; $input = '<img src="llama.jpg" data-caption="<script>alert(\'Loquacious llama!\')</script>" />';
$expected = '<figure><img src="llama.jpg" /><figcaption>alert(\'Loquacious llama!\')</figcaption></figure>'; $expected = '<figure><img src="llama.jpg" /><figcaption>alert(\'Loquacious llama!\')</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// Ensure the filter also works with uncommon yet valid attribute quoting. // Ensure the filter also works with uncommon yet valid attribute quoting.
$input = '<img src=llama.jpg data-caption=\'Loquacious llama!\' />'; $input = '<img src=llama.jpg data-caption=\'Loquacious llama!\' />';
$expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// Finally, ensure that this also works on any other tag. // Finally, ensure that this also works on any other tag.
$input = '<video src="llama.jpg" data-caption="Loquacious llama!" />'; $input = '<video src="llama.jpg" data-caption="Loquacious llama!" />';
$expected = '<figure><video src="llama.jpg"></video><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure><video src="llama.jpg"></video><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
$input = '<foobar data-caption="Loquacious llama!">baz</foobar>'; $input = '<foobar data-caption="Loquacious llama!">baz</foobar>';
$expected = '<figure><foobar>baz</foobar><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure><foobar>baz</foobar><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// So far we've tested that the caption filter works correctly. But we also // So far we've tested that the caption filter works correctly. But we also
// want to make sure that it works well in tandem with the "Limit allowed // want to make sure that it works well in tandem with the "Limit allowed
...@@ -271,17 +271,17 @@ function testAlignAndCaptionFilters() { ...@@ -271,17 +271,17 @@ function testAlignAndCaptionFilters() {
$expected = '<figure class="align-left"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure class="align-left"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="center" />'; $input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="center" />';
$expected = '<figure class="align-center"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure class="align-center"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="right" />'; $input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="right" />';
$expected = '<figure class="align-right"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure class="align-right"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
// Both data-caption and data-align attributes, but a disallowed data-align // Both data-caption and data-align attributes, but a disallowed data-align
// attribute value. // attribute value.
...@@ -289,7 +289,7 @@ function testAlignAndCaptionFilters() { ...@@ -289,7 +289,7 @@ function testAlignAndCaptionFilters() {
$expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>'; $expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets()); $this->assertIdentical($attached_library, $output->getAttachments());
} }
/** /**
......
...@@ -27,7 +27,7 @@ class FilterTestAssets extends FilterBase { ...@@ -27,7 +27,7 @@ class FilterTestAssets extends FilterBase {
*/ */
public function process($text, $langcode) { public function process($text, $langcode) {
$result = new FilterProcessResult($text); $result = new FilterProcessResult($text);
$result->addAssets(array( $result->addAttachments(array(
'library' => array( 'library' => array(
'filter/caption', 'filter/caption',
), ),
......
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