Skip to content

Commit

Permalink
Fix News metadata test (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish authored Mar 11, 2024
1 parent 3b795e1 commit c6c4788
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/codeception/acceptance/Content/NewsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ public function testTermPublishing(AcceptanceTester $I) {
* @group metadata
*/
public function testMetaData(AcceptanceTester $I) {
$time = \Drupal::time()->getCurrentTime();
$now = DateTime::createFromFormat('U', $time);
$now->setTime(12, 0, 0);
$now = $now->getTimestamp();

/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_time_formatter */
$date_time_formatter = \Drupal::service('date.formatter');

$date_string = $date_time_formatter->format($now, 'custom', 'Y-m-d');
$metadata_date = $date_time_formatter->format($now, 'custom', 'c', 'America/Los_Angeles');

$values = [
'featured_image_alt' => $this->faker->words(3, TRUE),
'banner_image_alt' => $this->faker->words(3, TRUE),
Expand Down Expand Up @@ -188,12 +199,6 @@ public function testMetaData(AcceptanceTester $I) {
],
], 'media');

$time = \Drupal::time()->getCurrentTime();
$date_string = \Drupal::service('date.formatter')
->format($time, 'custom', 'Y-m-d');
$metadata_date = \Drupal::service('date.formatter')
->format($time, 'custom', 'Y-m-d');

/** @var \Drupal\node\NodeInterface $node */
$node = $I->createEntity([
'title' => $this->faker->words(3, TRUE),
Expand All @@ -207,7 +212,8 @@ public function testMetaData(AcceptanceTester $I) {
$I->assertEquals($node->label(), $I->grabAttributeFrom('meta[property="og:title"]', 'content'), 'Metadata "og:title" should match.');
$I->assertEquals($node->label(), $I->grabAttributeFrom('meta[name="twitter:title"]', 'content'), 'Metadata "twitter:title" should match.');
$I->assertEquals('article', $I->grabAttributeFrom('meta[property="og:type"]', 'content'), 'Metadata "og:type" should match.');
$I->assertEquals("{$metadata_date}T04:00:00-08:00", $I->grabAttributeFrom('meta[property="article:published_time"]', 'content'), 'Metadata "article:published_time" should match.');

$I->assertEquals($metadata_date, $I->grabAttributeFrom('meta[property="article:published_time"]', 'content'), 'Metadata "article:published_time" should match.');

$I->cantSeeElement('meta', ['name' => 'description']);
$I->cantSeeElement('meta', ['property' => 'og:image']);
Expand Down

0 comments on commit c6c4788

Please sign in to comment.