Refactored to use assertEquals where applicable,

so in case of errors the messages are more meaningful
This commit is contained in:
Marcos Zuriaga 2016-10-10 02:15:00 +02:00
parent 0b716a4d5f
commit 652be86567
No known key found for this signature in database
GPG key ID: 7D15585354D072FF
4 changed files with 38 additions and 36 deletions

View file

@ -10,6 +10,7 @@
use \OCA\Passman\Db\Credential;
use \OCP\AppFramework\Db\Entity;
//@TODO Change assertTrue with assertEquals when applicable
class CredentialTest extends PHPUnit_Framework_TestCase {
CONST TEST_DATA = [
'id' => 5,
@ -51,28 +52,28 @@ class CredentialTest extends PHPUnit_Framework_TestCase {
}
public function testGetters(){
$this->assertTrue($this->credential->getId() === self::TEST_DATA['id']);
$this->assertTrue($this->credential->getGuid() === self::TEST_DATA['guid']);
$this->assertTrue($this->credential->getVaultId() === self::TEST_DATA['vault_id']);
$this->assertTrue($this->credential->getUserId() === self::TEST_DATA['user_id']);
$this->assertTrue($this->credential->getLabel() === self::TEST_DATA['label']);
$this->assertTrue($this->credential->getDescription() === self::TEST_DATA['description']);
$this->assertTrue($this->credential->getCreated() === self::TEST_DATA['created']);
$this->assertTrue($this->credential->getChanged() === self::TEST_DATA['changed']);
$this->assertTrue($this->credential->getTags() === self::TEST_DATA['tags']);
$this->assertTrue($this->credential->getEmail() === self::TEST_DATA['email']);
$this->assertTrue($this->credential->getUsername() === self::TEST_DATA['username']);
$this->assertTrue($this->credential->getPassword() === self::TEST_DATA['password']);
$this->assertTrue($this->credential->getUrl() === self::TEST_DATA['url']);
$this->assertTrue($this->credential->getFavicon() === self::TEST_DATA['favicon']);
$this->assertTrue($this->credential->getRenewInterval() === self::TEST_DATA['renew_interval']);
$this->assertTrue($this->credential->getExpireTime() === self::TEST_DATA['expire_time']);
$this->assertTrue($this->credential->getDeleteTime() === self::TEST_DATA['delete_time']);
$this->assertTrue($this->credential->getFiles() === self::TEST_DATA['files']);
$this->assertTrue($this->credential->getCustomFields() === self::TEST_DATA['custom_fields']);
$this->assertTrue($this->credential->getOtp() === self::TEST_DATA['otp']);
$this->assertTrue($this->credential->getHidden() === self::TEST_DATA['hidden']);
$this->assertTrue($this->credential->getSharedKey() === self::TEST_DATA['shared_key']);
$this->assertEquals(self::TEST_DATA['id'], $this->credential->getId());
$this->assertEquals(self::TEST_DATA['guid'], $this->credential->getGuid());
$this->assertEquals(self::TEST_DATA['vault_id'], $this->credential->getVaultId());
$this->assertEquals(self::TEST_DATA['user_id'], $this->credential->getUserId());
$this->assertEquals(self::TEST_DATA['label'], $this->credential->getLabel());
$this->assertEquals(self::TEST_DATA['description'], $this->credential->getDescription());
$this->assertEquals(self::TEST_DATA['created'], $this->credential->getCreated());
$this->assertEquals(self::TEST_DATA['changed'], $this->credential->getChanged());
$this->assertEquals(self::TEST_DATA['tags'], $this->credential->getTags());
$this->assertEquals(self::TEST_DATA['email'], $this->credential->getEmail());
$this->assertEquals(self::TEST_DATA['username'], $this->credential->getUsername());
$this->assertEquals(self::TEST_DATA['password'], $this->credential->getPassword());
$this->assertEquals(self::TEST_DATA['url'], $this->credential->getUrl());
$this->assertEquals(self::TEST_DATA['favicon'], $this->credential->getFavicon());
$this->assertEquals(self::TEST_DATA['renew_interval'], $this->credential->getRenewInterval());
$this->assertEquals(self::TEST_DATA['expire_time'], $this->credential->getExpireTime());
$this->assertEquals(self::TEST_DATA['delete_time'], $this->credential->getDeleteTime());
$this->assertEquals(self::TEST_DATA['files'], $this->credential->getFiles());
$this->assertEquals(self::TEST_DATA['custom_fields'], $this->credential->getCustomFields());
$this->assertEquals(self::TEST_DATA['otp'], $this->credential->getOtp());
$this->assertEquals(self::TEST_DATA['hidden'], $this->credential->getHidden());
$this->assertEquals(self::TEST_DATA['shared_key'], $this->credential->getSharedKey());
}
public function testSetters() {

View file

@ -12,7 +12,7 @@ use \OCP\AppFramework\Http;
class NotFoundJSONResponseTest extends PHPUnit_Framework_TestCase {
public function testOnEmptyResponse(){
$data = new NotFoundJSONResponse();
$this->assertTrue($data->getStatus() === Http::STATUS_NOT_FOUND);
$this->assertEquals(Http::STATUS_NOT_FOUND, $data->getStatus());
$this->assertJsonStringEqualsJsonString('[]', $data->render(), 'Expected empty JSON response');
}
@ -23,7 +23,7 @@ class NotFoundJSONResponseTest extends PHPUnit_Framework_TestCase {
'integer' => 21
];
$response = new NotFoundJSONResponse($data);
$this->assertTrue($response->getStatus() === Http::STATUS_NOT_FOUND);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertJsonStringEqualsJsonString(json_encode($data), $response->render(), 'Rendered data does not match with expected data');
}
}

View file

@ -20,25 +20,25 @@ class PermissionsEntityTest extends PHPUnit_Framework_TestCase {
}
public function testPermissionConstants(){
$this->assertTrue(PermissionEntity::READ === 0b00000001);
$this->assertTrue(PermissionEntity::WRITE === 0b00000010);
$this->assertTrue(PermissionEntity::FILES === 0b00000100);
$this->assertTrue(PermissionEntity::HISTORY === 0b00001000);
$this->assertTrue(PermissionEntity::OWNER === 0b10000000);
$this->assertEquals(0b00000001, PermissionEntity::READ);
$this->assertEquals(0b00000010, PermissionEntity::WRITE);
$this->assertEquals(0b00000100, PermissionEntity::FILES);
$this->assertEquals(0b00001000, PermissionEntity::HISTORY);
$this->assertEquals(0b10000000, PermissionEntity::OWNER);
}
public function testAddPermission(){
// Start with an empty permission
$this->permission->setPermissions(0);
$this->assertTrue($this->permission->getPermissions() === 0);
$this->assertEquals(0, $this->permission->getPermissions());
// Add read permission
$this->permission->addPermission(PermissionEntity::READ);
$this->assertTrue($this->permission->getPermissions() === PermissionEntity::READ);
$this->assertEquals(PermissionEntity::READ, $this->permission->getPermissions());
// Try adding another permission and check if it has both
$this->permission->addPermission(PermissionEntity::FILES);
$this->assertTrue($this->permission->getPermissions() === (PermissionEntity::READ | PermissionEntity::FILES));
$this->assertEquals(PermissionEntity::READ | PermissionEntity::FILES, $this->permission->getPermissions());
}
public function testRemovePermission(){
@ -46,17 +46,18 @@ class PermissionsEntityTest extends PHPUnit_Framework_TestCase {
// Start with a set of permissions
$this->permission->setPermissions($base_permissions);
$this->assertTrue($this->permission->getPermissions() === $base_permissions);
$this->assertEquals($base_permissions, $this->permission->getPermissions());
// Remove write permission
$expected_permissions = PermissionEntity::READ | PermissionEntity::HISTORY;
$this->permission->removePermission(PermissionEntity::WRITE);
$this->assertTrue($this->permission->getPermissions() === $expected_permissions);
$this->assertEquals($expected_permissions, $this->permission->getPermissions());
$this->assertNotEquals($base_permissions, $this->permission->getPermissions());
// Remove history permission
$expected_permissions = PermissionEntity::READ;
$this->permission->removePermission(PermissionEntity::HISTORY);
$this->assertTrue($this->permission->getPermissions() === $expected_permissions);
$this->assertEquals($expected_permissions, $this->permission->getPermissions());
}
public function testHasPermission() {

View file

@ -21,7 +21,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase {
sleep(1);
$new_time = Utils::getTime();
$this->assertTrue($old_time +1 === $new_time, "Evaluating that $old_time +1 === $new_time");
$this->assertEquals($old_time +1, $new_time, "Evaluating that $old_time +1 === $new_time");
}
public function testGetMicroTime(){