summaryrefslogtreecommitdiff
path: root/zend/tests/Zend/Gdata/DocsOnlineTest.php
blob: f573f195bae1550d56e7c6ae8247a36de5b948cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?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_Gdata_Docs
 * @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 $
 */

require_once 'Zend/Gdata/Docs.php';
require_once 'Zend/Http/Client.php';
require_once 'Zend/Gdata/ClientLogin.php';

/**
 * @category   Zend
 * @package    Zend_Gdata_Docs
 * @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_Gdata
 * @group      Zend_Gdata_Docs
 */
class Zend_Gdata_DocsOnlineTest extends PHPUnit_Framework_TestCase
{

    public function setUp()
    {
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
        $this->docTitle = constant('TESTS_ZEND_GDATA_DOCS_DOCUMENTTITLE');
        $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
        $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
        $this->gdata = new Zend_Gdata_Docs($client);
    }

    public function testGetSpreadsheetFeed()
    {
        $feed = $this->gdata->getDocumentListFeed();
        $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
        foreach ($feed->entries as $entry) {
            $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
            $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
        }

        $query = new Zend_Gdata_Docs_Query();
        $feed = $this->gdata->getDocumentListFeed($query);
        $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
        foreach ($feed->entries as $entry) {
            $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
            $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
        }

        $uri = $query->getQueryUrl();
        $feed = $this->gdata->getDocumentListFeed($uri);
        $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
        foreach ($feed->entries as $entry) {
            $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
            $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
        }
    }

    public function testQueryForTitle()
    {
        $query = new Zend_Gdata_Docs_Query();
        $query->title = $this->docTitle;
        $feed = $this->gdata->getDocumentListFeed($query);
        $this->assertTrue(strpos(strtolower($feed->entries[0]->title), strtolower($this->docTitle)) !== FALSE);
    }

    public function testGetDocumentListEntry()
    {
        $query = new Zend_Gdata_Docs_Query();
        $feed = $this->gdata->getDocumentListFeed($query);
        $selfLinkHref = $feed->entries[0]->getSelfLink()->href;
        $entry = $this->gdata->getDocumentListEntry($selfLinkHref);
        $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
    }

    public function testUploadFindAndDelete()
    {
        $documentTitle = 'spreadsheet_upload_test.csv';
        $newDocumentEntry = $this->gdata->uploadFile(
            'Zend/Gdata/_files/DocsTest.csv', $documentTitle,
            $this->gdata->lookupMimeType('CSV'),
            Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
        $this->assertTrue($newDocumentEntry->title->text === $documentTitle);

        // Get the newly created document.
        // First extract the document's ID key from the Atom id.
        $idParts = explode('/', $newDocumentEntry->id->text);
        $keyParts = explode('%3A', end($idParts));
        $documentFromGetDoc = $this->gdata->getDoc($keyParts[1], $keyParts[0]);
        $this->assertTrue($documentFromGetDoc->title->text === $documentTitle);
        if ($keyParts[0] == 'document') {
            $documentFromGetDocument = $this->gdata->getDocument($keyParts[1]);
            $this->assertTrue(
                $documentFromGetDocument->title->text === $documentTitle);
        }
        if ($keyParts[0] == 'spreadsheet') {
            $documentFromGetSpreadsheet = $this->gdata->getSpreadsheet(
                $keyParts[1]);
            $this->assertTrue(
                $documentFromGetSpreadsheet->title->text === $documentTitle);
        }
        if ($keyParts[0] == 'presentation') {
            $documentFromGetPresentation = $this->gdata->getPresentation(
                $keyParts[1]);
            $this->assertTrue(
                $documentFromGetPresentation->title->text === $documentTitle);
        }

        // Cleanup and remove the new document.
        $newDocumentEntry->delete();
    }

}