Skip to content

Commit

Permalink
Fix lever responses and add new test for get category by id
Browse files Browse the repository at this point in the history
  • Loading branch information
nuzil committed Nov 20, 2018
1 parent dfcac0c commit cd8b01b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
class ExtractDataFromCategoryTree
{
const START_CATEGORY_FETCH_LEVEL = 1;

/**
* @var Hydrator
*/
Expand All @@ -27,6 +25,11 @@ class ExtractDataFromCategoryTree
*/
private $iteratingCategory;

/**
* @var int
*/
private $startCategoryFetchLevel = 1;

/**
* @param Hydrator $categoryHydrator
*/
Expand All @@ -51,9 +54,12 @@ public function execute(\Iterator $iterator): array
$iterator->next();

$pathElements = explode("/", $category->getPath());
$this->iteratingCategory = $category;
if (empty($tree)){
$this->startCategoryFetchLevel = count($pathElements) - 1;
}

$currentLevelTree = $this->explodePathToArray($pathElements, self::START_CATEGORY_FETCH_LEVEL);
$this->iteratingCategory = $category;
$currentLevelTree = $this->explodePathToArray($pathElements, $this->startCategoryFetchLevel);
if (empty($tree)) {
$tree = $currentLevelTree;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,44 @@ public function testCategoriesTree()
);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetCategoryById()
{
$rootCategoryId = 13;
$query = <<<QUERY
{
category(id: {$rootCategoryId}) {
id
name
}
}
QUERY;

// get customer ID token
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
$customerTokenService = $this->objectManager->create(
\Magento\Integration\Api\CustomerTokenServiceInterface::class
);
$customerToken = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');

$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
$response = $this->graphQlQuery($query, [], '', $headerMap);
$responseDataObject = new DataObject($response);
//Some sort of smoke testing
self::assertEquals(
'Category 1.2',
$responseDataObject->getData('category/name')
);
self::assertEquals(
13,
$responseDataObject->getData('category/id')
);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand Down

0 comments on commit cd8b01b

Please sign in to comment.