-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get the number of subscribers of list, Fix #115
Signed-off-by: Xheni Myrtaj <[email protected]>
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* This controller provides REST API access to subscriber lists. | ||
* | ||
* @author Oliver Klee <[email protected]> | ||
* @author Xheni Myrtaj <[email protected]> | ||
*/ | ||
class ListController extends FOSRestController implements ClassResourceInterface | ||
{ | ||
|
@@ -96,4 +97,18 @@ public function getMembersAction(Request $request, SubscriberList $list): View | |
|
||
return View::create()->setData($list->getSubscribers()); | ||
} | ||
|
||
/** | ||
* Gets the total number of subscribers of a list. | ||
* @param Request $request | ||
* @param SubscriberList $list | ||
* | ||
* @return View | ||
*/ | ||
public function getCountAction(Request $request, SubscriberList $list): View | ||
{ | ||
$this->requireAuthentication($request); | ||
|
||
return View::create()->setData(count($list->getSubscribers())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
id,name,description,entered,modified,listorder,prefix,active,category,owner | ||
1,"News","News (and some fun stuff)","2016-06-22 15:01:17","2016-06-23 19:50:43",12,"phpList",1,"news",1 | ||
2,"More news","","2016-06-22 15:01:17","2016-06-23 19:50:43",12,"",1,"",1 | ||
3,"Tech news","","2019-02-11 15:01:15","2019-02-11 19:50:43",12,"",1,"",1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
* Testcase. | ||
* | ||
* @author Oliver Klee <[email protected]> | ||
* @author Xheni Myrtaj <[email protected]> | ||
*/ | ||
class ListControllerTest extends AbstractControllerTest | ||
{ | ||
|
@@ -107,6 +108,16 @@ public function getListsWithCurrentSessionKeyReturnsListData() | |
'public' => true, | ||
'category' => '', | ||
'id' => 2, | ||
], | ||
[ | ||
'name' => 'Tech news', | ||
'description' => '', | ||
'creation_date' => '2019-02-11T15:01:15+00:00', | ||
'list_position' => 12, | ||
'subject_prefix' => '', | ||
'public' => true, | ||
'category' => '', | ||
'id' => 3, | ||
] | ||
] | ||
); | ||
|
@@ -320,4 +331,83 @@ public function getListMembersWithCurrentSessionKeyForExistingListWithSubscriber | |
] | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getListCountForExistingListWithoutSessionKeyReturnsForbiddenStatus() | ||
{ | ||
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); | ||
$this->applyDatabaseChanges(); | ||
|
||
$this->client->request('get', '/api/v2/lists/1/count'); | ||
|
||
$this->assertHttpForbidden(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getListCountForExistingListWithExpiredSessionKeyReturnsForbiddenStatus() | ||
{ | ||
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); | ||
$this->getDataSet()->addTable(static::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv'); | ||
$this->getDataSet()->addTable(static::TOKEN_TABLE_NAME, __DIR__ . '/Fixtures/AdministratorToken.csv'); | ||
$this->applyDatabaseChanges(); | ||
|
||
$this->client->request( | ||
'get', | ||
'/api/v2/lists/1/count', | ||
[], | ||
[], | ||
['PHP_AUTH_USER' => 'unused', 'PHP_AUTH_PW' => 'cfdf64eecbbf336628b0f3071adba763'] | ||
); | ||
|
||
$this->assertHttpForbidden(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getListCountWithCurrentSessionKeyForExistingListReturnsOkayStatus() | ||
{ | ||
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); | ||
$this->applyDatabaseChanges(); | ||
|
||
$this->authenticatedJsonRequest('get', '/api/v2/lists/1/count'); | ||
|
||
$this->assertHttpOkay(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getListCountWithCurrentSessionKeyForExistingListWithSubscribersReturnsSubscribersCount() | ||
{ | ||
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); | ||
$this->getDataSet()->addTable(static::SUBSCRIBER_TABLE_NAME, __DIR__ . '/Fixtures/Subscriber.csv'); | ||
$this->getDataSet()->addTable(static::SUBSCRIPTION_TABLE_NAME, __DIR__ . '/Fixtures/Subscription.csv'); | ||
$this->applyDatabaseChanges(); | ||
|
||
$this->authenticatedJsonRequest('get', '/api/v2/lists/2/count'); | ||
$response = $this->getDecodedJsonResponseContent(); | ||
|
||
static::assertSame(1, $response); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getListCountWithCurrentSessionKeyForExistingListWithNoSubscribersReturnsZero() | ||
{ | ||
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); | ||
$this->getDataSet()->addTable(static::SUBSCRIBER_TABLE_NAME, __DIR__ . '/Fixtures/Subscriber.csv'); | ||
$this->getDataSet()->addTable(static::SUBSCRIPTION_TABLE_NAME, __DIR__ . '/Fixtures/Subscription.csv'); | ||
$this->applyDatabaseChanges(); | ||
|
||
$this->authenticatedJsonRequest('get', '/api/v2/lists/3/count'); | ||
$response = $this->getDecodedJsonResponseContent(); | ||
|
||
static::assertSame(0, $response); | ||
} | ||
} |