Skip to content

Make url_base and root_doc consistents in testing env #19831

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/actions/test_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,3 @@ bin/console database:update --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "database:update command FAILED" && exit 1;
fi

# Defines the base URL to match the default one used in web/e2e tests
bin/console config:set url_base http://localhost:80
2 changes: 1 addition & 1 deletion install/empty_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getEmptyData(): array
'planning_end' => '20:00:00',
'utf8_conv' => '1',
'use_public_faq' => '0',
'url_base' => 'http://localhost/glpi',
'url_base' => 'http://localhost',
'show_link_in_mail' => '0',
'text_login' => '',
'founded_new_version' => '',
Expand Down
2 changes: 1 addition & 1 deletion phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
use Glpi\Kernel\Kernel;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

define('GLPI_URI', getenv('GLPI_URI') ?: 'http://localhost:80');
define('GLPI_URI', getenv('GLPI_URI') ?: 'http://localhost');

define('TU_USER', '_test_user');
define('TU_PASS', 'PhpUnit_4');
Expand Down
10 changes: 5 additions & 5 deletions phpunit/functional/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,37 +235,37 @@ public function testGetMethodLink()

$this->assertSame(
sprintf(
'LDAP directory: <a href="/glpi/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
'LDAP directory: <a href="/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
$local_ldap_id
),
Auth::getMethodLink(Auth::LDAP, $local_ldap_id)
);

$this->assertSame(
sprintf(
'Email server: <a href="/glpi/front/authmail.form.php?id=%d" title="mail.example.org">mail.example.org</a>',
'Email server: <a href="/front/authmail.form.php?id=%d" title="mail.example.org">mail.example.org</a>',
$autmail->getID()
),
Auth::getMethodLink(Auth::MAIL, $autmail->getID())
);

$this->assertSame(
sprintf(
'CAS + LDAP directory: <a href="/glpi/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
'CAS + LDAP directory: <a href="/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
$local_ldap_id
),
Auth::getMethodLink(Auth::CAS, $local_ldap_id)
);
$this->assertSame(
sprintf(
'x509 certificate authentication + LDAP directory: <a href="/glpi/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
'x509 certificate authentication + LDAP directory: <a href="/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
$local_ldap_id
),
Auth::getMethodLink(Auth::X509, $local_ldap_id)
);
$this->assertSame(
sprintf(
'Other + LDAP directory: <a href="/glpi/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
'Other + LDAP directory: <a href="/front/authldap.form.php?id=%d" title="_local_ldap">_local_ldap</a>',
$local_ldap_id
),
Auth::getMethodLink(Auth::EXTERNAL, $local_ldap_id)
Expand Down
2 changes: 1 addition & 1 deletion phpunit/functional/ChangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public function testCentralChangeValidationList()
\Change::showCentralList(0, 'tovalidate', false);
$output = ob_get_clean();
$this->assertStringContainsString("Your changes to validate <span class='primary-bg primary-fg count'>1</span>", $output);
$this->assertMatchesRegularExpression("/href='\/glpi\/front\/change.form.php\?id=" . $change->getID() . "[^']+'>/", $output);
$this->assertMatchesRegularExpression("/href='\/front\/change.form.php\?id=" . $change->getID() . "[^']+'>/", $output);

// login as tech to check if the change validation is not shown
$this->login('tech', 'tech');
Expand Down
4 changes: 2 additions & 2 deletions phpunit/functional/CommonDBTMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ public function testCheckUnicity()
'uuid' => '76873749-0813-482f-ac20-eb7102ed3367',
]));

