getCreatedTime example


  protected function getExpectedNormalizedEntity() {
    return [
      'changed' => [
        [
          'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'created' => [
        [
          'value' => (new \DateTime())->setTimestamp((int) $this->entity->getCreatedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'fid' => [
        [
          'value' => 1,
        ],
      ],
      'filemime' => [
        [
          'value' => 'text/plain',
        ],

  protected function assertEntity(string $id, string $type, string $langcode, string $title, int $uid, bool $status, int $created, int $changed, bool $promoted, bool $sticky): void {
    /** @var \Drupal\node\NodeInterface $node */
    $node = Node::load($id);
    $this->assertInstanceOf(NodeInterface::class$node);
    $this->assertEquals($type$node->getType());
    $this->assertEquals($langcode$node->langcode->value);
    $this->assertEquals($title$node->getTitle());
    $this->assertEquals($uid$node->getOwnerId());
    $this->assertEquals($status$node->isPublished());
    $this->assertEquals($created$node->getCreatedTime());
    if (isset($changed)) {
      $this->assertEquals($changed$node->getChangedTime());
    }
    $this->assertEquals($promoted$node->isPromoted());
    $this->assertEquals($sticky$node->isSticky());
  }

  /** * Asserts various aspects of a node revision. * * @param int $id * The revision ID. * @param string $title * The expected title. * @param int $uid * The revision author ID. * @param string|null $log * The revision log message. * @param int $timestamp * The revision's time stamp. * * @internal */
$form['content_translation']['uid'] = [
        '#type' => 'entity_autocomplete',
        '#title' => t('Authored by'),
        '#target_type' => 'user',
        '#default_value' => User::load($uid),
        // Validation is done by static::entityFormValidate().         '#validate_reference' => FALSE,
        '#maxlength' => 60,
        '#description' => t('Leave blank for %anonymous.', ['%anonymous' => \Drupal::config('user.settings')->get('anonymous')]),
      ];

      $date = $new_translation ? REQUEST_TIME : $metadata->getCreatedTime();
      $form['content_translation']['created'] = [
        '#type' => 'textfield',
        '#title' => t('Authored on'),
        '#maxlength' => 25,
        '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', [
          '%time' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'),
          '%timezone' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'O'),
        ]),
        '#default_value' => $new_translation || !$date ? '' : $this->dateFormatter->format($date, 'custom', 'Y-m-d H:i:s O'),
      ];

      
    $langcode = 'it';
    $values = $entity->toArray();
    // Apply a default value for the metadata fields.     foreach ($metadata_fields as $field_name) {
      unset($values[$field_name]);
    }
    $entity->addTranslation($langcode$values);

    $metadata_source_translation = $this->manager->getTranslationMetadata($entity->getTranslation($default_langcode));
    $metadata_target_translation = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));

    $created_time = $metadata_source_translation->getCreatedTime();
    $changed_time = $metadata_source_translation->getChangedTime();
    $published = $metadata_source_translation->isPublished();
    $author = $metadata_source_translation->getAuthor();

    $this->assertEquals($created_time$metadata_target_translation->getCreatedTime(), 'Metadata created field has the same value for both translations.');
    $this->assertEquals($changed_time$metadata_target_translation->getChangedTime(), 'Metadata changed field has the same value for both translations.');
    $this->assertEquals($published$metadata_target_translation->isPublished(), 'Metadata published field has the same value for both translations.');
    $this->assertEquals($author->id()$metadata_target_translation->getAuthor()->id(), 'Metadata author field has the same value for both translations.');

    $metadata_target_translation->setCreatedTime(time() + 50);
    $metadata_target_translation->setChangedTime(time() + 50);
    

      '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(),
        ],
return $workspace;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    $author = User::load($this->entity->getOwnerId());
    return [
      'created' => [
        [
          'value' => (new \DateTime())->setTimestamp((int) $this->entity->getCreatedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'changed' => [
        [
          'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'id' => [
        [
          
$replacements[$original] = $node->toUrl('edit-form', $url_options)->toString();
          break;

        // Default values for the chained tokens handled below.         case 'author':
          $account = $node->getOwner() ? $node->getOwner() : User::load(0);
          $replacements[$original] = $account->label();
          $bubbleable_metadata->addCacheableDependency($account);
          break;

        case 'created':
          $replacements[$original] = \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'medium', '', NULL, $langcode);
          break;
      }
    }

    if ($author_tokens = $token_service->findWithPrefix($tokens, 'author')) {
      $replacements += $token_service->generate('user', $author_tokens['user' => $node->getOwner()]$options$bubbleable_metadata);
    }

    if ($created_tokens = $token_service->findWithPrefix($tokens, 'created')) {
      $replacements += $token_service->generate('date', $created_tokens['date' => $node->getCreatedTime()]$options$bubbleable_metadata);
    }
  }
// Verify that the creation message contains a link to a node.     $this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');

    // Check that the node exists in the database.     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
    $this->assertNotEmpty($node, 'Node found in database.');

    // Verify that pages do not show submitted information by default.     $this->drupalGet('node/' . $node->id());
    $this->assertSession()->pageTextNotContains($node->getOwner()->getAccountName());
    $this->assertSession()->pageTextNotContains($this->container->get('date.formatter')->format($node->getCreatedTime()));

    // Change the node type setting to show submitted by information.     /** @var \Drupal\node\NodeTypeInterface $node_type */
    $node_type = $node_type_storage->load('page');
    $node_type->setDisplaySubmitted(TRUE);
    $node_type->save();

    $this->drupalGet('node/' . $node->id());
    $this->assertSession()->pageTextContains($node->getOwner()->getAccountName());
    $this->assertSession()->pageTextContains($this->container->get('date.formatter')->format($node->getCreatedTime()));

    
// Load the specified comment and its associated node:     /** @var \Drupal\comment\CommentInterface $comment */
    $comment = $this->comments[$cid];
    if (empty($comment)) {
      return;
    }

    $comment->rss_namespaces = [];
    $comment->rss_elements = [
      [
        'key' => 'pubDate',
        'value' => gmdate('r', $comment->getCreatedTime()),
      ],
      [
        'key' => 'dc:creator',
        'value' => $comment->getAuthorName(),
      ],
      [
        'key' => 'guid',
        'value' => 'comment ' . $comment->id() . ' at ' . $base_url,
        'attributes' => ['isPermaLink' => 'false'],
      ],
    ];

    

          'value' => 19,
        ],
      ],
      'status' => [
        [
          'value' => FALSE,
        ],
      ],
      'created' => [
        [
          'value' => (new \DateTime())->setTimestamp($file->getCreatedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'changed' => [
        [
          'value' => (new \DateTime())->setTimestamp($file->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
    ];
  }

  
$id_map = $this->getMigration('d6_user_role')->getIdMap();
      foreach ($rids as $rid) {
        $role = $id_map->lookupDestinationIds([$rid])[0];
        $roles[] = reset($role);
      }

      /** @var \Drupal\user\UserInterface $user */
      $user = User::load($source->uid);
      $this->assertSame($source->uid, $user->id());
      $this->assertSame($source->name, $user->label());
      $this->assertSame($source->mail, $user->getEmail());
      $this->assertSame($source->created, $user->getCreatedTime());
      $this->assertSame($source->access, $user->getLastAccessedTime());
      $this->assertSame($source->login, $user->getLastLoginTime());
      $is_blocked = $source->status == 0;
      $this->assertSame($is_blocked$user->isBlocked());
      $expected_timezone_name = $source->timezone_name ?: $this->config('system.date')->get('timezone.default');
      $this->assertSame($expected_timezone_name$user->getTimeZone());
      $this->assertSame($source->init, $user->getInitialEmail());
      $this->assertSame($roles$user->getRoles());

      // Ensure the user's langcode, preferred_langcode and       // preferred_admin_langcode are valid.

  public function testComplexRender() {
    $executable = Views::getView('test_field_field_complex_test');
    $executable->execute();
    $date_formatter = \Drupal::service('date.formatter');

    $this->assertEquals($this->testUsers[0]->getTimeZone()$executable->getStyle()->getField(0, 'timezone'));
    $this->assertEquals("1, 3", $executable->getStyle()->getField(0, 'field_test_multiple'));
    $this->assertEquals("1", $executable->getStyle()->getField(0, 'field_test_multiple_1'));
    $this->assertEquals("3", $executable->getStyle()->getField(0, 'field_test_multiple_2'));
    $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'Y')trim(strip_tags($executable->getStyle()->getField(0, 'created'))));
    $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'H:i:s')trim(strip_tags($executable->getStyle()->getField(0, 'created_1'))));
    $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'fallback')trim(strip_tags($executable->getStyle()->getField(0, 'created_2'))));

    $this->assertEquals($this->testUsers[1]->getTimeZone()$executable->getStyle()->getField(1, 'timezone'));
    $this->assertEquals("7, 0", $executable->getStyle()->getField(1, 'field_test_multiple'));
    $this->assertEquals("7", $executable->getStyle()->getField(1, 'field_test_multiple_1'));
    $this->assertEquals("0", $executable->getStyle()->getField(1, 'field_test_multiple_2'));
    $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'Y')trim(strip_tags($executable->getStyle()->getField(1, 'created'))));
    $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'H:i:s')trim(strip_tags($executable->getStyle()->getField(1, 'created_1'))));
    $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'fallback')trim(strip_tags($executable->getStyle()->getField(1, 'created_2'))));

    
