WebsiteTest.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model;
  7. class WebsiteTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Store\Model\Website
  11. */
  12. protected $_model;
  13. protected function setUp()
  14. {
  15. $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  16. \Magento\Store\Model\Website::class
  17. );
  18. $this->_model->load(1);
  19. }
  20. /**
  21. * @magentoDbIsolation enabled
  22. */
  23. public function testLoadById()
  24. {
  25. $this->assertEquals(1, $this->_model->getId());
  26. $this->assertEquals('base', $this->_model->getCode());
  27. $this->assertEquals('Main Website', $this->_model->getName());
  28. }
  29. /**
  30. * @magentoDbIsolation enabled
  31. */
  32. public function testLoadByCode()
  33. {
  34. $this->_model->load('admin');
  35. $this->assertEquals(0, $this->_model->getId());
  36. $this->assertEquals('admin', $this->_model->getCode());
  37. $this->assertEquals('Admin', $this->_model->getName());
  38. }
  39. /**
  40. * @covers \Magento\Store\Model\Website::setGroups
  41. * @covers \Magento\Store\Model\Website::setStores
  42. * @covers \Magento\Store\Model\Website::getStores
  43. */
  44. public function testSetGroupsAndStores()
  45. {
  46. /* Groups */
  47. $expectedGroup = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  48. \Magento\Store\Model\Group::class
  49. );
  50. $expectedGroup->setId(123);
  51. $this->_model->setDefaultGroupId($expectedGroup->getId());
  52. $this->_model->setGroups([$expectedGroup]);
  53. $groups = $this->_model->getGroups();
  54. $this->assertSame($expectedGroup, reset($groups));
  55. /* Stores */
  56. $expectedStore = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  57. \Magento\Store\Model\Store::class
  58. );
  59. $expectedStore->setId(456);
  60. $expectedGroup->setDefaultStoreId($expectedStore->getId());
  61. $this->_model->setStores([$expectedStore]);
  62. $stores = $this->_model->getStores();
  63. $this->assertSame($expectedStore, reset($stores));
  64. }
  65. public function testGetGroups()
  66. {
  67. $groups = $this->_model->getGroups();
  68. $this->assertEquals([1], array_keys($groups));
  69. $this->assertInstanceOf(\Magento\Store\Model\Group::class, $groups[1]);
  70. $this->assertEquals(1, $groups[1]->getId());
  71. }
  72. public function testGetGroupIds()
  73. {
  74. $this->assertEquals([1 => 1], $this->_model->getGroupIds());
  75. }
  76. public function testGetGroupsCount()
  77. {
  78. $this->assertEquals(1, $this->_model->getGroupsCount());
  79. }
  80. public function testGetDefaultGroup()
  81. {
  82. $defaultGroup = $this->_model->getDefaultGroup();
  83. $this->assertInstanceOf(\Magento\Store\Model\Group::class, $defaultGroup);
  84. $this->assertEquals(1, $defaultGroup->getId());
  85. $this->_model->setDefaultGroupId(null);
  86. $this->assertFalse($this->_model->getDefaultGroup());
  87. }
  88. public function testGetStores()
  89. {
  90. $stores = $this->_model->getStores();
  91. $this->assertEquals([1], array_keys($stores));
  92. $this->assertInstanceOf(\Magento\Store\Model\Store::class, $stores[1]);
  93. $this->assertEquals(1, $stores[1]->getId());
  94. }
  95. public function testGetStoreIds()
  96. {
  97. $this->assertEquals([1 => 1], $this->_model->getStoreIds());
  98. }
  99. public function testGetStoreCodes()
  100. {
  101. $this->assertEquals([1 => 'default'], $this->_model->getStoreCodes());
  102. }
  103. public function testGetStoresCount()
  104. {
  105. $this->assertEquals(1, $this->_model->getStoresCount());
  106. }
  107. public function testIsCanDelete()
  108. {
  109. $this->assertFalse($this->_model->isCanDelete());
  110. $this->_model->isReadOnly(true);
  111. $this->assertFalse($this->_model->isCanDelete());
  112. }
  113. public function testGetWebsiteGroupStore()
  114. {
  115. $this->assertEquals('1--', $this->_model->getWebsiteGroupStore());
  116. $this->_model->setGroupId(123);
  117. $this->_model->setStoreId(456);
  118. $this->assertEquals('1-123-456', $this->_model->getWebsiteGroupStore());
  119. }
  120. public function testGetDefaultGroupId()
  121. {
  122. $this->assertEquals(1, $this->_model->getDefaultGroupId());
  123. }
  124. public function testGetBaseCurrency()
  125. {
  126. $currency = $this->_model->getBaseCurrency();
  127. $this->assertInstanceOf(\Magento\Directory\Model\Currency::class, $currency);
  128. $this->assertEquals('USD', $currency->getCode());
  129. }
  130. public function testGetDefaultStore()
  131. {
  132. $defaultStore = $this->_model->getDefaultStore();
  133. $this->assertInstanceOf(\Magento\Store\Model\Store::class, $defaultStore);
  134. $this->assertEquals(1, $defaultStore->getId());
  135. }
  136. public function testGetDefaultStoresSelect()
  137. {
  138. $this->assertInstanceOf(\Magento\Framework\DB\Select::class, $this->_model->getDefaultStoresSelect());
  139. }
  140. public function testIsReadonly()
  141. {
  142. $this->assertFalse($this->_model->isReadOnly());
  143. $this->_model->isReadOnly(true);
  144. $this->assertTrue($this->_model->isReadOnly());
  145. }
  146. /**
  147. * @magentoAppIsolation enabled
  148. * @magentoAppArea adminhtml
  149. */
  150. public function testCRUD()
  151. {
  152. $this->_model->setData(['code' => 'test_website', 'name' => 'test website', 'default_group_id' => 1]);
  153. /* emulate admin store */
  154. $crud = new \Magento\TestFramework\Entity($this->_model, ['name' => 'new name']);
  155. $crud->testCrud();
  156. }
  157. public function testCollection()
  158. {
  159. $collection = $this->_model->getCollection()->joinGroupAndStore()->addIdFilter(1);
  160. $this->assertEquals(1, count($collection->getItems()));
  161. }
  162. }