$err_msg = 'Impossible record for UUID = 76873749-0813-482f-ac20-eb7102ed3367<br>Other item exist<br>[<a href="/glpi/front/computer.form.php?id=' . $computers_id1 . '" title="testCheckUnicity01">testCheckUnicity01</a> - ID: ' . $computers_id1 . ' - Serial number: - Entity: Root entity &gt; _test_root_entity]';
$err_msg = 'Impossible record for UUID = 76873749-0813-482f-ac20-eb7102ed3367<br>Other item exist<br>[<a href="/front/computer.form.php?id=' . $computers_id1 . '" title="testCheckUnicity01">testCheckUnicity01</a> - ID: ' . $computers_id1 . ' - Serial number: - Entity: Root entity &gt; _test_root_entity]';
$this->hasSessionMessages(1, [$err_msg]);

$this->assertFalse($computer->add([
Expand Down Expand Up @@ -1516,7 +1516,7 @@ public function testSkipCheckUnicityWithTemplate()
'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true),
])
);
$err_msg = 'Impossible record for Name = ' . __FUNCTION__ . '01<br>Other item exist<br>[<a href="/glpi/front/computer.form.php?id=' . $computers_id . '" title="' . __FUNCTION__ . '01">' . __FUNCTION__ . '01</a> - ID: ' . $computers_id . ' - Serial number: - Entity: Root entity &gt; _test_root_entity]';
$err_msg = 'Impossible record for Name = ' . __FUNCTION__ . '01<br>Other item exist<br>[<a href="/front/computer.form.php?id=' . $computers_id . '" title="' . __FUNCTION__ . '01">' . __FUNCTION__ . '01</a> - ID: ' . $computers_id . ' - Serial number: - Entity: Root entity &gt; _test_root_entity]';
$this->hasSessionMessages(ERROR, [$err_msg]);

// purge all computer to check if uniqueness is checked against template when creating a new computer
Expand Down
4 changes: 2 additions & 2 deletions phpunit/functional/ComputerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,12 +944,12 @@ public static function formatSessionMessageAfterActionProvider(): iterable
yield [
"C1",
"Test",
'Test: <a href="/glpi/front/computer.form.php?id=CID" title="Computer 1">Computer 1</a>',
'Test: <a href="/front/computer.form.php?id=CID" title="Computer 1">Computer 1</a>',
];
yield [
"C2",
"Test",
'Test: <a href="/glpi/front/computer.form.php?id=CID" title="Computer 2">Computer 2</a>',
'Test: <a href="/front/computer.form.php?id=CID" title="Computer 2">Computer 2</a>',
];

// Test message without link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,12 @@ public function testGetInstance()
// Reset singleton instance
$instance_property->setValue(null, null);

// Define globals needed for getInstance
global $CFG_GLPI;
$original_cfg = $CFG_GLPI ?? [];
$CFG_GLPI['root_doc'] = '/glpi';

// Test that getInstance returns an instance
$instance = ImportMapGenerator::getInstance();
$this->assertInstanceOf(ImportMapGenerator::class, $instance);

// Test that getInstance returns the same instance on subsequent calls
$another_instance = ImportMapGenerator::getInstance();
$this->assertSame($instance, $another_instance);

