public function OauthTest::setUp in Media: Acquia DAM 8
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ OauthTest.php, line 77
Class
- OauthTest
- Oauth test.
Namespace
Drupal\Tests\media_acquiadam\UnitCode
public function setUp() {
parent::setUp();
$csrf_token = $this
->getMockBuilder(CsrfTokenGenerator::class)
->disableOriginalConstructor()
->getMock();
$csrf_token
->expects($this
->any())
->method('get')
->willReturn('testToken112233');
$csrf_token
->expects($this
->any())
->method('validate')
->withAnyParameters()
->willReturn(FALSE);
$csrf_token
->expects($this
->any())
->method('validate')
->with('testToken112233')
->willReturn(TRUE);
$url_generator = $this
->getMockBuilder(UrlGeneratorInterface::class)
->disableOriginalConstructor()
->getMock();
$url_generator
->expects($this
->any())
->method('generateFromRoute')
->willReturn('some/url/test');
$unrouted_url_assembler = $this
->getMockBuilder(UnroutedUrlAssemblerInterface::class)
->disableOriginalConstructor()
->getMock();
// @BUG: Forcing the UnroutedUrlAssembler return here forces a pass.
// UnroutedUrlAssembler is called by toString() in setAuthFinishRedirect
// and is overly complicated to mock/replace.
$unrouted_url_assembler
->expects($this
->any())
->method('assemble')
->willReturn('https://example.com/sub/path?extra=1');
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getBody')
->willReturn('{"access_token":"ACCESS_TOKEN", "token_type":"bearer", "expires_in":3600, "refresh_token": "refresh_token"}');
$http_client = $this
->getMockBuilder(GuzzleClient::class)
->disableOriginalConstructor()
->setMethods([
'post',
])
->getMock();
$http_client
->expects($this
->any())
->method('post')
->willReturn($response);
$current_user = $this
->getMockBuilder(AccountProxyInterface::class)
->disableOriginalConstructor()
->getMock();
$this->container = new ContainerBuilder();
$this->container
->set('string_translation', $this
->getStringTranslationStub());
$this->container
->set('config.factory', $this
->getConfigFactoryStub());
$this->container
->set('csrf_token', $csrf_token);
$this->container
->set('unrouted_url_assembler', $unrouted_url_assembler);
$this->container
->set('url_generator.non_bubbling', $url_generator);
$this->container
->set('http_client', $http_client);
$this->container
->set('logger.factory', $this
->getLoggerFactoryStub());
$this->container
->set('current_user', $current_user);
\Drupal::setContainer($this->container);
$this->oAuthClient = Oauth::create($this->container);
}