|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Storyblok\ManagementApi\Data\WorkflowData; |
| 6 | +use Storyblok\ManagementApi\Endpoints\TagApi; |
| 7 | +use Storyblok\ManagementApi\Endpoints\WorkflowApi; |
| 8 | +use Storyblok\ManagementApi\ManagementApiClient; |
| 9 | +use Symfony\Component\HttpClient\MockHttpClient; |
| 10 | + |
| 11 | +test('Testing list of tags', function (): void { |
| 12 | + $responses = [ |
| 13 | + \mockResponse("list-tags", 200), |
| 14 | + \mockResponse("list-tags", 200), |
| 15 | + //\mockResponse("empty-asset", 404), |
| 16 | + ]; |
| 17 | + |
| 18 | + $client = new MockHttpClient($responses); |
| 19 | + $mapiClient = ManagementApiClient::initTest($client); |
| 20 | + $tagApi = new TagApi($mapiClient, "222"); |
| 21 | + |
| 22 | + $storyblokResponse = $tagApi->page(); |
| 23 | + $string = $storyblokResponse->getLastCalledUrl(); |
| 24 | + expect($string)->toMatch('/.*tags.*$/'); |
| 25 | + |
| 26 | + |
| 27 | +}); |
| 28 | + |
| 29 | +test('Testing one tag', function (): void { |
| 30 | + $responses = [ |
| 31 | + \mockResponse("one-tag", 200), |
| 32 | + //\mockResponse("empty-asset", 404), |
| 33 | + ]; |
| 34 | + |
| 35 | + $client = new MockHttpClient($responses); |
| 36 | + $mapiClient = ManagementApiClient::initTest($client); |
| 37 | + $tagApi = new TagApi($mapiClient, "222"); |
| 38 | + |
| 39 | + $storyblokResponse = $tagApi->get( |
| 40 | + "56932" |
| 41 | + ); |
| 42 | + $string = $storyblokResponse->getLastCalledUrl(); |
| 43 | + expect($string)->toMatch('/.*tags.*$/'); |
| 44 | + $data = $storyblokResponse->data(); |
| 45 | + expect($data->getString("id"))->toBe("56932"); |
| 46 | + expect($data->id())->toBe("56932"); |
| 47 | + expect($data->name())->toBe("some"); |
| 48 | + |
| 49 | + |
| 50 | +}); |
| 51 | + |
| 52 | +test('Testing deleting tag', function (): void { |
| 53 | + $responses = [ |
| 54 | + \mockResponse("one-tag", 200), |
| 55 | + //\mockResponse("empty-asset", 404), |
| 56 | + ]; |
| 57 | + |
| 58 | + $client = new MockHttpClient($responses); |
| 59 | + $mapiClient = ManagementApiClient::initTest($client); |
| 60 | + $tagApi = new TagApi($mapiClient, "222"); |
| 61 | + |
| 62 | + $storyblokResponse = $tagApi->delete( |
| 63 | + "15268" |
| 64 | + ); |
| 65 | + $string = $storyblokResponse->getLastCalledUrl(); |
| 66 | + expect($string)->toMatch('/.*tags.*$/'); |
| 67 | + $data = $storyblokResponse->data(); |
| 68 | + expect($data->getString("id"))->toBe("56932"); |
| 69 | + expect($data->id())->toBe("56932"); |
| 70 | + expect($data->name())->toBe("some"); |
| 71 | + |
| 72 | +}); |
| 73 | + |
| 74 | +test('Testing creating tag', function (): void { |
| 75 | + $responses = [ |
| 76 | + \mockResponse("one-tag", 200), |
| 77 | + //\mockResponse("empty-asset", 404), |
| 78 | + ]; |
| 79 | + |
| 80 | + $client = new MockHttpClient($responses); |
| 81 | + $mapiClient = ManagementApiClient::initTest($client); |
| 82 | + $tagApi = new TagApi($mapiClient, "222"); |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + $storyblokResponse = $tagApi->create("name"); |
| 87 | + $string = $storyblokResponse->getLastCalledUrl(); |
| 88 | + expect($string)->toMatch('/.*tags.*$/'); |
| 89 | + expect($storyblokResponse->isOk())->toBeTrue(); |
| 90 | + |
| 91 | +}); |
| 92 | + |
| 93 | +test('Testing updating tag', function (): void { |
| 94 | + $responses = [ |
| 95 | + \mockResponse("one-tag", 200), |
| 96 | + \mockResponse("one-tag", 200), |
| 97 | + //\mockResponse("empty-asset", 404), |
| 98 | + ]; |
| 99 | + |
| 100 | + $client = new MockHttpClient($responses); |
| 101 | + $mapiClient = ManagementApiClient::initTest($client); |
| 102 | + $tagApi = new TagApi($mapiClient, "222"); |
| 103 | + |
| 104 | + |
| 105 | + $storyblokResponse = $tagApi->update("56932", "some"); |
| 106 | + |
| 107 | + $string = $storyblokResponse->getLastCalledUrl(); |
| 108 | + expect($string)->toMatch('/.*tags.*$/'); |
| 109 | + $data = $storyblokResponse->data(); |
| 110 | + expect($data->getString("id"))->toBe("56932"); |
| 111 | + expect($data->id())->toBe("56932"); |
| 112 | + expect($data->name())->toBe("some"); |
| 113 | + |
| 114 | +}); |
0 commit comments