resetAll example


  protected $defaultTheme = 'stark';

  /** * Tests that module-provided classes can be loaded when a module is enabled. * * @see \Drupal\module_autoload_test\SomeClass */
  public function testClassLoading() {
    // Enable the module_test and module_autoload_test modules.     \Drupal::service('module_installer')->install(['module_test', 'module_autoload_test'], FALSE);
    $this->resetAll();
    // Check twice to test an unprimed and primed system_list() cache.     for ($i = 0; $i < 2; $i++) {
      $this->drupalGet('module-test/class-loading');
      $this->assertSession()->statusCodeEquals(200);
      $this->assertSession()->pageTextContains($this->expected);
    }
  }

  /** * Tests that module-provided classes can't be loaded if module not installed. * * @see \Drupal\module_autoload_test\SomeClass */
// Test that the downcast drupal-media element no longer has an alt     // attribute.     $this->assertSourceAttributeSame('alt', NULL);
  }

  /** * Tests the CKEditor 5 media plugin loads the translated alt attribute. */
  public function testTranslationAlt() {
    \Drupal::service('module_installer')->install(['language', 'content_translation']);
    $this->resetAll();
    ConfigurableLanguage::create(['id' => 'fr'])->save();
    ContentLanguageSettings::loadByEntityTypeBundle('media', 'image')
      ->setDefaultLangcode('en')
      ->setLanguageAlterable(TRUE)
      ->save();
    $media = Media::create([
      'bundle' => 'image',
      'name' => 'Screaming hairy armadillo',
      'field_media_image' => [
        [
          'target_id' => 1,
          
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    ConfigurableLanguage::createFromLangcode('fr')->save();
    $this->config('system.site')->set('default_langcode', 'fr')->save();

    // Clear all caches so that the base field definition, its cache in the     // entity field manager, the t() cache, etc. are all cleared.     $this->resetAll();
  }

  /** * Tests that translated field descriptions do not affect the update system. */
  public function testTranslatedSchemaDefinition() {
    /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
    $stringStorage = \Drupal::service('locale.storage');

    $source = $stringStorage->createString([
      'source' => 'Revision ID',
    ])
parent::setUp();
    $this->ensureUpdatesToRun();
  }

  /** * Tests running update.php with some form of broken routing. */
  public function testWithBrokenRouting() {
    // Simulate a broken router, and make sure the front page is     // inaccessible.     \Drupal::state()->set('update_script_test_broken_inbound', TRUE);
    $this->resetAll();
    $this->drupalGet('<front>');
    $this->assertSession()->statusCodeEquals(500);

    $this->runUpdates(Url::fromRoute('system.db_update', []['path_processing' => FALSE]));

    // Remove the simulation of the broken router, and make sure we can get to     // the front page again.     \Drupal::state()->set('update_script_test_broken_inbound', FALSE);
    $this->drupalGet('<front>');
    $this->assertSession()->statusCodeEquals(200);
  }

}
$this->assertContains('page__front', $suggestions, 'Front page template was suggested.');
  }

  /** * Tests theme can provide classes. */
  public function testClassLoading() {
    // Install test theme and set it as default.     $this->config('system.theme')
      ->set('default', 'test_theme')
      ->save();
    $this->resetAll();
    // Visit page controller and confirm that the theme class is loaded.     $this->drupalGet('/theme-test/test-theme-class');
    $this->assertSession()->pageTextContains('Loading ThemeClass was successful.');
  }

  /** * Ensures a theme's .info.yml file is able to override a module CSS file from being added to the page. * * @see test_theme.info.yml */
  public function testCSSOverride() {
    
$link_title = $this->randomString();
    $this->submitForm(['title[0][value]' => $link_title], 'Save');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
    // Test the 'Delete' operation.     $this->clickLink('Delete');
    $this->assertSession()->pageTextContains("Are you sure you want to delete the custom menu link {$link_title}?");
    $this->submitForm([], 'Delete');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));

    // Clear the cache to ensure that recent caches aren't preventing us from     // seeing a broken add link.     $this->resetAll();
    $this->drupalGet('admin/structure/menu');

    // Select the edit menu link for our menu.     $links = $this->xpath('//*/td[contains(text(),:menu_label)]/following::a[normalize-space()=:link_label]', [':menu_label' => (string) $this->menu->label(), ':link_label' => 'Edit menu']);
    $links[0]->click();

    // Test the 'Add link' local action.     $this->clickLink('Add link');
    $link_title = $this->randomString();
    $this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
    $this->assertSession()->linkExists($link_title);
    
$this->mediaImage->setPublished()->save();
    $this->drupalGet($path['query' => ['uuid' => $uuid, 'token' => $token]]);
    $this->assertSession()->statusCodeEquals(403);
  }

  /** * Tests the media entity metadata API with translations. */
  public function testApiTranslation(): void {
    $this->container->get('module_installer')->install(['language', 'content_translation']);
    $this->resetAll();
    ConfigurableLanguage::create(['id' => 'fi'])->save();
    $this->container->get('config.factory')->getEditable('language.negotiation')
      ->set('url.source', 'path_prefix')
      ->set('url.prefixes.fi', 'fi')
      ->save();
    $this->rebuildContainer();
    ContentLanguageSettings::loadByEntityTypeBundle('media', 'image')
      ->setDefaultLangcode('en')
      ->setLanguageAlterable(TRUE)
      ->save();
    $media_fi = Media::load($this->mediaImage->id())->addTranslation('fi');
    
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Confirms that visiting the installer does not break things post-install. */
  public function testVisitInstallerPostInstall() {
    \Drupal::service('module_installer')->install(['system_test']);
    // Clear caches to ensure that system_test's routes are available.     $this->resetAll();
    // Confirm that the install_profile is correct.     $this->drupalGet('/system-test/get-install-profile');
    $this->assertSession()->pageTextContains('minimal');
    // Make an anonymous visit to the installer     $this->drupalLogout();
    $this->visitInstaller();
    // Ensure that the install profile is still correct.     $this->drupalGet('/system-test/get-install-profile');
    $this->assertSession()->pageTextContains('minimal');
  }

}
// Enable URL language detection and selection and set a prefix for both     // languages.     $edit = ['language_interface[enabled][language-url]' => 1];
    $this->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, 'Save settings');
    $edit = ['prefix[en]' => 'en'];
    $this->drupalGet('admin/config/regional/language/detection/url');
    $this->submitForm($edit, 'Save configuration');

    // Reset the cache after changing the negotiation settings as that changes     // how links are built.     $this->resetAll();

    $definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
    $this->assertTrue($definitions['path']->isTranslatable(), 'Node path is translatable.');
    $this->assertTrue($definitions['body']->isTranslatable(), 'Node body is translatable.');
  }

  /** * Creates content with a link field pointing to an alias of another language. * * @dataProvider providerLanguage */
  

    $assert_session->waitForElement('xpath', '//a[contains(text(), "Create a view")]');
    $assert_session->responseContains($views_text);

    $this->submitForm([], 'Save settings');
    // If no eligible view is available we should see a message.     $assert_session->pageTextContains('The views entity selection mode requires a view.');

    // Enable the entity_reference_test module which creates an eligible view.     $this->container->get('module_installer')
      ->install(['entity_reference_test']);
    $this->resetAll();
    $this->drupalGet($bundle_path . '/fields/' . $field_name);
    $page->findField('settings[handler]')->setValue('views');
    $assert_session
      ->waitForField('settings[handler_settings][view][view_and_display]')
      ->setValue('test_entity_reference:entity_reference_1');
    $this->submitForm([], 'Save settings');
    $assert_session->pageTextContains('Saved Test configuration.');

    // Switch the target type to 'entity_test'.     $edit = [
      'settings[target_type]' => 'entity_test',
    ];
