Skip to content

Commit d7b7a2e

Browse files
committed
GraphQl-387: Test coverage of getting IDs of CMS page/blocks by GraphQL API
1 parent 4ee64a5 commit d7b7a2e

File tree

2 files changed

+8
-73
lines changed

2 files changed

+8
-73
lines changed

app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Page.php

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,6 @@ public function __construct(
5858
$this->storeManager = $storeManager;
5959
}
6060

61-
/**
62-
* @deprecated
63-
* @see getDataByPageId(int $pageId)
64-
*
65-
* Get the page data
66-
*
67-
* @param int $pageId
68-
* @return array
69-
* @throws NoSuchEntityException
70-
*/
71-
public function getData(int $pageId): array
72-
{
73-
$page = $this->pageRepository->getById($pageId);
74-
75-
return $this->convertPageData($page);
76-
}
77-
7861
/**
7962
* Returns page data by page_id
8063
*
@@ -86,7 +69,7 @@ public function getDataByPageId(int $pageId): array
8669
{
8770
$page = $this->pageRepository->getById($pageId);
8871

89-
return $this->convertPageData($page, false, true);
72+
return $this->convertPageData($page);
9073
}
9174

9275
/**
@@ -101,17 +84,15 @@ public function getDataByPageIdentifier(string $pageIdentifier): array
10184
$storeId = (int)$this->storeManager->getStore()->getId();
10285
$page = $this->pageByIdentifier->execute($pageIdentifier, $storeId);
10386

104-
return $this->convertPageData($page, false, true);
87+
return $this->convertPageData($page);
10588
}
10689

10790
/**
10891
* @param PageInterface $page
109-
* @param bool $includePageId
110-
* @param bool $includePageIdentifier
11192
* @return array
11293
* @throws NoSuchEntityException
11394
*/
114-
private function convertPageData(PageInterface $page, $includePageId = true, $includePageIdentifier = false)
95+
private function convertPageData(PageInterface $page)
11596
{
11697
if (false === $page->isActive()) {
11798
throw new NoSuchEntityException();
@@ -128,16 +109,9 @@ private function convertPageData(PageInterface $page, $includePageId = true, $in
128109
PageInterface::META_TITLE => $page->getMetaTitle(),
129110
PageInterface::META_DESCRIPTION => $page->getMetaDescription(),
130111
PageInterface::META_KEYWORDS => $page->getMetaKeywords(),
112+
PageInterface::PAGE_ID => $page->getId(),
113+
PageInterface::IDENTIFIER => $page->getIdentifier(),
131114
];
132-
133-
if ($includePageId) {
134-
$pageData[PageInterface::PAGE_ID] = $page->getId();
135-
}
136-
137-
if ($includePageIdentifier) {
138-
$pageData[PageInterface::IDENTIFIER] = $page->getIdentifier();
139-
}
140-
141115
return $pageData;
142116
}
143117
}

app/code/Magento/CmsGraphQl/Model/Resolver/Page.php

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,60 +45,21 @@ public function resolve(
4545
array $value = null,
4646
array $args = null
4747
) {
48-
if (!isset($args['id']) && !isset($args['identifier'])) {
48+
if (!isset($args['id'], $args['identifier'])) {
4949
throw new GraphQlInputException(__('"Page id/identifier should be specified'));
5050
}
5151

5252
$pageData = [];
5353

5454
try {
5555
if (isset($args['id'])) {
56-
$pageData = $this->getPageDataById($this->getPageId($args));
56+
$pageData = $this->pageDataProvider->getDataByPageId((int)$args['id']);
5757
} elseif (isset($args['identifier'])) {
58-
$pageData = $this->getPageDataByIdentifier($this->getPageIdentifier($args));
58+
$pageData = $this->pageDataProvider->getDataByPageIdentifier((string)$args['identifier']);
5959
}
6060
} catch (NoSuchEntityException $e) {
6161
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
6262
}
63-
6463
return $pageData;
6564
}
66-
67-
/**
68-
* @param array $args
69-
* @return int
70-
*/
71-
private function getPageId(array $args): int
72-
{
73-
return isset($args['id']) ? (int)$args['id'] : 0;
74-
}
75-
76-
/**
77-
* @param array $args
78-
* @return string
79-
*/
80-
private function getPageIdentifier(array $args): string
81-
{
82-
return isset($args['identifier']) ? (string)$args['identifier'] : '';
83-
}
84-
85-
/**
86-
* @param int $pageId
87-
* @return array
88-
* @throws GraphQlNoSuchEntityException
89-
*/
90-
private function getPageDataById(int $pageId): array
91-
{
92-
return $this->pageDataProvider->getDataByPageId($pageId);
93-
}
94-
95-
/**
96-
* @param string $pageIdentifier
97-
* @return array
98-
* @throws GraphQlNoSuchEntityException
99-
*/
100-
private function getPageDataByIdentifier(string $pageIdentifier): array
101-
{
102-
return $this->pageDataProvider->getDataByPageIdentifier($pageIdentifier);
103-
}
10465
}

0 commit comments

Comments
 (0)