Skip to content

Commit

Permalink
Merge pull request #11 from silverstripe-iterators/pulls/tests
Browse files Browse the repository at this point in the history
Added some unit tests
  • Loading branch information
willmorgan committed Feb 25, 2014
2 parents 28c24b8 + 77e60f4 commit 5dae3e3
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .travis.yml
@@ -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/
2 changes: 2 additions & 0 deletions README.md
@@ -1,5 +1,7 @@
# SilverStripe Opauth Module

[![Build Status](https://secure.travis-ci.org/BetterBrief/silverstripe-opauth.png?branch=master)](http://travis-ci.org/BetterBrief/silverstripe-opauth)

## Introduction
Uses the [Opauth library](http://opauth.org) for easy drop-in strategies for social login. See their [documentation](https://github.com/opauth/opauth/wiki/)

Expand Down
109 changes: 109 additions & 0 deletions tests/unit/OpauthIdentityTest.php
@@ -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'
);
}

}

0 comments on commit 5dae3e3

Please sign in to comment.