AttributeTest.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <?php
  2. namespace Webkul\BagistoApi\Tests\Feature\GraphQL;
  3. use Webkul\BagistoApi\Tests\GraphQLTestCase;
  4. class AttributeTest extends GraphQLTestCase
  5. {
  6. /**
  7. * Get Attributes - Basic
  8. */
  9. public function test_get_all_attributes_basic(): void
  10. {
  11. $query = <<<'GQL'
  12. query getAllAttributes($first: Int, $after: String) {
  13. attributes(first: $first, after: $after) {
  14. edges {
  15. node {
  16. id
  17. _id
  18. code
  19. adminName
  20. type
  21. swatchType
  22. position
  23. isRequired
  24. isConfigurable
  25. options {
  26. edges {
  27. node {
  28. id
  29. adminName
  30. swatchValue
  31. }
  32. }
  33. totalCount
  34. }
  35. }
  36. cursor
  37. }
  38. pageInfo {
  39. endCursor
  40. hasNextPage
  41. }
  42. totalCount
  43. }
  44. }
  45. GQL;
  46. $response = $this->graphQL($query, ['first' => 10]);
  47. $response->assertSuccessful();
  48. $data = $response->json('data.attributes');
  49. $this->assertNotNull($data, 'attributes response is null');
  50. $this->assertIsArray($data['edges'] ?? [], 'attributes.edges is not an array');
  51. $this->assertArrayHasKey('pageInfo', $data);
  52. $this->assertArrayHasKey('totalCount', $data);
  53. // Ensure at least one attribute is returned
  54. $this->assertGreaterThanOrEqual(0, $data['totalCount']);
  55. if (! empty($data['edges'])) {
  56. $first = $data['edges'][0]['node'] ?? null;
  57. $this->assertNotNull($first, 'first edge.node is null');
  58. $this->assertArrayHasKey('id', $first);
  59. $this->assertArrayHasKey('_id', $first);
  60. $this->assertArrayHasKey('code', $first);
  61. $this->assertArrayHasKey('adminName', $first);
  62. $this->assertArrayHasKey('type', $first);
  63. $this->assertArrayHasKey('options', $first);
  64. $this->assertIsArray($first['options']['edges'] ?? []);
  65. $this->assertArrayHasKey('totalCount', $first['options']);
  66. }
  67. }
  68. /**
  69. * Get Attribute - Basic
  70. */
  71. public function test_get_attribute_by_id_basic(): void
  72. {
  73. $query = <<<'GQL'
  74. query getAttributeByID($id: ID!){
  75. attribute(id: $id) {
  76. id
  77. _id
  78. code
  79. adminName
  80. type
  81. swatchType
  82. validation
  83. regex
  84. position
  85. isRequired
  86. isUnique
  87. isFilterable
  88. isComparable
  89. isConfigurable
  90. isUserDefined
  91. isVisibleOnFront
  92. valuePerLocale
  93. valuePerChannel
  94. defaultValue
  95. enableWysiwyg
  96. createdAt
  97. updatedAt
  98. columnName
  99. validations
  100. }
  101. }
  102. GQL;
  103. $variables = ['id' => '/api/shop/attributes/23'];
  104. $response = $this->graphQL($query, $variables);
  105. $response->assertSuccessful();
  106. $node = $response->json('data.attribute');
  107. $this->assertNotNull($node, 'attribute response is null');
  108. $this->assertArrayHasKey('id', $node);
  109. $this->assertArrayHasKey('_id', $node);
  110. $this->assertArrayHasKey('code', $node);
  111. $this->assertArrayHasKey('adminName', $node);
  112. $this->assertArrayHasKey('type', $node);
  113. $this->assertArrayHasKey('createdAt', $node);
  114. $this->assertArrayHasKey('updatedAt', $node);
  115. }
  116. /**
  117. * Get Attributes with full Options and Translations
  118. */
  119. public function test_get_all_attributes_with_full_options_and_translations(): void
  120. {
  121. $query = <<<'GQL'
  122. query getAllAttributes($first: Int) {
  123. attributes(first: $first) {
  124. edges {
  125. node {
  126. id
  127. _id
  128. code
  129. adminName
  130. type
  131. swatchType
  132. validation
  133. regex
  134. position
  135. isRequired
  136. isUnique
  137. isFilterable
  138. isComparable
  139. isConfigurable
  140. isUserDefined
  141. isVisibleOnFront
  142. valuePerLocale
  143. valuePerChannel
  144. defaultValue
  145. enableWysiwyg
  146. createdAt
  147. updatedAt
  148. columnName
  149. validations
  150. options {
  151. edges {
  152. node {
  153. id
  154. _id
  155. adminName
  156. sortOrder
  157. swatchValue
  158. swatchValueUrl
  159. translation {
  160. id
  161. _id
  162. attributeOptionId
  163. locale
  164. label
  165. }
  166. translations {
  167. edges {
  168. node {
  169. id
  170. _id
  171. attributeOptionId
  172. locale
  173. label
  174. }
  175. }
  176. pageInfo {
  177. endCursor
  178. hasNextPage
  179. }
  180. totalCount
  181. }
  182. }
  183. cursor
  184. }
  185. pageInfo {
  186. endCursor
  187. hasNextPage
  188. }
  189. totalCount
  190. }
  191. translations {
  192. edges {
  193. node {
  194. id
  195. _id
  196. attributeId
  197. locale
  198. name
  199. }
  200. }
  201. pageInfo {
  202. endCursor
  203. hasNextPage
  204. }
  205. totalCount
  206. }
  207. }
  208. cursor
  209. }
  210. pageInfo {
  211. endCursor
  212. startCursor
  213. hasNextPage
  214. hasPreviousPage
  215. }
  216. totalCount
  217. }
  218. }
  219. GQL;
  220. $response = $this->graphQL($query, ['first' => 5]);
  221. $response->assertSuccessful();
  222. $data = $response->json('data.attributes');
  223. $this->assertNotNull($data, 'attributes response is null');
  224. $this->assertIsArray($data['edges'] ?? [], 'attributes.edges is not an array');
  225. $this->assertArrayHasKey('pageInfo', $data);
  226. $this->assertArrayHasKey('totalCount', $data);
  227. // pageInfo expected keys
  228. $this->assertArrayHasKey('endCursor', $data['pageInfo']);
  229. $this->assertArrayHasKey('startCursor', $data['pageInfo']);
  230. $this->assertArrayHasKey('hasNextPage', $data['pageInfo']);
  231. $this->assertArrayHasKey('hasPreviousPage', $data['pageInfo']);
  232. if (! empty($data['edges'])) {
  233. foreach ($data['edges'] as $edge) {
  234. $node = $edge['node'] ?? null;
  235. $this->assertNotNull($node, 'edge.node is null');
  236. $this->assertArrayHasKey('id', $node);
  237. $this->assertArrayHasKey('_id', $node);
  238. $this->assertArrayHasKey('code', $node);
  239. $this->assertArrayHasKey('adminName', $node);
  240. $this->assertArrayHasKey('type', $node);
  241. $this->assertArrayHasKey('options', $node);
  242. // options structure
  243. $this->assertIsArray($node['options']['edges'] ?? []);
  244. $this->assertArrayHasKey('totalCount', $node['options']);
  245. foreach ($node['options']['edges'] ?? [] as $optEdge) {
  246. $opt = $optEdge['node'] ?? null;
  247. $this->assertNotNull($opt, 'option edge.node is null');
  248. $this->assertArrayHasKey('id', $opt);
  249. $this->assertArrayHasKey('_id', $opt);
  250. $this->assertArrayHasKey('adminName', $opt);
  251. // translation and translations
  252. $this->assertArrayHasKey('translation', $opt);
  253. $this->assertArrayHasKey('translations', $opt);
  254. $this->assertIsArray($opt['translations']['edges'] ?? []);
  255. $this->assertArrayHasKey('pageInfo', $opt['translations']);
  256. $this->assertArrayHasKey('totalCount', $opt['translations']);
  257. }
  258. // attribute translations
  259. $this->assertIsArray($node['translations']['edges'] ?? []);
  260. $this->assertArrayHasKey('pageInfo', $node['translations']);
  261. $this->assertArrayHasKey('totalCount', $node['translations']);
  262. }
  263. }
  264. }
  265. /**
  266. * Get Attribute with Full Details
  267. */
  268. public function test_get_attribute_by_id_full_details(): void
  269. {
  270. $query = <<<'GQL'
  271. query getAttributeByID($id: ID!){
  272. attribute(id: $id) {
  273. id
  274. _id
  275. code
  276. adminName
  277. type
  278. swatchType
  279. validation
  280. regex
  281. position
  282. isRequired
  283. isUnique
  284. isFilterable
  285. isComparable
  286. isConfigurable
  287. isUserDefined
  288. isVisibleOnFront
  289. valuePerLocale
  290. valuePerChannel
  291. defaultValue
  292. enableWysiwyg
  293. createdAt
  294. updatedAt
  295. columnName
  296. validations
  297. options {
  298. edges {
  299. node {
  300. id
  301. _id
  302. adminName
  303. sortOrder
  304. swatchValue
  305. swatchValueUrl
  306. translation {
  307. id
  308. _id
  309. attributeOptionId
  310. locale
  311. label
  312. }
  313. translations {
  314. edges {
  315. node {
  316. id
  317. _id
  318. attributeOptionId
  319. locale
  320. label
  321. }
  322. }
  323. pageInfo {
  324. endCursor
  325. startCursor
  326. hasNextPage
  327. hasPreviousPage
  328. }
  329. totalCount
  330. }
  331. }
  332. cursor
  333. }
  334. pageInfo {
  335. endCursor
  336. startCursor
  337. hasNextPage
  338. hasPreviousPage
  339. }
  340. totalCount
  341. }
  342. translations {
  343. edges {
  344. node {
  345. id
  346. _id
  347. attributeId
  348. locale
  349. name
  350. }
  351. cursor
  352. }
  353. pageInfo {
  354. endCursor
  355. startCursor
  356. hasNextPage
  357. hasPreviousPage
  358. }
  359. totalCount
  360. }
  361. }
  362. }
  363. GQL;
  364. $variables = ['id' => '/api/shop/attributes/23'];
  365. $response = $this->graphQL($query, $variables);
  366. $response->assertSuccessful();
  367. $node = $response->json('data.attribute');
  368. $this->assertNotNull($node, 'attribute response is null');
  369. $this->assertArrayHasKey('options', $node);
  370. $this->assertArrayHasKey('translations', $node);
  371. // options structure
  372. $this->assertIsArray($node['options']['edges'] ?? []);
  373. $this->assertArrayHasKey('pageInfo', $node['options']);
  374. $this->assertArrayHasKey('totalCount', $node['options']);
  375. foreach ($node['options']['edges'] ?? [] as $optEdge) {
  376. $opt = $optEdge['node'] ?? null;
  377. $this->assertNotNull($opt);
  378. $this->assertArrayHasKey('translation', $opt);
  379. $this->assertArrayHasKey('translations', $opt);
  380. $this->assertArrayHasKey('pageInfo', $opt['translations']);
  381. }
  382. // translations structure
  383. $this->assertIsArray($node['translations']['edges'] ?? []);
  384. $this->assertArrayHasKey('pageInfo', $node['translations']);
  385. $this->assertArrayHasKey('totalCount', $node['translations']);
  386. }
  387. /**
  388. * Get Attribute Options - Basic
  389. */
  390. public function test_get_attribute_options_basic(): void
  391. {
  392. $query = <<<'GQL'
  393. query getAttributeOptions($first: Int) {
  394. attributeOptions(first: $first) {
  395. edges {
  396. node {
  397. id
  398. _id
  399. adminName
  400. sortOrder
  401. swatchValue
  402. }
  403. }
  404. pageInfo {
  405. hasNextPage
  406. endCursor
  407. }
  408. }
  409. }
  410. GQL;
  411. $response = $this->graphQL($query, ['first' => 10]);
  412. $response->assertSuccessful();
  413. $data = $response->json('data.attributeOptions');
  414. $this->assertNotNull($data, 'attributeOptions response is null');
  415. $this->assertIsArray($data['edges'] ?? [], 'attributeOptions.edges is not an array');
  416. $this->assertArrayHasKey('pageInfo', $data);
  417. $this->assertArrayHasKey('hasNextPage', $data['pageInfo']);
  418. $this->assertArrayHasKey('endCursor', $data['pageInfo']);
  419. if (! empty($data['edges'])) {
  420. $first = $data['edges'][0]['node'] ?? null;
  421. $this->assertNotNull($first, 'first option node is null');
  422. $this->assertArrayHasKey('id', $first);
  423. $this->assertArrayHasKey('_id', $first);
  424. $this->assertArrayHasKey('adminName', $first);
  425. $this->assertArrayHasKey('sortOrder', $first);
  426. $this->assertArrayHasKey('swatchValue', $first);
  427. }
  428. }
  429. /**
  430. * Get Attribute Options with Translations
  431. */
  432. public function test_get_attribute_options_with_translations_basic(): void
  433. {
  434. $query = <<<'GQL'
  435. query getAttributeOptionsWithTranslations($first: Int) {
  436. attributeOptions(first: $first) {
  437. edges {
  438. node {
  439. id
  440. adminName
  441. sortOrder
  442. translations(first: 10) {
  443. edges {
  444. node {
  445. locale
  446. label
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. GQL;
  455. $response = $this->graphQL($query, ['first' => 5]);
  456. $response->assertSuccessful();
  457. $data = $response->json('data.attributeOptions');
  458. $this->assertNotNull($data, 'attributeOptions response is null');
  459. $this->assertIsArray($data['edges'] ?? [], 'attributeOptions.edges is not an array');
  460. if (! empty($data['edges'])) {
  461. $first = $data['edges'][0]['node'] ?? null;
  462. $this->assertNotNull($first, 'first option node is null');
  463. $this->assertArrayHasKey('id', $first);
  464. $this->assertArrayHasKey('adminName', $first);
  465. $this->assertArrayHasKey('sortOrder', $first);
  466. $this->assertArrayHasKey('translations', $first);
  467. $this->assertIsArray($first['translations']['edges'] ?? []);
  468. $transFirst = $first['translations']['edges'][0]['node'] ?? null;
  469. if ($transFirst) {
  470. $this->assertArrayHasKey('locale', $transFirst);
  471. $this->assertArrayHasKey('label', $transFirst);
  472. }
  473. }
  474. }
  475. /**
  476. * Get Attribute Options with Swatches
  477. */
  478. public function test_get_attribute_options_with_swatches_basic(): void
  479. {
  480. $query = <<<'GQL'
  481. query getSwatchOptions($first: Int) {
  482. attributeOptions(first: $first) {
  483. edges {
  484. node {
  485. id
  486. adminName
  487. swatchValue
  488. swatchValueUrl
  489. translation {
  490. locale
  491. label
  492. }
  493. }
  494. }
  495. }
  496. }
  497. GQL;
  498. $response = $this->graphQL($query, ['first' => 20]);
  499. $response->assertSuccessful();
  500. $data = $response->json('data.attributeOptions');
  501. $this->assertNotNull($data, 'attributeOptions response is null');
  502. $this->assertIsArray($data['edges'] ?? [], 'attributeOptions.edges is not an array');
  503. if (! empty($data['edges'])) {
  504. foreach ($data['edges'] as $edge) {
  505. $node = $edge['node'] ?? null;
  506. $this->assertNotNull($node, 'option node is null');
  507. $this->assertArrayHasKey('id', $node);
  508. $this->assertArrayHasKey('adminName', $node);
  509. $this->assertArrayHasKey('swatchValue', $node);
  510. $this->assertArrayHasKey('swatchValueUrl', $node);
  511. $this->assertArrayHasKey('translation', $node);
  512. $trans = $node['translation'] ?? null;
  513. if ($trans) {
  514. $this->assertArrayHasKey('locale', $trans);
  515. $this->assertArrayHasKey('label', $trans);
  516. }
  517. }
  518. }
  519. }
  520. /**
  521. * Get Single Attribute Option Detail By Option ID
  522. */
  523. public function test_get_single_attribute_option_by_id_basic(): void
  524. {
  525. $query = <<<'GQL'
  526. query getAttributeOptionByID ($id: ID!) {
  527. attributeOption (id: $id) {
  528. id
  529. _id
  530. adminName
  531. sortOrder
  532. swatchValue
  533. swatchValueUrl
  534. translation {
  535. id
  536. _id
  537. attributeOptionId
  538. locale
  539. label
  540. }
  541. translations {
  542. edges {
  543. node {
  544. id
  545. _id
  546. attributeOptionId
  547. locale
  548. label
  549. }
  550. }
  551. pageInfo {
  552. endCursor
  553. startCursor
  554. hasNextPage
  555. hasPreviousPage
  556. }
  557. totalCount
  558. }
  559. }
  560. }
  561. GQL;
  562. $variables = ['id' => '/api/admin/attribute_options/1'];
  563. $response = $this->graphQL($query, $variables);
  564. $response->assertSuccessful();
  565. $node = $response->json('data.attributeOption');
  566. $this->assertNotNull($node, 'attributeOption response is null');
  567. $this->assertArrayHasKey('id', $node);
  568. $this->assertArrayHasKey('_id', $node);
  569. $this->assertArrayHasKey('adminName', $node);
  570. $this->assertArrayHasKey('sortOrder', $node);
  571. $this->assertArrayHasKey('swatchValue', $node);
  572. $this->assertArrayHasKey('swatchValueUrl', $node);
  573. $this->assertArrayHasKey('translation', $node);
  574. $this->assertArrayHasKey('translations', $node);
  575. $this->assertIsArray($node['translations']['edges'] ?? []);
  576. $this->assertArrayHasKey('pageInfo', $node['translations']);
  577. $this->assertArrayHasKey('totalCount', $node['translations']);
  578. $this->assertArrayHasKey('endCursor', $node['translations']['pageInfo']);
  579. $this->assertArrayHasKey('startCursor', $node['translations']['pageInfo']);
  580. $this->assertArrayHasKey('hasNextPage', $node['translations']['pageInfo']);
  581. $this->assertArrayHasKey('hasPreviousPage', $node['translations']['pageInfo']);
  582. }
  583. /**
  584. * Get Attribute Options - Pagination
  585. */
  586. public function test_get_attribute_options_pagination_basic(): void
  587. {
  588. $query = <<<'GQL'
  589. query getAttributeOptionsPaginated(
  590. $first: Int
  591. $after: String
  592. ) {
  593. attributeOptions(
  594. first: $first
  595. after: $after
  596. ) {
  597. edges {
  598. node {
  599. id
  600. adminName
  601. sortOrder
  602. }
  603. cursor
  604. }
  605. pageInfo {
  606. hasNextPage
  607. endCursor
  608. hasPreviousPage
  609. startCursor
  610. }
  611. }
  612. }
  613. GQL;
  614. $variables = ['first' => 10, 'after' => null];
  615. $response = $this->graphQL($query, $variables);
  616. $response->assertSuccessful();
  617. $data = $response->json('data.attributeOptions');
  618. $this->assertNotNull($data, 'attributeOptions response is null');
  619. $this->assertIsArray($data['edges'] ?? [], 'attributeOptions.edges is not an array');
  620. $this->assertArrayHasKey('pageInfo', $data);
  621. $this->assertArrayHasKey('hasNextPage', $data['pageInfo']);
  622. $this->assertArrayHasKey('endCursor', $data['pageInfo']);
  623. $this->assertArrayHasKey('hasPreviousPage', $data['pageInfo']);
  624. $this->assertArrayHasKey('startCursor', $data['pageInfo']);
  625. if (! empty($data['edges'])) {
  626. $firstEdge = $data['edges'][0] ?? null;
  627. $this->assertNotNull($firstEdge, 'first edge is null');
  628. $this->assertArrayHasKey('node', $firstEdge);
  629. $this->assertArrayHasKey('cursor', $firstEdge);
  630. $node = $firstEdge['node'] ?? null;
  631. $this->assertNotNull($node, 'edge.node is null');
  632. $this->assertArrayHasKey('id', $node);
  633. $this->assertArrayHasKey('adminName', $node);
  634. $this->assertArrayHasKey('sortOrder', $node);
  635. }
  636. }
  637. /**
  638. * Get Attribute Options with Attribute
  639. */
  640. public function test_get_attribute_with_options_basic(): void
  641. {
  642. $query = <<<'GQL'
  643. query getAttribute($id: ID!, $first: Int) {
  644. attribute(id: $id) {
  645. id
  646. code
  647. adminName
  648. options(first: $first) {
  649. edges {
  650. node {
  651. id
  652. adminName
  653. sortOrder
  654. swatchValue
  655. translation {
  656. locale
  657. label
  658. }
  659. }
  660. cursor
  661. }
  662. pageInfo {
  663. hasNextPage
  664. endCursor
  665. }
  666. }
  667. }
  668. }
  669. GQL;
  670. $variables = ['id' => '/api/shop/attributes/23', 'first' => 10];
  671. $response = $this->graphQL($query, $variables);
  672. $response->assertSuccessful();
  673. $data = $response->json('data.attribute');
  674. $this->assertNotNull($data, 'attribute response is null');
  675. $this->assertArrayHasKey('id', $data);
  676. $this->assertArrayHasKey('code', $data);
  677. $this->assertArrayHasKey('adminName', $data);
  678. $this->assertArrayHasKey('options', $data);
  679. $this->assertIsArray($data['options']['edges'] ?? [], 'attribute.options.edges is not an array');
  680. $this->assertArrayHasKey('pageInfo', $data['options']);
  681. $this->assertArrayHasKey('hasNextPage', $data['options']['pageInfo']);
  682. $this->assertArrayHasKey('endCursor', $data['options']['pageInfo']);
  683. if (! empty($data['options']['edges'])) {
  684. $firstEdge = $data['options']['edges'][0] ?? null;
  685. $this->assertNotNull($firstEdge, 'first attribute option edge is null');
  686. $this->assertArrayHasKey('node', $firstEdge);
  687. $this->assertArrayHasKey('cursor', $firstEdge);
  688. $node = $firstEdge['node'] ?? null;
  689. $this->assertNotNull($node, 'option node is null');
  690. $this->assertArrayHasKey('id', $node);
  691. $this->assertArrayHasKey('adminName', $node);
  692. $this->assertArrayHasKey('sortOrder', $node);
  693. $this->assertArrayHasKey('swatchValue', $node);
  694. $this->assertArrayHasKey('translation', $node);
  695. $trans = $node['translation'] ?? null;
  696. if ($trans) {
  697. $this->assertArrayHasKey('locale', $trans);
  698. $this->assertArrayHasKey('label', $trans);
  699. }
  700. }
  701. }
  702. /**
  703. * Get Color Options for Display
  704. */
  705. public function test_get_color_options_for_display(): void
  706. {
  707. $query = <<<'GQL'
  708. query getColorOptions {
  709. attributeOptions(first: 50) {
  710. edges {
  711. node {
  712. adminName
  713. swatchValue
  714. translation {
  715. label
  716. }
  717. }
  718. }
  719. }
  720. }
  721. GQL;
  722. $response = $this->graphQL($query);
  723. $response->assertSuccessful();
  724. $data = $response->json('data.attributeOptions');
  725. $this->assertNotNull($data, 'attributeOptions response is null');
  726. $this->assertIsArray($data['edges'] ?? [], 'attributeOptions.edges is not an array');
  727. if (! empty($data['edges'])) {
  728. foreach ($data['edges'] as $edge) {
  729. $node = $edge['node'] ?? null;
  730. $this->assertNotNull($node, 'option node is null');
  731. $this->assertArrayHasKey('adminName', $node);
  732. $this->assertArrayHasKey('swatchValue', $node);
  733. $this->assertArrayHasKey('translation', $node);
  734. $trans = $node['translation'] ?? null;
  735. if ($trans) {
  736. $this->assertArrayHasKey('label', $trans);
  737. }
  738. }
  739. }
  740. }
  741. }