Skip to content

Commit e387b90

Browse files
authored
Fix PHPUnit web tests execution inside dev container (#22011)
1 parent 75d265f commit e387b90

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

.docker/app/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ FROM ghcr.io/glpi-project/glpi-development-env:$PHP_VERSION
44

55
USER root
66

7+
# Use apache configuration suitable for GLPI 10.x
8+
RUN cp /etc/apache2/sites-available/glpi-10.x.conf /etc/apache2/sites-available/000-default.conf
9+
710
# Allow extra PHP configuration to be placed in a dedicated folder than can serve
811
# as a volume
912
ENV PHP_INI_SCAN_DIR "/usr/local/etc/php/conf.d/:/usr/local/etc/php/custom_conf.d/"

.github/actions/test_tests-web.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
set -e -u -x -o pipefail
33

44
php -S localhost:8088 phpunit/router.php &>/dev/null &
5-
bin/console config:set --config-dir=./tests/config --context=inventory enabled_inventory 1
65
vendor/bin/phpunit phpunit/web
7-
bin/console config:set --config-dir=./tests/config --context=inventory enabled_inventory 0

phpunit/APIBaseClass.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,14 +1758,26 @@ protected function checkEmptyContentRange($data, $headers)
17581758

17591759
public function testUndisclosedNotificationContent()
17601760
{
1761+
global $DB;
1762+
1763+
$user = getItemByTypeName('User', TU_USER);
1764+
17611765
// Enable notifications
17621766
Config::setConfigurationValues('core', [
17631767
'use_notifications' => '1',
17641768
'notifications_mailing' => '1',
17651769
]);
17661770

1771+
// Empty existing notifications
1772+
$DB->delete(
1773+
QueuedNotification::getTable(),
1774+
[
1775+
'itemtype' => User::class,
1776+
'items_id' => $user->getID(),
1777+
]
1778+
);
1779+
17671780
// Trigger a notification sending
1768-
$user = getItemByTypeName('User', TU_USER);
17691781
$this->query(
17701782
'lostPassword',
17711783
[
@@ -1795,6 +1807,12 @@ public function testUndisclosedNotificationContent()
17951807
[
17961808
'itemtype' => QueuedNotification::class,
17971809
'headers' => ['Session-Token' => $data['session_token']],
1810+
'query' => [
1811+
'searchText' => [
1812+
'itemtype' => User::class,
1813+
'items_id' => $user->getID(),
1814+
],
1815+
],
17981816
],
17991817
200
18001818
);
@@ -1821,6 +1839,18 @@ public function testUndisclosedNotificationContent()
18211839
'headers' => ['Session-Token' => $data['session_token']],
18221840
'query' => [
18231841
'reset' => 'reset',
1842+
'criteria' => [
1843+
[
1844+
'field' => 20,
1845+
'searchtype' => 'equals',
1846+
'value' => User::class,
1847+
],
1848+
[
1849+
'field' => 21,
1850+
'searchtype' => 'equals',
1851+
'value' => $user->getID(),
1852+
],
1853+
],
18241854
'forcedisplay' => [12, 13],
18251855
],
18261856
],

phpunit/web/Glpi/Inventory/InventoryTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
namespace tests\units\Glpi\Inventory;
3636

37+
use Config;
3738
use GuzzleHttp;
3839

3940
class InventoryTest extends \GLPITestCase
@@ -48,6 +49,11 @@ public function setUp(): void
4849
$this->http_client = new GuzzleHttp\Client();
4950
$this->base_uri = trim($CFG_GLPI['url_base'], "/") . "/";
5051

52+
// Enable inventory
53+
Config::setConfigurationValues('inventory', [
54+
'enabled_inventory' => '1',
55+
]);
56+
5157
parent::setUp();
5258
}
5359

phpunit/web/Glpi/Inventory/RequestTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
namespace tests\units\Glpi\Inventory;
3636

37+
use Config;
3738
use GuzzleHttp;
3839
use GuzzleHttp\Exception\RequestException;
3940
use GuzzleHttp\Psr7\Response;
@@ -50,6 +51,11 @@ public function setUp(): void
5051
$this->http_client = new GuzzleHttp\Client();
5152
$this->base_uri = trim($CFG_GLPI['url_base'], "/") . "/";
5253

54+
// Enable inventory
55+
Config::setConfigurationValues('inventory', [
56+
'enabled_inventory' => '1',
57+
]);
58+
5359
parent::setUp();
5460
}
5561

0 commit comments

Comments
 (0)