Quellcode durchsuchen

Fixes ZF-3077 Modified Zend_Service_Simpy tests to include an offline version that pulls credentials from the TestConfiguration file and modified Zend_Service_Simpy itself to use Zend_Http_Client directly rather than Zend_Rest_Client

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15885 44c647ce-9c0f-0410-b52a-842ac1e357ba
elazar vor 16 Jahren
Ursprung
Commit
068d274338
41 geänderte Dateien mit 954 neuen und 115 gelöschten Zeilen
  1. 25 11
      library/Zend/Service/Simpy.php
  2. 2 0
      tests/TestConfiguration.php.dist
  3. 3 7
      tests/Zend/Service/AllTests.php
  4. 88 0
      tests/Zend/Service/Simpy/AllTests.php
  5. 114 0
      tests/Zend/Service/Simpy/BaseProxy.php
  6. 72 97
      tests/Zend/Service/Simpy/BaseTests.php
  7. 87 0
      tests/Zend/Service/Simpy/OfflineProxy.php
  8. 41 0
      tests/Zend/Service/Simpy/OfflineTests.php
  9. 71 0
      tests/Zend/Service/Simpy/OnlineProxy.php
  10. 41 0
      tests/Zend/Service/Simpy/OnlineTests.php
  11. 5 0
      tests/Zend/Service/Simpy/_files/testDeleteLink_deleteLink_1
  12. 7 0
      tests/Zend/Service/Simpy/_files/testDeleteLink_getLinks_1
  13. 5 0
      tests/Zend/Service/Simpy/_files/testDeleteNote_deleteNote_1
  14. 23 0
      tests/Zend/Service/Simpy/_files/testDeleteNote_getNotes_1
  15. 7 0
      tests/Zend/Service/Simpy/_files/testDeleteNote_getNotes_2
  16. 5 0
      tests/Zend/Service/Simpy/_files/testException_deleteNote_1
  17. 32 0
      tests/Zend/Service/Simpy/_files/testGetLinks_getLinks_1
  18. 23 0
      tests/Zend/Service/Simpy/_files/testGetNotes_getNotes_1
  19. 15 0
      tests/Zend/Service/Simpy/_files/testGetTags_getTags_1
  20. 15 0
      tests/Zend/Service/Simpy/_files/testGetWatchlist_getWatchlist_1
  21. 23 0
      tests/Zend/Service/Simpy/_files/testGetWatchlist_getWatchlists_1
  22. 23 0
      tests/Zend/Service/Simpy/_files/testGetWatchlists_getWatchlists_1
  23. 32 0
      tests/Zend/Service/Simpy/_files/testLinkQuery_getLinks_1
  24. 17 0
      tests/Zend/Service/Simpy/_files/testMergeTags_getTags_1
  25. 15 0
      tests/Zend/Service/Simpy/_files/testMergeTags_getTags_2
  26. 5 0
      tests/Zend/Service/Simpy/_files/testMergeTags_mergeTags_1
  27. 15 0
      tests/Zend/Service/Simpy/_files/testRemoveTag_getTags_1
  28. 13 0
      tests/Zend/Service/Simpy/_files/testRemoveTag_getTags_2
  29. 5 0
      tests/Zend/Service/Simpy/_files/testRemoveTag_removeTag_1
  30. 0 0
      tests/Zend/Service/Simpy/_files/testRenameTag_getHttpClient_1
  31. 15 0
      tests/Zend/Service/Simpy/_files/testRenameTag_getTags_1
  32. 15 0
      tests/Zend/Service/Simpy/_files/testRenameTag_getTags_2
  33. 5 0
      tests/Zend/Service/Simpy/_files/testRenameTag_renameTag_1
  34. 5 0
      tests/Zend/Service/Simpy/_files/testSaveLink_deleteLink_1
  35. 5 0
      tests/Zend/Service/Simpy/_files/testSaveLink_saveLink_1
  36. 5 0
      tests/Zend/Service/Simpy/_files/testSaveNote_saveNote_1
  37. 15 0
      tests/Zend/Service/Simpy/_files/testSplitTag_getTags_1
  38. 17 0
      tests/Zend/Service/Simpy/_files/testSplitTag_getTags_2
  39. 5 0
      tests/Zend/Service/Simpy/_files/testSplitTag_splitTag_1
  40. 15 0
      tests/Zend/Service/Simpy/_files/testWatchlistFilters_getWatchlist_1
  41. 23 0
      tests/Zend/Service/Simpy/_files/testWatchlistFilters_getWatchlists_1

