Skip to content
Snippets Groups Projects
Select Git revision
  • 0c63d9e24fcaef1f3cb09823d5765e7fb48bc89e
  • 11.x default protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.2.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

schema.inc

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    EntityReferenceRdfaTest.php 2.57 KiB
    <?php
    /**
     * @file
     * Contains \Drupal\rdf\Tests\Field\TaxonomyTermReferenceRdfaTest.
     */
    
    namespace Drupal\rdf\Tests\Field;
    
    use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
    use Drupal\user\Entity\Role;
    use Drupal\user\RoleInterface;
    
    /**
     * Tests the RDFa output of the entity reference field formatter.
     *
     * @group rdf
     */
    class EntityReferenceRdfaTest extends FieldRdfaTestBase {
    
      use EntityReferenceTestTrait;
    
      /**
       * {@inheritdoc}
       */
      protected $fieldType = 'entity_reference';
    
      /**
       * The entity type used in this test.
       *
       * @var string
       */
      protected $entityType = 'entity_test';
    
      /**
       * The bundle used in this test.
       *
       * @var string
       */
      protected $bundle = 'entity_test';
    
      /**
       * The term for testing.
       *
       * @var \Drupal\taxonomy\Entity\Term
       */
      protected $targetEntity;
    
      /**
       * {@inheritdoc}
       */
      public static $modules = array('entity_reference', 'text', 'filter');
    
      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);
      }
    
      /**
       * Tests all the entity reference formatters.
       */
      public function testAllFormatters() {
        $entity_uri = $this->getAbsoluteUri($this->targetEntity);
    
        // Tests the label formatter.
        $this->assertFormatterRdfa(array('type' => 'entity_reference_label'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri'));
        // Tests the entity formatter.
        $this->assertFormatterRdfa(array('type' => 'entity_reference_entity_view'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri'));
      }
    
    }