当前位置: 首页>>代码示例>>PHP>>正文


PHP SS_Datetime::set_mock_now方法代码示例

本文整理汇总了PHP中SS_Datetime::set_mock_now方法的典型用法代码示例。如果您正苦于以下问题:PHP SS_Datetime::set_mock_now方法的具体用法?PHP SS_Datetime::set_mock_now怎么用?PHP SS_Datetime::set_mock_now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SS_Datetime的用法示例。


在下文中一共展示了SS_Datetime::set_mock_now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testRunTask

 /**
  * Test CronTaskController::runTask
  */
 public function testRunTask()
 {
     $runner = CronTaskController::create();
     $runner->setQuiet(true);
     $task = new CronTaskTest_TestCron();
     // Assuming first run, match the exact time (seconds are ignored)
     $this->assertEquals(0, CronTaskTest_TestCron::$times_run);
     SS_Datetime::set_mock_now('2010-06-20 13:00:10');
     $runner->runTask($task);
     $this->assertEquals(1, CronTaskTest_TestCron::$times_run);
     // Test that re-requsting the task in the same minute do not retrigger another run
     SS_Datetime::set_mock_now('2010-06-20 13:00:40');
     $runner->runTask($task);
     $this->assertEquals(1, CronTaskTest_TestCron::$times_run);
     // Job prior to next hour mark should not run
     SS_Datetime::set_mock_now('2010-06-20 13:40:00');
     $runner->runTask($task);
     $this->assertEquals(1, CronTaskTest_TestCron::$times_run);
     // Jobs just after the next hour mark should run
     SS_Datetime::set_mock_now('2010-06-20 14:10:00');
     $runner->runTask($task);
     $this->assertEquals(2, CronTaskTest_TestCron::$times_run);
     // Jobs run on the exact next expected date should run
     SS_Datetime::set_mock_now('2010-06-20 15:00:00');
     $runner->runTask($task);
     $this->assertEquals(3, CronTaskTest_TestCron::$times_run);
     // Jobs somehow delayed a whole day should be run
     SS_Datetime::set_mock_now('2010-06-21 13:40:00');
     $runner->runTask($task);
     $this->assertEquals(4, CronTaskTest_TestCron::$times_run);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-crontask,代码行数:34,代码来源:CronTaskControllerTest.php

示例2: preRequest

 public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     if (!$this->testSessionEnvironment->isRunningTests()) {
         return;
     }
     $testState = $this->testSessionEnvironment->getState();
     // Date and time
     if (isset($testState->datetime)) {
         SS_Datetime::set_mock_now($testState->datetime);
     }
     // Register mailer
     if (isset($testState->mailer)) {
         $mailer = $testState->mailer;
         Email::set_mailer(new $mailer());
         Config::inst()->update("Email", "send_all_emails_to", null);
     }
     // Allows inclusion of a PHP file, usually with procedural commands
     // to set up required test state. The file can be generated
     // through {@link TestSessionStubCodeWriter}, and the session state
     // set through {@link TestSessionController->set()} and the
     // 'testsession.stubfile' state parameter.
     if (isset($testState->stubfile)) {
         $file = $testState->stubfile;
         if (!Director::isLive() && $file && file_exists($file)) {
             // Connect to the database so the included code can interact with it
             global $databaseConfig;
             if ($databaseConfig) {
                 DB::connect($databaseConfig);
             }
             include_once $file;
         }
     }
 }
开发者ID:jeffreyguo,项目名称:silverstripe-testsession,代码行数:33,代码来源:TestSessionRequestFilter.php

示例3: testGetNextDateTimeDuring

 public function testGetNextDateTimeDuring()
 {
     $sched = $this->objFromFixture('ScheduleRangeDay', 'schedDay1');
     //During
     SS_Datetime::set_mock_now('2015-10-03 12:30:00');
     $this->assertEquals('2015-10-03 13:00:00', $sched->getNextDateTime()->Format('Y-m-d H:i:s'));
 }
开发者ID:silverstripe-australia,项目名称:silverstripe-schedulizer,代码行数:7,代码来源:ScheduleRangeDayTest.php

示例4: testCanView

 /**
  * @dataProvider canViewProvider
  */
 public function testCanView($date, $user, $page, $canView)
 {
     $userRecord = $this->objFromFixture('Member', $user);
     $pageRecord = $this->objFromFixture('BlogPost', $page);
     SS_Datetime::set_mock_now($date);
     $this->assertEquals($canView, $pageRecord->canView($userRecord));
 }
开发者ID:helpfulrobot,项目名称:silverstripe-blog,代码行数:10,代码来源:BlogPostTest.php

示例5: testDismiss

 public function testDismiss()
 {
     SS_Datetime::set_mock_now(date('Y-m-d H:i:s'));
     $step = $this->getDummyConfirmationStep();
     $step->start();
     $step->dismiss();
     // Assert not error at startup
     $this->assertEquals('Finished', $step->Status);
     $this->assertHasLog('Dismissing rollback window.');
 }
开发者ID:ss23,项目名称:deploynaut,代码行数:10,代码来源:EmergencyRollbackStepTest.php

示例6: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     Config::nest();
     SS_Datetime::set_mock_now('2013-10-10 20:00:00');
     /**
      * @var Blog $blog
      */
     $blog = $this->objFromFixture('Blog', 'FirstBlog');
     $blog->publish('Stage', 'Live');
 }
开发者ID:helpfulrobot,项目名称:silverstripe-blog,代码行数:14,代码来源:BlogTest.php

