-
Notifications
You must be signed in to change notification settings - Fork 4
/
ListsTests.php
346 lines (308 loc) · 10.7 KB
/
ListsTests.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
/*
* --------------------------------------------------------------------------------
* <copyright company="Aspose" file="ListsTests.php">
* Copyright (c) 2024 Aspose.Words for Cloud
* </copyright>
* <summary>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* </summary>
* --------------------------------------------------------------------------------
*/
namespace Aspose\Words\Tests;
use Aspose\Words\WordsApi;
use Aspose\Words\Model\Requests\{GetListOnlineRequest, GetListRequest, GetListsOnlineRequest, GetListsRequest, InsertListOnlineRequest, InsertListRequest, UpdateListLevelOnlineRequest, UpdateListLevelRequest, UpdateListOnlineRequest, UpdateListRequest};
use Aspose\Words\Model\{ListInsert, ListLevelUpdate, ListUpdate};
use PHPUnit\Framework\Assert;
/*
* Example of how to work with lists.
*/
class ListsTests extends BaseTestContext
{
/*
* Test for getting lists from document.
*/
public function testGetLists()
{
$remoteDataFolder = self::$baseRemoteFolderPath . "/DocumentElements/Lists";
$localFile = "DocumentElements/Lists/ListsGet.doc";
$remoteFileName = "TestGetLists.doc";
$this->uploadFile(
realpath(__DIR__ . '/../../..') . "/TestData/" . $localFile,
$remoteDataFolder . "/" . $remoteFileName
);
$request = new GetListsRequest(
$remoteFileName,
$remoteDataFolder,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->getLists($request);
Assert::assertTrue(json_decode($result, true) !== NULL);
Assert::assertNotNull($result->getLists());
Assert::assertNotNull($result->getLists()->getListInfo());
Assert::assertCount(2, $result->getLists()->getListInfo());
Assert::assertEquals(1, $result->getLists()->getListInfo()[0]->getListId());
}
/*
* Test for getting lists from document online.
*/
public function testGetListsOnline()
{
$localFile = "DocumentElements/Lists/ListsGet.doc";
$requestDocument = realpath(__DIR__ . '/../../..') . '/TestData/' . $localFile;
$request = new GetListsOnlineRequest(
$requestDocument,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->getListsOnline($request);
Assert::assertTrue(json_decode($result, true) !== NULL);
}
/*
* Test for getting list from document.
*/
public function testGetList()
{
$remoteDataFolder = self::$baseRemoteFolderPath . "/DocumentElements/Lists";
$localFile = "DocumentElements/Lists/ListsGet.doc";
$remoteFileName = "TestGetList.doc";
$this->uploadFile(
realpath(__DIR__ . '/../../..') . "/TestData/" . $localFile,
$remoteDataFolder . "/" . $remoteFileName
);
$request = new GetListRequest(
$remoteFileName,
1,
$remoteDataFolder,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->getList($request);
Assert::assertTrue(json_decode($result, true) !== NULL);
Assert::assertNotNull($result->getList());
Assert::assertEquals(1, $result->getList()->getListId());
}
/*
* Test for getting list from document online.
*/
public function testGetListOnline()
{
$localFile = "DocumentElements/Lists/ListsGet.doc";
$requestDocument = realpath(__DIR__ . '/../../..') . '/TestData/' . $localFile;
$request = new GetListOnlineRequest(
$requestDocument,
1,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->getListOnline($request);
Assert::assertTrue(json_decode($result, true) !== NULL);
}
/*
* Test for updating list from document.
*/
public function testUpdateList()
{
$remoteDataFolder = self::$baseRemoteFolderPath . "/DocumentElements/Lists";
$localFile = "DocumentElements/Lists/ListsGet.doc";
$remoteFileName = "TestUpdateList.doc";
$this->uploadFile(
realpath(__DIR__ . '/../../..') . "/TestData/" . $localFile,
$remoteDataFolder . "/" . $remoteFileName
);
$requestListUpdate = new ListUpdate(array(
"is_restart_at_each_section" => true,
));
$request = new UpdateListRequest(
$remoteFileName,
1,
$requestListUpdate,
$remoteDataFolder,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->updateList($request);
Assert::assertTrue(json_decode($result, true) !== NULL);
}
/*
* Test for updating list from document online.
*/
public function testUpdateListOnline()
{
$localFile = "DocumentElements/Lists/ListsGet.doc";
$requestDocument = realpath(__DIR__ . '/../../..') . '/TestData/' . $localFile;
$requestListUpdate = new ListUpdate(array(
"is_restart_at_each_section" => true,
));
$request = new UpdateListOnlineRequest(
$requestDocument,
1,
$requestListUpdate,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->updateListOnline($request);
Assert::assertTrue($result !== NULL);
Assert::assertNotNull($result->getModel()->getList());
Assert::assertEquals(1, $result->getModel()->getList()->getListId());
Assert::assertTrue($result->getModel()->getList()->getIsRestartAtEachSection());
}
/*
* Test for updating list level from document.
*/
public function testUpdateListLevel()
{
$remoteDataFolder = self::$baseRemoteFolderPath . "/DocumentElements/Lists";
$localFile = "DocumentElements/Lists/ListsGet.doc";
$remoteFileName = "TestUpdateListLevel.doc";
$this->uploadFile(
realpath(__DIR__ . '/../../..') . "/TestData/" . $localFile,
$remoteDataFolder . "/" . $remoteFileName
);
$requestListUpdate = new ListLevelUpdate(array(
"alignment" => "Right",
));
$request = new UpdateListLevelRequest(
$remoteFileName,
1,
1,
$requestListUpdate,
$remoteDataFolder,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->updateListLevel($request);
Assert::assertTrue(json_decode($result, true) !== NULL);
}
/*
* Test for updating list level from document online.
*/
public function testUpdateListLevelOnline()
{
$localFile = "DocumentElements/Lists/ListsGet.doc";
$requestDocument = realpath(__DIR__ . '/../../..') . '/TestData/' . $localFile;
$requestListUpdate = new ListLevelUpdate(array(
"alignment" => "Right",
));
$request = new UpdateListLevelOnlineRequest(
$requestDocument,
1,
$requestListUpdate,
1,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->updateListLevelOnline($request);
Assert::assertTrue($result !== NULL);
Assert::assertNotNull($result->getModel()->getList());
Assert::assertNotNull($result->getModel()->getList()->getListLevels());
Assert::assertNotNull($result->getModel()->getList()->getListLevels()->getListLevel());
Assert::assertCount(9, $result->getModel()->getList()->getListLevels()->getListLevel());
}
/*
* Test for inserting list from document.
*/
public function testInsertList()
{
$remoteDataFolder = self::$baseRemoteFolderPath . "/DocumentElements/Lists";
$localFile = "DocumentElements/Lists/ListsGet.doc";
$remoteFileName = "TestInsertList.doc";
$this->uploadFile(
realpath(__DIR__ . '/../../..') . "/TestData/" . $localFile,
$remoteDataFolder . "/" . $remoteFileName
);
$requestListInsert = new ListInsert(array(
"template" => "OutlineLegal",
));
$request = new InsertListRequest(
$remoteFileName,
$requestListInsert,
$remoteDataFolder,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->insertList($request);
Assert::assertTrue(json_decode($result, true) !== NULL);
Assert::assertNotNull($result->getList());
Assert::assertEquals(3, $result->getList()->getListId());
}
/*
* Test for inserting list from document online.
*/
public function testInsertListOnline()
{
$localFile = "DocumentElements/Lists/ListsGet.doc";
$requestDocument = realpath(__DIR__ . '/../../..') . '/TestData/' . $localFile;
$requestListInsert = new ListInsert(array(
"template" => "OutlineLegal",
));
$request = new InsertListOnlineRequest(
$requestDocument,
$requestListInsert,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
);
$result = $this->words->insertListOnline($request);
Assert::assertTrue($result !== NULL);
}
}