Commit 1b9e6bdb authored by webchick's avatar webchick

Issue #2349677 by davidhernandez, Xen, emma.maria, runand, mortendk: Copy...

Issue #2349677 by davidhernandez, Xen, emma.maria, runand, mortendk: Copy filter templates to Classy
parent 98d23400
......@@ -118,7 +118,7 @@ function testCaptionFilter() {
// Data-caption attribute.
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" />';
$expected = '<figure class="caption caption-img"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
......@@ -130,14 +130,14 @@ function testCaptionFilter() {
// HTML entities in the caption.
$input = '<img src="llama.jpg" data-caption="&ldquo;Loquacious llama!&rdquo;" />';
$expected = '<figure class="caption caption-img"><img src="llama.jpg" /><figcaption>“Loquacious llama!”</figcaption></figure>';
$expected = '<figure><img src="llama.jpg" /><figcaption>“Loquacious llama!”</figcaption></figure>';
$output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
// HTML encoded as HTML entities in data-caption attribute.
$input = '<img src="llama.jpg" data-caption="&lt;em&gt;Loquacious llama!&lt;/em&gt;" />';
$expected = '<figure class="caption caption-img"><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);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
......@@ -146,33 +146,33 @@ function testCaptionFilter() {
// not allowed by the HTML spec, but may happen when people manually write
// HTML, so we explicitly support it.
$input = '<img src="llama.jpg" data-caption="<em>Loquacious llama!</em>" />';
$expected = '<figure class="caption caption-img"><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);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
// Security test: attempt an XSS.
$input = '<img src="llama.jpg" data-caption="<script>alert(\'Loquacious llama!\')</script>" />';
$expected = '<figure class="caption caption-img"><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);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
// Ensure the filter also works with uncommon yet valid attribute quoting.
$input = '<img src=llama.jpg data-caption=\'Loquacious llama!\' />';
$expected = '<figure class="caption caption-img"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
// Finally, ensure that this also works on any other tag.
$input = '<video src="llama.jpg" data-caption="Loquacious llama!" />';
$expected = '<figure class="caption caption-video"><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);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
$input = '<foobar data-caption="Loquacious llama!">baz</foobar>';
$expected = '<figure class="caption caption-foobar"><foobar>baz</foobar><figcaption>Loquacious llama!</figcaption></figure>';
$expected = '<figure><foobar>baz</foobar><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
......@@ -198,17 +198,17 @@ function testAlignAndCaptionFilters() {
// Both data-caption and data-align attributes: all 3 allowed values for the
// data-align attribute.
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="left" />';
$expected = '<figure class="caption caption-img 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);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="center" />';
$expected = '<figure class="caption caption-img 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);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="right" />';
$expected = '<figure class="caption caption-img 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);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
......@@ -216,7 +216,7 @@ function testAlignAndCaptionFilters() {
// Both data-caption and data-align attributes, but a disallowed data-align
// attribute value.
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" data-align="left foobar" />';
$expected = '<figure class="caption caption-img"><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$expected = '<figure><img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAssets());
......
......@@ -117,9 +117,9 @@ public function testTextFormatElement() {
$output = $this->render($form);
$this->setRawContent($output);
$this->assertFieldByName('textformat[value]');
$this->assertRaw('<h4 class="label">Full HTML</h4>');
$this->assertRaw('<h4 class="label">Filtered HTML</h4>');
$this->assertRaw('<h4 class="label">Test format</h4>');
$this->assertRaw('<h4>Full HTML</h4>');
$this->assertRaw('<h4>Filtered HTML</h4>');
$this->assertRaw('<h4>Test format</h4>');
$this->assertNoPattern('|<h4[^>]*></h4>|', 'No empty H4 element found.');
}
......
......@@ -12,7 +12,7 @@
* - string classes: The classes of the captioned HTML tag.
*/
#}
<figure class="caption caption-{{ tag }}{%- if classes %} {{ classes }}{%- endif %}">
<figure{%- if classes %} class="{{ classes }}"{%- endif %}>
{{ node }}
<figcaption>{{ caption }}</figcaption>
</figure>
......@@ -19,13 +19,7 @@
* @ingroup themeable
*/
#}
{%
set classes = [
'filter-guidelines-item',
'filter-guidelines-' ~ format.format,
]
%}
<div{{ attributes.addClass(classes) }}>
<h4 class="label">{{ format.label }}</h4>
<div{{ attributes }}>
<h4>{{ format.label }}</h4>
{{ tips }}
</div>
......@@ -24,30 +24,19 @@
{% if tips|length %}
{% if multiple %}
<div class="compose-tips">
<div>
{% endif %}
{% for name, tip in tips %}
{% if multiple %}
{%
set tip_classes = [
'filter-type',
'filter-' ~ name|clean_class,
]
%}
<div{{ tip.attributes.addClass(tip_classes) }}>
<div{{ attributes }}>
<h3>{{ tip.name }}</h3>
{% endif %}
{% if tip.list|length %}
<ul class="tips">
<ul>
{% for item in tip.list %}
{%
set item_classes = [
long ? 'filter-' ~ item.id|replace({'/': '-'}),
]
%}
<li{{ item.attributes.addClass(item_classes) }}>{{ item.tip }}</li>
<li{{ tip.attributes }}>{{ item.tip }}</li>
{% endfor %}
</ul>
{% endif %}
......
......@@ -15,14 +15,9 @@
* @ingroup themeable
*/
#}
<div class="text-format-wrapper form-item">
<div>
{{ children }}
{% if description %}
{%
set classes = [
aria_description ? 'description',
]
%}
<div{{ attributes.addClass(classes) }}>{{ description }}</div>
<div{{ attributes }}>{{ description }}</div>
{% endif %}
</div>
{#
/**
* @file
* Default theme implementation for a filter caption.
*
* Returns HTML for a captioned image, audio, video or other tag.
*
* Available variables
* - string node: The complete HTML tag whose contents are being captioned.
* - string tag: The name of the HTML tag whose contents are being captioned.
* - string caption: The caption text.
* - string classes: The classes of the captioned HTML tag.
*/
#}
<figure class="caption caption-{{ tag }}{%- if classes %} {{ classes }}{%- endif %}">
{{ node }}
<figcaption>{{ caption }}</figcaption>
</figure>
{#
/**
* @file
* Default theme implementation for guidelines for a text format.
*
* Available variables:
* - format: Contains information about the current text format, including the
* following:
* - name: The name of the text format, potentially unsafe and needs to be
* escaped.
* - format: The machine name of the text format, e.g. 'basic_html'.
* - attributes: HTML attributes for the containing element.
* - tips: Descriptions and a CSS ID in the form of 'module-name/filter-id'
* (only used when 'long' is TRUE) for each filter in one or more text
* formats.
*
* @see template_preprocess_filter_tips()
*
* @ingroup themeable
*/
#}
{%
set classes = [
'filter-guidelines-item',
'filter-guidelines-' ~ format.format,
]
%}
<div{{ attributes.addClass(classes) }}>
<h4 class="label">{{ format.label }}</h4>
{{ tips }}
</div>
{#
/**
* @file
* Default theme implementation for a set of filter tips.
*
* Available variables:
* - tips: Descriptions and a CSS ID in the form of 'module-name/filter-id'
* (only used when 'long' is TRUE) for each filter in one or more text
* formats.
* - long: A flag indicating whether the passed-in filter tips contain extended
* explanations, i.e. intended to be output on the path 'filter/tips'
* (TRUE), or are in a short format, i.e. suitable to be displayed below a
* form element. Defaults to FALSE.
* - multiple: A flag indicating there is more than one filter tip.
*
* @see template_preprocess_filter_tips()
*
* @ingroup themeable
*/
#}
{% if multiple %}
<h2>{{ 'Text Formats'|t }}</h2>
{% endif %}
{% if tips|length %}
{% if multiple %}
<div class="compose-tips">
{% endif %}
{% for name, tip in tips %}
{% if multiple %}
{%
set tip_classes = [
'filter-type',
'filter-' ~ name|clean_class,
]
%}
<div{{ tip.attributes.addClass(tip_classes) }}>
<h3>{{ tip.name }}</h3>
{% endif %}
{% if tip.list|length %}
<ul class="tips">
{% for item in tip.list %}
{%
set item_classes = [
long ? 'filter-' ~ item.id|replace({'/': '-'}),
]
%}
<li{{ item.attributes.addClass(item_classes) }}>{{ item.tip }}</li>
{% endfor %}
</ul>
{% endif %}
{% if multiple %}
</div>
{% endif %}
{% endfor %}
{% if multiple %}
</div>
{% endif %}
{% endif %}
{#
/**
* @file
* Default theme implementation for a text format-enabled form element.
*
* Available variables:
* - children: Text format element children.
* - description: Text format element description.
* - attributes: HTML attributes for the containing element.
* - aria_description: Flag for whether or not an ARIA description has been
* added to the description container.
*
* @see template_preprocess_text_format_wrapper()
*
* @ingroup themeable
*/
#}
<div class="text-format-wrapper form-item">
{{ children }}
{% if description %}
{%
set classes = [
aria_description ? 'description',
]
%}
<div{{ attributes.addClass(classes) }}>{{ description }}</div>
{% endif %}
</div>
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