WebsiteTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Test\Unit\Model;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. use Magento\Store\Model\ScopeInterface;
  9. use Magento\Store\Model\Website;
  10. use Magento\Store\Model\WebsiteFactory;
  11. class WebsiteTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var Website
  15. */
  16. protected $model;
  17. /**
  18. * @var ObjectManager
  19. */
  20. protected $objectManagerHelper;
  21. /**
  22. * @var WebsiteFactory|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $websiteFactory;
  25. public function setUp()
  26. {
  27. $this->objectManagerHelper = new ObjectManager($this);
  28. $this->websiteFactory = $this->getMockBuilder(\Magento\Store\Model\WebsiteFactory::class)
  29. ->disableOriginalConstructor()
  30. ->setMethods(['create', 'getCollection', '__wakeup'])
  31. ->getMock();
  32. /** @var Website $websiteModel */
  33. $this->model = $this->objectManagerHelper->getObject(
  34. \Magento\Store\Model\Website::class,
  35. ['websiteFactory' => $this->websiteFactory]
  36. );
  37. }
  38. public function testIsCanDelete()
  39. {
  40. $websiteCollection = $this->createPartialMock(
  41. \Magento\Store\Model\ResourceModel\Website\Collection::class,
  42. ['getSize']
  43. );
  44. $websiteCollection->expects($this->any())->method('getSize')->will($this->returnValue(2));
  45. $this->websiteFactory->expects($this->any())
  46. ->method('create')
  47. ->willReturn($this->websiteFactory);
  48. $this->websiteFactory->expects($this->any())
  49. ->method('getCollection')
  50. ->willReturn($websiteCollection);
  51. $this->model->setId(2);
  52. $this->assertTrue($this->model->isCanDelete());
  53. }
  54. public function testGetScopeType()
  55. {
  56. $this->assertEquals(ScopeInterface::SCOPE_WEBSITE, $this->model->getScopeType());
  57. }
  58. public function testGetScopeTypeName()
  59. {
  60. $this->assertEquals('Website', $this->model->getScopeTypeName());
  61. }
  62. }