function testSpecificUsersCreateSite()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userOther = new UserAccountModel();
     $userOther->setEmail("*****@*****.**");
     $userOther->setUsername("other");
     $userOther->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->verifyEmail($user);
     $userRepo->create($userOther);
     $userRepo->verifyEmail($userOther);
     // reload user object so all flags set correctly
     $userOther = $userRepo->loadByUserName($userOther->getUsername());
     $user = $userRepo->loadByUserName("test");
     $extensionsManager = new ExtensionManager($this->app);
     $userPerRepo = new \repositories\UserPermissionsRepository($extensionsManager);
     ## Noone can create sites
     $permissions = $userPerRepo->getPermissionsForUserInIndex(null);
     $this->assertEquals(0, count($permissions->getPermissions()));
     $permissions = $userPerRepo->getPermissionsForUserInIndex($user);
     $this->assertEquals(0, count($permissions->getPermissions()));
     $permissions = $userPerRepo->getPermissionsForUserInIndex($userOther);
     $this->assertEquals(0, count($permissions->getPermissions()));
     ## Now create user group for all users
     $userGroupModel = new \models\UserGroupModel();
     $userGroupModel->setTitle("TITLE");
     $userGroupRepo = new \repositories\UserGroupRepository();
     $userGroupRepo->createForIndex($userGroupModel);
     $userGroupRepo->addUserToGroup($user, $userGroupModel);
     $userGroupRepo->addPermissionToGroup(new \userpermissions\CreateSiteUserPermission(), $userGroupModel, null);
     ## Now user can create sites, anon can't!
     $permissions = $userPerRepo->getPermissionsForUserInIndex(null, false);
     $this->assertEquals(0, count($permissions->getPermissions()));
     $permissions = $userPerRepo->getPermissionsForUserInIndex(null, true);
     $this->assertEquals(0, count($permissions->getPermissions()));
     $permissions = $userPerRepo->getPermissionsForUserInIndex($user, false);
     $this->assertEquals(1, count($permissions->getPermissions()));
     $permissions = $userPerRepo->getPermissionsForUserInIndex($user, true);
     $this->assertEquals(0, count($permissions->getPermissions()));
     $permissions = $userPerRepo->getPermissionsForUserInIndex($userOther, false);
     $this->assertEquals(0, count($permissions->getPermissions()));
     $permissions = $userPerRepo->getPermissionsForUserInIndex($userOther, true);
     $this->assertEquals(0, count($permissions->getPermissions()));
 }
 function testUserIsUserGroup()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userTest = new UserAccountModel();
     $userTest->setEmail("*****@*****.**");
     $userTest->setUsername("testtest");
     $userTest->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userTest);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $usrb = new \repositories\builders\UserGroupRepositoryBuilder();
     $usrb->setSite($site);
     $userGroups = $usrb->fetchAll();
     $this->assertTrue(count($userGroups) > 0);
     $userGroup = $userGroups[0];
     // Test user doesn't have it
     $srb = new \repositories\builders\SiteRepositoryBuilder();
     $srb->setUserInterestedIn($userTest);
     $sites = $srb->fetchAll();
     $this->assertEquals(0, count($sites));
     // added to user group
     $uiugr = new \repositories\UserGroupRepository();
     $uiugr->addUserToGroup($userTest, $userGroup);
     //  has it
     $srb = new \repositories\builders\SiteRepositoryBuilder();
     $srb->setUserInterestedIn($userTest);
     $sites = $srb->fetchAll();
     $this->assertEquals(1, count($sites));
 }