6
6
use Yoti \Entity \Profile ;
7
7
use Yoti \Entity \Attribute ;
8
8
use Yoti \Entity \AgeVerification ;
9
+ use Yoti \Entity \Anchor ;
10
+ use Yoti \Util \Profile \AnchorListConverter ;
11
+ use YotiTest \Util \Profile \TestAnchors ;
9
12
10
13
/**
11
14
* @coversDefaultClass \Yoti\Entity\Profile
@@ -15,22 +18,22 @@ class ProfileTest extends TestCase
15
18
/**
16
19
* @var \Yoti\Entity\Profile
17
20
*/
18
- public $ profile ;
21
+ private $ profile ;
19
22
20
23
/**
21
24
* @var \Yoti\YotiClient
22
25
*/
23
- public $ yotiClient ;
26
+ private $ yotiClient ;
24
27
25
28
/**
26
29
* @var string
27
30
*/
28
- public $ expectedPhoneNumber ;
31
+ private $ expectedPhoneNumber ;
29
32
30
33
/**
31
34
* @var Array Structured Postal Address
32
35
*/
33
- public $ dummyStructuredPostalAddress ;
36
+ private $ dummyStructuredPostalAddress ;
34
37
35
38
public function setup ()
36
39
{
@@ -93,28 +96,43 @@ public function testGetAttributeName()
93
96
*/
94
97
public function testShouldReturnFormattedAddressAsPostalAddressWhenNull ()
95
98
{
99
+ $ anchorsMap = AnchorListConverter::convert (new \ArrayObject ([
100
+ $ this ->parseAnchor (TestAnchors::VERIFIER_YOTI_ADMIN_ANCHOR ),
101
+ $ this ->parseAnchor (TestAnchors::UNKNOWN_ANCHOR ),
102
+ $ this ->parseAnchor (TestAnchors::SOURCE_DL_ANCHOR ),
103
+ ]));
104
+
96
105
$ structuredPostalAddress = new Attribute (
97
106
Profile::ATTR_STRUCTURED_POSTAL_ADDRESS ,
98
107
$ this ->dummyStructuredPostalAddress ,
99
- []
108
+ $ anchorsMap
100
109
);
101
- $ profileData = [
110
+
111
+ $ profile = new Profile ([
102
112
Profile::ATTR_STRUCTURED_POSTAL_ADDRESS => $ structuredPostalAddress ,
103
113
Profile::ATTR_GIVEN_NAMES => new Attribute (
104
114
Profile::ATTR_GIVEN_NAMES ,
105
115
'Given Name TEST ' ,
106
116
[]
107
117
),
108
- ];
109
- $ profile = new Profile ($ profileData );
110
- $ expectedPostalAddress = '15a North Street CARSHALTON SM5 2HW UK ' ;
111
-
118
+ ]);
112
119
$ this ->assertEquals ('Given Name TEST ' , $ profile ->getGivenNames ()->getValue ());
113
- $ this ->assertEquals ($ expectedPostalAddress , $ profile ->getPostalAddress ()->getValue ());
114
120
$ this ->assertEquals (
115
121
json_encode ($ this ->dummyStructuredPostalAddress ),
116
122
json_encode ($ profile ->getStructuredPostalAddress ()->getValue ())
117
123
);
124
+
125
+ $ postalAddress = $ profile ->getPostalAddress ();
126
+
127
+ $ this ->assertEquals ('15a North Street CARSHALTON SM5 2HW UK ' , $ postalAddress ->getValue ());
128
+ $ this ->assertEquals ($ anchorsMap [Anchor::TYPE_SOURCE_OID ], $ postalAddress ->getSources ());
129
+ $ this ->assertEquals ($ anchorsMap [Anchor::TYPE_VERIFIER_OID ], $ postalAddress ->getVerifiers ());
130
+
131
+ $ anchors = [];
132
+ array_walk ($ anchorsMap , function ($ val ) use (&$ anchors ) {
133
+ $ anchors = array_merge ($ anchors , array_values ($ val ));
134
+ });
135
+ $ this ->assertEquals ($ anchors , $ postalAddress ->getAnchors ());
118
136
}
119
137
120
138
/**
@@ -223,4 +241,16 @@ public function testGetDocumentImages()
223
241
$ profile = new Profile ($ profileData );
224
242
$ this ->assertSame ($ profileData ['document_images ' ], $ profile ->getDocumentImages ());
225
243
}
244
+
245
+ /**
246
+ * @param string $anchorString
247
+ *
248
+ * @return array $anchors
249
+ */
250
+ private function parseAnchor ($ anchorString )
251
+ {
252
+ $ anchor = new \Attrpubapi \Anchor ();
253
+ $ anchor ->mergeFromString (base64_decode ($ anchorString ));
254
+ return $ anchor ;
255
+ }
226
256
}
0 commit comments