passman/tests/unit/lib/Db/CredentialRevisionTest.php

66 lines
4.9 KiB
PHP
Raw Normal View History

2016-10-09 07:46:53 +08:00
<?php
/**
* Test case for the Database CredentialRevision model class
* Date: 9/10/16
* Time: 1:28
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @license AGPLv3
*/
use \OCA\Passman\Db\CredentialRevision;
class CredentialRevisionTest extends PHPUnit_Framework_TestCase {
CONST TEST_DATA = [
'id' => 30,
'guid' => 'FA8D80E0-90AB-4D7A-9937-913F486C24EA',
'credential_id' => 5,
'user_id' => 'WolFi',
'created' => 1475964600,
'credential_data' => 'eyJjcmVkZW50aWFsX2lkIjo0LCJndWlkIjoiODMxRDM0RkMtRTdDMC00NTQxLUJENjgtNTA3NzQ3ODI0MTkyIiwidXNlcl9pZCI6IndvbGZpIiwidmF1bHRfaWQiOjEsImxhYmVsIjoidGVzdDIiLCJkZXNjcmlwdGlvbiI6ImV5SnBkaUk2SWxoVVFuWlRjRE5oSzFSMU4zbFdkVlJNY0dFeGJVRWlMQ0oySWpveExDSnBkR1Z5SWpveE1EQXdMQ0pyY3lJNk1qVTJMQ0owY3lJNk5qUXNJbTF2WkdVaU9pSmpZMjBpTENKaFpHRjBZU0k2SWlJc0ltTnBjR2hsY2lJNkltRmxjeUlzSW5OaGJIUWlPaUkzWnpkSE1EaHpOM0ZJV1NJc0ltTjBJam9pYVM5TGFIRkhVVEJUZW5WNmRrb3JlQ0o5IiwiY3JlYXRlZCI6MTQ3NTc5NDIxMiwiY2hhbmdlZCI6MTQ3NTc5NDIxMiwidGFncyI6ImV5SnBkaUk2SW1ZeGRHNVdRVTlZWTJNM05uZGlUVWRuT1VjMUszY2lMQ0oySWpveExDSnBkR1Z5SWpveE1EQXdMQ0pyY3lJNk1qVTJMQ0owY3lJNk5qUXNJbTF2WkdVaU9pSmpZMjBpTENKaFpHRjBZU0k2SWlJc0ltTnBjR2hsY2lJNkltRmxjeUlzSW5OaGJIUWlPaUkzWnp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pGaHpUMWxoYkVZNU1rRTNhVUVpZlE9PSIsImhpZGRlbiI6MCwic2hhcmVkX2tleSI6bnVsbH0',
'edited_by' => 'sander',
];
/**
* @var CredentialRevision
*/
protected $revision;
public function setUp() {
$this->revision = CredentialRevision::fromRow(self::TEST_DATA);
}
public function testGetters() {
$this->assertEquals(self::TEST_DATA['id'], $this->revision->getId());
$this->assertEquals(self::TEST_DATA['guid'], $this->revision->getGuid());
$this->assertEquals(self::TEST_DATA['credential_id'], $this->revision->getCredentialId());
$this->assertEquals(self::TEST_DATA['user_id'], $this->revision->getUserId());
$this->assertEquals(self::TEST_DATA['created'], $this->revision->getCreated());
$this->assertEquals(self::TEST_DATA['credential_data'], $this->revision->getCredentialData());
$this->assertEquals(self::TEST_DATA['edited_by'], $this->revision->getEditedBy());
}
public function testSetters() {
/**
* Only testing one setter, if a custom setter is added a test should be made
*/
$this->revision->setEditedBy('WolFi');
$this->assertEquals('WolFi', $this->revision->getEditedBy());
}
public function testJsonSerialize(){
// Make sure we use the test data and it's not ben tampered by previous tests
$this->setUp();
$expected_array = [
'revision_id' => self::TEST_DATA['id'],
'guid' => self::TEST_DATA['guid'],
'created' => self::TEST_DATA['created'],
'credential_data' => json_decode(base64_decode(self::TEST_DATA['credential_data'])),
'edited_by' => self::TEST_DATA['edited_by'],
];
$actual_array = $this->revision->jsonSerialize();
$this->assertEquals($expected_array, $actual_array);
}
}