protected static function init()
 {
     self::$directory = \Stormpath\Resource\Directory::instantiate(array('name' => makeUniqueName('AccountStoreMappingTest Directory')));
     self::createResource(\Stormpath\Resource\Directory::PATH, self::$directory);
     $group = \Stormpath\Resource\Group::instantiate(array('name' => makeUniqueName('AccountStoreMappingTest Group')));
     self::$directory->createGroup($group);
     self::$application = \Stormpath\Resource\Application::instantiate(array('name' => makeUniqueName('AccountStoreMappingTest Application')));
     self::createResource(\Stormpath\Resource\Application::PATH, self::$application);
     self::$accountStoreMappingWithDir = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => self::$directory));
     self::$application->createAccountStoreMapping(self::$accountStoreMappingWithDir);
     self::$accountStoreMappingWithGroup = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => $group));
     self::$application->createAccountStoreMapping(self::$accountStoreMappingWithGroup);
     self::$inited = true;
 }
 /**
  * @expectedException \Stormpath\Resource\ResourceError
  */
 public function testDelete()
 {
     $group = \Stormpath\Resource\Group::instantiate(array('name' => 'Another New Group' . md5(time())));
     self::$directory->createGroup($group);
     $account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'Account Name', 'surname' => 'Surname', 'email' => md5(time()) . '@unknown12345678.kot', 'password' => 'superP4ss'));
     self::$directory->createAccount($account);
     $groupMembership = \Stormpath\Resource\GroupMembership::create(array('account' => $account, 'group' => $group));
     $groupMembership = \Stormpath\Resource\GroupMembership::get($groupMembership->href);
     $this->assertInstanceOf('\\Stormpath\\Resource\\GroupMembership', $groupMembership);
     $this->assertContains('Another New Group', $groupMembership->group->name);
     $this->assertContains('@unknown12345678.kot', $groupMembership->account->email);
     $href = $groupMembership->href;
     $groupMembership->delete();
     \Stormpath\Resource\GroupMembership::get($href);
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testAddGroupNonExistent()
 {
     self::$account->addGroup(\Stormpath\Resource\Group::instantiate());
 }
 public function testAuthenticateWithAccountStore()
 {
     $application = self::$application;
     $groupA = new \stdClass();
     $groupA->name = 'New Group in town A: ' . md5(time() . microtime() . uniqid());
     $groupA = \Stormpath\Resource\Group::instantiate($groupA);
     $application->createGroup($groupA);
     $groupB = new \stdClass();
     $groupB->name = 'New Group in town B: ' . md5(time() . microtime() . uniqid());
     $groupB = \Stormpath\Resource\Group::instantiate($groupB);
     $application->createGroup($groupB);
     $accountStoreMappingA = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => $groupA));
     $application->createAccountStoreMapping($accountStoreMappingA);
     $accountStoreMappingB = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => $groupB));
     $application->createAccountStoreMapping($accountStoreMappingB);
     $account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'Account Name', 'surname' => 'Surname', 'username' => 'super_unique_username', 'email' => '*****@*****.**', 'password' => 'superP4ss'));
     $application->createAccount($account);
     $groupA->addAccount($account);
     $authenticationRequest = new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => $accountStoreMappingA->getAccountStore()));
     $result = $application->authenticateAccount($authenticationRequest);
     $this->assertEquals('*****@*****.**', $result->account->email);
     try {
         $authenticationRequest = new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => $accountStoreMappingB->getAccountStore()));
         $application->authenticateAccount($authenticationRequest);
         $account->delete();
         $accountStoreMappingB->delete();
         $accountStoreMappingA->delete();
         $groupB->delete();
         $groupA->delete();
         $this->fail('Authentication should have failed.');
     } catch (\Stormpath\Resource\ResourceError $re) {
         $this->assertEquals(400, $re->getStatus());
         $this->assertEquals(7104, $re->getErrorCode());
         $this->assertContains('Invalid', $re->getMessage());
         $this->assertEquals("Login attempt failed because there is no Account in the Application's associated Account Stores with the specified username or email.", $re->getDeveloperMessage());
         $this->assertContains('7104', $re->getMoreInfo());
     }
     try {
         new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => 'not an instance of AccountStore'));
         $this->fail('UsernamePasswordRequest instantiation should have failed.');
     } catch (\InvalidArgumentException $iae) {
         $this->assertEquals("The value for accountStore in the \$options array should be an instance of \\Stormpath\\Resource\\AccountStore", $iae->getMessage());
     } catch (\Exception $e) {
         $this->fail('UsernamePasswordRequest instantiation with wrong type for account store should have thrown InvalidArgumentException.');
     }
     $account->delete();
     $accountStoreMappingB->delete();
     $accountStoreMappingA->delete();
     $groupB->delete();
     $groupA->delete();
 }
 public function testShouldBeAbleToGetGroupViaHTMLFragment()
 {
     $group = \Stormpath\Resource\Group::instantiate(array('name' => makeUniqueName('GroupTest htmlFragment')));
     self::$directory->createGroup($group);
     $href = $group->href;
     $hrefParts = array_reverse(explode('/', $href));
     $group = \Stormpath\Resource\Group::get($hrefParts[0]);
     $this->assertInstanceOf('\\Stormpath\\Resource\\Group', $group);
     $this->assertEquals($href, $group->href);
     $group2 = \Stormpath\Client::get($hrefParts[1] . '/' . $hrefParts[0], Stormpath::GROUP);
     $this->assertInstanceOf('\\Stormpath\\Resource\\Group', $group2);
     $this->assertEquals($href, $group2->href);
     $group->delete();
 }
 /**
  * @expectedException \Stormpath\Resource\ResourceError
  */
 public function testDelete()
 {
     $group = \Stormpath\Resource\Group::instantiate(array('name' => 'Deletable Group' . md5(time() . microtime() . uniqid())));
     self::$directory->createGroup($group);
     $group = \Stormpath\Resource\Group::get($group->href);
     $this->assertInstanceOf('\\Stormpath\\Resource\\Group', $group);
     $this->assertContains('Deletable Group', $group->name);
     $href = $group->href;
     $group->delete();
     \Stormpath\Resource\Group::get($href);
 }
 public function testCreateGroup()
 {
     $directory = self::$directory;
     $directory->status = 'enabled';
     $directory->save();
     $group = \Stormpath\Resource\Group::instantiate(array('name' => makeUniqueName('DirectoryTest createGroup')));
     $directory->createGroup($group);
     $group = \Stormpath\Resource\Group::get($group->href);
     $this->assertContains('Main_Directory', $group->directory->name);
     $this->assertContains('createGroup', $group->name);
     $group->delete();
 }
 public function testCreateGroup()
 {
     $directory = self::$directory;
     $directory->status = 'enabled';
     $directory->save();
     $group = \Stormpath\Resource\Group::instantiate(array('name' => 'New Group' . md5(time() . microtime() . uniqid())));
     $directory->createGroup($group);
     $group = \Stormpath\Resource\Group::get($group->href);
     $this->assertContains('Main Directory', $group->directory->name);
     $this->assertContains('New Group', $group->name);
     $group->delete();
 }