save example

protected function setUp($import_test_views = TRUE, $modules = ['comment_test_views']): void {
    parent::setUp($import_test_views$modules);
  }

  /** * Tests that "approve comment" link exists and works as expected. */
  public function testCommentApproveLink() {
    $this->drupalLogin($this->drupalCreateUser(['administer comments']));
    // Set the comment status to unpublished.     $this->comment->setUnpublished();
    $this->comment->save();
    $this->drupalGet('/admin/moderate-comments');
    $this->assertSession()->pageTextContains($this->comment->getSubject());
    $this->assertSession()->linkExists('Approve');
    $this->clickLink('Approve');
    $this->drupalGet('/admin/moderate-comments');
    $this->assertSession()->linkNotExists('Approve');
    // Ensure that "published" column in table is marked as yes.     $this->assertSession()->elementTextContains('xpath', "//table/tbody/tr/td[3]", 'Yes');
  }

}
return $form_state->getErrors();
  }

  /** * Tests widget constraint validation with composite constraints. */
  public function testValidationWithCompositeConstraint() {
    // First provide a valid value, this should cause no validation.     $entity = EntityTestCompositeConstraint::create([
      'name' => 'valid-value',
    ]);
    $entity->save();

    $errors = $this->getErrorsForEntity($entity);
    $this->assertFalse(isset($errors['name']));
    $this->assertFalse(isset($errors['type']));

    // Provide an invalid value for the name field.     $entity = EntityTestCompositeConstraint::create([
      'name' => 'failure-field-name',
    ]);
    $errors = $this->getErrorsForEntity($entity);
    $this->assertTrue(isset($errors['name']));
    
/** * Tests relative, root-relative, protocol-relative and absolute URLs. */
  public function testUrlHandling() {
    // Only the plain_text text format is available by default, which escapes     // all HTML.     FilterFormat::create([
      'format' => 'full_html',
      'name' => 'Full HTML',
      'filters' => [],
    ])->save();

    $defaults = [
      'type' => 'article',
      'promote' => 1,
    ];
    /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
    $file_url_generator = \Drupal::service('file_url_generator');
    $this->drupalCreateNode($defaults + [
      'body' => [
        'value' => '<p><a href="' . $file_url_generator->generateString('public://root-relative') . '">Root-relative URL</a></p>',
        'format' => 'full_html',
      ],

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a node type for testing.     NodeType::create(['type' => 'page', 'name' => 'page'])->save();

    // Add a file field.     FieldStorageConfig::create([
      'entity_type' => 'node',
      'field_name' => 'field_ief_file',
      'type' => 'file',
      'cardinality' => 1,
    ])->save();

    FieldConfig::create([
      'field_name' => 'field_ief_file',
      
return new ArrayAdapter($defaultLifetime);
    }

    public function testGetValuesHitAndMiss()
    {
        /** @var ArrayAdapter $cache */
        $cache = $this->createCachePool();

        // Hit         $item = $cache->getItem('foo');
        $item->set('::4711');
        $cache->save($item);

        $fooItem = $cache->getItem('foo');
        $this->assertTrue($fooItem->isHit());
        $this->assertEquals('::4711', $fooItem->get());

        // Miss (should be present as NULL in $values)         $cache->getItem('bar');

        // Fail (should be missing from $values)         $item = $cache->getItem('buz');
        $cache->save($item->set(function D) {}));

        
foreach (['user', 'node'] as $entity_type_id) {
      $this->installEntitySchema($entity_type_id);
    }
  }

  /** * Creates a painting node type. */
  protected function savePaintingType() {
    NodeType::create([
      'type' => 'painting',
    ])->save();
    $this->createTextField(
      'node', 'painting',
      'colors', 'Colors',
      FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
    );
    $this->createTextField(
      'node', 'painting',
      'shapes', 'Shapes',
      FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
    );
    $this->createImageField('photo', 'painting');
  }
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $filtered_html_format = FilterFormat::create([
      'format' => 'filtered_html',
      'name' => 'Filtered HTML',
    ]);
    $filtered_html_format->save();

    $this->drupalCreateContentType(['type' => 'test']);

    $user = $this->drupalCreateUser([
      'access content',
      'edit own test content',
      'create test content',
      $filtered_html_format->getPermissionName(),
    ]);
    $this->drupalLogin($user);
  }

  
