class TagViewTest in Doubleclick for Publishers (DFP) 8
@coversDefaultClass \Drupal\dfp\View\TagView @group dfp
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\dfp\Unit\View\TagViewTest
Expanded class hierarchy of TagViewTest
File
- tests/
src/ Unit/ View/ TagViewTest.php, line 20 - Contains \Drupal\Tests\dfp\Unit\View\TagViewTest.
Namespace
Drupal\Tests\dfp\Unit\ViewView source
class TagViewTest extends UnitTestCase {
/**
* @covers ::formatSize
* @dataProvider formatSizeProvider
*/
public function testFormatSize($size, $expected) {
$this
->assertSame($expected, TagView::formatSize($size));
}
/**
* Data provider for self::testFormatSize().
*/
public function formatSizeProvider() {
return [
[
'<none>',
'[]',
],
[
'fluid',
"'fluid'",
],
[
'300x250 ',
'[300, 250]',
],
[
'300x250, 728x90 ',
'[[300, 250], [728, 90]]',
],
[
'300x250, 728x90, fluid',
"[[300, 250], [728, 90], 'fluid']",
],
];
}
/**
* @covers ::getSlug
* @dataProvider getSlugProvider
*/
public function testGetSlug($tag_slug, $default_slug, $expected_slug) {
$tag = $this
->prophesize(TagInterface::class);
$tag
->slug()
->willReturn($tag_slug);
$config_factory = $this
->getConfigFactoryStub([
'dfp.settings' => [
'default_slug' => $default_slug,
],
]);
$token = $this
->prophesize(TokenInterface::class)
->reveal();
$module_handler = $this
->prophesize(ModuleHandlerInterface::class)
->reveal();
$tag_view = new TagView($tag
->reveal(), $config_factory
->get('dfp.settings'), $token, $module_handler);
$this
->assertSame($expected_slug, $tag_view
->getSlug());
}
/**
* Data provider for self::testGetSlug().
*/
public function getSlugProvider() {
return [
[
'slug',
'default_slug',
'slug',
],
[
'',
'default_slug',
'default_slug',
],
[
'<none>',
'default_slug',
'',
],
];
}
/**
* @covers ::getAdUnit
* @dataProvider getAdUnitProvider
*/
public function testGetAdUnit($tag_ad_unit, $default_ad_unit, $network_id, $expected_adunit) {
$tag = $this
->prophesize(TagInterface::class);
$tag
->adunit()
->willReturn($tag_ad_unit);
$config_factory = $this
->getConfigFactoryStub([
'dfp.settings' => [
'adunit_pattern' => $default_ad_unit,
'network_id' => $network_id,
],
]);
$token = $this
->createMock(TokenInterface::class);
$token
->method('replace')
->willReturnArgument(0);
$module_handler = $this
->prophesize(ModuleHandlerInterface::class)
->reveal();
$tag_view = new TagView($tag
->reveal(), $config_factory
->get('dfp.settings'), $token, $module_handler);
$this
->assertSame($expected_adunit, $tag_view
->getAdUnit());
}
/**
* Data provider for self::testGetAdUnit().
*/
public function getAdUnitProvider() {
return [
[
'adunit',
'default_adunit',
'12345',
'/12345/adunit',
],
[
'',
'default_adunit',
'67890',
'/67890/default_adunit',
],
];
}
/**
* @covers ::getShortTagQueryString
* @dataProvider getShortTagQueryStringProvider
*/
public function testGetShortTagQueryString($tag_ad_unit, $tag_sizes, $tag_targeting, $network_id, $regex) {
$tag = $this
->prophesize(TagInterface::class);
$tag
->adunit()
->willReturn($tag_ad_unit);
$tag
->size()
->willReturn($tag_sizes);
$tag
->targeting()
->willReturn($tag_targeting);
$config_factory = $this
->getConfigFactoryStub([
'dfp.settings' => [
'adunit_pattern' => 'default_adunit',
'network_id' => $network_id,
],
]);
$token = $this
->createMock(TokenInterface::class);
$token
->method('replace')
->willReturnArgument(0);
$module_handler = $this
->prophesize(ModuleHandlerInterface::class)
->reveal();
$tag_view = new TagView($tag
->reveal(), $config_factory
->get('dfp.settings'), $token, $module_handler);
$this
->assertRegExp($regex, $tag_view
->getShortTagQueryString());
}
/**
* Data provider for self::testGetShortTagQueryString().
*/
public function getShortTagQueryStringProvider() {
return [
[
'adunit',
'300x200',
[],
'12345',
'|^iu=/12345/adunit&sz=300x200&c=[0-9]{5}$|',
],
[
'adunit',
'300x200',
[
[
'target' => 'target',
'value' => 'value,value2',
],
],
'12345',
'|^iu=/12345/adunit&sz=300x200&c=[0-9]{5}&t=target%3Dvalue%2Cvalue2$|',
],
[
'adunit',
'300x200',
[
[
'target' => 'target',
'value' => 'value,value2',
],
[
'target' => 'target2',
'value' => 'value3',
],
],
'12345',
'|^iu=/12345/adunit&sz=300x200&c=[0-9]{5}&t=target%3Dvalue%2Cvalue2%26target2%3Dvalue3$|',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
TagViewTest:: |
public | function | Data provider for self::testFormatSize(). | |
TagViewTest:: |
public | function | Data provider for self::testGetAdUnit(). | |
TagViewTest:: |
public | function | Data provider for self::testGetShortTagQueryString(). | |
TagViewTest:: |
public | function | Data provider for self::testGetSlug(). | |
TagViewTest:: |
public | function | @covers ::formatSize @dataProvider formatSizeProvider | |
TagViewTest:: |
public | function | @covers ::getAdUnit @dataProvider getAdUnitProvider | |
TagViewTest:: |
public | function | @covers ::getShortTagQueryString @dataProvider getShortTagQueryStringProvider | |
TagViewTest:: |
public | function | @covers ::getSlug @dataProvider getSlugProvider | |
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 | Mocks a block with a block plugin. | 1 |
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:: |
protected | function | 340 |