public function testGetAggregateConfigCollection() { $aggregateConfigCollection = Tx_PtExtlist_Domain_Configuration_Data_Aggregates_AggregateConfigCollectionFactory::getInstance($this->configurationBuilderMock); $this->assertTrue(is_a($aggregateConfigCollection, \PunktDe\PtExtbase\Collection\ObjectCollection::class)); $aggregateConfig1 = $aggregateConfigCollection->getAggregateConfigByIdentifier('agg1'); $this->assertEquals($aggregateConfig1->getMethod(), 'avg'); }
/** * @test */ public function buildAggregateSqlByConfigCollectionReturnsExpectedSql() { $configOverwrite['listConfig']['test']['aggregateData']['sumField1'] = array('scope' => 'query', 'special' => 'special'); $configurationBuilderMock = Tx_PtExtlist_Tests_Domain_Configuration_ConfigurationBuilderMock::getInstance(null, $configOverwrite); $aggConfigCollection = Tx_PtExtlist_Domain_Configuration_Data_Aggregates_AggregateConfigCollectionFactory::getInstance($configurationBuilderMock); $dataBackend = $this->getDataBackend($configurationBuilderMock); $filterboxCollectionMock = $this->getMock('Tx_PtExtlist_Domain_Model_Filter_FilterboxCollection', array('getExcludeFilters'), array(), '', false); $filterboxCollectionMock->expects($this->any())->method('excludeFilters')->will($this->returnValue(array())); $dataBackend->_injectFilterboxCollection($filterboxCollectionMock); $actual = $dataBackend->_call('buildAggregateSQLByConfigCollection', $aggConfigCollection); $expected = "SELECT special AS sumField1, AVG(field2) AS avgField2\n FROM (SELECT tableName1.fieldName1 AS field1, tableName2.fieldName2 AS field2, (special) AS field3, tableName4.fieldName4 AS field4\nFROM companies\nWHERE employees > 0\nGROUP BY company\n) AS AGGREGATEQUERY"; $expected = preg_replace('/[\\n\\r]/', ' ', $expected); $expected = trim(preg_replace('/\\s\\s+/', ' ', $expected)); $actual = preg_replace('/[\\n\\r]/', ' ', $actual); $actual = trim(preg_replace('/\\s\\s+/', ' ', $actual)); $this->assertEquals($expected, $actual); }