/** * test timeaccount - sales contract filter * also tests Tinebase_Model_Filter_ExplicitRelatedRecord */ public function testTimeaccountContractFilter() { $this->_getTimeaccount(array('title' => 'TA1', 'number' => 12345, 'description' => 'UnitTest'), true); $ta1 = $this->_timeaccountController->get($this->_lastCreatedRecord['id']); $this->_getTimeaccount(array('title' => 'TA2', 'number' => 12346, 'description' => 'UnitTest'), true); $ta2 = $this->_timeaccountController->get($this->_lastCreatedRecord['id']); $cId = Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId(); $contract = Sales_Controller_Contract::getInstance()->create(new Sales_Model_Contract(array('title' => 'testRelateTimeaccount', 'number' => Tinebase_Record_Abstract::generateUID(), 'container_id' => $cId))); $ta1->relations = array($this->_getRelation($contract, $ta1)); $this->_timeaccountController->update($ta1); // search by contract $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'contract', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $contract->getId()))))); $filterArray = $f->toArray(); $this->assertEquals($contract->getId(), $filterArray[0]['value'][0]['value']['id']); $result = $this->_timeaccountController->search($f); $this->assertEquals(1, $result->count()); $this->assertEquals('TA1', $result->getFirstRecord()->title); // test empty filter (without contract) $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'contract', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => null))), array('field' => 'description', 'operator' => 'equals', 'value' => 'UnitTest'))); $result = $this->_timeaccountController->search($f); $this->assertEquals(1, $result->count(), 'Only one record should have been found!'); $this->assertEquals('TA2', $result->getFirstRecord()->title); // test generic relation filter $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'foreignRecord', 'operator' => 'AND', 'value' => array('appName' => 'Sales', 'linkType' => 'relation', 'modelName' => 'Contract', 'filters' => array('field' => 'query', 'operator' => 'contains', 'value' => 'TA1'))))); $result = $this->_timeaccountController->search($f); $this->assertEquals(1, $result->count()); $this->assertEquals('TA1', $result->getFirstRecord()->title); // test "not" operator $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'contract', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'not', 'value' => $contract->getId()))), array('field' => 'description', 'operator' => 'equals', 'value' => 'UnitTest'))); $result = $this->_timeaccountController->search($f); // TODO is this correct? do we expect the timaccount without contract to be missing from results? $this->assertEquals(0, $result->count(), 'No record should be found'); }