Пример #1
0
 public function setUp()
 {
     parent::setUp();
     // Enables anonymous user comments.
     user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array('access comments' => TRUE, 'post comments' => TRUE, 'skip comment approval' => TRUE));
     // Allows anonymous to leave their contact information.
     $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT);
     $this->setCommentPreview(DRUPAL_OPTIONAL);
     $this->setCommentForm(TRUE);
     $this->setCommentSubject(TRUE);
     $this->setCommentSettings('comment_default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
     // Prepares commonly used URIs.
     $this->base_uri = url('<front>', array('absolute' => TRUE));
     $this->node_uri = url('node/' . $this->node->id(), array('absolute' => TRUE));
     // Set relation between node and comment.
     $article_mapping = rdf_get_mapping('node', 'article');
     $comment_count_mapping = array('properties' => array('sioc:num_replies'), 'datatype' => 'xsd:integer', 'datatype_callback' => array('callable' => 'Drupal\\rdf\\CommonDataConverter::rawValue'));
     $article_mapping->setFieldMapping('comment_count', $comment_count_mapping)->save();
     // Save user mapping.
     $user_mapping = rdf_get_mapping('user', 'user');
     $username_mapping = array('properties' => array('foaf:name'));
     $user_mapping->setFieldMapping('name', $username_mapping)->save();
     $user_mapping->setFieldMapping('homepage', array('properties' => array('foaf:page'), 'mapping_type' => 'rel'))->save();
     // Save comment mapping.
     $mapping = rdf_get_mapping('comment', 'comment');
     $mapping->setBundleMapping(array('types' => array('sioc:Post', 'sioct:Comment')))->save();
     $field_mappings = array('subject' => array('properties' => array('dc:title')), 'created' => array('properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', 'datatype_callback' => array('callable' => 'date_iso8601')), 'changed' => array('properties' => array('dc:modified'), 'datatype' => 'xsd:dateTime', 'datatype_callback' => array('callable' => 'date_iso8601')), 'comment_body' => array('properties' => array('content:encoded')), 'pid' => array('properties' => array('sioc:reply_of'), 'mapping_type' => 'rel'), 'uid' => array('properties' => array('sioc:has_creator'), 'mapping_type' => 'rel'), 'name' => array('properties' => array('foaf:name')));
     // Iterate over shared field mappings and save.
     foreach ($field_mappings as $field_name => $field_mapping) {
         $mapping->setFieldMapping($field_name, $field_mapping)->save();
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $this->vocabulary = $this->createVocabulary();
     // RDF mapping - term bundle.
     rdf_get_mapping('taxonomy_term', $this->vocabulary->id())->setBundleMapping(array('types' => array('skos:Concept')))->setFieldMapping('name', array('properties' => array('rdfs:label', 'skos:prefLabel')))->save();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->createTestField();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:link')))->save();
 }
Пример #4
0
 protected function setUp()
 {
     parent::setUp();
     $this->createTestField();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:dateCreated')))->save();
     // Set up test entity.
     $this->entity = EntityTest::create(array());
     $this->entity->{$this->fieldName}->value = $this->testValue;
 }
Пример #5
0
 protected function setUp()
 {
     parent::setUp();
     $this->createTestField();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:email')))->save();
     // Set up test values.
     $this->testValue = '*****@*****.**';
     $this->entity = entity_create('entity_test', array());
     $this->entity->{$this->fieldName}->value = $this->testValue;
 }
 public function setUp()
 {
     parent::setUp();
     $this->createTestField();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:telephone')))->save();
     // Set up test values.
     $this->testValue = '555-555-5555';
     $this->entity = entity_create('entity_test', array());
     $this->entity->{$this->fieldName}->value = $this->testValue;
 }
Пример #7
0
 public function setUp()
 {
     parent::setUp();
     $this->createTestField();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:text')))->save();
     // Set up test entity.
     $this->entity = entity_create('entity_test');
     $this->entity->{$this->fieldName}->value = $this->testValue;
     $this->entity->{$this->fieldName}->summary = $this->testSummary;
 }
 protected function setUp()
 {
     parent::setUp();
     $web_user = $this->drupalCreateUser(array('bypass node access', 'administer taxonomy'));
     $this->drupalLogin($web_user);
     $this->vocabulary = $this->createVocabulary();
     // Create the field.
     $this->fieldName = 'field_taxonomy_test';
     $this->createTaxonomyTermReferenceField($this->fieldName, $this->vocabulary);
     // Set the RDF mapping for the new field.
     rdf_get_mapping('node', 'article')->setFieldMapping($this->fieldName, array('properties' => array('dc:subject'), 'mapping_type' => 'rel'))->save();
     rdf_get_mapping('taxonomy_term', $this->vocabulary->id())->setBundleMapping(array('types' => array('skos:Concept')))->setFieldMapping('name', array('properties' => array('rdfs:label')))->save();
 }
Пример #9
0
 /**
  * Test the handling of field mappings.
  */
 function testFieldMapping()
 {
     $field_name = 'created';
     // Test that the field mapping can be saved.
     $mapping = array('properties' => array('dc:created'), 'datatype' => 'xsd:dateTime', 'datatype_callback' => array('callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value'));
     rdf_get_mapping($this->entityType, $this->bundle)->setFieldMapping($field_name, $mapping)->save();
     $field_mapping = rdf_get_mapping($this->entityType, $this->bundle)->getFieldMapping($field_name);
     $this->assertEqual($mapping, $field_mapping, 'Field mapping saved.');
     // Test that the field mapping can be edited.
     $mapping = array('properties' => array('dc:date'), 'datatype' => 'foo:bar', 'datatype_callback' => array('callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value'));
     rdf_get_mapping($this->entityType, $this->bundle)->setFieldMapping($field_name, $mapping)->save();
     $field_mapping = rdf_get_mapping($this->entityType, $this->bundle)->getFieldMapping($field_name);
     $this->assertEqual($mapping, $field_mapping, 'Field mapping updated.');
 }
 public function setUp()
 {
     parent::setUp();
     $this->createTestField();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:interactionCount'), 'datatype_callback' => array('callable' => 'Drupal\\rdf\\Tests\\Field\\TestDataConverter::convertFoo')))->save();
     // Set up test values.
     $this->test_value = $this->randomName();
     $this->entity = entity_create('entity_test');
     $this->entity->{$this->fieldName}->value = $this->test_value;
     $this->entity->save();
     $this->uri = $this->getAbsoluteUri($this->entity);
 }
Пример #11
0
  /**
   * Saves Schema.org mappings in \Drupal\node\NodeTypeForm.
   */
  public static function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form_state->hasValue('types')) {
      $entity_type = $form_state->getFormObject()->getEntity();
      $mapping = rdf_get_mapping('node', $entity_type->id());
      if ($entity_type->isNew()) {
        $mapping = rdf_get_mapping('node', $form_state->getValue('types'));
      }

      if ($form_state->hasValue('types')) {
        $mapping->setBundleMapping(array('types' => array($form_state->getValue('types'))))
          ->save();
      }
    }
  }
 protected function setUp()
 {
     parent::setUp();
     $this->fieldName = 'field_image';
     // Create the image field.
     $this->createImageField($this->fieldName, 'article');
     // Set the RDF mapping for the new field.
     rdf_get_mapping('node', 'article')->setFieldMapping($this->fieldName, array('properties' => array('og:image'), 'mapping_type' => 'rel'))->setBundleMapping(array('types' => array()))->save();
     // Get the test image that simpletest provides.
     $image = current($this->drupalGetTestFiles('image'));
     // Save a node with the image.
     $nid = $this->uploadNodeImage($image, $this->fieldName, 'article', $this->randomMachineName());
     $this->node = Node::load($nid);
     $this->file = file_load($this->node->{$this->fieldName}->target_id);
 }
 protected function setUp()
 {
     parent::setUp();
     $web_user = $this->drupalCreateUser(array('bypass node access', 'administer taxonomy'));
     $this->drupalLogin($web_user);
     $this->vocabulary = $this->createVocabulary();
     // Create the field.
     $this->fieldName = 'field_taxonomy_test';
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'article', 'default')->setComponent($this->fieldName, array('type' => 'options_select'))->save();
     entity_get_display('node', 'article', 'full')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save();
     // Set the RDF mapping for the new field.
     rdf_get_mapping('node', 'article')->setFieldMapping($this->fieldName, array('properties' => array('dc:subject'), 'mapping_type' => 'rel'))->save();
     rdf_get_mapping('taxonomy_term', $this->vocabulary->id())->setBundleMapping(array('types' => array('skos:Concept')))->setFieldMapping('name', array('properties' => array('rdfs:label')))->save();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->fieldName = strtolower($this->randomMachineName());
     $type_name = 'article';
     $this->createFileField($this->fieldName, 'node', $type_name);
     // Set the teaser display to show this field.
     entity_get_display('node', 'article', 'teaser')->setComponent($this->fieldName, array('type' => 'file_default'))->save();
     // Set the RDF mapping for the new field.
     $mapping = rdf_get_mapping('node', 'article');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('rdfs:seeAlso'), 'mapping_type' => 'rel'))->save();
     $test_file = $this->getTestFile('text');
     // Create a new node with the uploaded file.
     $nid = $this->uploadNodeFile($test_file, $this->fieldName, $type_name);
     $this->node = node_load($nid, TRUE);
     $this->file = file_load($this->node->{$this->fieldName}->target_id);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     entity_reference_create_field($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType);
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:knows')))->save();
     // Create the entity to be referenced.
     $this->target_entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
     $this->target_entity->save();
     // Create the entity that will have the entity reference field.
     $this->entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
     $this->entity->save();
     $this->entity->{$this->fieldName}->entity = $this->target_entity;
     $this->entity->{$this->fieldName}->access = TRUE;
     $this->uri = $this->getAbsoluteUri($this->entity);
 }
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $vocabulary->save();
     entity_create('field_storage_config', array('name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'entity_test'))->save();
     $this->term = entity_create('taxonomy_term', array('name' => $this->randomName(), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->term->save();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:about')))->save();
     // Set up test values.
     $this->entity = entity_create('entity_test');
     $this->entity->{$this->fieldName}->target_id = $this->term->id();
     $this->entity->save();
     $this->uri = $this->getAbsoluteUri($this->entity);
 }
Пример #17
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     // Give anonymous users permission to view test entities.
     $this->installConfig(array('user'));
     Role::load(RoleInterface::ANONYMOUS_ID)->grantPermission('view test entity')->save();
     $this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType);
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:knows')))->save();
     // Create the entity to be referenced.
     $this->targetEntity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
     $this->targetEntity->save();
     // Create the entity that will have the entity reference field.
     $this->entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
     $this->entity->save();
     $this->entity->{$this->fieldName}->entity = $this->targetEntity;
     $this->uri = $this->getAbsoluteUri($this->entity);
 }
Пример #18
0
  /**
   * Tests editing a node type using the UI.
   */
  protected function testNodeTypeEditing() {
    $web_user = $this->drupalCreateUser(array(
      'bypass node access',
      'administer content types',
      'administer node fields',
    ));
    $this->drupalLogin($web_user);

    $edit_type = 'admin/structure/types/manage/page';
    // Verify that title and body fields are displayed.
    $this->drupalGet($edit_type);
    $this->assertRaw('Schema.org Mappings', 'Schema.Org tab found.');
    $this->assertRaw('Schema.org Type', 'Schema.Org tab content found.');

    // Change the rdf mapping.
    $edit = array(
      'types' => 'schema:Person',
    );
    $this->drupalPostForm($edit_type, $edit, t('Save content type'));
    $mapping = rdf_get_mapping('node', 'page');
    $type = $mapping->getBundleMapping();
    $this->assertEqual($type['types'][0], $edit['types'], 'Content mapping saved correctly.');
  }
Пример #19
0
  /**
   * Tests FieldMappingForm for content type mapped to a RDF type.
   */
  protected function testMappedTypeFieldUI() {
    $mapping = rdf_get_mapping('node', $this->type);
    $mapping->setBundleMapping(array('types' => array("schema:Person")))
      ->save();

    $manage_fields = 'admin/structure/types/manage/' . $this->type;
    $rdf_mappings = $manage_fields . '/fields/rdf';

    // Create a field, and a node with some data for the field.
    $label = 'Test field';
    $this->fieldUIAddNewField($manage_fields, 'test', $label, 'text');

    // Display the "Manage fields RDF" screen and check that the expected fields
    // are displayed.
    $this->drupalGet($rdf_mappings);
    $this->assertFieldByXPath('//table[@id="rdf-mapping"]//tr/td[1]', $label, 'Field is displayed in manage field RDF page.');

    $this->assertFieldByXPath('//table[@id="rdf-mapping"]//tr[@id="field-test"]/td[4]', 'Unmapped', 'Status displayed correctly when field is unmapped.');

    // Add RDF property and save.
    $mapped_value = 'schema:birthDate';
    $edit = array('fields[field_test][rdf-predicate]' => $mapped_value);
    $this->drupalPostForm($rdf_mappings, $edit, t('Save'));
    $this->assertRaw(t('Your settings have been saved.'), 'Manage Field RDF page reloaded.');
    $this->assertFieldByXPath('//table[@id="rdf-mapping"]//tr[@id="field-test"]/td[4]', 'Mapped', 'Status displayed correctly when field is mapped.');

    $mapping = rdf_get_mapping('node', $this->type);
    $bundle_mapping = $mapping->getFieldMapping('field_test');
    $this->assertEqual($bundle_mapping['properties'][0], $mapped_value, "Selected RDF mappings saved.");
  }
 /**
  * Helper function to test attribute generation.
  *
  * @param array $expected_attributes
  *   The expected return of rdf_rdfa_attributes.
  * @param array $field_mapping
  *   The field mapping to merge into the RDF mapping config.
  * @param mixed $data
  *   The data to pass into the datatype callback, if specified.
  */
 protected function _testAttributes($expected_attributes, $field_mapping, $data = NULL)
 {
     $mapping = rdf_get_mapping('node', 'article')->setFieldMapping('field_test', $field_mapping)->getPreparedFieldMapping('field_test');
     $attributes = rdf_rdfa_attributes($mapping, $data);
     ksort($expected_attributes);
     ksort($attributes);
     $this->assertEqual($expected_attributes, $attributes);
 }
 /**
  * Creates the RDF mapping for the field.
  */
 protected function createTestEntity($testValue)
 {
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:baseSalary')))->save();
     // Set up test entity.
     $this->entity = entity_create('entity_test', array());
     $this->entity->{$this->fieldName}->value = $testValue;
 }
Пример #22
0
 public function setUp()
 {
     parent::setUp();
     rdf_get_mapping('user', 'user')->setBundleMapping(array('types' => array('sioc:UserAccount')))->setFieldMapping('name', array('properties' => array('foaf:name')))->save();
 }
Пример #23
0
 protected function setUp()
 {
     parent::setUp();
     rdf_get_mapping('node', 'article')->setBundleMapping(array('types' => array('sioc:Item', 'foaf:Document')))->setFieldMapping('title', array('properties' => array('dc:title')))->setFieldMapping('created', array('properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', 'datatype_callback' => array('callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value')))->save();
 }
Пример #24
0
 public function setUp()
 {
     parent::setUp();
     rdf_get_mapping('node', 'article')->setBundleMapping(array('types' => array('sioc:Item', 'foaf:Document')))->setFieldMapping('title', array('properties' => array('dc:title')))->setFieldMapping('created', array('properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', 'datatype_callback' => array('callable' => 'date_iso8601')))->save();
 }
Пример #25
0
  /**
   * @inheritdoc
   *
   * Final submit handler- gather all data together and create new content type.
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->prefix = $this->randomString(4);
    $this->properties = array();
    foreach ($form_state->getValue('fields') as $key => $property) {
      if ($property['enable'] == 1) {
        $this->properties[$key] = $property;
      }
    }

    $page_one_values = $form_state->get(['page_values', 1]);
    $rdf_type = $page_one_values['rdf-type'];

    $this->createNodeType($rdf_type);

    $this->rdfMapping = rdf_get_mapping('node', $this->entity->id());
    $this->rdfMapping->setBundleMapping(array('types' => array($rdf_type)));

    $this->createField();
    $this->rdfMapping->save();

    drupal_set_message($this->t('Content Type %label created', array('%label' => $this->entity->label())));
    /*@TODO Revert all saved content type and fields in case of error*/
    $form_state->setRedirectUrl(new Url('entity.node.field_ui_fields', array(
      'node_type' => $this->entity->id(),
    )));
  }
