rebuildIfNeeded example

$this->assertFalse($access_plugin->access($this->normalUser));
    $this->drupalGet('test_access_static');
    $this->assertSession()->statusCodeEquals(403);

    $display = &$view->storage->getDisplay('default');
    $display['display_options']['access']['options']['access'] = TRUE;
    $access_plugin->options['access'] = TRUE;
    $view->save();
    // Saving a view will cause the router to be rebuilt when the kernel     // termination event fires. Simulate that here.     $this->container->get('router.builder')->rebuildIfNeeded();

    $this->assertTrue($access_plugin->access($this->normalUser));

    $this->drupalGet('test_access_static');
    $this->assertSession()->statusCodeEquals(200);
  }

}
$workflow_id = 'editorial';
    $this->drupalGet('/admin/config/workflow/workflows');
    $edit['bundles[' . $this->bundle . ']'] = TRUE;
    $this->drupalGet('admin/config/workflow/workflows/manage/' . $workflow_id . '/type/' . $this->entityTypeId);
    $this->submitForm($edit, 'Save');
    // Ensure the parent environment is up-to-date.     // @see content_moderation_workflow_insert()     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
    $router_builder = $this->container->get('router.builder');
    $router_builder->rebuildIfNeeded();
  }

  /** * {@inheritdoc} */
  protected function getEditorPermissions() {
    $editor_permissions = [
      "edit any {$this->bundle} content",
      "delete any {$this->bundle} content",
      "view {$this->bundle} revisions",
      "delete {$this->bundle} revisions",
    ];
$this->lock->expects($this->once())
      ->method('release')
      ->with('router_rebuild');

    $this->yamlDiscovery->expects($this->any())
      ->method('findAll')
      ->willReturn([]);

    $this->routeBuilder->setRebuildNeeded();

    // This will trigger a successful rebuild.     $this->assertTrue($this->routeBuilder->rebuildIfNeeded());

    // This will not trigger a rebuild.     $this->assertFalse($this->routeBuilder->rebuildIfNeeded());
  }

  /** * Tests routes can use alternative compiler classes. * * @see \Drupal\Core\Routing\RouteBuilder::rebuild() */
  public function testRebuildWithOverriddenRouteClass() {
    

  protected function refreshTestStateAfterRestConfigChange() {
    // Ensure that the cache tags invalidator has its internal values reset.     // Otherwise the http_response cache tag invalidation won't work.     $this->refreshVariables();

    // Tests using this base class may trigger route rebuilds due to changes to     // RestResourceConfig entities. Ensure the test generates routes using an     // up-to-date router.     \Drupal::service('router.builder')->rebuildIfNeeded();
  }

  /** * Return the expected error message. * * @param string $method * The HTTP method (GET, POST, PATCH, DELETE). * * @return string * The error string. */
  
    $this->drupalGet('test-disabled-display-2');
    $this->assertSession()->statusCodeEquals(404);

    // Enable each disabled display and save the view.     foreach ($display_ids as $display_id) {
      $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', TRUE);
      $view->save();
      $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
      $this->assertTrue($enabled, 'Display ' . $display_id . ' is now enabled');
    }

    \Drupal::service('router.builder')->rebuildIfNeeded();

    // Check that the originally disabled page_2 display is now enabled.     $this->drupalGet('test-disabled-display-2');
    $this->assertSession()->elementTextEquals('xpath', '//h1[@class="page-title"]', 'test_disabled_display');

    // Disable each disabled display and save the view.     foreach ($display_ids as $display_id) {
      $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', FALSE);
      $view->save();
      $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
      $this->assertFalse($enabled, 'Display ' . $display_id . ' is now disabled');
    }
/** * Installs a given list of modules and rebuilds the cache. * * @param string[] $module_list * An array of module names. */
  protected function installExtraModules(array $module_list) {
    \Drupal::service('module_installer')->install($module_list);

    // Installing modules updates the container and needs a router rebuild.     $this->container = \Drupal::getContainer();
    $this->container->get('router.builder')->rebuildIfNeeded();
  }

}
    // so no menu rebuild was executed (so the path is still available).     $config = $this->config('views.view.test_display_invalid');
    $config->set('display.page_1.display_plugin', 'invalid');
    $config->save();

    $this->drupalGet('test_display_invalid');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('The "invalid" plugin does not exist.');

    // Rebuild the router, and ensure that the path is not accessible anymore.     views_invalidate_cache();
    \Drupal::service('router.builder')->rebuildIfNeeded();

    $this->drupalGet('test_display_invalid');
    $this->assertSession()->statusCodeEquals(404);

    // Change the display plugin ID back to the correct ID.     $config = $this->config('views.view.test_display_invalid');
    $config->set('display.page_1.display_plugin', 'page');
    $config->save();

    // Place the block display.     $block = $this->drupalPlaceBlock('views_block:test_display_invalid-block_1', ['label' => 'Invalid display']);

    
