-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paul Schwörer <[email protected]>
- Loading branch information
1 parent
7bca800
commit 110e7ef
Showing
3 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"require": { | ||
"lsolesen/pel": "^0.9.6" | ||
}, | ||
"require-dev": { | ||
"christophwurst/nextcloud_testing": "^0.9.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
|
||
namespace tests\Unit\Mapper; | ||
|
||
|
||
use ChristophWurst\Nextcloud\Testing\DatabaseTransaction; | ||
use ChristophWurst\Nextcloud\Testing\TestCase; | ||
use OC; | ||
use OCA\Maps\DB\FavoriteShare; | ||
use OCA\Maps\DB\FavoriteShareMapper; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
|
||
class FavoriteShareMapperTest extends TestCase { | ||
use DatabaseTransaction; | ||
|
||
/* @var FavoriteShareMapper */ | ||
private $favoriteShareMapper; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->favoriteShareMapper = new FavoriteShareMapper( | ||
OC::$server->getDatabaseConnection(), | ||
OC::$server->getSecureRandom() | ||
); | ||
} | ||
|
||
public function testCreateByOwnerAndTokenIsSuccessful() { | ||
/* @var FavoriteShare */ | ||
$share = $this->favoriteShareMapper->create("testUser", "testCategory"); | ||
|
||
$this->assertIsString($share->getToken()); | ||
$this->assertEquals("testUser", $share->getOwner()); | ||
$this->assertEquals("testCategory", $share->getCategory()); | ||
} | ||
|
||
public function testFindByTokenIsSuccessful() { | ||
/* @var FavoriteShare */ | ||
$shareExpected = $this->favoriteShareMapper->create("testUser", "testCategory"); | ||
|
||
/* @var FavoriteShare */ | ||
$shareActual = $this->favoriteShareMapper->findByToken($shareExpected->getToken()); | ||
|
||
$this->assertEquals($shareExpected->getToken(), $shareActual->getToken()); | ||
$this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner()); | ||
$this->assertEquals($shareExpected->getCategory(), $shareActual->getCategory()); | ||
} | ||
|
||
public function testFindByOwnerAndCategoryIsSuccessful() { | ||
/* @var FavoriteShare */ | ||
$shareExpected = $this->favoriteShareMapper->create("testUser", "testCategory"); | ||
|
||
/* @var FavoriteShare */ | ||
$shareActual = $this->favoriteShareMapper->findByOwnerAndCategory("testUser", "testCategory"); | ||
|
||
$this->assertEquals($shareExpected->getToken(), $shareActual->getToken()); | ||
$this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner()); | ||
$this->assertEquals($shareExpected->getCategory(), $shareActual->getCategory()); | ||
} | ||
|
||
public function testFindAllByOwnerIsSuccessfulAndDoesNotContainOtherShares() { | ||
/* @var FavoriteShare */ | ||
$share1 = $this->favoriteShareMapper->create("testUser", "testCategory1"); | ||
|
||
/* @var FavoriteShare */ | ||
$share2 = $this->favoriteShareMapper->create("testUser", "testCategory2"); | ||
|
||
$this->favoriteShareMapper->create("testUser2", "testCategory"); | ||
|
||
/* @var array */ | ||
$shares = $this->favoriteShareMapper->findAllByOwner("testUser"); | ||
|
||
$shareTokens = array_map(function ($share) { | ||
return $share->getToken(); | ||
}, $shares); | ||
|
||
$this->assertEquals(2, count($shareTokens)); | ||
$this->assertContains($share1->getToken(), $shareTokens); | ||
$this->assertContains($share2->getToken(), $shareTokens); | ||
} | ||
|
||
public function testFindOrCreateByOwnerAndCategoryIsSuccessful() { | ||
/* @var FavoriteShare */ | ||
$share = $this->favoriteShareMapper->findOrCreateByOwnerAndCategory("testUser", "testCategory"); | ||
|
||
$this->assertIsString($share->getToken()); | ||
$this->assertEquals("testUser", $share->getOwner()); | ||
$this->assertEquals("testCategory", $share->getCategory()); | ||
} | ||
|
||
public function testRemoveByOwnerAndCategoryIsSuccessful() { | ||
/* @var FavoriteShare */ | ||
$share = $this->favoriteShareMapper->create("testUser", "testCategory"); | ||
|
||
$this->favoriteShareMapper->removeByOwnerAndCategory($share->getOwner(), $share->getCategory()); | ||
|
||
$this->expectException(DoesNotExistException::class); | ||
|
||
$this->favoriteShareMapper->findByOwnerAndCategory($share->getOwner(), $share->getCategory()); | ||
} | ||
|
||
} |