public function testProcess() { $timeSpanAlgorithmMock = $this->getAccessibleMock('Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_CondensedTimeSpansAlgorithm', array('dummy')); $timeSpan01 = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpan(); $timeSpan01->setStartDate(new DateTime('2011/12/24')); $timeSpan01->setEndDate(new DateTime('2011/12/31')); $timeSpan02 = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpan(); $timeSpan02->setStartDate(new DateTime('2011/12/28')); $timeSpan02->setEndDate(new DateTime('2012/01/03')); $timeSpan03 = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpan(); $timeSpan03->setStartDate(new DateTime('2012/03/05')); $timeSpan03->setEndDate(new DateTime('2012/03/08')); $timeSpan04 = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpan(); $timeSpan04->setStartDate(new DateTime('2012/01/02')); $timeSpan04->setEndDate(new DateTime('2012/01/02')); $timeSpan05 = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpan(); $timeSpan05->setStartDate(new DateTime('2012/05/04')); $timeSpan05->setEndDate(new DateTime('2012/05/04')); $timeSpan06 = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpan(); $timeSpan06->setStartDate(new DateTime('2012/05/04')); $timeSpan06->setEndDate(new DateTime('2012/05/04')); $timeSpans = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpanCollection(); $timeSpans->push($timeSpan01); $timeSpans->push($timeSpan02); $timeSpans->push($timeSpan03); $timeSpans->push($timeSpan04); $timeSpans->push($timeSpan05); $timeSpans->push($timeSpan06); $timeSpanAlgorithmMock->_set('timeSpans', $timeSpans); $actual = $timeSpanAlgorithmMock->process(); $actualValueInProperty = $timeSpanAlgorithmMock->_get('condensedTimeSpans'); $this->assertEquals($actual, $actualValueInProperty); $this->assertEquals(3, count($actual)); $expected = new DateTime('2011/12/24'); $this->assertEquals($expected->format('U'), $actual[0]->getStartDate()->format('U')); $expected = new DateTime('2012/01/03'); $this->assertEquals($expected->format('U'), $actual[0]->getEndDate()->format('U')); $expected = new DateTime('2012/03/05'); $this->assertEquals($expected->format('U'), $actual[1]->getStartDate()->format('U')); $expected = new DateTime('2012/03/08'); $this->assertEquals($expected->format('U'), $actual[1]->getEndDate()->format('U')); $expected = new DateTime('2012/05/04'); $this->assertEquals($expected->format('U'), $actual[2]->getStartDate()->format('U')); $expected = new DateTime('2012/05/04'); $this->assertEquals($expected->format('U'), $actual[2]->getEndDate()->format('U')); }
/** * @param array $queryResult * @return Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpanCollection Condensed time spans */ protected function buildCondensedTimeSpans($queryResult) { $timeSpans = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpanCollection(); foreach ($queryResult as $dateRanges) { foreach ($this->dateFieldConfigs as $key => $config) { if ($config['start'] == $config['end']) { $startField = $config['start']->getIdentifier(); $endField = $config['end']->getIdentifier(); } else { $startField = $this->buildFieldAlias($key, 'start'); $endField = $this->buildFieldAlias($key, 'end'); } $startDate = $dateRanges[$startField]; $endDate = $dateRanges[$endField]; if (!empty($startDate) && !empty($endDate)) { $timeSpan = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_TimeSpan(); $timeSpan->setStartDate(new DateTime("@" . $startDate)); $timeSpan->getStartDate()->setTimezone(new DateTimeZone(date_default_timezone_get())); $timeSpan->setEndDate(new DateTime("@" . $endDate)); $timeSpan->getEndDate()->setTimezone(new DateTimeZone(date_default_timezone_get())); $timeSpans->push($timeSpan); } } } $condensedTimeSpansAlgorithm = new Tx_PtExtlist_Domain_Model_Filter_DataProvider_TimeSpanAlgorithm_CondensedTimeSpansAlgorithm(); $condensedTimeSpansAlgorithm->setTimeSpans($timeSpans); return $condensedTimeSpansAlgorithm->process(); }