123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Store\Model;
- class WebsiteTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Store\Model\Website
- */
- protected $_model;
- protected function setUp()
- {
- $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
- \Magento\Store\Model\Website::class
- );
- $this->_model->load(1);
- }
- /**
- * @magentoDbIsolation enabled
- */
- public function testLoadById()
- {
- $this->assertEquals(1, $this->_model->getId());
- $this->assertEquals('base', $this->_model->getCode());
- $this->assertEquals('Main Website', $this->_model->getName());
- }
- /**
- * @magentoDbIsolation enabled
- */
- public function testLoadByCode()
- {
- $this->_model->load('admin');
- $this->assertEquals(0, $this->_model->getId());
- $this->assertEquals('admin', $this->_model->getCode());
- $this->assertEquals('Admin', $this->_model->getName());
- }
- /**
- * @covers \Magento\Store\Model\Website::setGroups
- * @covers \Magento\Store\Model\Website::setStores
- * @covers \Magento\Store\Model\Website::getStores
- */
- public function testSetGroupsAndStores()
- {
- /* Groups */
- $expectedGroup = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
- \Magento\Store\Model\Group::class
- );
- $expectedGroup->setId(123);
- $this->_model->setDefaultGroupId($expectedGroup->getId());
- $this->_model->setGroups([$expectedGroup]);
- $groups = $this->_model->getGroups();
- $this->assertSame($expectedGroup, reset($groups));
- /* Stores */
- $expectedStore = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
- \Magento\Store\Model\Store::class
- );
- $expectedStore->setId(456);
- $expectedGroup->setDefaultStoreId($expectedStore->getId());
- $this->_model->setStores([$expectedStore]);
- $stores = $this->_model->getStores();
- $this->assertSame($expectedStore, reset($stores));
- }
- public function testGetGroups()
- {
- $groups = $this->_model->getGroups();
- $this->assertEquals([1], array_keys($groups));
- $this->assertInstanceOf(\Magento\Store\Model\Group::class, $groups[1]);
- $this->assertEquals(1, $groups[1]->getId());
- }
- public function testGetGroupIds()
- {
- $this->assertEquals([1 => 1], $this->_model->getGroupIds());
- }
- public function testGetGroupsCount()
- {
- $this->assertEquals(1, $this->_model->getGroupsCount());
- }
- public function testGetDefaultGroup()
- {
- $defaultGroup = $this->_model->getDefaultGroup();
- $this->assertInstanceOf(\Magento\Store\Model\Group::class, $defaultGroup);
- $this->assertEquals(1, $defaultGroup->getId());
- $this->_model->setDefaultGroupId(null);
- $this->assertFalse($this->_model->getDefaultGroup());
- }
- public function testGetStores()
- {
- $stores = $this->_model->getStores();
- $this->assertEquals([1], array_keys($stores));
- $this->assertInstanceOf(\Magento\Store\Model\Store::class, $stores[1]);
- $this->assertEquals(1, $stores[1]->getId());
- }
- public function testGetStoreIds()
- {
- $this->assertEquals([1 => 1], $this->_model->getStoreIds());
- }
- public function testGetStoreCodes()
- {
- $this->assertEquals([1 => 'default'], $this->_model->getStoreCodes());
- }
- public function testGetStoresCount()
- {
- $this->assertEquals(1, $this->_model->getStoresCount());
- }
- public function testIsCanDelete()
- {
- $this->assertFalse($this->_model->isCanDelete());
- $this->_model->isReadOnly(true);
- $this->assertFalse($this->_model->isCanDelete());
- }
- public function testGetWebsiteGroupStore()
- {
- $this->assertEquals('1--', $this->_model->getWebsiteGroupStore());
- $this->_model->setGroupId(123);
- $this->_model->setStoreId(456);
- $this->assertEquals('1-123-456', $this->_model->getWebsiteGroupStore());
- }
- public function testGetDefaultGroupId()
- {
- $this->assertEquals(1, $this->_model->getDefaultGroupId());
- }
- public function testGetBaseCurrency()
- {
- $currency = $this->_model->getBaseCurrency();
- $this->assertInstanceOf(\Magento\Directory\Model\Currency::class, $currency);
- $this->assertEquals('USD', $currency->getCode());
- }
- public function testGetDefaultStore()
- {
- $defaultStore = $this->_model->getDefaultStore();
- $this->assertInstanceOf(\Magento\Store\Model\Store::class, $defaultStore);
- $this->assertEquals(1, $defaultStore->getId());
- }
- public function testGetDefaultStoresSelect()
- {
- $this->assertInstanceOf(\Magento\Framework\DB\Select::class, $this->_model->getDefaultStoresSelect());
- }
- public function testIsReadonly()
- {
- $this->assertFalse($this->_model->isReadOnly());
- $this->_model->isReadOnly(true);
- $this->assertTrue($this->_model->isReadOnly());
- }
- /**
- * @magentoAppIsolation enabled
- * @magentoAppArea adminhtml
- */
- public function testCRUD()
- {
- $this->_model->setData(['code' => 'test_website', 'name' => 'test website', 'default_group_id' => 1]);
- /* emulate admin store */
- $crud = new \Magento\TestFramework\Entity($this->_model, ['name' => 'new name']);
- $crud->testCrud();
- }
- public function testCollection()
- {
- $collection = $this->_model->getCollection()->joinGroupAndStore()->addIdFilter(1);
- $this->assertEquals(1, count($collection->getItems()));
- }
- }
|