Пример #26
0
 /**
  * Tests field item attributes.
  */
 public function testFieldItemAttributes()
 {
     // Make sure the test field will be rendered.
     entity_get_display('entity_test', 'entity_test', 'default')->setComponent('field_test_text', array('type' => 'text_default'))->save();
     // Create an entity and save test value in field_test_text.
     $test_value = $this->randomMachineName();
     $entity = entity_create('entity_test');
     $entity->field_test_text = $test_value;
     $entity->save();
     // Browse to the entity and verify that the attribute is rendered in the
     // field item HTML markup.
     $this->drupalGet('entity_test/' . $entity->id());
     $xpath = $this->xpath('//div[@data-field-item-attr="foobar"]/p[text()=:value]', array(':value' => $test_value));
     $this->assertTrue($xpath, 'The field item attribute has been found in the rendered output of the field.');
     // Enable the RDF module to ensure that two modules can add attributes to
     // the same field item.
     \Drupal::service('module_installer')->install(array('rdf'));
     $this->resetAll();
     // Set an RDF mapping for the field_test_text field. This RDF mapping will
     // be turned into RDFa attributes in the field item output.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping('field_test_text', array('properties' => array('schema:text')))->save();
     // Browse to the entity and verify that the attributes from both modules
     // are rendered in the field item HTML markup.
     $this->drupalGet('entity_test/' . $entity->id());
     $xpath = $this->xpath('//div[@data-field-item-attr="foobar" and @property="schema:text"]/p[text()=:value]', array(':value' => $test_value));
     $this->assertTrue($xpath, 'The field item attributes from both modules have been found in the rendered output of the field.');
 }
Пример #27
0
  /**
   * Overrides \Drupal\field_ui\FormDisplayOverview::submitForm().
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    $form_values = $form_state->getValue('fields');
    $mapping = rdf_get_mapping($this->entityTypeId, $this->bundle);

    // Add mapping for title field.
    if ($this->entityTypeId === 'node') {
      $type = $mapping->getFieldMapping('title');
      if (empty($type)) {
        $mapping->setFieldMapping('title', array(
            'properties' => array('schema:name'),
          )
        );
      }
    }

    foreach ($form_values as $key => $value) {
      $mapping->setFieldMapping($key, array(
          'properties' => array($value['rdf-predicate']),
        )
      );
    }
    $mapping->save();

    drupal_set_message($this->t('Your settings have been saved.'));
  }