/** * Test related method */ public function testConstruct() { $this->assertEntity($this->attribute); $this->assertEmptyCollection($this->attribute->getOptions()); $this->assertNull($this->attribute->getAvailableLocales()); $this->assertEmptyCollection($this->attribute->getTranslations()); $this->assertFalse($this->attribute->isRequired()); $this->assertFalse($this->attribute->isUnique()); $this->assertNull($this->attribute->getDefaultValue()); $this->assertFalse($this->attribute->isLocalizable()); $this->assertFalse($this->attribute->isScopable()); $this->assertFalse($this->attribute->isUseableAsGridColumn()); $this->assertFalse($this->attribute->isUseableAsGridFilter()); $this->assertNull($this->attribute->isDecimalsAllowed()); $this->assertNull($this->attribute->isNegativeAllowed()); }
/** * {@inheritdoc} */ public function guessConstraints(AbstractAttribute $attribute) { $constraints = array(); if ($attribute->isUnique()) { $constraints[] = new UniqueValue(); } return $constraints; }
/** * Get normalized unquie value for attribute * @param AbstractAttribute $attribute * * @return string */ protected function getNormalizedUnique(AbstractAttribute $attribute) { return $attribute->isUnique() ? '1' : '0'; }
/** * Ensure indexes from attribute if needed * * @param AbstractAttribute $attribute */ public function ensureIndexesFromAttribute(AbstractAttribute $attribute) { if ($attribute->isUseableAsGridFilter() || AbstractProduct::IDENTIFIER_TYPE === $attribute->getAttributeType() || $attribute->isUnique()) { $this->indexCreator->ensureIndexesFromAttribute($attribute); } }
function it_generates_attribute_indexes_when_saving_unique_attribute($collection, $namingUtility, AbstractAttribute $ean) { $ean->getCode()->willReturn('ean'); $ean->getBackendType()->willReturn('varchar'); $ean->isLocalizable()->willReturn(false); $ean->isScopable()->willReturn(false); $ean->isUnique()->willReturn(true); $ean->isUseableAsGridFilter()->willReturn(false); $ean->getAttributeType()->willReturn('pim_catalog_text'); $options = ['background' => true, 'w' => 0]; $namingUtility->getAttributeNormFields($ean)->willReturn(['normalizedData.ean']); $collection->ensureIndex(['normalizedData.ean' => 1], $options)->shouldBeCalled(); $this->ensureIndexesFromAttribute($ean); }
function it_removes_indexes_for_attribute_when_removing_it($indexPurger, AbstractAttribute $name, LifecycleEventArgs $args) { $name->isUseableAsGridFilter()->willReturn(true); $name->getAttributeType()->willReturn('pim_catalog_text'); $name->isUnique()->willReturn(false); $args->getEntity()->willReturn($name); $indexPurger->purgeIndexesFromAttribute($name)->shouldBeCalled(); $this->postRemove($args); }