Ejemplo n.º 1
0
 /**
  * @test
  *
  * @expectedException \BadMethodCallException
  */
 public function countDoesNotAllowJoinWithOnlyOneTableOnTheRight()
 {
     \Tx_Phpunit_Service_Database::count('JOIN tx_phpunit_test');
 }
Ejemplo n.º 2
0
 /**
  * Counts the dummy records in the table given by the first parameter $tableName
  * that match a given WHERE clause.
  *
  * @param string $tableName
  *        the name of the table to query, must not be empty
  * @param string $whereClause
  *        the WHERE part of the query, may be empty (all records will be
  *        counted in that case)
  *
  * @return integer the number of records that have been found, will be >= 0
  *
  * @throws InvalidArgumentException
  */
 public function countRecords($tableName, $whereClause = '')
 {
     if (!$this->isTableNameAllowed($tableName)) {
         throw new InvalidArgumentException('The given table name is invalid. This means it is either empty or not in the list of allowed tables.', 1334439501);
     }
     $whereForDummyColumn = $this->getDummyColumnName($tableName) . ' = 1';
     $compoundWhereClause = $whereClause !== '' ? '(' . $whereClause . ') AND ' . $whereForDummyColumn : $whereForDummyColumn;
     return Tx_Phpunit_Service_Database::count($tableName, $compoundWhereClause);
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function removeRelationOnRealRecordNotRemovesRelation()
 {
     $uidLocal = $this->fixture->createRecord('tx_phpunit_test');
     $uidForeign = $this->fixture->createRecord('tx_phpunit_test');
     // Create a new record that looks like a real record, i.e. the
     // is_dummy_record flag is set to 0.
     Tx_Phpunit_Service_Database::insert('tx_phpunit_test_article_mm', array('uid_local' => $uidLocal, 'uid_foreign' => $uidForeign, 'is_dummy_record' => 0));
     // Runs our delete method which should NOT affect the record created
     // above.
     $this->fixture->removeRelation('tx_phpunit_test_article_mm', $uidLocal, $uidForeign);
     // Caches the value that will be tested for later. We need to use the
     // following order to make sure the test record gets deleted even if
     // this test fails:
     // 1. reads the value to test
     // 2. deletes the test record
     // 3. tests the previously read value (and possibly fails)
     $numberOfCreatedRelations = Tx_Phpunit_Service_Database::count('tx_phpunit_test_article_mm', 'uid_local = ' . $uidLocal . ' AND uid_foreign = ' . $uidForeign);
     // Deletes the record as it will not be caught by the clean up function.
     Tx_Phpunit_Service_Database::delete('tx_phpunit_test_article_mm', 'uid_local = ' . $uidLocal . ' AND uid_foreign = ' . $uidForeign . ' AND is_dummy_record = 0');
     // Checks whether the relation had been created further up.
     $this->assertSame(1, $numberOfCreatedRelations);
 }