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 69 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Helper/HeadMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_View
*/

namespace Zend\View\Helper;
Expand All @@ -17,14 +18,16 @@
* Zend_Layout_View_Helper_HeadMeta
*
* @see http://www.w3.org/TR/xhtml1/dtds.html
* @package Zend_View
* @subpackage Helper
*/
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 +94,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 +128,7 @@ 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 @@ -198,6 +203,13 @@ protected function isValid($item)
|| (! $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()
Expand Down
55 changes: 55 additions & 0 deletions test/Helper/HeadMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,61 @@ public function testOverloadingSetPropertyOverwritesMetaTagStack()
$this->view->doctype('XHTML1_RDFA');
$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 915e77d

Please sign in to comment.