/**
  * @return void
  */
 public function rewind()
 {
     $this->current = null;
     $this->key = 0;
     $this->query->reset();
     $this->next();
 }
Beispiel #2
0
 /**
  * Run test toOptionIdArray method
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testToOptionIdArray()
 {
     $itemsByPageId = array_fill(0, 4, 123);
     $data = ['item1' => ['test' => 'test'], 'item2' => ['test' => 'test'], 'item3' => ['test' => 'test'], 'item4' => ['test' => 'test']];
     $objectMock = $this->getMock('Magento\\Framework\\Object', ['getData', 'getId', 'setData', 'getTitle', 'getIdentifier'], [], '', false);
     $criteriaMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\CriteriaInterface');
     $connectionMock = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['getTable']);
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $storeMock = $this->getMock('Magento\\Store\\Model\\Store', ['getCode'], [], '', false);
     $this->queryMock->expects($this->once())->method('fetchAll')->will($this->returnValue($data));
     $this->searchResultProcessorMock->expects($this->once())->method('getColumnValues')->with('page_id')->will($this->returnValue($itemsByPageId));
     $this->queryMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('id_field_name'));
     $objectMock->expects($this->any())->method('getData')->will($this->returnValueMap([['id_field_name', null, null], ['page_id', null, 123]]));
     $this->entityFactoryMock->expects($this->any())->method('create')->with('Magento\\Cms\\Model\\Page', ['data' => ['test' => 'test']])->will($this->returnValue($objectMock));
     $this->queryMock->expects($this->once())->method('getCriteria')->will($this->returnValue($criteriaMock));
     $criteriaMock->expects($this->once())->method('getPart')->with('first_store_flag')->will($this->returnValue(true));
     $this->queryMock->expects($this->once())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->queryMock->expects($this->once())->method('getResource')->will($this->returnValue($resourceMock));
     $connectionMock->expects($this->once())->method('select')->will($this->returnValue($selectMock));
     $selectMock->expects($this->once())->method('from')->with(['cps' => 'query_table'])->will($this->returnSelf());
     $resourceMock->expects($this->once())->method('getTable')->with('cms_page_store')->will($this->returnValue('query_table'));
     $selectMock->expects($this->once())->method('where')->with('cps.page_id IN (?)', array_fill(0, 4, 123))->will($this->returnSelf());
     $connectionMock->expects($this->once())->method('fetchPairs')->with($selectMock)->will($this->returnValue([123 => 999]));
     $objectMock->expects($this->any())->method('getId')->will($this->returnValue(123));
     $this->storeManagerMock->expects($this->any())->method('getStore')->with(999)->will($this->returnValue($storeMock));
     $storeMock->expects($this->any())->method('getCode')->will($this->returnValue('store_code'));
     $objectMock->expects($this->any())->method('setData');
     $objectMock->expects($this->any())->method('getTitle')->will($this->returnValue('item-value'));
     $objectMock->expects($this->any())->method('getIdentifier')->will($this->returnValue('identifier-value'));
     $expected = [['value' => 'identifier-value', 'label' => 'item-value'], ['value' => 'identifier-value|123', 'label' => 'item-value'], ['value' => 'identifier-value|123', 'label' => 'item-value'], ['value' => 'identifier-value|123', 'label' => 'item-value']];
     $this->assertEquals($expected, $this->collection->toOptionIdArray());
 }