Просмотр исходного кода

Added extra method to Doctype helper to test if RDFa is being used. Added test and documentation. See ZF-10796

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23538 44c647ce-9c0f-0410-b52a-842ac1e357ba
gammamatrix 15 лет назад
Родитель
Сommit
8f493fa4a4

+ 20 - 1
documentation/manual/en/module_specs/Zend_View-Helpers-Doctype.xml

@@ -117,7 +117,8 @@ $doctypeHelper->doctype('XHTML1_RDFA');
         </para>
 
         <programlisting language="html"><![CDATA[
-$doctype = $view->doctype()->getDoctype();
+<?php echo $this->doctype() ?>
+
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml">
 ]]></programlisting>
 
@@ -138,6 +139,24 @@ $doctype = $view->doctype()->getDoctype();
             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.
         </para>
 
+        <para>
+            Here is who you check if the doctype includes <acronym>RFDa</acronym> in the document.
+        </para>
+
+        <programlisting language="php"><![CDATA[
+<?php echo $this->doctype() ?>
+
+<?php if ($view->doctype()->isRdfa()): ?>
+
+    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml">
+
+<?php else: ?>
+
+    <html xmlns="http://www.w3.org/1999/xhtml">
+
+<?php endif; ?>
+]]></programlisting>
+        
     </example>
 </sect3>
 <!--

+ 9 - 0
library/Zend/View/Helper/Doctype.php

@@ -198,6 +198,15 @@ class Zend_View_Helper_Doctype extends Zend_View_Helper_Abstract
     public function isHtml5() {
         return (stristr($this->doctype(), '<!DOCTYPE html>') ? true : false);
     }
+    
+    /**
+     * Is doctype RDFa?
+     *
+     * @return booleean
+     */
+    public function isRdfa() {
+        return (stristr($this->getDoctype(), 'rdfa') ? true : false);
+    }
 
     /**
      * String representation of doctype

+ 16 - 0
tests/Zend/View/Helper/DoctypeTest.php

@@ -155,6 +155,22 @@ class Zend_View_Helper_DoctypeTest extends PHPUnit_Framework_TestCase
 		}
 	}
 
+    public function testIsRdfa()
+    {
+        $doctype = $this->helper->doctype('XHTML1_RDFA');
+        $this->assertTrue($doctype->isRdfa());
+
+        // built-in doctypes
+        foreach (array('HTML4_STRICT', 'HTML4_LOOSE', 'HTML4_FRAMESET', 'XHTML1_STRICT', 'XHTML1_TRANSITIONAL', 'XHTML1_FRAMESET') as $type) {
+            $doctype = $this->helper->doctype($type);
+            $this->assertFalse($doctype->isRdfa());
+        }
+
+        // custom doctype
+        $doctype = $this->helper->doctype('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 10.0 Strict//EN" "http://framework.zend.com/foo/DTD/html10-custom.dtd">');
+        $this->assertFalse($doctype->isRdfa());
+    }
+
 	public function testCanRegisterCustomHtml5Doctype() {
 		$doctype = $this->helper->doctype('<!DOCTYPE html>');
         $this->assertEquals('CUSTOM', $doctype->getDoctype());