$GLOBALS['config_test_run_module_overrides'] = TRUE;
    $name = 'system.site';
    $overridden_name = 'ZOMG overridden site name';
    $non_overridden_name = 'ZOMG this name is on disk mkay';
    $overridden_slogan = 'Yay for overrides!';
    $non_overridden_slogan = 'Yay for defaults!';
    $config_factory = $this->container->get('config.factory');
    $config_factory
      ->getEditable($name)
      ->set('name', $non_overridden_name)
      ->set('slogan', $non_overridden_slogan)
      ->save();

    $this->assertEquals($non_overridden_name$config_factory->get('system.site')->getOriginal('name', FALSE));
    $this->assertEquals($non_overridden_slogan$config_factory->get('system.site')->getOriginal('slogan', FALSE));
    $this->assertEquals($overridden_name$config_factory->get('system.site')->get('name'));
    $this->assertEquals($overridden_slogan$config_factory->get('system.site')->get('slogan'));

    // Test overrides of completely new configuration objects. In normal runtime     // this should only happen for configuration entities as we should not be     // creating simple configuration objects on the fly.     $config = $config_factory->get('config_override_test.new');
    $this->assertTrue($config->isNew(), 'The configuration object config_override_test.new is new');
    
/** * Tests the area handler. */
  public function testHTTPStatusCodeHandler() {
    $this->drupalGet('test-http-status-code');
    $this->assertSession()->statusCodeEquals(200);

    // Change the HTTP status code to 418.     $view = Views::getView('test_http_status_code');
    $display = &$view->storage->getDisplay('default');
    $display['display_options']['empty']['http_status_code']['status_code'] = 418;
    $view->save();

    // Test that the HTTP response is "I'm a teapot".     $this->drupalGet('test-http-status-code');
    $this->assertSession()->statusCodeEquals(418);
  }

}


  /** * {@inheritdoc} */
  protected function createEntity() {
    $entity_view_mode = EntityViewMode::create([
      'id' => 'user.test',
      'label' => 'Test',
      'targetEntityType' => 'user',
    ]);
    $entity_view_mode->save();
    return $entity_view_mode;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/entity_view_mode/entity_view_mode/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          


  /** * Tests template suggestions from big_pipe_theme_suggestions_big_pipe_interface_preview(). */
  public function testBigPipeThemeHookSuggestions() {
    $entity = $this->controller->create([
      'id' => 'test_block1',
      'theme' => 'stark',
      'plugin' => 'test_html',
    ]);
    $entity->save();

    // Test the rendering of a block.     $block = Block::load('test_block1');
    // Using the BlockViewBuilder we will be able to get a lovely     // #lazy_builder callback assigned.     $build = $this->blockViewBuilder->view($block);

    $variables = [];
    // In turn this is what createBigPipeJsPlaceholder() uses to     // build the BigPipe JS placeholder render array which is used as input     // for big_pipe_theme_suggestions_big_pipe_interface_preview().
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  public function testAjaxWithAdminRoute() {
    \Drupal::service('theme_installer')->install(['stable9', 'claro']);
    $theme_config = \Drupal::configFactory()->getEditable('system.theme');
    $theme_config->set('admin', 'claro');
    $theme_config->set('default', 'stable9');
    $theme_config->save();

    $account = $this->drupalCreateUser(['view the administration theme']);
    $this->drupalLogin($account);

    // First visit the site directly via the URL. This should render it in the     // admin theme.     $this->drupalGet('admin/ajax-test/theme');
    $assert = $this->assertSession();
    $assert->pageTextContains('Current theme: claro');

    // Now click the modal, which should also use the admin theme.

        ], Context::createDefaultContext());
    }

    private function enableAdminAccess(): void
    {
        $token = $this->browser->getServerParameter('HTTP_SW_CONTEXT_TOKEN');
        $payload = $this->getContainer()->get(SalesChannelContextPersister::class)->load($token$this->ids->get('sales-channel'));

        $payload[SalesChannelContextService::PERMISSIONS] = [ProductCartProcessor::ALLOW_PRODUCT_PRICE_OVERWRITES => true];

        $this->getContainer()->get(SalesChannelContextPersister::class)->save($token$payload$this->ids->get('sales-channel'));
    }
}
// We need to update the entity, so that the destination row IDs are     // correct.     $entity = $this->updateEntity($entity$row);
    $entity->isDefaultRevision(FALSE);
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
    $entity->save();
    return [$entity->getRevisionId()];
  }

  /** * {@inheritdoc} */
  public function getIds() {
    $ids = [];

    $revision_key = $this->getKey('revision');
    if (!$revision_key) {
      
protected function setUp(): void {
    parent::setUp();
    \Drupal::service('theme_installer')->install(['test_theme']);
  }

  /** * Tests that the Twig engine handles PHP data correctly. */
  public function testTwigVariableDataTypes() {
    $this->config('system.theme')
      ->set('default', 'test_theme')
      ->save();
    $this->drupalGet('twig-theme-test/php-variables');
    foreach (_test_theme_twig_php_values() as $type => $value) {
      $this->assertSession()->responseContains('<li>' . $type . ': ' . $value['expected'] . '</li>');
    }
  }

  /** * Tests the url and url_generate Twig functions. */
  public function testTwigUrlGenerator() {
    $this->drupalGet('twig-theme-test/url-generator');
    
Home | Imprint | This part of the site doesn't use cookies.