-
Notifications
You must be signed in to change notification settings - Fork 24
fix(alert): force closed alerts display after alert update #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8fb0f3b
fix(alert): force closed alerts display after alert update
TarekRemo 7179d6e
changelog
TarekRemo 4fb49b3
remove cache file
TarekRemo f0a80f2
Merge branch 'main' into main
TarekRemo ee8abb6
fix unit tests
TarekRemo 8a3b81d
changes
TarekRemo 973d68a
changes
TarekRemo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <phpunit | ||
| bootstrap="tests/bootstrap.php" | ||
| colors="true" | ||
| testdox="true" | ||
| > | ||
| <testsuites> | ||
| <testsuite name="Tests"> | ||
| <directory>tests</directory> | ||
| </testsuite> | ||
| </testsuites> | ||
| </phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * ------------------------------------------------------------------------- | ||
| * News plugin for GLPI | ||
| * ------------------------------------------------------------------------- | ||
| * | ||
| * LICENSE | ||
| * | ||
| * This file is part of News. | ||
| * | ||
| * News is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 2 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * News is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with News. If not, see <http://www.gnu.org/licenses/>. | ||
| * ------------------------------------------------------------------------- | ||
| * @copyright Copyright (C) 2015-2023 by News plugin team. | ||
| * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html | ||
| * @link https://github.com/pluginsGLPI/news | ||
| * ------------------------------------------------------------------------- | ||
| */ | ||
|
|
||
| require __DIR__ . '/../../../tests/bootstrap.php'; | ||
| require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
|
||
| $plugin = new Plugin(); | ||
| $plugin->checkPluginState('news'); | ||
| $plugin->getFromDBbyDir('news'); | ||
|
|
||
| if (!$plugin->isInstalled('news')) { | ||
| $plugin->install($plugin->getID()); | ||
| } | ||
|
|
||
| if (!$plugin->isActivated('news')) { | ||
| $plugin->activate($plugin->getID()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * ------------------------------------------------------------------------- | ||
| * News plugin for GLPI | ||
| * ------------------------------------------------------------------------- | ||
| * | ||
| * LICENSE | ||
| * | ||
| * This file is part of News. | ||
| * | ||
| * News is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 2 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * News is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with News. If not, see <http://www.gnu.org/licenses/>. | ||
| * ------------------------------------------------------------------------- | ||
| * @copyright Copyright (C) 2015-2023 by News plugin team. | ||
| * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html | ||
| * @link https://github.com/pluginsGLPI/news | ||
| * ------------------------------------------------------------------------- | ||
| */ | ||
|
|
||
| namespace GlpiPlugin\News\Tests\Units; | ||
|
|
||
| use Glpi\Tests\DbTestCase; | ||
| use PluginNewsAlert; | ||
| use PluginNewsAlert_User; | ||
| use User; | ||
|
|
||
| class PluginNewsAlertTest extends DbTestCase | ||
| { | ||
| private function getAlertUserState(int $au_id): int | ||
| { | ||
| $alert_user = new PluginNewsAlert_User(); | ||
| $this->assertTrue($alert_user->getFromDB($au_id)); | ||
| return (int) $alert_user->fields['state']; | ||
| } | ||
|
|
||
| public function testPostUpdateItemResetsHiddenAlerts(): void | ||
| { | ||
| $this->login('glpi'); | ||
|
|
||
| $alert = $this->createItem( | ||
| PluginNewsAlert::class, | ||
| [ | ||
| 'name' => 'closable Alert', | ||
| 'message' => 'This is a closable alert', | ||
| 'type' => 1, | ||
| 'is_displayed_onlogin' => 1, | ||
| 'is_displayed_oncentral' => 1, | ||
| 'is_displayed_onservicecatalog' => 1, | ||
| 'display_dates' => 1, | ||
| 'background_color' => 'white', | ||
| 'emphasis_color' => 'dark', | ||
| 'size' => 'medium', | ||
| 'icon' => 'settings', | ||
| 'is_displayed_onhelpdesk' => 1, | ||
| 'is_active' => 1, | ||
| 'entities_id' => 0, | ||
| 'is_close_allowed' => 1, | ||
| ], | ||
| ); | ||
| $alert_id = $alert->getID(); | ||
|
|
||
| $user_1 = $this->createItem( | ||
| User::class, | ||
| [ | ||
| 'name' => 'user 1', | ||
| 'password' => 'test', | ||
| 'password2' => 'test', | ||
| ], | ||
| ['password', 'password2'], | ||
| ); | ||
|
|
||
| $user_2 = $this->createItem( | ||
| User::class, | ||
| [ | ||
| 'name' => 'user 2', | ||
| 'password' => 'test', | ||
| 'password2' => 'test', | ||
| ], | ||
| ['password', 'password2'], | ||
| ); | ||
|
|
||
| $user_3 = $this->createItem( | ||
| User::class, | ||
| [ | ||
| 'name' => 'user 3', | ||
| 'password' => 'test', | ||
| 'password2' => 'test', | ||
| ], | ||
| ['password', 'password2'], | ||
| ); | ||
|
|
||
| $user_1_id = $user_1->getID(); | ||
| $user_2_id = $user_2->getID(); | ||
| $user_3_id = $user_3->getID(); | ||
|
|
||
| $alert_user_1 = $this->createItem(PluginNewsAlert_User::class, [ | ||
| 'plugin_news_alerts_id' => $alert_id, | ||
| 'users_id' => $user_1_id, | ||
| 'state' => PluginNewsAlert_User::HIDDEN, | ||
| ]); | ||
|
|
||
| $alert_user_2 = $this->createItem(PluginNewsAlert_User::class, [ | ||
| 'plugin_news_alerts_id' => $alert_id, | ||
| 'users_id' => $user_2_id, | ||
| 'state' => PluginNewsAlert_User::HIDDEN, | ||
| ]); | ||
|
|
||
| //user 3 has not hidden the alert | ||
| $alert_user_3 = $this->createItem(PluginNewsAlert_User::class, [ | ||
| 'plugin_news_alerts_id' => $alert_id, | ||
| 'users_id' => $user_3_id, | ||
| 'state' => PluginNewsAlert_User::VISIBLE, | ||
| ]); | ||
|
|
||
| $alert_user_1_id = $alert_user_1->getID(); | ||
| $alert_user_2_id = $alert_user_2->getID(); | ||
| $alert_user_3_id = $alert_user_3->getID(); | ||
|
|
||
| $this->updateItem(PluginNewsAlert::class, $alert_id, ['name' => 'Alert with hidden users (updated)']); | ||
|
|
||
| //assert that both users are now in VISIBLE state | ||
| $this->assertSame(PluginNewsAlert_User::VISIBLE, $this->getAlertUserState($alert_user_1_id)); | ||
| $this->assertSame(PluginNewsAlert_User::VISIBLE, $this->getAlertUserState($alert_user_2_id)); | ||
|
|
||
| //assert that user 3 is still in VISIBLE state | ||
| $this->assertSame(PluginNewsAlert_User::VISIBLE, $this->getAlertUserState($alert_user_3_id)); | ||
|
|
||
| //re-hide users 1 and 2 alerts | ||
| $this->updateItem(PluginNewsAlert_User::class, $alert_user_1_id, ['state' => PluginNewsAlert_User::HIDDEN]); | ||
| $this->updateItem(PluginNewsAlert_User::class, $alert_user_2_id, ['state' => PluginNewsAlert_User::HIDDEN]); | ||
|
|
||
| //update the alert with is_close_allowed = 0 | ||
| $this->updateItem(PluginNewsAlert::class, $alert_id, ['is_close_allowed' => 0]); | ||
|
|
||
| //assert that alerts are visible again | ||
| $this->assertSame(PluginNewsAlert_User::VISIBLE, $this->getAlertUserState($alert_user_1_id)); | ||
| $this->assertSame(PluginNewsAlert_User::VISIBLE, $this->getAlertUserState($alert_user_2_id)); | ||
|
|
||
| //assert that user 3 is still in VISIBLE state | ||
| $this->assertSame(PluginNewsAlert_User::VISIBLE, $this->getAlertUserState($alert_user_3_id)); | ||
| } | ||
|
|
||
| public function testPostUpdateItemDoesNotAffectOtherAlerts(): void | ||
| { | ||
| $this->login('glpi'); | ||
|
|
||
| $alert_1 = $this->createItem( | ||
| PluginNewsAlert::class, | ||
| [ | ||
| 'name' => 'alert 1', | ||
| 'message' => 'This is a closable alert', | ||
| 'type' => 1, | ||
| 'is_displayed_onlogin' => 1, | ||
| 'is_displayed_oncentral' => 1, | ||
| 'is_displayed_onservicecatalog' => 1, | ||
| 'display_dates' => 1, | ||
| 'background_color' => 'white', | ||
| 'emphasis_color' => 'dark', | ||
| 'size' => 'medium', | ||
| 'icon' => 'settings', | ||
| 'is_displayed_onhelpdesk' => 1, | ||
| 'is_active' => 1, | ||
| 'entities_id' => 0, | ||
| 'is_close_allowed' => 1, | ||
| ], | ||
| ); | ||
| $alert_1_id = $alert_1->getID(); | ||
|
|
||
| $alert_2 = $this->createItem( | ||
| PluginNewsAlert::class, | ||
| [ | ||
| 'name' => 'alert 2', | ||
| 'message' => 'This is a closable alert', | ||
| 'type' => 1, | ||
| 'is_displayed_onlogin' => 1, | ||
| 'is_displayed_oncentral' => 1, | ||
| 'is_displayed_onservicecatalog' => 1, | ||
| 'display_dates' => 1, | ||
| 'background_color' => 'white', | ||
| 'emphasis_color' => 'dark', | ||
| 'size' => 'medium', | ||
| 'icon' => 'settings', | ||
| 'is_displayed_onhelpdesk' => 1, | ||
| 'is_active' => 1, | ||
| 'entities_id' => 0, | ||
| 'is_close_allowed' => 1, | ||
| ], | ||
| ); | ||
| $alert_2_id = $alert_2->getID(); | ||
|
|
||
| $user_1 = $this->createItem( | ||
| User::class, | ||
| [ | ||
| 'name' => 'user 1', | ||
| 'password' => 'test', | ||
| 'password2' => 'test', | ||
| ], | ||
| ['password', 'password2'], | ||
| ); | ||
| $user_1_id = $user_1->getID(); | ||
|
|
||
| $alert_user_1 = $this->createItem(PluginNewsAlert_User::class, [ | ||
| 'plugin_news_alerts_id' => $alert_1_id, | ||
| 'users_id' => $user_1_id, | ||
| 'state' => PluginNewsAlert_User::HIDDEN, | ||
| ]); | ||
|
|
||
| $alert_user_2 = $this->createItem(PluginNewsAlert_User::class, [ | ||
| 'plugin_news_alerts_id' => $alert_2_id, | ||
| 'users_id' => $user_1_id, | ||
| 'state' => PluginNewsAlert_User::HIDDEN, | ||
| ]); | ||
|
|
||
| $alert_user_1_id = $alert_user_1->getID(); | ||
| $alert_user_2_id = $alert_user_2->getID(); | ||
|
|
||
| $this->updateItem(PluginNewsAlert::class, $alert_1_id, ['name' => 'Alert 1 (updated)']); | ||
|
|
||
| $this->assertSame(PluginNewsAlert_User::VISIBLE, $this->getAlertUserState($alert_user_1_id)); | ||
| $this->assertSame(PluginNewsAlert_User::HIDDEN, $this->getAlertUserState($alert_user_2_id)); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.