本文整理汇总了PHP中SS_Datetime::clear_mock_now方法的典型用法代码示例。如果您正苦于以下问题:PHP SS_Datetime::clear_mock_now方法的具体用法?PHP SS_Datetime::clear_mock_now怎么用?PHP SS_Datetime::clear_mock_now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SS_Datetime
的用法示例。
在下文中一共展示了SS_Datetime::clear_mock_now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
Injector::unnest();
SS_Datetime::clear_mock_now();
Config::unnest();
parent::tearDown();
}
示例2: tearDown
public function tearDown()
{
Injector::unnest();
SS_Datetime::clear_mock_now();
if ($this->envPath) {
Filesystem::removeFolder($this->envPath);
$this->envPath = null;
}
parent::tearDown();
}
示例3: testMemberProfileSuspensionNote
function testMemberProfileSuspensionNote()
{
SS_Datetime::set_mock_now('2011-10-10');
$normalMember = $this->objFromFixture('Member', 'test1');
$this->loginAs($normalMember);
$response = $this->get('ForumMemberProfile/edit/' . $normalMember->ID);
$this->assertNotContains(_t('ForumRole.SUSPENSIONNOTE'), $response->getBody(), 'Normal profiles don\'t show suspension note');
$suspendedMember = $this->objFromFixture('Member', 'suspended');
$this->loginAs($suspendedMember);
$response = $this->get('ForumMemberProfile/edit/' . $suspendedMember->ID);
$this->assertContains(_t('ForumRole.SUSPENSIONNOTE'), $response->getBody(), 'Suspended profiles show suspension note');
SS_Datetime::clear_mock_now();
}
示例4: testNowWithMockDate
public function testNowWithMockDate()
{
// Test setting
$mockDate = '2001-12-31 22:10:59';
SS_Datetime::set_mock_now($mockDate);
$systemDatetime = DBField::create_field('SS_Datetime', date('Y-m-d H:i:s'));
$nowDatetime = SS_Datetime::now();
$this->assertNotEquals($systemDatetime->Date(), $nowDatetime->Date());
$this->assertEquals($nowDatetime->getValue(), $mockDate);
// Test clearing
SS_Datetime::clear_mock_now();
$systemDatetime = DBField::create_field('SS_Datetime', date('Y-m-d H:i:s'));
$nowDatetime = SS_Datetime::now();
$this->assertEquals($systemDatetime->Date(), $nowDatetime->Date());
}
示例5: testRun
public function testRun()
{
SS_Datetime::set_mock_now('2014-01-31 13:00:00');
// less than two hours old
$orderRunningRecent = new Order(array('Status' => 'Cart'));
$orderRunningRecentID = $orderRunningRecent->write();
DB::query('UPDATE "Order" SET "LastEdited" = \'2014-01-31 12:30:00\' WHERE "ID" = ' . $orderRunningRecentID);
// three hours old
$orderRunningOld = new Order(array('Status' => 'Cart'));
$orderRunningOldID = $orderRunningOld->write();
DB::query('UPDATE "Order" SET "LastEdited" = \'2014-01-31 10:00:00\' WHERE "ID" = ' . $orderRunningOldID);
// three hours old
$orderPaidOld = new Order(array('Status' => 'Paid'));
$orderPaidOldID = $orderPaidOld->write();
DB::query('UPDATE "Order" SET "LastEdited" = \'2014-01-31 10:00:00\' WHERE "ID" = ' . $orderPaidOldID);
$task = new CartCleanupTaskTest_CartCleanupTaskFake();
$response = $task->run(new SS_HTTPRequest('GET', '/'));
$this->assertInstanceOf('Order', Order::get()->byID($orderRunningRecentID));
$this->assertNull(Order::get()->byID($orderRunningOldID));
$this->assertInstanceOf('Order', Order::get()->byID($orderPaidOldID));
$this->assertEquals('1 old carts removed.', $task->log[count($task->log) - 1]);
SS_Datetime::clear_mock_now();
}
示例6: testRecentlyPublishedPagesReport
function testRecentlyPublishedPagesReport()
{
$report = new RecentlyPublishedPagesReport();
$this->assertTrue(is_string($report->title()));
$this->assertTrue(is_array($report->columns()));
$this->assertTrue($report->canView());
$this->assertTrue($report->parameterFields() instanceof FieldSet);
$this->logInAs($this->objFromFixture('Member', 'admin'));
SS_Datetime::set_mock_now('2010-02-10 15:00:00');
$page1 = new Page();
$page1->Title = 'Page1';
$page1->write();
$wfr = $page1->openOrNewWorkflowRequest('WorkflowPublicationRequest');
$wfr->request('Request');
$wfr->approve('Approved');
SS_Datetime::set_mock_now('2010-02-15 15:00:00');
$page2 = new Page();
$page2->Title = 'Page2';
$page2->write();
$wfr = $page2->openOrNewWorkflowRequest('WorkflowPublicationRequest');
$wfr->request('Request');
$wfr->approve('Approved');
SS_Datetime::set_mock_now('2010-02-16 15:00:00');
$page3 = new Page();
$page3->Title = 'Page3';
$page3->write();
$wfr = $page3->openOrNewWorkflowRequest('WorkflowPublicationRequest');
$wfr->request('Request');
$wfr->approve('Approved');
SS_Datetime::set_mock_now('2010-02-14 00:00:00');
// Test with no dates set
$results = $report->sourceRecords(array(), '"Title" DESC', false);
//die();
$this->assertEquals($results->column('Title'), array('Page3', 'Page2'));
// Test with start date only
$results = $report->sourceRecords(array('StartDate' => array('date' => '14/02/2010', 'time' => '12:00 am')), '"Title" DESC', false);
$this->assertEquals($results->column('Title'), array('Page3', 'Page2'));
// Test with end date only
$results = $report->sourceRecords(array('EndDate' => array('date' => '14/02/2010', 'time' => '12:00 am')), '"Title" ASC', false);
$this->assertEquals($results->column('Title'), array('Page1'));
// Test with start and end dates
$results = $report->sourceRecords(array('StartDate' => array('date' => '04/02/2010', 'time' => '12:00 am'), 'EndDate' => array('date' => '12/02/2010', 'time' => '12:00 am')), '"Title" DESC', false);
$this->assertEquals($results->column('Title'), array('Page1'));
SS_Datetime::clear_mock_now();
}
示例7: tearDown
function tearDown()
{
// Preserve memory settings
ini_set('memory_limit', $this->originalMemoryLimit ? $this->originalMemoryLimit : -1);
// Restore email configuration
Email::set_mailer($this->originalMailer);
$this->originalMailer = null;
$this->mailer = null;
// Restore password validation
Member::set_password_validator($this->originalMemberPasswordValidator);
// Restore requirements
Requirements::set_backend($this->originalRequirements);
// Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls
self::$is_running_test = $this->originalIsRunningTest;
$this->originalIsRunningTest = null;
// Reset theme setting
SSViewer::set_theme($this->originalTheme);
// Reset mocked datetime
SS_Datetime::clear_mock_now();
// Restore nested_urls state
if ($this->originalNestedURLsState) {
SiteTree::enable_nested_urls();
} else {
SiteTree::disable_nested_urls();
}
// Stop the redirection that might have been requested in the test.
// Note: Ideally a clean Controller should be created for each test.
// Now all tests executed in a batch share the same controller.
$controller = Controller::has_curr() ? Controller::curr() : null;
if ($controller && $controller->response && $controller->response->getHeader('Location')) {
$controller->response->setStatusCode(200);
$controller->response->removeHeader('Location');
}
}
示例8: testAllVersions
public function testAllVersions()
{
// In 2005 this file was created
SS_Datetime::set_mock_now('2005-01-01 00:00:00');
$testPage = new VersionedTest_Subclass();
$testPage->Title = 'Archived page';
$testPage->Content = 'This is the content from 2005';
$testPage->ExtraField = '2005';
$testPage->write();
// In 2007 we updated it
SS_Datetime::set_mock_now('2007-01-01 00:00:00');
$testPage->Content = "It's 2007 already!";
$testPage->ExtraField = '2007';
$testPage->write();
// Check both versions are returned
$versions = Versioned::get_all_versions('VersionedTest_Subclass', $testPage->ID);
$content = array();
$extraFields = array();
foreach ($versions as $version) {
$content[] = $version->Content;
$extraFields[] = $version->ExtraField;
}
$this->assertEquals($versions->Count(), 2, 'All versions returned');
$this->assertEquals($content, array('This is the content from 2005', "It's 2007 already!"), 'Version fields returned');
$this->assertEquals($extraFields, array('2005', '2007'), 'Version fields returned');
// In 2009 we updated it again
SS_Datetime::set_mock_now('2009-01-01 00:00:00');
$testPage->Content = "I'm enjoying 2009";
$testPage->ExtraField = '2009';
$testPage->write();
// End mock, back to the present day:)
SS_Datetime::clear_mock_now();
$versions = Versioned::get_all_versions('VersionedTest_Subclass', $testPage->ID);
$content = array();
$extraFields = array();
foreach ($versions as $version) {
$content[] = $version->Content;
$extraFields[] = $version->ExtraField;
}
$this->assertEquals($versions->Count(), 3, 'Additional all versions returned');
$this->assertEquals($content, array('This is the content from 2005', "It's 2007 already!", "I'm enjoying 2009"), 'Additional version fields returned');
$this->assertEquals($extraFields, array('2005', '2007', '2009'), 'Additional version fields returned');
}
示例9: testExpiredRememberMeHashAutologin
public function testExpiredRememberMeHashAutologin()
{
$m1 = $this->objFromFixture('Member', 'noexpiry');
$m1->login(true);
$firstHash = RememberLoginHash::get()->filter('MemberID', $m1->ID)->First();
$this->assertNotNull($firstHash);
// re-generates the hash so we can get the token
$firstHash->Hash = $firstHash->getNewHash($m1);
$token = $firstHash->getToken();
$firstHash->ExpiryDate = '2000-01-01 00:00:00';
$firstHash->write();
SS_DateTime::set_mock_now('1999-12-31 23:59:59');
$response = $this->get('Security/login', $this->session(), null, array('alc_enc' => $m1->ID . ':' . $token, 'alc_device' => $firstHash->DeviceID));
$message = _t('Member.LOGGEDINAS', "You're logged in as {name}.", array('name' => $m1->FirstName));
$this->assertContains($message, $response->getBody());
$this->session()->inst_set('loggedInAs', null);
// re-generates the hash so we can get the token
$firstHash->Hash = $firstHash->getNewHash($m1);
$token = $firstHash->getToken();
$firstHash->ExpiryDate = '2000-01-01 00:00:00';
$firstHash->write();
SS_DateTime::set_mock_now('2000-01-01 00:00:01');
$response = $this->get('Security/login', $this->session(), null, array('alc_enc' => $m1->ID . ':' . $token, 'alc_device' => $firstHash->DeviceID));
$this->assertNotContains($message, $response->getBody());
$this->session()->inst_set('loggedInAs', null);
SS_Datetime::clear_mock_now();
}
示例10: tearDown
/**
* {@inheritdoc}
*/
public function tearDown()
{
SS_Datetime::clear_mock_now();
parent::tearDown();
}
示例11: testAgoInFuture
public function testAgoInFuture()
{
SS_Datetime::set_mock_now('2000-12-31 00:00:00');
$this->assertEquals('in 10 years', DBField::create_field('SS_Datetime', '2010-12-31 12:00:00')->Ago(), 'Exact past match on years');
$this->assertEquals('in 1 hour', DBField::create_field('SS_Datetime', '2000-12-31 1:01:05')->Ago(true, 1), 'Approximate past match on minutes, significance=1');
$this->assertEquals('in 61 mins', DBField::create_field('SS_Datetime', '2000-12-31 1:01:05')->Ago(), 'Approximate past match on minutes');
SS_Datetime::clear_mock_now();
}
示例12: testEmbargoUntilDate
function testEmbargoUntilDate()
{
$doc = new DMSDocument();
$doc->Filename = "DMS-test-lorum-file.pdf";
$doc->Folder = "tests";
$doc->write();
$doc->embargoUntilDate(strtotime('+1 minute'));
$this->assertTrue($doc->isHidden(), "Document is hidden");
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
$this->assertFalse($doc->isExpired(), "Document is not expired");
$doc->embargoUntilDate(strtotime('-1 second'));
$this->assertFalse($doc->isHidden(), "Document is not hidden");
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
$this->assertFalse($doc->isExpired(), "Document is not expired");
$embargoTime = "2019-04-05 11:43:13";
$doc->embargoUntilDate($embargoTime);
$this->assertTrue($doc->isHidden(), "Document is hidden");
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
$this->assertFalse($doc->isExpired(), "Document is not expired");
SS_Datetime::set_mock_now($embargoTime);
$this->assertFalse($doc->isHidden(), "Document is not hidden");
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
$this->assertFalse($doc->isExpired(), "Document is not expired");
SS_Datetime::clear_mock_now();
$doc->clearEmbargo();
$this->assertFalse($doc->isHidden(), "Document is not hidden");
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
$this->assertFalse($doc->isExpired(), "Document is not expired");
}
示例13: tearDown
public function tearDown()
{
// Preserve memory settings
ini_set('memory_limit', $this->originalMemoryLimit ? $this->originalMemoryLimit : -1);
// Restore email configuration
$this->originalMailer = null;
$this->mailer = null;
// Restore password validation
if ($this->originalMemberPasswordValidator) {
Member::set_password_validator($this->originalMemberPasswordValidator);
}
// Restore requirements
if ($this->originalRequirements) {
Requirements::set_backend($this->originalRequirements);
}
// Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls
self::$is_running_test = $this->originalIsRunningTest;
$this->originalIsRunningTest = null;
// Reset mocked datetime
SS_Datetime::clear_mock_now();
// Stop the redirection that might have been requested in the test.
// Note: Ideally a clean Controller should be created for each test.
// Now all tests executed in a batch share the same controller.
$controller = Controller::has_curr() ? Controller::curr() : null;
if ($controller && $controller->response && $controller->response->getHeader('Location')) {
$controller->response->setStatusCode(200);
$controller->response->removeHeader('Location');
}
//unnest injector / config now that tests are over
Injector::unnest();
Config::unnest();
}
示例14: testEmbargoExpiry
function testEmbargoExpiry()
{
// Get fixtures
$page = $this->objFromFixture('SiteTree', 'embargoexpirypage');
$custompublisher = $this->objFromFixture('Member', 'custompublisher');
$customauthor = $this->objFromFixture('Member', 'customauthor');
$this->session()->inst_set('loggedInAs', $customauthor->ID);
$request = $page->openWorkflowRequest('WorkflowPublicationRequest');
$this->assertNotNull($request);
$this->assertEquals($request->AuthorID, $customauthor->ID, "Logged-in member is set as the author of the request");
// Ensure we can actually get the fields
$this->assertNotNull($request->EmbargoField());
$this->assertNotNull($request->ExpiryField());
SS_Datetime::set_mock_now('2009-05-25 15:00:00');
// Set embargo date to 01/06/2009 3:00pm, expriry to 7 days later
$this->assertTrue($page->setEmbargo('01/06/2009', '3:00pm'), 'Setting embargo date');
$this->assertTrue($page->setExpiry('07/06/2009', '3:00pm'), 'Settin expiry date');
$request = $page->openWorkflowRequest('WorkflowPublicationRequest');
// Login as publisher and approve page
$custompublisher->logIn();
$this->session()->inst_set('loggedInAs', $custompublisher->ID);
$this->assertEquals(true, $request->approve('Looks good. Will go out a bit later'), 'Publisher (' . Member::currentUser()->Email . ') can approve page');
$request = $page->openWorkflowRequest('WorkflowPublicationRequest');
$this->assertEquals($request->Status, 'Scheduled', "Request is set to Scheduled after approving a request with embargo and/or expriy dates set");
$sp = new ScheduledPublishing();
$sp->suppressOutput();
$sp->run(new SS_HTTPRequest('GET', '/'));
$this->assertEquals($request->Status, 'Scheduled', "Request is still set to Scheduled after approving a request with embargo and/or expriy dates set, and running the publisher cron");
SS_Datetime::set_mock_now('2009-06-03 15:00:00');
$sp->run(new SS_HTTPRequest('GET', '/'));
$request = DataObject::get_by_id('WorkflowPublicationRequest', $request->ID);
$this->assertEquals($request->Status, 'Completed', "Request is Completed after embargo date set");
SS_Datetime::set_mock_now('2009-06-15 15:00:00');
$sp->run(new SS_HTTPRequest('GET', '/'));
$onLive = Versioned::get_by_stage('Page', 'Live', "\"SiteTree_Live\".\"ID\" = " . $page->ID);
$this->assertNull($onLive, 'Page has expired from live');
SS_Datetime::clear_mock_now();
}
示例15: testBatchSetResetExpiry
function testBatchSetResetExpiry()
{
$oldRequest = $_REQUEST;
$action = new BatchSetExpiry();
$this->assertTrue(is_string($action->getActionTitle()));
$this->assertTrue(is_string($action->getDoingText()));
$this->assertTrue($action->getParameterFields() instanceof FieldSet);
$this->logInAs($this->objFromFixture('Member', 'admin'));
$page1 = new Page();
$page1->write();
$page1->openOrNewWorkflowRequest('WorkflowPublicationRequest');
$page1ID = $page1->ID;
$page2 = new Page();
$page2->Content = '<a href="' . $page1->AbsoluteLink() . '">link here</a>';
$page2->write();
$page2ID = $page2->ID;
$pages = new DataObjectSet();
$pages->push($page1);
$pages->push($page2);
$this->assertEquals(array($page1->ID), $action->applicablePages($pages->column('ID')), 'applicableIds only returns pages with open requests');
SS_Datetime::set_mock_now('2009-06-15 15:00:00');
$_REQUEST['ExpiryDate_Batch'] = array('date' => '31/01/2010', 'time' => '3:00 pm');
$_REQUEST['ajax'] = 1;
// Test confirmation dialog
$page1->BacklinkTracking()->add($page2);
$confirmation = $action->confirmationDialog($pages->column('ID'));
$this->assertTrue($confirmation['alert']);
$action->run($pages);
$page1 = DataObject::get_by_id('Page', $page1ID);
$page2 = DataObject::get_by_id('Page', $page2ID);
$this->assertEquals($page1->ExpiryDate, '2010-01-31 15:00:00');
$this->assertNull($page2->openWorkflowRequest());
$this->assertNull($page2->ExpiryDate);
// Now test resetting
$action = new BatchResetExpiry();
$this->assertTrue(is_string($action->getActionTitle()));
$this->assertTrue(is_string($action->getDoingText()));
$pages = new DataObjectSet();
$pages->push($page1);
$pages->push($page2);
$this->assertEquals(array($page1->ID), $action->applicablePages(array($page1->ID, $page2->ID)), 'applicableIds only returns pages with open requests');
$action->run($pages);
$page1 = DataObject::get_by_id('Page', $page1ID);
$page2 = DataObject::get_by_id('Page', $page2ID);
$this->assertNull($page1->openWorkflowRequest()->ExpiryDate);
$this->assertNull($page2->openWorkflowRequest());
$_REQUEST = $oldRequest;
SS_Datetime::clear_mock_now();
}