/**
  * Tests default values on entities and fields.
  */
 public function testDefaultValues()
 {
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types() as $entity_type) {
         $this->assertDefaultValues($entity_type);
     }
 }
 /**
  * Tests validating test entity types.
  */
 public function testValidation()
 {
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types() as $entity_type) {
         $this->checkValidation($entity_type);
     }
 }
Example #3
0
 /**
  * Check node revision related operations.
  */
 public function testRevisions()
 {
     // All revisable entity variations have to have the same results.
     foreach (entity_test_entity_types(ENTITY_TEST_TYPES_REVISABLE) as $entity_type) {
         $this->runRevisionsTests($entity_type);
     }
 }
 /**
  * Tests basic CRUD functionality of the Entity API.
  */
 public function testCRUD()
 {
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types() as $entity_type) {
         $this->assertCRUD($entity_type, $this->createUser());
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $this->languageManager = $this->container->get('language_manager');
     $this->installEntitySchema('entity_test_rev');
     $this->installEntitySchema('entity_test_mul');
     $this->installEntitySchema('entity_test_mulrev');
     $this->installConfig(array('language'));
     // Create the test field.
     entity_test_install();
     // Enable translations for the test entity type.
     $this->state->set('entity_test.translation', TRUE);
     // Create a translatable test field.
     $this->field_name = drupal_strtolower($this->randomMachineName() . '_field_name');
     // Create an untranslatable test field.
     $this->untranslatable_field_name = drupal_strtolower($this->randomMachineName() . '_field_name');
     // Create field fields in all entity variations.
     foreach (entity_test_entity_types() as $entity_type) {
         entity_create('field_storage_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         entity_create('field_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => TRUE))->save();
         $this->field[$entity_type] = entity_load('field_config', $entity_type . '.' . $entity_type . '.' . $this->field_name);
         entity_create('field_storage_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         entity_create('field_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => FALSE))->save();
     }
     // Create the default languages.
     $this->installConfig(array('language'));
     // Create test languages.
     $this->langcodes = array();
     for ($i = 0; $i < 3; ++$i) {
         $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString(), 'weight' => $i));
         $this->langcodes[$i] = $language->getId();
         $language->save();
     }
 }
 /**
  * Tests basic form CRUD functionality.
  */
 function testFormCRUD()
 {
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types() as $entity_type) {
         $this->doTestFormCRUD($entity_type);
     }
 }
Example #7
0
 /**
  * Tests basic multilingual form CRUD functionality.
  */
 public function testMultilingualFormCRUD()
 {
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) {
         $this->doTestMultilingualFormCRUD($entity_type);
     }
 }
