Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handled custom attributes when converting XmlText to RichText #92

Merged
merged 9 commits into from
Apr 30, 2019
18 changes: 6 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,18 @@ addons:

matrix:
include:
- php: 5.6
env: TEST_CONFIG="phpunit.xml"
- php: 7.0
- php: 7.1
env: TEST_CONFIG="phpunit.xml"
- php: 7.2
env: TEST_CONFIG="phpunit.xml" CHECK_CS=true
- php: 7.0
env: TEST_CONFIG="phpunit-integration-legacy.xml"
- php: 5.6
env: TEST_CONFIG="phpunit-integration-legacy-solr.xml" SOLR_VERSION="4.10.4" CORES_SETUP="single" SOLR_CORES="collection1" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml"
- php: 7.1
env: TEST_CONFIG="phpunit-integration-legacy-solr.xml" SOLR_VERSION="6.6.0" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml"
- php: 7.3
env: TEST_CONFIG="phpunit.xml"
- php: 7.1
env: TEST_CONFIG="phpunit-integration-legacy-solr.xml" SOLR_VERSION="6.6.5" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml"
- php: 7.2
env: TEST_CONFIG="phpunit-integration-legacy-empty-db.xml" DB="postgresql" DATABASE="pgsql://postgres@localhost/testdb"
- php: 7.1
- php: 7.3
env: TEST_CONFIG="phpunit-integration-legacy-empty-db.xml" DB="mysql" DATABASE="mysql://root@localhost/testdb"
- php: 7.0
env: TEST_CONFIG="phpunit.xml" COMPOSER_REQUIRE="ezsystems/ezpublish-kernel:^6.13.6@dev"

