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

Public Member Functions

 linksDataProvider ()
 
 testSaveLinksDataNoProductsAttrs ($linksData)
 
 testSaveLinksDataWithProductsAttrs ($linksData)
 
 attributesDataProvider ()
 
 testGetAttributes ($dbAttributes, $returnedAttributes)
 

Protected Member Functions

 setUp ()
 
 processAttributeGetter ($dbAttributes)
 
 processBehaviorGetter ($behavior)
 

Protected Attributes

 $links
 
 $objectManagerHelper
 
 $link
 
 $resource
 
 $connection
 
 $importFactory
 
 $import
 

Detailed Description

Definition at line 12 of file LinksTest.php.

Member Function Documentation

◆ attributesDataProvider()

attributesDataProvider ( )
Returns
array

Definition at line 116 of file LinksTest.php.

117  {
118  return [
119  [
120  'dbAttributes' => [],
121  'returnedAttributes' => null
122  ],
123  [
124  'dbAttributes' => [
125  ['code' => 2, 'id' => 6, 'type' => 'sometable']
126  ],
127  'returnedAttributes' => [
128  2 => ['id' => 6, 'table' => 'table_name']
129  ]
130  ],
131  [
132  'dbAttributes' => [
133  ['code' => 8, 'id' => 11, 'type' => 'sometable1'],
134  ['code' => 4, 'id' => 7, 'type' => 'sometable2']
135  ],
136  'returnedAttributes' => [
137  4 => ['id' => 7, 'table' => 'table_name'],
138  8 => ['id' => 11, 'table' => 'table_name']
139  ]
140  ]
141  ];
142  }

◆ linksDataProvider()

linksDataProvider ( )
Returns
array

Definition at line 63 of file LinksTest.php.

64  {
65  return [
66  [
67  'linksData' => [
68  'product_ids' => [1, 2],
69  'relation' => [],
70  'attr_product_ids' => []
71  ]
72  ]
73  ];
74  }

◆ processAttributeGetter()

processAttributeGetter (   $dbAttributes)
protected
Parameters
$dbAttributes

Definition at line 147 of file LinksTest.php.

148  {
149  $select = $this->createMock(\Magento\Framework\DB\Select::class);
150  $this->connection->expects($this->once())->method('select')->will($this->returnValue($select));
151  $select->expects($this->once())->method('from')->will($this->returnSelf());
152  $select->expects($this->once())->method('where')->will($this->returnSelf());
153  $this->connection->expects($this->once())->method('fetchAll')->with($select)->will(
154  $this->returnValue($dbAttributes)
155  );
156  $this->link->expects($this->any())->method('getAttributeTypeTable')->will(
157  $this->returnValue('table_name')
158  );
159  }

◆ processBehaviorGetter()

processBehaviorGetter (   $behavior)
protected
Parameters
$behavior

Definition at line 177 of file LinksTest.php.

178  {
179  $dataSource = $this->createMock(\Magento\ImportExport\Model\ResourceModel\Import\Data::class);
180  $dataSource->expects($this->once())->method('getBehavior')->will($this->returnValue($behavior));
181  $this->import->expects($this->once())->method('getDataSourceModel')->will($this->returnValue($dataSource));
182  }

◆ setUp()

setUp ( )
protected

Definition at line 35 of file LinksTest.php.

36  {
37  $this->link = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Link::class);
38  $this->connection = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
39  $this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
40  $this->resource
41  ->expects($this->once())
42  ->method('getConnection')
43  ->will($this->returnValue($this->connection));
44 
45  $this->import = $this->createMock(\Magento\ImportExport\Model\Import::class);
46  $this->importFactory = $this->createPartialMock(\Magento\ImportExport\Model\ImportFactory::class, ['create']);
47  $this->importFactory->expects($this->any())->method('create')->will($this->returnValue($this->import));
48 
49  $this->objectManagerHelper = new ObjectManagerHelper($this);
50  $this->links = $this->objectManagerHelper->getObject(
51  \Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links::class,
52  [
53  'productLink' => $this->link,
54  'resource' => $this->resource,
55  'importFactory' => $this->importFactory
56  ]
57  );
58  }

◆ testGetAttributes()

testGetAttributes (   $dbAttributes,
  $returnedAttributes 
)
Parameters
array$dbAttributes
array$returnedAttributes@dataProvider attributesDataProvider

Definition at line 167 of file LinksTest.php.

168  {
169  $this->processAttributeGetter($dbAttributes);
170  $actualAttributes = $this->links->getAttributes();
171  $this->assertEquals($returnedAttributes, $actualAttributes);
172  }

◆ testSaveLinksDataNoProductsAttrs()

testSaveLinksDataNoProductsAttrs (   $linksData)
Parameters
array$linksData@dataProvider linksDataProvider

Definition at line 81 of file LinksTest.php.

82  {
83  $this->processBehaviorGetter('append');
85  $this->processAttributeGetter($attributes[2]['dbAttributes']);
86  $this->connection->expects($this->exactly(2))->method('insertOnDuplicate');
87  $this->links->saveLinksData($linksData);
88  }
$attributes
Definition: matrix.phtml:13

◆ testSaveLinksDataWithProductsAttrs()

testSaveLinksDataWithProductsAttrs (   $linksData)
Parameters
array$linksData@dataProvider linksDataProvider

Definition at line 95 of file LinksTest.php.

96  {
97  $linksData['attr_product_ids'] = [12 => true, 16 => true];
98  $linksData['position'] = [4 => 6];
99  $linksData['qty'] = [9 => 3];
100  $this->processBehaviorGetter('append');
101  $select = $this->createMock(\Magento\Framework\DB\Select::class);
102  $this->connection->expects($this->any())->method('select')->will($this->returnValue($select));
103  $select->expects($this->any())->method('from')->will($this->returnSelf());
104  $select->expects($this->any())->method('where')->will($this->returnSelf());
105  $this->connection->expects($this->once())->method('fetchAll')->with($select)->will($this->returnValue([]));
106  $this->connection->expects($this->once())->method('fetchPairs')->with($select)->will(
107  $this->returnValue([])
108  );
109  $this->connection->expects($this->exactly(4))->method('insertOnDuplicate');
110  $this->links->saveLinksData($linksData);
111  }

Field Documentation

◆ $connection

$connection
protected

Definition at line 27 of file LinksTest.php.

◆ $import

$import
protected

Definition at line 33 of file LinksTest.php.

◆ $importFactory

$importFactory
protected

Definition at line 30 of file LinksTest.php.

◆ $link

$link
protected

Definition at line 21 of file LinksTest.php.

◆ $links

$links
protected

Definition at line 15 of file LinksTest.php.

◆ $objectManagerHelper

$objectManagerHelper
protected

Definition at line 18 of file LinksTest.php.

◆ $resource

$resource
protected

Definition at line 24 of file LinksTest.php.


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