Skip to content

Commit

Permalink
get the number of subscribers of list, Fix #115
Browse files Browse the repository at this point in the history
Signed-off-by: Xheni Myrtaj <[email protected]>
  • Loading branch information
xh3n1 committed Jan 27, 2019
1 parent c8e3636 commit 8fb00c7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Controller/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 getNumberAction(Request $request, SubscriberList $list): View
{
$this->requireAuthentication($request);

return View::create()->setData(count($list->getSubscribers()));
}
}
61 changes: 61 additions & 0 deletions tests/Integration/Controller/ListControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Testcase.
*
* @author Oliver Klee <[email protected]>
* @author Xheni Myrtaj <[email protected]>
*
*/
class ListControllerTest extends AbstractControllerTest
{
Expand Down Expand Up @@ -320,4 +322,63 @@ public function getListMembersWithCurrentSessionKeyForExistingListWithSubscriber
]
);
}

/**
* @test
*/
public function getListNumberForExistingListWithoutSessionKeyReturnsForbiddenStatus()
{
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
$this->applyDatabaseChanges();

$this->client->request('get', '/api/v2/lists/1/number');

$this->assertHttpForbidden();
}

/**
* @test
*/
public function getListNumberForExistingListWithExpiredSessionKeyReturnsForbiddenStatus()
{
$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/number',
[],
[],
['PHP_AUTH_USER' => 'unused', 'PHP_AUTH_PW' => 'cfdf64eecbbf336628b0f3071adba763']
);

$this->assertHttpForbidden();
}

/**
* @test
*/
public function getListNumberWithCurrentSessionKeyForExistingListReturnsOkayStatus()
{
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
$this->applyDatabaseChanges();

$this->authenticatedJsonRequest('get', '/api/v2/lists/1/number');

$this->assertHttpOkay();
}

public function getListNumberWithCurrentSessionKeyForExistingListWithSubscribersReturnsSubscribers()
{
$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/number');

$this->assertEquals(1, true);
}
}

0 comments on commit 8fb00c7

Please sign in to comment.