Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from silverstripe-iterators/pulls/tests
Added some unit tests
- Loading branch information
Showing
3 changed files
with
133 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details | ||
|
||
language: php | ||
php: | ||
- 5.3 | ||
|
||
env: | ||
- DB=MYSQL CORE_RELEASE=3.1 | ||
- DB=PGSQL CORE_RELEASE=master | ||
|
||
matrix: | ||
include: | ||
- php: 5.4 | ||
env: DB=MYSQL CORE_RELEASE=master | ||
|
||
before_script: | ||
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support | ||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss | ||
- cd ~/builds/ss | ||
|
||
script: | ||
- phpunit opauth/tests/unit/ |
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
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
class OpauthIdentityTest extends SapphireTest { | ||
|
||
protected $usesDatabase = true; | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
|
||
Config::inst()->update('OpauthIdentity', 'member_mapper', array( | ||
'Facebook' => array( | ||
'FirstName' => 'info.first_name', | ||
'Surname' => 'info.last_name', | ||
'Locale' => 'raw.locale', | ||
) | ||
)); | ||
} | ||
|
||
public function testFindOrCreateMemberLinkOnMatch() { | ||
$member = new Member(array('Email' => 'existing@test.com')); | ||
$member->write(); | ||
|
||
$identity = OpauthIdentity::factory(array( | ||
'auth' => array( | ||
'provider' => 'Facebook', | ||
'uid' => 999, | ||
'info' => array('email' => 'existing@test.com') | ||
) | ||
)); | ||
$identity->findOrCreateMember(array('linkOnMatch' => false)); | ||
$this->assertEquals(0, $identity->MemberID, 'Does not link unless requested'); | ||
|
||
$identity = OpauthIdentity::factory(array( | ||
'auth' => array( | ||
'provider' => 'Facebook', | ||
'uid' => 999, | ||
'info' => array('email' => 'existing@test.com') | ||
) | ||
)); | ||
$identity->findOrCreateMember(array('linkOnMatch' => true)); | ||
$this->assertEquals( | ||
$member->ID, | ||
$identity->MemberID, | ||
'Links if requested and email matches' | ||
); | ||
|
||
$identity = OpauthIdentity::factory(array( | ||
'auth' => array( | ||
'provider' => 'Facebook', | ||
'uid' => 999, | ||
'info' => array('email' => 'new@test.com') | ||
) | ||
)); | ||
$identity->findOrCreateMember(array('linkOnMatch' => true)); | ||
$this->assertEquals(0, $identity->MemberID, 'Does not link if requested but no member found'); | ||
} | ||
|
||
public function testFindOrCreateMemberOverwriteExistingFields() { | ||
$member = new Member(array( | ||
'Email' => 'existing@test.com', | ||
'FirstName' => 'Existing', | ||
'Surname' => 'Existing', | ||
)); | ||
$member->write(); | ||
|
||
$identity = OpauthIdentity::factory(array( | ||
'auth' => array( | ||
'provider' => 'Facebook', | ||
'uid' => 999, | ||
'info' => array( | ||
'email' => 'existing@test.com', | ||
'first_name' => 'New', | ||
'last_name' => 'New' | ||
) | ||
) | ||
)); | ||
$member = $identity->findOrCreateMember(array('overwriteExistingFields' => false)); | ||
$this->assertEquals( | ||
'Existing', | ||
$member->FirstName, | ||
'Does not overwrite unless requested' | ||
); | ||
|
||
$identity = OpauthIdentity::factory(array( | ||
'auth' => array( | ||
'provider' => 'Facebook', | ||
'uid' => 999, | ||
'info' => array( | ||
'email' => 'existing@test.com', | ||
'first_name' => 'New', | ||
'last_name' => 'New' | ||
) | ||
) | ||
)); | ||
$member = $identity->findOrCreateMember(array('overwriteExistingFields' => array( | ||
'FirstName' | ||
))); | ||
$this->assertEquals( | ||
'New', | ||
$member->FirstName, | ||
'Overwrites existing fields if requested' | ||
); | ||
$this->assertEquals( | ||
'Existing', | ||
$member->Surname, | ||
'Does not overwrite fields if not present in whitelist' | ||
); | ||
} | ||
|
||
} |