Skip to content

Commit

Permalink
Merge 1ebd3b4 into a941b37
Browse files Browse the repository at this point in the history
  • Loading branch information
venca-x committed Mar 12, 2021
2 parents a941b37 + 1ebd3b4 commit aad4176
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 54 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ jobs:
- travis_retry composer create-project nette/code-checker temp/code-checker --no-progress
# Install Nette Coding Standard
- travis_retry composer create-project nette/coding-standard temp/coding-standard --no-progress

script:
- php temp/code-checker/code-checker -d src -d tests --short-arrays --strict-types
- php temp/coding-standard/ecs check src tests --preset php71


- stage: Code Coverage
php: 7.4
script:
- vendor/bin/tester -p phpdbg tests -s --coverage ./coverage.xml --coverage-src ./src
after_script:
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v1.0.1/coveralls.phar
- php coveralls.phar --verbose --config tests/.coveralls.yml


allow_failures:
- stage: Code Coverage
- env: title="Lowest Dependencies"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Nette addon for login with social networks
| Version | Facebook App API | PHP | Recommended Nette |
| --- | --- | --- | --- |
| dev-master | 8.0 or own | \>= 7.2 | Nette 3.0 |
| 1.2.x | 8.0 or own | \>= 7.1 | Nette 3.0 |
| 1.2.x | 8.0 or own | \>= 7.2 | Nette 3.0 |
| 1.1.x | 2.6 | \>= 7.0 | Nette 2.4 (Nette\SmartObject) |
| 1.0.x | 2.6 | \>= 5.5 | Nette 2.4, 2.3 (Nette\Object) |

Expand Down
3 changes: 1 addition & 2 deletions src/FacebookLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ public function setState($state)
*/
public function getLoginUrl()
{
$loginUrl = $this->helper->getLoginUrl($this->callBackUrl, $this->scope);
return $loginUrl;
return $this->helper->getLoginUrl($this->callBackUrl, $this->scope);
}


Expand Down
27 changes: 10 additions & 17 deletions src/TwitterLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace VencaX;

use Abraham;
use Exception;
use Nette;

