|
2 | 2 |
|
3 | 3 | namespace Rennokki\RedditApi\Test; |
4 | 4 |
|
5 | | -use Exception; |
6 | 5 | use Rennokki\RedditApi\Reddit; |
| 6 | +use Rennokki\RedditApi\RedditList; |
7 | 7 | use Rennokki\RedditApi\Subreddit; |
8 | 8 |
|
9 | 9 | class RedditTest extends TestCase |
@@ -64,15 +64,6 @@ public function test_after() |
64 | 64 | ); |
65 | 65 | } |
66 | 66 |
|
67 | | - public function test_before() |
68 | | - { |
69 | | - $this->api->before('111'); |
70 | | - |
71 | | - $this->assertStringContainsString( |
72 | | - 'before=111', $this->api->getCallableUrl() |
73 | | - ); |
74 | | - } |
75 | | - |
76 | 67 | public function test_sort_filtering() |
77 | 68 | { |
78 | 69 | foreach (Subreddit::$sorts as $sort) { |
@@ -128,50 +119,66 @@ public function test_time_filtering() |
128 | 119 |
|
129 | 120 | public function test_top() |
130 | 121 | { |
131 | | - try { |
132 | | - $data = $this |
133 | | - ->api |
134 | | - ->sort('hot') |
135 | | - ->get(); |
136 | | - } catch (Exception $e) { |
137 | | - return $this->assertFalse(true); |
138 | | - } |
| 122 | + $posts = $this |
| 123 | + ->api |
| 124 | + ->sort('hot') |
| 125 | + ->get(); |
139 | 126 |
|
140 | | - $this->assertTrue( |
141 | | - count($data['data']['children']) > 1 |
142 | | - ); |
| 127 | + $this->assertInstanceOf(RedditList::class, $posts); |
| 128 | + |
| 129 | + $this->assertCount(22, $posts); |
| 130 | + |
| 131 | + foreach ($posts as $post) { |
| 132 | + $this->assertNotNull($post['permalink'] ?? null); |
| 133 | + } |
143 | 134 | } |
144 | 135 |
|
145 | 136 | public function test_hot() |
146 | 137 | { |
147 | | - try { |
148 | | - $data = $this |
149 | | - ->api |
150 | | - ->sort('top') |
151 | | - ->time('all') |
152 | | - ->get(); |
153 | | - } catch (Exception $e) { |
154 | | - return $this->assertFalse(true); |
155 | | - } |
| 138 | + $posts = $this |
| 139 | + ->api |
| 140 | + ->sort('top') |
| 141 | + ->time('all') |
| 142 | + ->get(); |
156 | 143 |
|
157 | | - $this->assertTrue( |
158 | | - count($data['data']['children']) > 1 |
159 | | - ); |
| 144 | + $this->assertInstanceOf(RedditList::class, $posts); |
| 145 | + |
| 146 | + $this->assertCount(20, $posts); |
| 147 | + |
| 148 | + foreach ($posts as $post) { |
| 149 | + $this->assertNotNull($post['permalink'] ?? null); |
| 150 | + } |
160 | 151 | } |
161 | 152 |
|
162 | 153 | public function test_new() |
163 | 154 | { |
164 | | - try { |
165 | | - $data = $this |
166 | | - ->api |
167 | | - ->sort('new') |
168 | | - ->get(); |
169 | | - } catch (Exception $e) { |
170 | | - return $this->assertFalse(true); |
| 155 | + $posts = $this |
| 156 | + ->api |
| 157 | + ->sort('new') |
| 158 | + ->get(); |
| 159 | + |
| 160 | + $this->assertInstanceOf(RedditList::class, $posts); |
| 161 | + |
| 162 | + $this->assertCount(20, $posts); |
| 163 | + |
| 164 | + foreach ($posts as $post) { |
| 165 | + $this->assertNotNull($post['permalink'] ?? null); |
171 | 166 | } |
| 167 | + } |
172 | 168 |
|
173 | | - $this->assertTrue( |
174 | | - count($data['data']['children']) > 1 |
175 | | - ); |
| 169 | + public function test_next_page() |
| 170 | + { |
| 171 | + $posts = $this |
| 172 | + ->api |
| 173 | + ->sort('new') |
| 174 | + ->get(); |
| 175 | + |
| 176 | + $firstPageAfter = $posts->getAfter(); |
| 177 | + |
| 178 | + $posts = $posts->nextPage(); |
| 179 | + |
| 180 | + $secondPageAfter = $posts->getAfter(); |
| 181 | + |
| 182 | + $this->assertNotEquals($firstPageAfter, $secondPageAfter); |
176 | 183 | } |
177 | 184 | } |
0 commit comments