// Restore original globals
$CFG_GLPI = $original_cfg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class RoutingExtensionTest extends TestCase
{
public static function provideNoRouterPaths(): \Generator
{
yield ['path', 'test', [], '/glpi/test'];
yield ['path', 'foobar', [], '/glpi/foobar'];
yield ['path', 'test', ['foo' => 'bar'], '/glpi/test?foo=bar'];
yield ['path', 'foobar', ['foo' => 'bar'], '/glpi/foobar?foo=bar'];
yield ['url', 'test', [], 'http://localhost:80/test'];
yield ['url', 'foobar', [], 'http://localhost:80/foobar'];
yield ['url', 'test', ['foo' => 'bar'], 'http://localhost:80/test?foo=bar'];
yield ['url', 'foobar', ['foo' => 'bar'], 'http://localhost:80/foobar?foo=bar'];
yield ['path', 'test', [], '/test'];
yield ['path', 'foobar', [], '/foobar'];
yield ['path', 'test', ['foo' => 'bar'], '/test?foo=bar'];
yield ['path', 'foobar', ['foo' => 'bar'], '/foobar?foo=bar'];
yield ['url', 'test', [], 'http://localhost/test'];
yield ['url', 'foobar', [], 'http://localhost/foobar'];
yield ['url', 'test', ['foo' => 'bar'], 'http://localhost/test?foo=bar'];
yield ['url', 'foobar', ['foo' => 'bar'], 'http://localhost/foobar?foo=bar'];
}

#[DataProvider('provideNoRouterPaths')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testGetValues(): void
[
'id' => $changes_id,
'ref' => "#$changes_id",
'link' => '<a href="/glpi/front/change.form.php?id=' . $changes_id . '" title="change_testGetValues">change_testGetValues</a>',
'link' => '<a href="/front/change.form.php?id=' . $changes_id . '" title="change_testGetValues">change_testGetValues</a>',
'name' => 'change_testGetValues',
'content' => '<p>change_testGetValues content</p>',
'date' => '2021-07-19 17:11:28',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testGetValues(): void
'id' => $kbi_id,
'name' => 'kbi_testGetValues',
'answer' => "test answer' \"testGetValues",
'link' => '<a href="/glpi/front/knowbaseitem.form.php?id=' . $kbi_id . '" title="kbi_testGetValues">kbi_testGetValues</a>',
'link' => '<a href="/front/knowbaseitem.form.php?id=' . $kbi_id . '" title="kbi_testGetValues">kbi_testGetValues</a>',
],
$values
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testGetValues(): void
[
'id' => $problems_id,
'ref' => "#$problems_id",
'link' => "<a href=\"/glpi/front/problem.form.php?id=$problems_id\" title=\"problem_testGetValues\">problem_testGetValues</a>",
'link' => "<a href=\"/front/problem.form.php?id=$problems_id\" title=\"problem_testGetValues\">problem_testGetValues</a>",
'name' => 'problem_testGetValues',
'content' => '<p>problem_testGetValues content</p>',
'date' => '2021-07-19 17:11:28',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testGetValues(): void
[
'id' => $tickets_id,
'ref' => "#$tickets_id",
'link' => "<a href=\"/glpi/front/ticket.form.php?id=$tickets_id\" title=\"ticket_testGetValues\">ticket_testGetValues</a>",
'link' => "<a href=\"/front/ticket.form.php?id=$tickets_id\" title=\"ticket_testGetValues\">ticket_testGetValues</a>",
'name' => 'ticket_testGetValues',
'content' => '<p>ticket_testGetValues content</p>',
'date' => $now,
Expand Down Expand Up @@ -261,7 +261,7 @@ public function testGetValues(): void
'id' => getItemByTypeName(\KnowbaseItem::class, '_knowbaseitem01', true),
'name' => '_knowbaseitem01',
'answer' => "Answer for Knowledge base entry _knowbaseitem01 apple juice turnover",
'link' => "<a href=\"/glpi/front/knowbaseitem.form.php?id=1\" title=\"_knowbaseitem01\">_knowbaseitem01</a>",
'link' => "<a href=\"/front/knowbaseitem.form.php?id=1\" title=\"_knowbaseitem01\">_knowbaseitem01</a>",
],
],
'assets' => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ protected function testHandleRequestProvider(): iterable
],
'expected_status' => 200,
'expected_body' => [
'redirect' => "/glpi/front/form/form.php",
'redirect' => "/front/form/form.php",
],
];
// We can't test the "Failed to purge item" response because it doesn't
Expand Down
2 changes: 1 addition & 1 deletion phpunit/functional/Glpi/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function testPrepareInputForUpdate(): void
$this->assertCount(1, $form->getFormComments());

