14
14
*/
15
15
class CountryTest extends GraphQlAbstract
16
16
{
17
- public function testGetCountry ()
17
+ /**
18
+ * Test stores set up:
19
+ * STORE - WEBSITE - STORE GROUP
20
+ * default - base - main_website_store
21
+ * test - base - main_website_store
22
+ *
23
+ * @magentoApiDataFixture Magento/Store/_files/store.php
24
+ * @magentoConfigFixture default/general/locale/code en_US
25
+ * @magentoConfigFixture default/general/country/allow US
26
+ * @magentoConfigFixture test_store general/locale/code en_US
27
+ * @magentoConfigFixture test_store general/country/allow US,DE
28
+ */
29
+ public function testGetDefaultStoreUSCountry ()
18
30
{
19
- $ query = <<<QUERY
20
- query {
21
- country(id: "US") {
22
- id
23
- two_letter_abbreviation
24
- three_letter_abbreviation
25
- full_name_locale
26
- full_name_english
27
- available_regions {
28
- id
29
- code
30
- name
31
- }
31
+ $ result = $ this ->graphQlQuery ($ this ->getQuery ('US ' ));
32
+ $ this ->assertArrayHasKey ('country ' , $ result );
33
+ $ this ->assertEquals ('US ' , $ result ['country ' ]['id ' ]);
34
+ $ this ->assertEquals ('US ' , $ result ['country ' ]['two_letter_abbreviation ' ]);
35
+ $ this ->assertEquals ('USA ' , $ result ['country ' ]['three_letter_abbreviation ' ]);
36
+ $ this ->assertEquals ('United States ' , $ result ['country ' ]['full_name_locale ' ]);
37
+ $ this ->assertEquals ('United States ' , $ result ['country ' ]['full_name_english ' ]);
38
+ $ this ->assertCount (65 , $ result ['country ' ]['available_regions ' ]);
39
+ $ this ->assertArrayHasKey ('id ' , $ result ['country ' ]['available_regions ' ][0 ]);
40
+ $ this ->assertArrayHasKey ('code ' , $ result ['country ' ]['available_regions ' ][0 ]);
41
+ $ this ->assertArrayHasKey ('name ' , $ result ['country ' ]['available_regions ' ][0 ]);
32
42
}
33
- }
34
- QUERY ;
35
43
36
- $ result = $ this ->graphQlQuery ($ query );
44
+ /**
45
+ * Test stores set up:
46
+ * STORE - WEBSITE - STORE GROUP
47
+ * default - base - main_website_store
48
+ * test - base - main_website_store
49
+ *
50
+ * @magentoApiDataFixture Magento/Store/_files/store.php
51
+ * @magentoConfigFixture default/general/locale/code en_US
52
+ * @magentoConfigFixture default/general/country/allow US
53
+ * @magentoConfigFixture test_store general/locale/code en_US
54
+ * @magentoConfigFixture test_store general/country/allow US,DE
55
+ */
56
+ public function testGetTestStoreDECountry ()
57
+ {
58
+ $ result = $ this ->graphQlQuery (
59
+ $ this ->getQuery ('DE ' ),
60
+ [],
61
+ '' ,
62
+ ['Store ' => 'test ' ]
63
+ );
37
64
$ this ->assertArrayHasKey ('country ' , $ result );
38
- $ this ->assertArrayHasKey ( ' id ' , $ result ['country ' ]);
39
- $ this ->assertArrayHasKey ( ' two_letter_abbreviation ' , $ result ['country ' ]);
40
- $ this ->assertArrayHasKey ( ' three_letter_abbreviation ' , $ result ['country ' ]);
41
- $ this ->assertArrayHasKey ( ' full_name_locale ' , $ result ['country ' ]);
42
- $ this ->assertArrayHasKey ( ' full_name_english ' , $ result ['country ' ]);
43
- $ this ->assertArrayHasKey ( ' available_regions ' , $ result ['country ' ]);
65
+ $ this ->assertEquals ( ' DE ' , $ result ['country ' ][ ' id ' ]);
66
+ $ this ->assertEquals ( ' DE ' , $ result ['country ' ][ ' two_letter_abbreviation ' ]);
67
+ $ this ->assertEquals ( ' DEU ' , $ result ['country ' ][ ' three_letter_abbreviation ' ]);
68
+ $ this ->assertEquals ( ' Germany ' , $ result ['country ' ][ ' full_name_locale ' ]);
69
+ $ this ->assertEquals ( ' Germany ' , $ result ['country ' ][ ' full_name_english ' ]);
70
+ $ this ->assertCount ( 16 , $ result ['country ' ][ ' available_regions ' ]);
44
71
$ this ->assertArrayHasKey ('id ' , $ result ['country ' ]['available_regions ' ][0 ]);
45
72
$ this ->assertArrayHasKey ('code ' , $ result ['country ' ]['available_regions ' ][0 ]);
46
73
$ this ->assertArrayHasKey ('name ' , $ result ['country ' ]['available_regions ' ][0 ]);
47
74
}
48
75
49
76
/**
77
+ * Test stores set up:
78
+ * STORE - WEBSITE - STORE GROUP
79
+ * default - base - main_website_store
80
+ * test - base - main_website_store
81
+ *
82
+ * @magentoApiDataFixture Magento/Store/_files/store.php
83
+ * @magentoConfigFixture default/general/locale/code en_US
84
+ * @magentoConfigFixture default/general/country/allow US
85
+ * @magentoConfigFixture test_store general/locale/code en_US
86
+ * @magentoConfigFixture test_store general/country/allow US,DE
50
87
*/
51
- public function testGetCountryNotFoundException ()
88
+ public function testGetDefaultStoreDECountryNotFoundException ()
52
89
{
53
90
$ this ->expectException (\Exception::class);
54
91
$ this ->expectExceptionMessage ('GraphQL response contains errors: The country isn \'t available. ' );
55
92
56
- $ query = <<<QUERY
57
- query {
58
- country(id: "BLAH") {
59
- id
60
- two_letter_abbreviation
61
- three_letter_abbreviation
62
- full_name_locale
63
- full_name_english
64
- available_regions {
65
- id
66
- code
67
- name
68
- }
93
+ $ this ->graphQlQuery ($ this ->getQuery ('DE ' ));
69
94
}
70
- }
71
- QUERY ;
72
95
73
- $ this ->graphQlQuery ($ query );
74
- }
75
-
76
- /**
77
- */
78
96
public function testMissedInputParameterException ()
79
97
{
80
98
$ this ->expectException (\Exception::class);
@@ -94,4 +112,30 @@ public function testMissedInputParameterException()
94
112
95
113
$ this ->graphQlQuery ($ query );
96
114
}
115
+
116
+ /**
117
+ * Get query
118
+ *
119
+ * @param string $countryId
120
+ * @return string
121
+ */
122
+ private function getQuery (string $ countryId ): string
123
+ {
124
+ return <<<QUERY
125
+ query {
126
+ country(id: {$ countryId }) {
127
+ id
128
+ two_letter_abbreviation
129
+ three_letter_abbreviation
130
+ full_name_locale
131
+ full_name_english
132
+ available_regions {
133
+ id
134
+ code
135
+ name
136
+ }
137
+ }
138
+ }
139
+ QUERY ;
140
+ }
97
141
}
0 commit comments