Skip to content

Commit

Permalink
Use drupal time
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Oct 25, 2023
1 parent ec09b48 commit c96e538
Show file tree
Hide file tree
Showing 40 changed files with 208 additions and 200 deletions.
6 changes: 3 additions & 3 deletions config/sync/smart_date.smart_date_format.day.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ date_format: j
time_format: ''
time_hour_format: ''
allday_label: ''
separator: ' - '
join: ', '
separator: ''
join: ''
ampm_reduce: '1'
date_first: '1'
site_time_toggle: '1'
site_time_toggle: '0'
2 changes: 1 addition & 1 deletion config/sync/smart_date.smart_date_format.short_month.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ separator: ' - '
join: ', '
ampm_reduce: '1'
date_first: '1'
site_time_toggle: '1'
site_time_toggle: '0'
18 changes: 9 additions & 9 deletions tests/codeception/acceptance/AuthenticatedPermissionsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function _after(AcceptanceTester $I) {
/**
* Make sure authenticated users can't access things they should not.
*/
protected function footestAuthenticatedUserRestrictions(AcceptanceTester $I) {
public function testAuthenticatedUserRestrictions(AcceptanceTester $I) {
$I->logInWithRole('authenticated');
$I->amOnPage('/');
$I->canSeeResponseCodeIs(200);
Expand All @@ -76,7 +76,7 @@ protected function footestAuthenticatedUserRestrictions(AcceptanceTester $I) {
/**
* Make sure authenticated users can access things they should.
*/
protected function footestAuthenticatedUserPermissions(AcceptanceTester $I) {
public function testAuthenticatedUserPermissions(AcceptanceTester $I) {
$I->logInWithRole('authenticated');
$I->amOnPage('/patterns');
$I->canSeeResponseCodeIs(200);
Expand All @@ -85,7 +85,7 @@ protected function footestAuthenticatedUserPermissions(AcceptanceTester $I) {
/**
* Site Manager cannot escalate their own role above Site Manager.
*/
protected function footestSiteManagerEscalationSelf(AcceptanceTester $I) {
public function testSiteManagerEscalationSelf(AcceptanceTester $I) {
$site_manager = $I->logInWithRole('site_manager');
$site_manager_id = $site_manager->id();
$I->amOnPage('/admin/users');
Expand All @@ -101,7 +101,7 @@ protected function footestSiteManagerEscalationSelf(AcceptanceTester $I) {
/**
* Site Manager cannot escalate others' role above Site Manager.
*/
protected function footestSiteManagerEscalationOthers(AcceptanceTester $I) {
public function testSiteManagerEscalationOthers(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->amOnPage('/admin/users');
$I->canSee('Morgan');
Expand All @@ -115,7 +115,7 @@ protected function footestSiteManagerEscalationOthers(AcceptanceTester $I) {
/**
* PHP code is not allowed in redirects.
*/
protected function footestPhpInRedirect(AcceptanceTester $I) {
public function testPhpInRedirect(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->amOnPage('/admin/config/search/redirect/add');
$I->fillField('#edit-redirect-source-0-path', 'home');
Expand All @@ -128,7 +128,7 @@ protected function footestPhpInRedirect(AcceptanceTester $I) {
/**
* PHP code is escaped and not run when added to content.
*/
protected function footestPhpInContent(AcceptanceTester $I) {
public function testPhpInContent(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->amOnPage('/node/add/stanford_page');
$I->fillField('#edit-title-0-value', '<?php echo("injection test"); die(); ?>');
Expand All @@ -140,7 +140,7 @@ protected function footestPhpInContent(AcceptanceTester $I) {
/**
* PHP files are not allowed as uploads for favicons.
*/
protected function footestPhpUploadInFavicon(AcceptanceTester $I) {
public function testPhpUploadInFavicon(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$I->amOnPage('/admin/appearance/settings');
$I->seeCheckboxIsChecked('#edit-default-favicon');
Expand All @@ -156,7 +156,7 @@ protected function footestPhpUploadInFavicon(AcceptanceTester $I) {
/**
* PHP files are not allowed as uploads for the logo.
*/
protected function footestPhpUploadInLogo(AcceptanceTester $I) {
public function testPhpUploadInLogo(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$I->amOnPage('/admin/appearance/settings');
$I->seeCheckboxIsChecked('#edit-default-logo');
Expand All @@ -173,7 +173,7 @@ protected function footestPhpUploadInLogo(AcceptanceTester $I) {
/**
* Vocabs aren't seen if there are no permissions for them.
*/
protected function footestTaxonomyOverviewPage(AcceptanceTester $I) {
public function testTaxonomyOverviewPage(AcceptanceTester $I) {
$name = $this->faker->firstName;
$vocab = $I->createEntity([
'vid' => strtolower($name),
Expand Down
24 changes: 12 additions & 12 deletions tests/codeception/acceptance/Content/BasicPageCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct() {
* @group pathauto
* @group menu_link_weight
*/
protected function footestCreatingPage(AcceptanceTester $I) {
public function testCreatingPage(AcceptanceTester $I) {
$node_title = $this->faker->text(20);
$node = $I->createEntity([
'type' => 'stanford_page',
Expand Down Expand Up @@ -72,7 +72,7 @@ protected function footestCreatingPage(AcceptanceTester $I) {
/**
* Test deleting menu items clears them from the main menu.
*/
protected function footestDeletedMenuItems(AcceptanceTester $I) {
public function testDeletedMenuItems(AcceptanceTester $I) {
$node_title = $this->faker->text(20);
$node = $I->createEntity([
'type' => 'stanford_page',
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function footestDeletedMenuItems(AcceptanceTester $I) {
/**
* Number of h1 tags should always be 1.
*/
protected function footestH1Tags(AcceptanceTester $I) {
public function testH1Tags(AcceptanceTester $I) {
$I->amOnPage('/' . $this->faker->text);
$I->canSeeResponseCodeIs(404);
$I->canSeeNumberOfElements('h1', 1);
Expand All @@ -116,7 +116,7 @@ protected function footestH1Tags(AcceptanceTester $I) {
*
* Regression test for D8CORE-1547.
*/
protected function footestRevisionPage(AcceptanceTester $I) {
public function testRevisionPage(AcceptanceTester $I) {
$title = $this->faker->words(3, TRUE);
$I->logInWithRole('site_manager');
$node = $I->createEntity(['title' => $title, 'type' => 'stanford_page']);
Expand All @@ -128,7 +128,7 @@ protected function footestRevisionPage(AcceptanceTester $I) {
/**
* There should be Page Metadata fields
*/
protected function footestPageDescription(AcceptanceTester $I) {
public function testPageDescription(AcceptanceTester $I) {
$title = $this->faker->words(3, TRUE);
$description = $this->faker->words(10, TRUE);
$type_term = $I->createEntity([
Expand All @@ -150,7 +150,7 @@ protected function footestPageDescription(AcceptanceTester $I) {
/**
* Test that the vocabulary and default terms exist.
*/
protected function footestBasicPageVocabularyTermsExists(AcceptanceTester $I) {
public function testBasicPageVocabularyTermsExists(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->amOnPage("/admin/structure/taxonomy/manage/basic_page_types/overview");
$I->canSeeResponseCodeIs(200);
Expand All @@ -167,7 +167,7 @@ protected function footestBasicPageVocabularyTermsExists(AcceptanceTester $I) {
*
* @group menu_link_weight
*/
protected function footestUnpublishedMenuItems(AcceptanceTester $I) {
public function testUnpublishedMenuItems(AcceptanceTester $I) {
$unpublished_title = $this->faker->words(5, TRUE);
$unpublished_node = $I->createEntity([
'type' => 'stanford_page',
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function footestUnpublishedMenuItems(AcceptanceTester $I) {
/**
* Clone a basic page.
*/
protected function footestClone(AcceptanceTester $I) {
public function testClone(AcceptanceTester $I) {
$title = $this->faker->words(3, TRUE);

$I->logInWithRole('contributor');
Expand All @@ -228,7 +228,7 @@ protected function footestClone(AcceptanceTester $I) {
*
* @group scheduler
*/
protected function footestScheduler(AcceptanceTester $I) {
public function testScheduler(AcceptanceTester $I) {
$time = \Drupal::time();

/** @var \Drupal\system\TimeZoneResolver $timezone_resolver */
Expand Down Expand Up @@ -257,7 +257,7 @@ protected function footestScheduler(AcceptanceTester $I) {
/**
* Validate the Spacer Paragraph type exists
*/
protected function footestSpacerParagraph(AcceptanceTester $I) {
public function testSpacerParagraph(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$I->amOnPage('/admin/structure/paragraphs_type');
$I->canSee('Spacer');
Expand All @@ -269,7 +269,7 @@ protected function footestSpacerParagraph(AcceptanceTester $I) {
*
* @group metadata
*/
protected function footestMetaData(AcceptanceTester $I) {
public function testMetaData(AcceptanceTester $I) {
$values = [
'banner_image_alt' => $this->faker->words(3, TRUE),
'meta_image_alt' => $this->faker->words(3, TRUE),
Expand Down Expand Up @@ -364,7 +364,7 @@ protected function footestMetaData(AcceptanceTester $I) {
/**
* @group search-results
*/
protected function footestSearchResult(AcceptanceTester $I) {
public function testSearchResult(AcceptanceTester $I) {
$text = $this->faker->paragraphs(2, TRUE);
$wysiwyg = $I->createEntity([
'type' => 'stanford_wysiwyg',
Expand Down
4 changes: 2 additions & 2 deletions tests/codeception/acceptance/Content/CoursesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct() {
/**
* Test for view pages and taxonomy functionality
*/
protected function footestViewPagesExist(AcceptanceTester $I) {
public function testViewPagesExist(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$quarters_term = $this->createCourseQuartersTerm($I);
$subject_term = $this->createCourseSubjectsTerm($I);
Expand Down Expand Up @@ -63,7 +63,7 @@ protected function footestViewPagesExist(AcceptanceTester $I) {
/**
* Test rabbit hole settings and field locking
*/
protected function footestRabbitHoleRedirects(AcceptanceTester $I) {
public function testRabbitHoleRedirects(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$quarters_term = $this->createCourseQuartersTerm($I);
$subject_term = $this->createCourseSubjectsTerm($I);
Expand Down
2 changes: 1 addition & 1 deletion tests/codeception/acceptance/Content/CustomBlockCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct() {
/**
* Site managers should be able to edit custom blocks.
*/
protected function footestCustomBlockAccess(AcceptanceTester $I) {
public function testCustomBlockAccess(AcceptanceTester $I) {
$block = $I->createEntity([
'type' => 'stanford_component_block',
'info' => $this->faker->word(3, TRUE),
Expand Down
10 changes: 5 additions & 5 deletions tests/codeception/acceptance/Content/DefaultContentCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DefaultContentCest {
/**
* Test default images.
*/
protected function footestDefaultImages(AcceptanceTester $I) {
public function testDefaultImages(AcceptanceTester $I) {
$files = \Drupal::entityTypeManager()->getStorage('file')->loadMultiple();

/** @var \Drupal\file\FileInterface $file */
Expand All @@ -30,7 +30,7 @@ protected function footestDefaultImages(AcceptanceTester $I) {
/**
* Default content pages and meta data exist.
*/
protected function footestExistingContent(AcceptanceTester $I) {
public function testExistingContent(AcceptanceTester $I) {
$pages = [
'/',
'/resources',
Expand All @@ -49,7 +49,7 @@ protected function footestExistingContent(AcceptanceTester $I) {
/**
* There should be at least 15 media items.
*/
protected function footestMedia(AcceptanceTester $I) {
public function testMedia(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$I->amOnPage('/admin/content/media');
$I->canSeeNumberOfElements('table img, form img', [15, 999]);
Expand All @@ -58,7 +58,7 @@ protected function footestMedia(AcceptanceTester $I) {
/**
* XML Sitemap should exist after cron.
*/
protected function footestXmlSitemap(AcceptanceTester $I) {
public function testXmlSitemap(AcceptanceTester $I) {
$I->runDrush('cron');
$I->amOnPage('/sitemap.xml');
$I->canSeeResponseCodeIs(200);
Expand All @@ -69,7 +69,7 @@ protected function footestXmlSitemap(AcceptanceTester $I) {
*
* @group menu_link_weight
*/
protected function footestMenuItems(AcceptanceTester $I) {
public function testMenuItems(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->amOnPage('/admin/structure/menu/manage/main');

Expand Down
35 changes: 21 additions & 14 deletions tests/codeception/acceptance/Content/EventsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function _after(AcceptanceTester $I) {
*
* @group D8CORE-4858
*/
protected function footestListIntro(AcceptanceTester $I) {
public function testListIntro(AcceptanceTester $I) {
// Start with no events.
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
Expand Down Expand Up @@ -97,7 +97,7 @@ protected function footestListIntro(AcceptanceTester $I) {
/**
* Ensure events are in the sitemap.
*/
protected function footestXMLSiteMap(AcceptanceTester $I) {
public function testXMLSiteMap(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$I->amOnPage('/admin/config/search/xmlsitemap/settings/node/stanford_event');
$I->seeOptionIsSelected('#edit-xmlsitemap-status', 'Included');
Expand All @@ -107,7 +107,7 @@ protected function footestXMLSiteMap(AcceptanceTester $I) {
/**
* Test Page Title Conditions.
*/
protected function footestPageTitleIgnoreCondition(AcceptanceTester $I) {
public function testPageTitleIgnoreCondition(AcceptanceTester $I) {
$I->logInWithRole('administrator');
// Todo: make theme name dynamic.
$I->amOnPage('/admin/structure/block/manage/stanford_basic_pagetitle');
Expand All @@ -121,7 +121,7 @@ protected function footestPageTitleIgnoreCondition(AcceptanceTester $I) {
/**
* Test the event content type exists and has at least a couple of fields.
*/
protected function footestContentTypeExists(AcceptanceTester $I) {
public function testContentTypeExists(AcceptanceTester $I) {
$I->logInWithRole('administrator');
$I->amOnPage('/admin/structure/types/manage/stanford_event/fields');
$I->canSee('body');
Expand All @@ -148,7 +148,7 @@ protected function footestContentTypeExists(AcceptanceTester $I) {
/**
* Test Access to stuff for contrib role.
*/
protected function footestContributorPerms(AcceptanceTester $I) {
public function testContributorPerms(AcceptanceTester $I) {
$I->logInWithRole('contributor');

// Can create a node.
Expand Down Expand Up @@ -188,7 +188,7 @@ protected function footestContributorPerms(AcceptanceTester $I) {
/**
* Test thing.
*/
protected function footestEditorPerms(AcceptanceTester $I) {
public function testEditorPerms(AcceptanceTester $I) {
$I->logInWithRole('site_editor');

// Can create a node.
Expand Down Expand Up @@ -233,7 +233,7 @@ protected function footestEditorPerms(AcceptanceTester $I) {
/**
* Test thing.
*/
protected function footestSiteManagerPerms(AcceptanceTester $I) {
public function testSiteManagerPerms(AcceptanceTester $I) {
$I->logInWithRole('site_manager');

// Can create a node.
Expand Down Expand Up @@ -277,7 +277,7 @@ protected function footestSiteManagerPerms(AcceptanceTester $I) {
/**
* Test to make sure the main menu link is there.
*/
protected function footestDefaultContentExists(AcceptanceTester $I) {
public function testDefaultContentExists(AcceptanceTester $I) {
$I->logInWithRole('administrator');
// Events Main Menu Link.
$I->amOnPage('/admin/structure/menu/manage/main');
Expand All @@ -287,7 +287,7 @@ protected function footestDefaultContentExists(AcceptanceTester $I) {
/**
* Published checkbox should be hidden on term edit pages.
*/
protected function footestTermPublishing(AcceptanceTester $I) {
public function testTermPublishing(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$term = $I->createEntity([
'vid' => 'event_audience',
Expand All @@ -307,7 +307,7 @@ protected function footestTermPublishing(AcceptanceTester $I) {
/**
* Clone events get incremented date.
*/
protected function footestClone(AcceptanceTester $I) {
public function testClone(AcceptanceTester $I) {
$user = $I->createUserWithRoles(['contributor']);
/** @var \Drupal\node\NodeInterface $node */
$node = $this->createEventNode($I);
Expand Down Expand Up @@ -359,19 +359,26 @@ public function testEventCard(AcceptanceTester $I) {

$month = $xpath->query('//span[@class="su-event-start-month"]');
$I->assertNotEmpty($month);
$I->assertEquals(date('M', time()), $month->item(0)->nodeValue, 'Start Month does not match');
$I->assertEquals(self::getDateTimeString('M', time()), preg_replace('/(\r\n|\n|\r)/', '', $month->item(0)->nodeValue), 'Start Month does not match');

$day = $xpath->query('//span[@class="su-event-start-date"]');
$I->assertNotEmpty($day);
$I->assertEquals(date('j', time()), $day->item(0)->nodeValue, 'Start Date does not match');
$I->assertEquals(self::getDateTimeString('j', time()), preg_replace('/(\r\n|\n|\r)/', '', $day->item(0)->nodeValue), 'Start Date does not match');

$month = $xpath->query('//span[@class="su-event-end-month"]');
$I->assertNotEmpty($month);
$I->assertEquals(date('M', time() + (60 * 60 * 24)), $month->item(0)->nodeValue, 'End Month does not match');
$I->assertEquals(self::getDateTimeString('M', time() + (60 * 60 * 24)), preg_replace('/(\r\n|\n|\r)/', '', $month->item(0)->nodeValue), 'End Month does not match');

$day = $xpath->query('//span[@class="su-event-end-date"]');
$I->assertNotEmpty($day);
$I->assertEquals(date('j', time() + (60 * 60 * 24)), $day->item(0)->nodeValue, 'End Date does not match');
$I->assertEquals(self::getDateTimeString('j', time() + (60 * 60 * 24)), preg_replace('/(\r\n|\n|\r)/', '', $day->item(0)->nodeValue), 'End Date does not match');
}

protected static function getDateTimeString($format, $time) {
$timezone = \Drupal::config('system.date')
->get('timezone.default') ?: @date_default_timezone_get();
return \Drupal::service('date.formatter')
->format($time, 'custom', $format, $timezone);
}

/**
Expand Down
Loading

0 comments on commit c96e538

Please sign in to comment.