keyValue example

if ($revisionable) {
      $this->assertTrue($database_schema->tableExists($table_mapping->getDedicatedRevisionTableName($field_storage_definition)));
    }
  }

  /** * Asserts that the backup tables have been kept after a successful update. * * @internal */
  protected function assertBackupTables(): void {
    $backups = \Drupal::keyValue('entity.update_backup')->getAll();
    $backup = reset($backups);

    $schema = $this->database->schema();
    foreach ($backup['table_mapping']->getTableNames() as $table_name) {
      $this->assertTrue($schema->tableExists($table_name));
    }
  }

  /** * Tests that a failed entity schema update preserves the existing data. */
  

  public function testPostUpdate() {
    // There are expected to be failed updates.     $this->checkFailedUpdates = FALSE;

    $this->runUpdates();

    // There should be no post update hooks registered as being run.     $this->assertSame([], \Drupal::state()->get('post_update_test_execution', []));

    $key_value = \Drupal::keyValue('update__post_update');
    $this->assertEquals([]$key_value->get('existing_updates', []));
  }

  /** * {@inheritdoc} */
  protected function doSelectionTest() {
    // First update, should not be run since this module's update hooks fail.     $this->assertSession()->responseContains('8001 - This update will fail.');
    $this->assertSession()->responseContains('8002 - A further update');
    $this->assertSession()->assertEscaped("First update, should not be run since this module's update hooks fail.");
  }
