diff --git a/VERSIONS_HOTLINE/153767 b/VERSIONS_HOTLINE/153767 new file mode 100644 index 0000000000000000000000000000000000000000..9e5c26f5c95b85988e53af0d81c259241ad259a6 --- /dev/null +++ b/VERSIONS_HOTLINE/153767 @@ -0,0 +1 @@ + - correctif #153767 : Administration : correction de la sélection lors de la suppression des utilisateurs. \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Admin/SearchUsers.php b/library/ZendAfi/View/Helper/Admin/SearchUsers.php index 6c3d1a134dab2e367617743f57f2659a42d4e042..b94ff46eeec0abcf066ad359ef98d98ebf5916c6 100644 --- a/library/ZendAfi/View/Helper/Admin/SearchUsers.php +++ b/library/ZendAfi/View/Helper/Admin/SearchUsers.php @@ -47,7 +47,7 @@ class ZendAfi_View_Helper_Admin_SearchUsers 'controller' => 'users', 'action' => 'mass-delete'], null, true) - . '?' . http_build_query(array_filter($this->_context->getParams()))) + . '?' . $this->_getDeleteParams()) ->setImage($this->view->tagImg(Class_Admin_Skin::current() ->getIconUrl('buttons', 'delete'), @@ -66,4 +66,12 @@ class ZendAfi_View_Helper_Admin_SearchUsers '%d utilisateurs trouvés', $total); } + + + protected function _getDeleteParams() : string { + $params = array_filter($this->_context->getParams(), + fn($param) => '' !== (string)$param || 0 === $param); + + return http_build_query($params); + } } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/UsersControllerTest.php b/tests/application/modules/admin/controllers/UsersControllerTest.php index 951cf7ca0bf7751f6fc83ffb9a1dba4ec30aac73..655a4facb1be888b67271b7e7663179e2056c379 100644 --- a/tests/application/modules/admin/controllers/UsersControllerTest.php +++ b/tests/application/modules/admin/controllers/UsersControllerTest.php @@ -95,9 +95,13 @@ abstract class UsersControllerWithMarcusTestCase extends AbstractControllerTestC -class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { +abstract class UsersControllerIndexTestCase extends UsersControllerWithMarcusTestCase { + + protected $_role_level; + public function setUp() { parent::setUp(); + $time_source = new TimeSourceForTest('2012-02-01 14:00:00'); Class_User_SearchCriteria_Age::setTimeSource($time_source); Class_AdminVar::set('ENABLED_SEARCH_USER_AGE',1); @@ -108,7 +112,7 @@ class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { ->answers([]) ->whenCalled('fetchAll') - ->with('select idabon, count(*) as doublon from bib_admin_users where role_level = 2 group by idabon having doublon > 1;') + ->with('select idabon, count(*) as doublon from bib_admin_users where role_level = ' . $this->_role_level . ' group by idabon having doublon > 1;') ->answers([]) ->whenCalled('fetchAllByColumn') @@ -128,7 +132,12 @@ class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { 'password' => 'francis', 'last_login' => 0]); + $borrower_birthdate = (2 === $this->_role_level) + ? '(STR_TO_DATE(date_fin, \'%Y-%m-%d\') >= CURDATE()) AND ' + : ''; + $this->onLoaderOfModel(Class_Users::class) + ->whenCalled('isCurrentUserCanAccesBackend') ->answers(false) @@ -152,16 +161,16 @@ class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { ->answers([$francis]) ->whenCalled('findAllBy') - ->with(['role_level' => 2, + ->with(['role_level' => (string) $this->_role_level, 'order' => 'nom asc', - 'where' => '(STR_TO_DATE(date_fin, \'%Y-%m-%d\') >= CURDATE()) AND (naissance <=\'2002-02-01\') AND (naissance >=\'1913-02-01\') AND (id_user in (2233,987398)) AND (login LIKE "%francis%" OR nom LIKE "%francis%" OR prenom LIKE "%francis%" OR pseudo LIKE "%francis%" OR mail LIKE "%francis%" OR idabon LIKE "%francis%") AND (role_level <= 7)', + 'where' => $borrower_birthdate . '(naissance <=\'2002-02-01\') AND (naissance >=\'1913-02-01\') AND (id_user in (2233,987398)) AND (login LIKE "%francis%" OR nom LIKE "%francis%" OR prenom LIKE "%francis%" OR pseudo LIKE "%francis%" OR mail LIKE "%francis%" OR idabon LIKE "%francis%") AND (role_level <= 7)', 'limitPage' => [1, 20]]) ->answers([$francis]) ->whenCalled('countBy') - ->with(['role_level' => 2, + ->with(['role_level' => (string) $this->_role_level, 'order' => 'nom asc', - 'where' => '(STR_TO_DATE(date_fin, \'%Y-%m-%d\') >= CURDATE()) AND (naissance <=\'2002-02-01\') AND (naissance >=\'1913-02-01\') AND (id_user in (2233,987398)) AND (login LIKE "%francis%" OR nom LIKE "%francis%" OR prenom LIKE "%francis%" OR pseudo LIKE "%francis%" OR mail LIKE "%francis%" OR idabon LIKE "%francis%") AND (role_level <= 7)']) + 'where' => $borrower_birthdate . '(naissance <=\'2002-02-01\') AND (naissance >=\'1913-02-01\') AND (id_user in (2233,987398)) AND (login LIKE "%francis%" OR nom LIKE "%francis%" OR prenom LIKE "%francis%" OR pseudo LIKE "%francis%" OR mail LIKE "%francis%" OR idabon LIKE "%francis%") AND (role_level <= 7)']) ->answers(55) ->whenCalled('findAllBy') @@ -174,8 +183,16 @@ class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { ->beStrict(); - $this->dispatch('/admin/users?search_id_site=all&search_role_level=2&search_age_debut=10&search_age_fin=99&search_valid_subscription=1&search_review=1&search_search_for=\"\'fra"n\'cis"', true); + $this->dispatch('/admin/users?search_id_site=all&search_role_level=' . $this->_role_level . '&search_age_debut=10&search_age_fin=99&search_valid_subscription=1&search_review=1&search_search_for=\"\'fra"n\'cis"'); } +} + + + + +class UsersControllerIndexSearchRoleLevelBorowersTest extends UsersControllerIndexTestCase { + + protected $_role_level = 2; /** @test */ @@ -250,8 +267,7 @@ class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { /** @test */ public function linkToEditFrancisShouldBePresent() { - $this->assertXPath('//table//tr//a[contains(@href, "admin/users/edit/id/57")]', - $this->_response->getBody()); + $this->assertXPath('//table//tr//a[contains(@href, "admin/users/edit/id/57")]'); } @@ -287,8 +303,23 @@ class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { /** @test */ public function massDeleteButtonWithCurrentQueryParamsShouldBePresent() { - $this->assertXPathContentContains('//button[contains(@onclick, "admin/users/mass-delete?search_id_site=all&search_role_level=2&search_valid_subscription=1&search_statut=all&search_review=1")]', - 'Supprimer ces utilisateurs', $this->_response->getBody()); + $this->assertXPathContentContains('//button[@onclick = "window.location.href = \'/admin/users/mass-delete?search_id_site=all&search_role_level=2&search_valid_subscription=1&search_statut=all&search_never_logged=0&search_review=1&search_basket=all&search_search_for=%5C%22%27fra%22n%27cis%22&search_order=nom+asc&page=1\';"]', + 'Supprimer ces utilisateurs'); + } +} + + + + +class UsersControllerIndexSearchRoleLevelGuestTest extends UsersControllerIndexTestCase { + + protected $_role_level = 0; + + + /** @test */ + public function massDeleteButtonWithCurrentQueryParamsShouldBePresent() { + $this->assertXPathContentContains('//button[@onclick = "window.location.href = \'/admin/users/mass-delete?search_id_site=all&search_role_level=0&search_valid_subscription=1&search_statut=all&search_never_logged=0&search_review=1&search_basket=all&search_search_for=%5C%22%27fra%22n%27cis%22&search_order=nom+asc&page=1\';"]', + 'Supprimer ces utilisateurs'); } }