-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsuite.php
167 lines (143 loc) · 5.04 KB
/
testsuite.php
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
use PHPUnit\Framework\TestCase;
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
function make_user_data()
{
return array(
"email" => "[email protected]",
"firstname" => "Henry",
"lastname" => "Miller",
"userId" => "testuser",
"company" => "Dummies Ltd");
}
final class SmashdocTests extends TestCase
{
function __construct()
{
$this->partner_url = getenv('SMASHDOCS_PARTNER_URL');
$this->client_id = getenv('SMASHDOCS_CLIENT_ID');
$this->client_key = getenv('SMASHDOCS_CLIENT_KEY');
$this->group_id = 'testing';
$verbose = getenv('SMASHDOCS_DEBUG');
$this->sd = new Smashdocs($this->partner_url, $this->client_id, $this->client_key, $this->group_id, $verbose);
parent::__construct();
}
function _createDocument($empty=true)
{
if ($empty) {
$result = $this->sd->new_document('my title', 'my description', 'editor', make_user_data());
return $result['documentId'];
} else {
$result = $this->sd->upload_document('test.docx', 'title', 'description', 'editor', make_user_data());
return $result['documentId'];
}
}
function testListTemplates()
{
$result = $this->sd->list_templates();
$this->assertEquals(0, 0);
}
function testCreateAndDeleteDocument()
{
$documentId = $this->_createDocument();
$this->sd->delete_document($documentId);
$this->assertEquals(0, 0);
}
function XXXtestArchiveUnarchive()
{
$documentId = $this->_createDocument();
$this->sd->archive_document($documentId);
$this->sd->unarchive_document($documentId);
$this->sd->delete_document($documentId);
$this->assertEquals(0, 0);
}
function testCreateAndDeleteTwice()
{
$documentId = $this->_createDocument();
$this->sd->delete_document($documentId);
try {
$this->sd->delete_document($documentId);
} catch (DeletionError $e) {
}
$this->assertEquals(0, 0);
}
function testOpenDocument()
{
$documentId = $this->_createDocument();
$result = $this->sd->open_document($documentId, 'editor', make_user_data());
$this->assertContains('https://', $result['documentAccessLink']);
$this->sd->delete_document($result['documentId']);
$this->assertEquals(0, 0);
}
function testDuplicateDocument()
{
$documentId = $this->_createDocument(false);
$result = $this->sd->duplicate_document($documentId, 'my title', 'new description', 'testuser');
$this->sd->delete_document($documentId);
$this->sd->delete_document($result['documentId']);
$this->assertEquals(0, 0);
}
function testUpdateMetadata()
{
$documentId = $this->_createDocument();
$metadata = array(
"title" => "new title",
"description" => "new description"
);
$this->sd->update_metadata($documentId, $metadata);
$document_info = $this->sd->document_info($documentId);
$this->assertEquals($document_info["title"], "new title");
$this->assertEquals($document_info["description"], "new description");
}
function testExportDOCX()
{
$templates = $this->sd->list_templates();
$template_id = get_object_vars($templates[0])['id'];
$documentId = $this->_createDocument();
$fn = $this->sd->export_document($documentId, 'testuser', 'docx', $template_id);
$this->assertEquals(true, endsWith($fn, '.docx'));
}
function testExportSDXML()
{
$documentId = $this->_createDocument();
$fn = $this->sd->export_document($documentId, 'testuser', 'sdxml');
$this->assertEquals(true, endsWith($fn, '.sdxml.zip'));
}
function testExportHTML()
{
$documentId = $this->_createDocument();
$fn = $this->sd->export_document($documentId, 'testuser', 'html');
$this->assertEquals(true, endsWith($fn, '.html.zip'));
}
function testReviewDocoument()
{
$documentId = $this->_createDocument(false);
$this->sd->review_document($documentId);
}
function testGetDocuments()
{
$result = $this->sd->get_documents('dummy_group', '');
$result = $this->sd->get_documents('', 'testuser');
}
function testUploadDOCX()
{
$result = $this->sd->upload_document('test.docx', 'title', 'description', 'editor', make_user_data());
$documentId = $result['documentId'];
$this->sd->delete_document($result['documentId']);
$this->assertEquals(0, 0);
}
function testUploadSDXML()
{
$result = $this->sd->upload_document('test_sdxml_large.zip', 'title', 'description', 'editor', make_user_data());
$documentId = $result['documentId'];
$this->sd->delete_document($result['documentId']);
$this->assertEquals(0, 0);
}
}