Commit d3b40ef6 authored by Patrick Barroca's avatar Patrick Barroca 🐧

rel #46014 : count subscribers from groups

parent 8e302772
......@@ -141,7 +141,12 @@ class Class_Newsletter extends Storm_Model_Abstract {
public function getNumberOfUsers() {
return sprintf('%05d', Class_NewsletterSubscription::countAvailableUserForNewsletter($this->getId()));
$ids = [];
foreach($this->getUserGroups() as $group)
foreach($group->getUsersIds() as $id)
$ids[] = $id;
return sprintf('%05d', count(array_unique($ids)));
}
......
......@@ -19,10 +19,30 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class UserGroupLoader extends Storm_Model_Loader {
use Trait_MemoryCleaner;
public function getUsersIdsOf($group) {
$ids = [];
$page = 1;
while ($users = $group->getUsersPage($page, 1000)) {
$page++;
foreach($users as $user)
$ids[] = $user->getId();
$this->_cleanMemory();
}
return $ids;
}
}
class Class_UserGroup extends Storm_Model_Abstract {
use Trait_TreeViewableItem, Trait_HasManyDomaines;
protected $_table_name = 'user_groups';
protected $_loader_class = 'UserGroupLoader';
protected $_has_many =
['user_group_memberships' => ['model' => 'Class_UserGroupMembership',
'role' => 'user_group',
......@@ -403,7 +423,6 @@ class Class_UserGroup extends Storm_Model_Abstract {
}
public function getIcoInfo() {
if ($this->isDynamic())
return 'groups_star';
......@@ -411,6 +430,11 @@ class Class_UserGroup extends Storm_Model_Abstract {
}
public function getUsersIds() {
return $this->getLoader()->getUsersIdsOf($this);
}
public function getUsersPage($page, $items_by_page) {
if ($this->isDynamic())
return $this->getDynamicUsersPage($page, $items_by_page);
......
......@@ -73,10 +73,9 @@ class ZendAfi_Form_Admin_Newsletter extends ZendAfi_Form {
'letter',
['legend' => $this->_('Lettre')])
->addDisplayGroup(['auto_subscribe',
'subscribe_group_ids'],
'add_reader',
['legend' => $this->_('Inscription automatique des nouveaux utilisateurs')])
->addDisplayGroup(['subscribe_group_ids'],
'groups_subscriptions',
['legend' => $this->_('Destinataires')])
->addDisplayGroup(['contenu'],
'contenu_html',
......
......@@ -64,18 +64,35 @@ abstract class Admin_NewsletterControllerTestCase extends Admin_AbstractControll
->beStrict();
$this->fixture('Class_UserGroup',
['id' => 14,
'libelle' => 'My Group']);
$this->fixture('Class_UserGroup',
['id' => 15,
'libelle' => 'My Other Group']);
$pat = $this->fixture('Class_Users',
['id' => 23,
'login' => 'pat',
'password' => 'tap']);
$laurent = $this->fixture('Class_Users',
['id' => 22,
'login' => 'lla',
'password' => 'all',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'idabon' => '0007',
'id_site' => 1]);
$my_group = $this->fixture('Class_UserGroup',
['id' => 14,
'libelle' => 'My Group',
'users' => [$pat, $laurent]]);
$other_group = $this->fixture('Class_UserGroup',
['id' => 15,
'libelle' => 'My Other Group',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
$this->fixture('Class_Newsletter',
['id' => 1,
'titre' => 'Nouveautés classique',
'contenu' => 'Notre sélection du mois']);
'contenu' => 'Notre sélection du mois',
'user_groups' => [$my_group, $other_group]]);
Class_Newsletter::find(1)->setLastDistributionDateWithFormat();
......@@ -83,7 +100,8 @@ abstract class Admin_NewsletterControllerTestCase extends Admin_AbstractControll
['id' => 2,
'titre' => 'Animations',
'contenu' => 'Pour les jeunes',
'last_distribution_date' => null]);
'last_distribution_date' => null,
'user_groups' => [$my_group]]);
}
}
......@@ -121,18 +139,14 @@ class Admin_NewsletterControllerConfigActionTest extends Admin_NewsletterControl
class Admin_NewsletterControllerIndexActionTest extends Admin_NewsletterControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/admin/newsletter', true);
}
public function testIndexActionFound() {
$this->assertController('newsletter');
$this->assertAction('index');
Class_UserGroup::setMemoryCleaner(function() {});
$this->dispatch('/admin/newsletter', true);
}
public function testListNouveautesClassique() {
$this->assertXPathContentContains("//tbody//tr//td", 'Nouveautés classique');
$this->assertXPathContentContains("//td", 'Nouveautés classique');
}
......@@ -143,8 +157,8 @@ class Admin_NewsletterControllerIndexActionTest extends Admin_NewsletterControll
/** @test */
public function numberOfSubscriberShouldBeTwo() {
$this->assertXPathContentContains("//tbody//tr//td//a[@href='/admin/newsletter/edit-subscribers/id/1']", '00001');
public function numberOfSubscriberToNouveauteClassiqueShouldBeTwo() {
$this->assertXPathContentContains("//a[@href='/admin/newsletter/edit-subscribers/id/1']", '00002');
}
......@@ -155,67 +169,73 @@ class Admin_NewsletterControllerIndexActionTest extends Admin_NewsletterControll
public function testEditNouveautesClassiqueLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/edit/id/1']");
$this->assertXPath("//a[@href='/admin/newsletter/edit/id/1']");
}
public function testDeleteNouveautesClassiqueLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/delete/id/1']");
$this->assertXPath("//a[@href='/admin/newsletter/delete/id/1']");
}
public function testEditSubscribersNouveautesClassiqueLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/edit-subscribers/id/1']");
$this->assertXPath("//a[@href='/admin/newsletter/edit-subscribers/id/1']");
}
public function testPreviewNouveautesClassiqueLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/preview/id/1']");
$this->assertXPath("//a[@href='/admin/newsletter/preview/id/1']");
}
public function testDuplicateLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/duplicate/id/1']");
$this->assertXPath("//a[@href='/admin/newsletter/duplicate/id/1']");
}
public function testTestNouveautesClassiqueLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/sendtest/id/1']");
$this->assertXPath("//a[@href='/admin/newsletter/sendtest/id/1']");
}
public function testSendNouveautesClassiqueLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/send/id/1']");
$this->assertXPath("//a[@href='/admin/newsletter/send/id/1']");
}
public function testListAnimations() {
$this->assertXPathContentContains("//tbody//tr//td", 'Animations');
$this->assertXPathContentContains("//td", 'Animations');
}
/** @test */
public function numberOfSubscriberToAnimationsShouldBeTwo() {
$this->assertXPathContentContains("//a[@href='/admin/newsletter/edit-subscribers/id/2']", '00002');
}
public function testListAnimationsEditLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/edit/id/2']");
$this->assertXPath("//a[@href='/admin/newsletter/edit/id/2']");
}
public function testDeleteAnimationsLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/delete/id/2']");
$this->assertXPath("//a[@href='/admin/newsletter/delete/id/2']");
}
public function testPreviewAnimationsLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/preview/id/2']");
$this->assertXPath("//a[@href='/admin/newsletter/preview/id/2']");
}
public function testTestAnimationsLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/sendtest/id/2']");
$this->assertXPath("//a[@href='/admin/newsletter/sendtest/id/2']");
}
public function testSendAnimationsLink() {
$this->assertXPath("//tbody//tr//td//a[@href='/admin/newsletter/send/id/2']");
$this->assertXPath("//a[@href='/admin/newsletter/send/id/2']");
}
......@@ -388,6 +408,12 @@ class Admin_NewsletterControllerEditActionTest extends Admin_NewsletterControlle
}
/** @test */
public function groupsLegendShouldBeDestinataires() {
$this->assertXPathContentContains('//legend', 'Destinataires');
}
/** @test **/
public function autoAddNewUsersByGroupsShouldBePresentWithValue() {
$this->assertXPath("//input[@name='subscribe_group_ids'][@value='14-15']");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment