ThemeCustomizationsTest.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <?php
  2. namespace Webkul\BagistoApi\Tests\Feature\GraphQL;
  3. use Webkul\BagistoApi\Tests\GraphQLTestCase;
  4. /**
  5. * Theme Customizations GraphQL API Test Cases
  6. *
  7. * Organized by test categories:
  8. * - Get Theme Customizations Basic
  9. * - Get Theme Customizations - Filtered by Type
  10. * - Get Theme Customizations - Complete Details
  11. * - Single Theme Customization by ID
  12. */
  13. class ThemeCustomizationsTest extends GraphQLTestCase
  14. {
  15. /**
  16. * Test: Query theme customizations - Basic
  17. */
  18. public function test_theme_customizations_basic(): void
  19. {
  20. $query = <<<'GQL'
  21. query themeCustomizations($first: Int, $after: String) {
  22. themeCustomizations(first: $first, after: $after) {
  23. edges {
  24. node {
  25. id
  26. _id
  27. type
  28. name
  29. status
  30. themeCode
  31. sortOrder
  32. translation {
  33. locale
  34. options
  35. }
  36. }
  37. cursor
  38. }
  39. pageInfo {
  40. hasNextPage
  41. endCursor
  42. }
  43. totalCount
  44. }
  45. }
  46. GQL;
  47. $response = $this->graphQL($query, ['first' => 5]);
  48. $response->assertOk();
  49. $themeNode = $response->json('data.themeCustomizations.edges.0.node');
  50. expect($themeNode)->toHaveKeys([
  51. 'id',
  52. '_id',
  53. 'type',
  54. 'name',
  55. 'status',
  56. 'themeCode',
  57. 'sortOrder',
  58. 'translation',
  59. ]);
  60. expect($themeNode['translation'])->toHaveKeys([
  61. 'locale',
  62. 'options',
  63. ]);
  64. expect($response->json('data.themeCustomizations.edges.0.cursor'))->toBeString();
  65. $pageInfo = $response->json('data.themeCustomizations.pageInfo');
  66. expect($pageInfo)->toHaveKeys([
  67. 'hasNextPage',
  68. 'endCursor',
  69. ]);
  70. expect($response->json('data.themeCustomizations.totalCount'))->toBeInt();
  71. }
  72. /**
  73. * Test: Query theme customizations filtered by type
  74. */
  75. public function test_theme_customizations_filtered_by_type(): void
  76. {
  77. $query = <<<'GQL'
  78. query themeCustomizations($type: String) {
  79. themeCustomizations(type: $type) {
  80. edges {
  81. node {
  82. id
  83. _id
  84. type
  85. name
  86. status
  87. themeCode
  88. sortOrder
  89. translation {
  90. id
  91. _id
  92. themeCustomizationId
  93. locale
  94. options
  95. }
  96. translations {
  97. edges {
  98. node {
  99. id
  100. _id
  101. themeCustomizationId
  102. locale
  103. options
  104. }
  105. cursor
  106. }
  107. pageInfo {
  108. endCursor
  109. startCursor
  110. hasNextPage
  111. hasPreviousPage
  112. }
  113. totalCount
  114. }
  115. }
  116. cursor
  117. }
  118. pageInfo {
  119. endCursor
  120. startCursor
  121. hasNextPage
  122. hasPreviousPage
  123. }
  124. totalCount
  125. }
  126. }
  127. GQL;
  128. $response = $this->graphQL($query, ['type' => 'footer_links']);
  129. $response->assertOk();
  130. $themeNode = $response->json('data.themeCustomizations.edges.0.node');
  131. expect($themeNode)->toHaveKeys([
  132. 'id',
  133. '_id',
  134. 'type',
  135. 'name',
  136. 'status',
  137. 'themeCode',
  138. 'sortOrder',
  139. 'translation',
  140. 'translations',
  141. ]);
  142. expect($themeNode['translation'])->toHaveKeys([
  143. 'id',
  144. '_id',
  145. 'themeCustomizationId',
  146. 'locale',
  147. 'options',
  148. ]);
  149. $translationNode = $response->json('data.themeCustomizations.edges.0.node.translations.edges.0.node');
  150. expect($translationNode)->toHaveKeys([
  151. 'id',
  152. '_id',
  153. 'themeCustomizationId',
  154. 'locale',
  155. 'options',
  156. ]);
  157. $translationsPageInfo = $response->json('data.themeCustomizations.edges.0.node.translations.pageInfo');
  158. expect($translationsPageInfo)->toHaveKeys([
  159. 'endCursor',
  160. 'startCursor',
  161. 'hasNextPage',
  162. 'hasPreviousPage',
  163. ]);
  164. expect($response->json('data.themeCustomizations.edges.0.node.translations.totalCount'))->toBeInt();
  165. $pageInfo = $response->json('data.themeCustomizations.pageInfo');
  166. expect($pageInfo)->toHaveKeys([
  167. 'endCursor',
  168. 'startCursor',
  169. 'hasNextPage',
  170. 'hasPreviousPage',
  171. ]);
  172. expect($response->json('data.themeCustomizations.totalCount'))->toBeInt();
  173. }
  174. /**
  175. * Test: Query theme customizations with complete details
  176. */
  177. public function test_theme_customizations_complete_details(): void
  178. {
  179. $query = <<<'GQL'
  180. query themeCustomizations($first: Int, $after: String, $last: Int, $before: String, $type: String) {
  181. themeCustomizations(first: $first, after: $after, last: $last, before: $before, type: $type) {
  182. edges {
  183. node {
  184. id
  185. _id
  186. themeCode
  187. type
  188. name
  189. sortOrder
  190. status
  191. channelId
  192. createdAt
  193. updatedAt
  194. translation {
  195. id
  196. _id
  197. themeCustomizationId
  198. locale
  199. options
  200. }
  201. translations {
  202. edges {
  203. cursor
  204. node {
  205. id
  206. _id
  207. themeCustomizationId
  208. locale
  209. options
  210. }
  211. }
  212. pageInfo {
  213. endCursor
  214. startCursor
  215. hasNextPage
  216. hasPreviousPage
  217. }
  218. totalCount
  219. }
  220. }
  221. cursor
  222. }
  223. pageInfo {
  224. endCursor
  225. startCursor
  226. hasNextPage
  227. hasPreviousPage
  228. }
  229. totalCount
  230. }
  231. }
  232. GQL;
  233. $response = $this->graphQL($query, ['first' => 3]);
  234. $response->assertOk();
  235. $themeNode = $response->json('data.themeCustomizations.edges.0.node');
  236. expect($themeNode)->toHaveKeys([
  237. 'id',
  238. '_id',
  239. 'themeCode',
  240. 'type',
  241. 'name',
  242. 'sortOrder',
  243. 'status',
  244. 'channelId',
  245. 'createdAt',
  246. 'updatedAt',
  247. 'translation',
  248. 'translations',
  249. ]);
  250. expect($themeNode['translation'])->toHaveKeys([
  251. 'id',
  252. '_id',
  253. 'themeCustomizationId',
  254. 'locale',
  255. 'options',
  256. ]);
  257. $translationsNode = $response->json('data.themeCustomizations.edges.0.node.translations.edges.0.node');
  258. expect($translationsNode)->toHaveKeys([
  259. 'id',
  260. '_id',
  261. 'themeCustomizationId',
  262. 'locale',
  263. 'options',
  264. ]);
  265. expect($response->json('data.themeCustomizations.edges.0.node.translations.edges.0.cursor'))->toBeString();
  266. $translationsPageInfo = $response->json('data.themeCustomizations.edges.0.node.translations.pageInfo');
  267. expect($translationsPageInfo)->toHaveKeys([
  268. 'endCursor',
  269. 'startCursor',
  270. 'hasNextPage',
  271. 'hasPreviousPage',
  272. ]);
  273. expect($response->json('data.themeCustomizations.edges.0.node.translations.totalCount'))->toBeInt();
  274. expect($response->json('data.themeCustomizations.edges.0.cursor'))->toBeString();
  275. $pageInfo = $response->json('data.themeCustomizations.pageInfo');
  276. expect($pageInfo)->toHaveKeys([
  277. 'endCursor',
  278. 'startCursor',
  279. 'hasNextPage',
  280. 'hasPreviousPage',
  281. ]);
  282. expect($response->json('data.themeCustomizations.totalCount'))->toBeInt();
  283. }
  284. /**
  285. * Test: Query single theme customization by ID - Basic
  286. */
  287. public function test_get_theme_customization_by_id_basic(): void
  288. {
  289. $query = <<<'GQL'
  290. query getThemeCustomisation($id: ID!) {
  291. themeCustomization(id: $id) {
  292. id
  293. _id
  294. type
  295. name
  296. status
  297. themeCode
  298. translation {
  299. locale
  300. options
  301. }
  302. }
  303. }
  304. GQL;
  305. $response = $this->graphQL($query, ['id' => '/api/theme_customizations/1']);
  306. $response->assertOk();
  307. $theme = $response->json('data.themeCustomization');
  308. expect($theme)->toHaveKeys([
  309. 'id',
  310. '_id',
  311. 'type',
  312. 'name',
  313. 'status',
  314. 'themeCode',
  315. 'translation',
  316. ]);
  317. expect($theme['translation'])->toHaveKeys([
  318. 'locale',
  319. 'options',
  320. ]);
  321. }
  322. /**
  323. * Test: Query single theme customization by numeric ID
  324. */
  325. public function test_get_theme_customization_by_numeric_id(): void
  326. {
  327. $query = <<<'GQL'
  328. query getThemeCustomisation($id: ID!) {
  329. themeCustomization(id: $id) {
  330. id
  331. _id
  332. type
  333. name
  334. status
  335. themeCode
  336. sortOrder
  337. translation {
  338. locale
  339. options
  340. }
  341. }
  342. }
  343. GQL;
  344. $response = $this->graphQL($query, ['id' => '2']);
  345. $response->assertOk();
  346. $theme = $response->json('data.themeCustomization');
  347. expect($theme)->toHaveKeys([
  348. 'id',
  349. '_id',
  350. 'type',
  351. 'name',
  352. 'status',
  353. 'themeCode',
  354. 'sortOrder',
  355. 'translation',
  356. ]);
  357. expect($theme['translation'])->toHaveKeys([
  358. 'locale',
  359. 'options',
  360. ]);
  361. }
  362. /**
  363. * Test: Query single theme customization with complete details
  364. */
  365. public function test_get_theme_customization_complete_details(): void
  366. {
  367. $query = <<<'GQL'
  368. query getThemeCustomisation($id: ID!) {
  369. themeCustomization(id: $id) {
  370. id
  371. _id
  372. themeCode
  373. type
  374. name
  375. sortOrder
  376. status
  377. channelId
  378. createdAt
  379. updatedAt
  380. translation {
  381. id
  382. _id
  383. themeCustomizationId
  384. locale
  385. options
  386. }
  387. translations {
  388. edges {
  389. cursor
  390. node {
  391. id
  392. _id
  393. themeCustomizationId
  394. locale
  395. options
  396. }
  397. }
  398. pageInfo {
  399. endCursor
  400. startCursor
  401. hasNextPage
  402. hasPreviousPage
  403. }
  404. totalCount
  405. }
  406. }
  407. }
  408. GQL;
  409. $response = $this->graphQL($query, ['id' => '1']);
  410. $response->assertOk();
  411. $theme = $response->json('data.themeCustomization');
  412. expect($theme)->toHaveKeys([
  413. 'id',
  414. '_id',
  415. 'themeCode',
  416. 'type',
  417. 'name',
  418. 'sortOrder',
  419. 'status',
  420. 'channelId',
  421. 'createdAt',
  422. 'updatedAt',
  423. 'translation',
  424. 'translations',
  425. ]);
  426. expect($theme['translation'])->toHaveKeys([
  427. 'id',
  428. '_id',
  429. 'themeCustomizationId',
  430. 'locale',
  431. 'options',
  432. ]);
  433. $translationNode = $response->json('data.themeCustomization.translations.edges.0.node');
  434. expect($translationNode)->toHaveKeys([
  435. 'id',
  436. '_id',
  437. 'themeCustomizationId',
  438. 'locale',
  439. 'options',
  440. ]);
  441. expect($response->json('data.themeCustomization.translations.edges.0.cursor'))->toBeString();
  442. $pageInfo = $response->json('data.themeCustomization.translations.pageInfo');
  443. expect($pageInfo)->toHaveKeys([
  444. 'endCursor',
  445. 'startCursor',
  446. 'hasNextPage',
  447. 'hasPreviousPage',
  448. ]);
  449. expect($response->json('data.themeCustomization.translations.totalCount'))->toBeInt();
  450. }
  451. }