Skip to content

Commit

Permalink
Issue #67: Fix tests and details parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Dec 12, 2017
1 parent 4391bf3 commit 96f7783
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 23 deletions.
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '2'
services:
php56:
image: fpfis/php56-dev
volumes:
- .:/var/www/html
environment:
XDEBUG_CONFIG: "remote_enable=1 remote_host=${DOCKER_HOST_IP} remote_port=9000 idekey=PHPSTORM remote_autostart=1"
PHP_IDE_CONFIG: "serverName=Test"

php71:
image: fpfis/php71-dev
volumes:
- .:/var/www/html
environment:
XDEBUG_CONFIG: "remote_enable=1 remote_host=${DOCKER_HOST_IP} remote_port=9000 idekey=PHPSTORM remote_autostart=1"
PHP_IDE_CONFIG: "serverName=Test"
9 changes: 5 additions & 4 deletions src/Messages/Components/Details.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,19 @@ protected function parseXml($xml)
->setApplicationId($parser->getContent('demande/applicationReference'))
->setAuthor($parser->getContent('demande/organisationAuteur'))
->setRequester($parser->getContent('demande/serviceDemandeur'))
->setResponsible($parser->getContent('demande/organisationResponsable'))
->setTitle($parser->getContent('demande/titre'))
->setRemark($parser->getContent('demande/remarque'))
->setType($parser->getContent('demande/type'))
->setWorkflowCode($parser->getContent('demande/workflowCode'))
->setDestination($parser->getContent('demande/destination'))
->setProcedure($parser->getContent('demande/procedure'))
->setProcedure($parser->getAttribute('demande/procedure', 'id'))
->setDestination($parser->getAttribute('demande/destination', 'id'))
->setType($parser->getAttribute('demande/type', 'id'))
->setDelay($parser->getContent('demande/delai'))
->setRequestDate($parser->getContent('demande/dateDemande'))
->setStatus($parser->getContent('demande/statusDemande'))
->setInterServices($parser->getContent('demande/consultationInterServices'))
->setInterInstitution($parser->getContent('demande/procedureInterInstitution'))
->setReferenceFilesRemark($parser->getContent('demande/reference_files_note'));
->setReferenceFilesRemark($parser->getContent('demande/referenceFilesNote'));

return $this;
}
Expand Down
11 changes: 10 additions & 1 deletion src/Services/Plates/AttributesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ public function render(array $attributes)
{
$renderedAttributes = [];
foreach ($attributes as $key => $value) {
$renderedAttributes[] = $key.'="'.htmlspecialchars($value, ENT_XML1).'"';
$renderedAttributes[] = $key.'="'.$this->escape($value).'"';
}

return implode(' ', $renderedAttributes);
}

/**
* @param string $string
* @return string
*/
public function escape($string)
{
return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT, 'UTF-8');
}
}
26 changes: 13 additions & 13 deletions templates/components/details.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,48 @@
<titre><![CDATA[<?= $component->getTitle() ?>]]></titre>
<?php endif ?>
<?php if ($component->getResponsible()) : ?>
<organisationResponsable><?= $component->getResponsible() ?></organisationResponsable>
<organisationResponsable><![CDATA[<?= $component->getResponsible() ?>]]></organisationResponsable>
<?php endif ?>
<?php if ($component->getAuthor()) : ?>
<organisationAuteur><?= $component->getAuthor() ?></organisationAuteur>
<organisationAuteur><![CDATA[<?= $component->getAuthor() ?>]]></organisationAuteur>
<?php endif ?>
<?php if ($component->getRequester()) : ?>
<serviceDemandeur><?= $component->getRequester() ?></serviceDemandeur>
<serviceDemandeur><![CDATA[<?= $component->getRequester() ?>]]></serviceDemandeur>
<?php endif ?>
<?php if ($component->getApplicationId()) : ?>
<applicationReference><?= $component->getApplicationId() ?></applicationReference>
<applicationReference><![CDATA[<?= $component->getApplicationId() ?>]]></applicationReference>
<?php endif ?>
<?php if ($component->getRemark()) : ?>
<remarque><![CDATA[<?= $component->getRemark() ?>]]></remarque>
<?php endif ?>
<?php if ($component->getDelay()) : ?>
<delai><?= $component->getDelay() ?></delai>
<delai><![CDATA[<?= $component->getDelay() ?>]]></delai>
<?php endif ?>
<?php if ($component->getRequestDate()) : ?>
<dateDemande><?= $component->getRequestDate() ?></dateDemande>
<dateDemande><![CDATA[<?= $component->getRequestDate() ?>]]></dateDemande>
<?php endif ?>
<?php if ($component->getStatus()) : ?>
<statusDemande><?= $component->getStatus() ?></statusDemande>
<statusDemande><![CDATA[<?= $component->getStatus() ?>]]></statusDemande>
<?php endif ?>
<?php if ($component->getInterServices()) : ?>
<consultationInterServices><?= $component->getInterServices() ?></consultationInterServices>
<consultationInterServices><![CDATA[<?= $component->getInterServices() ?>]]></consultationInterServices>
<?php endif ?>
<?php if ($component->getInterInstitution()) : ?>
<procedureInterInstitution><?= $component->getInterInstitution() ?></procedureInterInstitution>
<procedureInterInstitution><![CDATA[<?= $component->getInterInstitution() ?>]]></procedureInterInstitution>
<?php endif ?>
<?php if ($component->getReferenceFilesRemark()) : ?>
<referenceFilesNote><![CDATA[<?= $component->getReferenceFilesRemark() ?>]]></referenceFilesNote>
<?php endif ?>
<?php if ($component->getProcedure()) : ?>
<procedure id="<?= $component->getProcedure() ?>"/>
<procedure id="<?= $this->escape($component->getProcedure()) ?>"/>
<?php endif ?>
<?php if ($component->getDestination()) : ?>
<destination id="<?= $component->getDestination() ?>"/>
<destination id="<?= $this->escape($component->getDestination()) ?>"/>
<?php endif ?>
<?php if ($component->getType()) : ?>
<type id="<?= $component->getType() ?>"/>
<type id="<?= $this->escape($component->getType()) ?>"/>
<?php endif ?>
<?php if ($component->getWorkflowCode()) : ?>
<workflowCode><?= $component->getWorkflowCode() ?></workflowCode>
<workflowCode><![CDATA[<?= $component->getWorkflowCode() ?>]]></workflowCode>
<?php endif ?>
</demande>
53 changes: 53 additions & 0 deletions tests/src/SanitizationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace EC\Poetry\Tests;