示例7: testFilter

 public function testFilter()
 {
     $member = Member::currentUser();
     if ($member) {
         $member->logout();
     }
     $count = BlogPost::get()->count();
     $this->assertEquals(3, $count, "Filtered blog posts");
     SS_Datetime::set_mock_now("2020-01-01 00:00:00");
     $count = BlogPost::get()->count();
     $this->assertEquals(5, $count, "Unfiltered blog posts");
 }
开发者ID:helpfulrobot,项目名称:micmania1-silverstripe-blog,代码行数:12,代码来源:BlogPostFilterTest.php

示例8: testRecentlyEdited

 function testRecentlyEdited()
 {
     SS_Datetime::set_mock_now('31-06-2009 00:00:00');
     $after = $this->objFromFixture('SiteTree', 'after');
     $before = $this->objFromFixture('SiteTree', 'before');
     $r = new SideReport_RecentlyEdited();
     // check if contains only elements not older than $daysAgo days
     $this->assertNotNull($r->records(array()));
     $this->assertContains($after->ID, $r->records(array())->column('ID'));
     $this->assertNotContains($before->ID, $r->records(array())->column('ID'));
     SS_DateTime::clear_mock_now();
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:12,代码来源:SideReportTest.php

示例9: testDeploy

 public function testDeploy()
 {
     SS_Datetime::set_mock_now(date('Y-m-d H:i:s'));
     $step = $this->getDummyConfirmationStep();
     $step->start();
     $step->deploy();
     // Assert not error at startup
     $this->assertEquals('Finished', $step->Status);
     // Assert that 'now' is used for the deployment date
     $this->assertEquals(SS_Datetime::now()->Format('Y-m-d H:i:s'), $step->Deployed);
     $this->assertHasLog('RequestDeploymentStep is being deployed');
 }
开发者ID:helpfulrobot,项目名称:silverstripe-deploynaut,代码行数:12,代码来源:TriggerDeployStepTest.php

示例10: 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();
 }
开发者ID:helpfulrobot,项目名称:silverstripe-forum,代码行数:13,代码来源:ForumMemberProfileTest.php

示例11: testExpiry

 /**
  * Test expiry of data
  */
 public function testExpiry()
 {
     $session1 = uniqid();
     $store = $this->getStore();
     // Store data now
     $data1 = array('Food' => 'Pizza');
     $store->write($session1, serialize($data1));
     $result1 = $store->read($session1);
     $this->assertEquals($data1, unserialize($result1));
     // Go to the future and test that the expiry is accurate
     SS_Datetime::set_mock_now('2040-03-16 12:00:00');
     $result2 = $store->read($session1);
     $this->assertEmpty($result2);
 }
开发者ID:owindsor,项目名称:silverstripe-hybridsessions,代码行数:17,代码来源:HybridSessionAbstractTest.php

示例12: testFilter

 public function testFilter()
 {
     $member = Member::currentUser();
     if ($member) {
         $member->logout();
     }
     /**
      * @var Blog $blog
      */
     $blog = $this->objFromFixture('Blog', 'FirstBlog');
     $this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts');
     SS_Datetime::set_mock_now('2020-01-01 00:00:00');
     $this->assertEquals(5, $blog->AllChildren()->Count(), 'Unfiltered blog posts');
 }
开发者ID:helpfulrobot,项目名称:silverstripe-blog,代码行数:14,代码来源:BlogPostFilterTest.php

示例13: 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());
 }
开发者ID:normann,项目名称:sapphire,代码行数:15,代码来源:DatetimeTest.php

示例14: testschedule

 public function testschedule($request)
 {
     $schedule = (int) $request->getVar('ID');
     $time = strtotime($request->getVar('date'));
     if ($schedule) {
         $schedule = ConfiguredSchedule::get()->byID($schedule);
     }
     if (!$time || !$schedule) {
         return 'Invalid date';
     }
     $date = date('Y-m-d H:i:s', $time);
     SS_Datetime::set_mock_now($date);
     $dateTime = $schedule->getNextScheduledDateTime();
     if ($dateTime) {
         return $dateTime->format('Y-m-d H:i:s');
     }
 }
开发者ID:silverstripe-australia,项目名称:silverstripe-schedulizer,代码行数:17,代码来源:SchedulizerModelAdmin.php

示例15: testVisible

 function testVisible()
 {
     $mobilePoll = $this->ObjFromFixture('Poll', 'mobile-poll');
     $this->assertTrue($mobilePoll->getVisible());
     $mobilePoll->IsActive = false;
     $mobilePoll->write();
     $this->assertFalse($mobilePoll->getVisible());
     $mobilePoll->IsActive = true;
     $mobilePoll->Embargo = "2010-10-10 10:10:10";
     $mobilePoll->Expiry = "2010-10-11 10:10:10";
     $mobilePoll->write();
     SS_Datetime::set_mock_now('2010-10-10 10:00:00');
     $this->assertFalse($mobilePoll->getVisible());
     SS_Datetime::set_mock_now('2010-10-10 11:00:00');
     $this->assertTrue($mobilePoll->getVisible());
     SS_Datetime::set_mock_now('2010-10-12 10:00:00');
     $this->assertFalse($mobilePoll->getVisible());
 }
开发者ID:helpfulrobot,项目名称:mateusz-silverstripe-polls,代码行数:18,代码来源:PollTest.php


注:本文中的SS_Datetime::set_mock_now方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。