/**
  * Test for methods _addAttributeValuesToRow()
  *
  * @covers \Magento\ImportExport\Model\Export\Entity\AbstractEav::_initAttributeValues
  * @covers \Magento\ImportExport\Model\Export\Entity\AbstractEav::_addAttributeValuesToRow
  */
 public function testAddAttributeValuesToRow()
 {
     $testAttributeCode = 'lastname';
     $testAttributeValue = 'value';
     $testAttributeOptions = ['value' => 'option'];
     /** @var $testAttribute \Magento\Eav\Model\Entity\Attribute */
     $testAttribute = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], '', false, false, false, ['__wakeup']);
     $testAttribute->setAttributeCode($testAttributeCode);
     $this->_model->expects($this->any())->method('getAttributeCollection')->will($this->returnValue([$testAttribute]));
     $this->_model->expects($this->any())->method('getAttributeOptions')->will($this->returnValue($testAttributeOptions));
     /** @var $item \Magento\Framework\Model\AbstractModel|\PHPUnit_Framework_MockObject_MockObject */
     $item = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [], '', false, true, true, ['getData', '__wakeup']);
     $item->expects($this->any())->method('getData')->will($this->returnValue($testAttributeValue));
     $method = new \ReflectionMethod($this->_model, '_initAttributeValues');
     $method->setAccessible(true);
     $method->invoke($this->_model);
     $method = new \ReflectionMethod($this->_model, '_addAttributeValuesToRow');
     $method->setAccessible(true);
     $row = $method->invoke($this->_model, $item);
     /**
      *  Prepare expected data
      */
     $expected = [];
     foreach ($this->_expectedAttributes as $code) {
         $expected[$code] = $testAttributeValue;
         if ($code == $testAttributeCode) {
             $expected[$code] = $testAttributeOptions[$expected[$code]];
         }
     }
     $this->assertEquals($expected, $row, 'Attributes were not added to result row');
 }
 /**
  * Test for method getAttributeOptions()
  */
 public function testGetAttributeOptions()
 {
     /** @var $attributeCollection \Magento\Customer\Model\ResourceModel\Attribute\Collection */
     $attributeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\ResourceModel\\Attribute\\Collection');
     $attributeCollection->addFieldToFilter('attribute_code', 'gender');
     /** @var $attribute \Magento\Customer\Model\Attribute */
     $attribute = $attributeCollection->getFirstItem();
     $expectedOptions = [];
     foreach ($attribute->getSource()->getAllOptions(false) as $option) {
         $expectedOptions[$option['value']] = $option['label'];
     }
     $actualOptions = $this->_model->getAttributeOptions($attribute);
     $this->assertEquals($expectedOptions, $actualOptions);
 }
Пример #3
0
 /**
  * Set parameters (push filters from post into export customer model)
  *
  * @param array $parameters
  * @return $this
  */
 public function setParameters(array $parameters)
 {
     //  push filters from post into export customer model
     $this->_customerEntity->setParameters($parameters);
     $this->_initCustomers();
     return parent::setParameters($parameters);
 }
Пример #4
0
 /**
  * Clean up already loaded attribute collection.
  *
  * @param \Magento\Framework\Data\Collection $collection
  * @return \Magento\Framework\Data\Collection
  */
 public function filterAttributeCollection(\Magento\Framework\Data\Collection $collection)
 {
     /** @var $attribute \Magento\Customer\Model\Attribute */
     foreach (parent::filterAttributeCollection($collection) as $attribute) {
         if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) {
             $data = $this->_attributeOverrides[$attribute->getAttributeCode()];
             if (isset($data['options_method']) && method_exists($this, $data['options_method'])) {
                 $data['filter_options'] = $this->{$data['options_method']}();
             }
             $attribute->addData($data);
         }
     }
     return $collection;
 }