Skip to content

Commit

Permalink
Merge pull request #16 from thebiggive/CLA-32-long-name-truncate
Browse files Browse the repository at this point in the history
CLA-32 – truncate name fields to meet schema validation requirements
  • Loading branch information
NoelLH authored Jun 29, 2023
2 parents 2ee16f9 + c7d0b93 commit 2cb7d49
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"require": {
"php": "^8.0",
"ext-dom": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"ext-xmlwriter": "*",
"ext-zlib": "*",
Expand Down
13 changes: 7 additions & 6 deletions src/Individual.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class Individual
public function __construct($title, $name, $surname, $phone, $houseNum, $postcode, $overseas = false)
{
$this->title = $title;
$this->surname = $surname;
$this->forename = $name;
$this->phone = $phone;
$this->houseNum = $houseNum;
$this->postcode = $postcode;
$this->isOverseas = $overseas;

$this->setForename($name);
$this->setSurname($surname);
$this->setHouseNum($houseNum);
}

public function getTitle()
Expand All @@ -40,7 +41,7 @@ public function getSurname()

public function setSurname($value)
{
$this->surname = $value;
$this->surname = mb_substr($value, 0, 35);
}

public function getForename()
Expand All @@ -50,7 +51,7 @@ public function getForename()

public function setForename($value)
{
$this->forename = $value;
$this->forename = mb_substr($value, 0, 35);
}

public function getPhone()
Expand All @@ -70,7 +71,7 @@ public function getHouseNum()

public function setHouseNum($value)
{
$this->houseNum = substr($value, 0, 40);
$this->houseNum = mb_substr($value, 0, 40);
}

public function getPostcode()
Expand Down
16 changes: 16 additions & 0 deletions tests/GovTalk/GiftAid/IndividualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public function testIndividualCreation()
$this->assertEquals($this->individual->getIsOverseas(), 'no');
}

public function testIndividualCreationWithLongNameAndAddressValues()
{
$testIndividual = new Individual(
title: '',
name: str_repeat('a', 36),
surname: str_repeat('b', 36),
houseNum: str_repeat('c', 41),
postcode: 'N11XX',
phone: '07777 777777',
);

$this->assertEquals(35, strlen($testIndividual->getForename()));
$this->assertEquals(35, strlen($testIndividual->getSurname()));
$this->assertEquals(40, strlen($testIndividual->getHouseNum()));
}

public function testForeignIndividualCreation()
{
$this->assertEquals($this->foreign->getTitle(), 'Ds');
Expand Down

0 comments on commit 2cb7d49

Please sign in to comment.