From d6f22dc0920ff64553960e2d7854e4365609c1df Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Thu, 22 Feb 2018 10:14:28 +0100 Subject: [PATCH] dev #58111 stopTracking when visiting new features --- .../admin/controllers/FeatureController.php | 1 + library/Class/Feature.php | 11 ++++++- .../IndexControllerFeaturesTrackingTest.php | 29 ++++++++++--------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/application/modules/admin/controllers/FeatureController.php b/application/modules/admin/controllers/FeatureController.php index ffc56905723..4c87e4d651b 100644 --- a/application/modules/admin/controllers/FeatureController.php +++ b/application/modules/admin/controllers/FeatureController.php @@ -23,6 +23,7 @@ class Admin_FeatureController extends ZendAfi_Controller_Action { public function indexAction() { $this->view->titre = $this->_('Les fonctionnalités du logiciel Bokeh'); + (new Class_Feature())->stopTracking(); $user = Class_Users::getIdentity(); $this->view->new_features = (new Class_Feature)->findNewFor($user); $this->view->checked_features = (new Class_Feature)->findCheckedBy($user); diff --git a/library/Class/Feature.php b/library/Class/Feature.php index 90cc49f6256..51dbb84bfaf 100644 --- a/library/Class/Feature.php +++ b/library/Class/Feature.php @@ -188,12 +188,21 @@ class Class_Feature { public function stopTracking() { + if (!Class_AdminVar::get('FEATURES_TRACKING_ENABLE')) + return; + + if(!$user = Class_Users::getIdentity()) + return; + + if(!$user->isAdmin()) + return; + $this->_getCookieJar()->getKey(); $this->_session = new Zend_Session_Namespace($this->_getCookieJar()->getKey()); return $this->_getCookieJar() ->setcookie($this->_getCookieJar()->getKey(), '1', - $this->getTimeSource()->time() + (3600 * 24 * 30 * 6)); + $this->getTimeSource()->time() + (3600 * 24 * 30 * 3)); } } diff --git a/tests/application/modules/admin/controllers/IndexControllerFeaturesTrackingTest.php b/tests/application/modules/admin/controllers/IndexControllerFeaturesTrackingTest.php index 90e1502920a..9cc11c5878a 100644 --- a/tests/application/modules/admin/controllers/IndexControllerFeaturesTrackingTest.php +++ b/tests/application/modules/admin/controllers/IndexControllerFeaturesTrackingTest.php @@ -39,12 +39,10 @@ abstract class IndexControllerFeaturesTrackingTestCase extends Admin_AbstractCon Class_Feature::setCookieJar($this->_cookie_jar = $this->mock() ->whenCalled('setcookie') - ->answers(null) + ->answers(true) ->whenCalled('getKey') - ->answers('tracking_features_7_11_20') - - ->beStrict()); + ->answers('tracking_features_7_11_20')); } @@ -128,10 +126,15 @@ class IndexControllerFeaturesTrackingExistingCookieVisitTest extends IndexControllerFeaturesTrackingTestCase { + public function setUp() { + parent::setUp(); + $_COOKIE['tracking_features_7_11_20'] = 1; + $this->dispatch('/', true); + } + + /** @test */ public function shouldNotDisplayNewFeaturesMessage() { - $_COOKIE['tracking_features_' . BOKEH_RELEASE_NUMBER] = 1; - $this->dispatch('/', true); $this->assertNotXPathContentContains('//script', $this->_expected_message); } } @@ -148,24 +151,24 @@ class IndexControllerFeaturesTrackingUntrackTest ->whenCalled('setcookie') ->with('tracking_features_7_11_20', 1, - 1534762314) - ->answers($_COOKIE = ['tracking_features_7_11_20' => 1]) + 1526986314) + ->answers(true) ->whenCalled('getKey') ->answers('tracking_features_7_11_20')); - - $this->dispatch('/admin/feature/stop-tracking', true); } /** @test */ - public function shouldNotDisplayNewFeaturesMessage() { - $this->assertEquals(1, $_COOKIE['tracking_features_7_11_20']); + public function stopTrackingActionshouldSetCookie() { + $this->dispatch('/admin/feature/stop-tracking', true); + $this->assertTrue($this->_cookie_jar->methodHasBeenCalled('setcookie')); } /** @test */ - public function shouldSetCookie() { + public function indexActionSetCookie() { + $this->dispatch('/admin/feature/index', true); $this->assertTrue($this->_cookie_jar->methodHasBeenCalled('setcookie')); } } \ No newline at end of file -- GitLab