Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SocialTest extends TestCase{
- /** @var \PB\Interfaces\SocialInterface */
- public $social;
- /** @var \PB\Social\Connector */
- public $connector;
- protected function prepareForTests(){
- parent::prepareForTests();
- $this->social = App::make('PB\Interfaces\SocialInterface');
- $this->connector = App::make('PB\Social\Connector');
- }
- public function testStoreRead(){
- $user = $this->getNewUser();
- $item = new \PB\Social\types\Facebook;
- $item->userId = $user->id;
- $item->id = 123;
- $item->firstName = 'Martin';
- $item->lastName = 'Briedis';
- $this->social->store($item);
- $byUserId = $this->social->getByUserId($item->userId);
- $this->assertEquals($item::TYPE, $byUserId[$item::TYPE]::TYPE);
- $this->assertEquals($item->id, $byUserId[$item::TYPE]->id);
- $this->assertEquals($item->userId, $byUserId[$item::TYPE]->userId);
- $byType = $this->social->getBySocial($item::TYPE, $item->id);
- $this->assertEquals($byType->userId, $item->userId);
- // Update
- $item->firstName = 'edited';
- $this->social->store($item);
- $newItem = $this->social->getBySocial($item::TYPE, $item->id);
- $this->assertEquals($item->firstName, $newItem->firstName);
- }
- public function testNewUserFromSocial(){
- $item = new \PB\Social\types\Facebook();
- $item->id = 1000;
- $item->email = uniqid() . '@test.com';
- $connectResult = $this->connector->connect($item);
- $this->assertEquals(true, $connectResult, 'Successfully connected');
- $this->assertTrue($item->getUser() instanceof User, 'New user has been created');
- $this->assertEquals($item->getUser()->id, Sentry::getUser()->getId(), 'User logged in');
- $this->assertTrue($item->getUser()->isClient, 'Must be client by default');
- $item2 = $this->social->getByUserIdType($item->userId, $item::TYPE);
- $this->assertEquals($item2->id, $item->id, 'Connection stored');
- }
- public function testExistingLogin(){
- $user = $this->getNewUser();
- $item = new \PB\Social\types\Facebook;
- $item->id = 10000;
- $item->userId = $user->id;
- $item->email = $user->email;
- $this->social->store($item);
- $item2 = new \PB\Social\types\Facebook;
- $item2->id = $item->id;
- $item2->email = $user->email;
- $connectResult = $this->connector->connect($item2);
- $this->assertTrue($connectResult);
- $this->assertEquals($user->id, Sentry::getUser()->getId());
- }
- public function testExistingUserConnect(){
- $user = $this->getNewUser();
- Sentry::login($user);
- $item = new \PB\Social\types\Facebook;
- $item->userId = $user->id;
- $item->id = time();
- $connectResult = $this->connector->connect($item);
- $this->assertTrue($connectResult);
- $fromDb = $this->social->getByUserIdType($user->id, $item::TYPE);
- $this->assertEquals($user->id, $fromDb->userId);
- }
- public function testUserWithEmailAlreadyRegistered(){
- $user = $this->getNewUser(uniqid("", true) . '@test.lv');
- $item = new \PB\Social\types\Facebook;
- $item->id = microtime();
- $item->email = $user->email;
- $this->setExpectedException('Cartalyst\Sentry\Users\UserExistsException');
- $this->connector->connect($item);
- }
- public function testReceivePointsThenRegisterSocialAccount(){
- /** @var \PB\Interfaces\TransactionInterface $transactions */
- $transactions = App::make('PB\Interfaces\TransactionInterface');
- /** @var \PB\Interfaces\ClientInterface $clients */
- $clients = App::make('PB\Interfaces\ClientInterface');
- $email = uniqid() . '@test.com';
- $shop = $this->getNewShop();
- $client = $clients->getOrCreateClient($email, 0);
- $points = 15;
- $shop->addPoints($points, Currency::EUR);
- $transactions->givePoints($client->id, $shop->id, $points, Currency::EUR);
- // Now create a new account
- $item = new \PB\Social\types\Facebook;
- $item->email = $email;
- $item->id = 12345;
- $re = $this->connector->connect($item);
- $this->assertTrue($re);
- /** @var User $user */
- $user = Sentry::getUser();
- $this->assertTrue($user->isClient);
- $this->assertEquals($user->client->pointAmount(Currency::EUR) - Client::REGISTRATION_BONUS, $points);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement