示例#1
0
 public function testPossibleFlowWithItem()
 {
     $firstItemMock = $this->getMock('Magento\\Framework\\Object', [], [], '', false);
     $secondItemMock = $this->getMock('Magento\\Framework\\Object', [], [], '', false);
     $requiredFields = ['required_field_one', 'required_field_two'];
     $arrItems = ['totalRecords' => 1, 'items' => [0 => 'value']];
     $items = ['item_id' => $firstItemMock, 0 => $secondItemMock];
     $firstItemMock->expects($this->exactly(2))->method('getId')->will($this->returnValue('item_id'));
     $firstItemMock->expects($this->atLeastOnce())->method('getData')->with('colName')->will($this->returnValue('first_value'));
     $secondItemMock->expects($this->atLeastOnce())->method('getData')->with('colName')->will($this->returnValue('second_value'));
     $firstItemMock->expects($this->once())->method('toArray')->with($requiredFields)->will($this->returnValue('value'));
     /** add items and set them values */
     $this->_model->addItem($firstItemMock);
     $this->assertEquals($arrItems, $this->_model->toArray($requiredFields));
     $this->_model->addItem($secondItemMock);
     $this->_model->setDataToAll('column', 'value');
     /** get items by column name */
     $this->assertEquals(['first_value', 'second_value'], $this->_model->getColumnValues('colName'));
     $this->assertEquals([$secondItemMock], $this->_model->getItemsByColumnValue('colName', 'second_value'));
     $this->assertEquals($firstItemMock, $this->_model->getItemByColumnValue('colName', 'second_value'));
     $this->assertEquals([], $this->_model->getItemsByColumnValue('colName', 'non_existing_value'));
     $this->assertEquals(null, $this->_model->getItemByColumnValue('colName', 'non_existing_value'));
     /** get items */
     $this->assertEquals(['item_id', 0], $this->_model->getAllIds());
     $this->assertEquals($firstItemMock, $this->_model->getFirstItem());
     $this->assertEquals($secondItemMock, $this->_model->getLastItem());
     $this->assertEquals($items, $this->_model->getItems('item_id'));
     /** remove existing items */
     $this->assertNull($this->_model->getItemById('not_existing_item_id'));
     $this->_model->removeItemByKey('item_id');
     $this->assertEquals([$secondItemMock], $this->_model->getItems());
     $this->_model->removeAllItems();
     $this->assertEquals([], $this->_model->getItems());
 }