View source
<?php
namespace Drupal\Tests\simple_fb_connect\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\simple_fb_connect\SimpleFbConnectFbFactory;
class SimpleFbConnectFbFactoryTest extends UnitTestCase {
protected $configFactory;
protected $loggerFactory;
protected $persistentDataHandler;
protected $fbFactory;
protected function setUp() {
parent::setUp();
$this->loggerFactory = $this
->getMock('Drupal\\Core\\Logger\\LoggerChannelFactoryInterface');
$this->persistentDataHandler = $this
->getMockBuilder('Drupal\\simple_fb_connect\\SimpleFbConnectPersistentDataHandler')
->disableOriginalConstructor()
->getMock();
}
protected function finalizeSetup($app_id, $app_secret) {
$this->configFactory = $this
->getConfigFactoryStub([
'simple_fb_connect.settings' => [
'app_id' => $app_id,
'app_secret' => $app_secret,
],
]);
$this->fbFactory = new SimpleFbConnectFbFactory($this->configFactory, $this->loggerFactory, $this->persistentDataHandler);
}
public function testGetFbServiceWithGoodData() {
$this
->finalizeSetup('123', 'abc');
$this
->assertInstanceOf('Facebook\\Facebook', $this->fbFactory
->getFbService());
}
public function testGetFbServiceWithBadData($app_id, $app_secret) {
$logger_channel = $this
->getMockBuilder('Drupal\\Core\\Logger\\LoggerChannel')
->disableOriginalConstructor()
->getMock();
$this->loggerFactory
->expects($this
->any())
->method('get')
->with('simple_fb_connect')
->willReturn($logger_channel);
$this
->finalizeSetup($app_id, $app_secret);
$this
->assertFalse($this->fbFactory
->getFbService());
}
public function getFbServiceBadDataProvider() {
return [
[
NULL,
NULL,
],
[
'',
'',
],
[
'123',
NULL,
],
[
NULL,
'abc',
],
[
'123',
'',
],
[
NULL,
'',
],
];
}
}