+ 25 - 11
library/Zend/Service/Simpy.php

@@ -22,6 +22,8 @@
  */
 
 
+require_once 'Zend/Http/Client.php';
+
 /**
  * @category   Zend
  * @package    Zend_Service
@@ -37,14 +39,14 @@ class Zend_Service_Simpy
      *
      * @var string
      */
-    protected $_baseUri = 'http://simpy.com';
+    protected $_baseUri = 'http://simpy.com/simpy/api/rest/';
 
     /**
-     * Zend_Service_Rest object
+     * HTTP client for use in making web service calls 
      *
-     * @var Zend_Service_Rest
+     * @var Zend_Http_Client 
      */
-    protected $_rest;
+    protected $_http;
 
     /**
      * Constructs a new Simpy (free) REST API Client
@@ -59,17 +61,27 @@ class Zend_Service_Simpy
          * @see Zend_Service_Rest
          */
         require_once 'Zend/Rest/Client.php';
-        $this->_rest = new Zend_Rest_Client($this->_baseUri);
-        $this->_rest->getHttpClient()
-            ->setAuth($username, $password);
+        $this->_http = new Zend_Http_Client;
+        $this->_http->setAuth($username, $password);
+    }
+
+    /**
+     * Returns the HTTP client currently in use by this class for REST API 
+     * calls, intended mainly for testing.
+     *
+     * @return Zend_Http_Client
+     */
+    public function getHttpClient()
+    {
+        return $this->_http;
     }
 
     /**
      * Sends a request to the REST API service and does initial processing
      * on the response.
      *
-     * @param  string       $op    Name of the operation for the request
-     * @param  string|array $query Query data for the request (optional)
+     * @param  string $op    Name of the operation for the request
+     * @param  array  $query Query data for the request (optional)
      * @throws Zend_Service_Exception
      * @return DOMDocument Parsed XML response
      */
