コード例 #1
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());
 }
コード例 #2
0
ファイル: Object.php プロジェクト: shabbirvividads/magento2
 /**
  * @param \Magento\Framework\Object $object
  * @return \Magento\Framework\Object
  * @throws \Exception
  */
 public function filter($object)
 {
     if (!$object instanceof \Magento\Framework\Object) {
         throw new \InvalidArgumentException('Expecting an instance of \\Magento\\Framework\\Object');
     }
     $class = get_class($object);
     $out = $this->_entityFactory->create($class);
     foreach ($object->getData() as $column => $value) {
         $value = parent::filter($value);
         if (isset($this->_columnFilters[$column])) {
             $value = $this->_columnFilters[$column]->filter($value);
         }
         $out->setData($column, $value);
     }
     return $out;
 }
コード例 #3
0
 /**
  * Get items with limit
  */
 public function testGetItemsWithNullLimit()
 {
     $transations = range(1, TransactionsCollection::TRANSACTION_MAXIMUM_COUNT + 10);
     $this->filterMapperMock->expects($this->once())->method('getFilter')->willReturn(new BraintreeSearchNodeStub());
     $this->braintreeAdapterMock->expects($this->once())->method('search')->willReturn($transations);
     $this->entityFactoryMock->expects($this->exactly(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT))->method('create')->willReturn($this->transactionMapMock);
     $collection = new TransactionsCollection($this->entityFactoryMock, $this->braintreeAdapterMock, $this->filterMapperMock);
     $collection->setPageSize(null);
     $collection->addFieldToFilter('orderId', ['like' => '0']);
     $items = $collection->getItems();
     $this->assertEquals(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT, count($items));
     $this->assertInstanceOf(DocumentInterface::class, $items[1]);
 }
コード例 #4
0
 /**
  * @param array $arguments
  * @return \Magento\Framework\DataObject|mixed
  */
 public function createDataObject(array $arguments = [])
 {
     return $this->entityFactory->create($this->getDataInterfaceName(), $arguments);
 }
コード例 #5
0
ファイル: Collection.php プロジェクト: Doability/magento2dev
 /**
  * Retrieve collection empty item
  *
  * @return \Magento\Framework\DataObject
  */
 public function getNewEmptyItem()
 {
     return $this->_entityFactory->create($this->_itemObjectClass);
 }