2016-10-09 22:12:40 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case for the Share request model class
|
|
|
|
* Date: 9/10/16
|
|
|
|
* Time: 15:56
|
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
|
|
|
|
* @license AGPLv3
|
|
|
|
*/
|
|
|
|
use \OCA\Passman\Db\SharingACL;
|
|
|
|
use \OCA\Passman\Utility\PermissionEntity;
|
|
|
|
|
2016-10-11 07:41:32 +08:00
|
|
|
/**
|
|
|
|
* @coversDefaultClass \OCA\Passman\Db\SharingACL
|
|
|
|
*/
|
2016-10-09 22:12:40 +08:00
|
|
|
class SharingACLTest extends PHPUnit_Framework_TestCase {
|
|
|
|
CONST TEST_DATA = [
|
|
|
|
'id' => 55,
|
|
|
|
'item_id' => 5,
|
|
|
|
'item_guid' => 'FA8D80E0-90AB-4D7A-9937-913F486C24EA',
|
|
|
|
'user_id' => 'WolFi',
|
|
|
|
'created' => 1475854509,
|
|
|
|
'expire' => 0,
|
|
|
|
'expire_views' => 0,
|
|
|
|
'permissions' => 0x07,
|
|
|
|
'vault_id' => 1,
|
|
|
|
'vault_guid' => 'FA8D80E0-90AB-4D7A-9937-913F486C24EA',
|
|
|
|
'shared_key' => 'eyJpdiI6IkllTjNqS3NTMkEvd3BHRnB5MjZwMkEiLCJ2IjoxLCJpdGVyIjoxMDAwLCJrcyI6MjU2LCJ0cyI6NjQsIm1vZGUiOiJjY20iLCJhZGF0YSI6IiIsImNpcGhlciI6ImFlcyIsInNhbHQiOiJtdG5CT2ZOL3hlRSIsImN0IjoieVo1S3hCUEJUSm0wZEo2VHFXNGZiOUxtc2lXb29BIn0=',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var SharingACL
|
|
|
|
*/
|
|
|
|
protected $acl;
|
|
|
|
|
2016-10-11 07:41:32 +08:00
|
|
|
/**
|
|
|
|
* @after
|
|
|
|
*/
|
2016-10-09 22:12:40 +08:00
|
|
|
public function setUp() {
|
|
|
|
$this->acl = SharingACL::fromRow(self::TEST_DATA);
|
|
|
|
}
|
|
|
|
|
2016-10-11 07:41:32 +08:00
|
|
|
/**
|
|
|
|
* @covers ::__construct
|
|
|
|
* @covers ::fromRow
|
|
|
|
* @covers ::getter
|
|
|
|
*/
|
2016-10-09 22:12:40 +08:00
|
|
|
public function testGetters() {
|
|
|
|
$this->assertEquals(self::TEST_DATA['id'], $this->acl->getId());
|
|
|
|
$this->assertEquals(self::TEST_DATA['item_id'], $this->acl->getItemId());
|
|
|
|
$this->assertEquals(self::TEST_DATA['item_guid'], $this->acl->getItemGuid());
|
|
|
|
$this->assertEquals(self::TEST_DATA['user_id'], $this->acl->getUserId());
|
|
|
|
$this->assertEquals(self::TEST_DATA['created'], $this->acl->getCreated());
|
|
|
|
$this->assertEquals(self::TEST_DATA['expire'], $this->acl->getExpire());
|
|
|
|
$this->assertEquals(self::TEST_DATA['expire_views'], $this->acl->getExpireViews());
|
|
|
|
$this->assertEquals(self::TEST_DATA['permissions'], $this->acl->getPermissions());
|
|
|
|
$this->assertEquals(self::TEST_DATA['vault_id'], $this->acl->getVaultId());
|
|
|
|
$this->assertEquals(self::TEST_DATA['vault_guid'], $this->acl->getVaultGuid());
|
|
|
|
$this->assertEquals(self::TEST_DATA['shared_key'], $this->acl->getSharedKey());
|
|
|
|
}
|
|
|
|
|
2016-10-11 07:41:32 +08:00
|
|
|
/**
|
|
|
|
* @covers ::setter
|
|
|
|
*/
|
2016-10-09 22:12:40 +08:00
|
|
|
public function testSetters() {
|
|
|
|
/**
|
|
|
|
* Only testing one setter since if it works all setters should work because php magic.
|
|
|
|
* please, if you override a setter implement it here.
|
|
|
|
*/
|
|
|
|
$this->acl->setSharedKey('ASDF THIS IS A KEY');
|
|
|
|
$this->assertEquals('ASDF THIS IS A KEY', $this->acl->getSharedKey());
|
|
|
|
|
|
|
|
// Reset values to test data
|
|
|
|
$this->setUp();
|
|
|
|
}
|
|
|
|
|
2016-10-11 07:41:32 +08:00
|
|
|
/**
|
|
|
|
* @coversNothing
|
|
|
|
*/
|
2016-10-09 22:12:40 +08:00
|
|
|
public function testInheritedExpectedClasses() {
|
|
|
|
$this->assertInstanceOf(PermissionEntity::class, $this->acl);
|
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $this->acl);
|
|
|
|
}
|
|
|
|
|
2016-10-11 07:41:32 +08:00
|
|
|
/**
|
|
|
|
* @coversNothing
|
|
|
|
* @uses \OCA\Passman\Utility\PermissionEntity
|
|
|
|
*/
|
2016-10-09 22:12:40 +08:00
|
|
|
public function testPermissionSystemIsWorking(){
|
|
|
|
$this->assertTrue($this->acl->hasPermission(PermissionEntity::FILES));
|
|
|
|
$this->assertFalse($this->acl->hasPermission(PermissionEntity::OWNER));
|
|
|
|
}
|
|
|
|
|
2016-10-11 07:41:32 +08:00
|
|
|
/**
|
|
|
|
* @covers ::jsonSerialize
|
|
|
|
*/
|
2016-10-09 22:12:40 +08:00
|
|
|
public function testJsonSerialize() {
|
|
|
|
$expected_data = [
|
|
|
|
'acl_id' => self::TEST_DATA['id'],
|
|
|
|
'item_id' => self::TEST_DATA['item_id'],
|
|
|
|
'item_guid' => self::TEST_DATA['item_guid'],
|
|
|
|
'user_id' => self::TEST_DATA['user_id'],
|
|
|
|
'created' => self::TEST_DATA['created'],
|
|
|
|
'expire' => self::TEST_DATA['expire'],
|
|
|
|
'expire_views' => self::TEST_DATA['expire_views'],
|
|
|
|
'permissions' => self::TEST_DATA['permissions'],
|
|
|
|
'vault_id' => self::TEST_DATA['vault_id'],
|
|
|
|
'vault_guid' => self::TEST_DATA['vault_guid'],
|
|
|
|
'shared_key' => self::TEST_DATA['shared_key'],
|
|
|
|
'pending' => false,
|
|
|
|
];
|
|
|
|
|
|
|
|
$actual_data = $this->acl->jsonSerialize();
|
|
|
|
|
|
|
|
$this->assertEquals($expected_data, $actual_data);
|
|
|
|
}
|
|
|
|
}
|