Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Applied changes for ZF-9743

  • Loading branch information...
commit 3c65a54836868da9e2f0dc6f3a5af98a0d5b89e7 1 parent 86d18c1
AldemarBernal AldemarBernal authored
54 documentation/manual/en/module_specs/Zend_View-Helpers-Doctype.xml
@@ -94,4 +94,58 @@ if ($view->doctype()->isHtml5()) {
94 94 }
95 95 ]]></programlisting>
96 96 </example>
  97 +
  98 + <example id="zend.view.helpers.initial.doctype.xhtml1_rdfa">
  99 + <title>Choosing a Doctype to Use with the Open Graph Protocol</title>
  100 +
  101 + <para>
  102 + To implement the <ulink url="http://opengraphprotocol.org/">
  103 + Open Graph Protocol</ulink>, you may specify the XHTML1_RDFA doctype.
  104 + This doctype allows a developer to use the <ulink url="http://www.w3.org/TR/xhtml-rdfa-primer/">
  105 + Resource Description Framework</ulink> within an <acronym>XHTML</acronym> document.
  106 + </para>
  107 +
  108 + <programlisting language="php"><![CDATA[
  109 +$doctypeHelper = new Zend_View_Helper_Doctype();
  110 +$doctypeHelper->doctype('XHTML1_RDFA');
  111 +]]></programlisting>
  112 +
  113 + <para>
  114 + The RDFa doctype allows XHTML to validate when the 'property'
  115 + meta tag attribute is used per the Open Graph Protocol spec. Example
  116 + within a view script:
  117 + </para>
  118 +
  119 + <programlisting language="html"><![CDATA[
  120 +<?php echo $this->doctype('XHTML1_RDFA'); ?>
  121 +<html xmlns="http://www.w3.org/1999/xhtml"
  122 +xmlns:og="http://opengraphprotocol.org/schema/">
  123 +<head>
  124 +<meta property="og:type" content="musician" />
  125 +]]></programlisting>
  126 +
  127 + <para>
  128 + In the previous example, we set the property to og:type. The og references
  129 + the Open Graph namespace we specified in the html tag.
  130 + The content identifies the page as being about a musician. See
  131 + the <ulink url="http://opengraphprotocol.org/">Open Graph Protocol documentation</ulink>
  132 + for supported properties. The <link linkend="zend.view.helpers.initial.headmeta">HeadMeta helper</link>
  133 + may be used to programmatically set these Open Graph Protocol meta tags.
  134 + </para>
  135 +
  136 + <para>
  137 + Here is how you check if the doctype is set to XHTML1_RDFA:
  138 + </para>
  139 +
  140 + <programlisting language="php"><![CDATA[
  141 +<?php echo $this->doctype() ?>
  142 +<html xmlns="http://www.w3.org/1999/xhtml"
  143 +<?php if ($view->doctype()->isRdfa()): ?>
  144 +xmlns:og="http://opengraphprotocol.org/schema/"
  145 +xmlns:fb="http://www.facebook.com/2008/fbml"
  146 +<?php endif; ?>
  147 +>
  148 +]]></programlisting>
  149 +
  150 + </example>
97 151 </section>
34 documentation/manual/en/module_specs/Zend_View-Helpers-HeadMeta.xml
@@ -73,6 +73,37 @@
73 73 </itemizedlist>
74 74
75 75 <para>
  76 + The following methods are also supported with XHTML1_RDFA doctype
  77 + set with the <link linkend="zend.view.helpers.initial.doctype">Doctype helper</link>:
  78 + </para>
  79 +
  80 + <itemizedlist>
  81 + <listitem>
  82 + <para>
  83 + <command>appendProperty($property, $content, $modifiers)</command>
  84 + </para>
  85 + </listitem>
  86 +
  87 + <listitem>
  88 + <para>
  89 + <command>offsetSetProperty($index, $property, $content, $modifiers)</command>
  90 + </para>
  91 + </listitem>
  92 +
  93 + <listitem>
  94 + <para>
  95 + <command>prependProperty($property, $content, $modifiers)</command>
  96 + </para>
  97 + </listitem>
  98 +
  99 + <listitem>
  100 + <para>
  101 + <command>setProperty($property, $content, $modifiers)</command>
  102 + </para>
  103 + </listitem>
  104 + </itemizedlist>
  105 +
  106 + <para>
