mirror of
https://github.com/nextcloud/passman.git
synced 2025-12-18 14:09:29 +08:00
Added unit test for SharingACLMapper
Renamed some vars Added launch_phpunit.sh to gitignore
This commit is contained in:
parent
9c53219346
commit
5186648889
4 changed files with 167 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -2,3 +2,6 @@ node_modules
|
||||||
.idea
|
.idea
|
||||||
.sass-cache
|
.sass-cache
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
|
||||||
|
# Don't mess with other dev's config
|
||||||
|
launch_phpunit.sh
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,12 @@ class SharingACLMapper extends Mapper {
|
||||||
/**
|
/**
|
||||||
* Gets the currently accepted share requests from the given user for the given vault guid
|
* Gets the currently accepted share requests from the given user for the given vault guid
|
||||||
* @param $user_id
|
* @param $user_id
|
||||||
* @param $vault_id
|
* @param $vault_guid
|
||||||
* @return SharingACL[]
|
* @return SharingACL[]
|
||||||
*/
|
*/
|
||||||
public function getVaultEntries($user_id, $vault_id) {
|
public function getVaultEntries($user_id, $vault_guid) {
|
||||||
$q = "SELECT * FROM ". self::TABLE_NAME ." WHERE user_id = ? AND vault_guid = ?";
|
$q = "SELECT * FROM ". self::TABLE_NAME ." WHERE user_id = ? AND vault_guid = ?";
|
||||||
return $this->findEntities($q, [$user_id, $vault_id]);
|
return $this->findEntities($q, [$user_id, $vault_guid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,29 @@ abstract class DatabaseHelperTest extends PHPUnit_Extensions_Database_TestCase {
|
||||||
return $this->datasets[$table_name]->getTable($table_name);
|
return $this->datasets[$table_name]->getTable($table_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a subset of rows from the dataset which field name matches
|
||||||
|
* the specified value
|
||||||
|
* @param $table_name The name of the table to search into
|
||||||
|
* @param $field_name The field name
|
||||||
|
* @param $value_match The value to match data against
|
||||||
|
* @return array An array of rows
|
||||||
|
*/
|
||||||
|
public function findInDataset($table_name, $field_name, $value_match) {
|
||||||
|
$table = $this->getTableDataset($table_name);
|
||||||
|
$rows = $table->getRowCount();
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
for ($i = 0; $i < $rows; $i++) {
|
||||||
|
$row = $table->getRow($i);
|
||||||
|
if ($row[$field_name] == $value_match){
|
||||||
|
$result[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @coversNothing
|
* @coversNothing
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,143 @@
|
||||||
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
|
||||||
* @license AGPLv3
|
* @license AGPLv3
|
||||||
*/
|
*/
|
||||||
class SharingACLMapperTest {
|
use \OCA\Passman\Db\SharingACLMapper;
|
||||||
|
use \OCA\Passman\Db\SharingACL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversDefaultClass \OCA\Passman\Db\SharingACLMapper
|
||||||
|
*/
|
||||||
|
class SharingACLMapperTest extends DatabaseHelperTest {
|
||||||
|
CONST TABLES = [
|
||||||
|
'oc_passman_sharing_acl'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SharingACLMapper
|
||||||
|
*/
|
||||||
|
protected $mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PHPUnit_Extensions_Database_DataSet_ITable
|
||||||
|
*/
|
||||||
|
protected $dataset;
|
||||||
|
/**
|
||||||
|
* This function should return the table name, for example
|
||||||
|
* for a test running on oc_passman_vaults it shall return ["oc_passman_vaults"]
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getTablesNames() {
|
||||||
|
return self::TABLES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$this->mapper = new SharingACLMapper($this->db);
|
||||||
|
$this->dataset = $this->getTableDataset(self::TABLES[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getItemACL
|
||||||
|
* @uses SharingACL
|
||||||
|
*/
|
||||||
|
public function testGetItemACL() {
|
||||||
|
$expected_acl = $this->dataset->getRow(0);
|
||||||
|
$expected_acl = SharingACL::fromRow($expected_acl);
|
||||||
|
|
||||||
|
$acl = $this->mapper->getItemACL(
|
||||||
|
$expected_acl->getUserId(),
|
||||||
|
$expected_acl->getItemGuid()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(SharingACL::class, $acl);
|
||||||
|
$this->assertEquals($expected_acl, $acl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getVaultEntries
|
||||||
|
*/
|
||||||
|
public function testGetVaultEntries() {
|
||||||
|
$expected_data = $this->findInDataset(self::TABLES[0], 'user_id', $this->dataset->getRow(0)['user_id']);
|
||||||
|
|
||||||
|
$this->assertNotCount(0, $expected_data, "The dataset has no values D:");
|
||||||
|
$result = $this->mapper->getVaultEntries($expected_data[0]['user_id'], $expected_data[0]['vault_guid']);
|
||||||
|
|
||||||
|
$this->assertInternalType('array', $expected_data);
|
||||||
|
$this->assertCount(count($expected_data), $result);
|
||||||
|
$this->assertInstanceOf(SharingACL::class, $result[0]);
|
||||||
|
|
||||||
|
foreach ($expected_data as &$row) {
|
||||||
|
$row = SharingACL::fromRow($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($expected_data, $result, "Data not matching the tests data", 0.0, 10, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::updateCredentialACL
|
||||||
|
*/
|
||||||
|
public function testUpdateCredentialACL() {
|
||||||
|
$expected_data = SharingACL::fromRow($this->dataset->getRow(0));
|
||||||
|
$data = $this->mapper->getItemACL(
|
||||||
|
$expected_data->getUserId(),
|
||||||
|
$expected_data->getItemGuid()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected_data, $data);
|
||||||
|
|
||||||
|
$data->setExpire(\OCA\Passman\Utility\Utils::getTime());
|
||||||
|
$this->mapper->updateCredentialACL($data);
|
||||||
|
|
||||||
|
$updated = $this->mapper->getItemACL(
|
||||||
|
$expected_data->getUserId(),
|
||||||
|
$expected_data->getItemGuid()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($data->getId(), $updated->getId());
|
||||||
|
$this->assertNotEquals($expected_data->getExpire(), $updated->getExpire());
|
||||||
|
$this->assertEquals($data->getExpire(), $updated->getExpire());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getCredentialAclList
|
||||||
|
*/
|
||||||
|
public function testGetCredentialAclList() {
|
||||||
|
$expected_data = $this->findInDataset(
|
||||||
|
self::TABLES[0],
|
||||||
|
'item_guid',
|
||||||
|
$this->dataset->getRow(0)['item_guid']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertNotEmpty($expected_data);
|
||||||
|
|
||||||
|
$data = $this->mapper->getCredentialAclList($expected_data[0]['item_guid']);
|
||||||
|
|
||||||
|
$this->assertInternalType('array', $data);
|
||||||
|
$this->assertCount(count($expected_data), $data);
|
||||||
|
$this->assertInstanceOf(SharingACL::class, $data[0]);
|
||||||
|
|
||||||
|
foreach ($expected_data as &$row) {
|
||||||
|
$row = SharingACL::fromRow($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($expected_data, $data, "Data not matching the tests data", 0.0, 10, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::deleteShareACL
|
||||||
|
*/
|
||||||
|
public function testDeleteShareACL() {
|
||||||
|
$test_data = SharingACL::fromRow($this->dataset->getRow(0));
|
||||||
|
|
||||||
|
$this->mapper->deleteShareACL($test_data);
|
||||||
|
|
||||||
|
$this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class);
|
||||||
|
|
||||||
|
$this->mapper->getItemACL(
|
||||||
|
$test_data->getUserId(),
|
||||||
|
$test_data->getItemGuid()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue