Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/base/controller/__tests__/PhabricatorAccessControlTestCase.php b/src/applications/base/controller/__tests__/PhabricatorAccessControlTestCase.php
index 1f5c94a498..0901613021 100644
--- a/src/applications/base/controller/__tests__/PhabricatorAccessControlTestCase.php
+++ b/src/applications/base/controller/__tests__/PhabricatorAccessControlTestCase.php
@@ -1,282 +1,280 @@
<?php
final class PhabricatorAccessControlTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testControllerAccessControls() {
$root = dirname(phutil_get_library_root('phabricator'));
require_once $root.'/support/PhabricatorStartup.php';
$application_configuration = new AphrontDefaultApplicationConfiguration();
$host = 'meow.example.com';
$_SERVER['REQUEST_METHOD'] = 'GET';
$request = id(new AphrontRequest($host, '/'))
->setApplicationConfiguration($application_configuration)
->setRequestData(array());
$controller = new PhabricatorTestController($request);
$u_public = id(new PhabricatorUser())
->setUsername('public');
$u_unverified = $this->generateNewTestUser()
->setUsername('unverified')
->save();
$u_unverified->setIsEmailVerified(0)->save();
$u_normal = $this->generateNewTestUser()
->setUsername('normal')
->save();
$u_disabled = $this->generateNewTestUser()
->setIsDisabled(true)
->setUsername('disabled')
->save();
$u_admin = $this->generateNewTestUser()
->setIsAdmin(true)
->setUsername('admin')
->save();
$u_notapproved = $this->generateNewTestUser()
->setIsApproved(0)
->setUsername('notapproved')
->save();
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('phabricator.base-uri', 'http://'.$host);
$env->overrideEnvConfig('policy.allow-public', false);
$env->overrideEnvConfig('auth.require-email-verification', false);
$env->overrideEnvConfig('auth.email-domains', array());
// Test standard defaults.
$this->checkAccess(
"Default",
id(clone $controller),
$request,
array(
$u_normal,
$u_admin,
$u_unverified,
),
array(
$u_public,
$u_disabled,
$u_notapproved,
));
// Test email verification.
$env->overrideEnvConfig('auth.require-email-verification', true);
$this->checkAccess(
"Email Verification Required",
id(clone $controller),
$request,
array(
$u_normal,
$u_admin,
),
array(
$u_unverified,
$u_public,
$u_disabled,
$u_notapproved,
));
$this->checkAccess(
"Email Verification Required, With Exception",
id(clone $controller)->setConfig('email', false),
$request,
array(
$u_normal,
$u_admin,
$u_unverified,
),
array(
$u_public,
$u_disabled,
$u_notapproved,
));
$env->overrideEnvConfig('auth.require-email-verification', false);
// Test admin access.
$this->checkAccess(
"Admin Required",
id(clone $controller)->setConfig('admin', true),
$request,
array(
$u_admin,
),
array(
$u_normal,
$u_unverified,
$u_public,
$u_disabled,
$u_notapproved,
));
// Test disabled access.
$this->checkAccess(
"Allow Disabled",
id(clone $controller)->setConfig('enabled', false),
$request,
array(
$u_normal,
$u_unverified,
$u_admin,
$u_disabled,
$u_notapproved,
),
array(
$u_public,
));
// Test no login required.
$this->checkAccess(
"No Login Required",
id(clone $controller)->setConfig('login', false),
$request,
array(
$u_normal,
$u_unverified,
$u_admin,
$u_public,
),
array(
$u_disabled,
$u_notapproved,
));
// Test public access.
$this->checkAccess(
"No Login Required",
id(clone $controller)->setConfig('public', true),
$request,
array(
$u_normal,
$u_unverified,
$u_admin,
),
array(
$u_disabled,
$u_public,
));
$env->overrideEnvConfig('policy.allow-public', true);
$this->checkAccess(
"Public + configured",
id(clone $controller)->setConfig('public', true),
$request,
array(
$u_normal,
$u_unverified,
$u_admin,
$u_public,
),
array(
$u_disabled,
$u_notapproved,
));
$env->overrideEnvConfig('policy.allow-public', false);
$app = PhabricatorApplication::getByClass('PhabricatorApplicationTest');
$app->reset();
$app->setPolicy(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicies::POLICY_NOONE);
$app_controller = id(clone $controller)->setCurrentApplication($app);
$this->checkAccess(
"Application Controller",
$app_controller,
$request,
array(
),
array(
$u_normal,
$u_unverified,
$u_admin,
$u_public,
$u_disabled,
$u_notapproved,
));
$this->checkAccess(
"Application Controller",
id(clone $app_controller)->setConfig('login', false),
$request,
array(
$u_normal,
$u_unverified,
$u_admin,
$u_public,
),
array(
$u_disabled,
$u_notapproved,
));
}
private function checkAccess(
$label,
$controller,
$request,
array $yes,
array $no) {
foreach ($yes as $user) {
$request->setUser($user);
$uname = $user->getUsername();
try {
$result = id(clone $controller)->willBeginExecution();
} catch (Exception $ex) {
$result = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($result === null),
"Expect user '{$uname}' to be allowed access to '{$label}'.");
}
foreach ($no as $user) {
$request->setUser($user);
$uname = $user->getUsername();
try {
$result = id(clone $controller)->willBeginExecution();
} catch (Exception $ex) {
$result = $ex;
}
- $this->assertEqual(
- false,
+ $this->assertFalse(
($result === null),
"Expect user '{$uname}' to be denied access to '{$label}'.");
}
}
}
diff --git a/src/applications/conduit/call/__tests__/ConduitCallTestCase.php b/src/applications/conduit/call/__tests__/ConduitCallTestCase.php
index 51bef15039..e33f7866fa 100644
--- a/src/applications/conduit/call/__tests__/ConduitCallTestCase.php
+++ b/src/applications/conduit/call/__tests__/ConduitCallTestCase.php
@@ -1,29 +1,28 @@
<?php
final class ConduitCallTestCase extends PhabricatorTestCase {
public function testConduitPing() {
$call = new ConduitCall('conduit.ping', array());
$call->setForceLocal(true);
$result = $call->execute();
- $this->assertEqual(false, empty($result));
+ $this->assertFalse(empty($result));
}
public function testConduitAuth() {
$call = new ConduitCall('user.whoami', array(), true);
$call->setForceLocal(true);
$caught = null;
try {
$result = $call->execute();
} catch (ConduitException $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($caught instanceof ConduitException),
"user.whoami should require authentication");
}
}
diff --git a/src/applications/diffusion/ssh/__tests__/DiffusionSSHMercurialWireTestCase.php b/src/applications/diffusion/ssh/__tests__/DiffusionSSHMercurialWireTestCase.php
index d1e8f8766c..89588d6ecb 100644
--- a/src/applications/diffusion/ssh/__tests__/DiffusionSSHMercurialWireTestCase.php
+++ b/src/applications/diffusion/ssh/__tests__/DiffusionSSHMercurialWireTestCase.php
@@ -1,58 +1,57 @@
<?php
final class DiffusionSSHMercurialWireTestCase
extends PhabricatorTestCase {
public function testMercurialClientWireProtocolParser() {
$data = dirname(__FILE__).'/hgwiredata/';
$dir = Filesystem::listDirectory($data, $include_hidden = false);
foreach ($dir as $file) {
$raw = Filesystem::readFile($data.$file);
$raw = explode("\n~~~~~~~~~~\n", $raw, 2);
$this->assertEqual(2, count($raw));
$expect = json_decode($raw[1], true);
- $this->assertEqual(true, is_array($expect), $file);
+ $this->assertTrue(is_array($expect), $file);
$this->assertParserResult($expect, $raw[0], $file);
}
}
private function assertParserResult(array $expect, $input, $file) {
list($x, $y) = PhutilSocketChannel::newChannelPair();
$xp = new DiffusionSSHMercurialWireClientProtocolChannel($x);
$y->write($input);
$y->flush();
$y->closeWriteChannel();
$messages = array();
for ($ii = 0; $ii < count($expect); $ii++) {
try {
$messages[] = $xp->waitForMessage();
} catch (Exception $ex) {
// This is probably the parser not producing as many messages as
// we expect. Log the exception, but continue to the assertion below
// since that will often be easier to diagnose.
phlog($ex);
break;
}
}
$this->assertEqual($expect, $messages, $file);
// Now, make sure the channel doesn't have *more* messages than we expect.
// Specifically, it should throw when we try to read another message.
$caught = null;
try {
$xp->waitForMessage();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($caught instanceof Exception),
"No extra messages for '{$file}'.");
}
}
diff --git a/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php b/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
index b9922ac2cb..eee9bbf949 100644
--- a/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
+++ b/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
@@ -1,254 +1,254 @@
<?php
/**
* @group file
*/
final class PhabricatorFileTestCase extends PhabricatorTestCase {
public function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testFileStorageReadWrite() {
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$params = array(
'name' => 'test.dat',
'storageEngines' => array(
$engine,
),
);
$file = PhabricatorFile::newFromFileData($data, $params);
// Test that the storage engine worked, and was the target of the write. We
// don't actually care what the data is (future changes may compress or
// encrypt it), just that it exists in the test storage engine.
$engine->readFile($file->getStorageHandle());
// Now test that we get the same data back out.
$this->assertEqual($data, $file->loadFileData());
}
public function testFileStorageUploadDifferentFiles() {
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$other_data = Filesystem::readRandomCharacters(64);
$params = array(
'name' => 'test.dat',
'storageEngines' => array(
$engine,
),
);
$first_file = PhabricatorFile::newFromFileData($data, $params);
$second_file = PhabricatorFile::newFromFileData($other_data, $params);
// Test that the the second file uses different storage handle from
// the first file.
$first_handle = $first_file->getStorageHandle();
$second_handle = $second_file->getStorageHandle();
- $this->assertEqual(true, ($first_handle != $second_handle));
+ $this->assertTrue($first_handle != $second_handle);
}
public function testFileStorageUploadSameFile() {
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$params = array(
'name' => 'test.dat',
'storageEngines' => array(
$engine,
),
);
$first_file = PhabricatorFile::newFromFileData($data, $params);
$second_file = PhabricatorFile::newFromFileData($data, $params);
// Test that the the second file uses the same storage handle as
// the first file.
$handle = $first_file->getStorageHandle();
$second_handle = $second_file->getStorageHandle();
$this->assertEqual($handle, $second_handle);
}
public function testFileStorageDelete() {
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$params = array(
'name' => 'test.dat',
'storageEngines' => array(
$engine,
),
);
$file = PhabricatorFile::newFromFileData($data, $params);
$handle = $file->getStorageHandle();
$file->delete();
$caught = null;
try {
$engine->readFile($handle);
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
}
public function testFileStorageDeleteSharedHandle() {
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$params = array(
'name' => 'test.dat',
'storageEngines' => array(
$engine,
),
);
$first_file = PhabricatorFile::newFromFileData($data, $params);
$second_file = PhabricatorFile::newFromFileData($data, $params);
$first_file->delete();
$this->assertEqual($data, $second_file->loadFileData());
}
public function testReadWriteTtlFiles() {
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$ttl = (time() + 60 * 60 * 24);
$params = array(
'name' => 'test.dat',
'ttl' => ($ttl),
'storageEngines' => array(
$engine,
),
);
$file = PhabricatorFile::newFromFileData($data, $params);
$this->assertEqual($ttl, $file->getTTL());
}
public function testFileTransformDelete() {
// We want to test that a file deletes all its inbound transformation
// records and outbound transformed derivatives when it is deleted.
// First, we create a chain of transforms, A -> B -> C.
$engine = new PhabricatorTestStorageEngine();
$params = array(
'name' => 'test.txt',
'storageEngines' => array(
$engine,
),
);
$a = PhabricatorFile::newFromFileData('a', $params);
$b = PhabricatorFile::newFromFileData('b', $params);
$c = PhabricatorFile::newFromFileData('c', $params);
id(new PhabricatorTransformedFile())
->setOriginalPHID($a->getPHID())
->setTransform('test:a->b')
->setTransformedPHID($b->getPHID())
->save();
id(new PhabricatorTransformedFile())
->setOriginalPHID($b->getPHID())
->setTransform('test:b->c')
->setTransformedPHID($c->getPHID())
->save();
// Now, verify that A -> B and B -> C exist.
$xform_a = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withTransforms(
array(
array(
'originalPHID' => $a->getPHID(),
'transform' => true,
),
))
->execute();
$this->assertEqual(1, count($xform_a));
$this->assertEqual($b->getPHID(), head($xform_a)->getPHID());
$xform_b = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withTransforms(
array(
array(
'originalPHID' => $b->getPHID(),
'transform' => true,
),
))
->execute();
$this->assertEqual(1, count($xform_b));
$this->assertEqual($c->getPHID(), head($xform_b)->getPHID());
// Delete "B".
$b->delete();
// Now, verify that the A -> B and B -> C links are gone.
$xform_a = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withTransforms(
array(
array(
'originalPHID' => $a->getPHID(),
'transform' => true,
),
))
->execute();
$this->assertEqual(0, count($xform_a));
$xform_b = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withTransforms(
array(
array(
'originalPHID' => $b->getPHID(),
'transform' => true,
),
))
->execute();
$this->assertEqual(0, count($xform_b));
// Also verify that C has been deleted.
$alternate_c = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs(array($c->getPHID()))
->execute();
$this->assertEqual(array(), $alternate_c);
}
}
diff --git a/src/applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php b/src/applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php
index 53a5a5d459..ff7647bc17 100644
--- a/src/applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php
+++ b/src/applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php
@@ -1,42 +1,40 @@
<?php
final class PhabricatorMailReceiverTestCase extends PhabricatorTestCase {
public function testAddressSimilarity() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('metamta.single-reply-handler-prefix', 'prefix');
$base = 'alincoln@example.com';
$same = array(
'alincoln@example.com',
'"Abrahamn Lincoln" <alincoln@example.com>',
'ALincoln@example.com',
'prefix+alincoln@example.com',
);
foreach ($same as $address) {
- $this->assertEqual(
- true,
+ $this->assertTrue(
PhabricatorMailReceiver::matchAddresses($base, $address),
"Address {$address}");
}
$diff = array(
'a.lincoln@example.com',
'aluncoln@example.com',
'prefixalincoln@example.com',
'badprefix+alincoln@example.com',
'bad+prefix+alincoln@example.com',
'prefix+alincoln+sufffix@example.com',
);
foreach ($diff as $address) {
- $this->assertEqual(
- false,
+ $this->assertFalse(
PhabricatorMailReceiver::matchAddresses($base, $address),
"Address: {$address}");
}
}
}
diff --git a/src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php b/src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
index a9dc9069d4..a64b302c1a 100644
--- a/src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
+++ b/src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
@@ -1,187 +1,179 @@
<?php
final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testMailSendFailures() {
$user = $this->generateNewTestUser();
$phid = $user->getPHID();
// Normally, the send should succeed.
$mail = new PhabricatorMetaMTAMail();
$mail->addTos(array($phid));
$mailer = new PhabricatorMailImplementationTestAdapter();
$mail->sendNow($force = true, $mailer);
$this->assertEqual(
PhabricatorMetaMTAMail::STATUS_SENT,
$mail->getStatus());
// When the mailer fails temporarily, the mail should remain queued.
$mail = new PhabricatorMetaMTAMail();
$mail->addTos(array($phid));
$mailer = new PhabricatorMailImplementationTestAdapter();
$mailer->setFailTemporarily(true);
$mail->sendNow($force = true, $mailer);
$this->assertEqual(
PhabricatorMetaMTAMail::STATUS_QUEUE,
$mail->getStatus());
// When the mailer fails permanently, the mail should be failed.
$mail = new PhabricatorMetaMTAMail();
$mail->addTos(array($phid));
$mailer = new PhabricatorMailImplementationTestAdapter();
$mailer->setFailPermanently(true);
$mail->sendNow($force = true, $mailer);
$this->assertEqual(
PhabricatorMetaMTAMail::STATUS_FAIL,
$mail->getStatus());
}
public function testRecipients() {
$user = $this->generateNewTestUser();
$phid = $user->getPHID();
$prefs = $user->loadPreferences();
$mailer = new PhabricatorMailImplementationTestAdapter();
$mail = new PhabricatorMetaMTAMail();
$mail->addTos(array($phid));
- $this->assertEqual(
- true,
+ $this->assertTrue(
in_array($phid, $mail->buildRecipientList()),
'"To" is a recipient.');
// Test that the "No Self Mail" preference works correctly.
$mail->setFrom($phid);
- $this->assertEqual(
- true,
+ $this->assertTrue(
in_array($phid, $mail->buildRecipientList()),
'"From" does not exclude recipients by default.');
$prefs->setPreference(
PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL,
true);
$prefs->save();
- $this->assertEqual(
- false,
+ $this->assertFalse(
in_array($phid, $mail->buildRecipientList()),
'"From" excludes recipients with no-self-mail set.');
$prefs->unsetPreference(
PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL);
$prefs->save();
- $this->assertEqual(
- true,
+ $this->assertTrue(
in_array($phid, $mail->buildRecipientList()),
'"From" does not exclude recipients by default.');
// Test that explicit exclusion works correctly.
$mail->setExcludeMailRecipientPHIDs(array($phid));
- $this->assertEqual(
- false,
+ $this->assertFalse(
in_array($phid, $mail->buildRecipientList()),
'Explicit exclude excludes recipients.');
$mail->setExcludeMailRecipientPHIDs(array());
// Test that mail tag preferences exclude recipients.
$prefs->setPreference(
PhabricatorUserPreferences::PREFERENCE_MAILTAGS,
array(
'test-tag' => false,
));
$prefs->save();
$mail->setMailTags(array('test-tag'));
- $this->assertEqual(
- false,
+ $this->assertFalse(
in_array($phid, $mail->buildRecipientList()),
'Tag preference excludes recipients.');
$prefs->unsetPreference(PhabricatorUserPreferences::PREFERENCE_MAILTAGS);
$prefs->save();
- $this->assertEqual(
- true,
+ $this->assertTrue(
in_array($phid, $mail->buildRecipientList()),
'Recipients restored after tag preference removed.');
}
public function testThreadIDHeaders() {
$this->runThreadIDHeadersWithConfiguration(true, true);
$this->runThreadIDHeadersWithConfiguration(true, false);
$this->runThreadIDHeadersWithConfiguration(false, true);
$this->runThreadIDHeadersWithConfiguration(false, false);
}
private function runThreadIDHeadersWithConfiguration(
$supports_message_id,
$is_first_mail) {
$mailer = new PhabricatorMailImplementationTestAdapter(
array(
'supportsMessageIDHeader' => $supports_message_id,
));
$thread_id = '<somethread-12345@somedomain.tld>';
$mail = new PhabricatorMetaMTAMail();
$mail->setThreadID($thread_id, $is_first_mail);
$mail->sendNow($force = true, $mailer);
$guts = $mailer->getGuts();
$dict = ipull($guts['headers'], 1, 0);
if ($is_first_mail && $supports_message_id) {
$expect_message_id = true;
$expect_in_reply_to = false;
$expect_references = false;
} else {
$expect_message_id = false;
$expect_in_reply_to = true;
$expect_references = true;
}
$case = "<message-id = ".($supports_message_id ? 'Y' : 'N').", ".
"first = ".($is_first_mail ? 'Y' : 'N').">";
- $this->assertEqual(
- true,
+ $this->assertTrue(
isset($dict['Thread-Index']),
"Expect Thread-Index header for case {$case}.");
$this->assertEqual(
$expect_message_id,
isset($dict['Message-ID']),
"Expectation about existence of Message-ID header for case {$case}.");
$this->assertEqual(
$expect_in_reply_to,
isset($dict['In-Reply-To']),
"Expectation about existence of In-Reply-To header for case {$case}.");
$this->assertEqual(
$expect_references,
isset($dict['References']),
"Expectation about existence of References header for case {$case}.");
}
}
diff --git a/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php b/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php
index ec5e699aa0..cbd2a938ed 100644
--- a/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php
+++ b/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php
@@ -1,70 +1,70 @@
<?php
final class PhabricatorUserEditorTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => 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);
+ $this->assertTrue(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));
+ $this->assertTrue($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));
+ $this->assertTrue($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/applications/phid/query/__tests__/PhabricatorObjectListQueryTestCase.php b/src/applications/phid/query/__tests__/PhabricatorObjectListQueryTestCase.php
index 5d0cdb968c..419e47672c 100644
--- a/src/applications/phid/query/__tests__/PhabricatorObjectListQueryTestCase.php
+++ b/src/applications/phid/query/__tests__/PhabricatorObjectListQueryTestCase.php
@@ -1,87 +1,87 @@
<?php
final class PhabricatorObjectListQueryTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testObjectListQuery() {
$user = $this->generateNewTestUser();
$name = $user->getUsername();
$phid = $user->getPHID();
$result = $this->parseObjectList("@{$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList("{$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList("{$name}, {$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList("@{$name}, {$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList("");
$this->assertEqual(array(), $result);
// Expect failure when loading a user if objects must be of type "DUCK".
$caught = null;
try {
$result = $this->parseObjectList("{$name}", array("DUCK"));
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, ($caught instanceof Exception));
+ $this->assertTrue($caught instanceof Exception);
// Expect failure when loading an invalid object.
$caught = null;
try {
$result = $this->parseObjectList("invalid");
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, ($caught instanceof Exception));
+ $this->assertTrue($caught instanceof Exception);
// Expect failure when loading ANY invalid object, by default.
$caught = null;
try {
$result = $this->parseObjectList("{$name}, invalid");
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, ($caught instanceof Exception));
+ $this->assertTrue($caught instanceof Exception);
// With partial results, this should load the valid user.
$result = $this->parseObjectList("{$name}, invalid", array(), true);
$this->assertEqual(array($phid), $result);
}
private function parseObjectList(
$list,
array $types = array(),
$allow_partial = false) {
$query = id(new PhabricatorObjectListQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setObjectList($list);
if ($types) {
$query->setAllowedTypes($types);
}
if ($allow_partial) {
$query->setAllowPartialResults(true);
}
return $query->execute();
}
}
diff --git a/src/applications/phortune/currency/__tests__/PhortuneCurrencyTestCase.php b/src/applications/phortune/currency/__tests__/PhortuneCurrencyTestCase.php
index d52f5e0e78..b9a3127f93 100644
--- a/src/applications/phortune/currency/__tests__/PhortuneCurrencyTestCase.php
+++ b/src/applications/phortune/currency/__tests__/PhortuneCurrencyTestCase.php
@@ -1,93 +1,93 @@
<?php
final class PhortuneCurrencyTestCase extends PhabricatorTestCase {
public function testCurrencyFormatForDisplay() {
$map = array(
0 => '$0.00 USD',
1 => '$0.01 USD',
100 => '$1.00 USD',
-123 => '$-1.23 USD',
5000000 => '$50000.00 USD',
);
foreach ($map as $input => $expect) {
$this->assertEqual(
$expect,
PhortuneCurrency::newFromUSDCents($input)->formatForDisplay(),
"formatForDisplay({$input})");
}
}
public function testCurrencyFormatBareValue() {
// NOTE: The PayPal API depends on the behavior of the bare value format!
$map = array(
0 => '0.00',
1 => '0.01',
100 => '1.00',
-123 => '-1.23',
5000000 => '50000.00',
);
foreach ($map as $input => $expect) {
$this->assertEqual(
$expect,
PhortuneCurrency::newFromUSDCents($input)->formatBareValue(),
"formatBareValue({$input})");
}
}
public function testCurrencyFromUserInput() {
$map = array(
'1.00' => 100,
'1.00 USD' => 100,
'$1.00' => 100,
'$1.00 USD' => 100,
'-$1.00 USD' => -100,
'$-1.00 USD' => -100,
'1' => 100,
'.99' => 99,
'$.99' => 99,
'-$.99' => -99,
'$-.99' => -99,
'$.99 USD' => 99,
);
$user = new PhabricatorUser();
foreach ($map as $input => $expect) {
$this->assertEqual(
$expect,
PhortuneCurrency::newFromUserInput($user, $input)->getValue(),
"newFromUserInput({$input})->getValue()");
}
}
public function testInvalidCurrencyFromUserInput() {
$map = array(
'--1',
'$$1',
'1 JPY',
'buck fiddy',
'1.2.3',
'1 dollar',
);
$user = new PhabricatorUser();
foreach ($map as $input) {
$caught = null;
try {
PhortuneCurrency::newFromUserInput($user, $input);
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, ($caught instanceof Exception), "{$input}");
+ $this->assertTrue($caught instanceof Exception, "{$input}");
}
}
}
diff --git a/src/applications/phortune/provider/__tests__/PhortunePaymentProviderTestCase.php b/src/applications/phortune/provider/__tests__/PhortunePaymentProviderTestCase.php
index 5b8d061825..cc5324d114 100644
--- a/src/applications/phortune/provider/__tests__/PhortunePaymentProviderTestCase.php
+++ b/src/applications/phortune/provider/__tests__/PhortunePaymentProviderTestCase.php
@@ -1,53 +1,51 @@
<?php
final class PhortunePaymentProviderTestCase extends PhabricatorTestCase {
public function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testNoPaymentProvider() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('phortune.test.enabled', true);
$method = id(new PhortunePaymentMethod())
->setMetadataValue('type', 'hugs');
$caught = null;
try {
$provider = $method->buildPaymentProvider();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($caught instanceof PhortuneNoPaymentProviderException),
'No provider should accept hugs; they are not a currency.');
}
public function testMultiplePaymentProviders() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('phortune.test.enabled', true);
$method = id(new PhortunePaymentMethod())
->setMetadataValue('type', 'test.multiple');
$caught = null;
try {
$provider = $method->buildPaymentProvider();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($caught instanceof PhortuneMultiplePaymentProvidersException),
'Expect exception when more than one provider handles a payment method.');
}
}
diff --git a/src/applications/phriction/storage/__tests__/PhrictionDocumentTestCase.php b/src/applications/phriction/storage/__tests__/PhrictionDocumentTestCase.php
index bca9507284..1d1c22c77f 100644
--- a/src/applications/phriction/storage/__tests__/PhrictionDocumentTestCase.php
+++ b/src/applications/phriction/storage/__tests__/PhrictionDocumentTestCase.php
@@ -1,51 +1,51 @@
<?php
/**
* @group phriction
*/
final class PhrictionDocumentTestCase extends PhabricatorTestCase {
public function testProjectSlugs() {
$slugs = array(
'/' => false,
'zebra/' => false,
'projects/' => false,
'projects/a/' => true,
'projects/a/b/' => true,
'stuff/projects/a/' => false,
);
foreach ($slugs as $slug => $expect) {
$this->assertEqual(
$expect,
PhrictionDocument::isProjectSlug($slug),
"Is '{$slug}' a project slug?");
}
}
public function testProjectSlugIdentifiers() {
$slugs = array(
'projects/' => null,
'derp/' => null,
'projects/a/' => 'a/',
'projects/a/b/' => 'a/',
);
foreach ($slugs as $slug => $expect) {
$ex = null;
$result = null;
try {
$result = PhrictionDocument::getProjectSlugIdentifier($slug);
} catch (Exception $e) {
$ex = $e;
}
if ($expect === null) {
- $this->assertEqual(true, (bool)$ex, "Slug '{$slug}' is invalid.");
+ $this->assertTrue((bool)$ex, "Slug '{$slug}' is invalid.");
} else {
$this->assertEqual($expect, $result, "Slug '{$slug}' identifier.");
}
}
}
}
diff --git a/src/applications/policy/__tests__/PhabricatorPolicyDataTestCase.php b/src/applications/policy/__tests__/PhabricatorPolicyDataTestCase.php
index 145cbe1f90..89b303b0d9 100644
--- a/src/applications/policy/__tests__/PhabricatorPolicyDataTestCase.php
+++ b/src/applications/policy/__tests__/PhabricatorPolicyDataTestCase.php
@@ -1,147 +1,147 @@
<?php
final class PhabricatorPolicyDataTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testProjectPolicyMembership() {
$author = $this->generateNewTestUser();
$proj_a = id(new PhabricatorProject())
->setName('A')
->setAuthorPHID($author->getPHID())
->save();
$proj_b = id(new PhabricatorProject())
->setName('B')
->setAuthorPHID($author->getPHID())
->save();
$proj_a->setViewPolicy($proj_b->getPHID())->save();
$proj_b->setViewPolicy($proj_a->getPHID())->save();
$user = new PhabricatorUser();
$results = id(new PhabricatorProjectQuery())
->setViewer($user)
->execute();
$this->assertEqual(0, count($results));
}
public function testCustomPolicyRuleUser() {
$user_a = $this->generateNewTestUser();
$user_b = $this->generateNewTestUser();
$author = $this->generateNewTestUser();
$policy = id(new PhabricatorPolicy())
->setRules(
array(
array(
'action' => PhabricatorPolicy::ACTION_ALLOW,
'rule' => 'PhabricatorPolicyRuleUsers',
'value' => array($user_a->getPHID()),
),
))
->save();
$task = ManiphestTask::initializeNewTask($author);
$task->setViewPolicy($policy->getPHID());
$task->save();
$can_a_view = PhabricatorPolicyFilter::hasCapability(
$user_a,
$task,
PhabricatorPolicyCapability::CAN_VIEW);
- $this->assertEqual(true, $can_a_view);
+ $this->assertTrue($can_a_view);
$can_b_view = PhabricatorPolicyFilter::hasCapability(
$user_b,
$task,
PhabricatorPolicyCapability::CAN_VIEW);
- $this->assertEqual(false, $can_b_view);
+ $this->assertFalse($can_b_view);
}
public function testCustomPolicyRuleAdministrators() {
$user_a = $this->generateNewTestUser();
$user_a->setIsAdmin(true)->save();
$user_b = $this->generateNewTestUser();
$author = $this->generateNewTestUser();
$policy = id(new PhabricatorPolicy())
->setRules(
array(
array(
'action' => PhabricatorPolicy::ACTION_ALLOW,
'rule' => 'PhabricatorPolicyRuleAdministrators',
'value' => null,
),
))
->save();
$task = ManiphestTask::initializeNewTask($author);
$task->setViewPolicy($policy->getPHID());
$task->save();
$can_a_view = PhabricatorPolicyFilter::hasCapability(
$user_a,
$task,
PhabricatorPolicyCapability::CAN_VIEW);
- $this->assertEqual(true, $can_a_view);
+ $this->assertTrue($can_a_view);
$can_b_view = PhabricatorPolicyFilter::hasCapability(
$user_b,
$task,
PhabricatorPolicyCapability::CAN_VIEW);
- $this->assertEqual(false, $can_b_view);
+ $this->assertFalse($can_b_view);
}
public function testCustomPolicyRuleLunarPhase() {
$user_a = $this->generateNewTestUser();
$author = $this->generateNewTestUser();
$policy = id(new PhabricatorPolicy())
->setRules(
array(
array(
'action' => PhabricatorPolicy::ACTION_ALLOW,
'rule' => 'PhabricatorPolicyRuleLunarPhase',
'value' => 'new',
),
))
->save();
$task = ManiphestTask::initializeNewTask($author);
$task->setViewPolicy($policy->getPHID());
$task->save();
$time_a = PhabricatorTime::pushTime(934354800, 'UTC');
$can_a_view = PhabricatorPolicyFilter::hasCapability(
$user_a,
$task,
PhabricatorPolicyCapability::CAN_VIEW);
- $this->assertEqual(true, $can_a_view);
+ $this->assertTrue($can_a_view);
unset($time_a);
$time_b = PhabricatorTime::pushTime(1116745200, 'UTC');
$can_a_view = PhabricatorPolicyFilter::hasCapability(
$user_a,
$task,
PhabricatorPolicyCapability::CAN_VIEW);
- $this->assertEqual(false, $can_a_view);
+ $this->assertFalse($can_a_view);
unset($time_b);
}
}
diff --git a/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php b/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php
index 860ca52f69..d54ca73651 100644
--- a/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php
+++ b/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php
@@ -1,337 +1,335 @@
<?php
final class PhabricatorPolicyTestCase extends PhabricatorTestCase {
/**
* Verify that any user can view an object with POLICY_PUBLIC.
*/
public function testPublicPolicyEnabled() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('policy.allow-public', true);
$this->expectVisibility(
$this->buildObject(PhabricatorPolicies::POLICY_PUBLIC),
array(
'public' => true,
'user' => true,
'admin' => true,
),
'Public Policy (Enabled in Config)');
}
/**
* Verify that POLICY_PUBLIC is interpreted as POLICY_USER when public
* policies are disallowed.
*/
public function testPublicPolicyDisabled() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('policy.allow-public', false);
$this->expectVisibility(
$this->buildObject(PhabricatorPolicies::POLICY_PUBLIC),
array(
'public' => false,
'user' => true,
'admin' => true,
),
'Public Policy (Disabled in Config)');
}
/**
* Verify that any logged-in user can view an object with POLICY_USER, but
* logged-out users can not.
*/
public function testUsersPolicy() {
$this->expectVisibility(
$this->buildObject(PhabricatorPolicies::POLICY_USER),
array(
'public' => false,
'user' => true,
'admin' => true,
),
'User Policy');
}
/**
* Verify that only administrators can view an object with POLICY_ADMIN.
*/
public function testAdminPolicy() {
$this->expectVisibility(
$this->buildObject(PhabricatorPolicies::POLICY_ADMIN),
array(
'public' => false,
'user' => false,
'admin' => true,
),
'Admin Policy');
}
/**
* Verify that no one can view an object with POLICY_NOONE.
*/
public function testNoOnePolicy() {
$this->expectVisibility(
$this->buildObject(PhabricatorPolicies::POLICY_NOONE),
array(
'public' => false,
'user' => false,
'admin' => false,
),
'No One Policy');
}
/**
* Test offset-based filtering.
*/
public function testOffsets() {
$results = array(
$this->buildObject(PhabricatorPolicies::POLICY_NOONE),
$this->buildObject(PhabricatorPolicies::POLICY_NOONE),
$this->buildObject(PhabricatorPolicies::POLICY_NOONE),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
);
$query = new PhabricatorPolicyAwareTestQuery();
$query->setResults($results);
$query->setViewer($this->buildUser('user'));
$this->assertEqual(
3,
count($query->setLimit(3)->setOffset(0)->execute()),
'Invisible objects are ignored.');
$this->assertEqual(
0,
count($query->setLimit(3)->setOffset(3)->execute()),
'Offset pages through visible objects only.');
$this->assertEqual(
2,
count($query->setLimit(3)->setOffset(1)->execute()),
'Offsets work correctly.');
$this->assertEqual(
2,
count($query->setLimit(0)->setOffset(1)->execute()),
'Offset with no limit works.');
}
/**
* Test limits.
*/
public function testLimits() {
$results = array(
$this->buildObject(PhabricatorPolicies::POLICY_USER),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
$this->buildObject(PhabricatorPolicies::POLICY_USER),
);
$query = new PhabricatorPolicyAwareTestQuery();
$query->setResults($results);
$query->setViewer($this->buildUser('user'));
$this->assertEqual(
3,
count($query->setLimit(3)->setOffset(0)->execute()),
'Limits work.');
$this->assertEqual(
2,
count($query->setLimit(3)->setOffset(4)->execute()),
'Limit + offset work.');
}
/**
* Test that omnipotent users bypass policies.
*/
public function testOmnipotence() {
$results = array(
$this->buildObject(PhabricatorPolicies::POLICY_NOONE),
);
$query = new PhabricatorPolicyAwareTestQuery();
$query->setResults($results);
$query->setViewer(PhabricatorUser::getOmnipotentUser());
$this->assertEqual(
1,
count($query->execute()));
}
/**
* Test that invalid policies reject viewers of all types.
*/
public function testRejectInvalidPolicy() {
$invalid_policy = "the duck goes quack";
$object = $this->buildObject($invalid_policy);
$this->expectVisibility(
$object = $this->buildObject($invalid_policy),
array(
'public' => false,
'user' => false,
'admin' => false,
),
'Invalid Policy');
}
/**
* An omnipotent user should be able to see even objects with invalid
* policies.
*/
public function testInvalidPolicyVisibleByOmnipotentUser() {
$invalid_policy = "the cow goes moo";
$object = $this->buildObject($invalid_policy);
$results = array(
$object,
);
$query = new PhabricatorPolicyAwareTestQuery();
$query->setResults($results);
$query->setViewer(PhabricatorUser::getOmnipotentUser());
$this->assertEqual(
1,
count($query->execute()));
}
public function testAllQueriesBelongToActualApplications() {
$queries = id(new PhutilSymbolLoader())
->setAncestorClass('PhabricatorPolicyAwareQuery')
->loadObjects();
foreach ($queries as $qclass => $query) {
$class = $query->getQueryApplicationClass();
if (!$class) {
continue;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
(bool)PhabricatorApplication::getByClass($class),
"Application class '{$class}' for query '{$qclass}'");
}
}
public function testMultipleCapabilities() {
$object = new PhabricatorPolicyTestObject();
$object->setCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
));
$object->setPolicies(
array(
PhabricatorPolicyCapability::CAN_VIEW
=> PhabricatorPolicies::POLICY_USER,
PhabricatorPolicyCapability::CAN_EDIT
=> PhabricatorPolicies::POLICY_NOONE,
));
$filter = new PhabricatorPolicyFilter();
$filter->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
));
$filter->setViewer($this->buildUser('user'));
$result = $filter->apply(array($object));
$this->assertEqual(array(), $result);
}
/**
* Test an object for visibility across multiple user specifications.
*/
private function expectVisibility(
PhabricatorPolicyTestObject $object,
array $map,
$description) {
foreach ($map as $spec => $expect) {
$viewer = $this->buildUser($spec);
$query = new PhabricatorPolicyAwareTestQuery();
$query->setResults(array($object));
$query->setViewer($viewer);
$caught = null;
try {
$result = $query->executeOne();
} catch (PhabricatorPolicyException $ex) {
$caught = $ex;
}
if ($expect) {
$this->assertEqual(
$object,
$result,
"{$description} with user {$spec} should succeed.");
} else {
- $this->assertEqual(
- true,
+ $this->assertTrue(
$caught instanceof PhabricatorPolicyException,
"{$description} with user {$spec} should fail.");
}
}
}
/**
* Build a test object to spec.
*/
private function buildObject($policy) {
$object = new PhabricatorPolicyTestObject();
$object->setCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
));
$object->setPolicies(
array(
PhabricatorPolicyCapability::CAN_VIEW => $policy,
));
return $object;
}
/**
* Build a test user to spec.
*/
private function buildUser($spec) {
$user = new PhabricatorUser();
switch ($spec) {
case 'public':
break;
case 'user':
$user->setPHID(1);
break;
case 'admin':
$user->setPHID(1);
$user->setIsAdmin(true);
break;
default:
throw new Exception("Unknown user spec '{$spec}'.");
}
return $user;
}
}
diff --git a/src/applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php b/src/applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php
index 3e88fe8e91..13f9527cd9 100644
--- a/src/applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php
+++ b/src/applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php
@@ -1,311 +1,292 @@
<?php
final class PhabricatorProjectEditorTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testViewProject() {
$user = $this->createUser();
$user->save();
$user2 = $this->createUser();
$user2->save();
$proj = $this->createProject();
$proj->setAuthorPHID($user->getPHID());
$proj->save();
$proj = $this->refreshProject($proj, $user, true);
$this->joinProject($proj, $user);
$proj->setViewPolicy(PhabricatorPolicies::POLICY_USER);
$proj->save();
$can_view = PhabricatorPolicyCapability::CAN_VIEW;
// When the view policy is set to "users", any user can see the project.
- $this->assertEqual(
- true,
- (bool)$this->refreshProject($proj, $user));
- $this->assertEqual(
- true,
- (bool)$this->refreshProject($proj, $user2));
+ $this->assertTrue((bool)$this->refreshProject($proj, $user));
+ $this->assertTrue((bool)$this->refreshProject($proj, $user2));
// When the view policy is set to "no one", members can still see the
// project.
$proj->setViewPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->save();
- $this->assertEqual(
- true,
- (bool)$this->refreshProject($proj, $user));
- $this->assertEqual(
- false,
- (bool)$this->refreshProject($proj, $user2));
+ $this->assertTrue((bool)$this->refreshProject($proj, $user));
+ $this->assertFalse((bool)$this->refreshProject($proj, $user2));
}
public function testEditProject() {
$user = $this->createUser();
$user->save();
$user2 = $this->createUser();
$user2->save();
$proj = $this->createProject();
$proj->setAuthorPHID($user->getPHID());
$proj->save();
// When edit and view policies are set to "user", anyone can edit.
$proj->setViewPolicy(PhabricatorPolicies::POLICY_USER);
$proj->setEditPolicy(PhabricatorPolicies::POLICY_USER);
$proj->save();
- $this->assertEqual(
- true,
- $this->attemptProjectEdit($proj, $user));
+ $this->assertTrue($this->attemptProjectEdit($proj, $user));
// When edit policy is set to "no one", no one can edit.
$proj->setEditPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->save();
$caught = null;
try {
$this->attemptProjectEdit($proj, $user);
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, ($caught instanceof Exception));
+ $this->assertTrue($caught instanceof Exception);
}
private function attemptProjectEdit(
PhabricatorProject $proj,
PhabricatorUser $user,
$skip_refresh = false) {
$proj = $this->refreshProject($proj, $user, true);
$new_name = $proj->getName().' '.mt_rand();
$xaction = new PhabricatorProjectTransaction();
$xaction->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME);
$xaction->setNewValue($new_name);
$editor = new PhabricatorProjectTransactionEditor();
$editor->setActor($user);
$editor->setContentSource(PhabricatorContentSource::newConsoleSource());
$editor->applyTransactions($proj, array($xaction));
return true;
}
public function testJoinLeaveProject() {
$user = $this->createUser();
$user->save();
$proj = $this->createProjectWithNewAuthor();
$proj->save();
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(
- true,
+ $this->assertTrue(
(bool)$proj,
'Assumption that projects are default visible to any user when created.');
- $this->assertEqual(
- false,
+ $this->assertFalse(
$proj->isUserMember($user->getPHID()),
'Arbitrary user not member of project.');
// Join the project.
$this->joinProject($proj, $user);
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(true, (bool)$proj);
+ $this->assertTrue((bool)$proj);
- $this->assertEqual(
- true,
+ $this->assertTrue(
$proj->isUserMember($user->getPHID()),
'Join works.');
// Join the project again.
$this->joinProject($proj, $user);
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(true, (bool)$proj);
+ $this->assertTrue((bool)$proj);
- $this->assertEqual(
- true,
+ $this->assertTrue(
$proj->isUserMember($user->getPHID()),
'Joining an already-joined project is a no-op.');
// Leave the project.
$this->leaveProject($proj, $user);
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(true, (bool)$proj);
+ $this->assertTrue((bool)$proj);
- $this->assertEqual(
- false,
+ $this->assertFalse(
$proj->isUserMember($user->getPHID()),
'Leave works.');
// Leave the project again.
$this->leaveProject($proj, $user);
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(true, (bool)$proj);
+ $this->assertTrue((bool)$proj);
- $this->assertEqual(
- false,
+ $this->assertFalse(
$proj->isUserMember($user->getPHID()),
'Leaving an already-left project is a no-op.');
// If a user can't edit or join a project, joining fails.
$proj->setEditPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->setJoinPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->save();
$proj = $this->refreshProject($proj, $user, true);
$caught = null;
try {
$this->joinProject($proj, $user);
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, ($ex instanceof Exception));
+ $this->assertTrue($ex instanceof Exception);
// If a user can edit a project, they can join.
$proj->setEditPolicy(PhabricatorPolicies::POLICY_USER);
$proj->setJoinPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->save();
$proj = $this->refreshProject($proj, $user, true);
$this->joinProject($proj, $user);
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(
- true,
+ $this->assertTrue(
$proj->isUserMember($user->getPHID()),
'Join allowed with edit permission.');
$this->leaveProject($proj, $user);
// If a user can join a project, they can join, even if they can't edit.
$proj->setEditPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->setJoinPolicy(PhabricatorPolicies::POLICY_USER);
$proj->save();
$proj = $this->refreshProject($proj, $user, true);
$this->joinProject($proj, $user);
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(
- true,
+ $this->assertTrue(
$proj->isUserMember($user->getPHID()),
'Join allowed with join permission.');
// A user can leave a project even if they can't edit it or join.
$proj->setEditPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->setJoinPolicy(PhabricatorPolicies::POLICY_NOONE);
$proj->save();
$proj = $this->refreshProject($proj, $user, true);
$this->leaveProject($proj, $user);
$proj = $this->refreshProject($proj, $user, true);
- $this->assertEqual(
- false,
+ $this->assertFalse(
$proj->isUserMember($user->getPHID()),
'Leave allowed without any permission.');
}
private function refreshProject(
PhabricatorProject $project,
PhabricatorUser $viewer,
$need_members = false) {
$results = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->needMembers($need_members)
->withIDs(array($project->getID()))
->execute();
if ($results) {
return head($results);
} else {
return null;
}
}
private function createProject() {
$project = new PhabricatorProject();
$project->setName('Test Project '.mt_rand());
return $project;
}
private function createProjectWithNewAuthor() {
$author = $this->createUser();
$author->save();
$project = $this->createProject();
$project->setAuthorPHID($author->getPHID());
return $project;
}
private function createUser() {
$rand = mt_rand();
$user = new PhabricatorUser();
$user->setUsername('unittestuser'.$rand);
$user->setRealName('Unit Test User '.$rand);
return $user;
}
private function joinProject(
PhabricatorProject $project,
PhabricatorUser $user) {
$this->joinOrLeaveProject($project, $user, '+');
}
private function leaveProject(
PhabricatorProject $project,
PhabricatorUser $user) {
$this->joinOrLeaveProject($project, $user, '-');
}
private function joinOrLeaveProject(
PhabricatorProject $project,
PhabricatorUser $user,
$operation) {
$spec = array(
$operation => array($user->getPHID() => $user->getPHID()),
);
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
->setNewValue($spec);
$editor = id(new PhabricatorProjectTransactionEditor())
->setActor($user)
->setContentSource(PhabricatorContentSource::newConsoleSource())
->setContinueOnNoEffect(true)
->applyTransactions($project, $xactions);
}
}
diff --git a/src/applications/repository/engine/__tests__/PhabricatorWorkingCopyPullTestCase.php b/src/applications/repository/engine/__tests__/PhabricatorWorkingCopyPullTestCase.php
index ac3ce297a3..58a6590871 100644
--- a/src/applications/repository/engine/__tests__/PhabricatorWorkingCopyPullTestCase.php
+++ b/src/applications/repository/engine/__tests__/PhabricatorWorkingCopyPullTestCase.php
@@ -1,32 +1,26 @@
<?php
final class PhabricatorWorkingCopyPullTestCase
extends PhabricatorWorkingCopyTestCase {
public function testGitPullBasic() {
$repo = $this->buildPulledRepository('GT');
- $this->assertEqual(
- true,
- Filesystem::pathExists($repo->getLocalPath().'/HEAD'));
+ $this->assertTrue(Filesystem::pathExists($repo->getLocalPath().'/HEAD'));
}
public function testHgPullBasic() {
$repo = $this->buildPulledRepository('HT');
- $this->assertEqual(
- true,
- Filesystem::pathExists($repo->getLocalPath().'/.hg'));
+ $this->assertTrue(Filesystem::pathExists($repo->getLocalPath().'/.hg'));
}
public function testSVNPullBasic() {
$repo = $this->buildPulledRepository('ST');
// We don't pull local clones for SVN, so we don't expect there to be
// a working copy.
- $this->assertEqual(
- false,
- Filesystem::pathExists($repo->getLocalPath()));
+ $this->assertFalse(Filesystem::pathExists($repo->getLocalPath()));
}
}
diff --git a/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php b/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php
index 5b60b2968e..2ab824abfa 100644
--- a/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php
+++ b/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php
@@ -1,158 +1,155 @@
<?php
final class PhabricatorRepositoryTestCase
extends PhabricatorTestCase {
public function testRepositoryURIProtocols() {
$tests = array(
'/path/to/repo' => 'file',
'file:///path/to/repo' => 'file',
'ssh://user@domain.com/path' => 'ssh',
'git@example.com:path' => 'ssh',
'git://git@example.com/path' => 'git',
'svn+ssh://example.com/path' => 'svn+ssh',
'https://example.com/repo/' => 'https',
'http://example.com/' => 'http',
'https://user@example.com/' => 'https',
);
foreach ($tests as $uri => $expect) {
$repository = new PhabricatorRepository();
$repository->setDetail('remote-uri', $uri);
$this->assertEqual(
$expect,
$repository->getRemoteProtocol(),
"Protocol for '{$uri}'.");
}
}
public function testBranchFilter() {
$git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;
$repo = new PhabricatorRepository();
$repo->setVersionControlSystem($git);
- $this->assertEqual(
- true,
+ $this->assertTrue(
$repo->shouldTrackBranch('imaginary'),
'Track all branches by default.');
$repo->setDetail(
'branch-filter',
array(
'master' => true,
));
- $this->assertEqual(
- true,
+ $this->assertTrue(
$repo->shouldTrackBranch('master'),
'Track listed branches.');
- $this->assertEqual(
- false,
+ $this->assertFalse(
$repo->shouldTrackBranch('imaginary'),
'Do not track unlisted branches.');
}
public function testSubversionPathInfo() {
$svn = PhabricatorRepositoryType::REPOSITORY_TYPE_SVN;
$repo = new PhabricatorRepository();
$repo->setVersionControlSystem($svn);
$repo->setDetail('remote-uri', 'http://svn.example.com/repo');
$this->assertEqual(
'http://svn.example.com/repo',
$repo->getSubversionPathURI());
$repo->setDetail('remote-uri', 'http://svn.example.com/repo/');
$this->assertEqual(
'http://svn.example.com/repo',
$repo->getSubversionPathURI());
$repo->setDetail('hosting-enabled', true);
$repo->setDetail('local-path', '/var/repo/SVN');
$this->assertEqual(
'file:///var/repo/SVN',
$repo->getSubversionPathURI());
$repo->setDetail('local-path', '/var/repo/SVN/');
$this->assertEqual(
'file:///var/repo/SVN',
$repo->getSubversionPathURI());
$this->assertEqual(
'file:///var/repo/SVN/a@',
$repo->getSubversionPathURI('a'));
$this->assertEqual(
'file:///var/repo/SVN/a@1',
$repo->getSubversionPathURI('a', 1));
$this->assertEqual(
'file:///var/repo/SVN/%3F@22',
$repo->getSubversionPathURI('?', 22));
$repo->setDetail('svn-subpath', 'quack/trunk/');
$this->assertEqual(
'file:///var/repo/SVN/quack/trunk/@',
$repo->getSubversionBaseURI());
$this->assertEqual(
'file:///var/repo/SVN/quack/trunk/@HEAD',
$repo->getSubversionBaseURI('HEAD'));
}
public function testFilterMercurialDebugOutput() {
$map = array(
"" => "",
"quack\n" => "quack\n",
"ignoring untrusted configuration option x.y = z\nquack\n" =>
"quack\n",
"ignoring untrusted configuration option x.y = z\n".
"ignoring untrusted configuration option x.y = z\n".
"quack\n" =>
"quack\n",
"ignoring untrusted configuration option x.y = z\n".
"ignoring untrusted configuration option x.y = z\n".
"ignoring untrusted configuration option x.y = z\n".
"quack\n" =>
"quack\n",
"quack\n".
"ignoring untrusted configuration option x.y = z\n".
"ignoring untrusted configuration option x.y = z\n".
"ignoring untrusted configuration option x.y = z\n" =>
"quack\n",
"ignoring untrusted configuration option x.y = z\n".
"ignoring untrusted configuration option x.y = z\n".
"duck\n".
"ignoring untrusted configuration option x.y = z\n".
"ignoring untrusted configuration option x.y = z\n".
"bread\n".
"ignoring untrusted configuration option x.y = z\n".
"quack\n" =>
"duck\nbread\nquack\n",
"ignoring untrusted configuration option x.y = z\n".
"duckignoring untrusted configuration option x.y = z\n".
"quack" =>
"duckquack",
);
foreach ($map as $input => $expect) {
$actual = PhabricatorRepository::filterMercurialDebugOutput($input);
$this->assertEqual($expect, $actual, $input);
}
}
}
diff --git a/src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php b/src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php
index 37c697f4ba..bcb21a6de8 100644
--- a/src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php
+++ b/src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php
@@ -1,1238 +1,1235 @@
<?php
final class PhabricatorChangeParserTestCase
extends PhabricatorWorkingCopyTestCase {
public function testGitParser() {
$repository = $this->buildDiscoveredRepository('CHA');
$viewer = PhabricatorUser::getOmnipotentUser();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryIDs(array($repository->getID()))
->execute();
$this->expectChanges(
$repository,
$commits,
array(
// 8ebb73c add +x
'8ebb73c3f127625ad090472f4f3bfc72804def54' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1389892449,
),
array(
'/file_moved',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_NORMAL,
1,
1389892449,
),
),
// ee9c790 add symlink
'ee9c7909e012da7d75e8e1293c7803a6e73ac26a' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1389892436,
),
array(
'/file_link',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_SYMLINK,
1,
1389892436,
),
),
// 7260ca4 add directory file
'7260ca4b6cec35e755bb5365c4ccdd3f1977772e' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1389892408,
),
array(
'/dir',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_DIRECTORY,
1,
1389892408,
),
array(
'/dir/subfile',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
1389892408,
),
),
// 1fe783c move a file
'1fe783cf207c1e5f3e01650d2d9cb80b8a707f0e' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1389892388,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_MOVE_AWAY,
DifferentialChangeType::FILE_NORMAL,
1,
1389892388,
),
array(
'/file_moved',
'/file',
'1fe783cf207c1e5f3e01650d2d9cb80b8a707f0e',
DifferentialChangeType::TYPE_MOVE_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
1389892388,
),
),
// 376af8c copy a file
'376af8cd8f5b96ec55b7d9a86ccc85b8df8fb833' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1389892377,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
1389892377,
),
array(
'/file_copy',
'/file',
'376af8cd8f5b96ec55b7d9a86ccc85b8df8fb833',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
1389892377,
),
),
// ece6ea6 changed a file
'ece6ea6c6836e8b11a103e21707b8f30e6840c94' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1389892352,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_NORMAL,
1,
1389892352,
),
),
// 513103f added a file
'513103f65b8413dd2f1a1b5c1d4852a4a598540f' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
// This is the initial commit and technically created this
// directory; arguably the parser should figure this out and
// mark this as a direct change.
0,
1389892330,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
1389892330,
),
),
));
}
public function testMercurialParser() {
$repository = $this->buildDiscoveredRepository('CHB');
$viewer = PhabricatorUser::getOmnipotentUser();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryIDs(array($repository->getID()))
->execute();
$this->expectChanges(
$repository,
$commits,
array(
'970357a2dc4264060e65d68e42240bb4e5984085' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1390249395,
),
array(
'/file_moved',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_NORMAL,
1,
1390249395,
),
),
'fbb49af9788e5dbffbc05a060b680df1fd457be3' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1390249380,
),
array(
'/file_link',
null,
null,
DifferentialChangeType::TYPE_ADD,
// TODO: This is not correct, and should be FILE_SYMLINK. See
// note in the parser about this. This is a known bug.
DifferentialChangeType::FILE_NORMAL,
1,
1390249380,
),
),
'0e8d3465944c7ed7a7c139da7edc652cf80dba69' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1390249342,
),
array(
'/dir',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_DIRECTORY,
1,
1390249342,
),
array(
'/dir/subfile',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
1390249342,
),
),
'22c75131ff15c8a44d7a729c4542b7f4c8ed27f4' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1390249320,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_MOVE_AWAY,
DifferentialChangeType::FILE_NORMAL,
1,
1390249320,
),
array(
'/file_moved',
'/file',
'22c75131ff15c8a44d7a729c4542b7f4c8ed27f4',
DifferentialChangeType::TYPE_MOVE_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
1390249320,
),
),
'd9d252df30cb7251ad3ea121eff30c7d2e36dd67' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1390249308,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
1390249308,
),
array(
'/file_copy',
'/file',
'd9d252df30cb7251ad3ea121eff30c7d2e36dd67',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
1390249308,
),
),
'1fc0445d5e3d0f33e9dcbb68bbe419a847460d25' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1390249294,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_NORMAL,
1,
1390249294,
),
),
'61518e196efb7f80700333cc0d00634c2578871a' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_DIRECTORY,
1,
1390249286,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
1390249286,
),
),
));
}
public function testSubversionParser() {
$repository = $this->buildDiscoveredRepository('CHC');
$viewer = PhabricatorUser::getOmnipotentUser();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryIDs(array($repository->getID()))
->execute();
$this->expectChanges(
$repository,
$commits,
array(
'15' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
15,
),
array(
'/file_copy',
null,
null,
DifferentialChangeType::TYPE_MULTICOPY,
DifferentialChangeType::FILE_NORMAL,
1,
15,
),
array(
'/file_copy_x',
'/file_copy',
'12',
DifferentialChangeType::TYPE_MOVE_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
15,
),
array(
'/file_copy_y',
'/file_copy',
'12',
DifferentialChangeType::TYPE_MOVE_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
15,
),
array(
'/file_copy_z',
'/file_copy',
'12',
DifferentialChangeType::TYPE_MOVE_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
15,
),
),
// Add a file from a different revision
'14' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
14,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
14,
),
array(
'/file_1',
'/file',
'1',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
14,
),
),
// Property change on "/"
'13' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_DIRECTORY,
1,
13,
),
),
// Copy a directory, removing and adding files to the copy
'12' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
12,
),
array(
'/dir',
null,
null,
// TODO: This might reasonbly be considered a bug in the parser; it
// should probably be COPY_AWAY.
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
12,
),
array(
'/dir/a',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
12,
),
array(
'/dir/b',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
12,
),
array(
'/dir/subdir',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_DIRECTORY,
0,
12,
),
array(
'/dir/subdir/a',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
12,
),
array(
'/dir/subdir/b',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
12,
),
array(
'/dir_copy',
'/dir',
'11',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_DIRECTORY,
1,
12,
),
array(
'/dir_copy/a',
'/dir/a',
'11',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
12,
),
array(
'/dir_copy/b',
'/dir/b',
'11',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
12,
),
array(
'/dir_copy/subdir',
'/dir/subdir',
'11',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_DIRECTORY,
1,
12,
),
array(
'/dir_copy/subdir/a',
'/dir/subdir/a',
'11',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
12,
),
array(
'/dir_copy/subdir/b',
'/dir/subdir/b',
'11',
DifferentialChangeType::TYPE_DELETE,
DifferentialChangeType::FILE_NORMAL,
1,
12,
),
array(
'/dir_copy/subdir/c',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
12,
),
),
// Add a directory with a subdirectory and files, sets up next commit
'11' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
11,
),
array(
'/dir',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_DIRECTORY,
1,
11,
),
array(
'/dir/a',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
11,
),
array(
'/dir/b',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
11,
),
array(
'/dir/subdir',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_DIRECTORY,
1,
11,
),
array(
'/dir/subdir/a',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
11,
),
array(
'/dir/subdir/b',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
11,
),
),
// Remove directory
'10' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
10,
),
array(
'/dir',
null,
null,
DifferentialChangeType::TYPE_DELETE,
DifferentialChangeType::FILE_DIRECTORY,
1,
10,
),
array(
'/dir/subfile',
null,
null,
DifferentialChangeType::TYPE_DELETE,
DifferentialChangeType::FILE_NORMAL,
1,
10,
),
),
// Replace directory with file
'9' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
9,
),
array(
'/file_moved',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_DIRECTORY,
1,
9,
),
),
// Replace file with file
'8' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
8,
),
array(
'/file_moved',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_NORMAL,
1,
8,
),
),
'7' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
7,
),
array(
'/file_moved',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_NORMAL,
1,
7,
),
),
'6' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
6,
),
array(
'/file_link',
null,
null,
DifferentialChangeType::TYPE_ADD,
// TODO: This is not correct, and should be FILE_SYMLINK.
DifferentialChangeType::FILE_NORMAL,
1,
6,
),
),
'5' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
5,
),
array(
'/dir',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_DIRECTORY,
1,
5,
),
array(
'/dir/subfile',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
5,
),
),
'4' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
4,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_MOVE_AWAY,
DifferentialChangeType::FILE_NORMAL,
1,
4,
),
array(
'/file_moved',
'/file',
'2',
DifferentialChangeType::TYPE_MOVE_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
4,
),
),
'3' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
3,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
3,
),
array(
'/file_copy',
'/file',
'2',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
3,
),
),
'2' => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
2,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_CHANGE,
DifferentialChangeType::FILE_NORMAL,
1,
2,
),
),
'1' => array(
array(
'/',
null,
null,
// The Git and Svn parsers don't recognize the first commit as
// creating "/", while the Mercurial parser does. All the parsers
// should probably behave like the Mercurial parser.
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
1,
),
array(
'/file',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
1,
),
),
));
}
public function testSubversionPartialParser() {
$repository = $this->buildBareRepository('CHD');
$repository->setDetail('svn-subpath', 'trunk/');
id(new PhabricatorRepositoryPullEngine())
->setRepository($repository)
->pullRepository();
id(new PhabricatorRepositoryDiscoveryEngine())
->setRepository($repository)
->discoverCommits();
$viewer = PhabricatorUser::getOmnipotentUser();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryIDs(array($repository->getID()))
->execute();
$this->expectChanges(
$repository,
$commits,
array(
// Copy of a file outside of the subpath from an earlier revision
// into the subpath.
4 => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
4,
),
array(
'/goat',
null,
null,
DifferentialChangeType::TYPE_COPY_AWAY,
DifferentialChangeType::FILE_NORMAL,
0,
4,
),
array(
'/trunk',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
4,
),
array(
'/trunk/goat',
'/goat',
'1',
DifferentialChangeType::TYPE_COPY_HERE,
DifferentialChangeType::FILE_NORMAL,
1,
4,
),
),
3 => array(
array(
'/',
null,
null,
DifferentialChangeType::TYPE_CHILD,
DifferentialChangeType::FILE_DIRECTORY,
0,
3,
),
array(
'/trunk',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_DIRECTORY,
1,
3,
),
array(
'/trunk/apple',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
3,
),
array(
'/trunk/banana',
null,
null,
DifferentialChangeType::TYPE_ADD,
DifferentialChangeType::FILE_NORMAL,
1,
3,
),
),
));
}
public function testSubversionValidRootParser() {
// First, automatically configure the root correctly.
$repository = $this->buildBareRepository('CHD');
id(new PhabricatorRepositoryPullEngine())
->setRepository($repository)
->pullRepository();
$caught = null;
try {
id(new PhabricatorRepositoryDiscoveryEngine())
->setRepository($repository)
->discoverCommits();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- false,
+ $this->assertFalse(
($caught instanceof Exception),
pht('Natural SVN root should work properly.'));
// This time, artificially break the root. We expect this to fail.
$repository = $this->buildBareRepository('CHD');
$repository->setDetail(
'remote-uri',
$repository->getDetail('remote-uri').'trunk/');
id(new PhabricatorRepositoryPullEngine())
->setRepository($repository)
->pullRepository();
$caught = null;
try {
id(new PhabricatorRepositoryDiscoveryEngine())
->setRepository($repository)
->discoverCommits();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($caught instanceof Exception),
pht('Artificial SVN root should fail.'));
}
public function testSubversionForeignStubsParser() {
$repository = $this->buildBareRepository('CHE');
$repository->setDetail('svn-subpath', 'branch/');
id(new PhabricatorRepositoryPullEngine())
->setRepository($repository)
->pullRepository();
id(new PhabricatorRepositoryDiscoveryEngine())
->setRepository($repository)
->discoverCommits();
$viewer = PhabricatorUser::getOmnipotentUser();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryIDs(array($repository->getID()))
->execute();
foreach ($commits as $commit) {
$this->parseCommit($repository, $commit);
}
// As a side effect, we expect parsing these commits to have created
// foreign stubs of other commits.
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryIDs(array($repository->getID()))
->execute();
$commits = mpull($commits, null, 'getCommitIdentifier');
- $this->assertEqual(
- true,
+ $this->assertTrue(
isset($commits['2']),
'Expect rCHE2 to exist as a foreign stub.');
// The foreign stub should be marked imported.
$commit = $commits['2'];
$this->assertEqual(
PhabricatorRepositoryCommit::IMPORTED_ALL,
(int)$commit->getImportStatus());
}
private function parseCommit(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit) {
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$parser = 'PhabricatorRepositoryGitCommitChangeParserWorker';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$parser = 'PhabricatorRepositoryMercurialCommitChangeParserWorker';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$parser = 'PhabricatorRepositorySvnCommitChangeParserWorker';
break;
default:
throw new Exception(pht('No support yet.'));
}
$parser_object = newv($parser, array(array()));
return $parser_object->parseChangesForUnitTest($repository, $commit);
}
private function expectChanges(
PhabricatorRepository $repository,
array $commits,
array $expect) {
foreach ($commits as $commit) {
$commit_identifier = $commit->getCommitIdentifier();
$expect_changes = idx($expect, $commit_identifier);
if ($expect_changes === null) {
$this->assertEqual(
$commit_identifier,
null,
pht(
'No test entry for commit "%s" in repository "%s"!',
$commit_identifier,
$repository->getCallsign()));
}
$changes = $this->parseCommit($repository, $commit);
$path_map = id(new DiffusionPathQuery())
->withPathIDs(mpull($changes, 'getPathID'))
->execute();
$path_map = ipull($path_map, 'path');
$target_commits = array_filter(mpull($changes, 'getTargetCommitID'));
if ($target_commits) {
$commits = id(new DiffusionCommitQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withIDs($target_commits)
->execute();
$target_commits = mpull($commits, 'getCommitIdentifier', 'getID');
}
$dicts = array();
foreach ($changes as $key => $change) {
$target_path = idx($path_map, $change->getTargetPathID());
$target_commit = idx($target_commits, $change->getTargetCommitID());
$dicts[$key] = array(
$path_map[(int)$change->getPathID()],
$target_path,
$target_commit ? (string)$target_commit : null,
(int)$change->getChangeType(),
(int)$change->getFileType(),
(int)$change->getIsDirect(),
(int)$change->getCommitSequence(),
);
}
$dicts = ipull($dicts, null, 0);
$expect_changes = ipull($expect_changes, null, 0);
ksort($dicts);
ksort($expect_changes);
$this->assertEqual(
$expect_changes,
$dicts,
pht('Commit %s', $commit_identifier));
}
}
}
diff --git a/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php b/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php
index d397788f20..fba21b7d5d 100644
--- a/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php
+++ b/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php
@@ -1,104 +1,102 @@
<?php
final class PhabricatorInfrastructureTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => 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);
+ $this->assertTrue(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));
+ $this->assertTrue(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));
+ $this->assertTrue($caught instanceof AphrontQueryCharacterSetException);
}
}
diff --git a/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php b/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php
index 7e5c5f9416..90950c613a 100644
--- a/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php
+++ b/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php
@@ -1,203 +1,193 @@
<?php
final class PhabricatorWorkerTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testLeaseTask() {
// Leasing should work.
$task = $this->scheduleTask();
$this->expectNextLease($task);
}
public function testMultipleLease() {
// We should not be able to lease a task multiple times.
$task = $this->scheduleTask();
$this->expectNextLease($task);
$this->expectNextLease(null);
}
public function testOldestFirst() {
// Older tasks should lease first, all else being equal.
$task1 = $this->scheduleTask();
$task2 = $this->scheduleTask();
$this->expectNextLease($task1);
$this->expectNextLease($task2);
}
public function testNewBeforeLeased() {
// Tasks not previously leased should lease before previously leased tasks.
$task1 = $this->scheduleTask();
$task2 = $this->scheduleTask();
$task1->setLeaseOwner('test');
$task1->setLeaseExpires(time() - 100000);
$task1->forceSaveWithoutLease();
$this->expectNextLease($task2);
$this->expectNextLease($task1);
}
public function testExecuteTask() {
$task = $this->scheduleAndExecuteTask();
$this->assertEqual(true, $task->isArchived());
$this->assertEqual(
PhabricatorWorkerArchiveTask::RESULT_SUCCESS,
$task->getResult());
}
public function testPermanentTaskFailure() {
$task = $this->scheduleAndExecuteTask(
array(
'doWork' => 'fail-permanent',
));
$this->assertEqual(true, $task->isArchived());
$this->assertEqual(
PhabricatorWorkerArchiveTask::RESULT_FAILURE,
$task->getResult());
}
public function testTemporaryTaskFailure() {
$task = $this->scheduleAndExecuteTask(
array(
'doWork' => 'fail-temporary',
));
- $this->assertEqual(false, $task->isArchived());
- $this->assertEqual(
- true,
- ($task->getExecutionException() instanceof Exception));
+ $this->assertFalse($task->isArchived());
+ $this->assertTrue($task->getExecutionException() instanceof Exception);
}
public function testTooManyTaskFailures() {
// Expect temporary failures, then a permanent failure.
$task = $this->scheduleAndExecuteTask(
array(
'doWork' => 'fail-temporary',
'getMaximumRetryCount' => 3,
'getWaitBeforeRetry' => -60,
));
// Temporary...
- $this->assertEqual(false, $task->isArchived());
- $this->assertEqual(
- true,
- ($task->getExecutionException() instanceof Exception));
+ $this->assertFalse($task->isArchived());
+ $this->assertTrue($task->getExecutionException() instanceof Exception);
$this->assertEqual(1, $task->getFailureCount());
// Temporary...
$task = $this->expectNextLease($task);
$task = $task->executeTask();
- $this->assertEqual(false, $task->isArchived());
- $this->assertEqual(
- true,
- ($task->getExecutionException() instanceof Exception));
+ $this->assertFalse($task->isArchived());
+ $this->assertTrue($task->getExecutionException() instanceof Exception);
$this->assertEqual(2, $task->getFailureCount());
// Temporary...
$task = $this->expectNextLease($task);
$task = $task->executeTask();
- $this->assertEqual(false, $task->isArchived());
- $this->assertEqual(
- true,
- ($task->getExecutionException() instanceof Exception));
+ $this->assertFalse($task->isArchived());
+ $this->assertTrue($task->getExecutionException() instanceof Exception);
$this->assertEqual(3, $task->getFailureCount());
// Temporary...
$task = $this->expectNextLease($task);
$task = $task->executeTask();
- $this->assertEqual(false, $task->isArchived());
- $this->assertEqual(
- true,
- ($task->getExecutionException() instanceof Exception));
+ $this->assertFalse($task->isArchived());
+ $this->assertTrue($task->getExecutionException() instanceof Exception);
$this->assertEqual(4, $task->getFailureCount());
// Permanent.
$task = $this->expectNextLease($task);
$task = $task->executeTask();
- $this->assertEqual(true, $task->isArchived());
+ $this->assertTrue($task->isArchived());
$this->assertEqual(
PhabricatorWorkerArchiveTask::RESULT_FAILURE,
$task->getResult());
}
public function testWaitBeforeRetry() {
$task = $this->scheduleTask(
array(
'doWork' => 'fail-temporary',
'getWaitBeforeRetry' => 1000000,
));
$this->expectNextLease($task)->executeTask();
$this->expectNextLease(null);
}
public function testRequiredLeaseTime() {
$task = $this->scheduleAndExecuteTask(
array(
'getRequiredLeaseTime' => 1000000,
));
- $this->assertEqual(true, ($task->getLeaseExpires() - time()) > 1000);
+ $this->assertTrue(($task->getLeaseExpires() - time()) > 1000);
}
public function testLeasedIsOldestFirst() {
// Tasks which expired earlier should lease first, all else being equal.
$task1 = $this->scheduleTask();
$task2 = $this->scheduleTask();
$task1->setLeaseOwner('test');
$task1->setLeaseExpires(time() - 100000);
$task1->forceSaveWithoutLease();
$task2->setLeaseOwner('test');
$task2->setLeaseExpires(time() - 200000);
$task2->forceSaveWithoutLease();
$this->expectNextLease($task2);
$this->expectNextLease($task1);
}
private function expectNextLease($task) {
$leased = id(new PhabricatorWorkerLeaseQuery())
->setLimit(1)
->execute();
if ($task === null) {
$this->assertEqual(0, count($leased));
return null;
} else {
$this->assertEqual(1, count($leased));
$this->assertEqual(
(int)head($leased)->getID(),
(int)$task->getID());
return head($leased);
}
}
private function scheduleAndExecuteTask(array $data = array()) {
$task = $this->scheduleTask($data);
$task = $this->expectNextLease($task);
$task = $task->executeTask();
return $task;
}
private function scheduleTask(array $data = array()) {
return PhabricatorWorker::scheduleTask('PhabricatorTestWorker', $data);
}
}
diff --git a/src/infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php b/src/infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php
index 221a493579..d15ed23c61 100644
--- a/src/infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php
+++ b/src/infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php
@@ -1,65 +1,61 @@
<?php
final class PhabricatorEdgeTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testCycleDetection() {
// The editor should detect that this introduces a cycle and prevent the
// edit.
$user = new PhabricatorUser();
$obj1 = id(new HarbormasterObject())->save();
$obj2 = id(new HarbormasterObject())->save();
$phid1 = $obj1->getPHID();
$phid2 = $obj2->getPHID();
$editor = id(new PhabricatorEdgeEditor())
->setActor($user)
->addEdge($phid1, PhabricatorEdgeConfig::TYPE_TEST_NO_CYCLE, $phid2)
->addEdge($phid2, PhabricatorEdgeConfig::TYPE_TEST_NO_CYCLE, $phid1);
$caught = null;
try {
$editor->save();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
- $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
// The first edit should go through (no cycle), bu the second one should
// fail (it introduces a cycle).
$editor = id(new PhabricatorEdgeEditor())
->setActor($user)
->addEdge($phid1, PhabricatorEdgeConfig::TYPE_TEST_NO_CYCLE, $phid2)
->save();
$editor = id(new PhabricatorEdgeEditor())
->setActor($user)
->addEdge($phid2, PhabricatorEdgeConfig::TYPE_TEST_NO_CYCLE, $phid1);
$caught = null;
try {
$editor->save();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
- $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
}
}
diff --git a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php
index 4828b0acb1..0097a5bef4 100644
--- a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php
+++ b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php
@@ -1,177 +1,176 @@
<?php
final class PhabricatorEnvTestCase extends PhabricatorTestCase {
public function testLocalWebResource() {
$map = array(
'/' => true,
'/D123' => true,
'/path/to/something/' => true,
"/path/to/\nHeader: x" => false,
'http://evil.com/' => false,
'//evil.com/evil/' => false,
'javascript:lol' => false,
'' => false,
null => false,
);
foreach ($map as $uri => $expect) {
$this->assertEqual(
$expect,
PhabricatorEnv::isValidLocalWebResource($uri),
"Valid local resource: {$uri}");
}
}
public function testRemoteWebResource() {
$map = array(
'http://example.com/' => true,
'derp://example.com/' => false,
'javascript:alert(1)' => false,
);
foreach ($map as $uri => $expect) {
$this->assertEqual(
$expect,
PhabricatorEnv::isValidRemoteWebResource($uri),
"Valid remote resource: {$uri}");
}
}
public function testDictionarySource() {
$source = new PhabricatorConfigDictionarySource(array('x' => 1));
$this->assertEqual(
array(
'x' => 1,
),
$source->getKeys(array('x', 'z')));
$source->setKeys(array('z' => 2));
$this->assertEqual(
array(
'x' => 1,
'z' => 2,
),
$source->getKeys(array('x', 'z')));
$source->setKeys(array('x' => 3));
$this->assertEqual(
array(
'x' => 3,
'z' => 2,
),
$source->getKeys(array('x', 'z')));
$source->deleteKeys(array('x'));
$this->assertEqual(
array(
'z' => 2,
),
$source->getKeys(array('x', 'z')));
}
public function testStackSource() {
$s1 = new PhabricatorConfigDictionarySource(array('x' => 1));
$s2 = new PhabricatorConfigDictionarySource(array('x' => 2));
$stack = new PhabricatorConfigStackSource();
$this->assertEqual(array(), $stack->getKeys(array('x')));
$stack->pushSource($s1);
$this->assertEqual(array('x' => 1), $stack->getKeys(array('x')));
$stack->pushSource($s2);
$this->assertEqual(array('x' => 2), $stack->getKeys(array('x')));
$stack->setKeys(array('x' => 3));
$this->assertEqual(array('x' => 3), $stack->getKeys(array('x')));
$stack->popSource();
$this->assertEqual(array('x' => 1), $stack->getKeys(array('x')));
$stack->popSource();
$this->assertEqual(array(), $stack->getKeys(array('x')));
$caught = null;
try {
$stack->popSource();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, ($caught instanceof Exception));
+ $this->assertTrue($caught instanceof Exception);
}
public function testOverrides() {
$outer = PhabricatorEnv::beginScopedEnv();
$outer->overrideEnvConfig('test.value', 1);
$this->assertEqual(1, PhabricatorEnv::getEnvConfig('test.value'));
$inner = PhabricatorEnv::beginScopedEnv();
$inner->overrideEnvConfig('test.value', 2);
$this->assertEqual(2, PhabricatorEnv::getEnvConfig('test.value'));
if (phutil_is_hiphop_runtime()) {
$inner->__destruct();
}
unset($inner);
$this->assertEqual(1, PhabricatorEnv::getEnvConfig('test.value'));
if (phutil_is_hiphop_runtime()) {
$outer->__destruct();
}
unset($outer);
}
public function testOverrideOrder() {
$outer = PhabricatorEnv::beginScopedEnv();
$inner = PhabricatorEnv::beginScopedEnv();
$caught = null;
try {
$outer->__destruct();
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
$caught instanceof Exception,
"Destroying a scoped environment which is not on the top of the stack ".
"should throw.");
if (phutil_is_hiphop_runtime()) {
$inner->__destruct();
}
unset($inner);
if (phutil_is_hiphop_runtime()) {
$outer->__destruct();
}
unset($outer);
}
public function testGetEnvExceptions() {
$caught = null;
try {
PhabricatorEnv::getEnvConfig("not.a.real.config.option");
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
$caught = null;
try {
PhabricatorEnv::getEnvConfig("test.value");
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(false, $caught instanceof Exception);
+ $this->assertFalse($caught instanceof Exception);
}
}
diff --git a/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php b/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
index 29f230b563..56457ceceb 100644
--- a/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
+++ b/src/infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
@@ -1,145 +1,144 @@
<?php
final class AphrontIsolatedDatabaseConnectionTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
// We disable this here because this test is unique (it is testing that
// isolation actually occurs) and must establish a live connection to the
// database to verify that.
self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK => false,
);
}
public function testIsolation() {
// This will fail if the connection isn't isolated.
queryfx(
$this->newIsolatedConnection(),
'INSERT INVALID SYNTAX');
- $this->assertEqual(true, true);
+ $this->assertTrue(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,
+ $this->assertTrue((bool)$id1, 'ID1 exists.');
+ $this->assertTrue((bool)$id2, 'ID2 exists.');
+ $this->assertTrue(
$id1 != $id2,
"IDs '{$id1}' and '{$id2}' are distinct.");
}
public function testDeletePermitted() {
$conn = $this->newIsolatedConnection();
queryfx($conn, 'DELETE');
- $this->assertEqual(true, true);
+ $this->assertTrue(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/__tests__/AphrontMySQLDatabaseConnectionTestCase.php b/src/infrastructure/storage/__tests__/AphrontMySQLDatabaseConnectionTestCase.php
index ccffbc2093..d78737c2f6 100644
--- a/src/infrastructure/storage/__tests__/AphrontMySQLDatabaseConnectionTestCase.php
+++ b/src/infrastructure/storage/__tests__/AphrontMySQLDatabaseConnectionTestCase.php
@@ -1,37 +1,37 @@
<?php
final class AphrontMySQLDatabaseConnectionTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
// We disable this here because we're testing live MySQL connections.
self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK => false,
);
}
public function testConnectionFailures() {
$conn = id(new HarbormasterScratchTable())->establishConnection('r');
queryfx($conn, 'SELECT 1');
// We expect the connection to recover from a 2006 (lost connection) when
// outside of a transaction...
$conn->simulateErrorOnNextQuery(2006);
queryfx($conn, 'SELECT 1');
// ...but when transactional, we expect the query to throw when the
// connection is lost, because it indicates the transaction was aborted.
$conn->openTransaction();
$conn->simulateErrorOnNextQuery(2006);
$caught = null;
try {
queryfx($conn, 'SELECT 1');
} catch (AphrontQueryConnectionLostException $ex) {
$caught = $ex;
}
- $this->assertEqual(true, $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
}
}
diff --git a/src/infrastructure/storage/__tests__/QueryFormattingTestCase.php b/src/infrastructure/storage/__tests__/QueryFormattingTestCase.php
index c583497751..b81484f7b2 100644
--- a/src/infrastructure/storage/__tests__/QueryFormattingTestCase.php
+++ b/src/infrastructure/storage/__tests__/QueryFormattingTestCase.php
@@ -1,57 +1,56 @@
<?php
final class QueryFormattingTestCase extends PhabricatorTestCase {
public function testQueryFormatting() {
$conn_r = id(new PhabricatorUser())->establishConnection('r');
$this->assertEqual(
'NULL',
qsprintf($conn_r, '%nd', null));
$this->assertEqual(
'0',
qsprintf($conn_r, '%nd', 0));
$this->assertEqual(
'0',
qsprintf($conn_r, '%d', 0));
$raised = null;
try {
qsprintf($conn_r, '%d', 'derp');
} catch (Exception $ex) {
$raised = $ex;
}
- $this->assertEqual(
+ $this->assertTrue(
(bool)$raised,
- true,
'qsprintf should raise exception for invalid %d conversion.');
$this->assertEqual(
"'<S>'",
qsprintf($conn_r, '%s', null));
$this->assertEqual(
'NULL',
qsprintf($conn_r, '%ns', null));
$this->assertEqual(
"'<S>', '<S>'",
qsprintf($conn_r, '%Ls', array('x', 'y')));
$this->assertEqual(
"'<B>'",
qsprintf($conn_r, '%B', null));
$this->assertEqual(
"NULL",
qsprintf($conn_r, '%nB', null));
$this->assertEqual(
"'<B>', '<B>'",
qsprintf($conn_r, '%LB', array('x', 'y')));
}
}
diff --git a/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php b/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php
index 25e0208ebb..0aae94d444 100644
--- a/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php
+++ b/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php
@@ -1,134 +1,133 @@
<?php
final class LiskFixtureTestCase extends PhabricatorTestCase {
public function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testTransactionalIsolation1of2() {
// NOTE: These tests are verifying that data is destroyed between tests.
// If the user from either test persists, the other test will fail.
$this->assertEqual(
0,
count(id(new HarbormasterScratchTable())->loadAll()));
id(new HarbormasterScratchTable())
->setData('alincoln')
->save();
}
public function testTransactionalIsolation2of2() {
$this->assertEqual(
0,
count(id(new HarbormasterScratchTable())->loadAll()));
id(new HarbormasterScratchTable())
->setData('ugrant')
->save();
}
public function testFixturesBasicallyWork() {
$this->assertEqual(
0,
count(id(new HarbormasterScratchTable())->loadAll()));
id(new HarbormasterScratchTable())
->setData('gwashington')
->save();
$this->assertEqual(
1,
count(id(new HarbormasterScratchTable())->loadAll()));
}
public function testReadableTransactions() {
// TODO: When we have semi-durable fixtures, use those instead. This is
// extremely hacky.
LiskDAO::endIsolateAllLiskEffectsToTransactions();
try {
$data = Filesystem::readRandomCharacters(32);
$obj = new HarbormasterScratchTable();
$obj->openTransaction();
$obj->setData($data);
$obj->save();
$loaded = id(new HarbormasterScratchTable())->loadOneWhere(
'data = %s',
$data);
$obj->killTransaction();
- $this->assertEqual(
- true,
+ $this->assertTrue(
($loaded !== null),
"Reads inside transactions should have transaction visibility.");
LiskDAO::beginIsolateAllLiskEffectsToTransactions();
} catch (Exception $ex) {
LiskDAO::beginIsolateAllLiskEffectsToTransactions();
throw $ex;
}
}
public function testGarbageLoadCalls() {
$obj = new HarbormasterObject();
$obj->save();
$id = $obj->getID();
$load = new HarbormasterObject();
$this->assertEqual(null, $load->load(0));
$this->assertEqual(null, $load->load(-1));
$this->assertEqual(null, $load->load(9999));
$this->assertEqual(null, $load->load(''));
$this->assertEqual(null, $load->load('cow'));
$this->assertEqual(null, $load->load($id."cow"));
- $this->assertEqual(true, (bool)$load->load((int)$id));
- $this->assertEqual(true, (bool)$load->load((string)$id));
+ $this->assertTrue((bool)$load->load((int)$id));
+ $this->assertTrue((bool)$load->load((string)$id));
}
public function testCounters() {
$obj = new HarbormasterObject();
$conn_w = $obj->establishConnection('w');
// Test that the counter bascially behaves as expected.
$this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'a'));
$this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'a'));
$this->assertEqual(3, LiskDAO::loadNextCounterID($conn_w, 'a'));
// This first insert is primarily a test that the previous LAST_INSERT_ID()
// value does not bleed into the creation of a new counter.
$this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'b'));
$this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'b'));
// These inserts alternate database connections. Since unit tests are
// transactional by default, we need to break out of them or we'll deadlock
// since the transactions don't normally close until we exit the test.
LiskDAO::endIsolateAllLiskEffectsToTransactions();
try {
$conn_1 = $obj->establishConnection('w', $force_new = true);
$conn_2 = $obj->establishConnection('w', $force_new = true);
$this->assertEqual(1, LiskDAO::loadNextCounterID($conn_1, 'z'));
$this->assertEqual(2, LiskDAO::loadNextCounterID($conn_2, 'z'));
$this->assertEqual(3, LiskDAO::loadNextCounterID($conn_1, 'z'));
$this->assertEqual(4, LiskDAO::loadNextCounterID($conn_2, 'z'));
$this->assertEqual(5, LiskDAO::loadNextCounterID($conn_1, 'z'));
LiskDAO::beginIsolateAllLiskEffectsToTransactions();
} catch (Exception $ex) {
LiskDAO::beginIsolateAllLiskEffectsToTransactions();
throw $ex;
}
}
}
diff --git a/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php b/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php
index 67128e82da..844f3ffc09 100644
--- a/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php
+++ b/src/infrastructure/storage/lisk/__tests__/LiskIsolationTestCase.php
@@ -1,113 +1,110 @@
<?php
final class LiskIsolationTestCase extends PhabricatorTestCase {
public function testIsolatedWrites() {
$dao = new LiskIsolationTestDAO();
$this->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.');
+ $this->assertTrue((bool)$id, 'Expect ID generated.');
+ $this->assertTrue((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);
+ $this->assertTrue(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,
+ $this->assertTrue(
(bool)$ex,
'Typoing "get" should throw.');
$ex = null;
try {
$dao->sxxName('z');
} catch (Exception $thrown) {
$ex = $thrown;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
(bool)$ex,
'Typoing "set" should throw.');
$ex = null;
try {
$dao->madeUpMethod();
} catch (Exception $thrown) {
$ex = $thrown;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
(bool)$ex,
'Made up method should throw.');
}
}
diff --git a/src/infrastructure/time/__tests__/PhabricatorTimeTestCase.php b/src/infrastructure/time/__tests__/PhabricatorTimeTestCase.php
index 54f10d875c..ef2db5cd66 100644
--- a/src/infrastructure/time/__tests__/PhabricatorTimeTestCase.php
+++ b/src/infrastructure/time/__tests__/PhabricatorTimeTestCase.php
@@ -1,82 +1,78 @@
<?php
final class PhabricatorTimeTestCase extends PhabricatorTestCase {
public function testPhabricatorTimeStack() {
$t = 1370202281;
$time = PhabricatorTime::pushTime($t, 'UTC');
- $this->assertEqual(
- true,
- (PhabricatorTime::getNow() === $t));
+ $this->assertTrue(PhabricatorTime::getNow() === $t);
unset($time);
- $this->assertEqual(
- false,
- (PhabricatorTime::getNow() === $t));
+ $this->assertFalse(PhabricatorTime::getNow() === $t);
}
public function testParseLocalTime() {
$u = new PhabricatorUser();
$u->setTimezoneIdentifier('UTC');
$v = new PhabricatorUser();
$v->setTimezoneIdentifier('America/Los_Angeles');
$t = 1370202281; // 2013-06-02 12:44:41 -0700
$time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('now', $u));
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('now', $v));
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $u));
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $v));
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $u));
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $v));
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('2013-06-02 19:44:41', $u));
$this->assertEqual(
$t,
PhabricatorTime::parseLocalTime('2013-06-02 12:44:41', $v));
$this->assertEqual(
$t + 3600,
PhabricatorTime::parseLocalTime('+1 hour', $u));
$this->assertEqual(
$t + 3600,
PhabricatorTime::parseLocalTime('+1 hour', $v));
unset($time);
$t = 1370239200; // 2013-06-02 23:00:00 -0700
$time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
// For the UTC user, midnight was 6 hours ago because it's early in the
// morning for htem. For the PDT user, midnight was 23 hours ago.
$this->assertEqual(
$t + (-6 * 3600) + 60,
PhabricatorTime::parseLocalTime('12:01:00 AM', $u));
$this->assertEqual(
$t + (-23 * 3600) + 60,
PhabricatorTime::parseLocalTime('12:01:00 AM', $v));
unset($time);
}
}
diff --git a/src/infrastructure/util/password/__tests__/PhabricatorPasswordHasherTestCase.php b/src/infrastructure/util/password/__tests__/PhabricatorPasswordHasherTestCase.php
index 32acf4cb9a..053acea4fc 100644
--- a/src/infrastructure/util/password/__tests__/PhabricatorPasswordHasherTestCase.php
+++ b/src/infrastructure/util/password/__tests__/PhabricatorPasswordHasherTestCase.php
@@ -1,42 +1,40 @@
<?php
final class PhabricatorPasswordHasherTestCase extends PhabricatorTestCase {
public function testHasherSyntax() {
$caught = null;
try {
PhabricatorPasswordHasher::getHasherForHash(
new PhutilOpaqueEnvelope('xxx'));
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($caught instanceof Exception),
pht('Exception on unparseable hash format.'));
$caught = null;
try {
PhabricatorPasswordHasher::getHasherForHash(
new PhutilOpaqueEnvelope('__test__:yyy'));
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(
- true,
+ $this->assertTrue(
($caught instanceof PhabricatorPasswordHasherUnavailableException),
pht('Fictional hasher unavailable.'));
}
public function testMD5Hasher() {
$hasher = new PhabricatorIteratedMD5PasswordHasher();
$this->assertEqual(
'md5:4824a35493d8b5dceab36f017d68425f',
$hasher->getPasswordHashForStorage(
new PhutilOpaqueEnvelope('quack'))->openEnvelope());
}
}
diff --git a/src/view/__tests__/PhabricatorAphrontViewTestCase.php b/src/view/__tests__/PhabricatorAphrontViewTestCase.php
index 2d05151d75..4d0d67c690 100644
--- a/src/view/__tests__/PhabricatorAphrontViewTestCase.php
+++ b/src/view/__tests__/PhabricatorAphrontViewTestCase.php
@@ -1,25 +1,25 @@
<?php
final class PhabricatorAphrontViewTestCase extends PhabricatorTestCase {
public function testHasChildren() {
$view = new AphrontNullView();
- $this->assertEqual(false, $view->hasChildren());
+ $this->assertFalse($view->hasChildren());
$values = array(
null,
'',
array(),
array(null, ''),
);
foreach ($values as $value) {
$view->appendChild($value);
- $this->assertEqual(false, $view->hasChildren());
+ $this->assertFalse($view->hasChildren());
}
$view->appendChild("!");
- $this->assertEqual(true, $view->hasChildren());
+ $this->assertTrue($view->hasChildren());
}
}
diff --git a/src/view/layout/__tests__/PHUIListViewTestCase.php b/src/view/layout/__tests__/PHUIListViewTestCase.php
index 57b8d8e381..78e1e6ea54 100644
--- a/src/view/layout/__tests__/PHUIListViewTestCase.php
+++ b/src/view/layout/__tests__/PHUIListViewTestCase.php
@@ -1,141 +1,141 @@
<?php
final class PHUIListViewTestCase extends PhabricatorTestCase {
public function testAppend() {
$menu = $this->newABCMenu();
$this->assertMenuKeys(
array(
'a',
'b',
'c',
),
$menu);
}
public function testAppendAfter() {
$menu = $this->newABCMenu();
$caught = null;
try {
$menu->addMenuItemAfter('x', $this->newLink('test1'));
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
$menu->addMenuItemAfter('a', $this->newLink('test2'));
$menu->addMenuItemAfter(null, $this->newLink('test3'));
$menu->addMenuItemAfter('a', $this->newLink('test4'));
$menu->addMenuItemAfter('test3', $this->newLink('test5'));
$this->assertMenuKeys(
array(
'a',
'test4',
'test2',
'b',
'c',
'test3',
'test5',
),
$menu);
}
public function testAppendBefore() {
$menu = $this->newABCMenu();
$caught = null;
try {
$menu->addMenuItemBefore('x', $this->newLink('test1'));
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
$menu->addMenuItemBefore('b', $this->newLink('test2'));
$menu->addMenuItemBefore(null, $this->newLink('test3'));
$menu->addMenuItemBefore('a', $this->newLink('test4'));
$menu->addMenuItemBefore('test3', $this->newLink('test5'));
$this->assertMenuKeys(
array(
'test5',
'test3',
'test4',
'a',
'test2',
'b',
'c',
),
$menu);
}
public function testAppendLabel() {
$menu = new PHUIListView();
$menu->addMenuItem($this->newLabel('fruit'));
$menu->addMenuItem($this->newLabel('animals'));
$caught = null;
try {
$menu->addMenuItemToLabel('x', $this->newLink('test1'));
} catch (Exception $ex) {
$caught = $ex;
}
- $this->assertEqual(true, $caught instanceof Exception);
+ $this->assertTrue($caught instanceof Exception);
$menu->addMenuItemToLabel('fruit', $this->newLink('apple'));
$menu->addMenuItemToLabel('fruit', $this->newLink('banana'));
$menu->addMenuItemToLabel('animals', $this->newLink('dog'));
$menu->addMenuItemToLabel('animals', $this->newLink('cat'));
$menu->addMenuItemToLabel('fruit', $this->newLink('cherry'));
$this->assertMenuKeys(
array(
'fruit',
'apple',
'banana',
'cherry',
'animals',
'dog',
'cat',
),
$menu);
}
private function newLink($key) {
return id(new PHUIListItemView())
->setKey($key)
->setHref('#')
->setName('Link');
}
private function newLabel($key) {
return id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LABEL)
->setKey($key)
->setName('Label');
}
private function newABCMenu() {
$menu = new PHUIListView();
$menu->addMenuItem($this->newLink('a'));
$menu->addMenuItem($this->newLink('b'));
$menu->addMenuItem($this->newLink('c'));
return $menu;
}
private function assertMenuKeys(array $expect, PHUIListView $menu) {
$items = $menu->getItems();
$keys = mpull($items, 'getKey');
$keys = array_values($keys);
$this->assertEqual($expect, $keys);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jul 28, 2:34 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
186972
Default Alt Text
(140 KB)

Event Timeline