forked from kayue/KayueWordpressBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
|
||
namespace Kayue\WordpressBundle\Tests\Model; | ||
|
||
use Kayue\WordpressBundle\Model\User; | ||
use Kayue\WordpressBundle\Entity\UserMeta; | ||
use Kayue\WordpressBundle\Entity\User; | ||
|
||
class UserTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
@@ -24,35 +25,61 @@ public function testEmail() | |
$this->assertEquals('[email protected]', $user->getEmail()); | ||
} | ||
|
||
public function testTrueHasRole() | ||
public function testAddRole() | ||
{ | ||
$this->markTestIncomplete(); | ||
/** @var $user User */ | ||
$user = new User(); | ||
$meta = new UserMeta(); | ||
$meta->setKey('wp_capabilities'); | ||
$meta->setValue(array('X' => true)); | ||
$user->addMeta($meta); | ||
|
||
$user = $this->getUser(); | ||
$this->assertContains('ROLE_WP_X', $user->getRoles()); | ||
|
||
return $user; | ||
} | ||
|
||
$defaultrole = User::ROLE_DEFAULT; | ||
$newrole = 'ROLE_X'; | ||
/** | ||
* @depends testAddRole | ||
*/ | ||
public function testAddAnotherRole(User $user) | ||
{ | ||
// get existing capabilities | ||
/** @var $capabilities UserMeta */ | ||
$capabilities = $user->getMetas()->filter(function(UserMeta $meta) { | ||
return $meta->getKey() === 'wp_capabilities'; | ||
})->first(); | ||
|
||
$this->assertTrue($user->hasRole($defaultrole)); | ||
$capabilities->setValue(array_merge($capabilities->getValue(), array('Y' => true))); | ||
|
||
$user->addRole($defaultrole); | ||
$this->assertTrue($user->hasRole($defaultrole)); | ||
$this->assertContains('ROLE_WP_X', $user->getRoles()); | ||
$this->assertContains('ROLE_WP_Y', $user->getRoles()); | ||
|
||
$user->addRole($newrole); | ||
$this->assertTrue($user->hasRole($newrole)); | ||
return $user; | ||
} | ||
|
||
public function testFalseHasRole() | ||
/** | ||
* @depends testAddAnotherRole | ||
*/ | ||
public function testRemoveRole(User $user) | ||
{ | ||
$this->markTestIncomplete(); | ||
// get existing capabilities | ||
/** @var $capabilities UserMeta */ | ||
$capabilities = $user->getMetas()->filter(function(UserMeta $meta) { | ||
return $meta->getKey() === 'wp_capabilities'; | ||
})->first(); | ||
|
||
$user = $this->getUser(); | ||
$newrole = 'ROLE_X'; | ||
$value = $capabilities->getValue(); | ||
$capabilities->setValue($value['X']); | ||
|
||
$this->assertFalse($user->hasRole($newrole)); | ||
$this->assertContainsOnly('ROLE_WP_X', $user->getRoles()); | ||
} | ||
|
||
public function testNoRole() | ||
{ | ||
$user = new User(); | ||
|
||
$user->addRole($newrole); | ||
$this->assertTrue($user->hasRole($newrole)); | ||
$this->assertEmpty($user->getRoles()); | ||
} | ||
|
||
/** | ||
|