// Generate and test tokens.     $tests = [];
    $tests['[user:uid]'] = $account->id();
    $tests['[user:name]'] = $account->getAccountName();
    $tests['[user:account-name]'] = $account->getAccountName();
    $tests['[user:display-name]'] = $account->getDisplayName();
    $tests['[user:mail]'] = $account->getEmail();
    $tests['[user:url]'] = $account->toUrl('canonical', $url_options)->toString();
    $tests['[user:edit-url]'] = $account->toUrl('edit-form', $url_options)->toString();
    $tests['[user:last-login]'] = $date_formatter->format($account->getLastLoginTime(), 'medium', '', NULL, $language_interface->getId());
    $tests['[user:last-login:short]'] = $date_formatter->format($account->getLastLoginTime(), 'short', '', NULL, $language_interface->getId());
    $tests['[user:created]'] = $date_formatter->format($account->getCreatedTime(), 'medium', '', NULL, $language_interface->getId());
    $tests['[user:created:short]'] = $date_formatter->format($account->getCreatedTime(), 'short', '', NULL, $language_interface->getId());
    $tests['[current-user:name]'] = $global_account->getAccountName();
    $tests['[current-user:account-name]'] = $global_account->getAccountName();
    $tests['[current-user:display-name]'] = $global_account->getDisplayName();

    $base_bubbleable_metadata = BubbleableMetadata::createFromObject($account);
    $metadata_tests = [];
    $metadata_tests['[user:uid]'] = $base_bubbleable_metadata;
    $metadata_tests['[user:name]'] = $base_bubbleable_metadata;
    $metadata_tests['[user:account-name]'] = $base_bubbleable_metadata;
    $metadata_tests['[user:display-name]'] = $base_bubbleable_metadata;
    
