Skip to content

Commit c771be8

Browse files
committed
test cases updated for requestBody Assertions
1 parent b10af4f commit c771be8

File tree

8 files changed

+281
-81
lines changed

8 files changed

+281
-81
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,20 +792,20 @@ $deleteFiles = $imageKit->bulkFileDeleteByIds($fileIds);
792792

793793
This will copy a file from one folder to another.
794794

795-
> If any file at the destination has the same name as the source file, then the source file and its versions (if `includeVersions` is set to true) will be appended to the destination file version history.
795+
> If any file at the destination has the same name as the source file, then the source file and its versions (if `includeFileVersions` is set to true) will be appended to the destination file version history.
796796
797797
Refer to the [Copy File API](https://docs.imagekit.io/api-reference/media-api/copy-file) for a better understanding of the **Request & Response Structure**.
798798

799799
#### Basic Usage
800800
```php
801801
$sourceFilePath = '/sample-folder1/sample-file.jpg';
802802
$destinationPath = '/sample-folder2/';
803-
$includeVersions = false;
803+
$includeFileVersions = false;
804804

805805
$copyFile = $imageKit->copy([
806806
'sourceFilePath' => $sourceFilePath,
807807
'destinationPath' => $destinationPath,
808-
'includeVersions' => $includeVersions
808+
'includeFileVersions' => $includeFileVersions
809809
]);
810810
```
811811

@@ -911,11 +911,11 @@ Refer to the [Copy Folder API](https://docs.imagekit.io/api-reference/media-api/
911911
```php
912912
$sourceFolderPath = '/source-folder/';
913913
$destinationPath = '/destination-folder/';
914-
$includeVersions = false;
914+
$includeFileVersions = false;
915915
$copyFolder = $imageKit->copyFolder([
916916
'sourceFolderPath' => $sourceFolderPath,
917917
'destinationPath' => $destinationPath,
918-
'includeVersions' => $includeVersions
918+
'includeFileVersions' => $includeFileVersions
919919
]);
920920
```
921921

sample/file_management/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
$copyFile = $imageKit->copy([
128128
'sourceFilePath' => $sourceFilePath,
129129
'destinationPath' => $destinationPath,
130-
'includeVersions' => false
130+
'includeFileVersions' => false
131131
]);
132132

133133
echo "\n\n";
@@ -205,11 +205,11 @@
205205

206206
$sourceFolderPath = $folderName;
207207
$destinationPath = '/sample-folder';
208-
$includeVersions = false;
208+
$includeFileVersions = false;
209209
$copyFolder = $imageKit->copyFolder([
210210
'sourceFolderPath' => $sourceFolderPath,
211211
'destinationPath' => $destinationPath,
212-
'includeVersions' => $includeVersions
212+
'includeFileVersions' => $includeFileVersions
213213
]);
214214

215215
echo "\n\n";

src/ImageKit/ImageKit.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ public function bulkDeleteFiles($fileIds=null)
687687
*
688688
* @link https://docs.imagekit.io/api-reference/media-api/copy-file
689689
*
690-
* @param $parameter['sourceFilePath','destinationPath','includeVersions']
690+
* @param $parameter['sourceFilePath','destinationPath','includeFileVersions']
691691
* @return Response
692692
*
693693
*/
@@ -702,12 +702,12 @@ public function copy($parameter=null)
702702
if(sizeof($parameter)==0){
703703
return Response::respond(true, ((object)ErrorMessages::$COPY_FILE_PARAMETER_EMPTY_ARRAY));
704704
}
705-
if (empty($parameter['sourceFilePath']) || empty($parameter['destinationPath']) || !isset($parameter['includeVersions'])) {
705+
if (empty($parameter['sourceFilePath']) || empty($parameter['destinationPath']) || !isset($parameter['includeFileVersions'])) {
706706
return Response::respond(true, ((object)ErrorMessages::$COPY_FILE_DATA_INVALID));
707707
}
708708

709709
$this->httpClient->setUri(Endpoints::getCopyFileEndpoint());
710-
return Manage\File::copy($parameter['sourceFilePath'], $parameter['destinationPath'], $parameter['includeVersions'], $this->httpClient);
710+
return Manage\File::copy($parameter['sourceFilePath'], $parameter['destinationPath'], $parameter['includeFileVersions'], $this->httpClient);
711711
}
712712

713713

@@ -719,21 +719,21 @@ public function copy($parameter=null)
719719
*
720720
* @param $sourceFilePath
721721
* @param $destinationPath
722-
* @param $includeVersions
722+
* @param $includeFileVersions
723723
* @return Response
724724
*
725725
* @deprecated since 3.0.0, use <code>copy</code>
726726
*
727727
*/
728-
public function copyFile($sourceFilePath=null, $destinationPath=null, $includeVersions=null)
728+
public function copyFile($sourceFilePath=null, $destinationPath=null, $includeFileVersions=null)
729729
{
730730

731731
if (empty($sourceFilePath) || empty($destinationPath)) {
732732
return Response::respond(true, ((object)ErrorMessages::$COPY_FILE_DATA_INVALID));
733733
}
734734

735735
$this->httpClient->setUri(Endpoints::getCopyFileEndpoint());
736-
return Manage\File::copy($sourceFilePath, $destinationPath, $includeVersions, $this->httpClient);
736+
return Manage\File::copy($sourceFilePath, $destinationPath, $includeFileVersions, $this->httpClient);
737737
}
738738

739739
/**
@@ -928,7 +928,7 @@ public function deleteFolder($folderPath=null)
928928
*
929929
* @link https://docs.imagekit.io/api-reference/media-api/copy-folder
930930
*
931-
* @param $parameter[$sourceFolderPath, $destinationPath, includeVersions]
931+
* @param $parameter[$sourceFolderPath, $destinationPath, includeFileVersions]
932932
*
933933
* @return Response
934934
*/
@@ -943,12 +943,12 @@ public function copyFolder($parameter=null)
943943
if(sizeof($parameter)==0){
944944
return Response::respond(true, ((object)ErrorMessages::$COPY_FOLDER_PARAMETER_EMPTY_ARRAY));
945945
}
946-
if (empty($parameter['sourceFolderPath']) || empty($parameter['destinationPath']) || !isset($parameter['includeVersions'])) {
946+
if (empty($parameter['sourceFolderPath']) || empty($parameter['destinationPath']) || !isset($parameter['includeFileVersions'])) {
947947
return Response::respond(true, ((object)ErrorMessages::$COPY_FOLDER_DATA_INVALID));
948948
}
949949

950950
$this->httpClient->setUri(Endpoints::getCopyFolderEndpoint());
951-
return Manage\Folder::copy($parameter['sourceFolderPath'], $parameter['destinationPath'], $parameter['includeVersions'], $this->httpClient);
951+
return Manage\Folder::copy($parameter['sourceFolderPath'], $parameter['destinationPath'], $parameter['includeFileVersions'], $this->httpClient);
952952
}
953953

954954
/**

tests/ImageKit/Manage/CacheTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public function testPurgeCache()
3131
$this->stubHttpClient('post', new Response(201, ['X-Foo' => 'Bar'], $mockBodyResponse));
3232

3333
$response = $this->client->purgeCache($image_url);
34-
34+
35+
// Request Check
36+
CacheTest::assertNotNull($image_url);
37+
if (!filter_var($image_url, FILTER_VALIDATE_URL)) {
38+
CacheTest::assertFalse('Invalid URL');
39+
}
40+
CacheTest::assertIsString($image_url);
41+
42+
// Response Check
3543
CacheTest::assertEquals(json_encode($responseBody), json_encode($response->result));
3644
}
3745

@@ -76,6 +84,11 @@ public function testPurgeCacheStatus()
7684

7785
$response = $this->client->purgeCacheStatus($cacheRequestId);
7886

87+
// Request Check
88+
CacheTest::assertNotNull($cacheRequestId);
89+
CacheTest::assertIsString($cacheRequestId);
90+
91+
// Response Check
7992
CacheTest::assertEquals(json_encode($responseBody), json_encode($response->result));
8093
}
8194

tests/ImageKit/Manage/CustomMetadataTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ public function testCreateFields()
4848

4949
$response = $this->client->createCustomMetadataField($requestBody);
5050

51+
// Request Check
52+
CacheTest::assertNotEmpty($requestBody);
53+
CacheTest::assertIsArray($requestBody);
54+
CacheTest::assertNotNull($requestBody['name']);
55+
CacheTest::assertIsString($requestBody['name']);
56+
CacheTest::assertNotNull($requestBody['label']);
57+
CacheTest::assertIsString($requestBody['label']);
58+
CacheTest::assertIsArray($requestBody['schema']);
59+
CacheTest::assertNotEmpty($requestBody['schema']);
60+
CacheTest::assertNotNull($requestBody['schema']['type']);
61+
CacheTest::assertIsString($requestBody['schema']['type']);
62+
63+
// Response Check
5164
CacheTest::assertEquals(json_encode($responseBody), json_encode($response->result));
5265
}
5366

@@ -197,6 +210,10 @@ public function testGetFields()
197210

198211
$response = $this->client->getCustomMetadataFields($includeDeleted);
199212

213+
// Request Check
214+
CacheTest::assertIsBool($includeDeleted);
215+
216+
// Response Check
200217
CacheTest::assertEquals(json_encode($responseBody), json_encode($response->result));
201218
}
202219

@@ -241,6 +258,15 @@ public function testUpdateFields()
241258

242259
$response = $this->client->updateCustomMetadataField($customMetadataFieldId, $requestBody);
243260

261+
// Request Check
262+
CacheTest::assertNotEmpty($requestBody);
263+
CacheTest::assertIsArray($requestBody);
264+
CacheTest::assertNotNull($requestBody['label']);
265+
CacheTest::assertIsString($requestBody['label']);
266+
CacheTest::assertIsArray($requestBody['schema']);
267+
CacheTest::assertNotEmpty($requestBody['schema']);
268+
269+
// Response Check
244270
CacheTest::assertEquals(json_encode($responseBody), json_encode($response->result));
245271
}
246272

@@ -390,7 +416,12 @@ public function testDeleteFields()
390416
$this->stubHttpClient('delete', new Response(201, ['X-Foo' => 'Bar'], $mockBodyResponse));
391417

392418
$response = $this->client->deleteCustomMetadataField($customMetadataFieldId);
419+
420+
// Request Check
421+
CacheTest::assertNotNull($customMetadataFieldId);
422+
CacheTest::assertIsString($customMetadataFieldId);
393423

424+
// Response Check
394425
CacheTest::assertNull($response->result);
395426
CacheTest::assertNull($response->error);
396427
}

0 commit comments

Comments
 (0)