'access administration pages',
      'administer permissions',
    ]);
    $this->drupalLogin($admin_user);

    // Add a language. The Afrikaans translation file of locale_test_translate     // (test.af.po) has been prepared with a configuration translation.     ConfigurableLanguage::createFromLangcode('af')->save();

    // Enable locale module.     $this->container->get('module_installer')->install(['locale']);
    $this->resetAll();

    // Enable import of translations. By default this is disabled for automated     // tests.     $this->config('locale.settings')
      ->set('translation.import_enabled', TRUE)
      ->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)
      ->save();

    // Add translation permissions now that the locale module has been enabled.     $edit = [
      'authenticated[translate interface]' => 'translate interface',
    ];
// Install the config_test module we're integrating with.     \Drupal::service('module_installer')->install(['config_test']);

    // Verify the configuration does not exist prior to installation.     $config_static = $this->config($default_config);
    $this->assertTrue($config_static->isNew());
    $config_entity = $this->config($default_configuration_entity);
    $this->assertTrue($config_entity->isNew());

    // Install the integration module.     \Drupal::service('module_installer')->install(['config_integration_test']);
    $this->resetAll();

    // Verify that default module config exists.     \Drupal::configFactory()->reset($default_config);
    \Drupal::configFactory()->reset($default_configuration_entity);
    $config_static = $this->config($default_config);
    $this->assertFalse($config_static->isNew());
    $this->assertSame('default setting', $config_static->get('foo'));
    $config_entity = $this->config($default_configuration_entity);
    $this->assertFalse($config_entity->isNew());
    $this->assertSame('Default integration config label', $config_entity->get('label'));

    
