Skip to content

Commit 7274087

Browse files
Adam Bozsokihalaz-lazlo
andcommitted
AT-2285: fix contact list lookup when there is spaces around the contact list name
Co-authored-by: Laszlo Halasz <laszlo.halasz@emarsys.com>
1 parent 600f9a4 commit 7274087

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/Suite/Api/ContactList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function findContactListByName(int $customerId, string $listName)
5555
{
5656
try {
5757
foreach ($this->getContactLists($customerId) as $contactListData) {
58-
if (strtolower($contactListData['name']) == strtolower($listName)) {
58+
if (trim(strtolower($contactListData['name'])) == strtolower($listName)) {
5959
return $contactListData['id'];
6060
}
6161
}

test/unit/Suite/Api/ContactListTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,35 @@ public function findContactListByName_Perfect_Perfect()
128128

129129
/**
130130
* @test
131+
* @dataProvider contactListNameProvider
131132
*/
132-
public function findContactListByName_CasesDoNotMatch_ContactListIdStillReturned()
133+
public function findContactListByName_CasesDoNotMatch_ContactListIdStillReturned($contactListName)
133134
{
134-
$contactLists = array(
135+
$contactLists = [
135136
$this->contactListData('id1', 'contact list 1'),
136137
$this->contactListData('id2', 'contact list 2'),
137-
$this->contactListData($this->contactListId, strtoupper($this->listName)),
138-
);
138+
$this->contactListData($this->contactListId, $contactListName),
139+
];
139140

140141
$this->apiClient->expects($this->once())->method('get')->with($this->endPoints->contactLists($this->customerId))
141142
->willReturn($this->apiSuccess($contactLists));
142143

143-
$contactListId = $this->listService->findContactListByName($this->customerId, $this->listName);
144+
$contactListId = $this->listService->findContactListByName($this->customerId, trim(strtolower($contactListName)));
144145

145146
$this->assertEquals($this->contactListId, $contactListId);
146147
}
147148

149+
public function contactListNameProvider()
150+
{
151+
return [
152+
'upperCase' => [strtoupper($this->listName)],
153+
'lowerCase' => [strtolower($this->listName)],
154+
'spaceAfter' => [$this->listName . " "],
155+
'spaceBefore' => [" " . $this->listName],
156+
'spaceInContactListName' => [" my very best contact list "]
157+
];
158+
}
159+
148160
/**
149161
* @test
150162
*/

0 commit comments

Comments
 (0)