@@ -318,6 +318,94 @@ public function testDebugDisabled()
318318 $ this ->assertEmpty ($ this ->getLogFileContents ());
319319 }
320320
321+ /**
322+ * Test that calling request_headers() returns the expected array of headers
323+ *
324+ * @since 2.0.0
325+ *
326+ * @return void
327+ */
328+ public function testRequestHeadersMethod ()
329+ {
330+ $ headers = $ this ->callPrivateMethod ($ this ->api , 'request_headers ' , []);
331+ $ this ->assertArrayHasKey ('Accept ' , $ headers );
332+ $ this ->assertArrayHasKey ('Content-Type ' , $ headers );
333+ $ this ->assertArrayHasKey ('User-Agent ' , $ headers );
334+ $ this ->assertArrayHasKey ('Authorization ' , $ headers );
335+ $ this ->assertEquals ($ headers ['Accept ' ], 'application/json ' );
336+ $ this ->assertEquals ($ headers ['Content-Type ' ], 'application/json; charset=utf-8 ' );
337+ $ this ->assertEquals ($ headers ['User-Agent ' ], 'ConvertKitPHPSDK/ ' . $ this ->api ::VERSION . ';PHP/ ' . phpversion ());
338+ $ this ->assertEquals ($ headers ['Authorization ' ], 'Bearer ' . $ _ENV ['CONVERTKIT_OAUTH_ACCESS_TOKEN ' ]);
339+ }
340+
341+ /**
342+ * Test that calling request_headers() with a different `type` parameter
343+ * returns the expected array of headers
344+ *
345+ * @since 2.0.0
346+ *
347+ * @return void
348+ */
349+ public function testRequestHeadersMethodWithType ()
350+ {
351+ $ headers = $ this ->callPrivateMethod ($ this ->api , 'request_headers ' , [
352+ 'type ' => 'text/html ' ,
353+ ]);
354+ $ this ->assertArrayHasKey ('Accept ' , $ headers );
355+ $ this ->assertArrayHasKey ('Content-Type ' , $ headers );
356+ $ this ->assertArrayHasKey ('User-Agent ' , $ headers );
357+ $ this ->assertArrayHasKey ('Authorization ' , $ headers );
358+ $ this ->assertEquals ($ headers ['Accept ' ], 'text/html ' );
359+ $ this ->assertEquals ($ headers ['Content-Type ' ], 'text/html; charset=utf-8 ' );
360+ $ this ->assertEquals ($ headers ['User-Agent ' ], 'ConvertKitPHPSDK/ ' . $ this ->api ::VERSION . ';PHP/ ' . phpversion ());
361+ $ this ->assertEquals ($ headers ['Authorization ' ], 'Bearer ' . $ _ENV ['CONVERTKIT_OAUTH_ACCESS_TOKEN ' ]);
362+ }
363+
364+ /**
365+ * Test that calling request_headers() with the `auth` parameter set to false
366+ * returns the expected array of headers
367+ *
368+ * @since 2.0.0
369+ *
370+ * @return void
371+ */
372+ public function testRequestHeadersMethodWithAuthDisabled ()
373+ {
374+ $ headers = $ this ->callPrivateMethod ($ this ->api , 'request_headers ' , [
375+ 'auth ' => false ,
376+ ]);
377+ $ this ->assertArrayHasKey ('Accept ' , $ headers );
378+ $ this ->assertArrayHasKey ('Content-Type ' , $ headers );
379+ $ this ->assertArrayHasKey ('User-Agent ' , $ headers );
380+ $ this ->assertArrayNotHasKey ('Authorization ' , $ headers );
381+ $ this ->assertEquals ($ headers ['Accept ' ], 'application/json ' );
382+ $ this ->assertEquals ($ headers ['Content-Type ' ], 'application/json; charset=utf-8 ' );
383+ $ this ->assertEquals ($ headers ['User-Agent ' ], 'ConvertKitPHPSDK/ ' . $ this ->api ::VERSION . ';PHP/ ' . phpversion ());
384+ }
385+
386+ /**
387+ * Test that calling request_headers() with a different `type` parameter
388+ * and the `auth` parameter set to false returns the expected array of headers
389+ *
390+ * @since 2.0.0
391+ *
392+ * @return void
393+ */
394+ public function testRequestHeadersMethodWithTypeAndAuthDisabled ()
395+ {
396+ $ headers = $ this ->callPrivateMethod ($ this ->api , 'request_headers ' , [
397+ 'type ' => 'text/html ' ,
398+ 'auth ' => false ,
399+ ]);
400+ $ this ->assertArrayHasKey ('Accept ' , $ headers );
401+ $ this ->assertArrayHasKey ('Content-Type ' , $ headers );
402+ $ this ->assertArrayHasKey ('User-Agent ' , $ headers );
403+ $ this ->assertArrayNotHasKey ('Authorization ' , $ headers );
404+ $ this ->assertEquals ($ headers ['Accept ' ], 'text/html ' );
405+ $ this ->assertEquals ($ headers ['Content-Type ' ], 'text/html; charset=utf-8 ' );
406+ $ this ->assertEquals ($ headers ['User-Agent ' ], 'ConvertKitPHPSDK/ ' . $ this ->api ::VERSION . ';PHP/ ' . phpversion ());
407+ }
408+
321409 /**
322410 * Test that get_oauth_url() returns the correct URL to begin the OAuth process.
323411 *
@@ -4867,8 +4955,6 @@ public function testGetSegmentsPagination()
48674955 */
48684956 public function testGetResourceLegacyForm ()
48694957 {
4870- $ this ->markTestIncomplete ();
4871-
48724958 $ markup = $ this ->api ->get_resource ($ _ENV ['CONVERTKIT_API_LEGACY_FORM_URL ' ]);
48734959
48744960 // Assert that the markup is HTML.
@@ -4887,8 +4973,6 @@ public function testGetResourceLegacyForm()
48874973 */
48884974 public function testGetResourceLandingPage ()
48894975 {
4890- $ this ->markTestIncomplete ();
4891-
48924976 $ markup = $ this ->api ->get_resource ($ _ENV ['CONVERTKIT_API_LANDING_PAGE_URL ' ]);
48934977
48944978 // Assert that the markup is HTML.
@@ -4907,8 +4991,6 @@ public function testGetResourceLandingPage()
49074991 */
49084992 public function testGetResourceLegacyLandingPage ()
49094993 {
4910- $ this ->markTestIncomplete ();
4911-
49124994 $ markup = $ this ->api ->get_resource ($ _ENV ['CONVERTKIT_API_LEGACY_LANDING_PAGE_URL ' ]);
49134995
49144996 // Assert that the markup is HTML.
@@ -4928,8 +5010,6 @@ public function testGetResourceLegacyLandingPage()
49285010 */
49295011 public function testGetResourceInvalidURL ()
49305012 {
4931- $ this ->markTestIncomplete ();
4932-
49335013 $ this ->expectException (InvalidArgumentException::class);
49345014 $ markup = $ this ->api ->get_resource ('not-a-url ' );
49355015 }
@@ -4944,8 +5024,6 @@ public function testGetResourceInvalidURL()
49445024 */
49455025 public function testGetResourceInaccessibleURL ()
49465026 {
4947- $ this ->markTestIncomplete ();
4948-
49495027 $ this ->expectException (ClientException::class);
49505028 $ markup = $ this ->api ->get_resource ('https://convertkit.com/a/url/that/does/not/exist ' );
49515029 }
0 commit comments