/**
  * Normalize available locales
  *
  * @param AbstractAttribute $attribute
  *
  * @return array
  */
 protected function normalizeAvailableLocales(AbstractAttribute $attribute)
 {
     $locales = array();
     foreach ($attribute->getAvailableLocales() as $locale) {
         $locales[] = $locale->getCode();
     }
     return $locales;
 }
 /**
  * Test get/add/remove availableLocales property
  *
  * TODO : Add more tests
  */
 public function testGetAddRemoveAvailableLocales()
 {
     $this->assertNull($this->attribute->getAvailableLocales());
     // Change value and assert new
     $newLocale = new Locale();
     $this->attribute->addAvailableLocale($newLocale);
     $this->assertInstanceOf('Pim\\Bundle\\CatalogBundle\\Entity\\Locale', $this->attribute->getAvailableLocales()->first());
     $this->assertCount(1, $this->attribute->getAvailableLocales());
     $this->attribute->removeAvailableLocale($newLocale);
     $this->assertNull($this->attribute->getAvailableLocales());
 }
 /**
  * {@inheritdoc}
  */
 protected function normalizeAvailableLocales(AbstractAttribute $attribute)
 {
     $availableLocales = $attribute->getAvailableLocales();
     if ($availableLocales) {
         $availableLocales = $availableLocales->map(function ($locale) {
             return $locale->getCode();
         })->toArray();
         $availableLocales = implode(self::ITEM_SEPARATOR, $availableLocales);
     }
     return $availableLocales ?: self::ALL_LOCALES;
 }
 /**
  * Filter expected values based on the locales available for the provided attribute
  *
  * @param AbstractAttribute $attribute
  * @param array             $values
  *
  * @return array
  */
 protected function filterExpectedValues(AbstractAttribute $attribute, array $values)
 {
     if ($attribute->getAvailableLocales()) {
         $availableLocales = $attribute->getAvailableLocales()->map(function ($locale) {
             return $locale->getCode();
         })->toArray();
         foreach ($values as $index => $value) {
             if ($value['locale'] && !in_array($value['locale'], $availableLocales)) {
                 unset($values[$index]);
             }
         }
     }
     return $values;
 }