Index: library/Zend/Gdata/Health.php =================================================================== --- library/Zend/Gdata/Health.php (revision 24746) +++ library/Zend/Gdata/Health.php (working copy) @@ -22,31 +22,16 @@ */ /** - * @see Zend_Gdata + * @see Zend_Exception */ -require_once 'Zend/Gdata.php'; +require_once 'Zend/Exception.php'; /** - * @see Zend_Gdata_Health_ProfileFeed + * @see Zend_Gdata */ -require_once 'Zend/Gdata/Health/ProfileFeed.php'; +require_once 'Zend/Gdata.php'; /** - * @see Zend_Gdata_Health_ProfileListFeed - */ -require_once 'Zend/Gdata/Health/ProfileListFeed.php'; - -/** - * @see Zend_Gdata_Health_ProfileListEntry - */ -require_once 'Zend/Gdata/Health/ProfileListEntry.php'; - -/** - * @see Zend_Gdata_Health_ProfileEntry - */ -require_once 'Zend/Gdata/Health/ProfileEntry.php'; - -/** * Service class for interacting with the Google Health Data API * * @link http://code.google.com/apis/health @@ -84,29 +69,6 @@ const H9_SANDBOX_SERVICE_NAME = 'weaver'; /** - * Profile ID used for all API interactions. This can only be set when - * using ClientLogin for authentication. - * - * @var string - */ - private $_profileID = null; - - /** - * True if API calls should be made to the H9 developer sandbox at /h9 - * rather than /health - * - * @var bool - */ - private $_useH9Sandbox = false; - - public static $namespaces = - array('ccr' => 'urn:astm-org:CCR', - 'batch' => 'http://schemas.google.com/gdata/batch', - 'h9m' => 'http://schemas.google.com/health/metadata', - 'gAcl' => 'http://schemas.google.com/acl/2007', - 'gd' => 'http://schemas.google.com/g/2005'); - - /** * Create Zend_Gdata_Health object * * @param Zend_Http_Client $client (optional) The HTTP client to use when @@ -118,157 +80,10 @@ */ public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0', $useH9Sandbox = false) { - $this->registerPackage('Zend_Gdata_Health'); - $this->registerPackage('Zend_Gdata_Health_Extension_Ccr'); - parent::__construct($client, $applicationId); - $this->_useH9Sandbox = $useH9Sandbox; + throw new Zend_Exception( + 'Google Health API has been discontinued by Google and was removed' + . ' from Zend Framework in 1.12.0. For more information see: ' + . 'http://googleblog.blogspot.ca/2011/06/update-on-google-health-and-google.html' + ); } - - /** - * Gets the id of the user's profile - * - * @return string The profile id - */ - public function getProfileID() - { - return $this->_profileID; - } - - /** - * Sets which of the user's profiles will be used - * - * @param string $id The profile ID - * @return Zend_Gdata_Health Provides a fluent interface - */ - public function setProfileID($id) { - $this->_profileID = $id; - return $this; - } - - /** - * Retrieves the list of profiles associated with the user's ClientLogin - * credentials. - * - * @param string $query The query of the feed as a URL or Query object - * @return Zend_Gdata_Feed - */ - public function getHealthProfileListFeed($query = null) - { - if ($this->_httpClient->getClientLoginToken() === null) { - require_once 'Zend/Gdata/App/AuthException.php'; - throw new Zend_Gdata_App_AuthException( - 'Profiles list feed is only available when using ClientLogin'); - } - - if($query === null) { - $uri = self::CLIENTLOGIN_PROFILELIST_FEED_URI; - } else if ($query instanceof Zend_Gdata_Query) { - $uri = $query->getQueryUrl(); - } else { - $uri = $query; - } - - // use correct feed for /h9 or /health - if ($this->_useH9Sandbox) { - $uri = preg_replace('/\/health\//', '/h9/', $uri); - } - - return parent::getFeed($uri, 'Zend_Gdata_Health_ProfileListFeed'); - } - - /** - * Retrieve a user's profile as a feed object. If ClientLogin is used, the - * profile associated with $this->_profileID is returned, otherwise - * the profile associated with the AuthSub token is read. - * - * @param mixed $query The query for the feed, as a URL or Query - * @return Zend_Gdata_Health_ProfileFeed - */ - public function getHealthProfileFeed($query = null) - { - if ($this->_httpClient->getClientLoginToken() !== null && - $this->getProfileID() == null) { - require_once 'Zend/Gdata/App/AuthException.php'; - throw new Zend_Gdata_App_AuthException( - 'Profile ID must not be null. Did you call setProfileID()?'); - } - - if ($query instanceof Zend_Gdata_Query) { - $uri = $query->getQueryUrl(); - } else if ($this->_httpClient->getClientLoginToken() !== null && - $query == null) { - $uri = self::CLIENTLOGIN_PROFILE_FEED_URI . '/' . $this->getProfileID(); - } else if ($query === null) { - $uri = self::AUTHSUB_PROFILE_FEED_URI; - } else { - $uri = $query; - } - - // use correct feed for /h9 or /health - if ($this->_useH9Sandbox) { - $uri = preg_replace('/\/health\//', '/h9/', $uri); - } - - return parent::getFeed($uri, 'Zend_Gdata_Health_ProfileFeed'); - } - - /** - * Retrieve a profile entry object - * - * @param mixed $query The query for the feed, as a URL or Query - * @return Zend_Gdata_Health_ProfileEntry - */ - public function getHealthProfileEntry($query = null) - { - if ($query === null) { - require_once 'Zend/Gdata/App/InvalidArgumentException.php'; - throw new Zend_Gdata_App_InvalidArgumentException( - 'Query must not be null'); - } else if ($query instanceof Zend_Gdata_Query) { - $uri = $query->getQueryUrl(); - } else { - $uri = $query; - } - return parent::getEntry($uri, 'Zend_Gdata_Health_ProfileEntry'); - } - - /** - * Posts a new notice using the register feed. This function constructs - * the atom profile entry. - * - * @param string $subject The subject line of the notice - * @param string $body The message body of the notice - * @param string $bodyType The (optional) type of message body - * (text, xhtml, html, etc.) - * @param string $ccrXML The (optional) CCR to add to the user's profile - * @return Zend_Gdata_Health_ProfileEntry - */ - public function sendHealthNotice($subject, $body, $bodyType = null, $ccrXML = null) - { - if ($this->_httpClient->getClientLoginToken()) { - $profileID = $this->getProfileID(); - if ($profileID !== null) { - $uri = self::CLIENTLOGIN_REGISTER_FEED_URI . '/' . $profileID; - } else { - require_once 'Zend/Gdata/App/AuthException.php'; - throw new Zend_Gdata_App_AuthException( - 'Profile ID must not be null. Did you call setProfileID()?'); - } - } else { - $uri = self::AUTHSUB_REGISTER_FEED_URI; - } - - $entry = new Zend_Gdata_Health_ProfileEntry(); - $entry->title = $this->newTitle($subject); - $entry->content = $this->newContent($body); - $entry->content->type = $bodyType ? $bodyType : 'text'; - $entry->setCcr($ccrXML); - - // use correct feed for /h9 or /health - if ($this->_useH9Sandbox) { - $uri = preg_replace('/\/health\//', '/h9/', $uri); - } - - return $this->insertEntry($entry, $uri, 'Zend_Gdata_Health_ProfileEntry'); - } } Index: library/Zend/Gdata/Health/ProfileListEntry.php =================================================================== --- library/Zend/Gdata/Health/ProfileListEntry.php (revision 24746) +++ library/Zend/Gdata/Health/ProfileListEntry.php (working copy) @@ -22,6 +22,11 @@ */ /** + * @see Zend_Exception + */ +require_once 'Zend/Exception.php'; + +/** * @see Zend_Gdata_Entry */ require_once 'Zend/Gdata/Entry.php'; @@ -40,61 +45,15 @@ class Zend_Gdata_Health_ProfileListEntry extends Zend_Gdata_Entry { /** - * The classname for individual profile list entry elements. - * - * @var string - */ - protected $_entryClassName = 'Zend_Gdata_Health_ProfileListEntry'; - - /** * Constructs a new Zend_Gdata_Health_ProfileListEntry object. * @param DOMElement $element (optional) The DOMElement on which to base this object. */ public function __construct($element = null) { - parent::__construct($element); + throw new Zend_Exception( + 'Google Health API has been discontinued by Google and was removed' + . ' from Zend Framework in 1.12.0. For more information see: ' + . 'http://googleblog.blogspot.ca/2011/06/update-on-google-health-and-google.html' + ); } - - /** - * Retrieves a DOMElement which corresponds to this element and all - * child properties. This is used to build an entry back into a DOM - * and eventually XML text for application storage/persistence. - * - * @param DOMDocument $doc The DOMDocument used to construct DOMElements - * @return DOMElement The DOMElement representing this element and all - * child properties. - */ - public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) - { - $element = parent::getDOM($doc, $majorVersion, $minorVersion); - return $element; - } - - /** - * Creates individual Entry objects of the appropriate type and - * stores them as members of this entry based upon DOM data. - * - * @param DOMNode $child The DOMNode to process - */ - protected function takeChildFromDOM($child) - { - parent::takeChildFromDOM($child); - } - - /** - * Retrieves the profile ID for the entry, which is contained in - * @return string The profile id - */ - public function getProfileID() { - return $this->getContent()->text; - } - - /** - * Retrieves the profile's title, which is contained in - * @return string The profile name - */ - public function getProfileName() { - return $this->getTitle()->text; - } - } Index: library/Zend/Gdata/Health/ProfileListFeed.php =================================================================== --- library/Zend/Gdata/Health/ProfileListFeed.php (revision 24746) +++ library/Zend/Gdata/Health/ProfileListFeed.php (working copy) @@ -22,6 +22,11 @@ */ /** + * @see Zend_Exception + */ +require_once 'Zend/Exception.php'; + +/** * @see Zend_Gdata_Feed */ require_once 'Zend/Gdata/Feed.php'; @@ -39,15 +44,12 @@ */ class Zend_Gdata_Health_ProfileListFeed extends Zend_Gdata_Feed { - /** - * The class name for individual profile feed elements. - * - * @var string - */ - protected $_entryClassName = 'Zend_Gdata_Health_ProfileListEntry'; - - public function getEntries() + public function __construct($element = null) { - return $this->entry; + throw new Zend_Exception( + 'Google Health API has been discontinued by Google and was removed' + . ' from Zend Framework in 1.12.0. For more information see: ' + . 'http://googleblog.blogspot.ca/2011/06/update-on-google-health-and-google.html' + ); } } Index: library/Zend/Gdata/Health/ProfileEntry.php =================================================================== --- library/Zend/Gdata/Health/ProfileEntry.php (revision 24746) +++ library/Zend/Gdata/Health/ProfileEntry.php (working copy) @@ -22,14 +22,14 @@ */ /** - * @see Zend_Gdata_Entry + * @see Zend_Exception */ -require_once 'Zend/Gdata/Entry.php'; +require_once 'Zend/Exception.php'; /** - * @see Zend_Gdata_Health_Extension_Ccr + * @see Zend_Gdata_Entry */ -require_once 'Zend/Gdata/Health/Extension/Ccr.php'; +require_once 'Zend/Gdata/Entry.php'; /** * Concrete class for working with Health profile entries. @@ -45,91 +45,15 @@ class Zend_Gdata_Health_ProfileEntry extends Zend_Gdata_Entry { /** - * The classname for individual profile entry elements. - * - * @var string - */ - protected $_entryClassName = 'Zend_Gdata_Health_ProfileEntry'; - - /** - * Google Health CCR data - * - * @var Zend_Gdata_Health_Extension_Ccr - */ - protected $_ccrData = null; - - /** * Constructs a new Zend_Gdata_Health_ProfileEntry object. * @param DOMElement $element (optional) The DOMElement on which to base this object. */ public function __construct($element = null) { - foreach (Zend_Gdata_Health::$namespaces as $nsPrefix => $nsUri) { - $this->registerNamespace($nsPrefix, $nsUri); - } - parent::__construct($element); + throw new Zend_Exception( + 'Google Health API has been discontinued by Google and was removed' + . ' from Zend Framework in 1.12.0. For more information see: ' + . 'http://googleblog.blogspot.ca/2011/06/update-on-google-health-and-google.html' + ); } - - /** - * Retrieves a DOMElement which corresponds to this element and all - * child properties. This is used to build an entry back into a DOM - * and eventually XML text for application storage/persistence. - * - * @param DOMDocument $doc The DOMDocument used to construct DOMElements - * @return DOMElement The DOMElement representing this element and all - * child properties. - */ - public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) - { - $element = parent::getDOM($doc, $majorVersion, $minorVersion); - if ($this->_ccrData !== null) { - $element->appendChild($this->_ccrData->getDOM($element->ownerDocument)); - } - - return $element; - } - - /** - * Creates individual Entry objects of the appropriate type and - * stores them as members of this entry based upon DOM data. - * - * @param DOMNode $child The DOMNode to process - */ - protected function takeChildFromDOM($child) - { - $absoluteNodeName = $child->namespaceURI . ':' . $child->localName; - - if (strstr($absoluteNodeName, $this->lookupNamespace('ccr') . ':')) { - $ccrElement = new Zend_Gdata_Health_Extension_Ccr(); - $ccrElement->transferFromDOM($child); - $this->_ccrData = $ccrElement; - } else { - parent::takeChildFromDOM($child); - - } - } - - /** - * Sets the profile entry's CCR data - * @param string $ccrXMLStr The CCR as an xml string - * @return Zend_Gdata_Health_Extension_Ccr - */ - public function setCcr($ccrXMLStr) { - $ccrElement = null; - if ($ccrXMLStr != null) { - $ccrElement = new Zend_Gdata_Health_Extension_Ccr(); - $ccrElement->transferFromXML($ccrXMLStr); - $this->_ccrData = $ccrElement; - } - return $ccrElement; - } - - - /** - * Returns all the CCR data in a profile entry - * @return Zend_Gdata_Health_Extension_Ccr - */ - public function getCcr() { - return $this->_ccrData; - } } Index: library/Zend/Gdata/Health/ProfileFeed.php =================================================================== --- library/Zend/Gdata/Health/ProfileFeed.php (revision 24746) +++ library/Zend/Gdata/Health/ProfileFeed.php (working copy) @@ -22,6 +22,11 @@ */ /** + * @see Zend_Exception + */ +require_once 'Zend/Exception.php'; + +/** * @see Zend_Gdata_Feed */ require_once 'Zend/Gdata/Feed.php'; @@ -40,13 +45,6 @@ class Zend_Gdata_Health_ProfileFeed extends Zend_Gdata_Feed { /** - * The class name for individual profile feed elements. - * - * @var string - */ - protected $_entryClassName = 'Zend_Gdata_Health_ProfileEntry'; - - /** * Creates a Health Profile feed, representing a user's Health profile * * @param DOMElement $element (optional) DOMElement from which this @@ -54,14 +52,10 @@ */ public function __construct($element = null) { - foreach (Zend_Gdata_Health::$namespaces as $nsPrefix => $nsUri) { - $this->registerNamespace($nsPrefix, $nsUri); - } - parent::__construct($element); + throw new Zend_Exception( + 'Google Health API has been discontinued by Google and was removed' + . ' from Zend Framework in 1.12.0. For more information see: ' + . 'http://googleblog.blogspot.ca/2011/06/update-on-google-health-and-google.html' + ); } - - public function getEntries() - { - return $this->entry; - } } Index: library/Zend/Gdata/Health/Query.php =================================================================== --- library/Zend/Gdata/Health/Query.php (revision 24746) +++ library/Zend/Gdata/Health/Query.php (working copy) @@ -22,6 +22,11 @@ */ /** + * @see Zend_Exception + */ +require_once 'Zend/Exception.php'; + +/** * @see Zend_Gdata_Query */ require_once('Zend/Gdata/Query.php'); @@ -55,231 +60,16 @@ * Namespace for an item category */ const ITEM_CATEGORY_NS = 'http://schemas.google.com/health/item'; - + /** - * The default URI for POST methods - * - * @var string + * Create Gdata_Query object */ - protected $_defaultFeedUri = self::HEALTH_PROFILE_FEED_URI; - - /** - * Sets the digest parameter's value. - * - * @param string $value - * @return Zend_Gdata_Health_Query Provides a fluent interface - */ - public function setDigest($value) + public function __construct($url = null) { - if ($value !== null) { - $this->_params['digest'] = $value; - } - return $this; + throw new Zend_Exception( + 'Google Health API has been discontinued by Google and was removed' + . ' from Zend Framework in 1.12.0. For more information see: ' + . 'http://googleblog.blogspot.ca/2011/06/update-on-google-health-and-google.html' + ); } - - /** - * Returns the digest parameter's value. - * - * @return string The value set for the digest parameter. - */ - public function getDigest() - { - if (array_key_exists('digest', $this->_params)) { - return $this->_params['digest']; - } else { - return null; - } - } - - /** - * Setter for category queries. - * - * @param string $item A category to query. - * @param string $name (optional) A specific item to search a category for. - * An example would be 'Lipitor' if $item is set to 'medication'. - * @return Zend_Gdata_Health_Query Provides a fluent interface - */ - public function setCategory($item, $name = null) - { - $this->_category = $item . - ($name ? '/' . urlencode('{' . self::ITEM_CATEGORY_NS . '}' . $name) : null); - return $this; - } - - /** - * Returns the query object's category. - * - * @return string id - */ - public function getCategory() - { - return $this->_category; - } - - /** - * Setter for the grouped parameter. - * - * @param string $value setting a count of results per group. - * @return Zend_Gdata_Health_Query Provides a fluent interface - */ - public function setGrouped($value) - { - if ($value !== null) { - $this->_params['grouped'] = $value; - } - return $this; - } - - /** - * Returns the value set for the grouped parameter. - * - * @return string grouped parameter. - */ - public function getGrouped() - { - if (array_key_exists('grouped', $this->_params)) { - return $this->_params['grouped']; - } else { - return null; - } - } - - /** - * Setter for the max-results-group parameter. - * - * @param int $value Specifies the maximum number of groups to be - * retrieved. Must be an integer value greater than zero. This parameter - * is only valid if grouped=true. - * @return Zend_Gdata_Health_Query Provides a fluent interface - */ - public function setMaxResultsGroup($value) - { - if ($value !== null) { - if ($value <= 0 || $this->getGrouped() !== 'true') { - require_once 'Zend/Gdata/App/InvalidArgumentException.php'; - throw new Zend_Gdata_App_InvalidArgumentException( - 'The max-results-group parameter must be set to a value - greater than 0 and can only be used if grouped=true'); - } else { - $this->_params['max-results-group'] = $value; - } - } - return $this; - } - - /** - * Returns the value set for max-results-group. - * - * @return int Returns max-results-group parameter. - */ - public function getMaxResultsGroup() - { - if (array_key_exists('max-results-group', $this->_params)) { - return $this->_params['max-results-group']; - } else { - return null; - } - } - - /** - * Setter for the max-results-group parameter. - * - * @param int $value Specifies the maximum number of records to be - * retrieved from each group. The limits that you specify with this - * parameter apply to all groups. Must be an integer value greater than - * zero. This parameter is only valid if grouped=true. - * @return Zend_Gdata_Health_Query Provides a fluent interface - */ - public function setMaxResultsInGroup($value) - { - if ($value !== null) { - if ($value <= 0 || $this->getGrouped() !== 'true') { - throw new Zend_Gdata_App_InvalidArgumentException( - 'The max-results-in-group parameter must be set to a value - greater than 0 and can only be used if grouped=true'); - } else { - $this->_params['max-results-in-group'] = $value; - } - } - return $this; - } - - /** - * Returns the value set for max-results-in-group. - * - * @return int Returns max-results-in-group parameter. - */ - public function getMaxResultsInGroup() - { - if (array_key_exists('max-results-in-group', $this->_params)) { - return $this->_params['max-results-in-group']; - } else { - return null; - } - } - - /** - * Setter for the start-index-group parameter. - * - * @param int $value Retrieves only items whose group ranking is at - * least start-index-group. This should be set to a 1-based index of the - * first group to be retrieved. The range is applied per category. - * This parameter is only valid if grouped=true. - * @return Zend_Gdata_Health_Query Provides a fluent interface - */ - public function setStartIndexGroup($value) - { - if ($value !== null && $this->getGrouped() !== 'true') { - throw new Zend_Gdata_App_InvalidArgumentException( - 'The start-index-group can only be used if grouped=true'); - } else { - $this->_params['start-index-group'] = $value; - } - return $this; - } - - /** - * Returns the value set for start-index-group. - * - * @return int Returns start-index-group parameter. - */ - public function getStartIndexGroup() - { - if (array_key_exists('start-index-group', $this->_params)) { - return $this->_params['start-index-group']; - } else { - return null; - } - } - - /** - * Setter for the start-index-in-group parameter. - * - * @param int $value A 1-based index of the records to be retrieved from - * each group. This parameter is only valid if grouped=true. - * @return Zend_Gdata_Health_Query Provides a fluent interface - */ - public function setStartIndexInGroup($value) - { - if ($value !== null && $this->getGrouped() !== 'true') { - throw new Zend_Gdata_App_InvalidArgumentException('start-index-in-group'); - } else { - $this->_params['start-index-in-group'] = $value; - } - return $this; - } - - /** - * Returns the value set for start-index-in-group. - * - * @return int Returns start-index-in-group parameter. - */ - public function getStartIndexInGroup() - { - if (array_key_exists('start-index-in-group', $this->_params)) { - return $this->_params['start-index-in-group']; - } else { - return null; - } - } } Index: library/Zend/Gdata/Health/Extension/Ccr.php =================================================================== --- library/Zend/Gdata/Health/Extension/Ccr.php (revision 24746) +++ library/Zend/Gdata/Health/Extension/Ccr.php (working copy) @@ -21,6 +21,11 @@ */ /** + * @see Zend_Exception + */ +require_once 'Zend/Exception.php'; + +/** * @see Zend_Gdata_App_Extension_Element */ require_once 'Zend/Gdata/App/Extension/Element.php'; @@ -36,10 +41,6 @@ */ class Zend_Gdata_Health_Extension_Ccr extends Zend_Gdata_App_Extension_Element { - protected $_rootNamespace = 'ccr'; - protected $_rootElement = 'ContinuityOfCareRecord'; - protected $_ccrDom = null; - /** * Creates a Zend_Gdata_Health_Extension_Ccr entry, representing CCR data * @@ -48,77 +49,10 @@ */ public function __construct($element = null) { - foreach (Zend_Gdata_Health::$namespaces as $nsPrefix => $nsUri) { - $this->registerNamespace($nsPrefix, $nsUri); - } + throw new Zend_Exception( + 'Google Health API has been discontinued by Google and was removed' + . ' from Zend Framework in 1.12.0. For more information see: ' + . 'http://googleblog.blogspot.ca/2011/06/update-on-google-health-and-google.html' + ); } - - /** - * Transfers each child and attribute into member variables. - * This is called when XML is received over the wire and the data - * model needs to be built to represent this XML. - * - * @param DOMNode $node The DOMNode that represents this object's data - */ - public function transferFromDOM($node) - { - $this->_ccrDom = $node; - } - - /** - * Retrieves a DOMElement which corresponds to this element and all - * child properties. This is used to build an entry back into a DOM - * and eventually XML text for sending to the server upon updates, or - * for application storage/persistence. - * - * @param DOMDocument $doc The DOMDocument used to construct DOMElements - * @return DOMElement The DOMElement representing this element and all - * child properties. - */ - public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) - { - if ($doc === null) { - $doc = new DOMDocument('1.0', 'utf-8'); - } - $domElement = $doc->importNode($this->_ccrDom, true); - return $domElement; - } - - /** - * Magic helper that allows drilling down and returning specific elements - * in the CCR. For example, to retrieve the users medications - * (/ContinuityOfCareRecord/Body/Medications) from the entry's CCR, call - * $entry->getCcr()->getMedications(). Similarly, getConditions() would - * return extract the user's conditions. - * - * @param string $name Name of the function to call - * @param unknown $args - * @return array. A list of the appropriate CCR data - */ - public function __call($name, $args) - { - if (substr($name, 0, 3) === 'get') { - $category = substr($name, 3); - - switch ($category) { - case 'Conditions': - $category = 'Problems'; - break; - case 'Allergies': - $category = 'Alerts'; - break; - case 'TestResults': - // TestResults is an alias for LabResults - case 'LabResults': - $category = 'Results'; - break; - default: - // $category is already well formatted - } - - return $this->_ccrDom->getElementsByTagNameNS($this->lookupNamespace('ccr'), $category); - } else { - return null; - } - } } Index: tests/Zend/Gdata/HealthOnlineTest.php =================================================================== --- tests/Zend/Gdata/HealthOnlineTest.php (revision 24746) +++ tests/Zend/Gdata/HealthOnlineTest.php (working copy) @@ -1,317 +0,0 @@ -user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL'); - $this->pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD'); - $serviceName = Zend_Gdata_Health::HEALTH_SERVICE_NAME; - $client = Zend_Gdata_ClientLogin::getHttpClient($this->user, $this->pass, $serviceName); - $this->health = new Zend_Gdata_Health($client, 'google-MyPHPApp-v1.0'); - } - - private function setupProfileID() - { - $profileListFeed = $this->health->getHealthProfileListFeed(); - $profileID = $profileListFeed->entry[0]->getProfileID(); - $this->health->setProfileID($profileID); - } - - public function testSetProfileID() - { - $this->health->setProfileID('123456790'); - $this->assertEquals('123456790', $this->health->getProfileID()); - } - - public function testGetHealthProfileListFeedWithoutUsingClientLogin() - { - $client = new Zend_Gdata_HttpClient(); - $this->health = new Zend_Gdata_Health($client); - - try { - $feed = $this->health->getHealthProfileListFeed(); - $this->fail('Expecting to catch Zend_Gdata_App_AuthException'); - } catch (Exception $e) { - $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_AuthException'), - 'Expecting Zend_Gdata_App_AuthException, got '.get_class($e)); - } - } - - public function testGetHealthProfileFeedWithoutUsingClientLogin() - { - try { - $feed = $this->health->getHealthProfileFeed(); - $this->fail('Expecting to catch Zend_Gdata_App_AuthException'); - } catch (Exception $e) { - $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_AuthException'), - 'Expecting Zend_Gdata_App_AuthException, got '.get_class($e)); - } - } - - public function testUseH9() - { - $serviceName = Zend_Gdata_Health::H9_SANDBOX_SERVICE_NAME; - $client = Zend_Gdata_ClientLogin::getHttpClient($this->user, $this->pass, $serviceName); - $h9 = new Zend_Gdata_Health($client, 'google-MyPHPApp-v1.0', true); - - $profileListFeed = $h9->getHealthProfileListFeed(); - $profileID = $profileListFeed->entry[0]->getProfileID(); - $h9->setProfileID($profileID); - - // query profile feed - $feed1 = $h9->getHealthProfileFeed(); - $this->assertTrue($feed1 instanceof Zend_Gdata_Health_ProfileFeed); - foreach ($feed1->getEntries() as $entry) { - $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileEntry); - $this->assertEquals($entry->getHttpClient(), $feed1->getHttpClient()); - } - - // send CCR - $subject = "Title of your notice goes here"; - $body = "Notice body can contain html entities"; - $type = "html"; - $ccrXML = file_get_contents('Zend/Gdata/Health/_files/ccr_notice_sample.xml', true); - - $responseEntry = $h9->sendHealthNotice($subject, $body, $type, $ccrXML); - - $this->assertTrue($responseEntry instanceof Zend_Gdata_Health_ProfileEntry); - $this->assertEquals($subject, $responseEntry->title->text); - $this->assertEquals($body, $responseEntry->content->text); - $this->assertEquals($type, $responseEntry->content->type); - $this->assertXmlStringEqualsXmlString($responseEntry->getCcr()->saveXML(), $ccrXML); - } - - public function testGetHealthProfileListFeed() - { - // no query - $feed1 = $this->health->getHealthProfileListFeed(); - $this->assertTrue($feed1 instanceof Zend_Gdata_Health_ProfileListFeed); - foreach ($feed1->getEntries() as $entry) { - $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileListEntry); - $this->assertEquals($entry->getHttpClient(), $feed1->getHttpClient()); - } - - // with query object - $query = new Zend_Gdata_Health_Query('https://www.google.com/health/feeds/profile/list'); - $feed2 = $this->health->getHealthProfileListFeed($query); - $this->assertTrue($feed2 instanceof Zend_Gdata_Health_ProfileListFeed); - foreach ($feed2->entry as $entry) { - $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileListEntry); - $this->assertEquals($entry->getHttpClient(), $feed2->getHttpClient()); - } - - // with direct query string - $feed3 = $this->health->getHealthProfileListFeed('https://www.google.com/health/feeds/profile/list'); - $this->assertTrue($feed3 instanceof Zend_Gdata_Health_ProfileListFeed); - foreach ($feed3->entry as $entry) { - $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileListEntry); - $this->assertEquals($entry->getHttpClient(), $feed3->getHttpClient()); - } - - $this->assertEquals($feed1->saveXML(), $feed2->saveXML()); - $this->assertEquals($feed1->saveXML(), $feed3->saveXML()); - $this->assertEquals($feed2->saveXML(), $feed3->saveXML()); - } - - - public function testGetProfileFeedNoQuery() - { - $this->setupProfileID(); - - // no query, digest=false - $profileFeed = $this->health->getHealthProfileFeed(); - $this->assertTrue($profileFeed instanceof Zend_Gdata_Health_ProfileFeed); - $this->assertTrue(count($profileFeed->entry) > 1, 'digest=false, should have multiple elements'); - foreach ($profileFeed->entry as $entry) { - $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileEntry); - $ccr = $entry->getCcr(); - $this->assertTrue($ccr instanceof Zend_Gdata_Health_Extension_Ccr); - $this->assertEquals($entry->getHttpClient(), $profileFeed->getHttpClient()); - } - } - - public function testGetProfileFeedByQuery() - { - $this->setupProfileID(); - $profileID = $this->health->getProfileID(); - - // with direct query string - $feed1 = $this->health->getHealthProfileFeed( - "https://www.google.com/health/feeds/profile/ui/{$profileID}?digest=true"); - $this->assertTrue($feed1 instanceof Zend_Gdata_Health_ProfileFeed); - $this->assertTrue(count($feed1->entry) === 1, 'digest=true, expected a single element'); - foreach ($feed1->entry as $entry) { - $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileEntry); - $ccr = $entry->getCcr(); - $this->assertTrue($ccr instanceof Zend_Gdata_Health_Extension_Ccr); - $this->assertEquals($entry->getHttpClient(), $feed1->getHttpClient()); - } - - // with query object - $query = new Zend_Gdata_Health_Query("https://www.google.com/health/feeds/profile/ui/{$profileID}"); - $query->setDigest('true'); - $feed2 = $this->health->getHealthProfileFeed($query); - $this->assertTrue($feed2 instanceof Zend_Gdata_Health_ProfileFeed); - $this->assertTrue(count($feed2->entry) === 1, 'digest=true, expected a single element'); - foreach ($feed2->entry as $entry) { - $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileEntry); - $ccr = $entry->getCcr(); - $this->assertTrue($ccr instanceof Zend_Gdata_Health_Extension_Ccr); - $this->assertEquals($entry->getHttpClient(), $feed2->getHttpClient()); - } - - $this->assertEquals($feed1->saveXML(), $feed2->saveXML()); - } - - public function testGetProfileEntryNoQuery() - { - try { - $entry = $this->health->getHealthProfileEntry(); - $this->fail('Expecting to catch Zend_Gdata_App_InvalidArgumentException'); - } catch (Exception $e) { - $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_InvalidArgumentException'), - 'Expecting Zend_Gdata_App_InvalidArgumentException, got '.get_class($e)); - } - } - - public function testGetProfileEntry() - { - $this->setupProfileID(); - $profileID = $this->health->getProfileID(); - - $feed = $this->health->getHealthProfileFeed(); - $entryFromProfileQuery = $feed->entry[0]; - $this->assertTrue($entryFromProfileQuery instanceof Zend_Gdata_Health_ProfileEntry); - - // direct query string - $entry1 = $this->health->getHealthProfileEntry($entryFromProfileQuery->id->text); - $this->assertTrue($entry1 instanceof Zend_Gdata_Health_ProfileEntry); - - // query object - $query = new Zend_Gdata_Health_Query("https://www.google.com/health/feeds/profile/ui/{$profileID}"); - $entry2 = $this->health->getHealthProfileEntry($query); - $this->assertTrue($entry2 instanceof Zend_Gdata_Health_ProfileEntry); - - $this->assertEquals($entryFromProfileQuery->getHttpClient(), $entry1->getHttpClient()); - $this->assertEquals($entryFromProfileQuery->getHttpClient(), $entry2->getHttpClient()); - $this->assertEquals($entry1->getHttpClient(), $entry2->getHttpClient()); - - $this->assertXmlStringEqualsXmlString($entryFromProfileQuery->getCcr()->saveXML(), $entry1->getCcr()->saveXML()); - $this->assertXmlStringEqualsXmlString($entryFromProfileQuery->getCcr()->saveXML(), $entry2->getCcr()->saveXML()); - $this->assertXmlStringEqualsXmlString($entry1->getCcr()->saveXML(), $entry2->getCcr()->saveXML()); - } - - public function testSendNoticeWithoutUsingClientLogin() - { - try { - $responseEntry = $this->health->sendHealthNotice("", ""); - $this->fail('Expecting to catch Zend_Gdata_App_AuthException'); - } catch (Exception $e) { - $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_AuthException'), - 'Expecting Zend_Gdata_App_AuthException, got '.get_class($e)); - } - } - - public function testSendNoticeWithoutCcr() - { - $this->setupProfileID(); - $profileID = $this->health->getProfileID(); - - $subject = "Title of your notice goes here"; - $body = "Notice body goes here"; - - $responseEntry = $this->health->sendHealthNotice($subject, $body); - - $this->assertTrue($responseEntry instanceof Zend_Gdata_Health_ProfileEntry); - $this->assertEquals($subject, $responseEntry->title->text); - $this->assertEquals($body, $responseEntry->content->text); - $this->assertNull($responseEntry->getCcr()); - } - - public function testSendNoticeWithoutCcrUsingDirectInsert() - { - $this->setupProfileID(); - $profileID = $this->health->getProfileID(); - - $subject = "Title of your notice goes here"; - $body = "Notice body goes here"; - - $entry = new Zend_Gdata_Health_ProfileEntry(); - - $author = $this->health->newAuthor(); - $author->name = $this->health->newName('John Doe'); - $author->email = $this->health->newEmail('user@example.com'); - $entry->setAuthor(array(0 => $author)); - - $entry->title = $this->health->newTitle($subject); - $entry->content = $this->health->newContent($body); - $entry->content->type = 'text'; - - $ccrXML = file_get_contents('Zend/Gdata/Health/_files/ccr_notice_sample.xml', true); - $entry->setCcr($ccrXML); - - $uri = "https://www.google.com/health/feeds/register/ui/{$profileID}"; - $responseEntry = $this->health->insertEntry($entry, $uri, 'Zend_Gdata_Health_ProfileEntry'); - - $this->assertTrue($responseEntry instanceof Zend_Gdata_Health_ProfileEntry); - $this->assertEquals($subject, $responseEntry->title->text); - $this->assertEquals($author->name->text, 'John Doe'); - $this->assertEquals($author->email->text, 'user@example.com'); - $this->assertEquals($body, $responseEntry->content->text); - } - - public function testSendNoticeWithCcr() - { - $this->setupProfileID(); - $profileID = $this->health->getProfileID(); - - $subject = "Title of your notice goes here"; - $body = "Notice body can contain html entities"; - $type = "html"; - $ccrXML = file_get_contents('Zend/Gdata/Health/_files/ccr_notice_sample.xml', true); - - $responseEntry = $this->health->sendHealthNotice($subject, $body, $type, $ccrXML); - - $this->assertTrue($responseEntry instanceof Zend_Gdata_Health_ProfileEntry); - $this->assertEquals($subject, $responseEntry->title->text); - $this->assertEquals($body, $responseEntry->content->text); - $this->assertEquals($type, $responseEntry->content->type); - $this->assertXmlStringEqualsXmlString($responseEntry->getCcr()->saveXML(), $ccrXML); - } -} -