|
7 | 7 | use Dotcms\PhpSdk\Config\Config; |
8 | 8 | use Dotcms\PhpSdk\DotCMSClient; |
9 | 9 | use Dotcms\PhpSdk\Http\HttpClient; |
| 10 | +use Dotcms\PhpSdk\Model\NavigationItem; |
10 | 11 | use Dotcms\PhpSdk\Model\PageAsset; |
| 12 | +use Dotcms\PhpSdk\Request\NavigationRequest; |
11 | 13 | use Dotcms\PhpSdk\Request\PageRequest; |
| 14 | +use Dotcms\PhpSdk\Service\NavigationService; |
12 | 15 | use Dotcms\PhpSdk\Service\PageService; |
13 | 16 | use GuzzleHttp\Promise\FulfilledPromise; |
14 | 17 | use PHPUnit\Framework\TestCase; |
@@ -41,6 +44,26 @@ public function testCreatePageRequest(): void |
41 | 44 | $this->assertEquals($format, $request->getFormat()); |
42 | 45 | } |
43 | 46 |
|
| 47 | + public function testCreateNavigationRequest(): void |
| 48 | + { |
| 49 | + // Test with default values |
| 50 | + $request = $this->client->createNavigationRequest(); |
| 51 | + $this->assertInstanceOf(NavigationRequest::class, $request); |
| 52 | + $this->assertEquals('/', $request->getPath()); |
| 53 | + $this->assertEquals(1, $request->getDepth()); |
| 54 | + $this->assertEquals(1, $request->getLanguageId()); |
| 55 | + |
| 56 | + // Test with custom values |
| 57 | + $path = '/about-us'; |
| 58 | + $depth = 2; |
| 59 | + $languageId = 3; |
| 60 | + $request = $this->client->createNavigationRequest($path, $depth, $languageId); |
| 61 | + $this->assertInstanceOf(NavigationRequest::class, $request); |
| 62 | + $this->assertEquals($path, $request->getPath()); |
| 63 | + $this->assertEquals($depth, $request->getDepth()); |
| 64 | + $this->assertEquals($languageId, $request->getLanguageId()); |
| 65 | + } |
| 66 | + |
44 | 67 | public function testGetPage(): void |
45 | 68 | { |
46 | 69 | /* |
@@ -131,4 +154,79 @@ public function testGetPageAsync(): void |
131 | 154 | */ |
132 | 155 | $this->markTestSkipped('This test would make an HTTP request. See comments for implementation options.'); |
133 | 156 | } |
| 157 | + |
| 158 | + public function testGetNavigation(): void |
| 159 | + { |
| 160 | + /* |
| 161 | + * This test is currently skipped because it would make a real HTTP request. |
| 162 | + * |
| 163 | + * To properly test this method without making HTTP requests, consider one of these approaches: |
| 164 | + * |
| 165 | + * 1. Modify DotCMSClient to accept a NavigationService in the constructor for testing: |
| 166 | + * - Change constructor to: __construct(Config $config, ?PageService $pageService = null, ?NavigationService $navigationService = null) |
| 167 | + * - Initialize navigationService as: $this->navigationService = $navigationService ?? new NavigationService($this->httpClient); |
| 168 | + * - Then in tests, create a mock NavigationService and inject it |
| 169 | + * |
| 170 | + * Example implementation with approach #1: |
| 171 | + * |
| 172 | + * // Create mocks |
| 173 | + * $navigationItemMock = $this->createMock(NavigationItem::class); |
| 174 | + * $navigationRequestMock = $this->createMock(NavigationRequest::class); |
| 175 | + * $navigationServiceMock = $this->createMock(NavigationService::class); |
| 176 | + * |
| 177 | + * // Configure the mock |
| 178 | + * $navigationServiceMock->expects($this->once()) |
| 179 | + * ->method('getNavigation') |
| 180 | + * ->with($navigationRequestMock) |
| 181 | + * ->willReturn($navigationItemMock); |
| 182 | + * |
| 183 | + * // Create client with mock service |
| 184 | + * $client = new DotCMSClient($this->config, null, $navigationServiceMock); |
| 185 | + * |
| 186 | + * // Call the method |
| 187 | + * $result = $client->getNavigation($navigationRequestMock); |
| 188 | + * |
| 189 | + * // Assert the result |
| 190 | + * $this->assertSame($navigationItemMock, $result); |
| 191 | + */ |
| 192 | + $this->markTestSkipped('This test would make an HTTP request. See comments for implementation options.'); |
| 193 | + } |
| 194 | + |
| 195 | + public function testGetNavigationAsync(): void |
| 196 | + { |
| 197 | + /* |
| 198 | + * This test is currently skipped because it would make a real HTTP request. |
| 199 | + * |
| 200 | + * To properly test this method without making HTTP requests, consider one of these approaches: |
| 201 | + * |
| 202 | + * 1. Modify DotCMSClient to accept a NavigationService in the constructor for testing: |
| 203 | + * - Change constructor to: __construct(Config $config, ?PageService $pageService = null, ?NavigationService $navigationService = null) |
| 204 | + * - Initialize navigationService as: $this->navigationService = $navigationService ?? new NavigationService($this->httpClient); |
| 205 | + * - Then in tests, create a mock NavigationService and inject it |
| 206 | + * |
| 207 | + * Example implementation with approach #1: |
| 208 | + * |
| 209 | + * // Create mocks |
| 210 | + * $navigationItemMock = $this->createMock(NavigationItem::class); |
| 211 | + * $navigationRequestMock = $this->createMock(NavigationRequest::class); |
| 212 | + * $promiseMock = new FulfilledPromise($navigationItemMock); |
| 213 | + * $navigationServiceMock = $this->createMock(NavigationService::class); |
| 214 | + * |
| 215 | + * // Configure the mock |
| 216 | + * $navigationServiceMock->expects($this->once()) |
| 217 | + * ->method('getNavigationAsync') |
| 218 | + * ->with($navigationRequestMock) |
| 219 | + * ->willReturn($promiseMock); |
| 220 | + * |
| 221 | + * // Create client with mock service |
| 222 | + * $client = new DotCMSClient($this->config, null, $navigationServiceMock); |
| 223 | + * |
| 224 | + * // Call the method |
| 225 | + * $result = $client->getNavigationAsync($navigationRequestMock); |
| 226 | + * |
| 227 | + * // Assert the result |
| 228 | + * $this->assertSame($promiseMock, $result); |
| 229 | + */ |
| 230 | + $this->markTestSkipped('This test would make an HTTP request. See comments for implementation options.'); |
| 231 | + } |
134 | 232 | } |
0 commit comments