diff options
author | Marcos Zuriaga <wolfi@wolfi.es> | 2016-10-14 16:39:33 +0300 |
---|---|---|
committer | Marcos Zuriaga <wolfi@wolfi.es> | 2016-10-14 16:39:33 +0300 |
commit | 286476a546516bd03b76e7621cdfad4f01cdad15 (patch) | |
tree | 3fbafec88a8547d56d8fc763bf9008f9990e823b /tests | |
parent | 61dbcedfa49a36a462e95b0288ef1b91a85b53df (diff) |
Fixed some types on sharerequest entity
Added partial unit test for sharerequest mapper
Changed some assertEquals to assertSame so we don't do loosy type checks
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/lib/Db/ShareRequestMapperTest.php | 86 | ||||
-rw-r--r-- | tests/unit/lib/Db/ShareRequestTest.php | 24 |
2 files changed, 97 insertions, 13 deletions
diff --git a/tests/unit/lib/Db/ShareRequestMapperTest.php b/tests/unit/lib/Db/ShareRequestMapperTest.php index 32368307..4f0b787a 100644 --- a/tests/unit/lib/Db/ShareRequestMapperTest.php +++ b/tests/unit/lib/Db/ShareRequestMapperTest.php @@ -8,6 +8,90 @@ * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es) * @license AGPLv3 */ -class ShareRequestMapperTest { +use OCA\Passman\Db\ShareRequestMapper; +use OCA\Passman\Db\ShareRequest; + +/** + * @coversDefaultClass OCA\Passman\Db\ShareRequestMapper + */ +class ShareRequestMapperTest extends DatabaseHelperTest { + CONST TABLES = [ + 'oc_passman_share_request' + ]; + + /** + * @var ShareRequestMapper + */ + protected $mapper; + + /** + * @var PHPUnit_Extensions_Database_DataSet_ITable + */ + protected $dataset; + + public function setUp() { + parent::setUp(); + $this->dataset = $this->getTableDataset(self::TABLES[0]); + $this->mapper = new ShareRequestMapper($this->db); + } + + /** + * 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; + } + + /** + * @covers ::getRequestByItemAndVaultGuid + */ + public function testGetRequestByItemAndVaultGuid() { + $expected = ShareRequest::fromRow($this->dataset->getRow(0)); + $data = $this->mapper->getRequestByItemAndVaultGuid( + $expected->getItemGuid(), + $expected->getTargetVaultGuid() + ); + + $this->assertInstanceOf(ShareRequest::class, $data); + $this->assertInstanceOf(\OCA\Passman\Utility\PermissionEntity::class, $data); + $this->assertSame($expected->getItemGuid(), $data->getItemGuid()); + $this->assertSame($expected->getTargetVaultGuid(), $data->getTargetVaultGuid()); + } + + /** + * @covers ::createRequest + */ + public function testCreateRequest() { + $tmp = new ShareRequest(); + $tmp->setSharedKey('asdf'); + $tmp->setCreated(1); + $tmp->setItemGuid('asdf'); + $tmp->setFromUserId('WolFi'); + $tmp->setPermissions(5); + $tmp->setTargetVaultGuid("ffjj-ee-3423-edsfd"); + $tmp->setTargetUserId('Sander'); + $tmp->setTargetVaultId(5); + $tmp->setItemId(50); + $tmp->setSharedKey('asdfasdfasd44*.-fasf'); + + $insert_data = $this->mapper->createRequest($tmp); + $this->assertInstanceOf(ShareRequest::class, $insert_data); + $this->assertNotNull($insert_data->getId()); + $this->assertGreaterThan(0, $insert_data->getId()); + + $data = $this->mapper->getRequestByItemAndVaultGuid( + $tmp->getItemGuid(), + $tmp->getTargetVaultGuid() + ); + $this->assertSame($insert_data->jsonSerialize(), $data->jsonSerialize()); + + $tmp->setId($data->getId()); + + $this->assertSame($tmp->jsonSerialize(), $insert_data->jsonSerialize()); + } }
\ No newline at end of file diff --git a/tests/unit/lib/Db/ShareRequestTest.php b/tests/unit/lib/Db/ShareRequestTest.php index 2441ef60..a5265246 100644 --- a/tests/unit/lib/Db/ShareRequestTest.php +++ b/tests/unit/lib/Db/ShareRequestTest.php @@ -45,16 +45,16 @@ class ShareRequestTest extends PHPUnit_Framework_TestCase { * @covers ::fromRow */ public function testGetters(){ - $this->assertEquals(self::TEST_DATA['id'], $this->request->getId()); - $this->assertEquals(self::TEST_DATA['item_id'], $this->request->getItemId()); - $this->assertEquals(self::TEST_DATA['item_guid'], $this->request->getItemGuid()); - $this->assertEquals(self::TEST_DATA['target_user_id'], $this->request->getTargetUserId()); - $this->assertEquals(self::TEST_DATA['target_vault_id'], $this->request->getTargetVaultId()); - $this->assertEquals(self::TEST_DATA['target_vault_guid'], $this->request->getTargetVaultGuid()); - $this->assertEquals(self::TEST_DATA['shared_key'], $this->request->getSharedKey()); - $this->assertEquals(self::TEST_DATA['permissions'], $this->request->getPermissions()); - $this->assertEquals(self::TEST_DATA['created'], $this->request->getCreated()); - $this->assertEquals(self::TEST_DATA['from_user_id'], $this->request->getFromUserId()); + $this->assertSame(self::TEST_DATA['id'], $this->request->getId()); + $this->assertSame(self::TEST_DATA['item_id'], $this->request->getItemId()); + $this->assertSame(self::TEST_DATA['item_guid'], $this->request->getItemGuid()); + $this->assertSame(self::TEST_DATA['target_user_id'], $this->request->getTargetUserId()); + $this->assertSame(self::TEST_DATA['target_vault_id'], $this->request->getTargetVaultId()); + $this->assertSame(self::TEST_DATA['target_vault_guid'], $this->request->getTargetVaultGuid()); + $this->assertSame(self::TEST_DATA['shared_key'], $this->request->getSharedKey()); + $this->assertSame(self::TEST_DATA['permissions'], $this->request->getPermissions()); + $this->assertSame(self::TEST_DATA['created'], $this->request->getCreated()); + $this->assertSame(self::TEST_DATA['from_user_id'], $this->request->getFromUserId()); } /** @@ -105,7 +105,7 @@ class ShareRequestTest extends PHPUnit_Framework_TestCase { $actual_data = $this->request->jsonSerialize(); - $this->assertEquals($expected_result, $actual_data); + $this->assertSame($expected_result, $actual_data); } /** @@ -126,6 +126,6 @@ class ShareRequestTest extends PHPUnit_Framework_TestCase { $actual_data = $this->request->asACLJson(); - $this->assertEquals($expected_result, $actual_data); + $this->assertSame($expected_result, $actual_data); } }
\ No newline at end of file |