/** * 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); }
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; } } }
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')); }
/** * @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)); }
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.'); }
/** * {@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'); }
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"); }
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(); }
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'); }
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(); }
/** * 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); }
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'); }
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()); }
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'); } }
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()); }
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(); }
public function setUp() { parent::setUp(); Config::nest(); if (!interface_exists('QueuedJob')) { $this->skipTest = true; $this->markTestSkipped("These tests need the QueuedJobs module installed to run"); } if (class_exists('Subsite')) { $this->skipTest = true; $this->markTestSkipped(get_class() . ' skipped when running with subsites'); } SS_Datetime::set_mock_now('2015-05-07 06:00:00'); Config::inst()->update('SearchUpdateBatchedProcessor', 'batch_size', 5); Config::inst()->update('SearchUpdateBatchedProcessor', 'batch_soft_cap', 0); Config::inst()->update('SearchUpdateCommitJobProcessor', 'cooldown', 600); Versioned::reading_stage("Stage"); Injector::inst()->registerService(new BatchedProcessor_QueuedJobService(), 'QueuedJobService'); FullTextSearch::force_index_list('BatchedProcessorTest_Index'); SearchUpdateCommitJobProcessor::$dirty_indexes = array(); SearchUpdateCommitJobProcessor::$has_run = false; $this->oldProcessor = SearchUpdater::$processor; SearchUpdater::$processor = new SearchUpdateQueuedJobProcessor(); }
public function testTimeout() { $step = $this->getDummyDeployment(); $step->start(); // Assert not error at startup $this->assertEquals('Started', $step->Status); $this->assertTrue(PipelineTest_MockLog::has_message('TestDeployStep:Snapshot creating snapshot of database')); // Go to two hours into the future SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+2 hours'))); // Retry step PipelineTest_MockLog::clear(); $step->start(); $this->assertEquals('Failed', $step->Status); $this->assertTrue($step->isTimedOut()); $this->assertTrue(PipelineTest_MockLog::has_message('Checking status of TestDeployStep:Snapshot...')); $this->assertTrue(PipelineTest_MockLog::has_message('TestDeployStep:Snapshot took longer than 3600 seconds to run and has timed out')); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); SS_Datetime::set_mock_now('2013-10-10 20:00:00'); }
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'); }
/** * Test delayed notification */ public function testSendDelay() { $step = $this->getDummyConfirmationStep(); // Assert dependencies are injected $this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService); $step->start(); // Assert not error at startup $this->assertEquals('Started', $step->Status); $this->assertHasLog('Starting TestConfirmStep...'); // Check only recipient and first admin has been notified $this->assertFalse($step->isTimedOut()); $link = Director::absoluteURL('naut/project/testproject/environment/uat'); $this->assertSentMessage("You requested approval for deployment of testproject/uat. Cancel? {$link}", '*****@*****.**'); $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**'); $this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages())); // Advance 1 hour and ensure no other notifications have been sent SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+1 hour'))); $this->clearLog(); $step->start(); $this->assertFalse($step->isTimedOut()); $this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages()); // Advance 3 hours (2 more) and ensure the next notification is sent out SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+3 hour'))); $this->clearLog(); $step->start(); $this->assertFalse($step->isTimedOut()); $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**'); $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**'); $this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages())); // Go to 5 hours (another 2) and ensure the final notification is sent SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+5 hour'))); $this->clearLog(); $step->start(); $this->assertFalse($step->isTimedOut()); $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**'); $this->assertEquals(1, count(PipelineTest_RecordingMessageSender::get_messages())); // Go to 24 hours and ensure no notifications are sent SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+24 hour'))); $this->clearLog(); $step->start(); $this->assertFalse($step->isTimedOut()); $this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages()); }
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(); }
public function setUp() { SS_Datetime::set_mock_now("2013-10-10 20:00:00"); parent::setUp(); }
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"); }
function testSuspended() { $private = $this->objFromFixture('Forum', 'loggedInOnly'); $limited = $this->objFromFixture('Forum', 'limitedToGroup'); $inheritedForum_loggedInOnly = $this->objFromFixture('Forum', 'inheritedForum_loggedInOnly'); SS_Datetime::set_mock_now('2011-10-10 12:00:00'); // try logging in a member suspendedexpired $suspendedexpired = $this->objFromFixture('Member', 'suspendedexpired'); $this->assertFalse($suspendedexpired->IsSuspended()); $suspendedexpired->logIn(); $this->assertTrue($private->canPost()); $this->assertTrue($limited->canPost()); $this->assertTrue($inheritedForum_loggedInOnly->canPost()); // try logging in a member suspended $suspended = $this->objFromFixture('Member', 'suspended'); $this->assertTrue($suspended->IsSuspended()); $suspended->logIn(); $this->assertFalse($private->canPost()); $this->assertFalse($limited->canPost()); $this->assertFalse($inheritedForum_loggedInOnly->canPost()); }
public function testAgoInFuture() { SS_Datetime::set_mock_now('2000-12-31 00:00:00'); $this->assertEquals('in 10 years', DBField::create_field('Date', '2010-12-31')->Ago(), 'Exact past match on years'); $this->assertEquals('in 1 day', DBField::create_field('Date', '2001-01-01')->Ago(true, 1), 'Approximate past match on minutes'); $this->assertEquals('in 24 hours', DBField::create_field('Date', '2001-01-01')->Ago(), 'Approximate past match on minutes'); SS_Datetime::clear_mock_now(); }
public function testArchiveRelatedDataWithoutVersioned() { SS_Datetime::set_mock_now('2009-01-01 00:00:00'); $relatedData = new VersionedTest_RelatedWithoutVersion(); $relatedData->Name = 'Related Data'; $relatedDataId = $relatedData->write(); $testData = new VersionedTest_DataObject(); $testData->Title = 'Test'; $testData->Content = 'Before Content'; $testData->Related()->add($relatedData); $id = $testData->write(); SS_Datetime::set_mock_now('2010-01-01 00:00:00'); $testData->Content = 'After Content'; $testData->write(); Versioned::reading_archived_date('2009-01-01 19:00:00'); $fetchedData = VersionedTest_DataObject::get()->byId($id); $this->assertEquals('Before Content', $fetchedData->Content, 'We see the correct content of the older version'); $relatedData = VersionedTest_RelatedWithoutVersion::get()->byId($relatedDataId); $this->assertEquals(1, $relatedData->Related()->count(), 'We have a relation, with no version table, querying it still works'); }
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(); }
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(); }
public function setUp() { SS_Datetime::set_mock_now("2014-01-01"); parent::setUp(); }