/** * Test export method * * @magentoDataFixture Magento/Customer/_files/import_export/customers.php */ public function testExport() { $expectedAttributes = array(); /** @var $collection \Magento\Customer\Model\Resource\Attribute\Collection */ $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Resource\\Attribute\\Collection'); /** @var $attribute \Magento\Customer\Model\Attribute */ foreach ($collection as $attribute) { $expectedAttributes[] = $attribute->getAttributeCode(); } $expectedAttributes = array_diff($expectedAttributes, $this->_model->getDisabledAttributes()); $this->_model->setWriter(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\ImportExport\\Model\\Export\\Adapter\\Csv')); $data = $this->_model->export(); $this->assertNotEmpty($data); $lines = $this->_csvToArray($data, 'email'); $this->assertEquals(count($expectedAttributes), count(array_intersect($expectedAttributes, $lines['header'])), 'Expected attribute codes were not exported'); $this->assertNotEmpty($lines['data'], 'No data was exported'); /** @var $objectManager \Magento\TestFramework\ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var $customers \Magento\Customer\Model\Customer[] */ $customers = $objectManager->get('Magento\\Framework\\Registry')->registry('_fixture/Magento_ImportExport_Customer_Collection'); foreach ($customers as $key => $customer) { foreach ($expectedAttributes as $code) { if (!in_array($code, $this->_model->getDisabledAttributes()) && isset($lines[$key][$code])) { $this->assertEquals($customer->getData($code), $lines[$key][$code], 'Attribute "' . $code . '" is not equal'); } } } }
/** * 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); }