/** * Changes an existing dummy record and stores the new data for this * record. Only fields that get new values in $recordData will be changed, * everything else will stay untouched. * * The array with the new recordData must contain at least one entry, but * must not contain a new UID for the record. If you need to change the UID, * you have to create a new record! * * @param string $tableName * the name of the table, must not be empty * @param integer $uid * the UID of the record to change, must not be empty * @param array $recordData * associative array containing key => value pairs for those fields * of the record that need to be changed, must not be empty * * @return void * * @throws InvalidArgumentException * @throws Tx_Phpunit_Exception_Database */ public function changeRecord($tableName, $uid, array $recordData) { $dummyColumnName = $this->getDummyColumnName($tableName); if (!$this->isTableNameAllowed($tableName)) { throw new InvalidArgumentException('The table "' . $tableName . '" is not on the lists with allowed tables.', 1334439098); } if ($uid === 0) { throw new InvalidArgumentException('The parameter $uid must not be zero.', 1334439105); } if (empty($recordData)) { throw new InvalidArgumentException('The array with the new record data must not be empty.', 1334439111); } if (isset($recordData['uid'])) { throw new InvalidArgumentException('The parameter $recordData must not contain changes to the UID of a record.', 1334439119); } if (isset($recordData[$dummyColumnName])) { throw new InvalidArgumentException('The parameter $recordData must not contain changes to the ' . 'field "' . $dummyColumnName . '". It is impossible to ' . 'convert a dummy record into a regular record.', 1334439125); } if (!$this->countRecords($tableName, 'uid=' . $uid)) { throw new Tx_Phpunit_Exception_Database(1334439132); } Tx_Phpunit_Service_Database::update($tableName, 'uid = ' . $uid . ' AND ' . $dummyColumnName . ' = 1', $recordData); }
/** * @test */ public function updateForTwoChangedRecordsReturnsTwo() { $uid1 = $this->testingFramework->createRecord('tx_phpunit_test'); $uid2 = $this->testingFramework->createRecord('tx_phpunit_test'); self::assertSame(2, \Tx_Phpunit_Service_Database::update('tx_phpunit_test', 'uid IN(' . $uid1 . ',' . $uid2 . ')', array('title' => 'foo'))); }