Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
alepane21 authored and rostyslav-hymon committed Mar 27, 2018
1 parent 2a01489 commit 2d12dac
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\ResourceModel\Category;

class CollectionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Catalog\Model\ResourceModel\Category\Collection
*/
protected $collection;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\ResourceModel\Category\Collection::class
);
}

protected function setDown() {
/* Refresh stores memory cache after store deletion */
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Store\Model\StoreManagerInterface::class
)->reinitStores();
}

/**
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php
*/
public function testJoinUrlRewriteOnDefault()
{
$categories = $this->collection->joinUrlRewrite()->addPathFilter('1/2/3');
$this->assertCount(1, $categories);
/** @var $category \Magento\Catalog\Model\Category */
$category = $categories->getFirstItem();
$this->assertStringEndsWith('category.html', $category->getUrl());
}

/**
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/category_multiple_stores.php
*/
public function testJoinUrlRewriteNotOnDefaultStore()
{
$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
$storeId = $store->load('second_category_store', 'code')->getId();
$categories = $this->collection->setStoreId($storeId)->joinUrlRewrite()->addPathFilter('1/2/3');
$this->assertCount(1, $categories);
/** @var $category \Magento\Catalog\Model\Category */
$category = $categories->getFirstItem();
$this->assertStringEndsWith('category-3-on-2.html', $category->getUrl());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/** @var \Magento\Catalog\Model\CategoryFactory $factory */
$factory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\CategoryFactory::class
);
/** @var \Magento\Catalog\Model\CategoryRepository $repository */
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\CategoryRepository::class
);
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
$storeManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Store\Model\StoreManagerInterface::class
);
/** @var \Magento\Store\Model\Store $store */
$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
if (!$store->load('second_category_store', 'code')->getId()) {
$websiteId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Store\Model\StoreManagerInterface::class
)->getWebsite()->getId();
$groupId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Store\Model\StoreManagerInterface::class
)->getWebsite()->getDefaultGroupId();
$store->setCode(
'second_category_store'
)->setWebsiteId(
$websiteId
)->setGroupId(
$groupId
)->setName(
'Fixture Store'
)->setSortOrder(
10
)->setIsActive(
1
);
$store->save();
}

/* Refresh stores memory cache */
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Store\Model\StoreManagerInterface::class
)->reinitStores();

/** @var \Magento\Catalog\Model\Category $newCategory */
$newCategory = $factory->create();
$newCategory
->setName('Category')
->setParentId(2)
->setLevel(2)
->setPath('1/2/3')
->setAvailableSortBy('name')
->setDefaultSortBy('name')
->setIsActive(true)
->setPosition(1);
$repository->save($newCategory);
$currentStoreId = $storeManager->getStore()->getId();
$storeManager->setCurrentStore($storeManager->getStore($store->getId()));
$newCategory
->setUrlKey('category-3-on-2');
$repository->save($newCategory);
$storeManager->setCurrentStore($storeManager->getStore($currentStoreId));

0 comments on commit 2d12dac

Please sign in to comment.