use EC\Poetry\Messages\Components\AbstractComponent;
use EC\Poetry\Poetry;
use Symfony\Component\Yaml\Yaml;

/**
* Class SensitizationTest.
*
* @package EC\Poetry\Tests
*/
class SanitizationTest extends AbstractTest
{

/**
* @param string $name
* @param array $setters
* @param array $getters
*
* @dataProvider dataProvider
*/
public function testSensitization($name, array $setters, array $getters)
{
$poetry = new Poetry();
/** @var AbstractComponent $component */
$component = $poetry->get('component.'.$name);

foreach ($setters as $setter => $value) {
$component->$setter($value);
}

$xml = $poetry->getRenderEngine()->render($component->getTemplate(), [
'component' => $component,
]);

$actual = $poetry->get('component.'.$name)->fromXml($xml);
// If XML is not valid test will fail here.
$xml = new \SimpleXMLElement($xml);
foreach ($getters as $getter => $value) {
expect($actual->$getter($value))->to->equal($value);
}
}

/**
* @return array
*/
public function dataProvider()
{
return Yaml::parse($this->getFixture('sanitization.yml'));
}
}
2 changes: 1 addition & 1 deletion tests/src/fixtures/arrays/components/details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
inter_services: "Yes"
inter_institution: "Yes"
reference_files_remark: "Note"
workflowCode: "STS"
workflow_code: "STS"
expected:
getClientId: "clientId"
getApplicationId: "applicationId"
Expand Down
8 changes: 4 additions & 4 deletions tests/src/fixtures/parsers/components/details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<serviceDemandeur>DGCOMM</serviceDemandeur>
<titre>Title</titre>
<remarque>Remark</remarque>
<type>INTER</type>
<destination>AUTRE</destination>
<procedure>NEANT</procedure>
<type id="INTER"/>
<destination id="AUTRE"/>
<procedure id="NEANT"/>
<delai>11/12/2007</delai>
<dateDemande>11/12/2007</dateDemande>
<statusDemande>Ready</statusDemande>
<consultationInterServices>Yes</consultationInterServices>
<procedureInterInstitution>Yes</procedureInterInstitution>
<reference_files_note>Note</reference_files_note>
<referenceFilesNote>Note</referenceFilesNote>
<workflowCode>STS</workflowCode>
</demande>
- getClientId : "clientId"
Expand Down
37 changes: 37 additions & 0 deletions tests/src/fixtures/sanitization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- component: details
setters:
setClientId: "<ID>"
setResponsible: "</Responsible>"
setApplicationId: "applicationId"
setAuthor: "DIGIT \ <> "
setRequester: "DGCOMM \\<>"
setTitle: "Title > <"
setRemark: "Remark!!{}"
setType: "INTER*^%(#"
setDestination: "AUTRE{}<[[]]"
setProcedure: "NEANT"
setDelay: "11/12/\\2007"
setRequestDate: "11\/12/2007"
setStatus: "Ready!><"
setInterServices: "<Yes?"
setInterInstitution: "/<Yes>"
setReferenceFilesRemark: "<<<Note>>>"
setWorkflowCode: "!!STS"
getters:
getClientId: "<ID>"
getResponsible: "</Responsible>"
getApplicationId: "applicationId"
getAuthor: "DIGIT \ <> "
getRequester: "DGCOMM \\<>"
getTitle: "Title > <"
getRemark: "Remark!!{}"
getType: "INTER*^%(#"
getDestination: "AUTRE{}<[[]]"
getProcedure: "NEANT"
getDelay: "11/12/\\2007"
getRequestDate: "11\/12/2007"
getStatus: "Ready!><"
getInterServices: "<Yes?"
getInterInstitution: "/<Yes>"
getReferenceFilesRemark: "<<<Note>>>"
getWorkflowCode: "!!STS"

0 comments on commit 96f7783

Please sign in to comment.