class DrupalClientTest in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 tests/src/Unit/DrupalClientTest.php \Drupal\Tests\fb_instant_articles\Unit\DrupalClientTest
Test the Drupal FBIA client wrapper.
@group fb_instant_articles
@coversDefaultClass \Drupal\fb_instant_articles\DrupalClient
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\fb_instant_articles\Unit\DrupalClientTest
Expanded class hierarchy of DrupalClientTest
File
- tests/
src/ Unit/ DrupalClientTest.php, line 21
Namespace
Drupal\Tests\fb_instant_articles\UnitView source
class DrupalClientTest extends UnitTestCase {
protected $logger;
protected $serializer;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->serializer = $this
->createMock(NormalizerInterface::class);
$this->logger = $this
->createMock(LoggerChannelInterface::class);
}
/**
* Test the import entity method.
*
* @covers ::importEntity
*/
public function testImportEntity() {
$client = $this
->getMockBuilder(DrupalClient::class)
->disableOriginalConstructor()
->onlyMethods([
'importArticle',
])
->getMock();
$client
->setStringTranslation($this
->getStringTranslationStub());
$client
->setSerializer($this->serializer);
$client
->setLogger($this->logger);
$client
->expects($this
->once())
->method('importArticle')
->with($this
->isNull(), $this
->isTrue());
$client
->importEntity($this
->createMock(ContentEntityInterface::class));
// Test that importArticle is called with FALSE for an unpublished entity.
$client = $this
->getMockBuilder(DrupalClient::class)
->disableOriginalConstructor()
->onlyMethods([
'importArticle',
])
->getMock();
$client
->setStringTranslation($this
->getStringTranslationStub());
$client
->setSerializer($this->serializer);
$client
->setLogger($this->logger);
$client
->expects($this
->once())
->method('importArticle')
->with($this
->isNull(), $this
->isFalse());
$entity = $this
->getMockBuilder(NodeInterface::class)
->getMock();
$entity
->method('isPublished')
->willReturn(FALSE);
$client
->importEntity($entity);
}
/**
* Test the remove entity method.
*
* @covers ::removeEntity
*/
public function testRemoveEntity() {
// Test that removeArticle is called with the canonical URL from the
// iaNormalizer object.
$client = $this
->getMockBuilder(DrupalClient::class)
->disableOriginalConstructor()
->onlyMethods([
'removeArticle',
])
->getMock();
$ia_status = $this
->getMockBuilder(InstantArticleStatus::class)
->disableOriginalConstructor()
->getMock();
$client
->method('removeArticle')
->willReturn($ia_status);
$client
->setStringTranslation($this
->getStringTranslationStub());
$client
->setLogger($this->logger);
$ia_normalizer = $this
->getMockBuilder(InstantArticleContentEntityNormalizer::class)
->disableOriginalConstructor()
->getMock();
$ia_normalizer
->method('entityCanonicalUrl')
->willReturn('http://www.example.com/node/1');
$client
->setIaNormalizer($ia_normalizer);
$client
->expects($this
->once())
->method('removeArticle')
->with('http://www.example.com/node/1');
$client
->removeEntity($this
->createMock(ContentEntityInterface::class));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalClientTest:: |
protected | property | ||
DrupalClientTest:: |
protected | property | ||
DrupalClientTest:: |
protected | function |
Overrides UnitTestCase:: |
|
DrupalClientTest:: |
public | function | Test the import entity method. | |
DrupalClientTest:: |
public | function | Test the remove entity method. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |