public function testSave()
{
$user = new User();
$group = new Group();
$group->setName('test');
$this->em->persist($group);
$this->assertFalse($user->isAdmin());
$this->assertFalse($user->isPublic());
$this->repository->save($user, array('username' => 'foo_bar', 'password' => 'secret', 'email' => '*****@*****.**', 'first_name' => 'Foo', 'last_name' => 'Bar', 'status' => User::STATUS_INACTIVE, 'is_public' => TRUE, 'is_admin' => TRUE, 'attributes' => array('phone' => 123), 'user_type' => array(1)));
$this->em->flush();
$this->em->clear();
$users = $this->repository->findAll();
$this->assertEquals(1, sizeof($users));
$user = array_shift($users);
$this->assertEquals(1, $user->getId());
$this->assertEquals('foo_bar', $user->getUsername());
$this->assertTrue($user->checkPassword('secret'));
$this->assertEquals('*****@*****.**', $user->getEmail());
$this->assertEquals('Foo', $user->getFirstName());
$this->assertEquals('Bar', $user->getLastName());
$this->assertEquals(User::STATUS_INACTIVE, $user->getStatus());
$this->assertFalse($user->isActive());
$this->assertLessThan(5, time() - $user->getCreated()->getTimestamp());
$this->assertEquals(123, $user->getAttribute('phone'));
$this->assertTrue($user->isAdmin());
$this->assertTrue($user->isPublic());
$this->assertEquals(1, sizeof($user->getUserTypes()));
// test attribute change
$user->addAttribute('phone', 1234);
$this->em->persist($user);
$this->em->flush();
$this->assertEquals(1234, $user->getAttribute('phone'));
}