76 107 The <varname>$keyValue</varname> item is used to define a value for the 'name'
77 108 or 'http-equiv' key; <varname>$content</varname> is the value for the
78 109 'content' key, and <varname>$modifiers</varname> is an optional associative
@@ -85,7 +116,8 @@
85 116 $keyValue, $keyType = 'name', $modifiers = array(), $placement =
86 117 'APPEND')</command>. <varname>$keyValue</varname> is the content for the key
87 118 specified in <varname>$keyType</varname>, which should be either 'name' or
88   - 'http-equiv'. <varname>$placement</varname> can be either 'SET' (overwrites
  119 + 'http-equiv'. <varname>$keyType</varname> may also be specified as 'property' if the
  120 + doctype has been set to XHTML1_RDFA. <varname>$placement</varname> can be 'SET' (overwrites
89 121 all previously stored values), 'APPEND' (added to end of stack), or
90 122 'PREPEND' (added to top of stack).
91 123 </para>
6 library/Zend/View/Helper/Doctype.php
@@ -39,10 +39,10 @@ class Doctype extends AbstractHelper
39 39 * DocType constants
40 40 */
41 41 const XHTML11 = 'XHTML11';
42   - const XHTML1_RDFA1 = 'XHTML_RDFA1';
43 42 const XHTML1_STRICT = 'XHTML1_STRICT';
44 43 const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL';
45 44 const XHTML1_FRAMESET = 'XHTML1_FRAMESET';
  45 + const XHTML1_RDFA = 'XHTML1_RDFA';
46 46 const XHTML_BASIC1 = 'XHTML_BASIC1';
47 47 const XHTML5 = 'XHTML5';
48 48 const HTML4_STRICT = 'HTML4_STRICT';
@@ -82,10 +82,10 @@ public function __construct()
82 82 $this->_registry = new ArrayObject(array(
83 83 'doctypes' => array(
84 84 self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
85   - self::XHTML1_RDFA1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
86 85 self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
87 86 self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
88 87 self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
  88 + self::XHTML1_RDFA => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
89 89 self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
90 90 self::XHTML5 => '<!DOCTYPE html>',
91 91 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)
114 114 if (null !== $doctype) {
115 115 switch ($doctype) {
116 116 case self::XHTML11:
117   - case self::XHTML1_RDFA1:
118 117 case self::XHTML1_STRICT:
119 118 case self::XHTML1_TRANSITIONAL:
120 119 case self::XHTML1_FRAMESET:
  120 + case self::XHTML1_RDFA:
121 121 case self::XHTML_BASIC1:
122 122 case self::XHTML5:
123 123 case self::HTML4_STRICT:
16 library/Zend/View/Helper/HeadMeta.php
@@ -39,7 +39,7 @@ class HeadMeta extends Placeholder\Container\Standalone
39 39 * Types of attributes
40 40 * @var array
41 41 */
42   - protected $_typeKeys = array('name', 'http-equiv', 'charset');
  42 + protected $_typeKeys = array('name', 'http-equiv', 'charset', 'property');
43 43 protected $_requiredKeys = array('content');
44 44 protected $_modifierKeys = array('lang', 'scheme');
45 45
@@ -105,6 +105,8 @@ protected function _normalizeType($type)
105 105 return 'name';
106 106 case 'HttpEquiv':
107 107 return 'http-equiv';
  108 + case 'Property':
  109 + return 'property';
108 110 default:
109 111 throw new Exception\DomainException(sprintf(
110 112 'Invalid type "%s" passed to _normalizeType',
@@ -125,6 +127,10 @@ protected function _normalizeType($type)
125 127 * - offsetGetHttpEquiv($index, $keyValue, $content, $modifers = array())
126 128 * - prependHttpEquiv($keyValue, $content, $modifiers = array())
127 129 * - setHttpEquiv($keyValue, $content, $modifiers = array())
  130 + * - appendProperty($keyValue, $content, $modifiers = array())
  131 + * - offsetGetProperty($index, $keyValue, $content, $modifiers = array())
  132 + * - prependProperty($keyValue, $content, $modifiers = array())
  133 + * - setProperty($keyValue, $content, $modifiers = array())
128 134 *
129 135 * @param string $method
130 136 * @param array $args
@@ -133,7 +139,7 @@ protected function _normalizeType($type)
133 139 */
134 140 public function __call($method, $args)
135 141 {
136   - if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv)$/', $method, $matches)) {
  142 + if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property)$/', $method, $matches)) {
137 143 $action = $matches['action'];
138 144 $type = $this->_normalizeType($matches['type']);
139 145 $argc = count($args);
@@ -209,6 +215,12 @@ protected function _isValid($item)
209 215 return false;
210 216 }
211 217
  218 + // <meta property= ... /> is only supported with doctype RDFa
  219 + if (!$this->view->plugin('doctype')->isRdfa()
  220 + && $item->type === 'property') {
  221 + return false;
  222 + }
  223 +
212 224 return true;
213 225 }
214 226
2  tests/Zend/Form/View/Helper/FormInputTest.php
@@ -369,10 +369,10 @@ public function xhtmlDoctypes()
369 369 {
370 370 return array(
371 371 array('XHTML11'),
372   - array('XHTML_RDFA1'),
373 372 array('XHTML1_STRICT'),
374 373 array('XHTML1_TRANSITIONAL'),
375 374 array('XHTML1_FRAMESET'),
  375 + array('XHTML1_RDFA'),
376 376 array('XHTML_BASIC1'),
377 377 array('XHTML5'),
378 378 );
4 tests/Zend/View/Helper/DoctypeTest.php
@@ -100,7 +100,7 @@ public function testIsXhtmlReturnsTrueForXhtmlDoctypes()
100 100 Helper\Doctype::XHTML1_STRICT,
101 101 Helper\Doctype::XHTML1_TRANSITIONAL,
102 102 Helper\Doctype::XHTML1_FRAMESET,
103   - Helper\Doctype::XHTML1_RDFA1,
  103 + Helper\Doctype::XHTML1_RDFA,
104 104 Helper\Doctype::XHTML5
105 105 );
106 106
@@ -217,7 +217,7 @@ public function testIsRdfaReturnsTrueForRdfaDoctype()
217 217 $this->assertFalse($this->helper->__invoke($type)->isRdfa());
218 218 }
219 219
220   - $this->assertTrue($this->helper->__invoke(Helper\Doctype::XHTML1_RDFA1)->isRdfa());
  220 + $this->assertTrue($this->helper->__invoke(Helper\Doctype::XHTML1_RDFA)->isRdfa());
221 221 }
222 222 }
223 223
55 tests/Zend/View/Helper/HeadMetaTest.php
@@ -438,6 +438,61 @@ public function testCharset()
438 438 $view->plugin('headMeta')->toString());
439 439 }
440 440
  441 + /**
  442 + * @group ZF-9743
  443 + */
  444 + public function testPropertyIsSupportedWithRdfaDoctype()
  445 + {
  446 + $this->view->doctype('XHTML1_RDFA');
  447 + $this->helper->__invoke('foo', 'og:title', 'property');
  448 + $this->assertEquals('<meta property="og:title" content="foo" />',
  449 + $this->helper->toString()
  450 + );
  451 + }
  452 +
  453 + /**
  454 + * @group ZF-9743
  455 + */
  456 + public function testPropertyIsNotSupportedByDefaultDoctype()
  457 + {
  458 + try {
  459 + $this->helper->__invoke('foo', 'og:title', 'property');
  460 + $this->fail('meta property attribute should not be supported on default doctype');
  461 + } catch (ViewException $e) {
  462 + $this->assertContains('Invalid value passed', $e->getMessage());
  463 + }
  464 + }
  465 +
  466 + /**
  467 + * @group ZF-9743
  468 + * @depends testPropertyIsSupportedWithRdfaDoctype
  469 + */
  470 + public function testOverloadingAppendPropertyAppendsMetaTagToStack()
  471 + {
  472 + $this->view->doctype('XHTML1_RDFA');
  473 + $this->_testOverloadAppend('property');
  474 + }
  475 +
  476 + /**
  477 + * @group ZF-9743
  478 + * @depends testPropertyIsSupportedWithRdfaDoctype
  479 + */
  480 + public function testOverloadingPrependPropertyPrependsMetaTagToStack()
  481 + {
  482 + $this->view->doctype('XHTML1_RDFA');
  483 + $this->_testOverloadPrepend('property');
  484 + }
  485 +
  486 + /**
  487 + * @group ZF-9743
  488 + * @depends testPropertyIsSupportedWithRdfaDoctype
  489 + */
  490 + public function testOverloadingSetPropertyOverwritesMetaTagStack()
  491 + {
  492 + $this->view->doctype('XHTML1_RDFA');
  493 + $this->_testOverloadSet('property');
  494 + }
  495 +
441 496 /**
442 497 * @group ZF-11835
443 498 */

0 comments on commit 3c65a54

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