/** * Resets and rebuilds the environment after setup. */
  protected function rebuildAll() {
    // Reset/rebuild all data structures after enabling the modules, primarily     // to synchronize all data structures and caches between the test runner and     // the child site.     // @see \Drupal\Core\DrupalKernel::bootCode()     // @todo Test-specific setUp() methods may set up further fixtures; find a     // way to execute this after setUp() is done, or to eliminate it entirely.     $this->resetAll();

    // Explicitly call register() again on the container registered in \Drupal.     // @todo This should already be called through     // DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that     // appears to be calling a different container.     $this->container->get('stream_wrapper_manager')->register();
  }

  /** * Returns the parameters that will be used when the test installs Drupal. * * @see install_drupal() * @see install_state_defaults() * * @return array * Array of parameters for use in install_drupal(). */
// Load the stored user. The password hash shouldn't need a rehash.     $user_storage = $this->container->get('entity_type.manager')->getStorage('user');
    $account = User::load($account->id());

    // Check that the stored password doesn't need rehash.     $this->assertFalse($password_hasher->needsRehash($account->getPassword()));

    // The current hashing cost is set to 10 in the container. Increase cost by     // one, by enabling a module containing the necessary container changes.     \Drupal::service('module_installer')->install(['user_custom_pass_hash_params_test']);
    $this->resetAll();
    // Reload the hashing service after container changes.     $password_hasher = $this->container->get('password');

    // Check that the stored password does need rehash.     $this->assertTrue($password_hasher->needsRehash($account->getPassword()));

    $account->passRaw = $password;
    $this->drupalLogin($account);
    // Load the stored user, which should have a different password hash now.     $user_storage->resetCache([$account->id()]);
    $account = $user_storage->load($account->id());

    

  public function testInfoAlterations() {
    $this->stateSet([
      // Enable language_test type info.       'language_test.language_types' => TRUE,
      // Enable language_test negotiation info (not altered yet).       'language_test.language_negotiation_info' => TRUE,
      // Alter LanguageInterface::TYPE_CONTENT to be configurable.       'language_test.content_language_type' => TRUE,
    ]);
    $this->container->get('module_installer')->install(['language_test']);
    $this->resetAll();

    // Check that fixed language types are properly configured without the need     // of saving the language negotiation settings.     $this->checkFixedLanguageTypes();

    $type = LanguageInterface::TYPE_CONTENT;
    $language_types = $this->languageManager()->getLanguageTypes();
    $this->assertContains($type$language_types, 'Content language type is configurable.');

    // Enable some core and custom language negotiation methods. The test     // language type is supposed to be configurable.
Home | Imprint | This part of the site doesn't use cookies.