diff --git a/application/modules/admin/controllers/RedmineController.php b/application/modules/admin/controllers/RedmineController.php index 7db8e79b8b98d7b7a83d1ed3acb5797b8f8ba53a..6cf1d3c823d690f715db1b8c92a589a10788b471 100644 --- a/application/modules/admin/controllers/RedmineController.php +++ b/application/modules/admin/controllers/RedmineController.php @@ -37,11 +37,11 @@ class Admin_RedmineController extends ZendAfi_Controller_Action { }; $renderUser = function($library_id, $data) { - return $this->view->libraries[$library_id]['user'] = $this->extractConnectedUser($data, Class_Users::getIdentity()->getRedmineLibrary()); + return $this->view->libraries[$library_id]['user'] = Class_WebService_redmine::extractConnectedUser($data, Class_Users::getIdentity()->getRedmineLibrary()); }; $renderProject = function($library_id, $data) { - return $this->view->libraries[$library_id ]['project'] = $this->extractProject($data); + return $this->view->libraries[$library_id ]['project'] = Class_WebService_redmine::extractProject($data); }; foreach($libraries as $library) { @@ -64,7 +64,7 @@ class Admin_RedmineController extends ZendAfi_Controller_Action { public function testAction() { $renderSuccess = function($library_id, $data) { - if($connected = $this->extractConnectedUser($data, Class_Bib::find($library_id))) + if($connected = Class_WebService_Redmine::extractConnectedUser($data, Class_Bib::find($library_id))) return $this->view->getHelper('Redmine_AccountStatus')->successfullConnection($connected); return $this->view->getHelper('Redmine_AccountStatus')->connectionFail(); }; @@ -77,26 +77,6 @@ class Admin_RedmineController extends ZendAfi_Controller_Action { } - protected function extractConnectedUser($data, $library) { - if(!isset($data['user'])) - return false; - - if($library) - $library->setRedmineUserId($data['user']['id']) - ->setRedmineApiKey($data['user']['api_key']) - ->save(); - - return $this->_('Vous êtes connecté(e) en tant que %s %s', - $data['user']['firstname'], - $data['user']['lastname']); - } - - - protected function extractProject($data) { - return $data['project']['name']; - } - - protected function withResponseDoInPopup($library, $data, $call_back, $title) { return $this->_helper->json(['title' => $title, 'content' => $this->withResponseDo($library, $data, $call_back)]); diff --git a/library/Class/WebService/Redmine.php b/library/Class/WebService/Redmine.php index 6becaa4881c8d8e31963ac4a784bc43663c7d442..9edfe120fc4bba08c3bc2e054f97ba421c2ac8a2 100644 --- a/library/Class/WebService/Redmine.php +++ b/library/Class/WebService/Redmine.php @@ -117,5 +117,28 @@ class Class_WebService_Redmine extends Class_WebService_Abstract { return $models; } + + + public static function extractConnectedUser($data, $library) { + if(!isset($data['user'])) + return false; + + if($library) + $library->setRedmineUserId($data['user']['id']) + ->setRedmineApiKey($data['user']['api_key']) + ->save(); + + return (new self())->_('Vous êtes connecté(e) en tant que %s %s', + $data['user']['firstname'], + $data['user']['lastname']); + } + + + public static function extractProject($data) { + if(!isset($data['project'])) + return ''; + + return $data['project']['name']; + } } ?> \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/BibControllerTest.php b/tests/application/modules/admin/controllers/BibControllerTest.php index 5136632b1cf94164d4382608685a1fb1124254df..680d6e0af0dc672f24241a3b9bbd5e13f86e0ed8 100644 --- a/tests/application/modules/admin/controllers/BibControllerTest.php +++ b/tests/application/modules/admin/controllers/BibControllerTest.php @@ -1206,7 +1206,7 @@ class BibControllerWithRemineAPITest extends BibControllerWithRedmineAPITestCase /** @test */ public function redmineApiKeyShouldBeEmpty() { - $this->assertXPath('//table//tr//td//input[@name="redmine_api_key"][@value=""][@type="text"]', $this->_response->getBody()); + $this->assertXPath('//table//tr//td//input[@name="redmine_api_key"][@value=""][@type="password"]', $this->_response->getBody()); } diff --git a/tests/application/modules/admin/controllers/RedmineControllerTest.php b/tests/application/modules/admin/controllers/RedmineControllerTest.php index 9777713fe7950239ea7495310e7af39b8ab436d5..ea3fc33820fe9e9a3c9503b6831feacf3d363c50 100644 --- a/tests/application/modules/admin/controllers/RedmineControllerTest.php +++ b/tests/application/modules/admin/controllers/RedmineControllerTest.php @@ -68,7 +68,7 @@ class Admin_RedmineControllerWithAnnecyLibraryTestCase extends Admin_RedmineCont -class Admin_RedmineControllerWithEmptyLibraryTestCase extends Admin_RedmineControllerTestCase { +abstract class Admin_RedmineControllerWithEmptyLibraryTestCase extends Admin_RedmineControllerTestCase { public function setUp() { parent::setUp(); @@ -100,7 +100,7 @@ class Admin_RedmineControllerTestActionWithBibTest extends Admin_RedmineControll /** @test */ public function responseShouldContainsNoBibGiven() { - $this->assertEquals(RedmineFixtures::noServerUrlGiven()); + $this->assertEquals(RedmineFixtures::noServerUrlGiven(), $this->_response->getBody()); } }