/** * creates mock items and adds to listStatus * * @return array */ protected function addItems() { $origin = 'stock'; $code = 'cataloginventory'; $message = Data::ERROR_QTY; $additionalData = null; $mockItems = []; for ($i = 0; $i < 2; $i++) { $mockItems[] = ['origin' => $origin . $i, 'code' => $code, 'message' => $message . $i, 'additionalData' => $additionalData]; $this->listStatus->addItem($origin . $i, $code, $message . $i, $additionalData); } return $mockItems; }
public function testRemoveErrorInfosByParamsAllErrorsRemoved() { $message = "message"; $message2 = "message2"; $this->errorInfos->expects($this->at(0))->method('addItem')->with(null, null, $message); $this->errorInfos->expects($this->at(1))->method('addItem')->with(null, null, $message2); $this->assertEquals($this->model, $this->model->addErrorInfo(null, null, $message)); $this->assertEquals($this->model, $this->model->addErrorInfo(null, null, $message2)); $this->assertEquals($message . "\n" . $message2, $this->model->getMessage()); $params = []; $removedItems = [['message' => $message], ['message' => $message2]]; $this->errorInfos->expects($this->once())->method('removeItemsByParams')->with($params)->will($this->returnValue($removedItems)); $this->errorInfos->expects($this->once())->method('getItems')->will($this->returnValue([])); $this->assertEquals($this->model, $this->model->removeErrorInfosByParams($params)); $this->assertFalse($this->model->getHasError()); $this->assertEquals('', $this->model->getMessage()); }
/** * Removes error infos, that have parameters equal to passed in $params. * $params can have following keys (if not set - then any item is good for this key): * 'origin', 'code', 'message' * * @param array $params * @return $this */ public function removeErrorInfosByParams($params) { $removedItems = $this->_errorInfos->removeItemsByParams($params); foreach ($removedItems as $item) { if ($item['message'] !== null) { $this->removeMessageByText($item['message']); } } if (!$this->_errorInfos->getItems()) { $this->_setHasError(false); } return $this; }