DeleteWebsiteToStockLinkTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventorySales\Test\Integration\Website;
  8. use Magento\Framework\Registry;
  9. use Magento\InventorySalesApi\Model\GetAssignedStockIdForWebsiteInterface;
  10. use Magento\Store\Model\Website;
  11. use Magento\Store\Model\WebsiteFactory;
  12. use Magento\TestFramework\Helper\Bootstrap;
  13. use PHPUnit\Framework\TestCase;
  14. class DeleteWebsiteToStockLinkTest extends TestCase
  15. {
  16. /**
  17. * @var WebsiteFactory
  18. */
  19. private $websiteFactory;
  20. /**
  21. * @var GetAssignedStockIdForWebsiteInterface
  22. */
  23. private $getAssignedStockIdForWebsite;
  24. protected function setUp()
  25. {
  26. $this->websiteFactory = Bootstrap::getObjectManager()->get(WebsiteFactory::class);
  27. $this->getAssignedStockIdForWebsite = Bootstrap::getObjectManager()->get(
  28. GetAssignedStockIdForWebsiteInterface::class
  29. );
  30. }
  31. public function testDeleteWebsiteToStockLink()
  32. {
  33. $websiteCode = 'test_1';
  34. /** @var Website $website */
  35. $website = $this->websiteFactory->create();
  36. $website->setCode($websiteCode);
  37. // Use website model because we haven't api interfaces for website saving/deleting
  38. $website->save();
  39. $this->deleteWebsite($website);
  40. $stockId = $this->getAssignedStockIdForWebsite->execute($websiteCode);
  41. self::assertNull($stockId);
  42. }
  43. /**
  44. * @param Website $website
  45. * @return void
  46. */
  47. private function deleteWebsite(Website $website)
  48. {
  49. $registry = Bootstrap::getObjectManager()->get(Registry::class);
  50. $registry->unregister('isSecureArea');
  51. $registry->register('isSecureArea', true);
  52. $website->delete();
  53. $registry->unregister('isSecureArea');
  54. $registry->register('isSecureArea', false);
  55. }
  56. }