getChangedTime example

    $edit['current_pass'] = $user1->passRaw;
    $this->drupalGet("user/" . $user1->id() . "/edit");
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("The changes have been saved.");

    // Confirm there's only one session in the database as the existing session     // has been migrated when the password is changed.     // @see \Drupal\user\Entity\User::postSave()     $this->assertSame(1, (int) \Drupal::database()->select('sessions', 's')->countQuery()->execute()->fetchField());

    // Make sure the changed timestamp is updated.     $this->assertEquals(REQUEST_TIME, $user1->getChangedTime(), 'Changing a user sets "changed" timestamp.');

    // Make sure the user can log in with their new password.     $this->drupalLogout();
    $user1->passRaw = $new_pass;
    $this->drupalLogin($user1);
    $this->drupalLogout();

    // Test that the password strength indicator displays.     $config = $this->config('user.settings');
    $this->drupalLogin($user1);

    
$tests['[node:body]'] = $node->body->processed;
    $tests['[node:summary]'] = $node->body->summary_processed;
    $tests['[node:langcode]'] = $node->language()->getId();
    $tests['[node:url]'] = $node->toUrl('canonical', $url_options)->toString();
    $tests['[node:edit-url]'] = $node->toUrl('edit-form', $url_options)->toString();
    $tests['[node:author]'] = $account->getAccountName();
    $tests['[node:author:uid]'] = $node->getOwnerId();
    $tests['[node:author:name]'] = $account->getAccountName();
    /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
    $date_formatter = $this->container->get('date.formatter');
    $tests['[node:created:since]'] = $date_formatter->formatTimeDiffSince($node->getCreatedTime()['langcode' => $this->interfaceLanguage->getId()]);
    $tests['[node:changed:since]'] = $date_formatter->formatTimeDiffSince($node->getChangedTime()['langcode' => $this->interfaceLanguage->getId()]);

    $base_bubbleable_metadata = BubbleableMetadata::createFromObject($node);

    $metadata_tests = [];
    $metadata_tests['[node:nid]'] = $base_bubbleable_metadata;
    $metadata_tests['[node:vid]'] = $base_bubbleable_metadata;
    $metadata_tests['[node:type]'] = $base_bubbleable_metadata;
    $metadata_tests['[node:type-name]'] = $base_bubbleable_metadata;
    $metadata_tests['[node:title]'] = $base_bubbleable_metadata;
    $metadata_tests['[node:body]'] = $base_bubbleable_metadata;
    $metadata_tests['[node:summary]'] = $base_bubbleable_metadata;
    
$rel = 'canonical';
    if ($entity instanceof ContentEntityInterface && !$entity->isDefaultRevision()) {
      $rel = 'revision';
      $key .= '_revision';
    }
    if ($entity->hasLinkTemplate($rel) && $entity->toUrl($rel)->isRouted()) {
      $build['#contextual_links'][$key] = [
        'route_parameters' => $entity->toUrl($rel)->getRouteParameters(),
      ];
      if ($entity instanceof EntityChangedInterface) {
        $build['#contextual_links'][$key]['metadata'] = [
          'changed' => $entity->getChangedTime(),
        ];
      }
    }
  }

  /** * Specific per-entity building. * * @param array $build * The render array that is being created. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to be prepared. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display * The entity view display holding the display options configured for the * entity components. * @param string $view_mode * The view mode that should be used to prepare the entity. */
public function testTimestamps() {
    // Use the default timestamps.     $edit = [
      'uid' => $this->webUser->id(),
      'type' => 'article',
      'title' => $this->randomMachineName(8),
    ];

    Node::create($edit)->save();
    $node = $this->drupalGetNodeByTitle($edit['title']);
    $this->assertEquals(REQUEST_TIME, $node->getCreatedTime(), 'Creating a node sets default "created" timestamp.');
    $this->assertEquals(REQUEST_TIME, $node->getChangedTime(), 'Creating a node sets default "changed" timestamp.');

    // Store the timestamps.     $created = $node->getCreatedTime();

    $node->save();
    $node = $this->drupalGetNodeByTitle($edit['title'], TRUE);
    $this->assertEquals($created$node->getCreatedTime(), 'Updating a node preserves "created" timestamp.');

    // Programmatically set the timestamps using hook_ENTITY_TYPE_presave().     $node->title = 'testing_node_presave';

    
