Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GraphQlReaderTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
23 class GraphQlReaderTest extends \PHPUnit\Framework\TestCase
24 {
26  private $configModel;
27 
29  private $graphQlController;
30 
32  private $objectManager;
33 
35  private $jsonSerializer;
36 
37  protected function setUp()
38  {
41  $cache = $this->objectManager->get(Cache::class);
42  $cache->clean();
43  $fileResolverMock = $this->getMockBuilder(
44  \Magento\Framework\Config\FileResolverInterface::class
45  )->disableOriginalConstructor()->getMock();
46  $fileList = [
47  file_get_contents(__DIR__ . '/../_files/schemaA.graphqls'),
48  file_get_contents(__DIR__ . '/../_files/schemaB.graphqls')
49  ];
50  $fileResolverMock->expects($this->any())->method('get')->will($this->returnValue($fileList));
51  $graphQlReader = $this->objectManager->create(
52  \Magento\Framework\GraphQlSchemaStitching\GraphQlReader::class,
53  ['fileResolver' => $fileResolverMock]
54  );
55  $reader = $this->objectManager->create(
56  \Magento\Framework\GraphQlSchemaStitching\Reader::class,
57  ['readers' => ['graphql_reader' => $graphQlReader]]
58  );
59  $data = $this->objectManager->create(
60  \Magento\Framework\GraphQl\Config\Data ::class,
61  ['reader' => $reader]
62  );
63  $this->configModel = $this->objectManager->create(
64  \Magento\Framework\GraphQl\Config::class,
65  ['data' => $data]
66  );
67  $outputMapper = $this->objectManager->create(
68  \Magento\Framework\GraphQl\Schema\Type\Output\OutputMapper::class,
69  ['config' => $this->configModel]
70  );
71  $schemaGenerator = $this->objectManager->create(
72  SchemaGenerator::class,
73  ['outputMapper' => $outputMapper]
74  );
75  $this->graphQlController = $this->objectManager->create(
76  GraphQl::class,
77  ['schemaGenerator' => $schemaGenerator]
78  );
79  $this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
80  }
81 
85  public function testDispatchIntrospectionWithCustomSDL()
86  {
87  $query
88  = <<<QUERY
89  query IntrospectionQuery {
90  __schema {
91  queryType { name }
92  types {
93  ...FullType
94  }
95  }
96 }
97 
98 fragment FullType on __Type {
99  kind
100  name
101  description
102  fields(includeDeprecated: true) {
103  name
104  description
105  args {
106  ...InputValue
107  }
108  type {
109  ...TypeRef
110  }
111  isDeprecated
112  deprecationReason
113  }
114  inputFields {
115  ...InputValue
116  }
117  interfaces {
118  ...TypeRef
119  }
120  enumValues(includeDeprecated: true) {
121  name
122  description
123  isDeprecated
124  }
125  possibleTypes {
126  ...TypeRef
127  }
128 }
129 
130 fragment InputValue on __InputValue {
131  name
132  description
133  type { ...TypeRef }
134  defaultValue
135 }
136 
137 fragment TypeRef on __Type {
138  kind
139  name
140  ofType {
141  kind
142  name
143  ofType {
144  kind
145  name
146  ofType {
147  kind
148  name
149  ofType {
150  kind
151  name
152  ofType {
153  kind
154  name
155  ofType {
156  kind
157  name
158  ofType {
159  kind
160  name
161  }
162  }
163  }
164  }
165  }
166  }
167  }
168 }
169 
170 
171 QUERY;
172  $postData = [
173  'query' => $query,
174  'variables' => null,
175  'operationName' => 'IntrospectionQuery'
176  ];
178  $request = $this->objectManager->get(\Magento\Framework\App\Request\Http::class);
179  $request->setPathInfo('/graphql');
180  $request->setContent(json_encode($postData));
181  $headers = $this->objectManager->create(\Zend\Http\Headers::class)
182  ->addHeaders(['Content-Type' => 'application/json']);
183  $request->setHeaders($headers);
184  $response = $this->graphQlController->dispatch($request);
185  $output = $this->jsonSerializer->unserialize($response->getContent());
186  $expectedOutput = require __DIR__ . '/../_files/schema_response_sdl_description.php';
187 
188  $schemaResponseFields = $output['data']['__schema']['types'];
189  $schemaResponseFieldsFirstHalf = array_slice($schemaResponseFields, 0, 25);
190  $schemaResponseFieldsSecondHalf = array_slice($schemaResponseFields, -21, 21);
191  $mergedSchemaResponseFields = array_merge($schemaResponseFieldsFirstHalf, $schemaResponseFieldsSecondHalf);
192 
193  foreach ($expectedOutput as $searchTerm) {
194  $this->assertTrue(
195  (in_array($searchTerm, $mergedSchemaResponseFields)),
196  'Missing type in the response'
197  );
198  }
199  //Checks to make sure that the given description exists in the expectedOutput array
200  $this->assertTrue(
201  array_key_exists(
202  array_search(
203  'Comment for empty PhysicalProductInterface',
204  array_column($expectedOutput, 'description')
205  ),
206  $expectedOutput
207  )
208  );
209  $this->assertTrue(
210  array_key_exists(
211  array_search(
212  'Comment for empty Enum',
213  array_column($expectedOutput, 'description')
214  ),
215  $expectedOutput
216  )
217  );
218  $this->assertTrue(
219  array_key_exists(
220  array_search(
221  'Comment for SearchResultPageInfo',
222  array_column($expectedOutput, 'description')
223  ),
224  $expectedOutput
225  )
226  );
227  }
228 }
$response
Definition: 404.php:11
$fileList
Definition: export.php:13
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
taxRateField this edit on("click.mselect-delete", ".mselect-delete", function() { if(!confirm('<?=/*@escapeNotVerified */__( 'Do you really want to delete this tax rate?') ?>')) { return;} var that=$(this), select=that.closest('.mselect-list').prev(), rateValue=that.parent().find( 'input[type="checkbox"]').val();$( 'body').trigger( 'processStart');var ajaxOptions={ type:'POST', data:{ tax_calculation_rate_id:rateValue, form_key:$( 'input[name="form_key"]').val() }, dataType:'json', url:'<?=/*@escapeNotVerified */$block->getTaxRateDeleteUrl() ?>', success:function(result, status) { $( 'body').trigger( 'processStop');if(result.success) { that.parent().remove();select.find( 'option').each(function() { if(this.value===rateValue) { $(this).remove();} });select.trigger( 'change.hiddenSelect');} else { if(result.error_message) alert({ content:result.error_message });else alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} }, error:function() { $( 'body').trigger( 'processStop');alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} };$.ajax(ajaxOptions);}) .on( 'click.mselectAdd'
Definition: edit.phtml:164