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

Update PNR traveller date of birth format #231

Merged
merged 16 commits into from
Sep 23, 2018
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
16 changes: 14 additions & 2 deletions src/Amadeus/Client/Struct/Pnr/AddMultiElements/TravellerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function loadTraveller(TravellerOptions $traveller)

if ($traveller->dateOfBirth instanceof \DateTime) {
$this->passengerData[0]->dateOfBirth = new DateOfBirth(
$traveller->dateOfBirth->format('dmY')
$this->formatDateOfBirth($traveller->dateOfBirth)
);
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ protected function addInfant($traveller)

if ($traveller->infant->dateOfBirth instanceof \DateTime) {
$tmpInfant->dateOfBirth = new DateOfBirth(
$traveller->infant->dateOfBirth->format('dmY')
$this->formatDateOfBirth($traveller->infant->dateOfBirth)
);
}

Expand All @@ -175,4 +175,16 @@ protected function makePassengerIfNeeded()
$this->passengerData[0]->travellerInformation->passenger[0] = new Passenger(null, null);
}
}

protected function formatDateOfBirth(\DateTime $dateOfBirth)
{
$day = (int) $dateOfBirth->format('d');
if ($day < 10) {
$day = "0$day";
}

$monthAndYear = strtoupper($dateOfBirth->format('My'));

return $day . $monthAndYear;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Test\Amadeus\Client\Struct\Pnr\AddMultiElements;

use Amadeus\Client\Struct\Pnr\AddMultiElements\TravellerInfo;
use Test\Amadeus\BaseTestCase;

/**
* TravellerInfoTest
*
* @package Test\Amadeus\Client\Struct\Pnr\AddMultiElements
* @author Artem Zakharchenko <[email protected]>
*/
class TravellerInfoTest extends BaseTestCase
{
public function testDateOfBirthFormat()
{
$travellerInfoClass = new \ReflectionClass('\Amadeus\Client\Struct\Pnr\AddMultiElements\TravellerInfo');

$method = $travellerInfoClass->getMethod('formatDateOfBirth');
$method->setAccessible(true);

$travellerInfo = new TravellerInfo();

$dateOfBirth = \DateTime::createFromFormat('d-m-Y', '15-08-2000');
$this->assertEquals('15AUG00', $method->invoke($travellerInfo, $dateOfBirth));

// Format when day earlier than 10
$dateOfBirth2 = \DateTime::createFromFormat('d-m-Y', '01-02-1992');
$this->assertEquals('01FEB92', $method->invoke($travellerInfo, $dateOfBirth2));
}
}
12 changes: 3 additions & 9 deletions tests/Amadeus/Client/Struct/Pnr/AddMultiElementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public function testMakePnrWithPassengerDateOfBirth()
$this->assertEquals(1, count($requestStruct->travellerInfo));
$this->assertEquals(1, count($requestStruct->travellerInfo[0]->passengerData));
$this->assertEquals(706, $requestStruct->travellerInfo[0]->passengerData[0]->dateOfBirth->dateAndTimeDetails->qualifier);
$this->assertEquals('08011947', $requestStruct->travellerInfo[0]->passengerData[0]->dateOfBirth->dateAndTimeDetails->date);
$this->assertEquals('08JAN47', $requestStruct->travellerInfo[0]->passengerData[0]->dateOfBirth->dateAndTimeDetails->date);
}

public function testMakePnrWithGenericRemarkAndExplicitReceivedFrom()
Expand Down Expand Up @@ -1161,7 +1161,7 @@ public function testCanCreatePnrWithChild()
$this->assertNull($requestStruct->travellerInfo[0]->elementManagementPassenger->reference);
$this->assertEquals(1, count($requestStruct->travellerInfo[0]->passengerData));
$this->assertEquals(706, $requestStruct->travellerInfo[0]->passengerData[0]->dateOfBirth->dateAndTimeDetails->qualifier);
$this->assertEquals('31012010', $requestStruct->travellerInfo[0]->passengerData[0]->dateOfBirth->dateAndTimeDetails->date);
$this->assertEquals('31JAN10', $requestStruct->travellerInfo[0]->passengerData[0]->dateOfBirth->dateAndTimeDetails->date);
$this->assertEquals('CHD', $requestStruct->travellerInfo[0]->passengerData[0]->travellerInformation->passenger[0]->type);
}

Expand Down Expand Up @@ -1235,13 +1235,10 @@ public function testCanCreateAddSegmentsMessageForExistingPnr()
$this->assertEquals(AddMultiElements\Reference::QUAL_OTHER, $requestStruct->originDestinationDetails[0]->itineraryInfo[0]->elementManagementItinerary->reference->qualifier);
$this->assertEquals('GENERIC TRAVEL REQUEST', $requestStruct->originDestinationDetails[0]->itineraryInfo[0]->airAuxItinerary->freetextItinerary->longFreetext);
$this->assertEquals(AddMultiElements\RelatedProduct::STATUS_CONFIRMED, $requestStruct->originDestinationDetails[0]->itineraryInfo[0]->airAuxItinerary->relatedProduct->status);


}

public function testCanCreateMessageForManipulateExistingPnr()
{

$ameOptions = new PnrAddMultiElementsOptions([
'recordLocator' => 'ABC123',
'actionCode' => PnrAddMultiElementsOptions::ACTION_END_TRANSACT,
Expand Down Expand Up @@ -1305,7 +1302,6 @@ public function testAddInfantPassengerNoDetails()

public function testaddInfantPassengerWithFirstnameNoSurname()
{

$createPnrOptions = new PnrCreatePnrOptions();
$createPnrOptions->receivedFrom = "unittest";
$createPnrOptions->travellers[] = new Traveller([
Expand Down Expand Up @@ -1346,7 +1342,6 @@ public function testaddInfantPassengerWithFirstnameNoSurname()

public function testaddInfantPassengerWithFirstnameSurnameAndBirthDate()
{

$createPnrOptions = new PnrCreatePnrOptions();
$createPnrOptions->receivedFrom = "unittest";
$createPnrOptions->travellers[] = new Traveller([
Expand Down Expand Up @@ -1388,12 +1383,11 @@ public function testaddInfantPassengerWithFirstnameSurnameAndBirthDate()
$this->assertEquals('Cohen', $msg->travellerInfo[0]->passengerData[1]->travellerInformation->traveller->surname);
$this->assertEquals('Junior', $msg->travellerInfo[0]->passengerData[1]->travellerInformation->passenger[0]->firstName);
$this->assertEquals(AddMultiElements\Passenger::PASST_INFANT, $msg->travellerInfo[0]->passengerData[1]->travellerInformation->passenger[0]->type);
$this->assertEquals('08012016', $msg->travellerInfo[0]->passengerData[1]->dateOfBirth->dateAndTimeDetails->date);
$this->assertEquals('08JAN16', $msg->travellerInfo[0]->passengerData[1]->dateOfBirth->dateAndTimeDetails->date);
}

public function testCanHandleAddInfantPassengerWhereMainPassengerHasNoFirstName()
{

$createPnrOptions = new PnrCreatePnrOptions();
$createPnrOptions->receivedFrom = "unittest";
$createPnrOptions->travellers[] = new Traveller([
Expand Down