Skip to content
Snippets Groups Projects
Select Git revision
  • 5ba7b026c0baeae9b293934a752ea03442a2c38c
  • 4.x default
  • 3.x
  • 2.x
  • 8.x-1.x
  • 7.x-1.x
  • 4.1.0
  • 4.0.12
  • 4.0.11
  • 4.0.10
  • 4.0.9
  • 4.0.8
  • 4.0.7
  • 4.0.6
  • previous/3228271-broken-link-check/2021-08-20
  • 4.0.5
  • 4.0.4
  • 4.0.3
  • 4.0.2
  • 4.0.1
  • 4.0.0-alpha3
  • 4.0.0-alpha2
  • 4.0.0-alpha1
  • 3.0.2
  • 3.0.1
  • 3.0.0
26 results

TypedEntityExampleWebTestCase.php

Blame
  • user avatar
    Issue #10: Use module invoke from xautoload
    Mateu Aguiló Bosch authored
    5ba7b026
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    TypedEntityExampleWebTestCase.php 2.20 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\typed_entity_example\Tests\TypedEntityExampleWebTestCase
     */
    
    namespace Drupal\typed_entity_example\Tests;
    
    use Drupal\typed_entity\TypedEntity\TypedEntityManager;
    
    class TypedEntityExampleWebTestCase extends \DrupalWebTestCase {
    
      /**
       * Declare test information.
       *
       * @return array
       *   The information array.
       */
      public static function getInfo() {
        return array(
          'name' => 'Typed entity example (functional)',
          'description' => 'Functional tests for Typed Entity.',
          'group' => 'Typed Entity',
        );
      }
    
      /**
       * Set up.
       */
      protected function setUp() {
        parent::setUp('typed_entity_example');
      }
    
      /**
       * Test factory.
       */
      public function testFactory() {
        $article = $this->drupalCreateNode(array(
          'type' => 'article',
          'title' => 'Test article',
        ));
        $typed_article = TypedEntityManager::create('node', $article);
        $reflection_article = new \ReflectionClass($typed_article);
        if ($reflection_article->name == 'Drupal\typed_entity_example\TypedEntity\Node\Article') {
          $this->pass('The hook_typed_entity_registry_info is taking precedence.');
        }
        else {
          $this->fail('The hook_typed_entity_registry_info is not taking precedence.');
        }
    
        // Test the fallback to the TypedNode.
        $page = $this->drupalCreateNode(array(
          'type' => 'page',
          'title' => 'Test article',
        ));
        $typed_page = TypedEntityManager::create('node', $page);
    
        $reflection_page = new \ReflectionClass($typed_page);
        if ($reflection_page->name == 'Drupal\typed_entity_example\TypedEntity\TypedNode') {
          $this->pass('The factory is falling back to TypedNode.');
        }
        else {
          $this->fail('The factory is not falling back to TypedNode.');
        }
    
        // Test the fallback to TypedEntity.
        $account = $this->drupalCreateUser();
        $typed_user = TypedEntityManager::create('user', $account);
        $reflection_user = new \ReflectionClass($typed_user);
        if ($reflection_user->name == 'Drupal\typed_entity\TypedEntity\TypedEntity') {
          $this->pass('The factory is falling back to TypedEntity.');
        }
        else {
          $this->fail('The factory is not falling back to TypedEntity.');
        }
      }
    
    }