Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/Helper/HeadMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HeadMeta extends Placeholder\Container\AbstractStandalone
* Types of attributes
* @var array
*/
protected $typeKeys = array('name', 'http-equiv', 'charset', 'property');
protected $typeKeys = array('name', 'http-equiv', 'charset', 'property', 'itemprop');
protected $requiredKeys = array('content');
protected $modifierKeys = array('lang', 'scheme');

Expand Down Expand Up @@ -91,6 +91,8 @@ protected function normalizeType($type)
return 'http-equiv';
case 'Property':
return 'property';
case 'Itemprop':
return 'itemprop';
default:
throw new Exception\DomainException(sprintf(
'Invalid type "%s" passed to normalizeType',
Expand Down Expand Up @@ -123,7 +125,11 @@ protected function normalizeType($type)
*/
public function __call($method, $args)
{
if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property)$/', $method, $matches)) {
if (preg_match(
'/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property|Itemprop)$/',
$method,
$matches)
) {
$action = $matches['action'];
$type = $this->normalizeType($matches['type']);
$argc = count($args);
Expand Down Expand Up @@ -169,10 +175,10 @@ public function __call($method, $args)
*/
public function setCharset($charset)
{
$item = new stdClass;
$item->type = 'charset';
$item->charset = $charset;
$item->content = null;
$item = new stdClass;
$item->type = 'charset';
$item->charset = $charset;
$item->content = null;
$item->modifiers = array();
$this->set($item);
return $this;
Expand All @@ -188,20 +194,29 @@ protected function isValid($item)
{
if ((!$item instanceof stdClass)
|| !isset($item->type)
|| !isset($item->modifiers))
{
|| !isset($item->modifiers)
) {
return false;
}

if (!isset($item->content)
&& (! $this->view->plugin('doctype')->isHtml5()
|| (! $this->view->plugin('doctype')->isHtml5() && $item->type !== 'charset'))) {
&& (! $this->view->plugin('doctype')->isHtml5()
|| (! $this->view->plugin('doctype')->isHtml5() && $item->type !== 'charset'))
) {
return false;
}

// <meta itemprop= ... /> is only supported with doctype html
if (! $this->view->plugin('doctype')->isHtml5()
&& $item->type === 'itemprop'
) {
return false;
}

// <meta property= ... /> is only supported with doctype RDFa
if (!$this->view->plugin('doctype')->isRdfa()
&& $item->type === 'property') {
&& $item->type === 'property'
) {
return false;
}

Expand Down
55 changes: 55 additions & 0 deletions test/Helper/HeadMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,61 @@ public function testOverloadingSetPropertyOverwritesMetaTagStack()
$this->_testOverloadSet('property');
}

/**
* @issue 3751
*/
public function testItempropIsSupportedWithHtml5Doctype()
{
$this->view->doctype('HTML5');
$this->helper->__invoke('HeadMeta with Microdata', 'description', 'itemprop');
$this->assertEquals('<meta itemprop="description" content="HeadMeta with Microdata">',
$this->helper->toString()
);
}

/**
* @issue 3751
*/
public function testItempropIsNotSupportedByDefaultDoctype()
{
try {
$this->helper->__invoke('HeadMeta with Microdata', 'description', 'itemprop');
$this->fail('meta itemprop attribute should not be supported on default doctype');
} catch (ViewException $e) {
$this->assertContains('Invalid value passed', $e->getMessage());
}
}

/**
* @issue 3751
* @depends testItempropIsSupportedWithHtml5Doctype
*/
public function testOverloadingAppendItempropAppendsMetaTagToStack()
{
$this->view->doctype('HTML5');
$this->_testOverloadAppend('itemprop');
}

/**
* @issue 3751
* @depends testItempropIsSupportedWithHtml5Doctype
*/
public function testOverloadingPrependItempropPrependsMetaTagToStack()
{
$this->view->doctype('HTML5');
$this->_testOverloadPrepend('itemprop');
}

/**
* @issue 3751
* @depends testItempropIsSupportedWithHtml5Doctype
*/
public function testOverloadingSetItempropOverwritesMetaTagStack()
{
$this->view->doctype('HTML5');
$this->_testOverloadSet('itemprop');
}

/**
* @group ZF-11835
*/
Expand Down

0 comments on commit e7eef3c

Please sign in to comment.