From eb87ce043e584576d34c6650208e24a9cdbe1bd8 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Thu, 9 Nov 2017 18:11:04 +0100 Subject: [PATCH] Issue #62: Add tests for CreateTranslationRequest. --- src/Messages/Requests/CreateReviewRequest.php | 1 + .../Requests/CreateTranslationRequest.php | 24 +++++++ .../Requests/CreateReviewRequestTest.php | 22 ++++++- .../{ => requests}/create-review-request.yml | 0 .../requests/create-review-request.yml | 66 +++++++++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) rename tests/src/fixtures/factories/with-array/{ => requests}/create-review-request.yml (100%) create mode 100644 tests/src/fixtures/factories/with-xml/requests/create-review-request.yml diff --git a/src/Messages/Requests/CreateReviewRequest.php b/src/Messages/Requests/CreateReviewRequest.php index 34bfbde..5d333eb 100644 --- a/src/Messages/Requests/CreateReviewRequest.php +++ b/src/Messages/Requests/CreateReviewRequest.php @@ -3,6 +3,7 @@ namespace EC\Poetry\Messages\Requests; use EC\Poetry\Messages\Components\Identifier; +use EC\Poetry\Services\Parser; use EC\Poetry\Services\Settings; /** diff --git a/src/Messages/Requests/CreateTranslationRequest.php b/src/Messages/Requests/CreateTranslationRequest.php index 54c42e3..d3979f7 100644 --- a/src/Messages/Requests/CreateTranslationRequest.php +++ b/src/Messages/Requests/CreateTranslationRequest.php @@ -68,4 +68,28 @@ public static function getConstraints(ClassMetadata $metadata) $metadata->addPropertyConstraint('targets', new Assert\Valid(['traverse' => true])); $metadata->addPropertyConstraint('referenceDocuments', new Assert\Valid(['traverse' => true])); } + + /** + * {@inheritdoc} + */ + public function withXml($xml) + { + parent::withXml($xml); + + $parser = $this->getParser(); + $parser->addXmlContent($xml); + + $parser->eachComponent("POETRY/request/contacts", function (Parser $component) { + $this->withContact() + ->setParser($this->getParser()) + ->withXml($component->outerHtml()); + }, $this); + + $xml = $parser->getOuterContent('POETRY/request/retour'); + $this->withReturnAddress() + ->setParser($this->getParser()) + ->withXml($xml); + + return $this; + } } diff --git a/tests/src/Messages/Requests/CreateReviewRequestTest.php b/tests/src/Messages/Requests/CreateReviewRequestTest.php index 29801e3..5492873 100644 --- a/tests/src/Messages/Requests/CreateReviewRequestTest.php +++ b/tests/src/Messages/Requests/CreateReviewRequestTest.php @@ -106,11 +106,31 @@ public function testWithArray(array $array, array $expressions) $this->assertExpressions($expressions, ['message' => $message]); } + /** + * @param string $xml + * @param array $expressions + * + * @dataProvider parserProvider + */ + public function testWithXml($xml, $expressions) + { + $message = $this->getContainer()->get('request.create_review_request')->withXml($xml); + $this->assertExpressions($expressions, ['message' => $message]); + } + + /** + * @return array + */ + public function parserProvider() + { + return Yaml::parse($this->getFixture('factories/with-xml/requests/create-review-request.yml')); + } + /** * @return mixed */ public function withArrayProvider() { - return Yaml::parse($this->getFixture('factories/with-array/create-review-request.yml')); + return Yaml::parse($this->getFixture('factories/with-array/requests/create-review-request.yml')); } } diff --git a/tests/src/fixtures/factories/with-array/create-review-request.yml b/tests/src/fixtures/factories/with-array/requests/create-review-request.yml similarity index 100% rename from tests/src/fixtures/factories/with-array/create-review-request.yml rename to tests/src/fixtures/factories/with-array/requests/create-review-request.yml diff --git a/tests/src/fixtures/factories/with-xml/requests/create-review-request.yml b/tests/src/fixtures/factories/with-xml/requests/create-review-request.yml new file mode 100644 index 0000000..3490e96 --- /dev/null +++ b/tests/src/fixtures/factories/with-xml/requests/create-review-request.yml @@ -0,0 +1,66 @@ +- + xml: + + + + + STSI + 2017 + 40017 + 0 + 11 + REV + + + Job ID 3999 + NE-CMS Erasmus+ - Erasmus Mundus Joint Master Degrees + EAC + IE/CE/EAC + IE/CE/EAC/C/4 + FPFIS + 12/09/2017 + https://ec.europa.eu/programmes/erasmus-plus/opportunities-for-individuals/staff-teaching/erasmus-mundus_en + + + + STS + + john + bob + + MY-TEST-USER + MY-TEST-PASSWORD + https://example.com/callback/wsdl/PoetryIntegration.wsdl + TestReturnPath + + + content.html + BASE64ENCODEDFILECONTENT + + 1 + + + 12/09/2017 + + + + expressions: + - message.getIdentifier().getCode() == 'STSI' + - message.getIdentifier().getYear() == '2017' + - message.getIdentifier().getNumber() == '40017' + - message.getIdentifier().getVersion() == '0' + - message.getIdentifier().getPart() == '11' + - message.getIdentifier().getProduct() == 'REV' + - message.getContacts()[0].getType() == 'auteur' + - message.getContacts()[0].getNickname() == 'john' + - message.getContacts()[0].getEmail() == null + - message.getContacts()[1].getType() == 'secretaire' + - message.getContacts()[1].getNickname() == 'bob' + - message.getContacts()[1].getEmail() == null + - message.getReturnAddress().getType() == 'webService' + - message.getReturnAddress().getAction() == 'UPDATE' + - message.getReturnAddress().getUser() == 'MY-TEST-USER' + - message.getReturnAddress().getPassword() == 'MY-TEST-PASSWORD' + - message.getReturnAddress().getAddress() == 'https://example.com/callback/wsdl/PoetryIntegration.wsdl' + - message.getReturnAddress().getPath() == 'TestReturnPath'