@@ -77,9 +89,11 @@ class Zend_Service_Simpy
     {
         if ($query != null) {
             $query = array_diff($query, array_filter($query, 'is_null'));
+            $query = '?' . http_build_query($query);
         }
 
-        $response = $this->_rest->restGet('/simpy/api/rest/' . $op . '.do', $query);
+        $this->_http->setUri($this->_baseUri . $op . '.do' . $query);
+        $response = $this->_http->request('GET');
 
         if ($response->isSuccessful()) {
             $doc = new DOMDocument();
@@ -108,7 +122,7 @@ class Zend_Service_Simpy
          * @see Zend_Service_Exception
          */
         require_once 'Zend/Service/Exception.php';
-        throw new Zend_Service_Exception('HTTP ' . $response->getStatus());
+        throw new Zend_Service_Exception($response->getMessage(), $response->getStatus());
     }
 
     /**

+ 2 - 0
tests/TestConfiguration.php.dist

@@ -468,6 +468,8 @@ define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY', 'Enter API key here');
  * Zend_Service_Simpy tests
  */
 define('TESTS_ZEND_SERVICE_SIMPY_ENABLED', false);
+define('TESTS_ZEND_SERVICE_SIMPY_USERNAME', 'syapizend');
+define('TESTS_ZEND_SERVICE_SIMPY_PASSWORD', 'mgt37ge');
 
 /**
  * Zend_Service_SlideShare tests

+ 3 - 7
tests/Zend/Service/AllTests.php

@@ -72,9 +72,9 @@ require_once 'Zend/Service/Nirvanix/AllTests.php';
 require_once 'Zend/Service/ReCaptcha/AllTests.php';
 
 /**
- * @see Zend_Service_SimpyTest
+ * @see Zend_Service_Simpy_AllTests
  */
-require_once 'Zend/Service/SimpyTest.php';
+require_once 'Zend/Service/Simpy/AllTests.php';
 
 /**
  * @see Zend_Service_SlideShareTest
@@ -142,11 +142,7 @@ class Zend_Service_AllTests
         $suite->addTest(Zend_Service_Flickr_AllTests::suite());
         $suite->addTest(Zend_Service_Nirvanix_AllTests::suite());
         $suite->addTest(Zend_Service_ReCaptcha_AllTests::suite());
-        if (defined('TESTS_ZEND_SERVICE_SIMPY_ENABLED') && constant('TESTS_ZEND_SERVICE_SIMPY_ENABLED')) {
-            $suite->addTestSuite('Zend_Service_SimpyTest');
-        } else {
-            $suite->addTestSuite('Zend_Service_SimpyTest_Skip');
-        }
+        $suite->addTest(Zend_Service_Simpy_AllTests::suite());
         $suite->addTestSuite('Zend_Service_SlideShareTest');
         $suite->addTest(Zend_Service_StrikeIron_AllTests::suite());
         $suite->addTest(Zend_Service_Technorati_AllTests::suite());

+ 88 - 0
tests/Zend/Service/Simpy/AllTests.php

@@ -0,0 +1,88 @@
+<?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_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: AllTests.php 12004 2008-10-18 14:29:41Z mikaelkael $
+ */
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Zend_Service_Simpy_AllTests::main');
+}
+
+/**
+ * Test helper
+ */
+require_once dirname(__FILE__) . '/../../../TestHelper.php';
+
+/**
+ * Exclude from code coverage report
+ */
+PHPUnit_Util_Filter::addFileToFilter(__FILE__);
+
+/** @see Zend_Service_Simpy_OnlineTest */
+require_once 'Zend/Service/Simpy/OnlineTest.php';
+
+/** @see Zend_Service_Simpy_OfflineTest */
+require_once 'Zend/Service/Simpy/OfflineTest.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Service_Simpy_AllTests
+{
+    /**
+     * Runs this test suite
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+
+    /**
+     * Creates and returns this test suite
+     *
+     * @return PHPUnit_Framework_TestSuite
+     */
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend Framework - Zend_Service_Simpy');
+
+        $suite->addTestSuite('Zend_Service_Simpy_OfflineTest');
+
+        if (defined('TESTS_ZEND_SERVICE_SIMPY_ENABLED') &&
+            constant('TESTS_ZEND_SERVICE_SIMPY_ENABLED') &&
+            defined('TESTS_ZEND_SERVICE_SIMPY_USERNAME') &&
+            constant('TESTS_ZEND_SERVICE_SIMPY_USERNAME') &&
+            defined('TESTS_ZEND_SERVICE_SIMPY_PASSWORD')
+            constant('TESTS_ZEND_SERVICE_SIMPY_PASSWORD')) {
+            $suite->addTestSuite('Zend_Service_Simpy_OnlineTest');
+        }
+
+        return $suite;
+    }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Zend_Service_Simpy_AllTests::main') {
+    Zend_Service_Simpy_AllTests::main();
+}

+ 114 - 0
tests/Zend/Service/Simpy/BaseProxy.php

@@ -0,0 +1,114 @@
+<?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_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: SimpyTest.php 11973 2008-10-15 16:00:56Z matthew $
+ */
+
+
+/**
+ * @see Zend_Service_Simpy
+ */
+require_once 'Zend/Service/Simpy.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Service_Simpy_BaseProxy
+{
+    /**
+     * Simpy service consumer
+     *
+     * @var Zend_Service_Simpy
+     */
+    protected $_simpy;
+
+    /**
+     * Name of the current test case being executed
+     *
+     * @var string
+     */
+    protected $_test;
+
+    /**
+     * Mapping of methods to the number of calls made per method for the 
+     * current test case being executed
+     *
+     * @var array
+     */
+    protected $_calls;
+
+    /**
+     * Constructor to initialize the service consumer.
+     *
+     * @param string $test Name of the test case currently being executed
+     * @return void
+     */
+    public final function __construct($test)
+    {
+        $this->_test = $test;
+        $this->_calls = array();
+
+        if (defined('TESTS_ZEND_SERVICE_SIMPY_USERNAME')) {
+            $username = TESTS_ZEND_SERVICE_SIMPY_USERNAME;
+            $password = TESTS_ZEND_SERVICE_SIMPY_PASSWORD;
+        } else {
+            $username = null;
+            $password = null;
+        }
+
+        $this->_simpy = new Zend_Service_Simpy($username, $password);
+
+        $this->init();
+    }
+
+    /**
+     * Initialize method to be overridden in subclasses if needed.
+     *
+     * @return void
+     */
+    public function init()
+    {
+    }
+
+    /**
+     * Returns the path to the file intended to contain the service consumer 
+     * response for the current method call.
+     *
+     * @param string $name Name of the method being called
+     * @return string File path
+     */
+    protected function _getFilePath($name)
+    {
+        if (!isset($this->_calls[$name])) {
+            $this->_calls[$name] = 0;
+        }
+
+        $this->_calls[$name]++;
+
+        $dir = dirname(__FILE__) . '/_files/';
+        $file = $this->_test . '_' . $name . '_' . $this->_calls[$name];
+
+        return $dir . $file;
+    }
+}