$this->drupalGet('/admin/config/workflow/workflows');
    $this->assertSession()->linkByHrefExists('admin/config/workflow/workflows/manage/' . $workflow_id);
    $edit['bundles[' . $content_type_id . ']'] = TRUE;
    $this->drupalGet('admin/config/workflow/workflows/manage/' . $workflow_id . '/type/node');
    $this->submitForm($edit, 'Save');
    // Ensure the parent environment is up-to-date.     // @see content_moderation_workflow_insert()     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
    $router_builder = $this->container->get('router.builder');
    $router_builder->rebuildIfNeeded();
  }

  /** * Grants given user permission to create content of given type. * * @param \Drupal\Core\Session\AccountInterface $account * User to grant permission to. * @param string $content_type_id * Content type ID. */
  protected function grantUserPermissionToCreateContentOfType(AccountInterface $account$content_type_id) {
    
$view = Views::getView('test_display');
    $view->storage->setStatus(TRUE);
    $view->setDisplay('page_1');
    $view->display_handler->overrideOption('cache', [
      'type' => 'time',
      'options' => [
        'results_lifespan' => '3600',
        'output_lifespan' => '3600',
      ],
    ]);
    $view->save();
    $this->container->get('router.builder')->rebuildIfNeeded();

    /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
    $render_cache = \Drupal::service('render_cache');
    $cache_element = DisplayPluginBase::buildBasicRenderable('test_display', 'page_1');
    $cache_element['#cache'] += ['contexts' => $this->container->getParameter('renderer.config')['required_cache_contexts']];
    $this->assertFalse($render_cache->get($cache_element));

    $this->drupalGet('test-display');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertNotEmpty($render_cache->get($cache_element));
    $cache_tags = [
      
$themes = [
      'olivero',
      'claro',
      'stark',
    ];
    \Drupal::service('theme_installer')->install($themes);

    foreach ($themes as $theme) {
      $theme_config = \Drupal::configFactory()->getEditable('system.theme');
      $theme_config->set('default', $theme);
      $theme_config->save();
      \Drupal::service('router.builder')->rebuildIfNeeded();

      $this->drupalGet('ajax-test/exception-link');
      $page = $this->getSession()->getPage();
      // We don't want the test to error out because of an expected Javascript       // console error.       $this->failOnJavascriptConsoleErrors = FALSE;
      // Click on the AJAX link.       $this->clickLink('Ajax Exception');
      $this->assertSession()
        ->statusMessageContainsAfterWait("Oops, something went wrong. Check your browser's developer console for more details.", 'error');

      
parent::setUp();

    $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
    $moderated_bundle->save();

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated_bundle');
    $workflow->save();

    /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
    $router_builder = $this->container->get('router.builder');
    $router_builder->rebuildIfNeeded();

    $admin = $this->drupalCreateUser([
      'access content overview',
      'administer nodes',
      'bypass node access',
      'view all revisions',
      'use editorial transition create_new_draft',
      'use editorial transition publish',
    ]);
    $this->drupalLogin($admin);
  }

  
/** * Tests role access plugin. */
  public function testAccessRole() {
    /** @var \Drupal\views\ViewEntityInterface $view */
    $view = \Drupal::entityTypeManager()->getStorage('view')->load('test_access_role');
    $display = &$view->getDisplay('default');
    $display['display_options']['access']['options']['role'] = [
      $this->normalRole => $this->normalRole,
    ];
    $view->save();
    $this->container->get('router.builder')->rebuildIfNeeded();
    $expected = [
      'config' => ['user.role.' . $this->normalRole],
      'module' => ['user', 'views_test_data'],
    ];
    $this->assertSame($expected$view->calculateDependencies()->getDependencies());

    $executable = Views::executableFactory()->get($view);
    $executable->setDisplay('page_1');

    $access_plugin = $executable->display_handler->getPlugin('access');
    $this->assertInstanceOf(Role::class$access_plugin);

    
$dialog_buttons->pressButton('Apply');
      $this->assertJsCondition("document.title === '" . $new_title . " (Content) | " . \Drupal::config('system.site')->get('name') . "'");
    }
  }

  /** * Tests contextual links on Views page displays. */
  public function testPageContextualLinks() {
    $view = View::load('test_display');
    $view->enable()->save();
    $this->container->get('router.builder')->rebuildIfNeeded();

    // Create node so the view has content and the contextual area is higher     // than 0 pixels.     $this->drupalCreateContentType(['type' => 'page']);
    $this->createNode();

    // When no "main content" block is placed, we find a contextual link     // placeholder for editing just the view.     $this->drupalGet('test-display');
    $page = $this->getSession()->getPage();
    $this->assertSession()->assertWaitOnAjaxRequest();

    
$this->assertLocalTasks();
    // Test that default secondary tab is in first position.     $this->assertSession()->elementsCount('xpath', "//ul/li[1]/a[contains(text(), 'Default')]", 1);

    // Create new view mode and verify it's available on the Manage Display     // screen after enabling it.     EntityViewMode::create([
      'id' => 'user.test',
      'label' => 'Test',
      'targetEntityType' => 'user',
    ])->save();
    $this->container->get('router.builder')->rebuildIfNeeded();

    $edit = ['display_modes_custom[test]' => TRUE];
    $this->drupalGet('admin/config/people/accounts/display');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->linkExists('Test');

    // Create new form mode and verify it's available on the Manage Form     // Display screen after enabling it.     EntityFormMode::create([
      'id' => 'user.test',
      'label' => 'Test',
      
->setCardinality(3)
      ->save();
    FieldConfig::create([
      'entity_type' => static::$entityTypeId,
      'field_name' => 'field_rest_test_multivalue',
      'bundle' => $entity_bundle,
    ])
      ->setLabel('Test field: multi-value')
      ->setTranslatable(FALSE)
      ->save();

    \Drupal::service('router.builder')->rebuildIfNeeded();

    // Reload entity so that it has the new field.     $reloaded_entity = $this->entityLoadUnchanged($entity->id());
    // Some entity types are not stored, hence they cannot be reloaded.     if ($reloaded_entity !== NULL) {
      $entity = $reloaded_entity;

      // Set a default value on the fields.       $entity->set('field_rest_test', ['value' => 'All the faith he had had had had no effect on the outcome of his life.']);
      $entity->set('field_jsonapi_test_entity_ref', ['user' => $account->id()]);
      $entity->set('field_rest_test_multivalue', [['value' => 'One']['value' => 'Two']]);
      
Home | Imprint | This part of the site doesn't use cookies.