diff --git a/.travis.yml b/.travis.yml index 2494b07..f2f7956 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/README.md b/README.md index 131426f..898cd3c 100644 --- a/README.md +++ b/README.md @@ -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) | diff --git a/src/FacebookLogin.php b/src/FacebookLogin.php index 2731aaf..90d8710 100644 --- a/src/FacebookLogin.php +++ b/src/FacebookLogin.php @@ -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); } diff --git a/src/TwitterLogin.php b/src/TwitterLogin.php index 975f64b..638f9b9 100644 --- a/src/TwitterLogin.php +++ b/src/TwitterLogin.php @@ -3,6 +3,7 @@ namespace VencaX; +use Abraham; use Exception; use Nette; @@ -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; @@ -51,16 +49,6 @@ public function __construct( } - /** - * Set scope - * @param $scope - */ - public function setScope($scope) - { - $this->scope = $scope; - } - - /** * Get URL for login * @param string $callbackURL @@ -68,8 +56,13 @@ public function setScope($scope) */ 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']; @@ -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); diff --git a/tests/tests/Bootstrap.php b/tests/tests/Bootstrap.php new file mode 100644 index 0000000..153e7c8 --- /dev/null +++ b/tests/tests/Bootstrap.php @@ -0,0 +1,36 @@ +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; + } +} diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index 4e8044d..1963d93 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -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); @@ -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); @@ -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(); diff --git a/tests/tests/bootstrap.php b/tests/tests/bootstrap.php deleted file mode 100644 index 7dbdc79..0000000 --- a/tests/tests/bootstrap.php +++ /dev/null @@ -1,22 +0,0 @@ -setDebugMode(false); -$configurator->setTempDirectory(__DIR__ . '/temp'); -$configurator->createRobotLoader() - ->addDirectory(__DIR__ . '/../../src/') - ->register(); - -$configurator->addConfig(__DIR__ . '/config/config.neon'); - -return $configurator->createContainer();