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

Issue #67: Fix tests and details parsing. #68

Merged
merged 5 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions src/Messages/Components/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function getAttributes()
{
$attributes = [
'channel' => $this->getChannel(),
'dealine' => $this->getDeadline(),
'statusDealine' => $this->getDeadlineStatus(),
'deadline' => $this->getDeadline(),
'statusDeadline' => $this->getDeadlineStatus(),
'marked' => $this->getConfidential(),
'format' => $this->getFormat(),
'legiswrite' => $this->getLegiswriteFormat(),
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ private function parseAttributionsSend(Parser $parser)
$this->withReturnAddress()
->setParser($this->getParser())
->setType($component->attr('type'))
->setAction($component->attr('action'))
->setUser($component->getContent('attributionsSend/retourUser'))
->setPassword($component->getContent('attributionsSend/retourPassword'))
->setAddress($component->getContent('attributionsSend/retourAddress'))
Expand All @@ -357,6 +356,7 @@ private function parseAttributions(Parser $parser)
{
$this->setFormat($parser->getAttribute('attributions', 'format'))
->setLanguage($parser->getAttribute('attributions', 'lgCode'))
->setAction($parser->getAttribute('attributions', 'action'))
->setTrackChanges($parser->getAttribute('attributions', 'trackChanges'))
->setRemark($parser->getContent('attributions/attributionsRemark'))
->setDelay($parser->getContent('attributions/attributionsDelai'))
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');
}
}
1 change: 1 addition & 0 deletions src/Services/Providers/MessagesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function register(Container $container)
'component.source' => Component\Source::class,
'component.status' => Component\Status::class,
'component.target' => Component\Target::class,
'component.source_language' => Component\SourceLanguage::class,
];
$this->serviceFactory($messages, $container);

