You are here

class SimpleFbConnectFbFactoryTest in Simple FB Connect 8.3

@coversDefaultClass Drupal\simple_fb_connect\SimpleFbConnectFbFactory @group simple_fb_connect

Hierarchy

Expanded class hierarchy of SimpleFbConnectFbFactoryTest

File

tests/src/Unit/SimpleFbConnectFbFactoryTest.php, line 12

Namespace

Drupal\Tests\simple_fb_connect\Unit
View source
class SimpleFbConnectFbFactoryTest extends UnitTestCase {
  protected $configFactory;
  protected $loggerFactory;
  protected $persistentDataHandler;
  protected $fbFactory;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->loggerFactory = $this
      ->getMock('Drupal\\Core\\Logger\\LoggerChannelFactoryInterface');
    $this->persistentDataHandler = $this
      ->getMockBuilder('Drupal\\simple_fb_connect\\SimpleFbConnectPersistentDataHandler')
      ->disableOriginalConstructor()
      ->getMock();
  }

  /**
   * Creates mocks with desired configFactory parameters.
   */
  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);
  }

  /**
   * Tests getFbService when app ID and app Secrete have been set.
   *
   * @covers ::getFbService
   * @covers ::validateConfig
   * @covers ::getAppId
   * @covers ::getAppSecret
   */
  public function testGetFbServiceWithGoodData() {
    $this
      ->finalizeSetup('123', 'abc');
    $this
      ->assertInstanceOf('Facebook\\Facebook', $this->fbFactory
      ->getFbService());
  }

  /**
   * Tests getFbService with bad data.
   *
   * @covers ::getFbService
   * @covers ::validateConfig
   * @covers ::getAppId
   * @covers ::getAppSecret
   *
   * @dataProvider getFbServiceBadDataProvider
   */
  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());
  }

  /**
   * Data provider for testLoginUser().
   *
   * @return array
   *   Nested arrays of values to check.
   *
   * @see ::testLoginuser()
   */
  public function getFbServiceBadDataProvider() {
    return [
      [
        NULL,
        NULL,
      ],
      [
        '',
        '',
      ],
      [
        '123',
        NULL,
      ],
      [
        NULL,
        'abc',
      ],
      [
        '123',
        '',
      ],
      [
        NULL,
        '',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
SimpleFbConnectFbFactoryTest::$configFactory protected property
SimpleFbConnectFbFactoryTest::$fbFactory protected property
SimpleFbConnectFbFactoryTest::$loggerFactory protected property
SimpleFbConnectFbFactoryTest::$persistentDataHandler protected property
SimpleFbConnectFbFactoryTest::finalizeSetup protected function Creates mocks with desired configFactory parameters.
SimpleFbConnectFbFactoryTest::getFbServiceBadDataProvider public function Data provider for testLoginUser().
SimpleFbConnectFbFactoryTest::setUp protected function Overrides UnitTestCase::setUp
SimpleFbConnectFbFactoryTest::testGetFbServiceWithBadData public function Tests getFbService with bad data.
SimpleFbConnectFbFactoryTest::testGetFbServiceWithGoodData public function Tests getFbService when app ID and app Secrete have been set.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.