/** * Tests recorded schema versions of early installed modules in the installer. */
  public function testRequiredModuleSchemaVersions(): void {
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    $version = $update_registry->getInstalledVersion('system');
    $this->assertGreaterThan(0, $version);
    $version = $update_registry->getInstalledVersion('user');
    $this->assertGreaterThan(0, $version);

    $post_update_key_value = \Drupal::keyValue('post_update');
    $existing_updates = $post_update_key_value->get('existing_updates', []);
    $this->assertContains('module_test_post_update_test', $existing_updates);
  }

  /** * Ensures that post update functions are removed on uninstallation. */
  public function testUninstallPostUpdateFunctions(): void {
    // First, to avoid false positives, ensure that the post_update function     // exists while the module is still installed.     $post_update_key_value = $this->container->get('keyvalue')
      

    catch (AccessDeniedHttpException $e) {
      // Expected exception; just continue testing.     }

    try {
      // Generate a valid hash key but store a modified settings array.       $selection_settings = [];
      $selection_settings_key = Crypt::hmacBase64(serialize($selection_settings) . $this->entityType . 'default', Settings::getHashSalt());

      $selection_settings[$this->randomMachineName()] = $this->randomString();
      \Drupal::keyValue('entity_autocomplete')->set($selection_settings_key$selection_settings);

      $entity_reference_controller->handleAutocomplete($request$this->entityType, 'default', $selection_settings_key);
    }
    catch (AccessDeniedHttpException $e) {
      $this->assertSame('Invalid selection settings key.', $e->getMessage());
    }

  }

  /** * Returns the result of an Entity reference autocomplete request. * * @param string $input * The label of the entity to query by. * @param int $entity_id * The label of the entity to query by. * * @return mixed * The JSON value encoded in its appropriate PHP type. */
'update_test_postupdate_post_update_second',
      'update_test_postupdate_post_update_test0',
      'update_test_postupdate_post_update_test1',
      'update_test_postupdate_post_update_test_batch-1',
      'update_test_postupdate_post_update_test_batch-2',
      'update_test_postupdate_post_update_test_batch-3',
    ];
    $this->assertSame($updates, \Drupal::state()->get('post_update_test_execution', []));

    // Test post_update key value stores contains a list of the update functions     // that have run.     $existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_updates'));
    $expected_updates = [
      'update_test_postupdate_post_update_first',
      'update_test_postupdate_post_update_second',
      'update_test_postupdate_post_update_test1',
      'update_test_postupdate_post_update_test0',
      'update_test_postupdate_post_update_test_batch',
    ];
    foreach ($expected_updates as $expected_update) {
      $this->assertEquals(1, $existing_updates[$expected_update]new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", ['@expected_update' => $expected_update]));
    }

    

  protected function setUp(): void {
    parent::setUp();

    $this->setUpCurrentUser([]['view any workspace']);
    $this->container->get('module_installer')->install(['workspace_update_test']);
    $this->rebuildContainer();

    // Ensure the workspace_update_test_post_update_check_active_workspace()     // update runs.     $existing_updates = \Drupal::keyValue('post_update')->get('existing_updates', []);
    $index = array_search('workspace_update_test_post_update_check_active_workspace', $existing_updates);
    unset($existing_updates[$index]);
    \Drupal::keyValue('post_update')->set('existing_updates', $existing_updates);
  }

  /** * Tests that there is no active workspace during database updates. */
  public function testActiveWorkspaceDuringUpdate() {
    /** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
    $workspace_manager = \Drupal::service('workspaces.manager');

    

  protected function getMigrationPluginManager() {
    return $this->migrationPluginManager;
  }

  /** * {@inheritdoc} */
  public function setStatus($status) {
    \Drupal::keyValue('migrate_status')->set($this->id()$status);
  }

  /** * {@inheritdoc} */
  public function getStatus() {
    return \Drupal::keyValue('migrate_status')->get($this->id()static::STATUS_IDLE);
  }

  /** * {@inheritdoc} */
$all_update_functions = $post_update_registry->getPendingUpdateFunctions();
    $empty_result = TRUE;
    foreach ($all_update_functions as $function) {
      [$function_module] = explode('_post_update_', $function);
      if ($module === $function_module) {
        $empty_result = FALSE;
        break;
      }
    }
    $this->assertTrue($empty_result, 'Ensures that no pending post update functions are available.');

    $existing_updates = \Drupal::keyValue('post_update')->get('existing_updates', []);
    switch ($module) {
      case 'update_test_postupdate':
        $expected = [
          'update_test_postupdate_post_update_first',
          'update_test_postupdate_post_update_second',
          'update_test_postupdate_post_update_test1',
          'update_test_postupdate_post_update_test0',
          'update_test_postupdate_post_update_foo',
          'update_test_postupdate_post_update_bar',
          'update_test_postupdate_post_update_baz',
        ];
        
    // in the route parameters.     $selection_settings = $element['#selection_settings'] ?? [];
    // Don't serialize the entity, it will be added explicitly afterwards.     if (isset($selection_settings['entity']) && ($selection_settings['entity'] instanceof EntityInterface)) {
      $element['#autocomplete_query_parameters']['entity_type'] = $selection_settings['entity']->getEntityTypeId();
      $element['#autocomplete_query_parameters']['entity_id'] = $selection_settings['entity']->id();
      unset($selection_settings['entity']);
    }
    $data = serialize($selection_settings) . $element['#target_type'] . $element['#selection_handler'];
    $selection_settings_key = Crypt::hmacBase64($data, Settings::getHashSalt());

    $key_value_storage = \Drupal::keyValue('entity_autocomplete');
    if (!$key_value_storage->has($selection_settings_key)) {
      $key_value_storage->set($selection_settings_key$selection_settings);
    }

    $element['#autocomplete_route_name'] = 'system.entity_autocomplete';
    $element['#autocomplete_route_parameters'] = [
      'target_type' => $element['#target_type'],
      'selection_handler' => $element['#selection_handler'],
      'selection_settings_key' => $selection_settings_key,
    ];

    
return $iterator instanceof \Countable ? $iterator->count() : iterator_count($this->initializeIterator());
  }

  /** * Get the high water storage object. * * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface * The storage object. */
  protected function getHighWaterStorage() {
    if (!isset($this->highWaterStorage)) {
      $this->highWaterStorage = \Drupal::keyValue('migrate:high_water');
    }
    return $this->highWaterStorage;
  }

  /** * The current value of the high water mark. * * The high water mark defines a timestamp stating the time the import was last * run. If the mark is set, only content with a higher timestamp will be * imported. * * @return int|null * A Unix timestamp representing the high water mark, or NULL if no high * water mark has been stored. */
/** @var \Drupal\language\Config\LanguageConfigOverride $view_config */
    // Ensure that views are translated as expected.     $view_config = \Drupal::languageManager()->getLanguageConfigOverride('es', 'views.view.who_s_new');
    $this->assertSame('Aplicar', $view_config->get('display.default.display_options.exposed_form.options.submit_button'));
    $view_config = \Drupal::languageManager()->getLanguageConfigOverride('es', 'views.view.archive');
    $this->assertSame('Aplicar', $view_config->get('display.default.display_options.exposed_form.options.submit_button'));

    // Manually update the translation status so can re-run the import.     $status = locale_translation_get_status();
    $status['drupal']['es']->type = 'local';
    $status['drupal']['es']->files['local']->timestamp = time();
    \Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);
    // Run the translation import.     $this->drupalGet('admin/reports/translations');
    $this->submitForm([], 'Update translations');

    // Ensure that only the config we expected to have changed has.     $comparer = $this->configImporter()->getStorageComparer();
    $expected_changelist_spanish_collection = [
      'create' => [],
      // The view was untranslated but the translation exists so the installer       // performs the translation.       'update' => ['views.view.who_s_new'],
      

  public function testKeyValue() {
    $keyvalue = $this->getMockBuilder('Drupal\Core\KeyValueStore\KeyValueFactory')
      ->disableOriginalConstructor()
      ->getMock();
    $keyvalue->expects($this->once())
      ->method('get')
      ->with('test_collection')
      ->willReturn(TRUE);
    $this->setMockContainerService('keyvalue', $keyvalue);

    $this->assertNotNull(\Drupal::keyValue('test_collection'));
  }

  /** * Tests the state() method. * * @covers ::state */
  public function testState() {
    $this->setMockContainerService('state');
    $this->assertNotNull(\Drupal::state());
  }

  
'name' => $this->randomMachineName(),
      $field_name => $this->randomString(),
    ]);
    $this->entity->save();
  }

  /** * Tests that column-level schema changes are detected for fields with data. */
  public function testColumnUpdate() {
    // Change the field type in the stored schema.     $schema = \Drupal::keyValue('entity.storage_schema.sql')->get('entity_test_rev.field_schema_data.test');
    $schema['entity_test_rev__test']['fields']['test_value']['type'] = 'varchar_ascii';
    \Drupal::keyValue('entity.storage_schema.sql')->set('entity_test_rev.field_schema_data.test', $schema);

    // Now attempt to run automatic updates. An exception should be thrown     // since there is data in the table.     $this->expectException(FieldStorageDefinitionUpdateForbiddenException::class);
    $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
    $field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('test', 'entity_test_rev');
    $entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
  }

}
    $fields = $view->displayHandlers->get('entity_reference_1')->getOption('fields');
    $fields['type']['exclude'] = FALSE;
    $view->displayHandlers->get('entity_reference_1')->setOption('fields', $fields);
    $view->save();

    // Prepare the selection settings key needed by the entity reference     // autocomplete route.     $target_type = 'node';
    $selection_handler = 'views';
    $selection_settings = $this->handlerSettings;
    $selection_settings_key = Crypt::hmacBase64(serialize($selection_settings) . $target_type . $selection_handler, Settings::getHashSalt());
    \Drupal::keyValue('entity_autocomplete')->set($selection_settings_key$selection_settings);

    $result = Json::decode($this->drupalGet('entity_reference_autocomplete/' . $target_type . '/' . $selection_handler . '/' . $selection_settings_key['query' => ['q' => 't']]));

    $expected = [
      0 => [
        'value' => $this->nodes[1]->bundle() . ': ' . $this->nodes[1]->label() . ' (' . $this->nodes[1]->id() . ')',
        'label' => '<span class="views-field views-field-type"><span class="field-content">' . $this->nodes[1]->bundle() . '</span></span>: <span class="views-field views-field-title"><span class="field-content">' . Html::escape($this->nodes[1]->label()) . '</span></span>',
      ],
      1 => [
        'value' => $this->nodes[2]->bundle() . ': ' . $this->nodes[2]->label() . ' (' . $this->nodes[2]->id() . ')',
        'label' => '<span class="views-field views-field-type"><span class="field-content">' . $this->nodes[2]->bundle() . '</span></span>: <span class="views-field views-field-title"><span class="field-content">' . Html::escape($this->nodes[2]->label()) . '</span></span>',
      ],
    // the schema for them.     $entity_type_ids = [];
    $entities = \Drupal::entityTypeManager()->getDefinitions();
    foreach ($entities as $entity_type_id => $definition) {
      if ($definition instanceof ContentEntityTypeInterface && $definition->getProvider() == 'entity_test') {
        $this->installEntitySchema($entity_type_id);
        $entity_type_ids[] = $entity_type_id;
      }
    }

    // Get a list of all the entities in the schema.     $key_value_store = \Drupal::keyValue('entity.storage_schema.sql');
    $schema = $key_value_store->getAll();

    // Count the storage definitions provided by the entity_test module, so that     // after uninstall we can be sure there were some to be deleted.     $entity_type_id_count = 0;

    foreach (array_keys($schema) as $storage_definition_name) {
      [$entity_type_id] = explode('.', $storage_definition_name);
      if (in_array($entity_type_id$entity_type_ids)) {
        $entity_type_id_count++;
      }
    }
Home | Imprint | This part of the site doesn't use cookies.