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

Commit

Permalink
Merge remote-tracking branch 'AldemarBernal/feature/opengraph'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Jun 1, 2012
6 parents d2649e3 + f0162d1 + 6f01416 + a2b3753 + 1786961 + 905ecbc commit d157fcb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Helper/Doctype.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class Doctype extends AbstractHelper
* DocType constants
*/
const XHTML11 = 'XHTML11';
const XHTML1_RDFA1 = 'XHTML_RDFA1';
const XHTML1_STRICT = 'XHTML1_STRICT';
const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL';
const XHTML1_FRAMESET = 'XHTML1_FRAMESET';
const XHTML1_RDFA = 'XHTML1_RDFA';
const XHTML_BASIC1 = 'XHTML_BASIC1';
const XHTML5 = 'XHTML5';
const HTML4_STRICT = 'HTML4_STRICT';
Expand Down Expand Up @@ -82,10 +82,10 @@ public function __construct()
$this->_registry = new ArrayObject(array(
'doctypes' => array(
self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
self::XHTML1_RDFA1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
self::XHTML1_RDFA => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
self::XHTML5 => '<!DOCTYPE html>',
self::HTML4_STRICT => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
Expand Down Expand Up @@ -114,10 +114,10 @@ public function __invoke($doctype = null)
if (null !== $doctype) {
switch ($doctype) {
case self::XHTML11:
case self::XHTML1_RDFA1:
case self::XHTML1_STRICT:
case self::XHTML1_TRANSITIONAL:
case self::XHTML1_FRAMESET:
case self::XHTML1_RDFA:
case self::XHTML_BASIC1:
case self::XHTML5:
case self::HTML4_STRICT:
Expand Down
16 changes: 14 additions & 2 deletions src/Helper/HeadMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HeadMeta extends Placeholder\Container\Standalone
* Types of attributes
* @var array
*/
protected $_typeKeys = array('name', 'http-equiv', 'charset');
protected $_typeKeys = array('name', 'http-equiv', 'charset', 'property');
protected $_requiredKeys = array('content');
protected $_modifierKeys = array('lang', 'scheme');

Expand Down Expand Up @@ -105,6 +105,8 @@ protected function _normalizeType($type)
return 'name';
case 'HttpEquiv':
return 'http-equiv';
case 'Property':
return 'property';
default:
throw new Exception\DomainException(sprintf(
'Invalid type "%s" passed to _normalizeType',
Expand All @@ -125,6 +127,10 @@ protected function _normalizeType($type)
* - offsetGetHttpEquiv($index, $keyValue, $content, $modifers = array())
* - prependHttpEquiv($keyValue, $content, $modifiers = array())
* - setHttpEquiv($keyValue, $content, $modifiers = array())
* - appendProperty($keyValue, $content, $modifiers = array())
* - offsetGetProperty($index, $keyValue, $content, $modifiers = array())
* - prependProperty($keyValue, $content, $modifiers = array())
* - setProperty($keyValue, $content, $modifiers = array())
*
* @param string $method
* @param array $args
Expand All @@ -133,7 +139,7 @@ protected function _normalizeType($type)
*/
public function __call($method, $args)
{
if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv)$/', $method, $matches)) {
if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property)$/', $method, $matches)) {
$action = $matches['action'];
$type = $this->_normalizeType($matches['type']);
$argc = count($args);
Expand Down Expand Up @@ -209,6 +215,12 @@ protected function _isValid($item)
return false;
}

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

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions test/Helper/DoctypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testIsXhtmlReturnsTrueForXhtmlDoctypes()
Helper\Doctype::XHTML1_STRICT,
Helper\Doctype::XHTML1_TRANSITIONAL,
Helper\Doctype::XHTML1_FRAMESET,
Helper\Doctype::XHTML1_RDFA1,
Helper\Doctype::XHTML1_RDFA,
Helper\Doctype::XHTML5
);

Expand Down Expand Up @@ -217,7 +217,7 @@ public function testIsRdfaReturnsTrueForRdfaDoctype()
$this->assertFalse($this->helper->__invoke($type)->isRdfa());
}

$this->assertTrue($this->helper->__invoke(Helper\Doctype::XHTML1_RDFA1)->isRdfa());
$this->assertTrue($this->helper->__invoke(Helper\Doctype::XHTML1_RDFA)->isRdfa());
}
}

55 changes: 55 additions & 0 deletions test/Helper/HeadMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,61 @@ public function testCharset()
$view->plugin('headMeta')->toString());
}

/**
* @group ZF-9743
*/
public function testPropertyIsSupportedWithRdfaDoctype()
{
$this->view->doctype('XHTML1_RDFA');
$this->helper->__invoke('foo', 'og:title', 'property');
$this->assertEquals('<meta property="og:title" content="foo" />',
$this->helper->toString()
);
}

/**
* @group ZF-9743
*/
public function testPropertyIsNotSupportedByDefaultDoctype()
{
try {
$this->helper->__invoke('foo', 'og:title', 'property');
$this->fail('meta property attribute should not be supported on default doctype');
} catch (ViewException $e) {
$this->assertContains('Invalid value passed', $e->getMessage());
}
}

/**
* @group ZF-9743
* @depends testPropertyIsSupportedWithRdfaDoctype
*/
public function testOverloadingAppendPropertyAppendsMetaTagToStack()
{
$this->view->doctype('XHTML1_RDFA');
$this->_testOverloadAppend('property');
}

/**
* @group ZF-9743
* @depends testPropertyIsSupportedWithRdfaDoctype
*/
public function testOverloadingPrependPropertyPrependsMetaTagToStack()
{
$this->view->doctype('XHTML1_RDFA');
$this->_testOverloadPrepend('property');
}

/**
* @group ZF-9743
* @depends testPropertyIsSupportedWithRdfaDoctype
*/
public function testOverloadingSetPropertyOverwritesMetaTagStack()
{
$this->view->doctype('XHTML1_RDFA');
$this->_testOverloadSet('property');
}

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

0 comments on commit d157fcb

Please sign in to comment.