diff --git a/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php b/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php index ca4b5169f2..ec5e699aa0 100644 --- a/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php +++ b/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php @@ -1,68 +1,70 @@ true, ); } public function testRegistrationEmailOK() { $env = PhabricatorEnv::beginScopedEnv(); $env->overrideEnvConfig('auth.email-domains', array('example.com')); $this->registerUser( 'PhabricatorUserEditorTestCaseOK', 'PhabricatorUserEditorTestCase@example.com'); + + $this->assertEqual(true, true); } public function testRegistrationEmailInvalid() { $env = PhabricatorEnv::beginScopedEnv(); $env->overrideEnvConfig('auth.email-domains', array('example.com')); $prefix = str_repeat('a', PhabricatorUserEmail::MAX_ADDRESS_LENGTH); $email = $prefix.'@evil.com@example.com'; try { $this->registerUser( 'PhabricatorUserEditorTestCaseInvalid', $email); } catch (Exception $ex) { $caught = $ex; } $this->assertEqual(true, ($caught instanceof Exception)); } public function testRegistrationEmailDomain() { $env = PhabricatorEnv::beginScopedEnv(); $env->overrideEnvConfig('auth.email-domains', array('example.com')); $caught = null; try { $this->registerUser( 'PhabricatorUserEditorTestCaseDomain', 'PhabricatorUserEditorTestCase@whitehouse.gov'); } catch (Exception $ex) { $caught = $ex; } $this->assertEqual(true, ($caught instanceof Exception)); } private function registerUser($username, $email) { $user = id(new PhabricatorUser()) ->setUsername($username) ->setRealname($username); $email = id(new PhabricatorUserEmail()) ->setAddress($email) ->setIsVerified(0); id(new PhabricatorUserEditor()) ->setActor($user) ->createNewUser($user, $email); } } diff --git a/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php b/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php index 68822568ae..d397788f20 100644 --- a/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php +++ b/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php @@ -1,103 +1,104 @@ true, ); } /** * This is more of an acceptance test case instead of a unittest. It verifies * that all symbols can be loaded correctly. It can catch problems like * missing methods in descendants of abstract base classes. */ public function testEverythingImplemented() { id(new PhutilSymbolLoader())->selectAndLoadSymbols(); + $this->assertEqual(true, true); } public function testApplicationsInstalled() { $all = PhabricatorApplication::getAllApplications(); $installed = PhabricatorApplication::getAllInstalledApplications(); $this->assertEqual( count($all), count($installed), 'In test cases, all applications should default to installed.'); } public function testMySQLAgreesWithUsAboutBMP() { // Build a string with every BMP character in it, then insert it into MySQL // and read it back. We expect to get the same string out that we put in, // demonstrating that strings which pass our BMP checks are also valid in // MySQL and no silent data truncation will occur. $buf = ''; for ($ii = 0x01; $ii <= 0x7F; $ii++) { $buf .= chr($ii); } for ($ii = 0xC2; $ii <= 0xDF; $ii++) { for ($jj = 0x80; $jj <= 0xBF; $jj++) { $buf .= chr($ii).chr($jj); } } // NOTE: This is \xE0\xA0\xZZ. for ($ii = 0xE0; $ii <= 0xE0; $ii++) { for ($jj = 0xA0; $jj <= 0xBF; $jj++) { for ($kk = 0x80; $kk <= 0xBF; $kk++) { $buf .= chr($ii).chr($jj).chr($kk); } } } // NOTE: This is \xE1\xZZ\xZZ through \xEF\xZZ\xZZ. for ($ii = 0xE1; $ii <= 0xEF; $ii++) { for ($jj = 0x80; $jj <= 0xBF; $jj++) { for ($kk = 0x80; $kk <= 0xBF; $kk++) { $buf .= chr($ii).chr($jj).chr($kk); } } } $this->assertEqual(194431, strlen($buf)); $this->assertEqual(true, phutil_is_utf8_with_only_bmp_characters($buf)); $write = id(new HarbormasterScratchTable()) ->setData('all.utf8.bmp') ->setBigData($buf) ->save(); $read = id(new HarbormasterScratchTable())->load($write->getID()); $this->assertEqual($buf, $read->getBigData()); } public function testRejectMySQLBMPQueries() { $table = new HarbormasterScratchTable(); $conn_r = $table->establishConnection('w'); $snowman = "\xE2\x98\x83"; $gclef = "\xF0\x9D\x84\x9E"; qsprintf($conn_r, 'SELECT %B', $snowman); qsprintf($conn_r, 'SELECT %s', $snowman); qsprintf($conn_r, 'SELECT %B', $gclef); $caught = null; try { qsprintf($conn_r, 'SELECT %s', $gclef); } catch (AphrontQueryCharacterSetException $ex) { $caught = $ex; } $this->assertEqual( true, ($caught instanceof AphrontQueryCharacterSetException)); } } diff --git a/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php b/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php index ab1ce2f7b1..29f230b563 100644 --- a/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php +++ b/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php @@ -1,141 +1,145 @@ false, ); } public function testIsolation() { // This will fail if the connection isn't isolated. queryfx( $this->newIsolatedConnection(), 'INSERT INVALID SYNTAX'); + + $this->assertEqual(true, true); } public function testInsertGeneratesID() { $conn = $this->newIsolatedConnection(); queryfx($conn, 'INSERT'); $id1 = $conn->getInsertID(); queryfx($conn, 'INSERT'); $id2 = $conn->getInsertID(); $this->assertEqual(true, (bool)$id1, 'ID1 exists.'); $this->assertEqual(true, (bool)$id2, 'ID2 exists.'); $this->assertEqual( true, $id1 != $id2, "IDs '{$id1}' and '{$id2}' are distinct."); } public function testDeletePermitted() { $conn = $this->newIsolatedConnection(); queryfx($conn, 'DELETE'); + + $this->assertEqual(true, true); } public function testTransactionStack() { $conn = $this->newIsolatedConnection(); $conn->openTransaction(); queryfx($conn, 'INSERT'); $conn->saveTransaction(); $this->assertEqual( array( 'START TRANSACTION', 'INSERT', 'COMMIT', ), $conn->getQueryTranscript()); $conn = $this->newIsolatedConnection(); $conn->openTransaction(); queryfx($conn, 'INSERT 1'); $conn->openTransaction(); queryfx($conn, 'INSERT 2'); $conn->killTransaction(); $conn->openTransaction(); queryfx($conn, 'INSERT 3'); $conn->openTransaction(); queryfx($conn, 'INSERT 4'); $conn->saveTransaction(); $conn->saveTransaction(); $conn->openTransaction(); queryfx($conn, 'INSERT 5'); $conn->killTransaction(); queryfx($conn, 'INSERT 6'); $conn->saveTransaction(); $this->assertEqual( array( 'START TRANSACTION', 'INSERT 1', 'SAVEPOINT Aphront_Savepoint_1', 'INSERT 2', 'ROLLBACK TO SAVEPOINT Aphront_Savepoint_1', 'SAVEPOINT Aphront_Savepoint_1', 'INSERT 3', 'SAVEPOINT Aphront_Savepoint_2', 'INSERT 4', 'SAVEPOINT Aphront_Savepoint_1', 'INSERT 5', 'ROLLBACK TO SAVEPOINT Aphront_Savepoint_1', 'INSERT 6', 'COMMIT', ), $conn->getQueryTranscript()); } public function testTransactionRollback() { $check = array(); $phid = new HarbormasterScratchTable(); $phid->openTransaction(); for ($ii = 0; $ii < 3; $ii++) { $key = $this->generateTestData(); $obj = new HarbormasterScratchTable(); $obj->setData($key); $obj->save(); $check[] = $key; } $phid->killTransaction(); foreach ($check as $key) { $this->assertNoSuchRow($key); } } private function newIsolatedConnection() { $config = array(); return new AphrontIsolatedDatabaseConnection($config); } private function generateTestData() { return Filesystem::readRandomCharacters(20); } private function assertNoSuchRow($data) { try { $row = id(new HarbormasterScratchTable())->loadOneWhere( 'data = %s', $data); $this->assertEqual( null, $row, 'Expect fake row to exist only in isolation.'); } catch (AphrontQueryConnectionException $ex) { // If we can't connect to the database, conclude that the isolated // connection actually is isolated. Philosophically, this perhaps allows // us to claim this test does not depend on the database? } } } diff --git a/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php b/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php index aba1873751..67128e82da 100644 --- a/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php +++ b/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php @@ -1,112 +1,113 @@ assertEqual(null, $dao->getID(), 'Expect no ID.'); $this->assertEqual(null, $dao->getPHID(), 'Expect no PHID.'); $dao->save(); // Effects insert $id = $dao->getID(); $phid = $dao->getPHID(); $this->assertEqual(true, (bool)$id, 'Expect ID generated.'); $this->assertEqual(true, (bool)$phid, 'Expect PHID generated.'); $dao->save(); // Effects update $this->assertEqual($id, $dao->getID(), 'Expect ID unchanged.'); $this->assertEqual($phid, $dao->getPHID(), 'Expect PHID unchanged.'); } public function testEphemeral() { $dao = new LiskIsolationTestDAO(); $dao->save(); $dao->makeEphemeral(); $this->tryTestCases( array( $dao, ), array( false, ), array($this, 'saveDAO')); } public function saveDAO($dao) { $dao->save(); } public function testIsolationContainment() { $dao = new LiskIsolationTestDAO(); try { $dao->establishLiveConnection('r'); $this->assertFailure( "LiskIsolationTestDAO did not throw an exception when instructed to ". "explicitly connect to an external database."); } catch (LiskIsolationTestDAOException $ex) { // Expected, pass. } + $this->assertEqual(true, true); } public function testMagicMethods() { $dao = new LiskIsolationTestDAO(); $this->assertEqual( null, $dao->getName(), 'getName() on empty object'); $this->assertEqual( $dao, $dao->setName('x'), 'setName() returns $this'); $this->assertEqual( 'y', $dao->setName('y')->getName(), 'setName() has an effect'); $ex = null; try { $dao->gxxName(); } catch (Exception $thrown) { $ex = $thrown; } $this->assertEqual( true, (bool)$ex, 'Typoing "get" should throw.'); $ex = null; try { $dao->sxxName('z'); } catch (Exception $thrown) { $ex = $thrown; } $this->assertEqual( true, (bool)$ex, 'Typoing "set" should throw.'); $ex = null; try { $dao->madeUpMethod(); } catch (Exception $thrown) { $ex = $thrown; } $this->assertEqual( true, (bool)$ex, 'Made up method should throw.'); } }