Example #8
0
 /**
  * Returns an array of route objects.
  *
  * @return \Symfony\Component\Routing\Route[]
  *   An array of route objects.
  */
 public function routes()
 {
     $types = entity_test_entity_types(ENTITY_TEST_TYPES_ROUTING);
     $routes = array();
     foreach ($types as $entity_type_id) {
         $routes["entity.{$entity_type_id}.admin_form"] = new Route("{$entity_type_id}/structure/{bundle}", array('_controller' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testAdmin'), array('_permission' => 'administer entity_test content'), array('_admin_route' => TRUE));
     }
     return $routes;
 }
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $this->derivatives = array();
     $types = entity_test_entity_types();
     foreach ($types as $entity_type) {
         $this->derivatives[$entity_type] = array();
         $this->derivatives[$entity_type]['base_route'] = "entity_test.edit_{$entity_type}";
         $this->derivatives[$entity_type]['route_name'] = "entity_test.edit_{$entity_type}";
         $this->derivatives[$entity_type]['title'] = 'Edit';
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
Example #10
0
 /**
  * Returns an array of route objects.
  *
  * @return \Symfony\Component\Routing\Route[]
  *   An array of route objects.
  */
 public function routes()
 {
     $types = entity_test_entity_types();
     $types[] = 'entity_test_string_id';
     $types[] = 'entity_test_no_id';
     $routes = array();
     foreach ($types as $entity_type) {
         $routes["entity_test.add_{$entity_type}"] = new Route("{$entity_type}/add", array('_content' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testAdd', 'entity_type' => $entity_type), array('_permission' => 'administer entity_test content'));
         $routes["entity_test.edit_{$entity_type}"] = new Route("{$entity_type}/manage/{" . $entity_type . '}', array('_content' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testEdit', '_entity_type' => $entity_type), array('_permission' => 'administer entity_test content'), array('parameters' => array($entity_type => array('type' => 'entity:' . $entity_type))));
         $routes["entity_test.admin_{$entity_type}"] = new Route("{$entity_type}/structure/{bundle}", array('_content' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testAdmin'), array('_permission' => 'administer entity_test content'));
     }
     return $routes;
 }
Example #11
0
 /**
  * Returns an array of route objects.
  *
  * @return \Symfony\Component\Routing\Route[]
  *   An array of route objects.
  */
 public function routes()
 {
     $types = entity_test_entity_types(ENTITY_TEST_TYPES_ROUTING);
     $types[] = 'entity_test_string_id';
     $types[] = 'entity_test_no_id';
     $routes = array();
     foreach ($types as $entity_type_id) {
         $routes["entity.{$entity_type_id}.add_form"] = new Route("{$entity_type_id}/add", array('_controller' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testAdd', 'entity_type_id' => $entity_type_id), array('_permission' => 'administer entity_test content'));
         $routes["entity.{$entity_type_id}.canonical"] = new Route($entity_type_id . '/manage/{' . $entity_type_id . '}', array('_controller' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testEdit', 'entity_type_id' => $entity_type_id), array('_permission' => 'administer entity_test content'), array('parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id))));
         $routes["entity.{$entity_type_id}.edit_form"] = new Route($entity_type_id . '/manage/{' . $entity_type_id . '}', array('_controller' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testEdit', 'entity_type_id' => $entity_type_id), array('_permission' => 'administer entity_test content'), array('parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id))));
         $routes["entity.{$entity_type_id}.delete_form"] = new Route('entity_test/delete/' . $entity_type_id . '/{' . $entity_type_id . '}', array('_entity_form' => $entity_type_id . '.delete'), array('_permission' => 'administer entity_test content'));
         $routes["entity.{$entity_type_id}.admin_form"] = new Route("{$entity_type_id}/structure/{bundle}", array('_controller' => '\\Drupal\\entity_test\\Controller\\EntityTestController::testAdmin'), array('_permission' => 'administer entity_test content'));
     }
     return $routes;
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $this->derivatives = array();
     $types = entity_test_entity_types(ENTITY_TEST_TYPES_ROUTING);
     foreach ($types as $entity_type) {
         $this->derivatives[$entity_type . '.canonical'] = array();
         $this->derivatives[$entity_type . '.canonical']['base_route'] = "entity.{$entity_type}.canonical";
         $this->derivatives[$entity_type . '.canonical']['route_name'] = "entity.{$entity_type}.canonical";
         $this->derivatives[$entity_type . '.canonical']['title'] = 'View';
         $this->derivatives[$entity_type . '.edit'] = array();
         $this->derivatives[$entity_type . '.edit']['base_route'] = "entity.{$entity_type}.canonical";
         $this->derivatives[$entity_type . '.edit']['route_name'] = "entity.{$entity_type}.edit_form";
         $this->derivatives[$entity_type . '.edit']['title'] = 'Edit';
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
 /**
  * Tests validating test entity types.
  */
 public function testValidation()
 {
     // Ensure that the constraint manager is marked as cached cleared.
     $plugin_cache_clearer = \Drupal::service('plugin.cache_clearer');
     $get_cached_discoveries = function () {
         return $this->cachedDiscoveries;
     };
     $get_cached_discoveries = $get_cached_discoveries->bindTo($plugin_cache_clearer, $plugin_cache_clearer);
     $cached_discoveries = $get_cached_discoveries();
     $cached_discovery_classes = [];
     foreach ($cached_discoveries as $cached_discovery) {
         $cached_discovery_classes[] = get_class($cached_discovery);
     }
     $this->assertTrue(in_array('Drupal\\Core\\Validation\\ConstraintManager', $cached_discovery_classes));
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types() as $entity_type) {
         $this->checkValidation($entity_type);
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $this->languageManager = $this->container->get('language_manager');
     foreach (entity_test_entity_types() as $entity_type_id) {
         // The entity_test schema is installed by the parent.
         if ($entity_type_id != 'entity_test') {
             $this->installEntitySchema($entity_type_id);
         }
     }
     $this->installConfig(array('language'));
     // Create the test field.
     module_load_install('entity_test');
     entity_test_install();
     // Enable translations for the test entity type.
     $this->state->set('entity_test.translation', TRUE);
     // Create a translatable test field.
     $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     // Create an untranslatable test field.
     $this->untranslatableFieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     // Create field fields in all entity variations.
     foreach (entity_test_entity_types() as $entity_type) {
         FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         FieldConfig::create(['field_name' => $this->fieldName, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => TRUE])->save();
         FieldStorageConfig::create(array('field_name' => $this->untranslatableFieldName, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         FieldConfig::create(['field_name' => $this->untranslatableFieldName, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => FALSE])->save();
     }
     // Create the default languages.
     $this->installConfig(array('language'));
     // Create test languages.
     $this->langcodes = array();
     for ($i = 0; $i < 3; ++$i) {
         $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString(), 'weight' => $i));
         $this->langcodes[$i] = $language->getId();
         $language->save();
     }
 }
 /**
  * Tests multilingual properties.
  */
 public function testMultilingualProperties()
 {
     // Test all entity variations with data table support.
     foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) {
         $this->_testMultilingualProperties($entity_type);
     }
 }
Example #16
0
 /**
  * Tests that changing entity language does not break field language.
  */
 public function testLanguageChange()
 {
     // Test all entity variations with data table support.
     foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) {
         $this->doTestLanguageChange($entity_type);
     }
 }
Example #17
0
 /**
  * Tests validating test entity types.
  */
 public function testValidation()
 {
     // Ensure that the constraint manager is marked as cached cleared.
     // Use the protected property on the cache_clearer first to check whether
     // the constraint manager is added there.
     // Ensure that the proxy class is initialized, which has the necessary
     // method calls attached.
     \Drupal::service('plugin.cache_clearer');
     $plugin_cache_clearer = \Drupal::service('drupal.proxy_original_service.plugin.cache_clearer');
     $get_cached_discoveries = function () {
         return $this->cachedDiscoveries;
     };
     $get_cached_discoveries = $get_cached_discoveries->bindTo($plugin_cache_clearer, $plugin_cache_clearer);
     $cached_discoveries = $get_cached_discoveries();
     $cached_discovery_classes = [];
     foreach ($cached_discoveries as $cached_discovery) {
         $cached_discovery_classes[] = get_class($cached_discovery);
     }
     $this->assertTrue(in_array('Drupal\\Core\\Validation\\ConstraintManager', $cached_discovery_classes));
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types() as $entity_type) {
         $this->checkValidation($entity_type);
     }
 }
 /**
  * Tests getting processed property values via a computed property.
  */
 public function testComputedProperties()
 {
     // All entity variations have to have the same results.
     foreach (entity_test_entity_types() as $entity_type) {
         $this->assertComputedProperties($entity_type);
     }
 }