diff --git a/src/Facebook/InstantArticles/Elements/Caption.php b/src/Facebook/InstantArticles/Elements/Caption.php index 8776f89a..e08d0813 100644 --- a/src/Facebook/InstantArticles/Elements/Caption.php +++ b/src/Facebook/InstantArticles/Elements/Caption.php @@ -37,6 +37,7 @@ class Caption extends FormattedText { // Font size + const SIZE_SMALL = 'op-small'; const SIZE_MEDIUM = 'op-medium'; const SIZE_LARGE = 'op-large'; const SIZE_XLARGE = 'op-extra-large'; @@ -72,7 +73,7 @@ class Caption extends FormattedText private $credit; /** - * @var string text Size. Values: "op-medium"|"op-large"|"op-extra-large" + * @var string text Size. Values: "op-small"|"op-medium"|"op-large"|"op-extra-large" */ private $fontSize; @@ -161,6 +162,7 @@ public function withCredit($credit) /** * The Fontsize that will be used. * + * @see Caption::SIZE_SMALL * @see Caption::SIZE_MEDIUM * @see Caption::SIZE_LARGE * @see Caption::SIZE_XLARGE @@ -176,7 +178,8 @@ public function withFontsize($font_size) [ Caption::SIZE_XLARGE, Caption::SIZE_LARGE, - Caption::SIZE_MEDIUM + Caption::SIZE_MEDIUM, + Caption::SIZE_SMALL ] ); $this->fontSize = $font_size; @@ -301,6 +304,7 @@ public function getCredit() /** * @return string the Font size. * + * @see Caption::SIZE_SMALL * @see Caption::SIZE_MEDIUM * @see Caption::SIZE_LARGE * @see Caption::SIZE_XLARGE diff --git a/src/Facebook/InstantArticles/Transformer/Rules/CaptionRule.php b/src/Facebook/InstantArticles/Transformer/Rules/CaptionRule.php index 03de4b87..070e0768 100644 --- a/src/Facebook/InstantArticles/Transformer/Rules/CaptionRule.php +++ b/src/Facebook/InstantArticles/Transformer/Rules/CaptionRule.php @@ -53,6 +53,7 @@ public static function createFrom($configuration) Caption::ALIGN_CENTER, Caption::ALIGN_RIGHT, + Caption::SIZE_SMALL, Caption::SIZE_MEDIUM, Caption::SIZE_LARGE, Caption::SIZE_XLARGE, @@ -90,6 +91,9 @@ public function apply($transformer, $container_of_caption, $node) $caption->withTextAlignment(Caption::ALIGN_RIGHT); } + if ($this->getProperty(Caption::SIZE_SMALL, $node)) { + $caption->withFontsize(Caption::SIZE_SMALL); + } if ($this->getProperty(Caption::SIZE_MEDIUM, $node)) { $caption->withFontsize(Caption::SIZE_MEDIUM); } diff --git a/src/Facebook/InstantArticles/Transformer/Rules/H1Rule.php b/src/Facebook/InstantArticles/Transformer/Rules/H1Rule.php index 41327ec3..2b259061 100644 --- a/src/Facebook/InstantArticles/Transformer/Rules/H1Rule.php +++ b/src/Facebook/InstantArticles/Transformer/Rules/H1Rule.php @@ -41,6 +41,7 @@ public static function createFrom($configuration) Caption::ALIGN_CENTER, Caption::ALIGN_RIGHT, + Caption::SIZE_SMALL, Caption::SIZE_MEDIUM, Caption::SIZE_LARGE, Caption::SIZE_XLARGE diff --git a/tests/Facebook/InstantArticles/Elements/CaptionTest.php b/tests/Facebook/InstantArticles/Elements/CaptionTest.php index 97c4ed01..336c627b 100644 --- a/tests/Facebook/InstantArticles/Elements/CaptionTest.php +++ b/tests/Facebook/InstantArticles/Elements/CaptionTest.php @@ -85,7 +85,7 @@ public function testRenderWithPosition() $this->assertEquals($expected, $rendered); } - public function testRenderWithFontSize() + public function testRenderWithLargeFontSize() { $caption = Caption::create() @@ -101,6 +101,22 @@ public function testRenderWithFontSize() $this->assertEquals($expected, $rendered); } + public function testRenderWithSmallFontSize() + { + $caption = + Caption::create() + ->appendText('Small Caption Title') + ->withFontsize(Caption::SIZE_SMALL); + + $expected = + '
'. + 'Small Caption Title'. + '
'; + + $rendered = $caption->render(); + $this->assertEquals($expected, $rendered); + } + public function testRenderWithTextAlignment() { $caption =