You are here

class FieldSqlStorageTest in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php \Drupal\system\Tests\Entity\FieldSqlStorageTest

Tests Field SQL Storage .

Field_sql_storage.module implements the default back-end storage plugin for the Field Storage API.

@group Entity

Hierarchy

Expanded class hierarchy of FieldSqlStorageTest

File

core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php, line 23
Contains \Drupal\system\Tests\Entity\FieldSqlStorageTest.

Namespace

Drupal\system\Tests\Entity
View source
class FieldSqlStorageTest extends EntityUnitTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array(
    'field',
    'field_test',
    'text',
    'entity_test',
  );

  /**
   * The name of the created field.
   *
   * @var string
   */
  protected $fieldName;

  /**
   * @var int
   */
  protected $fieldCardinality;

  /**
   * A field storage to use in this class.
   *
   * @var \Drupal\field\Entity\FieldStorageConfig
   */
  protected $fieldStorage;

  /**
   * A field to use in this test class.
   *
   * @var \Drupal\field\Entity\FieldConfig
   */
  protected $field;

  /**
   * Name of the data table of the field.
   *
   * @var string
   */
  protected $table;

  /**
   * Name of the revision table of the field.
   *
   * @var string
   */
  protected $revisionTable;

  /**
   * The table mapping for the tested entity type.
   *
   * @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping
   */
  protected $tableMapping;
  protected function setUp() {
    parent::setUp();
    $this
      ->installEntitySchema('entity_test_rev');
    $entity_type = 'entity_test_rev';
    $this->fieldName = strtolower($this
      ->randomMachineName());
    $this->fieldCardinality = 4;
    $this->fieldStorage = entity_create('field_storage_config', array(
      'field_name' => $this->fieldName,
      'entity_type' => $entity_type,
      'type' => 'test_field',
      'cardinality' => $this->fieldCardinality,
    ));
    $this->fieldStorage
      ->save();
    $this->field = entity_create('field_config', array(
      'field_storage' => $this->fieldStorage,
      'bundle' => $entity_type,
    ));
    $this->field
      ->save();

    /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    $table_mapping = \Drupal::entityManager()
      ->getStorage($entity_type)
      ->getTableMapping();
    $this->tableMapping = $table_mapping;
    $this->table = $table_mapping
      ->getDedicatedDataTableName($this->fieldStorage);
    $this->revisionTable = $table_mapping
      ->getDedicatedRevisionTableName($this->fieldStorage);
  }

  /**
   * Tests field loading works correctly by inserting directly in the tables.
   */
  function testFieldLoad() {
    $entity_type = $bundle = 'entity_test_rev';
    $storage = $this->container
      ->get('entity.manager')
      ->getStorage($entity_type);
    $columns = array(
      'bundle',
      'deleted',
      'entity_id',
      'revision_id',
      'delta',
      'langcode',
      $this->tableMapping
        ->getFieldColumnName($this->fieldStorage, 'value'),
    );

    // Create an entity with four revisions.
    $revision_ids = array();
    $entity = entity_create($entity_type);
    $entity
      ->save();
    $revision_ids[] = $entity
      ->getRevisionId();
    for ($i = 0; $i < 4; $i++) {
      $entity
        ->setNewRevision();
      $entity
        ->save();
      $revision_ids[] = $entity
        ->getRevisionId();
    }

    // Generate values and insert them directly in the storage tables.
    $values = array();
    $query = db_insert($this->revisionTable)
      ->fields($columns);
    foreach ($revision_ids as $revision_id) {

      // Put one value too many.
      for ($delta = 0; $delta <= $this->fieldCardinality; $delta++) {
        $value = mt_rand(1, 127);
        $values[$revision_id][] = $value;
        $query
          ->values(array(
          $bundle,
          0,
          $entity
            ->id(),
          $revision_id,
          $delta,
          $entity
            ->language()
            ->getId(),
          $value,
        ));
      }
      $query
        ->execute();
    }
    $query = db_insert($this->table)
      ->fields($columns);
    foreach ($values[$revision_id] as $delta => $value) {
      $query
        ->values(array(
        $bundle,
        0,
        $entity
          ->id(),
        $revision_id,
        $delta,
        $entity
          ->language()
          ->getId(),
        $value,
      ));
    }
    $query
      ->execute();

    // Load every revision and check the values.
    foreach ($revision_ids as $revision_id) {
      $entity = $storage
        ->loadRevision($revision_id);
      foreach ($values[$revision_id] as $delta => $value) {
        if ($delta < $this->fieldCardinality) {
          $this
            ->assertEqual($entity->{$this->fieldName}[$delta]->value, $value);
        }
        else {
          $this
            ->assertFalse(array_key_exists($delta, $entity->{$this->fieldName}));
        }
      }
    }

    // Load the "current revision" and check the values.
    $entity = $storage
      ->load($entity
      ->id());
    foreach ($values[$revision_id] as $delta => $value) {
      if ($delta < $this->fieldCardinality) {
        $this
          ->assertEqual($entity->{$this->fieldName}[$delta]->value, $value);
      }
      else {
        $this
          ->assertFalse(array_key_exists($delta, $entity->{$this->fieldName}));
      }
    }

    // Add a translation in an unavailable language code and verify it is not
    // loaded.
    $unavailable_langcode = 'xx';
    $values = array(
      $bundle,
      0,
      $entity
        ->id(),
      $entity
        ->getRevisionId(),
      0,
      $unavailable_langcode,
      mt_rand(1, 127),
    );
    db_insert($this->table)
      ->fields($columns)
      ->values($values)
      ->execute();
    db_insert($this->revisionTable)
      ->fields($columns)
      ->values($values)
      ->execute();
    $entity = $storage
      ->load($entity
      ->id());
    $this
      ->assertFalse(array_key_exists($unavailable_langcode, $entity->{$this->fieldName}));
  }

  /**
   * Tests field saving works correctly by reading directly from the tables.
   */
  function testFieldWrite() {
    $entity_type = $bundle = 'entity_test_rev';
    $entity = entity_create($entity_type);
    $revision_values = array();

    // Check insert. Add one value too many.
    $values = array();
    for ($delta = 0; $delta <= $this->fieldCardinality; $delta++) {
      $values[$delta]['value'] = mt_rand(1, 127);
    }
    $entity->{$this->fieldName} = $values;
    $entity
      ->save();

    // Read the tables and check the correct values have been stored.
    $rows = db_select($this->table, 't')
      ->fields('t')
      ->execute()
      ->fetchAllAssoc('delta', \PDO::FETCH_ASSOC);
    $this
      ->assertEqual(count($rows), $this->fieldCardinality);
    foreach ($rows as $delta => $row) {
      $expected = array(
        'bundle' => $bundle,
        'deleted' => 0,
        'entity_id' => $entity
          ->id(),
        'revision_id' => $entity
          ->getRevisionId(),
        'langcode' => $entity
          ->language()
          ->getId(),
        'delta' => $delta,
        $this->fieldName . '_value' => $values[$delta]['value'],
      );
      $this
        ->assertEqual($row, $expected, "Row {$delta} was stored as expected.");
    }

    // Test update. Add less values and check that the previous values did not
    // persist.
    $values = array();
    for ($delta = 0; $delta <= $this->fieldCardinality - 2; $delta++) {
      $values[$delta]['value'] = mt_rand(1, 127);
    }
    $entity->{$this->fieldName} = $values;
    $entity
      ->save();
    $rows = db_select($this->table, 't')
      ->fields('t')
      ->execute()
      ->fetchAllAssoc('delta', \PDO::FETCH_ASSOC);
    $this
      ->assertEqual(count($rows), count($values));
    foreach ($rows as $delta => $row) {
      $expected = array(
        'bundle' => $bundle,
        'deleted' => 0,
        'entity_id' => $entity
          ->id(),
        'revision_id' => $entity
          ->getRevisionId(),
        'langcode' => $entity
          ->language()
          ->getId(),
        'delta' => $delta,
        $this->fieldName . '_value' => $values[$delta]['value'],
      );
      $this
        ->assertEqual($row, $expected, "Row {$delta} was stored as expected.");
    }

    // Create a new revision.
    $revision_values[$entity
      ->getRevisionId()] = $values;
    $values = array();
    for ($delta = 0; $delta < $this->fieldCardinality; $delta++) {
      $values[$delta]['value'] = mt_rand(1, 127);
    }
    $entity->{$this->fieldName} = $values;
    $entity
      ->setNewRevision();
    $entity
      ->save();
    $revision_values[$entity
      ->getRevisionId()] = $values;

    // Check that data for both revisions are in the revision table.
    foreach ($revision_values as $revision_id => $values) {
      $rows = db_select($this->revisionTable, 't')
        ->fields('t')
        ->condition('revision_id', $revision_id)
        ->execute()
        ->fetchAllAssoc('delta', \PDO::FETCH_ASSOC);
      $this
        ->assertEqual(count($rows), min(count($values), $this->fieldCardinality));
      foreach ($rows as $delta => $row) {
        $expected = array(
          'bundle' => $bundle,
          'deleted' => 0,
          'entity_id' => $entity
            ->id(),
          'revision_id' => $revision_id,
          'langcode' => $entity
            ->language()
            ->getId(),
          'delta' => $delta,
          $this->fieldName . '_value' => $values[$delta]['value'],
        );
        $this
          ->assertEqual($row, $expected, "Row {$delta} was stored as expected.");
      }
    }

    // Test emptying the field.
    $entity->{$this->fieldName} = NULL;
    $entity
      ->save();
    $rows = db_select($this->table, 't')
      ->fields('t')
      ->execute()
      ->fetchAllAssoc('delta', \PDO::FETCH_ASSOC);
    $this
      ->assertEqual(count($rows), 0);
  }

  /**
   * Tests that long entity type and field names do not break.
   */
  function testLongNames() {

    // Use one of the longest entity_type names in core.
    $entity_type = $bundle = 'entity_test_label_callback';
    $storage = $this->container
      ->get('entity.manager')
      ->getStorage($entity_type);

    // Create two fields and generate random values.
    $name_base = Unicode::strtolower($this
      ->randomMachineName(FieldStorageConfig::NAME_MAX_LENGTH - 1));
    $field_names = array();
    $values = array();
    for ($i = 0; $i < 2; $i++) {
      $field_names[$i] = $name_base . $i;
      entity_create('field_storage_config', array(
        'field_name' => $field_names[$i],
        'entity_type' => $entity_type,
        'type' => 'test_field',
      ))
        ->save();
      entity_create('field_config', array(
        'field_name' => $field_names[$i],
        'entity_type' => $entity_type,
        'bundle' => $bundle,
      ))
        ->save();
      $values[$field_names[$i]] = mt_rand(1, 127);
    }

    // Save an entity with values.
    $entity = entity_create($entity_type, $values);
    $entity
      ->save();

    // Load the entity back and check the values.
    $entity = $storage
      ->load($entity
      ->id());
    foreach ($field_names as $field_name) {
      $this
        ->assertEqual($entity
        ->get($field_name)->value, $values[$field_name]);
    }
  }

  /**
   * Test trying to update a field with data.
   */
  function testUpdateFieldSchemaWithData() {
    $entity_type = 'entity_test_rev';

    // Create a decimal 5.2 field and add some data.
    $field_storage = entity_create('field_storage_config', array(
      'field_name' => 'decimal52',
      'entity_type' => $entity_type,
      'type' => 'decimal',
      'settings' => array(
        'precision' => 5,
        'scale' => 2,
      ),
    ));
    $field_storage
      ->save();
    $field = entity_create('field_config', array(
      'field_storage' => $field_storage,
      'bundle' => $entity_type,
    ));
    $field
      ->save();
    $entity = entity_create($entity_type, array(
      'id' => 0,
      'revision_id' => 0,
    ));
    $entity->decimal52->value = '1.235';
    $entity
      ->save();

    // Attempt to update the field in a way that would work without data.
    $field_storage
      ->setSetting('scale', 3);
    try {
      $field_storage
        ->save();
      $this
        ->fail(t('Cannot update field schema with data.'));
    } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
      $this
        ->pass(t('Cannot update field schema with data.'));
    }
  }

  /**
   * Test that failure to create fields is handled gracefully.
   */
  function testFieldUpdateFailure() {

    // Create a text field.
    $field_storage = entity_create('field_storage_config', array(
      'field_name' => 'test_text',
      'entity_type' => 'entity_test_rev',
      'type' => 'text',
      'settings' => array(
        'max_length' => 255,
      ),
    ));
    $field_storage
      ->save();

    // Attempt to update the field in a way that would break the storage. The
    // parenthesis suffix is needed because SQLite has *very* relaxed rules for
    // data types, so we actually need to provide an invalid SQL syntax in order
    // to break it.
    // @see https://www.sqlite.org/datatype3.html
    $prior_field_storage = $field_storage;
    $field_storage
      ->setSetting('max_length', '-1)');
    try {
      $field_storage
        ->save();
      $this
        ->fail(t('Update succeeded.'));
    } catch (\Exception $e) {
      $this
        ->pass(t('Update properly failed.'));
    }

    // Ensure that the field tables are still there.
    $tables = array(
      $this->tableMapping
        ->getDedicatedDataTableName($prior_field_storage),
      $this->tableMapping
        ->getDedicatedRevisionTableName($prior_field_storage),
    );
    foreach ($tables as $table_name) {
      $this
        ->assertTrue(db_table_exists($table_name), t('Table %table exists.', array(
        '%table' => $table_name,
      )));
    }
  }

  /**
   * Test adding and removing indexes while data is present.
   */
  function testFieldUpdateIndexesWithData() {

    // Create a decimal field.
    $field_name = 'testfield';
    $entity_type = 'entity_test_rev';
    $field_storage = entity_create('field_storage_config', array(
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'type' => 'text',
    ));
    $field_storage
      ->save();
    $field = entity_create('field_config', array(
      'field_storage' => $field_storage,
      'bundle' => $entity_type,
    ));
    $field
      ->save();
    $tables = array(
      $this->tableMapping
        ->getDedicatedDataTableName($field_storage),
      $this->tableMapping
        ->getDedicatedRevisionTableName($field_storage),
    );

    // Verify the indexes we will create do not exist yet.
    foreach ($tables as $table) {
      $this
        ->assertFalse(Database::getConnection()
        ->schema()
        ->indexExists($table, 'value'), t("No index named value exists in @table", array(
        '@table' => $table,
      )));
      $this
        ->assertFalse(Database::getConnection()
        ->schema()
        ->indexExists($table, 'value_format'), t("No index named value_format exists in @table", array(
        '@table' => $table,
      )));
    }

    // Add data so the table cannot be dropped.
    $entity = entity_create($entity_type, array(
      'id' => 1,
      'revision_id' => 1,
    ));
    $entity->{$field_name}->value = 'field data';
    $entity
      ->enforceIsNew();
    $entity
      ->save();

    // Add an index.
    $field_storage
      ->setIndexes([
      'value' => [
        [
          'value',
          255,
        ],
      ],
    ]);
    $field_storage
      ->save();
    foreach ($tables as $table) {
      $this
        ->assertTrue(Database::getConnection()
        ->schema()
        ->indexExists($table, "{$field_name}_value"), t("Index on value created in @table", array(
        '@table' => $table,
      )));
    }

    // Add a different index, removing the existing custom one.
    $field_storage
      ->setIndexes([
      'value_format' => [
        [
          'value',
          127,
        ],
        [
          'format',
          127,
        ],
      ],
    ]);
    $field_storage
      ->save();
    foreach ($tables as $table) {
      $this
        ->assertTrue(Database::getConnection()
        ->schema()
        ->indexExists($table, "{$field_name}_value_format"), t("Index on value_format created in @table", array(
        '@table' => $table,
      )));
      $this
        ->assertFalse(Database::getConnection()
        ->schema()
        ->indexExists($table, "{$field_name}_value"), t("Index on value removed in @table", array(
        '@table' => $table,
      )));
    }

    // Verify that the tables were not dropped in the process.
    $entity = $this->container
      ->get('entity.manager')
      ->getStorage($entity_type)
      ->load(1);
    $this
      ->assertEqual($entity->{$field_name}->value, 'field data', t("Index changes performed without dropping the tables"));
  }

  /**
   * Test foreign key support.
   */
  function testFieldSqlStorageForeignKeys() {

    // Create a 'shape' field, with a configurable foreign key (see
    // field_test_field_schema()).
    $field_name = 'testfield';
    $foreign_key_name = 'shape';
    $field_storage = entity_create('field_storage_config', array(
      'field_name' => $field_name,
      'entity_type' => 'entity_test',
      'type' => 'shape',
      'settings' => array(
        'foreign_key_name' => $foreign_key_name,
      ),
    ));
    $field_storage
      ->save();

    // Get the field schema.
    $schema = $field_storage
      ->getSchema();

    // Retrieve the field definition and check that the foreign key is in place.
    $this
      ->assertEqual($schema['foreign keys'][$foreign_key_name]['table'], $foreign_key_name, 'Foreign key table name preserved through CRUD');
    $this
      ->assertEqual($schema['foreign keys'][$foreign_key_name]['columns'][$foreign_key_name], 'id', 'Foreign key column name preserved through CRUD');

    // Update the field settings, it should update the foreign key definition too.
    $foreign_key_name = 'color';
    $field_storage
      ->setSetting('foreign_key_name', $foreign_key_name);
    $field_storage
      ->save();

    // Reload the field schema after the update.
    $schema = $field_storage
      ->getSchema();

    // Check that the foreign key is in place.
    $this
      ->assertEqual($schema['foreign keys'][$foreign_key_name]['table'], $foreign_key_name, 'Foreign key table name modified after update');
    $this
      ->assertEqual($schema['foreign keys'][$foreign_key_name]['columns'][$foreign_key_name], 'id', 'Foreign key column name modified after update');
  }

  /**
   * Tests table name generation.
   */
  public function testTableNames() {

    // Note: we need to test entity types with long names. We therefore use
    // fields on imaginary entity types (works as long as we don't actually save
    // them), and just check the generated table names.
    // Short entity type and field name.
    $entity_type = 'short_entity_type';
    $field_name = 'short_field_name';
    $field_storage = entity_create('field_storage_config', array(
      'entity_type' => $entity_type,
      'field_name' => $field_name,
      'type' => 'test_field',
    ));
    $expected = 'short_entity_type__short_field_name';
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedDataTableName($field_storage), $expected);
    $expected = 'short_entity_type_revision__short_field_name';
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedRevisionTableName($field_storage), $expected);

    // Short entity type, long field name
    $entity_type = 'short_entity_type';
    $field_name = 'long_field_name_abcdefghijklmnopqrstuvwxyz';
    $field_storage = entity_create('field_storage_config', array(
      'entity_type' => $entity_type,
      'field_name' => $field_name,
      'type' => 'test_field',
    ));
    $expected = 'short_entity_type__' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedDataTableName($field_storage), $expected);
    $expected = 'short_entity_type_r__' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedRevisionTableName($field_storage), $expected);

    // Long entity type, short field name
    $entity_type = 'long_entity_type_abcdefghijklmnopqrstuvwxyz';
    $field_name = 'short_field_name';
    $field_storage = entity_create('field_storage_config', array(
      'entity_type' => $entity_type,
      'field_name' => $field_name,
      'type' => 'test_field',
    ));
    $expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedDataTableName($field_storage), $expected);
    $expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedRevisionTableName($field_storage), $expected);

    // Long entity type and field name.
    $entity_type = 'long_entity_type_abcdefghijklmnopqrstuvwxyz';
    $field_name = 'long_field_name_abcdefghijklmnopqrstuvwxyz';
    $field_storage = entity_create('field_storage_config', array(
      'entity_type' => $entity_type,
      'field_name' => $field_name,
      'type' => 'test_field',
    ));
    $expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedDataTableName($field_storage), $expected);
    $expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedRevisionTableName($field_storage), $expected);

    // Try creating a second field and check there are no clashes.
    $field_storage2 = entity_create('field_storage_config', array(
      'entity_type' => $entity_type,
      'field_name' => $field_name . '2',
      'type' => 'test_field',
    ));
    $this
      ->assertNotEqual($this->tableMapping
      ->getDedicatedDataTableName($field_storage), $this->tableMapping
      ->getDedicatedDataTableName($field_storage2));
    $this
      ->assertNotEqual($this->tableMapping
      ->getDedicatedRevisionTableName($field_storage), $this->tableMapping
      ->getDedicatedRevisionTableName($field_storage2));

    // Deleted field.
    $field_storage = entity_create('field_storage_config', array(
      'entity_type' => 'some_entity_type',
      'field_name' => 'some_field_name',
      'type' => 'test_field',
      'deleted' => TRUE,
    ));
    $expected = 'field_deleted_data_' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedDataTableName($field_storage, TRUE), $expected);
    $expected = 'field_deleted_revision_' . substr(hash('sha256', $field_storage
      ->uuid()), 0, 10);
    $this
      ->assertEqual($this->tableMapping
      ->getDedicatedRevisionTableName($field_storage, TRUE), $expected);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertContentTrait::$content protected property The current raw content.
