public function testGetValues()
 {
     $expected = [1, 2, 3];
     $this->source->expects($this->once())->method('getAllOptions')->with(true, true)->willReturn($expected);
     $this->attribute->expects($this->once())->method('getSource')->willReturn($this->source);
     $this->swatch->expects($this->once())->method('getData')->with('entity_attribute')->willReturn($this->attribute);
     $method = new \ReflectionMethod('Magento\\Swatches\\Model\\Form\\Element\\AbstractSwatch', 'getValues');
     $method->setAccessible(true);
     $this->assertEquals($expected, $method->invoke($this->swatch));
 }
Example #2
0
 /**
  * Get option as hash
  *
  * @param \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource $sourceModel
  * @return array
  */
 private function getOptions(\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource $sourceModel)
 {
     $result = [];
     foreach ($sourceModel->getAllOptions() as $option) {
         if ($option['value'] != '') {
             $result[] = $option;
         }
     }
     return $result;
 }
 /**
  * Check whether attribute instance (attribute, backend, frontend or source) has method and applicable
  *
  * @param AbstractAttribute|\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend|\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend|\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource $instance
  * @param string $method
  * @param array $args array of arguments
  * @return boolean
  */
 protected function _isCallableAttributeInstance($instance, $method, $args)
 {
     if ($instance instanceof \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend && ($method == 'beforeSave' || $method == 'afterSave')) {
         $attributeCode = $instance->getAttribute()->getAttributeCode();
         if (isset($args[0]) && $args[0] instanceof \Magento\Framework\DataObject && $args[0]->getData($attributeCode) === false) {
             return false;
         }
     }
     return parent::_isCallableAttributeInstance($instance, $method, $args);
 }
 public function testAfterAfterSaveNotSwatchAttribute()
 {
     $this->abstractSource->expects($this->once())->method('getAllOptions')->willReturn($this->allOptions);
     $this->swatch->expects($this->once())->method('getId')->willReturn(1);
     $this->swatch->expects($this->once())->method('save');
     $this->swatch->expects($this->once())->method('isDeleted')->with(false);
     $this->swatch->expects($this->exactly(2))->method('setData')->withConsecutive(['type', Swatch::SWATCH_TYPE_TEXTUAL], ['value', null]);
     $this->collection->expects($this->exactly(2))->method('addFieldToFilter')->withConsecutive(['option_id', self::OPTION_ID], ['store_id', self::OPTION_ID])->willReturnSelf();
     $this->collection->expects($this->once())->method('getFirstItem')->willReturn($this->swatch);
     $this->collectionFactory->expects($this->once())->method('create')->willReturn($this->collection);
     $this->attribute->expects($this->at(0))->method('getData')->with('option')->willReturn($this->optionIds);
     $this->attribute->expects($this->at(1))->method('getSource')->willReturn($this->abstractSource);
     $this->attribute->expects($this->at(2))->method('getData')->with('swatch/value')->willReturn([self::STORE_ID => [self::OPTION_ID => null]]);
     $this->attribute->expects($this->at(3))->method('getData')->with('option/delete/' . self::OPTION_ID)->willReturn(false);
     $this->swatchHelper->expects($this->exactly(2))->method('isSwatchAttribute')->with($this->attribute)->will($this->onConsecutiveCalls(true, false));
     $this->swatchHelper->expects($this->once())->method('isVisualSwatch')->with($this->attribute)->willReturn(false);
     $this->swatchHelper->expects($this->once())->method('isTextSwatch')->with($this->attribute)->willReturn(true);
     $this->eavAttribute->afterAfterSave($this->attribute);
 }
Example #5
0
 /**
  * Get a text for index option value
  *
  * @param  string|int $value
  * @return string|bool
  */
 public function getIndexOptionText($value)
 {
     switch ($value) {
         case self::VALUE_YES:
             return 'Yes';
         case self::VALUE_NO:
             return 'No';
     }
     return parent::getIndexOptionText($value);
 }