Expand Down
4 changes: 2 additions & 2 deletions templates/components/contact.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
?>
<contacts <?= $this->attributes($component->getAttributes()) ?>>
<contactNickname><?= $component->getNickname() ?></contactNickname>
<contactNickname><![CDATA[<?= $component->getNickname() ?>]]></contactNickname>
<?php if ($component->getEmail()) : ?>
<contactEmail><?= $component->getEmail() ?></contactEmail>
<contactEmail><![CDATA[<?= $component->getEmail() ?>]]></contactEmail>
<?php endif ?>
</contacts>
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>
6 changes: 3 additions & 3 deletions templates/components/reference-document.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<documentReference <?= $this->attributes($component->getAttributes()) ?>>
<documentReferenceName><![CDATA[<?= $component->getName() ?>]]></documentReferenceName>
<?php if ($component->getPath()) : ?>
<documentReferencePath><?= $component->getPath() ?></documentReferencePath>
<documentReferencePath><![CDATA[<?= $component->getPath() ?>]]></documentReferencePath>
<?php endif ?>
<?php if ($component->getSize()) : ?>
<documentReferenceSize><?= $component->getSize() ?></documentReferenceSize>
<documentReferenceSize><![CDATA[<?= $component->getSize() ?>]]></documentReferenceSize>
<?php endif ?>
<?php if ($component->getRemark()) : ?>
<documentReferenceRemark><![CDATA[<?= $component->getRemark() ?>]]></documentReferenceRemark>
<?php endif ?>
<documentReferenceFile><?= $component->getFile() ?></documentReferenceFile>
<documentReferenceFile><![CDATA[<?= $component->getFile() ?>]]></documentReferenceFile>
</documentReference>
2 changes: 1 addition & 1 deletion templates/components/return-address.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
<?php if ($component->getRemark()) : ?>
<retourRemark><![CDATA[<?= $component->getRemark() ?>]]></retourRemark>
<?php endif ?>
</retour>
</retour>
4 changes: 3 additions & 1 deletion templates/components/source-language.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
* @var \EC\Poetry\Messages\Components\SourceLanguage $component
*/
?>
<documentSourceLang lgCode="<?= $component->getCode() ?>"><documentSourceLangPages><?= $component->getPages() ?></documentSourceLangPages></documentSourceLang>
<documentSourceLang lgCode="<?= $this->escape($component->getCode()) ?>">
<documentSourceLangPages><![CDATA[<?= $component->getPages() ?>]]></documentSourceLangPages>
</documentSourceLang>
4 changes: 2 additions & 2 deletions templates/components/source.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<documentSourceName><![CDATA[<?= $component->getName() ?>]]></documentSourceName>
<documentSourceFile><![CDATA[<?= $component->getFile() ?>]]></documentSourceFile>
<?php if ($component->getPath()) : ?>
<documentSourcePath><?= $component->getPath() ?></documentSourcePath>
<documentSourcePath><![CDATA[<?= $component->getPath() ?>]]></documentSourcePath>
<?php endif ?>
<?php if ($component->getSourceLanguages()) : ?>
<?php foreach ($component->getSourceLanguages() as $target) : ?>
<?= $this->component($target); ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if ($component->getSize()) : ?>
<documentSourceSize><?= $component->getSize() ?></documentSourceSize>
<documentSourceSize><![CDATA[<?= $component->getSize() ?>]]></documentSourceSize>
<?php endif ?>
</documentSource>
4 changes: 2 additions & 2 deletions templates/components/status.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
?>
<status <?= $this->attributes($component->getAttributes()) ?>>
<statusDate><?= $component->getDate() ?></statusDate>
<statusDate><![CDATA[<?= $component->getDate() ?>]]></statusDate>
<?php if ($component->getTime()) : ?>
<statusTime><?= $component->getTime() ?></statusTime>
<statusTime><![CDATA[<?= $component->getTime() ?>]]></statusTime>
<?php endif ?>
<?php if ($component->getMessage()) : ?>
<statusMessage><![CDATA[<?= $component->getMessage() ?>]]></statusMessage>
Expand Down
20 changes: 9 additions & 11 deletions templates/components/target.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,31 @@
?>
<attributions
<?php if ($component->getAction()) : ?>
action="<?= $component->getAction() ?>"
action="<?= $this->escape($component->getAction()) ?>"
<?php endif ?>
format="<?= $component->getFormat() ?>" lgCode="<?= $component->getLanguage() ?>">
format="<?= $this->escape($component->getFormat()) ?>" lgCode="<?= $this->escape($component->getLanguage()) ?>">
<?php if ($component->getRemark()) : ?>
<attributionsRemark><![CDATA[<?= $component->getRemark() ?>]]></attributionsRemark>
<?php endif ?>
<?php if ($component->getDelay()) : ?>
<attributionsDelai
<?php if ($component->getDelayFormat()) : ?>
format="<?= $component->getDelayFormat() ?>"
<?php endif ?>
><?= $component->getDelay() ?></attributionsDelai>
<?php if ($component->getDelayFormat()) : ?>
format="<?= $this->escape($component->getDelayFormat()) ?>"
<?php endif ?>><![CDATA[<?= $component->getDelay() ?>]]></attributionsDelai>
<?php endif ?>
<?php if ($component->getAcceptedDelay()) : ?>
<attributionsDelaiAccepted
<?php if ($component->getAcceptedDelayFormat()) : ?>
format="<?= $component->getAcceptedDelayFormat() ?>"
<?php endif ?>
><?= $component->getAcceptedDelay() ?></attributionsDelaiAccepted>
<?php if ($component->getAcceptedDelayFormat()) : ?>
format="<?= $this->escape($component->getAcceptedDelayFormat()) ?>"
<?php endif ?>><![CDATA[<?= $component->getAcceptedDelay() ?>]]></attributionsDelaiAccepted>
<?php endif ?>
<?php if ($component->getReturnAddresses()) : ?>
<?php foreach ($component->getReturnAddresses() as $address) : ?>
<?= $this->component($address); ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if ($component->getTranslatedFile()) : ?>
<attributionsFile><?= $component->getTranslatedFile() ?></attributionsFile>
<attributionsFile><![CDATA[<?= $component->getTranslatedFile() ?>]]></attributionsFile>
<?php endif ?>
<?php if ($component->getContacts()) : ?>
<?php foreach ($component->getContacts() as $contact) : ?>
Expand Down
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.
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
Loading