Ejemplo n.º 1
0
 /**
  * Retrieve test collection
  *
  * @return \Magento\Framework\Data\Collection
  */
 protected function _getTestCollection()
 {
     $collection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Core\\Model\\EntityFactory', array(), array(), '', false));
     $items = array(new \Magento\Framework\Object(array('test1' => '1', 'test2' => '2')));
     foreach ($items as $item) {
         $collection->addItem($item);
     }
     return $collection;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve test collection
  *
  * @return \Magento\Framework\Data\Collection
  */
 protected function _getTestCollection()
 {
     $collection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false));
     $items = [new \Magento\Framework\Object(['sub_test1' => '1', 'sub_test2' => '2']), new \Magento\Framework\Object(['sub_test1' => '1', 'sub_test2' => '2']), new \Magento\Framework\Object(['sub_test1' => '1', 'sub_test2' => '2'])];
     foreach ($items as $item) {
         $collection->addItem($item);
     }
     return $collection;
 }
Ejemplo n.º 3
0
 /**
  * Create mocks for all $this->_model dependencies
  *
  * @return array
  */
 protected function _getModelDependencies()
 {
     $translator = $this->getMock('stdClass');
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $attributeCollection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false));
     foreach ($this->_attributes as $attributeData) {
         $arguments = $objectManagerHelper->getConstructArguments('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['eavTypeFactory' => $this->getMock('Magento\\Eav\\Model\\Entity\\TypeFactory', [], [], '', false)]);
         $arguments['data'] = $attributeData;
         $attribute = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', $arguments, '', true, true, true, ['_construct']);
         $attributeCollection->addItem($attribute);
     }
     $data = ['translator' => $translator, 'attribute_collection' => $attributeCollection, 'page_size' => 1, 'collection_by_pages_iterator' => 'not_used', 'entity_type_id' => 1, 'customer_collection' => 'not_used'];
     return $data;
 }
Ejemplo n.º 4
0
 public function getGroupCollectionDataProvider()
 {
     $item1 = new \Magento\Framework\Object(['attribute_group_code' => 'recurring-payment']);
     $item2 = new \Magento\Framework\Object(['attribute_group_code' => 'data1']);
     $item3 = new \Magento\Framework\Object(['attribute_group_code' => 'data2']);
     $collection1 = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Core\\Model\\EntityFactory', array(), array(), '', false));
     $collection1->addItem($item1);
     $collection1->addItem($item2);
     $collection2 = clone $collection1;
     $collection3 = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Core\\Model\\EntityFactory', array(), array(), '', false));
     $collection3->addItem($item2);
     $collection3->addItem($item3);
     return [[$collection1, true, 2], [$collection2, false, 1], [$collection3, false, 2]];
 }
Ejemplo n.º 5
0
 /**
  * Retrieve new invoice collection from an array of invoices' data
  *
  * @param array $invoicesData
  * @return \Magento\Framework\Data\Collection
  */
 protected function _getInvoiceCollection(array $invoicesData)
 {
     $className = 'Magento\\Sales\\Model\\Order\\Invoice';
     $result = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Core\\Model\\EntityFactory', array(), array(), '', false));
     $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $arguments = array('orderFactory' => $this->getMock('Magento\\Sales\\Model\\OrderFactory', array(), array(), '', false), 'orderResourceFactory' => $this->getMock('Magento\\Sales\\Model\\Resource\\OrderFactory', array(), array(), '', false), 'calculatorFactory' => $this->getMock('Magento\\Framework\\Math\\CalculatorFactory', array(), array(), '', false), 'invoiceItemCollectionFactory' => $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Invoice\\Item\\CollectionFactory', array(), array(), '', false), 'invoiceCommentFactory' => $this->getMock('Magento\\Sales\\Model\\Order\\Invoice\\CommentFactory', array(), array(), '', false), 'commentCollectionFactory' => $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Invoice\\Comment\\CollectionFactory', array(), array(), '', false));
     foreach ($invoicesData as $oneInvoiceData) {
         $arguments['data'] = $oneInvoiceData;
         $arguments = $objectManagerHelper->getConstructArguments($className, $arguments);
         /** @var $prevInvoice \Magento\Sales\Model\Order\Invoice */
         $prevInvoice = $this->getMock($className, array('_init'), $arguments);
         $result->addItem($prevInvoice);
     }
     return $result;
 }