$id = $form->getID();
$this->hasSessionMessages(INFO, ['Item successfully updated: <a href="/glpi/front/form/form.form.php?id=' . $id . '" title="Form with first section">Form with first section</a>']);
$this->hasSessionMessages(INFO, ['Item successfully updated: <a href="/front/form/form.form.php?id=' . $id . '" title="Form with first section">Form with first section</a>']);
}

public function testGetSectionsOnEmptyForm(): void
Expand Down
6 changes: 3 additions & 3 deletions phpunit/functional/Glpi/Helpdesk/Tile/TilesManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testTilesCanBeAddedToHelpdeskProfiles(): void
$this->assertEquals("FAQ", $second_tile->getTitle());
$this->assertEquals("Link to the FAQ", $second_tile->getDescription());
$this->assertEquals("browse-kb", $second_tile->getIllustration());
$this->assertEquals("/glpi/front/helpdesk.faq.php", $second_tile->getTileUrl());
$this->assertEquals("/front/helpdesk.faq.php", $second_tile->getTileUrl());
}

public function testTilesCantBeAddedToCentralProfiles(): void
Expand Down Expand Up @@ -313,7 +313,7 @@ public function testTilesAreOrderedByRanks(): void
$this->assertEquals("FAQ", $third_tile->getTitle());
$this->assertEquals("Link to the FAQ", $third_tile->getDescription());
$this->assertEquals("browse-kb", $third_tile->getIllustration());
$this->assertEquals("/glpi/front/helpdesk.faq.php", $third_tile->getTileUrl());
$this->assertEquals("/front/helpdesk.faq.php", $third_tile->getTileUrl());
}

public function testTilesOrderCanBeSet(): void
Expand Down Expand Up @@ -372,7 +372,7 @@ public function testTilesOrderCanBeSet(): void
$this->assertEquals("FAQ", $third_tile->getTitle());
$this->assertEquals("Link to the FAQ", $third_tile->getDescription());
$this->assertEquals("browse-kb", $third_tile->getIllustration());
$this->assertEquals("/glpi/front/helpdesk.faq.php", $third_tile->getTileUrl());
$this->assertEquals("/front/helpdesk.faq.php", $third_tile->getTileUrl());
}

public function testDeleteTile(): void
Expand Down
15 changes: 7 additions & 8 deletions phpunit/functional/Glpi/RichText/RichTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function testGetSafeHtmlDoChangeDocPath()
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
$bkp_root_doc = $CFG_GLPI['root_doc'];

// Images path should be corrected when root doc changed
// see #15113

Expand Down Expand Up @@ -435,11 +435,13 @@ public function testGetSafeHtmlDoChangeDocPath()
);
}
}
$CFG_GLPI['root_doc'] = $bkp_root_doc;
}

public static function getTextFromHtmlProvider(): iterable
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

// Handling of basic content
yield [
'content' => '<p>Some HTML text</p>',
Expand Down Expand Up @@ -493,7 +495,7 @@ public static function getTextFromHtmlProvider(): iterable
<li>el 2</li>
</ul>
<div>
<a href="/glpi/front/computer.form.php?id=150"><img src="/path/to/img" alt="an image" /></a>
<a href="/front/computer.form.php?id=150"><img src="/path/to/img" alt="an image" /></a>
Should I yell <strong>for the important words</strong>?
</div>
HTML;
Expand Down Expand Up @@ -525,7 +527,6 @@ public static function getTextFromHtmlProvider(): iterable
];

// Text with presentation from complex HTML
$base_url = GLPI_URI;
yield [
'content' => $content,
'keep_presentation' => true,
Expand All @@ -541,12 +542,11 @@ public static function getTextFromHtmlProvider(): iterable
* el 1
* el 2

[an image] [{$base_url}/glpi/front/computer.form.php?id=150] Should I yell FOR THE IMPORTANT WORDS?
[an image] [{$CFG_GLPI['url_base']}/front/computer.form.php?id=150] Should I yell FOR THE IMPORTANT WORDS?
PLAINTEXT,
];

