@@ -4012,6 +4012,105 @@ public function testCreatePurchaseWithInvalidData()
40124012 );
40134013 }
40144014
4015+ /**
4016+ * Test that get_segments() returns the expected data.
4017+ *
4018+ * @since 2.0.0
4019+ *
4020+ * @return void
4021+ */
4022+ public function testGetSegments ()
4023+ {
4024+ $ result = $ this ->api ->get_segments ();
4025+
4026+ // Assert segments and pagination exist.
4027+ $ this ->assertDataExists ($ result , 'segments ' );
4028+ $ this ->assertPaginationExists ($ result );
4029+ }
4030+
4031+ /**
4032+ * Test that get_segments() returns the expected data
4033+ * when the total count is included.
4034+ *
4035+ * @since 1.0.0
4036+ *
4037+ * @return void
4038+ */
4039+ public function testGetSegmentsWithTotalCount ()
4040+ {
4041+ $ result = $ this ->api ->get_segments (
4042+ include_total_count: true
4043+ );
4044+
4045+ // Assert segments and pagination exist.
4046+ $ this ->assertDataExists ($ result , 'segments ' );
4047+ $ this ->assertPaginationExists ($ result );
4048+
4049+ // Assert total count is included.
4050+ $ this ->assertArrayHasKey ('total_count ' , get_object_vars ($ result ->pagination ));
4051+ $ this ->assertGreaterThan (0 , $ result ->pagination ->total_count );
4052+ }
4053+
4054+ /**
4055+ * Test that get_segments() returns the expected data
4056+ * when pagination parameters and per_page limits are specified.
4057+ *
4058+ * @since 2.0.0
4059+ *
4060+ * @return void
4061+ */
4062+ public function testGetSegmentsPagination ()
4063+ {
4064+ $ result = $ this ->api ->get_segments (
4065+ per_page: 1
4066+ );
4067+
4068+ // Assert segments and pagination exist.
4069+ $ this ->assertDataExists ($ result , 'segments ' );
4070+ $ this ->assertPaginationExists ($ result );
4071+
4072+ // Assert a single segment was returned.
4073+ $ this ->assertCount (1 , $ result ->segments );
4074+
4075+ // Assert has_previous_page and has_next_page are correct.
4076+ $ this ->assertFalse ($ result ->pagination ->has_previous_page );
4077+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
4078+
4079+ // Use pagination to fetch next page.
4080+ $ result = $ this ->api ->get_segments (
4081+ per_page: 1 ,
4082+ after_cursor: $ result ->pagination ->end_cursor
4083+ );
4084+
4085+ // Assert segments and pagination exist.
4086+ $ this ->assertDataExists ($ result , 'segments ' );
4087+ $ this ->assertPaginationExists ($ result );
4088+
4089+ // Assert a single segment was returned.
4090+ $ this ->assertCount (1 , $ result ->segments );
4091+
4092+ // Assert has_previous_page and has_next_page are correct.
4093+ $ this ->assertTrue ($ result ->pagination ->has_previous_page );
4094+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
4095+
4096+ // Use pagination to fetch previous page.
4097+ $ result = $ this ->api ->get_segments (
4098+ per_page: 1 ,
4099+ before_cursor: $ result ->pagination ->start_cursor
4100+ );
4101+
4102+ // Assert segments and pagination exist.
4103+ $ this ->assertDataExists ($ result , 'segments ' );
4104+ $ this ->assertPaginationExists ($ result );
4105+
4106+ // Assert a single segment was returned.
4107+ $ this ->assertCount (1 , $ result ->segments );
4108+
4109+ // Assert has_previous_page and has_next_page are correct.
4110+ $ this ->assertFalse ($ result ->pagination ->has_previous_page );
4111+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
4112+ }
4113+
40154114 /**
40164115 * Test that fetching a legacy form's markup works.
40174116 *
0 commit comments