/** * Test for method filterEntityCollection() * * @magentoDataFixture Magento/Customer/_files/import_export/customers.php */ public function testFilterEntityCollection() { $createdAtDate = '2038-01-01'; /** @var $objectManager \Magento\TestFramework\ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** * Change created_at date of first customer for future filter test. */ $customers = $objectManager->get('Magento\\Framework\\Registry')->registry('_fixture/Magento_ImportExport_Customer_Collection'); $customers[0]->setCreatedAt($createdAtDate); $customers[0]->save(); /** * Change type of created_at attribute. In this case we have possibility to test date rage filter */ $attributeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Resource\\Attribute\\Collection'); $attributeCollection->addFieldToFilter('attribute_code', 'created_at'); /** @var $createdAtAttribute \Magento\Customer\Model\Attribute */ $createdAtAttribute = $attributeCollection->getFirstItem(); $createdAtAttribute->setBackendType('datetime'); $createdAtAttribute->save(); /** * Prepare filter.asd */ $parameters = array(\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP => array('email' => 'example.com', 'created_at' => array($createdAtDate, ''), 'store_id' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\StoreManagerInterface')->getStore()->getId())); $this->_model->setParameters($parameters); /** @var $customers \Magento\Customer\Model\Resource\Customer\Collection */ $collection = $this->_model->filterEntityCollection(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Resource\\Customer\\Collection')); $collection->load(); $this->assertCount(1, $collection); $this->assertEquals($customers[0]->getId(), $collection->getFirstItem()->getId()); }
/** * Test for method exportItem() * * @covers \Magento\CustomerImportExport\Model\Export\Customer::exportItem */ public function testExportItem() { /** @var $writer \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter */ $writer = $this->getMockForAbstractClass('Magento\\ImportExport\\Model\\Export\\Adapter\\AbstractAdapter', [], '', false, false, true, ['writeRow']); $writer->expects($this->once())->method('writeRow')->will($this->returnCallback([$this, 'validateWriteRow'])); $this->_model->setWriter($writer); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $arguments = $objectManagerHelper->getConstructArguments('Magento\\Framework\\Model\\AbstractModel'); $arguments['data'] = $this->_customerData; $item = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', $arguments); $this->_model->exportItem($item); }