Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
LinkTest Class Reference
Inheritance diagram for LinkTest:

Public Member Functions

 testGetWebsiteIdByProductId ()
 
 testSaveWebsiteIds ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $model
 
 $resource
 
 $connection
 
 $dbSelect
 

Detailed Description

Definition at line 11 of file LinkTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Definition at line 33 of file LinkTest.php.

34  {
35  $this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
36  $this->connection =
37  $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
38  $this->dbSelect = $this->getMockBuilder(\Magento\Framework\Db\Select::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41  $this->connection->expects($this->any())
42  ->method('select')
43  ->willReturn($this->dbSelect);
44  $this->resource->expects($this->any())
45  ->method('getConnection')
46  ->willReturn($this->connection);
47  $this->resource->expects($this->atLeastOnce())
48  ->method('getTableName')
49  ->with('catalog_product_website')
50  ->willReturn('catalog_product_website');
51  $this->model = new Link($this->resource);
52  }

◆ testGetWebsiteIdByProductId()

testGetWebsiteIdByProductId ( )

Definition at line 54 of file LinkTest.php.

55  {
56  $websiteIds = [1,2];
57  $productId = 1;
58  $this->dbSelect->expects($this->once())
59  ->method("from")
60  ->with('catalog_product_website', 'website_id')
61  ->willReturn($this->dbSelect);
62  $this->dbSelect->expects($this->once())
63  ->method("where")
64  ->with('product_id = ?', (int) $productId);
65  $this->connection->expects($this->once())
66  ->method('fetchCol')
67  ->willReturn($websiteIds);
68 
69  $this->assertEquals($websiteIds, $this->model->getWebsiteIdsByProductId($productId));
70  }

◆ testSaveWebsiteIds()

testSaveWebsiteIds ( )

Definition at line 72 of file LinkTest.php.

73  {
74  $newWebsiteIds = [2,3];
75  $websiteIds = [1,2];
76  $productId = 1;
77  $product = $this->createMock(ProductInterface::class);
78  $product->expects($this->atLeastOnce())
79  ->method('getId')
80  ->willReturn($productId);
81  $this->dbSelect->expects($this->once())
82  ->method("from")
83  ->with('catalog_product_website', 'website_id')
84  ->willReturn($this->dbSelect);
85  $this->dbSelect->expects($this->once())
86  ->method("where")
87  ->with('product_id = ?', (int) $productId);
88  $this->connection->expects($this->once())
89  ->method('fetchCol')
90  ->willReturn($websiteIds);
91 
92  $this->connection->expects($this->once())
93  ->method('insertMultiple')
94  ->with('catalog_product_website', [
95  ['product_id' => $productId, 'website_id' => 3]
96  ]);
97 
98  $this->connection->expects($this->once())
99  ->method('delete')
100  ->with('catalog_product_website', ['product_id = ?' => $productId, 'website_id = ?' => 1]);
101 
102  $this->assertTrue($this->model->saveWebsiteIds($product, $newWebsiteIds));
103  }

Field Documentation

◆ $connection

$connection
protected

Definition at line 26 of file LinkTest.php.

◆ $dbSelect

$dbSelect
protected

Definition at line 31 of file LinkTest.php.

◆ $model

$model
protected

Definition at line 16 of file LinkTest.php.

◆ $resource

$resource
protected

Definition at line 21 of file LinkTest.php.


The documentation for this class was generated from the following file: