-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#111. Add 100% coverage on BitMaskTrait
- Loading branch information
1 parent
ba161bb
commit 9a89c3d
Showing
3 changed files
with
132 additions
and
5 deletions.
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
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,127 @@ | ||
<?php | ||
|
||
namespace rjapitest\unit\extensions; | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use rjapi\extension\BitMask; | ||
use rjapi\extension\BitMaskTrait; | ||
use rjapitest\_data\UserFixture; | ||
use rjapitest\unit\TestCase; | ||
|
||
/** | ||
* Class BitMaskTest | ||
* @package rjapitest\unit\extensions | ||
* | ||
* @property BitMask bitMask | ||
*/ | ||
class BitMaskTraitTest extends TestCase | ||
{ | ||
use BitMaskTrait; | ||
|
||
private const FIELD = 'permissions'; | ||
private $bitMask; | ||
private $users; | ||
private $user; | ||
private $model; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->bitMask = new BitMask([ | ||
self::FIELD => [ | ||
'enabled' => true, | ||
'flags' => [ | ||
'publisher' => 1, | ||
'editor' => 2, | ||
'manager' => 4, | ||
'photo_reporter' => 8, | ||
'admin' => 16, | ||
], | ||
], | ||
]); | ||
$this->users[] = UserFixture::createAndGet(); | ||
$this->user = UserFixture::createAndGet(); | ||
$this->model = $this->user; | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws \rjapi\exceptions\AttributesException | ||
*/ | ||
public function it_sets_flags_index() | ||
{ | ||
$maskData = $this->setFlagsIndex(new Collection($this->users)); | ||
$this->assertInstanceOf(Collection::class, $maskData); | ||
$this->assertEquals(1, $maskData[0]['editor']); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws \rjapi\exceptions\AttributesException | ||
*/ | ||
public function it_sets_flags_view() | ||
{ | ||
$maskData = $this->setFlagsView($this->user); | ||
$this->assertEquals(1, $maskData['editor']); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws \rjapi\exceptions\AttributesException | ||
*/ | ||
public function it_sets_flags_create() | ||
{ | ||
$maskData = $this->setFlagsCreate(); | ||
$this->assertEquals(1, $maskData['editor']); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws \rjapi\exceptions\AttributesException | ||
*/ | ||
public function it_sets_flags_update() | ||
{ | ||
$this->setFlagsUpdate($this->model); | ||
$this->assertEquals(1, $this->model['editor']); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws \rjapi\exceptions\AttributesException | ||
*/ | ||
public function it_sets_mask_create() | ||
{ | ||
$this->setMaskCreate([ | ||
'publisher' => 0, | ||
'editor' => 0, | ||
'manager' => 0, | ||
'photo_reporter' => 0, | ||
'admin' => 1, | ||
]); | ||
$this->assertEquals(16, $this->model->permissions); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws \rjapi\exceptions\AttributesException | ||
*/ | ||
public function it_sets_mask_update() | ||
{ | ||
$this->setMaskUpdate($this->model, | ||
[ | ||
'publisher' => 0, | ||
'editor' => 0, | ||
'manager' => 0, | ||
'photo_reporter' => 0, | ||
'admin' => 1, | ||
]); | ||
$this->assertEquals(16, $this->model->permissions); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
UserFixture::delete($this->user->id); | ||
UserFixture::delete($this->users[0]->id); | ||
parent::tearDown(); | ||
} | ||
} |