Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 protected function processStubRow(Row $row)
 {
     // We stub the uri value ourselves so we can create a real stub file for it.
     if (!$row->getDestinationProperty('uri')) {
         $field_definitions = $this->entityManager->getFieldDefinitions($this->storage->getEntityTypeId(), $this->getKey('bundle'));
         $value = UriItem::generateSampleValue($field_definitions['uri']);
         if (empty($value)) {
             throw new MigrateException('Stubbing failed, unable to generate value for field uri');
         }
         // generateSampleValue() wraps the value in an array.
         $value = reset($value);
         // Make it into a proper public file uri, stripping off the existing
         // scheme if present.
         $value = 'public://' . preg_replace('|^[a-z]+://|i', '', $value);
         $value = Unicode::substr($value, 0, $field_definitions['uri']->getSetting('max_length'));
         // Create a real file, so File::preSave() can do filesize() on it.
         touch($value);
         $row->setDestinationProperty('uri', $value);
     }
     parent::processStubRow($row);
 }
Beispiel #2
0
 /**
  * Helper method to mock all store definitions.
  */
 protected function setupFieldStorageDefinition()
 {
     $id_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $id_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(IntegerItem::schema($id_field_storage_definition));
     $uuid_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $uuid_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(UuidItem::schema($uuid_field_storage_definition));
     $type_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $type_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(StringItem::schema($type_field_storage_definition));
     $langcode_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $langcode_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(LanguageItem::schema($langcode_field_storage_definition));
     $name_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $name_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(StringItem::schema($name_field_storage_definition));
     $description_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $description_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(TextLongItem::schema($description_field_storage_definition));
     $homepage_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $homepage_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(UriItem::schema($homepage_field_storage_definition));
     // Setup the user_id entity reference field.
     $this->entityManager->expects($this->any())->method('getDefinition')->willReturnMap([['user', TRUE, static::userEntityInfo()]]);
     $user_id_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $user_id_field_storage_definition->expects($this->any())->method('getSetting')->with('target_type')->willReturn('user');
     $user_id_field_storage_definition->expects($this->any())->method('getSettings')->willReturn(['target_type' => 'user']);
     $user_id_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(EntityReferenceItem::schema($user_id_field_storage_definition));
     $revision_id_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
     $revision_id_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(IntegerItem::schema($revision_id_field_storage_definition));
     $this->entityManager->expects($this->any())->method('getFieldStorageDefinitions')->willReturn(['id' => $id_field_storage_definition, 'uuid' => $uuid_field_storage_definition, 'type' => $type_field_storage_definition, 'langcode' => $langcode_field_storage_definition, 'name' => $name_field_storage_definition, 'description' => $description_field_storage_definition, 'homepage' => $homepage_field_storage_definition, 'user_id' => $user_id_field_storage_definition, 'revision_id' => $revision_id_field_storage_definition]);
 }