init
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace HybridauthTest\Hybridauth\Data;
|
||||
|
||||
use Hybridauth\Data\Collection;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function some_random_id()
|
||||
{
|
||||
return 69;
|
||||
}
|
||||
|
||||
public function some_random_year()
|
||||
{
|
||||
return 2020;
|
||||
}
|
||||
|
||||
public function some_random_array()
|
||||
{
|
||||
return ['id' => 69, 'slugs' => ['Γεια σας', 'Bonjour', '안녕하세요', 'year' => 2020]];
|
||||
}
|
||||
|
||||
public function some_random_object()
|
||||
{
|
||||
$object = new \StdClass();
|
||||
$object->id = 69;
|
||||
$object->slugs = ['Γεια σας', 'Bonjour', '안녕하세요', 'year' => 2020];
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function test_instance_of()
|
||||
{
|
||||
$collection = new Collection();
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection);
|
||||
}
|
||||
|
||||
public function test_identity()
|
||||
{
|
||||
$array = $this->some_random_array();
|
||||
|
||||
$collection = new Collection($array);
|
||||
|
||||
$result = $collection->toArray();
|
||||
|
||||
$this->assertEquals($result, $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Collection::exists
|
||||
*/
|
||||
public function test_exists()
|
||||
{
|
||||
$array = $this->some_random_array();
|
||||
|
||||
$collection = new Collection($array);
|
||||
|
||||
$this->assertTrue($collection->exists('id'));
|
||||
|
||||
$this->assertFalse($collection->exists('_non_existant_'));
|
||||
|
||||
//
|
||||
|
||||
$object = $this->some_random_object();
|
||||
|
||||
$collection = new Collection($object);
|
||||
|
||||
$this->assertTrue($collection->exists('id'));
|
||||
|
||||
$this->assertFalse($collection->exists('_non_existant_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Collection::get
|
||||
*/
|
||||
public function test_get()
|
||||
{
|
||||
$array = $this->some_random_array();
|
||||
|
||||
$collection = new Collection($array);
|
||||
|
||||
$this->assertEquals($collection->get('id'), $this->some_random_id());
|
||||
|
||||
$this->assertNull($collection->get('_non_existant_'));
|
||||
|
||||
//
|
||||
|
||||
$object = $this->some_random_object();
|
||||
|
||||
$collection = new Collection($object);
|
||||
|
||||
$this->assertEquals($collection->get('id'), $this->some_random_id());
|
||||
|
||||
$this->assertNull($collection->get('_non_existant_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Collection::filter
|
||||
*/
|
||||
public function test_filter()
|
||||
{
|
||||
$array = $this->some_random_array();
|
||||
|
||||
$collection = new Collection($array);
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('id'));
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('slugs'));
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('_non_existant_'));
|
||||
|
||||
$this->assertNull($collection->filter('slugs')->get('_non_existant_'));
|
||||
|
||||
$this->assertEquals($collection->filter('slugs')->get('year'), $this->some_random_year());
|
||||
|
||||
//
|
||||
|
||||
$object = $this->some_random_object();
|
||||
|
||||
$collection = new Collection($object);
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('id'));
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('slugs'));
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('_non_existant_'));
|
||||
|
||||
$this->assertNull($collection->filter('slugs')->get('_non_existant_'));
|
||||
|
||||
$this->assertEquals($collection->filter('slugs')->get('year'), $this->some_random_year());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace HybridauthTest\Hybridauth\Data;
|
||||
|
||||
use Hybridauth\Data\Parser;
|
||||
|
||||
class ParserTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test_instance_of()
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\Data\\Parser', $parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Parser::parse
|
||||
* @covers Parser::parseJson
|
||||
*/
|
||||
public function test_parser_json()
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$object = new \StdClass();
|
||||
$object->id = 69;
|
||||
$object->slugs = ['Γεια σας', 'Bonjour', '안녕하세요'];
|
||||
|
||||
$json = json_encode($object);
|
||||
|
||||
//
|
||||
|
||||
$result = $parser->parse($json);
|
||||
|
||||
$this->assertInstanceOf('\\StdClass', $result);
|
||||
|
||||
$this->assertEquals($result, $object);
|
||||
|
||||
//
|
||||
|
||||
$result = $parser->parseJson($json);
|
||||
|
||||
$this->assertInstanceOf('\\StdClass', $result);
|
||||
|
||||
$this->assertEquals($result, $object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Parser::parse
|
||||
* @covers Parser::parseQueryString
|
||||
*/
|
||||
public function test_parser_querystring()
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$object = new \StdClass();
|
||||
$object->id = 69;
|
||||
$object->slug = 'oauth';
|
||||
|
||||
$string = 'id=69&slug=oauth';
|
||||
|
||||
//
|
||||
|
||||
$result = $parser->parse($string);
|
||||
|
||||
$this->assertInstanceOf('\\StdClass', $result);
|
||||
|
||||
$this->assertEquals($result, $object);
|
||||
|
||||
//
|
||||
|
||||
$result = $parser->parseQueryString($string);
|
||||
|
||||
$this->assertInstanceOf('\\StdClass', $result);
|
||||
|
||||
$this->assertEquals($result, $object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace HybridauthTest\Hybridauth;
|
||||
|
||||
use Hybridauth\Hybridauth;
|
||||
|
||||
class HybridauthTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test_pass()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace HybridauthTest\Hybridauth\Storage;
|
||||
|
||||
use Hybridauth\Storage\Session;
|
||||
|
||||
session_start(); // they will hate me for this..
|
||||
|
||||
class SessionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function some_random_session_data()
|
||||
{
|
||||
return [
|
||||
['foo', 'bar'],
|
||||
[1234, 'bar'],
|
||||
['foo', 1234],
|
||||
|
||||
['Bonjour', '안녕하세요'],
|
||||
['ஹலோ', 'Γεια σας'],
|
||||
|
||||
['array', [1, 2, 3]],
|
||||
['string', json_encode($this)],
|
||||
['object', $this],
|
||||
|
||||
['provider.token.request_token', '9DYPEJ&qhvhP3eJ!'],
|
||||
['provider.token.oauth_token', '80359084-clg1DEtxQF3wstTcyUdHF3wsdHM'],
|
||||
['provider.token.oauth_token_secret', 'qiHTi1znz6qiH3tTcyUdHnz6qiH3tTcyUdH3xW3wsDvV08e'],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_instance_of()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\Storage\\StorageInterface', $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider some_random_session_data
|
||||
* @covers Session::get
|
||||
* @covers Session::set
|
||||
*/
|
||||
public function test_set_and_get_data($key, $value)
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->set($key, $value);
|
||||
|
||||
$data = $storage->get($key);
|
||||
|
||||
$this->assertEquals($value, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider some_random_session_data
|
||||
* @covers Session::delete
|
||||
*/
|
||||
public function test_delete_data($key, $value)
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->set($key, $value);
|
||||
|
||||
$storage->delete($key);
|
||||
|
||||
$data = $storage->get($key);
|
||||
|
||||
$this->assertNull($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider some_random_session_data
|
||||
* @covers Session::clear
|
||||
*/
|
||||
public function test_clear_data($key, $value)
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->set($key, $value);
|
||||
|
||||
$storage->clear();
|
||||
|
||||
$data = $storage->get($key);
|
||||
|
||||
$this->assertNull($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Session::clear
|
||||
*/
|
||||
public function test_clear_data_bulk()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
foreach ((array)$this->some_random_session_data() as $key => $value) {
|
||||
$storage->set($key, $value);
|
||||
}
|
||||
|
||||
$storage->clear();
|
||||
|
||||
foreach ((array)$this->some_random_session_data() as $key => $value) {
|
||||
$data = $storage->get($key);
|
||||
|
||||
$this->assertNull($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider some_random_session_data
|
||||
* @covers Session::deleteMatch
|
||||
*/
|
||||
public function test_delete_match_data($key, $value)
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->set($key, $value);
|
||||
|
||||
$storage->deleteMatch('provider.token.');
|
||||
|
||||
$data = $storage->get('provider.token.request_token');
|
||||
|
||||
$this->assertNull($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace HybridauthTest\Hybridauth\User;
|
||||
|
||||
use Hybridauth\User\Activity;
|
||||
|
||||
class ActivityTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test_instance_of()
|
||||
{
|
||||
$activity = new Activity();
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\User\\Activity', $activity);
|
||||
}
|
||||
|
||||
public function test_has_attributes()
|
||||
{
|
||||
$activity_class = '\\Hybridauth\\User\\Activity';
|
||||
|
||||
$this->assertClassHasAttribute('id', $activity_class);
|
||||
$this->assertClassHasAttribute('date', $activity_class);
|
||||
$this->assertClassHasAttribute('text', $activity_class);
|
||||
$this->assertClassHasAttribute('user', $activity_class);
|
||||
}
|
||||
|
||||
public function test_set_attributes()
|
||||
{
|
||||
$activity = new Activity();
|
||||
|
||||
$activity->id = true;
|
||||
$activity->date = true;
|
||||
$activity->text = true;
|
||||
$activity->user = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Hybridauth\Exception\UnexpectedValueException
|
||||
*/
|
||||
public function test_property_overloading()
|
||||
{
|
||||
$activity = new Activity();
|
||||
$activity->slug = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace HybridauthTest\Hybridauth\User;
|
||||
|
||||
use Hybridauth\User\Contact;
|
||||
|
||||
class ContactTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test_instance_of()
|
||||
{
|
||||
$contact = new Contact();
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\User\\Contact', $contact);
|
||||
}
|
||||
|
||||
public function test_has_attributes()
|
||||
{
|
||||
$contact_class = '\\Hybridauth\\User\\Contact';
|
||||
|
||||
$this->assertClassHasAttribute('identifier', $contact_class);
|
||||
$this->assertClassHasAttribute('webSiteURL', $contact_class);
|
||||
$this->assertClassHasAttribute('profileURL', $contact_class);
|
||||
$this->assertClassHasAttribute('photoURL', $contact_class);
|
||||
$this->assertClassHasAttribute('displayName', $contact_class);
|
||||
$this->assertClassHasAttribute('description', $contact_class);
|
||||
$this->assertClassHasAttribute('email', $contact_class);
|
||||
}
|
||||
|
||||
public function test_set_attributes()
|
||||
{
|
||||
$contact = new Contact();
|
||||
|
||||
$contact->identifier = true;
|
||||
$contact->webSiteURL = true;
|
||||
$contact->profileURL = true;
|
||||
$contact->photoURL = true;
|
||||
$contact->displayName = true;
|
||||
$contact->description = true;
|
||||
$contact->email = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Hybridauth\Exception\UnexpectedValueException
|
||||
*/
|
||||
public function test_property_overloading()
|
||||
{
|
||||
$contact = new Contact();
|
||||
$contact->slug = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace HybridauthTest\Hybridauth\User;
|
||||
|
||||
use Hybridauth\User\Profile;
|
||||
|
||||
class ProfileTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test_instance_of()
|
||||
{
|
||||
$profile = new Profile();
|
||||
|
||||
$this->assertInstanceOf('\\Hybridauth\\User\\Profile', $profile);
|
||||
}
|
||||
|
||||
public function test_has_attributes()
|
||||
{
|
||||
$profile_class = '\\Hybridauth\\User\\Profile';
|
||||
|
||||
$this->assertClassHasAttribute('identifier', $profile_class);
|
||||
$this->assertClassHasAttribute('webSiteURL', $profile_class);
|
||||
$this->assertClassHasAttribute('profileURL', $profile_class);
|
||||
$this->assertClassHasAttribute('photoURL', $profile_class);
|
||||
$this->assertClassHasAttribute('displayName', $profile_class);
|
||||
$this->assertClassHasAttribute('firstName', $profile_class);
|
||||
$this->assertClassHasAttribute('lastName', $profile_class);
|
||||
$this->assertClassHasAttribute('description', $profile_class);
|
||||
$this->assertClassHasAttribute('gender', $profile_class);
|
||||
$this->assertClassHasAttribute('language', $profile_class);
|
||||
$this->assertClassHasAttribute('age', $profile_class);
|
||||
$this->assertClassHasAttribute('birthDay', $profile_class);
|
||||
$this->assertClassHasAttribute('birthMonth', $profile_class);
|
||||
$this->assertClassHasAttribute('birthYear', $profile_class);
|
||||
$this->assertClassHasAttribute('email', $profile_class);
|
||||
$this->assertClassHasAttribute('emailVerified', $profile_class);
|
||||
$this->assertClassHasAttribute('phone', $profile_class);
|
||||
$this->assertClassHasAttribute('address', $profile_class);
|
||||
$this->assertClassHasAttribute('country', $profile_class);
|
||||
$this->assertClassHasAttribute('region', $profile_class);
|
||||
$this->assertClassHasAttribute('city', $profile_class);
|
||||
$this->assertClassHasAttribute('zip', $profile_class);
|
||||
}
|
||||
|
||||
public function test_set_attributes()
|
||||
{
|
||||
$profile = new Profile();
|
||||
|
||||
$profile->identifier = true;
|
||||
$profile->webSiteURL = true;
|
||||
$profile->profileURL = true;
|
||||
$profile->photoURL = true;
|
||||
$profile->displayName = true;
|
||||
$profile->firstName = true;
|
||||
$profile->lastName = true;
|
||||
$profile->description = true;
|
||||
$profile->gender = true;
|
||||
$profile->language = true;
|
||||
$profile->age = true;
|
||||
$profile->birthDay = true;
|
||||
$profile->birthMonth = true;
|
||||
$profile->birthYear = true;
|
||||
$profile->email = true;
|
||||
$profile->emailVerified = true;
|
||||
$profile->phone = true;
|
||||
$profile->address = true;
|
||||
$profile->country = true;
|
||||
$profile->region = true;
|
||||
$profile->city = true;
|
||||
$profile->zip = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Hybridauth\Exception\UnexpectedValueException
|
||||
*/
|
||||
public function test_property_overloading()
|
||||
{
|
||||
$profile = new Profile();
|
||||
$profile->slug = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user