|
1 <?php |
|
2 |
|
3 namespace FOS\UserBundle\Tests\CouchDocument; |
|
4 |
|
5 use FOS\UserBundle\CouchDocument\UserManager; |
|
6 use Doctrine\ODM\CouchDB\Mapping\ClassMetadata; |
|
7 |
|
8 class UserManagerTest extends \PHPUnit_Framework_TestCase |
|
9 { |
|
10 private $userManager; |
|
11 private $dm; |
|
12 private $repository; |
|
13 |
|
14 const USERTYPE = 'FOS\UserBundle\Tests\CouchDocument\DummyUser'; |
|
15 |
|
16 public function setUp() |
|
17 { |
|
18 if (!class_exists('Doctrine\ODM\CouchDB\Version')) { |
|
19 $this->markTestSkipped('Doctrine CouchDB has to be installed for this test to run.'); |
|
20 } |
|
21 |
|
22 $c = $this->getMock('FOS\UserBundle\Util\CanonicalizerInterface'); |
|
23 $ef = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface'); |
|
24 |
|
25 $class = new ClassMetadata(self::USERTYPE); |
|
26 $class->mapField(array('fieldName' => 'username')); |
|
27 |
|
28 $this->dm = $this->getMock('Doctrine\ODM\CouchDB\DocumentManager', array('getRepository', 'persist', 'remove', 'flush', 'getClassMetadata'), array(), '', false); |
|
29 $this->repository = $this->getMock('Doctrine\ODM\CouchDB\DocumentRepository', array('findBy', 'findAll'), array(), '', false); |
|
30 $this->dm->expects($this->any()) |
|
31 ->method('getRepository') |
|
32 ->with($this->equalTo(self::USERTYPE)) |
|
33 ->will($this->returnValue($this->repository)); |
|
34 $this->dm->expects($this->any()) |
|
35 ->method('getClassMetadata') |
|
36 ->with($this->equalTo(self::USERTYPE)) |
|
37 ->will($this->returnValue($class)); |
|
38 $this->userManager = new UserManager($ef, "sha1", $c, $c, $this->dm, self::USERTYPE); |
|
39 } |
|
40 |
|
41 public function testDeleteUser() |
|
42 { |
|
43 $user = new DummyUser(); |
|
44 $this->dm->expects($this->once())->method('remove')->with($this->equalTo($user)); |
|
45 $this->dm->expects($this->once())->method('flush'); |
|
46 |
|
47 $this->userManager->deleteUser($user); |
|
48 } |
|
49 |
|
50 public function testGetClass() |
|
51 { |
|
52 $this->assertEquals(self::USERTYPE, $this->userManager->getClass()); |
|
53 } |
|
54 |
|
55 public function testFindUserBy() |
|
56 { |
|
57 $crit = array("foo" => "bar"); |
|
58 $this->repository->expects($this->once())->method('findBy')->with($this->equalTo($crit))->will($this->returnValue(array())); |
|
59 |
|
60 $this->userManager->findUserBy($crit); |
|
61 } |
|
62 |
|
63 public function testFindUsers() |
|
64 { |
|
65 $this->repository->expects($this->once())->method('findAll')->will($this->returnValue(array())); |
|
66 |
|
67 $this->userManager->findUsers(); |
|
68 } |
|
69 |
|
70 public function testUpdateUser() |
|
71 { |
|
72 $user = new DummyUser(); |
|
73 $this->dm->expects($this->once())->method('persist')->with($this->equalTo($user)); |
|
74 $this->dm->expects($this->once())->method('flush'); |
|
75 |
|
76 $this->userManager->updateUser($user); |
|
77 } |
|
78 } |
|
79 |
|
80 class DummyUser extends \FOS\UserBundle\Document\User |
|
81 { |
|
82 |
|
83 } |