| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572 |
- <?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-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * @category Zend
- * @package Zend_Service_Simpy
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Service
- * @group Zend_Service_Simpy
- */
- abstract class Zend_Service_Simpy_BaseTests extends PHPUnit_Framework_TestCase
- {
- /**
- * Simpy service consumer proxy
- *
- * @var Zend_Service_Simpy_BaseProxy
- */
- protected $_simpy;
- /**
- * Sample link data
- *
- * @var array
- */
- protected $_link = array(
- 'title' => 'Zend Framework',
- 'href' => 'http://framework.zend.com',
- 'accessType' => 'public',
- 'tags' => array('zend', 'framework', 'php'),
- 'urlNickname' => 'Zend Framework web site',
- 'note' => 'This web site rules!'
- );
- /**
- * Sample note data
- *
- * @var array
- */
- protected $_note = array(
- 'title' => 'Test Note',
- 'tags' => array('test'),
- 'description' => 'This is a test note.'
- );
- public function testException()
- {
- try {
- $this->_simpy->deleteNote(null);
- $this->fail('Exception not thrown');
- } catch (Zend_Service_Exception $e) {
- // success
- }
- }
- public function testSaveLink()
- {
- try {
- extract($this->_link);
- /**
- * Delete the link if it already exists and bypass the exception
- * that would be thrown as a result
- */
- try {
- $this->_simpy->deleteLink($href);
- } catch (Zend_Service_Exception $e) {
- // ignore exception
- }
- /**
- * @see Zend_Service_Simpy_Link
- */
- require_once 'Zend/Service/Simpy/Link.php';
- $this->_simpy->saveLink(
- $title,
- $href,
- Zend_Service_Simpy_Link::ACCESSTYPE_PUBLIC,
- $tags,
- $urlNickname,
- $note
- );
- } catch (Zend_Service_Exception $e) {
- $this->fail('Could not save link: ' . $e->getMessage());
- }
- }
- public function testGetLinks()
- {
- $linkSet = $this->_simpy->getLinks();
- $this->assertEquals(
- $linkSet->getLength(),
- 1,
- 'Link set does not have expected size'
- );
- $link = $linkSet->getIterator()->current();
- extract($this->_link);
- $this->assertEquals(
- $link->getAccessType(),
- $accessType,
- 'Access type does not match'
- );
- $this->assertEquals(
- $link->getUrl(),
- $href,
- 'URL does not match'
- );
- $this->assertNotEquals(
- strtotime($link->getModDate()),
- false,
- 'Mod date is invalid'
- );
- $this->assertNotEquals(
- strtotime($link->getAddDate()),
- false,
- 'Add date is invalid'
- );
- $this->assertEquals(
- $link->getTitle(),
- $title,
- 'Title does not match'
- );
- $this->assertEquals(
- $link->getNickname(),
- $urlNickname,
- 'Nickname does not match'
- );
- $this->assertEquals(
- $link->getTags(),
- $tags,
- 'Tags do not match'
- );
- $this->assertEquals(
- $link->getNote(),
- $note,
- 'Note does not match'
- );
- }
- public function testLinkQuery()
- {
- $date = date('Y-m-d');
- /**
- * @see Zend_Service_Simpy_LinkQuery
- */
- require_once 'Zend/Service/Simpy/LinkQuery.php';
- $linkQuery = new Zend_Service_Simpy_LinkQuery;
- $linkQuery->setQueryString($this->_link['title']);
- $linkQuery->setBeforeDate($date);
- $this->assertNull(
- $linkQuery->getDate(),
- 'Date has been initialized'
- );
- $linkQuery->setAfterDate($date);
- $this->assertNull(
- $linkQuery->getDate(),
- 'Date has been initialized'
- );
- $linkQuery->setDate($date);
- $this->assertNull(
- $linkQuery->getBeforeDate(),
- 'Before date has retained its value'
- );
- $this->assertNull(
- $linkQuery->getAfterDate(),
- 'After date has retained its value'
- );
- $linkQuery
- ->setLimit(1)
- ->setDate(null);
- $this->assertEquals(
- $linkQuery->getLimit(),
- 1,
- 'Limit was not set'
- );
- $linkQuery->setLimit(array());
- $this->assertNull(
- $linkQuery->getLimit(),
- 'Invalid limit value was accepted'
- );
- $linkSet = $this->_simpy->getLinks($linkQuery);
- $this->assertEquals(
- $linkSet->getLength(),
- 1,
- 'Link set does not have the expected size'
- );
- }
- public function testGetTags()
- {
- $tagSet = $this->_simpy->getTags();
- $this->assertEquals(
- $tagSet->getLength(),
- count($this->_link['tags']),
- 'Tag set does not have the expected size'
- );
- foreach ($tagSet as $tag) {
- $this->assertContains(
- $tag->getTag(),
- $this->_link['tags'],
- 'Tag ' . $tag->getTag() . ' does not exist'
- );
- $this->assertEquals(
- $tag->getCount(),
- 1,
- 'Tag count does not match'
- );
- }
- }
- public function testRenameTag()
- {
- $fromTag = 'framework';
- $toTag = 'frameworks';
- $tagsArray = $this->_getTagsArray();
- $this->assertContains(
- $fromTag,
- $tagsArray,
- 'Source tag was not found'
- );
- $this->assertNotContains(
- $toTag,
- $tagsArray,
- 'Destination tag already exists'
- );
- $this->_simpy->renameTag($fromTag, $toTag);
- $tagsArray = $this->_getTagsArray();
- $this->assertContains(
- $toTag,
- $tagsArray,
- 'Destination tag was not found'
- );
- }
- public function testSplitTag()
- {
- $fromTag = 'frameworks';
- $toTag1 = 'framework';
- $toTag2 = 'frameworks';
- $tagsArray = $this->_getTagsArray();
- $this->assertContains(
- $fromTag,
- $tagsArray,
- 'Source tag was not found'
- );
- $this->_simpy->splitTag($fromTag, $toTag1, $toTag2);
- $tagsArray = $this->_getTagsArray();
- $this->assertContains(
- $toTag1,
- $tagsArray,
- 'First destination tag was not found'
- );
- $this->assertContains(
- $toTag2,
- $tagsArray,
- 'Second destination tag was not found'
- );
- }
- public function testMergeTags()
- {
- $fromTag1 = 'framework';
- $fromTag2 = 'frameworks';
- $toTag = 'framework';
- $tagsArray = $this->_getTagsArray();
- $this->assertContains(
- $fromTag1,
- $tagsArray,
- 'First source tag was not found'
- );
- $this->assertContains(
- $fromTag2,
- $tagsArray,
- 'Second source tag was not found'
- );
- $this->_simpy->mergeTags($fromTag1, $fromTag2, $toTag);
- $tagsArray = $this->_getTagsArray();
- $this->assertContains(
- $toTag,
- $tagsArray,
- 'Destination tag was not found'
- );
- }
- public function testRemoveTag()
- {
- $tag = 'zend';
- $tagsArray = $this->_getTagsArray();
- $this->assertContains(
- $tag,
- $tagsArray,
- 'Tag to remove was not found'
- );
- $this->_simpy->removeTag($tag);
- $tagsArray = $this->_getTagsArray();
- $this->assertNotContains(
- $tag,
- $tagsArray,
- 'Tag was not removed'
- );
- }
- public function testDeleteLink()
- {
- $this->_simpy->deleteLink($this->_link['href']);
- $linkSet = $this->_simpy->getLinks();
- $this->assertEquals(
- $linkSet->getLength(),
- 0,
- 'Link was not deleted'
- );
- }
- public function testSaveNote()
- {
- try {
- extract($this->_note);
- $this->_simpy->saveNote(
- $title,
- $tags,
- $description
- );
- } catch (Zend_Service_Exception $e) {
- $this->fail('Could not save note: ' . $e->getMessage());
- }
- }
- public function testGetNotes()
- {
- $noteSet = $this->_simpy->getNotes();
- $this->assertGreaterThanOrEqual(
- $noteSet->getLength(),
- 1,
- 'Note set does not have the expected size'
- );
- $note = $noteSet->getIterator()->current();
- extract($this->_note);
- $this->assertEquals(
- $note->getAccessType(),
- 'private',
- 'Access type does not match'
- );
- $this->assertEquals(
- $note->getUri(),
- 'http://www.simpy.com/simpy/NoteDetails.do?noteId=' . $note->getId(),
- 'URI does not match'
- );
- $this->assertEquals(
- $note->getTitle(),
- $title,
- 'Title does not match'
- );
- $this->assertEquals(
- $note->getTags(),
- $tags,
- 'Tags do not match'
- );
- $this->assertEquals(
- $note->getDescription(),
- $description,
- 'Description does not match'
- );
- $this->assertNotEquals(
- strtotime($note->getAddDate()),
- false,
- 'Add date is invalid'
- );
- $this->assertNotEquals(
- strtotime($note->getModDate()),
- false,
- 'Mod date is invalid'
- );
- }
- public function testDeleteNote()
- {
- $noteSet = $this->_simpy->getNotes();
- $noteId = $noteSet->getIterator()->current()->getId();
- $this->_simpy->deleteNote($noteId);
- $noteSet = $this->_simpy->getNotes();
- foreach ($noteSet as $note) {
- $this->assertNotEquals(
- $note->getId(),
- $noteId,
- 'Note was not deleted'
- );
- }
- }
- private function _getWatchlistIterator()
- {
- $watchlistSet = $this->_simpy->getWatchlists();
- $watchlistSetIterator = $watchlistSet->getIterator();
- if (!count($watchlistSetIterator)) {
- $this->markTestSkipped('Account has no watchlists');
- }
- return $watchlistSetIterator;
- }
- public function testGetWatchlists()
- {
- $watchlistSetIterator = $this->_getWatchlistIterator();
- $watchlist = $watchlistSetIterator->current();
- $this->assertNotNull(
- $watchlist,
- 'Watchlist is invalid'
- );
- }
- public function testGetWatchlist()
- {
- $watchlistSetIterator = $this->_getWatchlistIterator();
- $watchlistId = $watchlistSetIterator->current()->getId();
- $watchlist = $this->_simpy->getWatchlist($watchlistId);
- $this->assertEquals(
- $watchlist->getId(),
- $watchlistId,
- 'ID does not match'
- );
- $watchlistName = $watchlist->getName();
- $this->assertFalse(
- empty($watchlistName),
- 'Name is empty'
- );
- $this->assertNotEquals(
- strtotime($watchlist->getAddDate()),
- false,
- 'Add date is invalid'
- );
- $this->assertGreaterThanOrEqual(
- $watchlist->getNewLinks(),
- 0,
- 'New link count is invalid'
- );
- $this->assertTrue(
- is_array($watchlist->getUsers()),
- 'User list is not an array'
- );
- }
- public function testWatchlistFilters()
- {
- $watchlistSetIterator = $this->_getWatchlistIterator();
- $watchlistId = $watchlistSetIterator->current()->getId();
- $watchlist = $this->_simpy->getWatchlist($watchlistId);
- $filterSet = $watchlist->getFilters();
- if (!$filterSet->getLength()) {
- $this->markTestSkipped('Watchlist has no filters');
- }
- $filter = $filterSet->getIterator()->current();
- $filterName = $filter->getName();
- $this->assertFalse(
- empty($filterName),
- 'Name is invalid'
- );
- $filterQuery = $filter->getQuery();
- $this->assertFalse(
- empty($filterQuery),
- 'Query is invalid'
- );
- }
- protected function _getTagsArray()
- {
- $tagSet = $this->_simpy->getTags();
- $tagArray = array();
- foreach ($tagSet as $tag) {
- $tagArray[] = $tag->getTag();
- }
- return $tagArray;
- }
- }
|