You are here

function MessagingTestCase::assertTableRows in Messaging 7

Same name and namespace in other branches
  1. 6.4 tests/messaging_test_case.inc \MessagingTestCase::assertTableRows()
2 calls to MessagingTestCase::assertTableRows()
MessagingTestCase::assertUserRows in tests/messaging_test_case.inc
Messaging_Methods_Tests::testMessagingMethods in tests/messaging_methods.test
Test message sending callbacks for enabled plug-ins

File

tests/messaging_test_case.inc, line 93

Class

MessagingTestCase

Code

function assertTableRows($table, $target, $conditions = NULL, $message = NULL) {
  $sql = 'SELECT COUNT(*) FROM {' . $table . '}';
  $print = $where = array();
  if ($conditions) {
    foreach ($conditions as $field => $value) {
      $where[] = "{$field} = '%s'";
      $print[] = "{$field}={$value}";
    }
  }
  if (!empty($where)) {
    $sql .= ' WHERE ' . implode(' AND ', $where);
  }
  $count = db_result(db_query($sql, $conditions));
  $message = $message ? $message : 'Right number of rows in table ' . $table . '[' . implode(', ', $print) . ']=' . $target;
  $message .= " ({$count})";
  $this
    ->assertEqual($count, $target, $message);
}