Ejemplo n.º 6
0
 /**
  * Create mock for abstract customer model class
  *
  * @return \Magento\CustomerImportExport\Model\Import\AbstractCustomer|PHPUnit_Framework_MockObject_MockObject
  */
 protected function _getModelMock()
 {
     $customerCollection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Core\\Model\\EntityFactory', array(), array(), '', false));
     foreach ($this->_customers as $customer) {
         $customerCollection->addItem(new \Magento\Framework\Object($customer));
     }
     $modelMock = $this->getMockBuilder('Magento\\CustomerImportExport\\Model\\Import\\AbstractCustomer')->disableOriginalConstructor()->setMethods(['_getCustomerCollection', '_validateRowForUpdate', '_validateRowForDelete'])->getMockForAbstractClass();
     $property = new \ReflectionProperty($modelMock, '_websiteCodeToId');
     $property->setAccessible(true);
     $property->setValue($modelMock, array_flip($this->_websites));
     $property = new \ReflectionProperty($modelMock, '_availableBehaviors');
     $property->setAccessible(true);
     $property->setValue($modelMock, $this->_availableBehaviors);
     $modelMock->expects($this->any())->method('_getCustomerCollection')->will($this->returnValue($customerCollection));
     return $modelMock;
 }
Ejemplo n.º 7
0
 public function testCountTotalsWithSubItems()
 {
     $this->_model->reset(true);
     $this->_model->setColumn('test4', 'sum');
     $this->_model->setColumn('test5', 'avg');
     // prepare collection
     $collection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false));
     $items = [new \Magento\Framework\DataObject(['children' => new \Magento\Framework\DataObject(['test4' => '1', 'test5' => '2'])]), new \Magento\Framework\DataObject(['children' => new \Magento\Framework\DataObject(['test4' => '1', 'test5' => '2'])]), new \Magento\Framework\DataObject(['children' => new \Magento\Framework\DataObject(['test4' => '1', 'test5' => '2'])])];
     foreach ($items as $item) {
         // prepare sub-collection
         $subCollection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false));
         $subCollection->addItem(new \Magento\Framework\DataObject(['test4' => '1', 'test5' => '2']));
         $subCollection->addItem(new \Magento\Framework\DataObject(['test4' => '2', 'test5' => '2']));
         $item->setChildren($subCollection);
         $collection->addItem($item);
     }
     $expected = new \Magento\Framework\DataObject(['test4' => 9, 'test5' => 2]);
     $this->assertEquals($expected, $this->_model->countTotals($collection));
 }
Ejemplo n.º 8
0
 /**
  * Create mocks for all $this->_model dependencies
  *
  * @return array
  */
 protected function _getModelDependencies()
 {
     $dataSourceModel = $this->getMock('stdClass', ['getNextBunch']);
     $connection = $this->getMock('stdClass');
     $attributeCollection = $this->_createAttrCollectionMock();
     $customerStorage = $this->_createCustomerStorageMock();
     $customerEntity = $this->_createCustomerEntityMock();
     $addressCollection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false));
     foreach ($this->_addresses as $address) {
         $addressCollection->addItem(new \Magento\Framework\Object($address));
     }
     $regionCollection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false));
     foreach ($this->_regions as $region) {
         $regionCollection->addItem(new \Magento\Framework\Object($region));
     }
     $data = ['data_source_model' => $dataSourceModel, 'connection' => $connection, 'page_size' => 1, 'max_data_size' => 1, 'bunch_size' => 1, 'attribute_collection' => $attributeCollection, 'entity_type_id' => 1, 'customer_storage' => $customerStorage, 'customer_entity' => $customerEntity, 'address_collection' => $addressCollection, 'entity_table' => 'not_used', 'region_collection' => $regionCollection];
     return $data;
 }