Skip to content

Commit 118a791

Browse files
committed
Add some more tests
1 parent 1096efb commit 118a791

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

phpunit.xml.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Standard module phpunit configuration.
4+
Requires PHPUnit ^5.7
5+
-->
6+
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
7+
<testsuite name="Default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</phpunit>

src/AddressFinderField.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,27 @@ public function __construct($name, $title = null, $value = null)
9797
parent::__construct($name, $title, $value);
9898
}
9999

100+
/**
101+
* @param bool $bool
102+
*
103+
* @return $this
104+
*/
100105
public function setShowLatLngManual($bool)
101106
{
102107
$this->showLatLngManual = $bool;
103108

104109
return $this;
105110
}
106111

112+
/**
113+
* @param bool $bool
114+
*
115+
* @return $this
116+
*/
107117
public function setRequireLatLngManual($bool)
108118
{
109119
$this->requireLatLngManual = $bool;
120+
$this->showLatLngManual = true;
110121

111122
return $this;
112123
}
@@ -115,7 +126,7 @@ public function setRequireLatLngManual($bool)
115126
/**
116127
* @param bool $bool
117128
*
118-
* @return void
129+
* @return $this
119130
*/
120131
public function setReadonly($bool)
121132
{
@@ -131,6 +142,8 @@ public function setReadonly($bool)
131142
/**
132143
* @param string $message
133144
* @param string $messageType
145+
*
146+
* @return $this
134147
*/
135148
public function setError($message, $messageType)
136149
{
@@ -148,7 +161,7 @@ public function setError($message, $messageType)
148161
}
149162

150163
/**
151-
* @return void
164+
* @return $this
152165
*/
153166
public function performReadonlyTransformation()
154167
{
@@ -167,7 +180,9 @@ public function performReadonlyTransformation()
167180
}
168181

169182
/**
183+
* @param bool $bool
170184
*
185+
* @return $this
171186
*/
172187
public function setDisabled($bool)
173188
{
@@ -232,7 +247,7 @@ public function FieldHolder($properties = array())
232247
}
233248

234249
/**
235-
*
250+
* @return string
236251
*/
237252
public function getApiKey()
238253
{

tests/AddressFinderFieldTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace FullscreenInteractive\SilverStripe\Tests;
44

55
use SilverStripe\Dev\SapphireTest;
6+
use SilverStripe\Forms\RequiredFields;
67
use FullscreenInteractive\SilverStripe\AddressFinderField;
78

89
class AddressFinderFieldTest extends SapphireTest
@@ -11,7 +12,34 @@ public function testConstructor()
1112
{
1213
$field = new AddressFinderField('name', 'Title');
1314

14-
$this->assertEquals('Title', $field->getTitle());
15-
$this->assertEquals(6, $field->getManualFields()->count());
15+
$this->assertEquals('Title', $field->Title());
16+
$this->assertEquals(11, $field->getManualFields()->count(), '11 address fields');
17+
}
18+
19+
public function testSetRequireLatLngManual()
20+
{
21+
$field = new AddressFinderField('name', 'Title');
22+
$field = $field->setRequireLatLngManual(true);
23+
24+
$fieldHolder = $field->FieldHolder();
25+
26+
$this->assertContains('input type="text" name="name[Longitude]"', $fieldHolder);
27+
}
28+
29+
public function testValidator()
30+
{
31+
$field = new AddressFinderField('name', 'Title');
32+
$required = new RequiredFields('name');
33+
34+
$this->assertFalse($field->validate($required));
35+
36+
$field->setValue([
37+
'Address' => '1 Test Street, Test Land, 90210',
38+
'PostalLine1' => '1 Test Street',
39+
'City' => 'Test Land',
40+
'Postcode' => '90210'
41+
]);
42+
43+
$this->assertTrue($field->validate($required));
1644
}
1745
}

0 commit comments

Comments
 (0)