$users_roles[] = $roles[$role];
      }
    }
    asort($users_roles);
    $row['roles']['data'] = [
      '#theme' => 'item_list',
      '#items' => $users_roles,
    ];
    $options = [
      'return_as_object' => TRUE,
    ];
    $row['member_for']['data'] = $this->dateFormatter->formatTimeDiffSince($entity->getCreatedTime()$options)->toRenderable();
    $last_access = $this->dateFormatter->formatTimeDiffSince($entity->getLastAccessedTime()$options);

    if ($entity->getLastAccessedTime()) {
      $row['access']['data']['#markup'] = $last_access->getString();
      CacheableMetadata::createFromObject($last_access)->applyTo($row['access']['data']);
    }
    else {
      $row['access']['data']['#markup'] = t('never');
    }
    return $row + parent::buildRow($entity);
  }

  
$url = $entity->toUrl('edit-form', $options);
      $this->drupalGet($url$options);
      $this->submitForm($edit$this->getFormSubmitAction($entity$langcode));
    }

    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    foreach ($this->langcodes as $langcode) {
      $translation = $entity->getTranslation($langcode);
      $metadata = $this->manager->getTranslationMetadata($translation);
      $this->assertEquals($values[$langcode]['uid']$metadata->getAuthor()->id(), 'Translation author correctly stored.');
      $this->assertEquals($values[$langcode]['created']$metadata->getCreatedTime(), 'Translation date correctly stored.');
      $this->assertEquals($values[$langcode]['sticky']$translation->isSticky(), 'Sticky of Translation correctly stored.');
      $this->assertEquals($values[$langcode]['promote']$translation->isPromoted(), 'Promoted of Translation correctly stored.');
    }
  }

  /** * Tests that translation page inherits admin status of edit page. */
  public function testTranslationLinkTheme() {
    $this->drupalLogin($this->administrator);
    $article = $this->drupalCreateNode(['type' => 'article', 'langcode' => $this->langcodes[0]]);

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