aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php197
1 files changed, 196 insertions, 1 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 15f05d48..765c108e 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -1041,7 +1041,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1041 $this->assertSame('test title entry' . $ids[$key], $result); 1041 $this->assertSame('test title entry' . $ids[$key], $result);
1042 } 1042 }
1043 1043
1044 rsort($ids); 1044 $ids = array_reverse($ids);
1045 1045
1046 $crawler = $client->request('GET', '/unread/list'); 1046 $crawler = $client->request('GET', '/unread/list');
1047 $form = $crawler->filter('button[id=submit-sort]')->form(); 1047 $form = $crawler->filter('button[id=submit-sort]')->form();
@@ -1061,6 +1061,201 @@ class EntryControllerTest extends WallabagCoreTestCase
1061 } 1061 }
1062 } 1062 }
1063 1063
1064 public function testSortOnCreationDate()
1065 {
1066 $this->logInAs('admin');
1067 $client = $this->getClient();
1068
1069 $entry1 = new Entry($this->getLoggedInUser());
1070 $entry1->setTitle('test title entry7');
1071 $entry1->setCreatedAt(new \DateTime('2013-04-03T13:37:00'));
1072 $this->getEntityManager()->persist($entry1);
1073
1074 $entry2 = new Entry($this->getLoggedInUser());
1075 $entry2->setTitle('test title entry8');
1076 $entry2->setCreatedAt(new \DateTime('2012-04-03T13:37:00'));
1077 $this->getEntityManager()->persist($entry2);
1078
1079 $entry3 = new Entry($this->getLoggedInUser());
1080 $entry3->setTitle('test title entry9');
1081 $entry3->setCreatedAt(new \DateTime('2014-04-03T13:37:00'));
1082 $this->getEntityManager()->persist($entry3);
1083
1084 $this->getEntityManager()->flush();
1085
1086 $crawler = $client->request('GET', '/unread/list');
1087 $form = $crawler->filter('button[id=submit-sort]')->form();
1088 $data = [
1089 'entry_sort[sortType]' => 'createdAt',
1090 'entry_sort[sortOrder]' => 'asc',
1091 ];
1092 $crawler = $client->submit($form, $data);
1093
1094 $this->assertCount(7, $crawler->filter('li.entry'));
1095
1096 $matches = [];
1097 preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches);
1098
1099 $results = array_values(array_unique($matches[0]));
1100
1101 $ids = [8, 7, 9, 1, 2, 4, 5];
1102
1103 foreach ($results as $key => $result) {
1104 $this->assertSame('test title entry' . $ids[$key], $result);
1105 }
1106
1107 $ids = array_reverse($ids);
1108
1109 $crawler = $client->request('GET', '/unread/list');
1110 $form = $crawler->filter('button[id=submit-sort]')->form();
1111 $data = [
1112 'entry_sort[sortType]' => 'createdAt',
1113 'entry_sort[sortOrder]' => 'desc',
1114 ];
1115 $crawler = $client->submit($form, $data);
1116
1117 $matches = [];
1118 preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches);
1119
1120 $results = array_values(array_unique($matches[0]));
1121
1122 foreach ($results as $key => $result) {
1123 $this->assertSame('test title entry' . $ids[$key], $result);
1124 }
1125 }
1126
1127 public function testSortOnStarredDate()
1128 {
1129 $this->logInAs('admin');
1130 $client = $this->getClient();
1131
1132 $entry1 = new Entry($this->getLoggedInUser());
1133 $entry1->setTitle('test title entry7');
1134 $entry1->setStarred(true);
1135 $entry1->setStarredAt(new \DateTime('2013-04-03T13:37:00'));
1136 $this->getEntityManager()->persist($entry1);
1137
1138 $entry2 = new Entry($this->getLoggedInUser());
1139 $entry2->setTitle('test title entry8');
1140 $entry2->setStarred(true);
1141 $entry2->setStarredAt(new \DateTime('2012-04-03T13:37:00'));
1142 $this->getEntityManager()->persist($entry2);
1143
1144 $entry3 = new Entry($this->getLoggedInUser());
1145 $entry3->setTitle('test title entry9');
1146 $entry3->setStarred(true);
1147 $entry3->setStarredAt(new \DateTime('2014-04-03T13:37:00'));
1148 $this->getEntityManager()->persist($entry3);
1149
1150 $this->getEntityManager()->flush();
1151
1152 $crawler = $client->request('GET', '/starred/list');
1153 $form = $crawler->filter('button[id=submit-sort]')->form();
1154 $data = [
1155 'entry_sort[sortType]' => 'starredAt',
1156 'entry_sort[sortOrder]' => 'asc',
1157 ];
1158 $crawler = $client->submit($form, $data);
1159
1160 $this->assertCount(4, $crawler->filter('li.entry'));
1161
1162 $matches = [];
1163 preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches);
1164
1165 $results = array_values(array_unique($matches[0]));
1166
1167 $ids = [5, 8, 7, 9];
1168
1169 foreach ($results as $key => $result) {
1170 $this->assertSame('test title entry' . $ids[$key], $result);
1171 }
1172
1173 $ids = array_reverse($ids);
1174
1175 $crawler = $client->request('GET', '/starred/list');
1176 $form = $crawler->filter('button[id=submit-sort]')->form();
1177 $data = [
1178 'entry_sort[sortType]' => 'starredAt',
1179 'entry_sort[sortOrder]' => 'desc',
1180 ];
1181 $crawler = $client->submit($form, $data);
1182
1183 $matches = [];
1184 preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches);
1185
1186 $results = array_values(array_unique($matches[0]));
1187
1188 foreach ($results as $key => $result) {
1189 $this->assertSame('test title entry' . $ids[$key], $result);
1190 }
1191 }
1192
1193 public function testSortOnArchivedDate()
1194 {
1195 $this->logInAs('admin');
1196 $client = $this->getClient();
1197
1198 $entry1 = new Entry($this->getLoggedInUser());
1199 $entry1->setTitle('test title entry7');
1200 $entry1->setArchived(true);
1201 $entry1->setArchivedAt(new \DateTime('2010-04-03T13:37:00'));
1202 $this->getEntityManager()->persist($entry1);
1203
1204 $entry2 = new Entry($this->getLoggedInUser());
1205 $entry2->setTitle('test title entry8');
1206 $entry2->setArchived(true);
1207 $entry2->setArchivedAt(new \DateTime('2000-04-03T13:37:00'));
1208 $this->getEntityManager()->persist($entry2);
1209
1210 $entry3 = new Entry($this->getLoggedInUser());
1211 $entry3->setTitle('test title entry9');
1212 $entry3->setArchived(true);
1213 $entry3->setArchivedAt(new \DateTime('2020-04-03T13:37:00'));
1214 $this->getEntityManager()->persist($entry3);
1215
1216 $this->getEntityManager()->flush();
1217
1218 $crawler = $client->request('GET', '/archive/list');
1219 $form = $crawler->filter('button[id=submit-sort]')->form();
1220 $data = [
1221 'entry_sort[sortType]' => 'archivedAt',
1222 'entry_sort[sortOrder]' => 'asc',
1223 ];
1224 $crawler = $client->submit($form, $data);
1225
1226 $this->assertCount(4, $crawler->filter('li.entry'));
1227
1228 $matches = [];
1229 preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches);
1230
1231 $results = array_values(array_unique($matches[0]));
1232
1233 $ids = [6, 8, 7, 9];
1234
1235 foreach ($results as $key => $result) {
1236 $this->assertSame('test title entry' . $ids[$key], $result);
1237 }
1238
1239 $ids = array_reverse($ids);
1240
1241 $crawler = $client->request('GET', '/archive/list');
1242 $form = $crawler->filter('button[id=submit-sort]')->form();
1243 $data = [
1244 'entry_sort[sortType]' => 'archivedAt',
1245 'entry_sort[sortOrder]' => 'desc',
1246 ];
1247 $crawler = $client->submit($form, $data);
1248
1249 $matches = [];
1250 preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches);
1251
1252 $results = array_values(array_unique($matches[0]));
1253
1254 foreach ($results as $key => $result) {
1255 $this->assertSame('test title entry' . $ids[$key], $result);
1256 }
1257 }
1258
1064 public function testShareEntryPublicly() 1259 public function testShareEntryPublicly()
1065 { 1260 {
1066 $this->logInAs('admin'); 1261 $this->logInAs('admin');