+ 72 - 97
tests/Zend/Service/SimpyTest.php → tests/Zend/Service/Simpy/BaseTests.php

@@ -25,12 +25,7 @@
 /**
  * Test helper
  */
-require_once dirname(__FILE__) . '/../../TestHelper.php';
-
-/**
- * @see Zend_Service_Simpy
- */
-require_once 'Zend/Service/Simpy.php';
+require_once dirname(__FILE__) . '/../../../TestHelper.php';
 
 
 /**
@@ -40,12 +35,12 @@ require_once 'Zend/Service/Simpy.php';
  * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
+abstract class Zend_Service_Simpy_BaseTests extends PHPUnit_Framework_TestCase
 {
     /**
-     * Simpy service consumer
+     * Simpy service consumer proxy
      *
-     * @var Zend_Service_Simpy
+     * @var Zend_Service_Simpy_BaseProxy
      */
     protected $_simpy;
 
@@ -74,19 +69,6 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
         'description' => 'This is a test note.'
     );
 
-    public function setUp()
-    {
-        sleep(5);
-
-        $this->_simpy = new Zend_Service_Simpy('syapizend', 'mgt37ge');
-
-        /**
-         * Until Simpy includes time zone support, timestamp values must be
-         * tested against the time zone in use by Simpy's servers
-         */
-        date_default_timezone_set('America/New_York');
-    }
-
     public function testException()
     {
         try {
@@ -141,7 +123,6 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
         );
 
         $link = $linkSet->getIterator()->current();
-        $date = date('Y-m-d');
         extract($this->_link);
 
         $this->assertEquals(
@@ -156,16 +137,16 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
             'URL does not match'
         );
 
-        $this->assertEquals(
-            substr($link->getModDate(), 0, 10),
-            $date,
-            'Mod date does not match'
+        $this->assertNotEquals(
+            strtotime($link->getModDate()),
+            false,
+            'Mod date is invalid'
         );
 
-        $this->assertEquals(
-            substr($link->getAddDate(), 0, 10),
-            $date,
-            'Add date does not match'
+        $this->assertNotEquals(
+            strtotime($link->getAddDate()),
+            false,
+            'Add date is invalid'
         );
 
         $this->assertEquals(
@@ -229,7 +210,9 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
             'After date has retained its value'
         );
 
-        $linkQuery->setLimit(1);
+        $linkQuery
+            ->setLimit(1)
+            ->setDate(null);
 
         $this->assertEquals(
             $linkQuery->getLimit(),
@@ -423,10 +406,9 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
 
     public function testGetNotes()
     {
-        $date = date('Y-m-d');
         $noteSet = $this->_simpy->getNotes();
 
-        $this->assertEquals(
+        $this->assertGreaterThanOrEqual(
             $noteSet->getLength(),
             1,
             'Note set does not have the expected size'
@@ -465,16 +447,16 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
             'Description does not match'
         );
 
-        $this->assertEquals(
-            $note->getAddDate(),
-            $date,
-            'Add date does not match'
+        $this->assertNotEquals(
+            strtotime($note->getAddDate()),
+            false,
+            'Add date is invalid'
         );
 
-        $this->assertEquals(
-            $note->getModDate(),
-            $date,
-            'Mod date does not match'
+        $this->assertNotEquals(
+            strtotime($note->getModDate()),
+            false,
+            'Mod date is invalid'
         );
     }
 
@@ -493,16 +475,22 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
         }
     }
 
-    public function testGetWatchlists()
+    private function _getWatchlistIterator()
     {
         $watchlistSet = $this->_simpy->getWatchlists();
-        $watchlist = $watchlistSet->getIterator()->current();
+        $watchlistSetIterator = $watchlistSet->getIterator();
 
-        $this->assertEquals(
-            $watchlistSet->getLength(),
-            1,
-            'Watchlist set does not have the expected size'
-        );
+        if (!count($watchlistSetIterator)) {
+            $this->markTestSkipped('Account has no watchlists');
+        }
+        
+        return $watchlistSetIterator;
+    }
+
+    public function testGetWatchlists()
+    {
+        $watchlistSetIterator = $this->_getWatchlistIterator(); 
+        $watchlist = $watchlistSetIterator->current();
 
         $this->assertNotNull(
             $watchlist,
@@ -512,67 +500,67 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
 
     public function testGetWatchlist()
     {
-        $watchlist = $this->_simpy->getWatchlist('1331');
+        $watchlistSetIterator = $this->_getWatchlistIterator(); 
+        $watchlistId = $watchlistSetIterator->current()->getId();
+
+        $watchlist = $this->_simpy->getWatchlist($watchlistId);
 
         $this->assertEquals(
             $watchlist->getId(),
-            '1331',
+            $watchlistId,
             'ID does not match'
         );
 
-        $this->assertEquals(
-            $watchlist->getName(),
-            'Test Watchlist',
-            'Name does not match'
-        );
+        $watchlistName = $watchlist->getName();
 
-        $this->assertEquals(
-            $watchlist->getDescription(),
-            'This is a watchlist for testing purposes. Please do not remove it.',
-            'Description does not match'
+        $this->assertFalse(
+            empty($watchlistName),
+            'Name is empty'
         );
 
-        $this->assertEquals(
-            $watchlist->getAddDate(),
-            'Fri Dec 08 21:40:56 EST 2006',
-            'Add date does not match'
+        $this->assertNotEquals(
+            strtotime($watchlist->getAddDate()),
+            false,
+            'Add date is invalid'
         );
 
-        $this->assertEquals(
+        $this->assertGreaterThanOrEqual(
             $watchlist->getNewLinks(),
             0,
-            'New link count does not match'
+            'New link count is invalid'
         );
 
-        $this->assertEquals(
-            $watchlist->getUsers(),
-            array('otis'),
-            'User list does not match'
+        $this->assertTrue(
+            is_array($watchlist->getUsers()),
+            'User list is not an array'
         );
     }
 
     public function testWatchlistFilters()
     {
-        $filterSet = $this->_simpy->getWatchlist('1331')->getFilters();
+        $watchlistSetIterator = $this->_getWatchlistIterator(); 
+        $watchlistId = $watchlistSetIterator->current()->getId();
+        $watchlist = $this->_simpy->getWatchlist($watchlistId);
+        $filterSet = $watchlist->getFilters();
 
-        $this->assertEquals(
-            $filterSet->getLength(),
-            1,
-            'Filter set does not have the expected size'
-        );
+        if (!$filterSet->getLength()) {
+            $this->markTestSkipped('Watchlist has no filters');
+        }
 
         $filter = $filterSet->getIterator()->current();
 
-        $this->assertEquals(
-            $filter->getName(),
-            'Test Filter',
-            'Name does not match'
+        $filterName = $filter->getName();
+
+        $this->assertFalse(
+            empty($filterName),
+            'Name is invalid'
         );
 
-        $this->assertEquals(
-            $filter->getQuery(),
-            'zend',
-            'Query does not match'
+        $filterQuery = $filter->getQuery();
+
+        $this->assertFalse(
+            empty($filterQuery),
+            'Query is invalid'
         );
     }
 
@@ -588,16 +576,3 @@ class Zend_Service_SimpyTest extends PHPUnit_Framework_TestCase
         return $tagArray;
     }
 }
-
-
-class Zend_Service_SimpyTest_Skip extends PHPUnit_Framework_TestCase
-{
-    public function setUp()
-    {
-        $this->markTestSkipped('Zend_Service_Simpy tests not enabled in TestConfiguration.php');
-    }
-
-    public function testNothing()
-    {
-    }
-}

+ 87 - 0
tests/Zend/Service/Simpy/OfflineProxy.php

@@ -0,0 +1,87 @@
+<?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_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: SimpyTest.php 11973 2008-10-15 16:00:56Z matthew $
+ */
+
+
+require_once 'BaseProxy.php';
+
+/**
+ * @see Zend_Http_Client_Adapter_Test
+ */
+require_once 'Zend/Http/Client/Adapter/Test.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Service_Simpy_OfflineProxy extends Zend_Service_Simpy_BaseProxy
+{
+    /**
+     * Test adapter, stored because Zend_Http_Client provides no accessor 
+     * method or public property for it
+     *
+     * @var Zend_Http_Client_Adapter
+     */
+    protected $_adapter;
+
+    /**
+     * Initialize the HTTP client test adapter.
+     *
+     * @return void
+     */
+    public function init()
+    {
+        $this->_adapter = new Zend_Http_Client_Adapter_Test;
+        $this->_simpy->getHttpClient()->setAdapter($this->_adapter);
+    }
+
+    /**
+     * Proxy all method calls to the service consumer object using a test 
+     * HTTP client adapter and reading responses from local files.
+     *
+     * @param string $name Name of the method called
+     * @param array $args Arguments passed in the method call
+     * @return mixed Return value of the called method
+     */
+    public function __call($name, array $args)
+    {
+        $file = $this->_getFilePath($name);
+        $body = file_get_contents($file);
+
+        $this->_adapter->setResponse(
+            'HTTP/1.1 200 OK' . "\r\n" . 
+            'Content-Type: text/xml' . "\r\n" .
+            "\r\n" . 
+            $body
+        );
+
+        $return = call_user_func_array(
+            array($this->_simpy, $name),
+            $args
+        );
+
+        return $return;
+    }
+}

+ 41 - 0
tests/Zend/Service/Simpy/OfflineTests.php

@@ -0,0 +1,41 @@
+<?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_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: SimpyTest.php 11973 2008-10-15 16:00:56Z matthew $
+ */
+
+
+require_once 'BaseTests.php';
+require_once 'OfflineProxy.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Service_Simpy_OfflineTests extends Zend_Service_Simpy_BaseTests 
+{
+    public function setUp()
+    {
+        $this->_simpy = new Zend_Service_Simpy_OfflineProxy($this->getName());
+    }
+}

+ 71 - 0
tests/Zend/Service/Simpy/OnlineProxy.php

@@ -0,0 +1,71 @@
+<?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_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: SimpyTest.php 11973 2008-10-15 16:00:56Z matthew $
+ */
+
+
+require_once 'BaseProxy.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Service_Simpy_OnlineProxy extends Zend_Service_Simpy_BaseProxy
+{
+    /**
+     * Proxy all method calls to the service consumer object and write 
+     * responses to local files, regardless of whether service calls result 
+     * in an exception being thrown.
+     *
+     * @param string $name Name of the method called
+     * @param array $args Arguments passed in the method call
+     * @return mixed Return value of the called method
+     */
+    public function __call($name, array $args)
+    {
+        sleep(3);
+
+        try {
+            $return = call_user_func_array(
+                array($this->_simpy, $name),
+                $args
+            );
+        } catch (Exception $e) { }
+
+        $response = $this->_simpy
+            ->getHttpClient()
+            ->getLastResponse()
+            ->getBody();
+
+        $file = $this->_getFilePath($name);
+
+        file_put_contents($file, $response);
+
+        if (isset($e)) {
+            throw $e;
+        }
+
+        return $return;
+    }
+}

+ 41 - 0
tests/Zend/Service/Simpy/OnlineTests.php

@@ -0,0 +1,41 @@
+<?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_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: SimpyTest.php 11973 2008-10-15 16:00:56Z matthew $
+ */
+
+
+require_once 'BaseTests.php';
+require_once 'OnlineProxy.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Service_Simpy
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Service_Simpy_OnlineTests extends Zend_Service_Simpy_BaseTests 
+{
+    public function setUp()
+    {
+        $this->_simpy = new Zend_Service_Simpy_OnlineProxy($this->getName());
+    }
+}

+ 5 - 0
tests/Zend/Service/Simpy/_files/testDeleteLink_deleteLink_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Link deleted successfully.]]></message>
+</status>

+ 7 - 0
tests/Zend/Service/Simpy/_files/testDeleteLink_getLinks_1

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+    <links/>
+  
+  
+

+ 5 - 0
tests/Zend/Service/Simpy/_files/testDeleteNote_deleteNote_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Note deleted successfully.]]></message>
+</status>

+ 23 - 0
tests/Zend/Service/Simpy/_files/testDeleteNote_getNotes_1

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <notes>
+      
+        <note accessType="private">
+          <uri><![CDATA[http://www.simpy.com/simpy/NoteDetails.do?noteId=21984]]></uri>
+          <id>21984</id>
+          <modDate>2009-06-04</modDate>
+          <addDate>2009-06-04 </addDate>
+          <title><![CDATA[Test Note]]></title>
+          <tags>
+            
+              <tag><![CDATA[test]]></tag>
+            
+          </tags>
+          <description><![CDATA[This is a test note.]]></description>
+        </note>
+      
+    </notes>
+  
+

+ 7 - 0
tests/Zend/Service/Simpy/_files/testDeleteNote_getNotes_2

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+    <notes/>
+  
+  
+

+ 5 - 0
tests/Zend/Service/Simpy/_files/testException_deleteNote_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>200</code>
+  <message><![CDATA[Unknown Note.]]></message>
+</status>

+ 32 - 0
tests/Zend/Service/Simpy/_files/testGetLinks_getLinks_1

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <links>
+      
+        <link clicks="1" 
+          
+            
+            accessType="public"
+          
+          >
+          <url><![CDATA[http://framework.zend.com]]></url>
+          <modDate>2009-06-04</modDate>
+          <addDate>2009-06-04 00:14</addDate>
+          <title><![CDATA[Zend Framework]]></title>
+          <nickname><![CDATA[Zend Framework web site]]></nickname>
+          <tags>
+            
+              <tag><![CDATA[zend]]></tag>
+            
+              <tag><![CDATA[framework]]></tag>
+            
+              <tag><![CDATA[php]]></tag>
+            
+          </tags>
+          <note><![CDATA[This web site rules!]]></note>
+        </link>
+      
+    </links>
+  
+

+ 23 - 0
tests/Zend/Service/Simpy/_files/testGetNotes_getNotes_1

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <notes>
+      
+        <note accessType="private">
+          <uri><![CDATA[http://www.simpy.com/simpy/NoteDetails.do?noteId=21984]]></uri>
+          <id>21984</id>
+          <modDate>2009-06-04</modDate>
+          <addDate>2009-06-04 </addDate>
+          <title><![CDATA[Test Note]]></title>
+          <tags>
+            
+              <tag><![CDATA[test]]></tag>
+            
+          </tags>
+          <description><![CDATA[This is a test note.]]></description>
+        </note>
+      
+    </notes>
+  
+

+ 15 - 0
tests/Zend/Service/Simpy/_files/testGetTags_getTags_1

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="framework" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 15 - 0
tests/Zend/Service/Simpy/_files/testGetWatchlist_getWatchlist_1

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+
+<watchlist id="1331" name="Test Watchlist"
+       description="This is a watchlist for testing purposes. Please do not remove it."
+       addDate="Fri Dec 08 21:40:56 EST 2006"
+       newLinks="0">
+
+  
+    <user username="otis"/>
+  
+  
+    <filter name="Test Filter" query="zend"/>
+  
+</watchlist>

+ 23 - 0
tests/Zend/Service/Simpy/_files/testGetWatchlist_getWatchlists_1

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <watchlists>
+      
+        
+        <watchlist id="1331" name="Test Watchlist"
+          description="This is a watchlist for testing purposes. Please do not remove it."
+          addDate="Fri Dec 08 21:40:56 EST 2006" newLinks="0" >
+
+            
+              <user username="otis"/>
+            
+            
+              <filter name="Test Filter"
+                query="zend"/>
+            
+        </watchlist>
+      
+    </watchlists>
+  
+

+ 23 - 0
tests/Zend/Service/Simpy/_files/testGetWatchlists_getWatchlists_1

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <watchlists>
+      
+        
+        <watchlist id="1331" name="Test Watchlist"
+          description="This is a watchlist for testing purposes. Please do not remove it."
+          addDate="Fri Dec 08 21:40:56 EST 2006" newLinks="0" >
+
+            
+              <user username="otis"/>
+            
+            
+              <filter name="Test Filter"
+                query="zend"/>
+            
+        </watchlist>
+      
+    </watchlists>
+  
+

+ 32 - 0
tests/Zend/Service/Simpy/_files/testLinkQuery_getLinks_1

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <links>
+      
+        <link clicks="1" 
+          
+            
+            accessType="public"
+          
+          >
+          <url><![CDATA[http://framework.zend.com]]></url>
+          <modDate>2009-06-04</modDate>
+          <addDate>2009-06-04 00:14</addDate>
+          <title><![CDATA[Zend Framework]]></title>
+          <nickname><![CDATA[Zend Framework web site]]></nickname>
+          <tags>
+            
+              <tag><![CDATA[zend]]></tag>
+            
+              <tag><![CDATA[framework]]></tag>
+            
+              <tag><![CDATA[php]]></tag>
+            
+          </tags>
+          <note><![CDATA[This web site rules!]]></note>
+        </link>
+      
+    </links>
+  
+

+ 17 - 0
tests/Zend/Service/Simpy/_files/testMergeTags_getTags_1

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="framework" count="1"/>
+      
+        <tag name="frameworks" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 15 - 0
tests/Zend/Service/Simpy/_files/testMergeTags_getTags_2

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="framework" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 5 - 0
tests/Zend/Service/Simpy/_files/testMergeTags_mergeTags_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Tags merged successfully.]]></message>
+</status>

+ 15 - 0
tests/Zend/Service/Simpy/_files/testRemoveTag_getTags_1

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="framework" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 13 - 0
tests/Zend/Service/Simpy/_files/testRemoveTag_getTags_2

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="framework" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+    </tags>
+  
+

+ 5 - 0
tests/Zend/Service/Simpy/_files/testRemoveTag_removeTag_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Tag removed successfully.]]></message>
+</status>

+ 0 - 0
tests/Zend/Service/Simpy/_files/testRenameTag_getHttpClient_1


+ 15 - 0
tests/Zend/Service/Simpy/_files/testRenameTag_getTags_1

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="framework" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 15 - 0
tests/Zend/Service/Simpy/_files/testRenameTag_getTags_2

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="frameworks" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 5 - 0
tests/Zend/Service/Simpy/_files/testRenameTag_renameTag_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Tag renamed successfully.]]></message>
+</status>

+ 5 - 0
tests/Zend/Service/Simpy/_files/testSaveLink_deleteLink_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>200</code>
+  <message><![CDATA[Unknown URL.]]></message>
+</status>

+ 5 - 0
tests/Zend/Service/Simpy/_files/testSaveLink_saveLink_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Link saved successfully.]]></message>
+</status>

+ 5 - 0
tests/Zend/Service/Simpy/_files/testSaveNote_saveNote_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Note saved successfully.]]></message>
+</status>

+ 15 - 0
tests/Zend/Service/Simpy/_files/testSplitTag_getTags_1

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="frameworks" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 17 - 0
tests/Zend/Service/Simpy/_files/testSplitTag_getTags_2

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <tags user="syapizend">
+      
+        <tag name="framework" count="1"/>
+      
+        <tag name="frameworks" count="1"/>
+      
+        <tag name="php" count="1"/>
+      
+        <tag name="zend" count="1"/>
+      
+    </tags>
+  
+

+ 5 - 0
tests/Zend/Service/Simpy/_files/testSplitTag_splitTag_1

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<status>
+  <code>0</code>
+  <message><![CDATA[Tag split successfully.]]></message>
+</status>

+ 15 - 0
tests/Zend/Service/Simpy/_files/testWatchlistFilters_getWatchlist_1

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+
+<watchlist id="1331" name="Test Watchlist"
+       description="This is a watchlist for testing purposes. Please do not remove it."
+       addDate="Fri Dec 08 21:40:56 EST 2006"
+       newLinks="0">
+
+  
+    <user username="otis"/>
+  
+  
+    <filter name="Test Filter" query="zend"/>
+  
+</watchlist>

+ 23 - 0
tests/Zend/Service/Simpy/_files/testWatchlistFilters_getWatchlists_1

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+  
+  
+    <watchlists>
+      
+        
+        <watchlist id="1331" name="Test Watchlist"
+          description="This is a watchlist for testing purposes. Please do not remove it."
+          addDate="Fri Dec 08 21:40:56 EST 2006" newLinks="0" >
+
+            
+              <user username="otis"/>
+            
+            
+              <filter name="Test Filter"
+                query="zend"/>
+            
+        </watchlist>
+      
+    </watchlists>
+  
+