Skip to content
Browse files

Applied changes for ZF-9743

  • Loading branch information...
1 parent 86d18c1 commit 3c65a54836868da9e2f0dc6f3a5af98a0d5b89e7 @AldemarBernal AldemarBernal committed May 31, 2012
View
54 documentation/manual/en/module_specs/Zend_View-Helpers-Doctype.xml
@@ -94,4 +94,58 @@ if ($view->doctype()->isHtml5()) {
}
]]></programlisting>
</example>
+
+ <example id="zend.view.helpers.initial.doctype.xhtml1_rdfa">
+ <title>Choosing a Doctype to Use with the Open Graph Protocol</title>
+
+ <para>
+ To implement the <ulink url="http://opengraphprotocol.org/">
+ Open Graph Protocol</ulink>, you may specify the XHTML1_RDFA doctype.
+ This doctype allows a developer to use the <ulink url="http://www.w3.org/TR/xhtml-rdfa-primer/">
+ Resource Description Framework</ulink> within an <acronym>XHTML</acronym> document.
+ </para>
+
+ <programlisting language="php"><![CDATA[
+$doctypeHelper = new Zend_View_Helper_Doctype();
+$doctypeHelper->doctype('XHTML1_RDFA');
+]]></programlisting>
+
+ <para>
+ The RDFa doctype allows XHTML to validate when the 'property'
+ meta tag attribute is used per the Open Graph Protocol spec. Example
+ within a view script:
+ </para>
+
+ <programlisting language="html"><![CDATA[
+<?php echo $this->doctype('XHTML1_RDFA'); ?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+xmlns:og="http://opengraphprotocol.org/schema/">
+<head>
+<meta property="og:type" content="musician" />
+]]></programlisting>
+
+ <para>
+ In the previous example, we set the property to og:type. The og references
+ the Open Graph namespace we specified in the html tag.
+ The content identifies the page as being about a musician. See
+ the <ulink url="http://opengraphprotocol.org/">Open Graph Protocol documentation</ulink>
+ for supported properties. The <link linkend="zend.view.helpers.initial.headmeta">HeadMeta helper</link>
+ may be used to programmatically set these Open Graph Protocol meta tags.
+ </para>
+
+ <para>
+ Here is how you check if the doctype is set to XHTML1_RDFA:
+ </para>
+
+ <programlisting language="php"><![CDATA[
+<?php echo $this->doctype() ?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+<?php if ($view->doctype()->isRdfa()): ?>
+xmlns:og="http://opengraphprotocol.org/schema/"
+xmlns:fb="http://www.facebook.com/2008/fbml"
+<?php endif; ?>
+>
+]]></programlisting>
+
+ </example>
</section>
View
34 documentation/manual/en/module_specs/Zend_View-Helpers-HeadMeta.xml
@@ -73,6 +73,37 @@
</itemizedlist>
<para>
+ The following methods are also supported with XHTML1_RDFA doctype
+ set with the <link linkend="zend.view.helpers.initial.doctype">Doctype helper</link>:
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ <command>appendProperty($property, $content, $modifiers)</command>
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ <command>offsetSetProperty($index, $property, $content, $modifiers)</command>
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ <command>prependProperty($property, $content, $modifiers)</command>
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ <command>setProperty($property, $content, $modifiers)</command>
+ </para>
+ </listitem>
+ </itemizedlist>
+
+ <para>
The <varname>$keyValue</varname> item is used to define a value for the 'name'
or 'http-equiv' key; <varname>$content</varname> is the value for the
'content' key, and <varname>$modifiers</varname> is an optional associative
@@ -85,7 +116,8 @@
$keyValue, $keyType = 'name', $modifiers = array(), $placement =
'APPEND')</command>. <varname>$keyValue</varname> is the content for the key
specified in <varname>$keyType</varname>, which should be either 'name' or
- 'http-equiv'. <varname>$placement</varname> can be either 'SET' (overwrites
+ 'http-equiv'. <varname>$keyType</varname> may also be specified as 'property' if the
+ doctype has been set to XHTML1_RDFA. <varname>$placement</varname> can be 'SET' (overwrites
all previously stored values), 'APPEND' (added to end of stack), or
'PREPEND' (added to top of stack).
</para>
View
6 library/Zend/View/Helper/Doctype.php
@@ -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';
@@ -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">',
@@ -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:
View
16 library/Zend/View/Helper/HeadMeta.php
@@ -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');
@@ -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',
@@ -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
@@ -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);
@@ -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;
}
View
2 tests/Zend/Form/View/Helper/FormInputTest.php
@@ -369,10 +369,10 @@ public function xhtmlDoctypes()
{
return array(
array('XHTML11'),
- array('XHTML_RDFA1'),
array('XHTML1_STRICT'),
array('XHTML1_TRANSITIONAL'),
array('XHTML1_FRAMESET'),
+ array('XHTML1_RDFA'),
array('XHTML_BASIC1'),
array('XHTML5'),
);
View
4 tests/Zend/View/Helper/DoctypeTest.php
@@ -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
);
@@ -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());
}
}
View
55 tests/Zend/View/Helper/HeadMetaTest.php
@@ -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
*/

0 comments on commit 3c65a54

Please sign in to comment.
Something went wrong with that request. Please try again.