'd7_custom_block_translation',
    ]);
  }

  /** * Tests the Drupal 7 i18n content block strings to Drupal 8 migration. */
  public function testCustomBlockContentTranslation() {
    /** @var \Drupal\block_content\Entity\BlockContent $block */
    $block = BlockContent::load(1)->getTranslation('fr');
    $this->assertSame('fr - Mildly amusing limerick of the day', $block->label());
    $this->assertGreaterThanOrEqual($block->getChangedTime(), \Drupal::time()->getRequestTime());
    $this->assertLessThanOrEqual(time()$block->getChangedTime());
    $this->assertSame('fr', $block->language()->getId());
    $translation = "fr - A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall";
    $this->assertSame($translation$block->body->value);
    $this->assertSame('filtered_html', $block->body->format);

    $block = $block->getTranslation('is');
    $this->assertSame('is - Mildly amusing limerick of the day', $block->label());
    $this->assertGreaterThanOrEqual($block->getChangedTime(), \Drupal::time()->getRequestTime());
    $this->assertLessThanOrEqual(time()$block->getChangedTime());
    $this->assertSame('is', $block->language()->getId());
    
// Generate and test sanitized tokens.     $tests = [];
    $tests['[file:fid]'] = $file->id();
    $tests['[file:name]'] = Html::escape($file->getFilename());
    $tests['[file:path]'] = Html::escape($file->getFileUri());
    $tests['[file:mime]'] = Html::escape($file->getMimeType());
    $tests['[file:size]'] = format_size($file->getSize());
    $tests['[file:url]'] = Html::escape($file->createFileUrl(FALSE));
    $tests['[file:created]'] = $date_formatter->format($file->getCreatedTime(), 'medium', '', NULL, $language_interface->getId());
    $tests['[file:created:short]'] = $date_formatter->format($file->getCreatedTime(), 'short', '', NULL, $language_interface->getId());
    $tests['[file:changed]'] = $date_formatter->format($file->getChangedTime(), 'medium', '', NULL, $language_interface->getId());
    $tests['[file:changed:short]'] = $date_formatter->format($file->getChangedTime(), 'short', '', NULL, $language_interface->getId());
    $tests['[file:owner]'] = Html::escape($this->adminUser->getDisplayName());
    $tests['[file:owner:uid]'] = $file->getOwnerId();

    $base_bubbleable_metadata = BubbleableMetadata::createFromObject($file);
    $metadata_tests = [];
    $metadata_tests['[file:fid]'] = $base_bubbleable_metadata;
    $metadata_tests['[file:name]'] = $base_bubbleable_metadata;
    $metadata_tests['[file:path]'] = $base_bubbleable_metadata;
    $metadata_tests['[file:mime]'] = $base_bubbleable_metadata;
    $metadata_tests['[file:size]'] = $base_bubbleable_metadata;
    
'links' => [
        'self' => ['href' => $self_url],
      ],
      'data' => [
        'id' => $file->uuid(),
        'type' => 'file--file',
        'links' => [
          'self' => ['href' => $self_url],
        ],
        'attributes' => [
          'created' => (new \DateTime())->setTimestamp($file->getCreatedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'changed' => (new \DateTime())->setTimestamp($file->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'filemime' => 'text/plain',
          'filename' => $expected_as_filename ? $expected_filename : 'example.txt',
          'filesize' => strlen($this->testFileData),
          'langcode' => 'en',
          'status' => $expected_status,
          'uri' => [
            'value' => 'public://foobar/' . $expected_filename,
            'url' => base_path() . $this->siteDirectory . '/files/foobar/' . rawurlencode($expected_filename),
          ],
          'drupal_internal__fid' => (int) $file->id(),
        ],
        
'links' => [
        'self' => ['href' => $self_url],
      ],
      'data' => [
        'id' => $this->entity->uuid(),
        'type' => 'comment--comment',
        'links' => [
          'self' => ['href' => $self_url],
        ],
        'attributes' => [
          'created' => '1973-11-29T21:33:09+00:00',
          'changed' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'comment_body' => [
            'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
            'format' => 'plain_text',
            'processed' => "<p>The name &quot;llama&quot; was adopted by European settlers from native Peruvians.</p>\n",
          ],
          'default_langcode' => TRUE,
          'entity_type' => 'entity_test',
          'field_name' => 'comment',
          'homepage' => NULL,
          'langcode' => 'en',
          'name' => NULL,
          

  protected $defaultTheme = 'stark';

  /** * Tests user creation and display from the administration interface. */
  public function testUserAdd() {
    $user = $this->drupalCreateUser(['administer users']);
    $this->drupalLogin($user);

    $this->assertEquals(REQUEST_TIME, $user->getCreatedTime(), 'Creating a user sets default "created" timestamp.');
    $this->assertEquals(REQUEST_TIME, $user->getChangedTime(), 'Creating a user sets default "changed" timestamp.');

    // Create a field.     $field_name = 'test_field';
    FieldStorageConfig::create([
      'field_name' => $field_name,
      'entity_type' => 'user',
      'module' => 'image',
      'type' => 'image',
      'cardinality' => 1,
      'locked' => FALSE,
      'indexes' => ['target_id' => ['target_id']],
      
'parent' => $expected_parent_normalization,
      'weight' => [
        ['value' => 0],
      ],
      'langcode' => [
        [
          'value' => 'en',
        ],
      ],
      'changed' => [
        [
          'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'default_langcode' => [
        [
          'value' => TRUE,
        ],
      ],
      'path' => [
        [
          'alias' => '/llama',
          
'd6_custom_block',
    ]);
  }

  /** * Tests the Drupal 6 content block to Drupal 8 migration. */
  public function testBlockMigration() {
    /** @var \Drupal\block_content\Entity\BlockContent $block */
    $block = BlockContent::load(1);
    $this->assertSame('My block 1', $block->label());
    $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
    $this->assertLessThanOrEqual(time()$block->getChangedTime());
    $this->assertSame('en', $block->language()->getId());
    $this->assertSame('<h3>My first content block body</h3>', $block->body->value);
    $this->assertSame('full_html', $block->body->format);

    $block = BlockContent::load(2);
    $this->assertSame('My block 2', $block->label());
    $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
    $this->assertLessThanOrEqual(time()$block->getChangedTime());
    $this->assertSame('en', $block->language()->getId());
    $this->assertSame('<h3>My second content block body</h3>', $block->body->value);
    
$this->drupalGet('node/add/page');
    $this->assertSession()->pageTextNotContains('Not saved yet');

    // Create node to edit.     $edit['title[0][value]'] = $this->randomMachineName(8);
    $edit['body[0][value]'] = $this->randomMachineName(16);
    $this->submitForm($edit, 'Save');

    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
    $this->drupalGet("node/" . $node->id() . "/edit");
    $this->assertSession()->pageTextNotContains('Published');
    $this->assertSession()->pageTextNotContains($this->container->get('date.formatter')->format($node->getChangedTime(), 'short'));

    // Check that users with the 'administer nodes' permission can see the meta     // information.     $this->drupalLogin($this->adminUser);
    $this->drupalGet('node/add/page');
    $this->assertSession()->pageTextContains('Not saved yet');

    // Create node to edit.     $edit['title[0][value]'] = $this->randomMachineName(8);
    $edit['body[0][value]'] = $this->randomMachineName(16);
    $this->submitForm($edit, 'Save');

    
// Create a second revision of node1.     $node1_revision_1 = $node1;
    $node1->setNewRevision(TRUE);
    $node1->setTitle('Node revision 2 title');
    $node1->save();

    $connection = Database::getConnection();
    // Change the changed time for node so that we can test ordering.     $connection->update('node_field_data')
      ->fields([
        'changed' => $node1->getChangedTime() + 100,
      ])
      ->condition('nid', $node2->id())
      ->execute();
    $connection->update('node_field_data')
      ->fields([
        'changed' => $node1->getChangedTime() + 200,
      ])
      ->condition('nid', $node3->id())
      ->execute();

    // Test that a user without the 'access content' permission cannot
if ($this->operation == 'edit') {
      $form['#title'] = $this->t('<em>Edit @type</em> @title', [
        '@type' => node_get_type_label($node),
        '@title' => $node->label(),
      ]);
    }

    // Changed must be sent to the client, for later overwrite error checking.     $form['changed'] = [
      '#type' => 'hidden',
      '#default_value' => $node->getChangedTime(),
    ];

    $form = parent::form($form$form_state);

    $form['advanced']['#attributes']['class'][] = 'entity-meta';

    $form['meta'] = [
      '#type' => 'details',
      '#group' => 'advanced',
      '#weight' => -10,
      '#title' => $this->t('Status'),
      
'#markup' => $this->t('@entity_type_label: @entity_bundle_label', [
                '@entity_type_label' => $entity_type->getLabel(),
                '@entity_bundle_label' => $bundle_info[$entity_type_id][$revision->bundle()]['label'],
              ]),
            ];
          }
          else {
            $type = ['#markup' => $bundle_info[$entity_type_id][$revision->bundle()]['label']];
          }

          $changed = $revision instanceof EntityChangedInterface
            ? $this->dateFormatter->format($revision->getChangedTime())
            : '';

          if ($revision instanceof EntityOwnerInterface && isset($revision_owners[$revision->getOwnerId()])) {
            $author = [
              '#theme' => 'username',
              '#account' => $revision_owners[$revision->getOwnerId()],
            ];
          }
          else {
            $author = ['#markup' => ''];
          }

          
Home | Imprint | This part of the site doesn't use cookies.