Skip to content

Commit f9d09de

Browse files
authored
Merge pull request #700 from postnl/bugfix/POSTNL-338
fix: POSTNL-338 overcome 2 lines street address validation
2 parents ae2f293 + 7497bf4 commit f9d09de

File tree

15 files changed

+74
-15
lines changed

15 files changed

+74
-15
lines changed

Service/Customer/Data.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
class Data
77
{
8+
private const ADDRESS_MAX_LINES = 3;
9+
810
protected int $addressLineExtend = 0;
911

1012
protected Address $addressHelper;
@@ -23,14 +25,15 @@ public function getAddressLinesExtendCount(): int
2325
public function canExtendAddressLines(): bool
2426
{
2527
$allowedLines = (int)$this->addressHelper->getStreetLines();
26-
return $allowedLines === 1;
28+
return $allowedLines < self::ADDRESS_MAX_LINES;
2729
}
2830

2931
public function setAddressLineExtend(): void
3032
{
3133
if (!$this->canExtendAddressLines()) {
3234
return;
3335
}
34-
$this->addressLineExtend = 2;
36+
37+
$this->addressLineExtend = self::ADDRESS_MAX_LINES - (int)$this->addressHelper->getStreetLines();
3538
}
3639
}

Test/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getInstance(array $args = [])
3535
/**
3636
* Basic setup
3737
*/
38-
public function setUp() : void
38+
protected function setUp() : void
3939
{
4040
ini_set('error_reporting', E_ALL);
4141
ini_set('display_errors', '1');

Test/Unit/Block/Adminhtml/Grid/Shipment/DownloadPdfActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DownloadPdfActionTest extends TestCase
1919
/**
2020
* {@inheritdoc}
2121
*/
22-
public function setUp() : void
22+
protected function setUp() : void
2323
{
2424
parent::setUp();
2525

Test/Unit/Block/Adminhtml/Shipment/ViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ViewTest extends TestCase
3030
/**
3131
* {@inheritdoc}
3232
*/
33-
public function setUp() : void
33+
protected function setUp() : void
3434
{
3535
parent::setUp();
3636

Test/Unit/Config/CheckoutConfiguration/IsShippingOptionsActiveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class IsShippingOptionsActiveTest extends TestCase
2525
*/
2626
private $accountConfiguration;
2727

28-
public function setUp() : void
28+
protected function setUp() : void
2929
{
3030
parent::setUp();
3131

Test/Unit/Config/Validator/ValidAddressTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ValidAddressTest extends TestCase
2020
*/
2121
private $instance;
2222

23-
public function setUp() : void
23+
protected function setUp() : void
2424
{
2525
parent::setUp();
2626

Test/Unit/Plugin/Ui/Component/MassActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MassActionTest extends TestCase
1818
/**
1919
* Set up
2020
*/
21-
public function setUp() : void
21+
protected function setUp() : void
2222
{
2323
parent::setUp();
2424

Test/Unit/Service/Carrier/Price/Filter/CountryFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CountryFilterTest extends TestCase
1515
*/
1616
private $input = [];
1717

18-
public function setUp() : void
18+
protected function setUp() : void
1919
{
2020
parent::setUp();
2121

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace TIG\PostNL\Test\Unit\Service\Customer;
5+
6+
use Magento\Customer\Helper\Address;
7+
use TIG\PostNL\Service\Customer\Data;
8+
use TIG\PostNL\Test\TestCase;
9+
10+
class DataTest extends TestCase
11+
{
12+
private $addressHelperMock;
13+
private Data $data;
14+
15+
protected function setUp(): void
16+
{
17+
$this->addressHelperMock = $this->createMock(Address::class);
18+
$this->data = new Data($this->addressHelperMock);
19+
20+
parent::setUp();
21+
}
22+
23+
public function testGetAddressLinesExtendCountReturnsInitialValue()
24+
{
25+
$this->assertSame(0, $this->data->getAddressLinesExtendCount());
26+
}
27+
28+
public function testCanExtendAddressLinesReturnsTrueWhenAllowedLinesLessThanMax()
29+
{
30+
$this->addressHelperMock->method('getStreetLines')->willReturn(2);
31+
$this->assertTrue($this->data->canExtendAddressLines());
32+
}
33+
34+
public function testCanExtendAddressLinesReturnsFalseWhenAllowedLinesEqualOrGreaterThanMax()
35+
{
36+
$this->addressHelperMock->method('getStreetLines')->willReturn(3);
37+
$this->assertFalse($this->data->canExtendAddressLines());
38+
39+
$this->addressHelperMock->method('getStreetLines')->willReturn(4);
40+
$this->assertFalse($this->data->canExtendAddressLines());
41+
}
42+
43+
public function testSetAddressLineExtendSetsValueWhenCanExtend()
44+
{
45+
$this->addressHelperMock->method('getStreetLines')->willReturn(2);
46+
$this->data->setAddressLineExtend();
47+
$this->assertSame(1, $this->data->getAddressLinesExtendCount());
48+
}
49+
50+
public function testSetAddressLineExtendDoesNothingWhenCannotExtend()
51+
{
52+
$this->addressHelperMock->method('getStreetLines')->willReturn(3);
53+
$this->data->setAddressLineExtend();
54+
$this->assertSame(0, $this->data->getAddressLinesExtendCount());
55+
}
56+
}

Test/Unit/Service/Import/Matrixrate/RowTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class RowTest extends TestCase
1414
*/
1515
private $instance;
1616

17-
public function setUp() : void
17+
protected function setUp() : void
1818
{
1919
parent::setUp();
2020

0 commit comments

Comments
 (0)