Expand All @@ -15,15 +16,12 @@ class TwitterLogin extends BaseLogin
{
public const SOCIAL_NAME = 'twitter';

/** @var \TwitterOAuth */
/** @var Abraham\TwitterOAuth\TwitterOAuth */
private $twitterOAuth;

/** @var array Request token */
private $requestToken;

/** @var string scope */
private $scope = '';

/** @var Nette\Http\Session session */
private $session;

Expand Down Expand Up @@ -51,25 +49,20 @@ public function __construct(
}


/**
* Set scope
* @param $scope
*/
public function setScope($scope)
{
$this->scope = $scope;
}


/**
* Get URL for login
* @param string $callbackURL
* @return string URL login
*/
public function getLoginUrl()
{
$this->twitterOAuth = new \TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret']);
$this->requestToken = $this->twitterOAuth->getRequestToken($this->params['callbackURL']);
$this->twitterOAuth = new Abraham\TwitterOAuth\TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret']);
$this->requestToken = $this->twitterOAuth->oauth(
'oauth/request_token',
[
'oauth_callback' => $this->params['callbackURL'],
]
);

$sessionSection = $this->session->getSection('twitter');
$sessionSection->oauth_token = $token = $this->requestToken['oauth_token'];
Expand Down Expand Up @@ -97,7 +90,7 @@ public function getMe($oauthToken, $oauthVerifier)
}

//Create TwitteroAuth object with app key/secret and token key/secret from default phase
$this->twitterOAuth = new \TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret'], $sessionSection->oauth_token, $sessionSection->oauth_token_secret);
$this->twitterOAuth = new Abraham\TwitterOAuth\TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret'], $sessionSection->oauth_token, $sessionSection->oauth_token_secret);

//Request access tokens from twitter
$access_token = $this->twitterOAuth->getAccessToken($oauthVerifier);
Expand Down
36 changes: 36 additions & 0 deletions tests/tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Test;

use Nette\Configurator;


class Bootstrap
{
public static function boot(): Configurator
{
$configurator = new Configurator;

$configurator->setTimeZone('Europe/Prague');
$configurator->setTempDirectory(__DIR__ . '/temp');

$configurator->createRobotLoader()
->addDirectory(__DIR__ . '/../../src/')
->register();

$configurator
->addConfig(__DIR__ . '/config/config.neon');

return $configurator;
}


public static function bootForTests(): Configurator
{
$configurator = self::boot();
\Tester\Environment::setup();
return $configurator;
}
}
39 changes: 31 additions & 8 deletions tests/tests/InstanceTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ declare(strict_types=1);

namespace Test;

use Abraham;
use Nette;
use Tester;
use Tester\Assert;
use VencaX;

require __DIR__ . '/../../vendor/autoload.php';

class InstanceTest extends Tester\TestCase
{
/** @var VencaX\SocialLogin */
private $container;

private $socialLogin;


public function __construct(Nette\DI\Container $container)
{
$this->container = $container;
}


public function setUp()
{
$container = require __DIR__ . '/bootstrap.php';
$this->socialLogin = $container->getByType('VencaX\SocialLogin');
$this->socialLogin = $this->container->getByType('VencaX\SocialLogin');
}


public function testFacebookLoginUrl()
{
$this->socialLogin->facebook->setScope(['email']);
$this->socialLogin->facebook->setState('https://www.mypage.cz/sign/facebook');

$url = $this->socialLogin->facebook->getLoginUrl();

$urlParseArray = parse_url($url);
Expand All @@ -39,12 +49,16 @@ class InstanceTest extends Tester\TestCase
Assert::same('123456789', $urlParseQueryArray['client_id']);
Assert::same('code', $urlParseQueryArray['response_type']);
Assert::same('http://www.muj-web.cz/homepage/facebook-login', $urlParseQueryArray['redirect_uri']);
//Assert::same('', $urlParseQueryArray['scope']);
Assert::same('email', $urlParseQueryArray['scope']);
Assert::same('https://www.mypage.cz/sign/facebook', $urlParseQueryArray['state']);
}


public function testGoogleLoginUrl()
{
$this->socialLogin->google->setScope(['https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/userinfo.email']);
$this->socialLogin->google->setState('https://www.mypage.cz/sign/google');

$url = $this->socialLogin->google->getLoginUrl();

$urlParseArray = parse_url($url);
Expand All @@ -61,16 +75,25 @@ class InstanceTest extends Tester\TestCase
Assert::same('online', $urlParseQueryArray['access_type']);
Assert::same('123456789', $urlParseQueryArray['client_id']);
Assert::same('http://www.muj-web.cz/homepage/google-login', $urlParseQueryArray['redirect_uri']);
Assert::same('https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email', $urlParseQueryArray['scope']);
Assert::same('https://www.mypage.cz/sign/google', $urlParseQueryArray['state']);
}


public function testTwitterLoginUrl()
{
//$url = $this->socialLogin->twitter->getLoginUrl();
//Assert::same(false, $this->socialLogin->twitter->getSocialLoginCookie());
Assert::exception(function () {
$this->socialLogin->twitter->getLoginUrl();
}, Abraham\TwitterOAuth\TwitterOAuthException::class, '{"errors":[{"code":32,"message":"Could not authenticate you."}]}');

Assert::same(false, $this->socialLogin->twitter->isThisServiceLastLogin());
}
}

$test = new InstanceTest;
require __DIR__ . '/Bootstrap.php';

$container = \Test\Bootstrap::bootForTests()
->createContainer();

$test = new InstanceTest($container);
$test->run();
22 changes: 0 additions & 22 deletions tests/tests/bootstrap.php

This file was deleted.

0 comments on commit aad4176

Please sign in to comment.