Пример #1
0
 /**
  * Updates an integer field of a database table by one. This is mainly needed
  * for counting up the relation counter when creating a database relation.
  *
  * The field to update must be of type integer.
  *
  * @param string $tableName
  *        name of the table, must not be empty
  * @param integer $uid
  *        the UID of the record to modify, must be > 0
  * @param string $fieldName
  *        the field name of the field to modify, must not be empty
  *
  * @return void
  *
  * @throws InvalidArgumentException
  * @throws Tx_Phpunit_Exception_Database
  */
 public function increaseRelationCounter($tableName, $uid, $fieldName)
 {
     if (!$this->isTableNameAllowed($tableName)) {
         throw new InvalidArgumentException('The table name "' . $tableName . '" is invalid. This means it is either empty or not in the list of allowed tables.', 1334439601);
     }
     if (!Tx_Phpunit_Service_Database::tableHasColumn($tableName, $fieldName)) {
         throw new InvalidArgumentException('The table ' . $tableName . ' has no column ' . $fieldName . '.', 1334439616);
     }
     Tx_Phpunit_Service_Database::enableQueryLogging();
     $dbResult = $GLOBALS['TYPO3_DB']->sql_query('UPDATE ' . $tableName . ' SET ' . $fieldName . '=' . $fieldName . '+1 WHERE uid=' . $uid);
     if (!$dbResult) {
         throw new Tx_Phpunit_Exception_Database(1334439623);
     }
     if ($GLOBALS['TYPO3_DB']->sql_affected_rows() === 0) {
         throw new Tx_Phpunit_Exception_Database(1334439632);
     }
     $this->markTableAsDirty($tableName);
 }
Пример #2
0
 /**
  * @test
  */
 public function messageAfterQueryWithLastQueryEnabledContainsLastQuery()
 {
     Tx_Phpunit_Service_Database::getDatabaseConnection()->exec_SELECTquery('title', 'tx_phpunit_test', '');
     $subject = new Tx_Phpunit_Exception_EmptyQueryResult();
     self::assertContains('SELECT', $subject->getMessage());
 }
Пример #3
0
 /**
  * Imports the SQL definitions from a (ext_)tables.sql file.
  *
  * @param string $definitionContent
  *        the SQL to import, must not be empty
  *
  * @return void
  */
 private function importDatabaseDefinitions($definitionContent)
 {
     /* @var $install \TYPO3\CMS\Install\Service\SqlSchemaMigrationService */
     $install = GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService');
     $fieldDefinitionsFile = $install->getFieldDefinitions_fileContent($definitionContent);
     if (empty($fieldDefinitionsFile)) {
         return;
     }
     // find statements to query
     $fieldDefinitionsDatabase = $install->getFieldDefinitions_fileContent($this->getTestDatabaseSchema());
     $diff = $install->getDatabaseExtra($fieldDefinitionsFile, $fieldDefinitionsDatabase);
     $updateStatements = $install->getUpdateSuggestions($diff);
     $updateTypes = array('add', 'change', 'create_table');
     $databaseConnection = Tx_Phpunit_Service_Database::getDatabaseConnection();
     foreach ($updateTypes as $updateType) {
         if (array_key_exists($updateType, $updateStatements)) {
             foreach ((array) $updateStatements[$updateType] as $string) {
                 $databaseConnection->admin_query($string);
             }
         }
     }
 }
Пример #4
0
 /**
  * @test
  */
 public function getDatabaseConnectionReturnsGlobalsDatabaseConnection()
 {
     self::assertSame($GLOBALS['TYPO3_DB'], \Tx_Phpunit_Service_Database::getDatabaseConnection());
 }
Пример #5
0
 /**
  * Retrieves the table names of the current DB and stores them in
  * self::$tableNameCache.
  *
  * This function does nothing if the table names already have been
  * retrieved.
  *
  * @return void
  */
 private static function retrieveTableNames()
 {
     if (!empty(self::$tableNameCache)) {
         return;
     }
     self::$tableNameCache = $GLOBALS['TYPO3_DB']->admin_get_tables();
 }
Пример #6
0
 /**
  * Retrieves the table names of the current DB and stores them in
  * self::$tableNameCache.
  *
  * This function does nothing if the table names already have been
  * retrieved.
  *
  * @return void
  */
 private static function retrieveTableNames()
 {
     if (!empty(self::$tableNameCache)) {
         return;
     }
     self::$tableNameCache = self::getDatabaseConnection()->admin_get_tables();
 }
Пример #7
0
 /**
  * @test
  */
 public function selectReturnsMySqliResult()
 {
     self::assertInstanceOf(\mysqli_result::class, Tx_Phpunit_Service_Database::select('title', 'tx_phpunit_test'));
 }
Пример #8
0
 /**
  * @test
  */
 public function existsRecordWithUidUsesAdditionalNonEmptyWhereClause()
 {
     $uid = $this->testingFramework->createRecord('tx_phpunit_test', array('deleted' => 1));
     $this->assertFalse(Tx_Phpunit_Service_Database::existsRecordWithUid('tx_phpunit_test', $uid, ' AND deleted = 0'));
 }
Пример #9
0
 /**
  * @test
  */
 public function increaseRelationCounterIncreasesNonZeroFieldValueByOne()
 {
     $uid = $this->fixture->createRecord('tx_phpunit_test', array('related_records' => 41));
     $this->fixture->increaseRelationCounter('tx_phpunit_test', $uid, 'related_records');
     $row = Tx_Phpunit_Service_Database::selectSingle('related_records', 'tx_phpunit_test', 'uid = ' . $uid);
     $this->assertSame(42, intval($row['related_records']));
 }