Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteWebsiteToStockLinkTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 use Magento\Store\Model\WebsiteFactory;
15 use PHPUnit\Framework\TestCase;
16 
17 class DeleteWebsiteToStockLinkTest extends TestCase
18 {
22  private $websiteFactory;
23 
27  private $getAssignedStockIdForWebsite;
28 
29  protected function setUp()
30  {
31  $this->websiteFactory = Bootstrap::getObjectManager()->get(WebsiteFactory::class);
32  $this->getAssignedStockIdForWebsite = Bootstrap::getObjectManager()->get(
33  GetAssignedStockIdForWebsiteInterface::class
34  );
35  }
36 
37  public function testDeleteWebsiteToStockLink()
38  {
39  $websiteCode = 'test_1';
40 
42  $website = $this->websiteFactory->create();
43  $website->setCode($websiteCode);
44  // Use website model because we haven't api interfaces for website saving/deleting
45  $website->save();
46  $this->deleteWebsite($website);
47 
48  $stockId = $this->getAssignedStockIdForWebsite->execute($websiteCode);
49  self::assertNull($stockId);
50  }
51 
56  private function deleteWebsite(Website $website)
57  {
58  $registry = Bootstrap::getObjectManager()->get(Registry::class);
59  $registry->unregister('isSecureArea');
60  $registry->register('isSecureArea', true);
61  $website->delete();
62  $registry->unregister('isSecureArea');
63  $registry->register('isSecureArea', false);
64  }
65 }
if(!isset($_GET['website_code'])) $websiteCode
Definition: website.php:11