setContainerParameter example


  public function testTwigTransTags() {
    // Run this once without and once with Twig debug because trans can work     // differently depending on that setting.     $this->drupalGet('twig-theme-test/trans', ['language' => \Drupal::languageManager()->getLanguage('xx')]);
    $this->assertTwigTransTags();

    // Enable debug, rebuild the service container, and clear all caches.     $parameters = $this->container->getParameter('twig.config');
    $parameters['debug'] = TRUE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();
    $this->resetAll();

    $this->drupalGet('twig-theme-test/trans', ['language' => \Drupal::languageManager()->getLanguage('xx')]);
    $this->assertTwigTransTags();
  }

  /** * Tests empty Twig "trans" tags. */
  public function testEmptyTwigTransTags() {
    
$this->assertSame([]$cors_config['allowedHeaders']);
    $this->assertSame([]$cors_config['allowedMethods']);
    $this->assertSame(['*']$cors_config['allowedOrigins']);

    $this->assertFalse($cors_config['exposedHeaders']);
    $this->assertFalse($cors_config['maxAge']);
    $this->assertFalse($cors_config['supportsCredentials']);

    // Enable CORS with the default options.     $cors_config['enabled'] = TRUE;

    $this->setContainerParameter('cors.config', $cors_config);
    $this->rebuildContainer();

    // Fire off a request.     $this->drupalGet('/test-page', []['Origin' => 'http://example.com']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
    $this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', '*');
    $this->assertSession()->responseHeaderNotContains('Vary', 'Origin');

    // Fire the same exact request. This time it should be cached.     $this->drupalGet('/test-page', []['Origin' => 'http://example.com']);
    
// 6. controller result: CacheableResponse object, per-role cacheable route access.     $this->drupalGet('router_test/test22');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Contexts', 'user.roles');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'http_response');

    // Finally, verify that the X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags     // headers are not sent when their container parameter is set to FALSE.     $this->drupalGet('router_test/test18');
    $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Contexts');
    $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Tags');
    $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Max-Age');
    $this->setContainerParameter('http.response.debug_cacheability_headers', FALSE);
    $this->rebuildContainer();
    $this->resetAll();
    $this->drupalGet('router_test/test18');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache-Contexts');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache-Tags');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache-Max-Age');
  }

  /** * Confirms that multiple routes with the same path do not cause an error. */
  
/** * Tests the dump function. */
  public function testDump() {
    // Test Twig Debug disabled.     $this->drupalGet('/twig-theme-test/dump');
    $this->assertSession()->elementsCount('css', '.sf-dump', 0);

    // Test Twig Debug enabled.     $parameters = $this->container->getParameter('twig.config');
    $parameters['debug'] = TRUE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->resetAll();

    $this->drupalGet('/twig-theme-test/dump');
    $dumps = $this->getSession()->getPage()->findAll('css', '.sf-dump');
    $this->assertEquals(4, count($dumps));

    // Test dumping single variable.     $this->assertStringContainsString('💩', $dumps[0]->getText());
    $this->assertStringNotContainsString('🐣', $dumps[0]->getText());

    // Test dumping context.
Cache::invalidateTags($tags);
    $this->drupalGet($path);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
  }

  /** * Tests that the page cache doesn't depend on cacheability headers. */
  public function testPageCacheTagsIndependentFromCacheabilityHeaders() {
    // Disable the cacheability headers.     $this->setContainerParameter('http.response.debug_cacheability_headers', FALSE);
    $this->rebuildContainer();
    $this->resetAll();

    $path = 'system-test/cache_tags_page';
    $tags = ['system_test_cache_tags_page'];
    $this->drupalGet($path);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags.     $this->drupalGet($path);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
    

  protected $defaultTheme = 'stark';

  /** * Ensures Twig template auto reload setting can be overridden. */
  public function testTwigAutoReloadOverride() {
    // Enable auto reload and rebuild the service container.     $parameters = $this->container->getParameter('twig.config');
    $parameters['auto_reload'] = TRUE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();

    // Check isAutoReload() via the Twig service container.     $this->assertTrue($this->container->get('twig')->isAutoReload(), 'Automatic reloading of Twig templates enabled.');

    // Disable auto reload and check the service container again.     $parameters = $this->container->getParameter('twig.config');
    $parameters['auto_reload'] = FALSE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();

    
// After writing settings.php, the installer removes write permissions     // from the site directory. To allow drupal_generate_test_ua() to write     // a file containing the private key for drupal_valid_test_ua(), the site     // directory has to be writable.     // TestBase::restoreEnvironment() will delete the entire site directory.     // Not using File API; a potential error must trigger a PHP warning.     chmod(DRUPAL_ROOT . '/' . $this->siteDirectory, 0777);

    // During tests, cacheable responses should get the debugging cacheability     // headers by default.     $this->setContainerParameter('http.response.debug_cacheability_headers', TRUE);
  }

  /** * Initialize various configurations post-installation. * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * The container. */
  protected function initConfig(ContainerInterface $container) {
    $config = $container->get('config.factory');

    


  /** * {@inheritdoc} */
  protected function initConfig(ContainerInterface $container) {
    parent::initConfig($container);

    // Enable twig debugging to make testing template usage easy.     $parameters = $container->getParameter('twig.config');
    $parameters['debug'] = TRUE;
    $this->setContainerParameter('twig.config', $parameters);
  }

  /** * Tests the oembed media source. */
  public function testMediaOEmbedVideoSource() {
    $media_type_id = 'test_media_oembed_type';
    $provided_fields = [
      'type',
      'title',
      'default_name',
      

  public function testTwigDebugMarkup() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container->get('renderer');
    $extension = twig_extension();
    \Drupal::service('theme_installer')->install(['test_theme']);
    $this->config('system.theme')->set('default', 'test_theme')->save();
    $this->drupalCreateContentType(['type' => 'page']);
    // Enable debug, rebuild the service container, and clear all caches.     $parameters = $this->container->getParameter('twig.config');
    $parameters['debug'] = TRUE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();
    $this->resetAll();

    $cache = $this->container->get('theme.registry')->get();
    // Create array of Twig templates.     $templates = drupal_find_theme_templates($cache$extension$this->getThemePath('test_theme'));
    $templates += drupal_find_theme_templates($cache$extension$this->getModulePath('node'));

    // Create a node and test different features of the debug markup.     $node = $this->drupalCreateNode();
    $builder = \Drupal::entityTypeManager()->getViewBuilder('node');
    
Home | Imprint | This part of the site doesn't use cookies.