# test only master (+ Pull requests)
branches:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"require": {
"ezsystems/ezpublish-kernel": "^6.13.6@dev || ^7.2.5@dev",
"ezsystems/repository-forms": "^1.9 || ^2.0"
"ezsystems/repository-forms": "^1.9 || ^2.0",
"ezsystems/ezplatform-richtext": "^1.1"
andrerom marked this conversation as resolved.
Show resolved Hide resolved
},
"require-dev": {
"phpunit/phpunit": "^5.7",
Expand Down
2 changes: 1 addition & 1 deletion lib/FieldType/XmlText/Converter/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
use Psr\Log\LoggerInterface;
use eZ\Publish\Core\FieldType\RichText\Converter\Aggregate;
use eZ\Publish\Core\FieldType\RichText\Converter\Xslt;
use eZ\Publish\Core\FieldType\RichText\Validator;
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
use Psr\Log\NullLogger;
use Psr\Log\LogLevel;
use Symfony\Component\Debug\Exception\ContextErrorException;
use eZ\Publish\API\Repository\Repository;
use EzSystems\EzPlatformRichText\eZ\RichText\Validator\Validator;

class RichText implements Converter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<xsl:value-of select="@custom:language"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:value-of disable-output-escaping="yes" select="./text()"/>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
Expand Down Expand Up @@ -149,6 +150,18 @@
<xsl:template match="line">
</xsl:template>

<xsl:template name="custom-attributes">
<xsl:if test="@*[namespace-uri() = 'http://ez.no/namespaces/ezpublish3/custom/' and not( local-name() = 'class' ) and not( local-name() = 'align' )]">
<xsl:element name="ezattribute" namespace="http://docbook.org/ns/docbook">
<xsl:for-each select="@*[namespace-uri() = 'http://ez.no/namespaces/ezpublish3/custom/' and not( local-name() = 'class' ) and not( local-name() = 'align' )]">
alongosz marked this conversation as resolved.
Show resolved Hide resolved
<xsl:call-template name="addHashValue">
<xsl:with-param name="attribute" select="current()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:template>

<xsl:template match="paragraph">
<xsl:element name="para" namespace="http://docbook.org/ns/docbook">
<xsl:if test="@class">
Expand All @@ -161,6 +174,7 @@
<xsl:with-param name="align" select="@align"/>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:variable name="lines" select="line"/>
<xsl:choose>
<xsl:when test="count( $lines ) &gt; 0">
Expand All @@ -185,6 +199,7 @@

<xsl:template match="custom[@name='quote']">
<xsl:element name="blockquote" namespace="http://docbook.org/ns/docbook">
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand All @@ -196,6 +211,7 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand All @@ -208,6 +224,7 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand All @@ -217,22 +234,26 @@
<xsl:when test="@name='underline'">
<xsl:element name="emphasis" namespace="http://docbook.org/ns/docbook">
<xsl:attribute name="role">underlined</xsl:attribute>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:when test="@name='strike'">
<xsl:element name="emphasis" namespace="http://docbook.org/ns/docbook">
<xsl:attribute name="role">strikedthrough</xsl:attribute>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:when test="@name='sub'">
<xsl:element name="subscript" namespace="http://docbook.org/ns/docbook">
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:when test="@name='sup'">
<xsl:element name="superscript" namespace="http://docbook.org/ns/docbook">
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
Expand Down Expand Up @@ -278,6 +299,7 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand Down Expand Up @@ -367,6 +389,7 @@
<xsl:with-param name="align" select="@align"/>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand All @@ -378,6 +401,7 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand All @@ -389,6 +413,7 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand All @@ -400,6 +425,7 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand Down Expand Up @@ -451,6 +477,7 @@
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:if test="$tableElement = 'table'">
<xsl:element name="caption" namespace="http://docbook.org/ns/docbook">
<xsl:value-of select="@custom:caption"/>
Expand All @@ -471,6 +498,7 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand Down Expand Up @@ -517,6 +545,7 @@
<xsl:value-of select="@custom:scope"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand Down Expand Up @@ -553,6 +582,7 @@
<xsl:value-of select="@xhtml:rowspan"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="custom-attributes" />
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/FieldType/Converter/EzxmlToDocbookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
namespace EzSystems\EzPlatformXmlTextFieldType\Tests\FieldType\Converter;

use eZ\Publish\Core\FieldType\RichText\Validator;
use EzSystems\EzPlatformRichText\eZ\RichText\Validator\Validator;
use eZ\Publish\Core\FieldType\XmlText\Converter\RichText;
use eZ\Publish\Core\SignalSlot\Repository;
use eZ\Publish\API\Repository\ContentService;
Expand Down Expand Up @@ -58,8 +58,8 @@ private function createApiRepositoryStub()
protected function getConverter($inputFile)
{
$validatorSchemas = [
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng',
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
'./vendor/ezsystems/ezplatform-richtext/src/lib/eZ/RichText/Resources/schemas/docbook/ezpublish.rng',
'./vendor/ezsystems/ezplatform-richtext/src/lib/eZ/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
];
$apiRepositoryStub = $this->createApiRepositoryStub();

Expand Down
6 changes: 3 additions & 3 deletions tests/lib/FieldType/Converter/RichTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use eZ\Publish\API\Repository\Values\Content\Location;
use Psr\Log\NullLogger;
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
use eZ\Publish\Core\FieldType\RichText\Validator;
use EzSystems\EzPlatformRichText\eZ\RichText\Validator\Validator;

class RichTextTest extends TestCase
{
Expand Down Expand Up @@ -258,8 +258,8 @@ public function getValidator()
{
return new Validator(
array(
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng',
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
'./vendor/ezsystems/ezplatform-richtext/src/lib/eZ/RichText/Resources/schemas/docbook/ezpublish.rng',
'./vendor/ezsystems/ezplatform-richtext/src/lib/eZ/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<para ezxhtml:textalign="center">This is a centered paragraph.</para>
<para ezxhtml:textalign="right">This is a right aligned paragraph.</para>
<para ezxhtml:textalign="justify">This is a justified paragraph.</para>
<para><ezattribute><ezvalue key="name-1">value 1</ezvalue><ezvalue key="name-2">value 2</ezvalue></ezattribute>This is a paragraph with custom tags.</para>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
version="5.0-variant ezpublish-1.0">
<title ezxhtml:level="2">This is a heading.</title>
<para>This is a paragraph with <emphasis ezxhtml:class="emphasisClass">emphasized</emphasis> text.</para>
<para>This is a paragraph with <emphasis><ezattribute><ezvalue key="name-1">value 1</ezvalue><ezvalue key="name-2">value 2</ezvalue></ezattribute>emphasized (custom attributes)</emphasis> text.</para>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
version="5.0-variant ezpublish-1.0">
<title ezxhtml:level="2">This is a heading.</title>
<para>This is a paragraph with <emphasis role="strong" ezxhtml:class="emphasisStrongClass">strong</emphasis> text.</para>
<para>This is a paragraph with <emphasis role="strong"><ezattribute><ezvalue key="name-1">value 1</ezvalue><ezvalue key="name-2">value 2</ezvalue></ezattribute>strong (custom attributes)</emphasis> text.</para>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
version="5.0-variant ezpublish-1.0">
<title ezxhtml:level="2">This is a heading.</title>
<para>This is a paragraph with <emphasis role="underlined">underlined</emphasis> text.</para>
<para>This is a paragraph with <emphasis role="underlined"><ezattribute><ezvalue key="name-1">value 1</ezvalue><ezvalue key="name-2">value 2</ezvalue></ezattribute>underlined (custom attributes)</emphasis> text.</para>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@
<orderedlist ezxhtml:class="orderedListClass">
<listitem ezxhtml:class="listItemClass"><para>This is a list item.</para></listitem>
</orderedlist>
<orderedlist>
<ezattribute>
<ezvalue key="name-1">list 1</ezvalue>
<ezvalue key="name-2">list 2</ezvalue>
</ezattribute>
<listitem>
<ezattribute>
<ezvalue key="name-1">list item 1</ezvalue>
<ezvalue key="name-2">list item 2</ezvalue>
</ezattribute>
<para>This is a list item (custom attributes).</para>
</listitem>
</orderedlist>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@
<itemizedlist ezxhtml:class="itemizedListClass">
<listitem ezxhtml:class="listItemClass"><para>This is a list item.</para></listitem>
</itemizedlist>
<itemizedlist>
<ezattribute>
<ezvalue key="name-1">list 1</ezvalue>
<ezvalue key="name-2">list 2</ezvalue>
</ezattribute>
<listitem>
<ezattribute>
<ezvalue key="name-1">list item 1</ezvalue>
<ezvalue key="name-2">list item 2</ezvalue>
</ezattribute>
<para>This is a list item.</para>
</listitem>
</itemizedlist>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,56 @@
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"
version="5.0-variant ezpublish-1.0">
<informaltable class="tableClass" width="24" title="tableTitle" border="1" style="border-width:42px;">
<ezattribute>
<ezvalue key="summary">tableTitle</ezvalue>
<ezvalue key="caption"/>
<ezvalue key="table-1">value 1</ezvalue>
<ezvalue key="table-2">value 2</ezvalue>
</ezattribute>
<tbody>
<tr class="rowClass1">
<ezattribute>
<ezvalue key="row">value 1</ezvalue>
</ezattribute>
<th class="headingClass1" ezxhtml:width="102" valign="top" colspan="1" rowspan="5" abbr="XSLT" scope="col">
<ezattribute>
<ezvalue key="valign">top</ezvalue>
<ezvalue key="abbr">XSLT</ezvalue>
<ezvalue key="scope">col</ezvalue>
<ezvalue key="header">value 1</ezvalue>
</ezattribute>
<para>11</para>
</th>
<th class="headingClass2" ezxhtml:width="37%" valign="middle" colspan="2" rowspan="6" abbr="XSD" scope="row">
<ezattribute>
<ezvalue key="valign">middle</ezvalue>
<ezvalue key="abbr">XSD</ezvalue>
<ezvalue key="scope">row</ezvalue>
<ezvalue key="header">value 2</ezvalue>
</ezattribute>
<para>12.1</para>
<para>12.2</para>
</th>
</tr>
<tr class="rowClass2">
<ezattribute>
<ezvalue key="row">value 2</ezvalue>
</ezattribute>
<td class="cellClass1" ezxhtml:width="74%" valign="bottom" colspan="3" rowspan="7">
<ezattribute>
<ezvalue key="valign">bottom</ezvalue>
<ezvalue key="column">value 1</ezvalue>
</ezattribute>
<para>21</para>
<itemizedlist ezxhtml:class="itemizedListClass">
<listitem ezxhtml:class="listItemClass"><para>This is a list item.</para></listitem>
</itemizedlist>
</td>
<td class="cellClass2" ezxhtml:width="38" valign="baseline" colspan="4" rowspan="8">
<ezattribute>
<ezvalue key="valign">baseline</ezvalue>
<ezvalue key="column">value 2</ezvalue>
</ezattribute>
<para>22</para>
<para><literallayout class="normal">This is a paragraph
with some
Expand Down
Loading