Ver Fonte

[1.11] Promote Zend_View_Helper_Gravatar to trunk

- Merged in Zend_View_Helper_Gravatar from incubator
  - Updated document structure to make it valid

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23080 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew há 15 anos atrás
pai
commit
13507f69a8

+ 150 - 0
documentation/manual/en/module_specs/Zend_View-Helpers-Gravatar.xml

@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect3 id="zend.view.helpers.initial.gravatar">
+    <title>Gravatar View Helper</title>
+
+    <para>
+        The <classname>Gravatar</classname> view helper is used to received avatars from Gravatar's
+        service.
+    </para>
+
+    <example id="zend.view.helpers.initial.gravatar.usage">
+        <title>Basic Usage of Gravatar View Helper</title>
+
+        <programlisting language="php"><![CDATA[
+// From a view script (using XHTML DOCTYPE):
+echo $this->gravatar('example@example.com');
+
+/* results in the following output:
+    <img src="http://www.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8?s=80&d=mm&r=g" />
+ */
+]]></programlisting>
+    </example>
+
+    <note role="info">
+        <para>
+            Of course we can configure this helper. We can change height of image (by default it is
+            80px), and add <acronym>CSS</acronym> class or other attributes to image tag. The above
+            simply shows the most basic usage.
+        </para>
+    </note>
+
+    <warning>
+        <title>Use a valid email address!</title>
+
+        <para>
+            The email address you provide the helper should be valid. This class does not validate
+            the address (only the rating parameter). It is recommended to validate your email
+            address within your model layer.
+        </para>
+    </warning>
+
+    <example id="zend.view.helpers.initial.gravatar.advanced">
+        <title>Advanced Usage of Gravatar View Helper</title>
+
+        <para>
+            There are several ways to configure the returned gravatar. In most cases, you may either
+            pass an array of options as a second argument to the helper, or call methods on the
+            returned object in order to configure it.
+        </para>
+
+        <itemizedlist>
+            <listitem>
+                <para>
+                    The <varname>img_size</varname> option can be used to specify an alternate
+                    height; alternately, call <methodname>setImgSize()</methodname>.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    The <varname>secure</varname> option can be used to force usage of SSL in
+                    the returned image URI by passing a boolean <constant>true</constant> value (or
+                    disabling SSL usage by passing <constant>false</constant>). Alternately, call
+                    the <methodname>setSecure()</methodname> method. (By default, the setting
+                    follows the same security as the current page request.)
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    To add attributes to the image, pass an array of key/value pairs as the
+                    <emphasis>third</emphasis> argument to the helper, or call the
+                    <methodname>setAttribs()</methodname> method.
+                </para>
+            </listitem>
+        </itemizedlist>
+
+        <programlisting language="php"><![CDATA[
+// Within the view script (using HTML DOCTYPE)
+echo $this->gravatar('example@example.com',
+    array('imgSize' => 90, 'defaultImg' => 'monsterid', 'secure' => true),
+    array('class' => 'avatar', 'title' => 'Title for this image')
+);
+    
+// Or use mutator methods
+$this->gravatar()
+     ->setEmail('example@example.com')
+     ->setImgSize(90)
+     ->setDefaultImg(Zend_View_Helper_Gravatar::DEFAULT_MONSTERID)
+     ->setSecure(true)
+     ->setAttribs(array('class' => 'avatar', 'title' => 'Title for this image'));
+
+/* Both generate the following output:
+<img class="avatar" title="Title for this image"
+    src="https://secure.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8?s=90&d=monsterid&r=g" >
+ */
+]]></programlisting>
+    </example>
+
+    <sect4 id="zend.view.helper.gravatar.options">
+        <title>Options</title>
+
+        <variablelist>
+            <title>Zend_Service_Gravatar Options</title>
+
+            <varlistentry>
+                <term>img_size</term>
+
+                <listitem>
+                    <para>
+                        An integer describing the height of the avatar, in pixels; defaults to "80".
+                    </para>
+                </listitem>
+            </varlistentry>
+
+            <varlistentry>
+                <term>default_img</term>
+
+                <listitem>
+                    <para>
+                        Image to return if the gravatar service is unable to match the email address
+                        provided. Defaults to "mm", the "mystery man" image.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+            <varlistentry>
+                <term>rating</term>
+
+                <listitem>
+                    <para>
+                        Audience rating to confine returned images to. Defaults to "g"; may be one
+                        of "g", "pg", "r", or "x", in order of least offensive to most offensive.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+            <varlistentry>
+                <term>secure</term>
+
+                <listitem>
+                    <para>
+                        Whether or not to load the image via an SSL connection. Defaults to the what
+                        is detected from the current request.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </sect4>
+</sect3>

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