AssertContentTrait::$drupalSettings protected property The drupalSettings value from the current raw $content.
AssertContentTrait::$elements protected property The XML structure parsed from the current raw $content. 2
AssertContentTrait::$plainTextContent protected property The plain-text content of raw $content (text nodes).
AssertContentTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertContentTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertContentTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertContentTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertContentTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertContentTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertContentTrait::assertLink protected function Passes if a link with the specified label is found.
AssertContentTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertContentTrait::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
AssertContentTrait::assertNoEscaped protected function Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertNoField protected function Asserts that a field does not exist with the given name or ID.
AssertContentTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertContentTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertContentTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertContentTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertContentTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertContentTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertContentTrait::assertNoLinkByHrefInMainRegion protected function Passes if a link containing a given href is not found in the main region.
AssertContentTrait::assertNoOption protected function Asserts that a select option in the current page does not exist.
AssertContentTrait::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
AssertContentTrait::assertNoPattern protected function Triggers a pass if the perl regex pattern is not found in raw content.
AssertContentTrait::assertNoRaw protected function Passes if the raw text is NOT found on the loaded page, fail otherwise.
AssertContentTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertNoTitle protected function Pass if the page title is not the given string.
AssertContentTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertContentTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionSelectedWithDrupalSelector protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionWithDrupalSelector protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertContentTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertContentTrait::assertText protected function Passes if the page (with HTML stripped) contains the text.
AssertContentTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertContentTrait::assertTextPattern protected function Asserts that a Perl regex pattern is found in the plain-text content.
AssertContentTrait::assertThemeOutput protected function Asserts themed output.
AssertContentTrait::assertTitle protected function Pass if the page title is the given string.
AssertContentTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertContentTrait::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
AssertContentTrait::buildXPathQuery protected function Builds an XPath query.
AssertContentTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertContentTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
AssertContentTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertContentTrait::getDrupalSettings protected function Gets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::getRawContent protected function Gets the current raw content.
AssertContentTrait::getSelectedItem protected function Get the selected value from a select field.
AssertContentTrait::getTextContent protected function Retrieves the plain-text content from the current raw content.
AssertContentTrait::getUrl protected function Get the current URL from the cURL handler. 1
AssertContentTrait::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
AssertContentTrait::removeWhiteSpace protected function Removes all white-space between HTML tags from the raw content.
AssertContentTrait::setDrupalSettings protected function Sets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::setRawContent protected function Sets the raw content (e.g. HTML).
AssertContentTrait::xpath protected function Performs an xpath search on the contents of the internal browser.
AssertHelperTrait::castSafeStrings protected function Casts MarkupInterface objects into strings.
EntityUnitTestBase::$entityManager protected property The entity manager service.
EntityUnitTestBase::$generatedIds protected property A list of generated identifiers.
EntityUnitTestBase::$state protected property The state service.
EntityUnitTestBase::createUser protected function Creates a user.
EntityUnitTestBase::generateRandomEntityId protected function Generates a random ID avoiding collisions.
EntityUnitTestBase::getHooksInfo protected function Returns the entity_test hook invocation info.
EntityUnitTestBase::installModule protected function Installs a module and refreshes services.
EntityUnitTestBase::refreshServices protected function Refresh services. 1
EntityUnitTestBase::reloadEntity protected function Reloads the given entity from the storage and returns it.
EntityUnitTestBase::uninstallModule protected function Uninstalls a module and refreshes services.
FieldSqlStorageTest::$field protected property A field to use in this test class.
FieldSqlStorageTest::$fieldCardinality protected property
FieldSqlStorageTest::$fieldName protected property The name of the created field.
FieldSqlStorageTest::$fieldStorage protected property A field storage to use in this class.
FieldSqlStorageTest::$modules public static property Modules to enable. Overrides EntityUnitTestBase::$modules
FieldSqlStorageTest::$revisionTable protected property Name of the revision table of the field.
FieldSqlStorageTest::$table protected property Name of the data table of the field.
FieldSqlStorageTest::$tableMapping protected property The table mapping for the tested entity type.
FieldSqlStorageTest::setUp protected function Performs setup tasks before each individual test method is run. Overrides EntityUnitTestBase::setUp
FieldSqlStorageTest::testFieldLoad function Tests field loading works correctly by inserting directly in the tables.
FieldSqlStorageTest::testFieldSqlStorageForeignKeys function Test foreign key support.
FieldSqlStorageTest::testFieldUpdateFailure function Test that failure to create fields is handled gracefully.
FieldSqlStorageTest::testFieldUpdateIndexesWithData function Test adding and removing indexes while data is present.
FieldSqlStorageTest::testFieldWrite function Tests field saving works correctly by reading directly from the tables.
FieldSqlStorageTest::testLongNames function Tests that long entity type and field names do not break.
FieldSqlStorageTest::testTableNames public function Tests table name generation.
FieldSqlStorageTest::testUpdateFieldSchemaWithData function Test trying to update a field with data.
KernelTestBase::$configDirectories protected property The configuration directories for this test run.
KernelTestBase::$keyValueFactory protected property A KeyValueMemoryFactory instance to use when building the container.
KernelTestBase::$moduleFiles private property
KernelTestBase::$streamWrappers protected property Array of registered stream wrappers.
KernelTestBase::$themeFiles private property
KernelTestBase::beforePrepareEnvironment protected function Act on global state information before the environment is altered for a test. Overrides TestBase::beforePrepareEnvironment
KernelTestBase::containerBuild public function Sets up the base service container for this test. 12
KernelTestBase::defaultLanguageData protected function Provides the data for setting the default language on the container. 1
KernelTestBase::disableModules protected function Disables modules for this test.
KernelTestBase::enableModules protected function Enables modules for this test.
KernelTestBase::installConfig protected function Installs default configuration for a given list of modules.
KernelTestBase::installEntitySchema protected function Installs the storage schema for a specific entity type.
KernelTestBase::installSchema protected function Installs a specific table from a module schema definition.
KernelTestBase::prepareConfigDirectories protected function Create and set new configuration directories. 1
KernelTestBase::registerStreamWrapper protected function Registers a stream wrapper for this test.
KernelTestBase::render protected function Renders a render array.
KernelTestBase::tearDown protected function Performs cleanup tasks after each individual test method has been run. Overrides TestBase::tearDown
KernelTestBase::__construct function Constructor for Test. Overrides TestBase::__construct
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
SessionTestTrait::$sessionName protected property The name of the session cookie.
SessionTestTrait::generateSessionName protected function Generates a session cookie name.
SessionTestTrait::getSessionName protected function Returns the session name in use on the child site.
TestBase::$assertions protected property Assertions thrown in that test case.
TestBase::$configImporter protected property The config importer that can used in a test. 5
TestBase::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
TestBase::$container protected property The dependency injection container used in the test.
TestBase::$databasePrefix protected property The database prefix of this test run.
TestBase::$dieOnFail public property Whether to die in case any test assertion fails.
TestBase::$httpAuthCredentials protected property HTTP authentication credentials (<username>:<password>).
TestBase::$httpAuthMethod protected property HTTP authentication method (specified as a CURLAUTH_* constant).
TestBase::$kernel protected property The DrupalKernel instance used in the test. 1
TestBase::$originalConf protected property The original configuration (variables), if available.
TestBase::$originalConfig protected property The original configuration (variables).
TestBase::$originalConfigDirectories protected property The original configuration directories.
TestBase::$originalContainer protected property The original container.
TestBase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
TestBase::$originalLanguage protected property The original language.
TestBase::$originalPrefix protected property The original database prefix when running inside Simpletest.
TestBase::$originalProfile protected property The original installation profile.
TestBase::$originalSessionName protected property The name of the session cookie of the test-runner.
TestBase::$originalSettings protected property The settings array.
TestBase::$originalShutdownCallbacks protected property The original array of shutdown function callbacks. 1
TestBase::$originalSite protected property The site directory of the original parent site.
TestBase::$originalUser protected property The original user, before testing began. 1
TestBase::$privateFilesDirectory protected property The private file directory for the test environment.
TestBase::$publicFilesDirectory protected property The public file directory for the test environment.
TestBase::$results public property Current results of this test case.
TestBase::$siteDirectory protected property The site directory of this test run.
TestBase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
TestBase::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 4
TestBase::$tempFilesDirectory protected property The temporary file directory for the test environment.
TestBase::$testId protected property The test run ID.
TestBase::$timeLimit protected property Time limit for the test.
TestBase::$translationFilesDirectory protected property The translation file directory for the test environment.
TestBase::$verbose public property TRUE if verbose debugging is enabled.
TestBase::$verboseClassName protected property Safe class name for use in verbose output filenames.
TestBase::$verboseDirectory protected property Directory where verbose output files are put.
TestBase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
TestBase::$verboseId protected property Incrementing identifier for verbose output filenames.
TestBase::assert protected function Internal helper: stores the assert.
TestBase::assertEqual protected function Check to see if two values are equal.
TestBase::assertErrorLogged protected function Asserts that a specific error has been logged to the PHP error log.
TestBase::assertFalse protected function Check to see if a value is false.
TestBase::assertIdentical protected function Check to see if two values are identical.
TestBase::assertIdenticalObject protected function Checks to see if two objects are identical.
TestBase::assertNoErrorsLogged protected function Asserts that no errors have been logged to the PHP error.log thus far.
TestBase::assertNotEqual protected function Check to see if two values are not equal.
TestBase::assertNotIdentical protected function Check to see if two values are not identical.
TestBase::assertNotNull protected function Check to see if a value is not NULL.
TestBase::assertNull protected function Check to see if a value is NULL.
TestBase::assertTrue protected function Check to see if a value is not false.
TestBase::changeDatabasePrefix private function Changes the database connection to the prefixed one.
TestBase::checkRequirements protected function Checks the matching requirements for Test. 2
TestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
TestBase::configImporter public function Returns a ConfigImporter object to import test importing of configuration. 5
TestBase::copyConfig public function Copies configuration objects from source storage to target storage.
TestBase::deleteAssert public static function Delete an assertion record by message ID.
TestBase::error protected function Fire an error assertion. 3
TestBase::errorHandler public function Handle errors during test runs.
TestBase::exceptionHandler protected function Handle exceptions.
TestBase::fail protected function Fire an assertion that is always negative.
TestBase::filePreDeleteCallback public static function Ensures test files are deletable within file_unmanaged_delete_recursive().
TestBase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
TestBase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
TestBase::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
TestBase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
TestBase::getDatabasePrefix public function Gets the database prefix.
TestBase::getTempFilesDirectory public function Gets the temporary files directory.
TestBase::insertAssert public static function Store an assertion from outside the testing context.
TestBase::pass protected function Fire an assertion that is always positive.
TestBase::prepareDatabasePrefix private function Generates a database prefix for running tests.
TestBase::prepareEnvironment private function Prepares the current environment for running the test.
TestBase::restoreEnvironment private function Cleans up the test environment and restores the original environment.
TestBase::run public function Run all tests in this class. 1
TestBase::settingsSet protected function Changes in memory settings.
TestBase::storeAssertion protected function Helper method to store an assertion record in the configured database.
TestBase::verbose protected function Logs a verbose message in a text file.