WeWorkProviderTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the overtrue/socialite.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. use Overtrue\Socialite\Providers\WeWorkProvider;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. class WeWorkProviderTest extends TestCase
  14. {
  15. public function testQrConnect()
  16. {
  17. $response = (new WeWorkProvider(Request::create('foo'), [
  18. 'client_id' => 'ww100000a5f2191',
  19. 'client_secret' => 'client_secret',
  20. 'redirect' => 'http://www.oa.com',
  21. ]))
  22. ->setAgentId('1000000')
  23. ->stateless()
  24. ->redirect();
  25. $this->assertSame('https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=ww100000a5f2191&agentid=1000000&redirect_uri=http%3A%2F%2Fwww.oa.com', $response->getTargetUrl());
  26. }
  27. public function testOAuthWithAgentId()
  28. {
  29. $response = (new WeWorkProvider(Request::create('foo'), [
  30. 'client_id' => 'CORPID',
  31. 'client_secret' => 'client_secret',
  32. 'redirect' => 'REDIRECT_URI',
  33. ]))
  34. ->scopes(['snsapi_base'])
  35. ->setAgentId('1000000')
  36. ->stateless()
  37. ->redirect();
  38. $this->assertSame('https://open.weixin.qq.com/connect/oauth2/authorize?appid=CORPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_base&agentid=1000000#wechat_redirect', $response->getTargetUrl());
  39. }
  40. public function testOAuthWithoutAgentId()
  41. {
  42. $response = (new WeWorkProvider(Request::create('foo'), [
  43. 'client_id' => 'CORPID',
  44. 'client_secret' => 'client_secret',
  45. 'redirect' => 'REDIRECT_URI',
  46. ]))
  47. ->scopes(['snsapi_base'])
  48. ->stateless()
  49. ->redirect();
  50. $this->assertSame('https://open.weixin.qq.com/connect/oauth2/authorize?appid=CORPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_base#wechat_redirect', $response->getTargetUrl());
  51. }
  52. }