// Text with presentation from complex HTML (compact mode)
$base_url = GLPI_URI;
yield [
'content' => $content,
'keep_presentation' => true,
Expand All @@ -567,7 +567,6 @@ public static function getTextFromHtmlProvider(): iterable
];

// Text with presentation from complex HTML (with no case transformation)
$base_url = GLPI_URI;
yield [
'content' => $content,
'keep_presentation' => true,
Expand Down Expand Up @@ -625,7 +624,7 @@ public static function isRichTextHtmlContentProvider(): iterable

yield [
'content' => <<<HTML
<a href="/glpi/">GLPI</a>
<a href="/">GLPI</a>
HTML,
'expected_result' => true,
];
Expand Down
8 changes: 3 additions & 5 deletions phpunit/functional/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,18 +712,16 @@ public function testDisplayBackLink()
/** @var array $CFG_GLPI */
global $CFG_GLPI;

$CFG_GLPI['url_base'] = 'http://localhost/glpi';

ob_start();
\Html::displayBackLink();
$output = ob_get_clean();
$this->assertSame('<a href="http://localhost/glpi">Back</a>', $output);
$this->assertSame('<a href="http://localhost">Back</a>', $output);

$_SERVER['HTTP_REFERER'] = 'http://localhost/glpi/originalpage.html';
$_SERVER['HTTP_REFERER'] = 'http://localhost/originalpage.html';
ob_start();
\Html::displayBackLink();
$output = ob_get_clean();
$this->assertSame('<a href="http://localhost/glpi/originalpage.html">Back</a>', $output);
$this->assertSame('<a href="http://localhost/originalpage.html">Back</a>', $output);
$_SERVER['HTTP_REFERER'] = ''; // reset referer to prevent having this var in test loop mode
}

Expand Down
4 changes: 1 addition & 3 deletions phpunit/functional/NotificationEventAjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ public function testRaise()
//no ajax notification configured per default
$this->assertCount(1, $queue);

$GLPI_URI = GLPI_URI;

$data = array_pop($queue);
unset($data['id']);
unset($data['create_time']);
Expand Down Expand Up @@ -181,7 +179,7 @@ public function testRaise()
'body_html' => null,
'body_text' => <<<TEXT

URL : {$GLPI_URI}/index.php?redirect=ticket_{$ticket->getID()}
URL : {$CFG_GLPI['url_base']}/index.php?redirect=ticket_{$ticket->getID()}

Ticket: Description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testAddDataForTemplate()
'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true),
'users_id' => \Session::getLoginUserID(),
'itemtype' => 'Computer',
'url' => 'http://glpi.localhost/front/computer.php?is_deleted=0&as_map=0&browse=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=view&criteria%5B0%5D%5Bsearchtype%5D=contains&criteria%5B0%5D%5Bvalue%5D=test&itemtype=Computer&start=0&_glpi_csrf_token=735e344f1f47545e5bea56aa4e75c15ca45d3628307937c3bf185e0a3bca39db&sort%5B%5D=1&order%5B%5D=ASC',
'url' => 'http://localhost/front/computer.php?is_deleted=0&as_map=0&browse=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=view&criteria%5B0%5D%5Bsearchtype%5D=contains&criteria%5B0%5D%5Bvalue%5D=test&itemtype=Computer&start=0&_glpi_csrf_token=735e344f1f47545e5bea56aa4e75c15ca45d3628307937c3bf185e0a3bca39db&sort%5B%5D=1&order%5B%5D=ASC',
]);
$this->assertGreaterThan(0, $saved_searches_id);

Expand Down
5 changes: 4 additions & 1 deletion phpunit/functional/NotificationTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public function testClone()

public static function linksProvider(): iterable
{
$base_url = GLPI_URI;
/** @var array $CFG_GLPI */
global $CFG_GLPI;

$base_url = $CFG_GLPI['url_base'];

yield [
'content' => <<<HTML
Expand Down
Loading