32 $this->eavConfig = $this->createMock(\
Magento\Eav\Model\Config::class);
34 AbstractEntity::class,
35 [
'eavConfig' => $this->eavConfig]
37 $this->_model = $this->getMockForAbstractClass(
38 AbstractEntity::class,
57 $attribute1 = $this->createPartialMock(\
Magento\Eav\Model\Entity\Attribute::class, [
'__wakeup']);
58 $attribute1->setAttributeSetInfo([0 => $attribute1Sort]);
59 $attribute2 = $this->createPartialMock(\
Magento\Eav\Model\Entity\Attribute::class, [
'__wakeup']);
60 $attribute2->setAttributeSetInfo([0 => $attribute2Sort]);
70 'attribute1 bigger than attribute2' => [
71 'attribute1Sort' => [
'group_sort' => 7,
'sort' => 5],
72 'attribute2Sort' => [
'group_sort' => 5,
'sort' => 10],
75 'attribute1 smaller than attribute2' => [
76 'attribute1Sort' => [
'group_sort' => 7,
'sort' => 5],
77 'attribute2Sort' => [
'group_sort' => 7,
'sort' => 10],
80 'attribute1 equals to attribute2' => [
81 'attribute1Sort' => [
'group_sort' => 7,
'sort' => 5],
82 'attribute2Sort' => [
'group_sort' => 7,
'sort' => 5],
93 protected function _getAttributes()
96 $codes = [
'entity_type_id',
'attribute_set_id',
'created_at',
'updated_at',
'parent_id',
'increment_id'];
97 foreach ($codes as
$code) {
98 $mock = $this->createPartialMock(
100 [
'getBackend',
'getBackendTable',
'__wakeup']
102 $mock->setAttributeId(
$code);
105 $backendModel = $this->createPartialMock(
107 [
'getBackend',
'getBackendTable']
110 $backendModel->setAttribute($mock);
112 $mock->expects($this->any())->method(
'getBackend')->will($this->returnValue($backendModel));
114 $mock->expects($this->any())->method(
'getBackendTable')->will($this->returnValue(
$code .
'_table'));
128 $connection = $this->createPartialMock(\
Magento\Framework\DB\Adapter\Pdo\Mysql::class, [
133 'prepareColumnValue',
138 $statement = $this->createPartialMock(
139 \Zend_Db_Statement::class,
140 [
'closeCursor',
'columnCount',
'errorCode',
'errorInfo',
'fetch',
'nextRowset',
'rowCount']
148 $connection->expects($this->any())->method(
'query')->will($this->returnValue($statement));
155 $this->returnValue([
'value' => [
'test']])
158 $connection->expects($this->any())->method(
'prepareColumnValue')->will($this->returnArgument(2));
165 $this->equalTo(
'test_table')
167 $this->returnValue(
true)
175 ->method(
'getIndexList')
178 'PK_ENTITYTABLE' => [
200 [
'getBackend',
'getBackendTable',
'isInSet',
'getApplyTo',
'getAttributeCode',
'__wakeup']
219 $this->returnValue(
false)
237 $object = $this->createPartialMock(
238 \
Magento\Catalog\Model\Product::class,
239 [
'getOrigData',
'__wakeup',
'beforeSave',
'afterSave',
'validateBeforeSave']
241 $object->setEntityTypeId(1);
243 $object->setData($key,
$value);
245 $object->expects($this->any())->method(
'getOrigData')->will($this->returnValue($productOrigData));
257 $backendModel = $this->createPartialMock(
268 $backendModel->expects(
273 $this->returnValue([
'test_table' => [[
'value_id' => 0,
'attribute_id' =>
$attributeCode]]])
276 $backendModel->expects($this->any())->method(
'isStatic')->will($this->returnValue(
false));
278 $backendModel->expects($this->never())->method(
'getEntityValueId');
281 $attribute->expects($this->any())->method(
'getBackend')->will($this->returnValue($backendModel));
285 ->disableOriginalConstructor()
288 $this->eavConfig = $this->createMock(\
Magento\Eav\Model\Config::class);
290 AbstractEntity::class,
295 'entityTable' =>
'entityTable',
301 $model = $this->getMockBuilder(AbstractEntity::class)
303 ->setMethods([
'_getValue',
'beginTransaction',
'commit',
'rollback',
'getConnection'])
305 $model->expects($this->any())->method(
'_getValue')->will($this->returnValue(
$eavConfig));
308 $eavConfig->expects($this->any())->method(
'getAttribute')->will(
309 $this->returnCallback(
315 $model->isPartialSave(
true);
330 'test_attr' =>
'test_attr',
341 'test_attr' =>
'test_attr',
343 'entity_id' => 12345,
346 [
'test_attr' =>
'test_attr']
351 [
'test_attr' =>
'99.99',
'attribute_set_id' =>
$attributeSetId,
'entity_id' => 12345,
'store_id' => 1],
352 [
'test_attr' =>
'99.9900']
360 public function testDuplicateExceptionProcessingOnSave()
362 $connection = $this->createMock(AdapterInterface::class);
363 $connection->expects($this->once())->method(
'rollback');
366 $model = $this->getMockBuilder(AbstractEntity::class)
367 ->disableOriginalConstructor()
368 ->setMethods([
'getConnection'])
369 ->getMockForAbstractClass();
373 $object = $this->getMockBuilder(AbstractModel::class)
374 ->disableOriginalConstructor()
376 $object->expects($this->once())->method(
'hasDataChanges')->willReturn(
true);
377 $object->expects($this->once())->method(
'beforeSave')->willThrowException(
new DuplicateException());
378 $object->expects($this->once())->method(
'setHasDataChanges')->with(
true);
productAttributesDataProvider()
testCompareAttributes($attribute1Sort, $attribute2Sort, $expected)
static compareAttributesDataProvider()
_getAttributeMock($attributeCode, $attributeSetId)