public function testSave()
 {
     $connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $resourceMock = $this->getMock('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', ['_construct', 'getConnection', '__wakeup', 'getIdFieldName'], [], '', false);
     $connectionInterfaceMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionInterfaceMock));
     $data = 'tableName';
     $this->resourcesMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->resourcesMock->expects($this->any())->method('getTableName')->with($data)->will($this->returnValue('tableName'));
     $mainTableReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', '_mainTable');
     $mainTableReflection->setAccessible(true);
     $mainTableReflection->setValue($this->model, 'tableName');
     $idFieldNameReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', '_idFieldName');
     $idFieldNameReflection->setAccessible(true);
     $idFieldNameReflection->setValue($this->model, 'idFieldName');
     $connectionMock->expects($this->any())->method('save')->with('tableName', 'idFieldName');
     $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('idFieldName'));
     $abstractModelMock = $this->setupAbstractModel($resourceMock);
     $abstractModelMock->setIdFieldName('id');
     $abstractModelMock->setData(['id' => 12345, 'name' => 'Test Name', 'value' => 'Test Value']);
     $abstractModelMock->afterLoad();
     $this->assertEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $newData = ['value' => 'Test Value New'];
     $abstractModelMock->addData($newData);
     $this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $abstractModelMock->isObjectNew(false);
     $connectionMock->expects($this->any())->method('update')->with('tableName', $newData, 'idFieldName');
     $this->relationProcessorMock->expects($this->once())->method('validateDataIntegrity');
     $this->entityManager->expects($this->once())->method('save');
     $this->model->save($abstractModelMock);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Framework\Model\AbstractModel $object)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'save');
     if (!$pluginInfo) {
         return parent::save($object);
     } else {
         return $this->___callPlugins('save', func_get_args(), $pluginInfo);
     }
 }
Ejemplo n.º 3
0
 public function testSave()
 {
     $this->entityManager->expects($this->once())->method('save')->with($this->rule);
     $this->assertEquals($this->model->save($this->rule), $this->model);
 }