/** @test */ public function getSortingStateCollectionReturnsSortingStatesOfRegisteredObservers() { $sortingStateMock1 = $this->buildSortingStateMock('test1', 1); $sortingStateMock2 = $this->buildSortingStateMock('test2', 1); $sortingStateCollectionMock1 = new Tx_PtExtlist_Domain_Model_Sorting_SortingStateCollection(); $sortingStateCollectionMock1->addSortingState($sortingStateMock1); $sortingStateCollectionMock1->addSortingState($sortingStateMock2); $sortingStateMock3 = $this->buildSortingStateMock('test3', 0); $sortingStateMock4 = $this->buildSortingStateMock('test4', 0); $sortingStateCollectionMock2 = new Tx_PtExtlist_Domain_Model_Sorting_SortingStateCollection(); $sortingStateCollectionMock2->addSortingState($sortingStateMock3); $sortingStateCollectionMock2->addSortingState($sortingStateMock4); $sortingObserverMock1 = $this->getMock('Tx_PtExtlist_Domain_Model_Sorting_SortingObserverInterface', array('getSortingStateCollection', 'registerSorter', 'resetSorting', 'resetToDefaultSorting'), array(), '', FALSE); /* @var $sortingObserverMock Tx_PtExtlist_Domain_Model_Sorting_SortingObserverInterface */ $sortingObserverMock1->expects($this->any())->method('getSortingStateCollection')->will($this->returnValue($sortingStateCollectionMock1)); $sortingObserverMock2 = $this->getMock('Tx_PtExtlist_Domain_Model_Sorting_SortingObserverInterface', array('getSortingStateCollection', 'registerSorter', 'resetSorting', 'resetToDefaultSorting'), array(), '', FALSE); /* @var $sortingObserverMock Tx_PtExtlist_Domain_Model_Sorting_SortingObserverInterface */ $sortingObserverMock2->expects($this->any())->method('getSortingStateCollection')->will($this->returnValue($sortingStateCollectionMock2)); $sorter = new Tx_PtExtlist_Domain_Model_Sorting_Sorter(); $sorter->registerSortingObserver($sortingObserverMock1); $sorter->registerSortingObserver($sortingObserverMock2); $sortingStateCollection = $sorter->getSortingStateCollection(); $this->assertEquals($sortingStateCollection->count(), 4); $this->assertEquals($sortingStateCollection->getItemByIndex(0), $sortingStateMock1); $this->assertEquals($sortingStateCollection->getItemByIndex(1), $sortingStateMock2); $this->assertEquals($sortingStateCollection->getItemByIndex(2), $sortingStateMock3); $this->assertEquals($sortingStateCollection->getItemByIndex(3), $sortingStateMock4); }
/** * Factory method to create a sorting state from a given session array * * @param Tx_PtExtlist_Domain_Configuration_ConfigurationBuilder $configurationBuilder * @param array $sessionArray * @return Tx_PtExtlist_Domain_Model_Sorting_SortingStateCollection */ public static function getInstanceBySessionArray(Tx_PtExtlist_Domain_Configuration_ConfigurationBuilder $configurationBuilder, array $sessionArray) { $sortingStateCollection = new Tx_PtExtlist_Domain_Model_Sorting_SortingStateCollection(); foreach ($sessionArray as $sortingStateSessionArray) { $sortingStateCollection->addSortingState(Tx_PtExtlist_Domain_Model_Sorting_SortingState::getInstanceBySessionArray($configurationBuilder, $sortingStateSessionArray)); } return $sortingStateCollection; }
/** * Builds sorting state collection by respecting the registered sorting observers * and getting their sorting informations. * * @return void */ protected function buildSortingStateCollection() { $this->sortingStateCollection = new Tx_PtExtlist_Domain_Model_Sorting_SortingStateCollection(); // Gather sorting states from registered sorting observers if (is_array($this->sortingObservers)) { foreach ($this->sortingObservers as $sortingObserver) { /* @var $sortingObserver Tx_PtExtlist_Domain_Model_Sorting_SortingObserverInterface */ $sortingStateCollectionFromObserver = $sortingObserver->getSortingStateCollection(); foreach ($sortingStateCollectionFromObserver as $sortingStateFromSortingObserver) { $this->sortingStateCollection->addSortingState($sortingStateFromSortingObserver); } } } }
/** * Build sorting state collection for this column * * @return void */ protected function buildSortingStateCollection() { $this->sortingStateCollection = new Tx_PtExtlist_Domain_Model_Sorting_SortingStateCollection(); if (count($this->sortedFields) > 0) { foreach ($this->sortedFields as $fieldIdentifier => $sortingDirection) { if ($this->sortingFieldConfig->hasItem($fieldIdentifier)) { $fieldConfig = $this->sortingFieldConfig->getItemById($fieldIdentifier); if ($fieldConfig->getForceDirection()) { $sortingState = Tx_PtExtlist_Domain_Model_Sorting_SortingState::getInstanceByFieldIdentifierAndSortingDirection($this->columnConfig->getConfigurationBuilder(), $fieldConfig->getField(), $fieldConfig->getDirection()); } else { $sortingState = Tx_PtExtlist_Domain_Model_Sorting_SortingState::getInstanceByFieldIdentifierAndSortingDirection($this->columnConfig->getConfigurationBuilder(), $fieldConfig->getField(), $sortingDirection); } $this->sortingStateCollection->addSortingState($sortingState); } } } }
/** @test */ public function getSortingsQueryReturnsCorrectQueryObjectForSortings() { $fieldConfigurationMock1 = $this->getMock(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig, array('getIdentifier'), array(), '', FALSE); $fieldConfigurationMock1->expects($this->any())->method('getIdentifier')->will($this->returnValue('test1')); $sortingDirection1 = Tx_PtExtlist_Domain_QueryObject_Query::SORTINGSTATE_ASC; $sortingState1 = new Tx_PtExtlist_Domain_Model_Sorting_SortingState($fieldConfigurationMock1, $sortingDirection1); $fieldConfigurationMock2 = $this->getMock(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig, array('getIdentifier'), array(), '', FALSE); $fieldConfigurationMock2->expects($this->any())->method('getIdentifier')->will($this->returnValue('test2')); $sortingDirection2 = Tx_PtExtlist_Domain_QueryObject_Query::SORTINGSTATE_DESC; $sortingState2 = new Tx_PtExtlist_Domain_Model_Sorting_SortingState($fieldConfigurationMock2, $sortingDirection2); $sortingStateCollection = new Tx_PtExtlist_Domain_Model_Sorting_SortingStateCollection(); $sortingStateCollection->addSortingState($sortingState1); $sortingStateCollection->addSortingState($sortingState2); $sortingsQuery = $sortingStateCollection->getSortingsQuery(); $this->assertEquals($sortingsQuery->getSortings(), array('test1' => $sortingDirection1, 'test2' => $sortingDirection2)); }