@@ -396,6 +396,7 @@ echo $this->formCheckbox('foo',
         <xi:include href="Zend_View-Helpers-Partial.xml" />
         <xi:include href="Zend_View-Helpers-Placeholder.xml" />
         <xi:include href="Zend_View-Helpers-Doctype.xml" />
+        <xi:include href="Zend_View-Helpers-Gravatar.xml" />
         <xi:include href="Zend_View-Helpers-HeadLink.xml" />
         <xi:include href="Zend_View-Helpers-HeadMeta.xml" />
         <xi:include href="Zend_View-Helpers-HeadScript.xml" />

+ 363 - 0
library/Zend/View/Helper/Gravatar.php

@@ -0,0 +1,363 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_View
+ * @subpackage Helper
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @version    $Id: Doctype.php 16971 2009-07-22 18:05:45Z mikaelkael $
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+
+/** Zend_View_Helper_HtmlElement */
+require_once 'Zend/View/Helper/HtmlElement.php';
+
+/**
+ * Helper for retrieving avatars from gravatar.com
+ *
+ * @package    Zend_View
+ * @subpackage Helper
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @link http://pl.gravatar.com/site/implement/url
+ */
+class Zend_View_Helper_Gravatar extends Zend_View_Helper_HtmlElement
+{
+
+    /**
+     * URL to gravatar service
+     */
+    const GRAVATAR_URL = 'http://www.gravatar.com/avatar';
+    /**
+     * Secure URL to gravatar service
+     */
+    const GRAVATAR_URL_SECURE = 'https://secure.gravatar.com/avatar';
+
+    /**
+     * Gravatar rating
+     */
+    const RATING_G  = 'g';
+    const RATING_PG = 'pg';
+    const RATING_R  = 'r';
+    const RATING_X  = 'x';
+
+    /**
+     * Default gravatar image value constants
+     */
+    const DEFAULT_404       = '404';
+    const DEFAULT_MM        = 'mm';
+    const DEFAULT_IDENTICON = 'identicon';
+    const DEFAULT_MONSTERID = 'monsterid';
+    const DEFAULT_WAVATAR   = 'wavatar';
+
+    /**
+     * Options
+     *
+     * @var array
+     */
+    protected $_options = array(
+        'img_size'    => 80, 
+        'default_img' => self::DEFAULT_MM, 
+        'rating'      => self::RATING_G, 
+        'secure'      => null,
+    );
+
+    /**
+     * Email Adress
+     *
+     * @var string
+     */
+    protected $_email;
+
+    /**
+     * Attributes for HTML image tag
+     *
+     * @var array
+     */
+    protected $_attribs;
+
+    /**
+     * Returns an avatar from gravatar's service.
+     *
+     * $options may include the following:
+     * - 'img_size' int height of img to return
+     * - 'default_img' string img to return if email adress has not found
+     * - 'rating' string rating parameter for avatar
+     * - 'secure' bool load from the SSL or Non-SSL location
+     *
+     * @see    http://pl.gravatar.com/site/implement/url
+     * @see    http://pl.gravatar.com/site/implement/url More information about gravatar's service.
+     * @param  string|null $email Email adress.
+     * @param  null|array $options Options
+     * @param  array $attribs Attributes for image tag (title, alt etc.)
+     * @return Zend_View_Helper_Gravatar
+     */
+    public function gravatar($email = "", $options = array(), $attribs = array())
+    {
+        $this->setEmail($email);
+        $this->setOptions($options);
+        $this->setAttribs($attribs);
+        return $this;
+    }
+
+    /**
+     * Configure state
+     * 
+     * @param  array $options 
+     * @return Zend_View_Helper_Gravatar
+     */
+    public function setOptions(array $options)
+    {
+        foreach ($options as $key => $value) {
+            $method = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
+            if (method_exists($this, $method)) {
+                $this->{$method}($value);
+            }
+        }
+        return $this;
+    }
+
+    /**
+     * Get img size
+     *
+     * @return int The img size
+     */
+    public function getImgSize()
+    {
+        return $this->_options['img_size'];
+    }
+
+    /**
+     * Set img size in pixels
+     *
+     * @param int $imgSize Size of img must be between 1 and 512
+     * @return Zend_View_Helper_Gravatar
+     */
+    public function setImgSize($imgSize)
+    {
+        $this->_options['img_size'] = (int) $imgSize;
+        return $this;
+    }
+
+    /**
+     * Get default img
+     *
+     * @return string
+     */
+    public function getDefaultImg()
+    {
+        return $this->_options['default_img'];
+    }
+
+    /**
+     * Set default img
+     *
+     * Can be either an absolute URL to an image, or one of the DEFAULT_* constants
+     *
+     * @param string $defaultImg
+     * @link http://pl.gravatar.com/site/implement/url More information about default image.
+     * @return Zend_View_Helper_Gravatar
+     */
+    public function setDefaultImg($defaultImg)
+    {
+        $this->_options['default_img'] = urlencode($defaultImg);
+        return $this;
+    }
+
+    /**
+     *  Set rating value
+     *
+     * Must be one of the RATING_* constants
+     *
+     * @param string $rating Value for rating. Allowed values are: g, px, r,x
+     * @link http://pl.gravatar.com/site/implement/url More information about rating.
+     * @throws Zend_View_Exception
+     */
+    public function setRating($rating)
+    {
+        switch ($rating) {
+            case self::RATING_G:
+            case self::RATING_PG: 
+            case self::RATING_R: 
+            case self::RATING_X:
+                $this->_options['rating'] = $rating;
+                break;
+            default:
+                require_once 'Zend/View/Exception.php';
+                throw new Zend_View_Exception(sprintf(
+                    'The rating value "%s" is not allowed',
+                    $rating
+                ));
+        }
+        return $this;
+    }
+
+    /**
+     * Get rating value
+     *
+     * @return string
+     */
+    public function getRating()
+    {
+        return $this->_options['rating'];
+    }
+
+    /**
+     * Set email adress
+     *
+     * @param string $email
+     * @return Zend_View_Helper_Gravatar
+     */
+    public function setEmail( $email )
+    {
+        $this->_email = $email;
+        return $this;
+    }
+
+    /**
+     * Get email adress
+     *
+     * @return string
+     */
+    public function getEmail()
+    {
+        return $this->_email;
+    }
+
+    /**
+     * Load from an SSL or No-SSL location?
+     *
+     * @param bool $flag
+     * @return Zend_View_Helper_Gravatar
+     */
+    public function setSecure($flag)
+    {
+        $this->_options['secure'] = ($flag === null) ? null : (bool) $flag;
+        return $this;  
+    }
+
+    /**
+     * Get an SSL or a No-SSL location
+     *
+     * @return bool
+     */
+    public function getSecure()
+    {
+        if ($this->_options['secure'] === null) {
+            return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
+        }
+        return $this->_options['secure'];
+    }
+
+    /**
+     * Get attribs of image
+     *
+     * Warning!
+     * If you set src attrib, you get it, but this value will be overwritten in 
+     * protected method _setSrcAttribForImg(). And finally your get other src 
+     * value!
+     *
+     * @return array
+     */
+    public function getAttribs()
+    {
+        return $this->_attribs;
+    }
+
+    /**
+     * Set attribs for image tag
+     *
+     * Warning! You shouldn't set src attrib for image tag.
+     * This attrib is overwritten in protected method _setSrcAttribForImg().
+     * This method(_setSrcAttribForImg) is called in public method getImgTag().
+
+     * @param array $attribs
+     * @return Zend_View_Helper_Gravatar
+     */
+    public function setAttribs(array $attribs)
+    {
+        $this->_attribs = $attribs;
+        return $this;
+    }
+
+    /**
+     * Get URL to gravatar's service.
+     *
+     * @return string URL
+     */
+    protected function _getGravatarUrl()
+    {
+        return ($this->getSecure() === false) ? self::GRAVATAR_URL : self::GRAVATAR_URL_SECURE;
+    }
+
+    /**
+     * Get avatar url (including size, rating and default image oprions)
+     * 
+     * @return string
+     */
+    protected function _getAvatarUrl()
+    {
+        $src = $this->_getGravatarUrl()
+             . '/'
+             . md5($this->getEmail())
+             . '?s='
+             . $this->getImgSize()
+             . '&d='
+             . $this->getDefaultImg()
+             . '&r='
+             . $this->getRating();
+        return $src;
+    }
+
+    /**
+     * Set src attrib for image.
+     *
+     * You shouldn't set a own url value!
+     * It sets value, uses protected method _getAvatarUrl.
+     *
+     * If already exsist overwritten.
+     */
+    protected function _setSrcAttribForImg()
+    {
+        $attribs        = $this->getAttribs();
+        $attribs['src'] = $this->_getAvatarUrl();
+        $this->setAttribs($attribs);
+    }
+
+    /**
+     * Return valid image tag 
+     *
+     * @return string 
+     */
+    public function getImgTag()
+    {
+        $this->_setSrcAttribForImg();
+        $html = '<img'
+              . $this->_htmlAttribs($this->getAttribs())
+              . $this->getClosingBracket();
+
+        return $html;
+    }
+    
+    /**
+     * Return valid image tag
+     *
+     * @return string
+     */
+    public function  __toString()
+    {
+        return $this->getImgTag();
+
+    }
+}

+ 2 - 0
tests/Zend/View/Helper/AllTests.php

@@ -48,6 +48,7 @@ require_once 'Zend/View/Helper/FormSubmitTest.php';
 require_once 'Zend/View/Helper/FormTest.php';
 require_once 'Zend/View/Helper/FormTextTest.php';
 require_once 'Zend/View/Helper/FormTextareaTest.php';
+require_once 'Zend/View/Helper/GravatarTest.php';
 require_once 'Zend/View/Helper/HeadLinkTest.php';
 require_once 'Zend/View/Helper/HeadMetaTest.php';
 require_once 'Zend/View/Helper/HeadScriptTest.php';
@@ -117,6 +118,7 @@ class Zend_View_Helper_AllTests
         $suite->addTestSuite('Zend_View_Helper_FormTest');
         $suite->addTestSuite('Zend_View_Helper_FormTextTest');
         $suite->addTestSuite('Zend_View_Helper_FormTextareaTest');
+        $suite->addTestSuite('Zend_View_Helper_GravatarTest');
         $suite->addTestSuite('Zend_View_Helper_HeadLinkTest');
         $suite->addTestSuite('Zend_View_Helper_HeadMetaTest');
         $suite->addTestSuite('Zend_View_Helper_HeadScriptTest');

+ 291 - 0
tests/Zend/View/Helper/GravatarTest.php

@@ -0,0 +1,291 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_View
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: BaseUrlTest.php 20096 2010-01-06 02:05:09Z bkarwin $
+ */
+
+// Call Zend_View_Helper_BaseUrlTest::main() if this source file is executed directly.
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Zend_View_Helper_GravatarTest::main');
+}
+
+require_once dirname(__FILE__) . '/../../../TestHelper.php';
+
+/**
+ * @see Zend_View_Helper_Gravatar
+ */
+require_once 'Zend/View/Helper/Gravatar.php';
+
+/**
+ * @see Zend_View
+ */
+require_once 'Zend/View.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_View
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @group      Zend_View
+ * @group      Zend_View_Helper
+ */
+class Zend_View_Helper_GravatarTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Zend_View_Helper_Gravatar
+     */
+    protected $_object;
+
+    /**
+     * @var Zend_View
+     */
+    protected $_view;
+
+    /**
+     * Main
+     */
+    public static function main()
+    {
+        $suite  = new PHPUnit_Framework_TestSuite("Zend_View_Helper_GravatarTest");
+        $result = PHPUnit_TextUI_TestRunner::run($suite);
+    }
+
+    /**
+     * Prepares the environment before running a test.
+     */
+    protected function setUp()
+    {
+        $this->_object = new Zend_View_Helper_Gravatar();
+        $this->_view   = new Zend_View();
+        $this->_view->doctype()->setDoctype(strtoupper("XHTML1_STRICT"));
+        $this->_object->setView($this->_view);
+
+        if( isset($_SERVER['HTTPS'])) {
+            unset ($_SERVER['HTTPS']);
+        }
+    }
+
+    /**
+     * Cleans up the environment after running a test.
+     */
+    protected function tearDown()
+    {
+        unset($this->_object, $this->_view);
+    }
+
+    /**
+     * Test default options.
+     */
+    public function testGravataXHTMLDoctype()
+    {
+        $this->assertRegExp('/\/>$/',
+            $this->_object->gravatar('example@example.com')->__toString());
+    }
+
+    /**
+     * Test if doctype is HTML
+     */
+    public function testGravatarHTMLDoctype()
+    {
+        $object = new Zend_View_Helper_Gravatar();
+        $view   = new Zend_View();
+        $view->doctype()->setDoctype(strtoupper("HTML5"));
+        $object->setView($view);
+        
+        $this->assertRegExp('/[^\/]>$/',
+            $this->_object->gravatar('example@example.com')->__toString());
+    }
+
+    /**
+     * Test get set methods
+     */
+    public function testGetAndSetMethods()
+    {
+        $attribs = array('class' => 'gravatar', 'title' => 'avatar', 'id' => 'gravatar-1');
+        $this->_object->setDefaultImg('monsterid')
+             ->setImgSize(150)
+             ->setSecure(true)
+             ->setEmail("example@example.com")
+             ->setAttribs($attribs)
+             ->setRating('pg');
+        $this->assertEquals("monsterid", $this->_object->getDefaultImg());
+        $this->assertEquals("pg", $this->_object->getRating());
+        $this->assertEquals("example@example.com", $this->_object->getEmail());
+        $this->assertEquals($attribs, $this->_object->getAttribs());
+        $this->assertEquals(150, $this->_object->getImgSize());
+        $this->assertTrue($this->_object->getSecure());
+    }
+
+    public function tesSetDefaultImg()
+    {
+        $this->_object->gravatar("example@example.com");
+
+        $img = array(
+            "wavatar",
+            "http://www.example.com/images/avatar/example.png",
+            Zend_View_Helper_Gravatar::DEFAULT_MONSTERID,
+        );
+        
+        foreach ($img as $value) {
+            $this->_object->setDefaultImg($value);
+            $this->assertEquals(urlencode($value), $this->_object->getDefaultImg());
+        }
+    }
+
+    public function testSetImgSize()
+    {
+        $imgSizesRight = array(1, 500, "600");
+        foreach ($imgSizesRight as $value) {
+            $this->_object->setImgSize($value);
+            $this->assertType('int', $this->_object->getImgSize());
+        }
+    }
+
+    public function testInvalidRatingParametr()
+    {
+        $ratingsWrong = array( 'a', 'cs', 456);
+        $this->setExpectedException('Zend_View_Exception');
+        foreach ($ratingsWrong as $value) {
+            $this->_object->setRating($value);
+        }
+    }
+
+    public function testSetRating()
+    {
+        $ratingsRight = array( 'g', 'pg', 'r', 'x', Zend_View_Helper_Gravatar::RATING_R);
+        foreach ($ratingsRight as $value) {
+            $this->_object->setRating($value);
+            $this->assertEquals($value, $this->_object->getRating());
+        }
+    }
+
+    public function testSetSecure()
+    {
+        $values = array("true", "false", "text", $this->_view, 100, true, "", null, 0, false);
+        foreach ($values as $value) {
+            $this->_object->setSecure($value);
+            $this->assertType('bool', $this->_object->getSecure());
+        }
+    }
+
+    /**
+     * Test SSL location
+     */
+    public function testHttpsSource()
+    {
+        $this->assertRegExp('/src="https:\/\/secure.gravatar.com\/avatar\/[a-z0-9]{32}.+"/',
+                $this->_object->gravatar("example@example.com", array('secure' => true))->__toString());
+    }
+
+    /**
+     * Test HTML attribs
+     */
+    public function testImgAttribs()
+    {
+        $this->assertRegExp('/class="gravatar" title="Gravatar"/',
+                $this->_object->gravatar("example@example.com", array(),
+                        array('class' => 'gravatar', 'title' => 'Gravatar'))
+                     ->__toString()
+        );
+    }
+
+    /**
+     * Test gravatar's options (rating, size, default image and secure)
+     */
+    public function testGravatarOptions()
+    {
+        $this->assertRegExp('/src="http:\/\/www.gravatar.com\/avatar\/[a-z0-9]{32}\?s=125&amp;d=wavatar&amp;r=pg"/',
+                $this->_object->gravatar("example@example.com",
+                        array('rating' => 'pg', 'imgSize' => 125, 'defaultImg' => 'wavatar',
+                            'secure' => false))
+                     ->__toString()
+        );
+    }
+
+    /**
+     * Test auto detect location.
+     * If request was made through the HTTPS protocol use secure location.
+     */
+    public function testAutoDetectLocation()
+    {
+        $values = array("on", "", 1, true);
+
+        foreach ($values as $value) {
+            $_SERVER['HTTPS'] = $value;
+            $this->assertRegExp('/src="https:\/\/secure.gravatar.com\/avatar\/[a-z0-9]{32}.+"/',
+                    $this->_object->gravatar("example@example.com")->__toString());
+        }
+    }
+
+    /**
+     * @link http://php.net/manual/en/reserved.variables.server.php Section "HTTPS"
+     */
+    public function testAutoDetectLocationOnIis()
+    {
+        $_SERVER['HTTPS'] = "off";
+        
+        $this->assertRegExp('/src="http:\/\/www.gravatar.com\/avatar\/[a-z0-9]{32}.+"/',
+                $this->_object->gravatar("example@example.com")->__toString());
+    }
+
+    public function testSetAttribsWithSrcKey()
+    {
+        $email = 'example@example.com';
+        $this->_object->setEmail($email);
+        $this->_object->setAttribs(array(
+            'class' => 'gravatar',
+            'src'   => 'http://example.com',
+            'id'    => 'gravatarID',
+        ));
+
+        $this->assertRegExp('/src="http:\/\/www.gravatar.com\/avatar\/[a-z0-9]{32}.+"/',
+                            $this->_object->getImgTag());
+    }
+
+    public function testForgottenEmailParameter()
+    {
+        $this->assertRegExp('/(src="http:\/\/www.gravatar.com\/avatar\/[a-z0-9]{32}.+")/',
+                            $this->_object->getImgTag());
+    }
+
+    public function testReturnImgTag()
+    {
+        $this->assertRegExp("/^<img\s.+/",
+        $this->_object->gravatar("example@example.com")->__toString());
+    }
+
+    public function testReturnThisObject()
+    {
+        $this->assertType('Zend_View_Helper_Gravatar', $this->_object->gravatar());
+    }
+
+    public function testInvalidKeyPassedToSetOptionsMethod()
+    {
+        $options = array(
+            'unknown' => array('val' => 1)
+        );
+        $this->_object->gravatar()->setOptions($options);
+    }
+}
+
+// Call Zend_View_Helper_BaseUrlTest::main() if this source file is executed directly.
+if (PHPUnit_MAIN_METHOD == 'Zend_View_Helper_BaseUrlTest::main') {
+    Zend_View_Helper_BaseUrlTest::main();
+}