From 0e164bacdbe5e6f4750f09be74e8245da897fa56 Mon Sep 17 00:00:00 2001
From: lpeidro <luis.ruiz@metadrop.net>
Date: Wed, 12 Mar 2025 17:31:09 +0100
Subject: [PATCH 1/7] Issue #3512462: Fix false positive broken-links

---
 src/Repository.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/Repository.php b/src/Repository.php
index 6d3592f..e0a6ce9 100644
--- a/src/Repository.php
+++ b/src/Repository.php
@@ -472,8 +472,11 @@ class Repository implements RepositoryInterface {
     if (empty($prefix)) {
       return $path;
     }
-    $path = ltrim($path, '/');
-    return str_replace($prefix, '', $path);
+    $processed_path = ltrim($path, '/');
+    if (str_starts_with($processed_path, $prefix)) {
+      $path = substr($processed_path, strlen($prefix));
+    }
+    return $path;
   }
 
   /**
-- 
GitLab


From b4306547cca319d9659fb0e58de48e8feda54f15 Mon Sep 17 00:00:00 2001
From: lpeidro <luis.ruiz@metadrop.net>
Date: Wed, 12 Mar 2025 20:19:34 +0100
Subject: [PATCH 2/7] Issue #3512462: Unit tests for false broken links

---
 ...EntityMeshEntityRenderMultilingualTest.php | 49 ++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
index 293ae31..44412e6 100644
--- a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
+++ b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
@@ -3,8 +3,8 @@
 namespace Drupal\Tests\entity_mesh\Kernel;
 
 use Drupal\language\Entity\ContentLanguageSettings;
-use Drupal\node\Entity\Node;
 use Drupal\language\Entity\ConfigurableLanguage;
+use Drupal\node\Entity\Node;
 
 /**
  * Tests the Entity Mesh link auditing with multilingual support.
@@ -20,6 +20,7 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
    */
   protected static $modules = [
     'content_translation',
+    'path_alias',
   ];
 
   /**
@@ -30,6 +31,7 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
 
     // Install the necessary schemas.
     $this->installConfig(['content_translation']);
+    $this->installEntitySchema('path_alias');
 
     // Enable the French language.
     ConfigurableLanguage::createFromLangcode('fr')->save();
@@ -49,6 +51,7 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
     $this->container->get('kernel')->rebuildContainer();
     $this->container->get('router.builder')->rebuild();
     $this->createExampleNodes();
+    $this->createExampleAlias();
 
   }
 
@@ -100,6 +103,8 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
       <p>Internal access denied link invalid translation: <a href="/es/node/1">Internal access denied link invalid translation/a></p>
       <p>Internal access denied link not published translation: <a href="/it/node/1">Internal access denied link not published translation</a></p>
       <p>Internal valid link published translation: <a href="/de/node/1">Internal valid link published translation</a></p>
+      <p>Internal access denied alias link not published translation: <a href="/it/node-1-it-alias">Internal access denied alias link not published translation</a></p>
+      <p>Internal alias link published translation: <a href="/de/node-1-de-alias">Internal valid alias link published translation</a></p>
     ';
 
     // Create a node entity in French.
@@ -115,6 +120,25 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
     $node_en->save();
   }
 
+  /**
+   * Create alias.
+   */
+  protected function createExampleAlias() {
+    $cases = [
+      ['lang' => 'it', 'path' => '/node/1', 'alias' => '/node-1-it-alias'],
+      ['lang' => 'de', 'path' => '/node/1', 'alias' => '/node-1-de-alias'],
+    ];
+    foreach ($cases as $case) {
+      /** @var \Drupal\path_alias\PathAliasInterface $path_alias */
+      $path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')->create([
+        'path' => $case['path'],
+        'alias' => $case['alias'],
+        'langcode' => $case['lang'],
+      ]);
+      $path_alias->save();
+    }
+  }
+
   /**
    * Provides test cases for different types of links.
    */
@@ -182,6 +206,29 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
         'expected_target_entity_id'       => 1,
         'excepted_target_entity_langcode' => 'de',
       ]),
+
+      'Internal valid alias link translation DE' => array_merge($defaults, [
+        'source_entity_id'                => 2,
+        'target_href'                     => '/de/node-1-de-alias',
+        'expected_target_link_type'       => 'internal',
+        'excepted_target_subcategory'     => 'link',
+        'expected_target_entity_type'     => 'node',
+        'expected_target_entity_bundle'   => 'page',
+        'expected_target_entity_id'       => 1,
+        'excepted_target_entity_langcode' => 'de',
+      ]),
+
+      'Internal access denied alias link not published translation IT' => array_merge($defaults, [
+        'source_entity_id'                => 2,
+        'target_href'                     => '/it/node-1-it-alias',
+        'expected_target_link_type'       => 'internal',
+        'excepted_target_subcategory'     => 'access-denied-link',
+        'expected_target_entity_type'     => 'node',
+        'expected_target_entity_bundle'   => 'page',
+        'expected_target_entity_id'       => 1,
+        'excepted_target_entity_langcode' => 'it',
+      ]),
+
     ];
   }
 
-- 
GitLab


From 588c8d73501f68b178f5167a7d610bca3d786e40 Mon Sep 17 00:00:00 2001
From: lpeidro <luis.ruiz@metadrop.net>
Date: Wed, 12 Mar 2025 20:39:25 +0100
Subject: [PATCH 3/7] Issue #3512462: Set Path alias module configuration in
 base test class

---
 tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php | 3 +--
 tests/src/Kernel/EntityMeshTestBase.php                     | 2 ++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
index 44412e6..5202bf5 100644
--- a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
+++ b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
@@ -20,7 +20,6 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
    */
   protected static $modules = [
     'content_translation',
-    'path_alias',
   ];
 
   /**
@@ -31,7 +30,7 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
 
     // Install the necessary schemas.
     $this->installConfig(['content_translation']);
-    $this->installEntitySchema('path_alias');
+
 
     // Enable the French language.
     ConfigurableLanguage::createFromLangcode('fr')->save();
diff --git a/tests/src/Kernel/EntityMeshTestBase.php b/tests/src/Kernel/EntityMeshTestBase.php
index e86ebf0..9a0fbc9 100644
--- a/tests/src/Kernel/EntityMeshTestBase.php
+++ b/tests/src/Kernel/EntityMeshTestBase.php
@@ -31,6 +31,7 @@ abstract class EntityMeshTestBase extends KernelTestBase {
     'text',
     'language',
     'entity_mesh',
+    'path_alias',
   ];
 
   /**
@@ -43,6 +44,7 @@ abstract class EntityMeshTestBase extends KernelTestBase {
     $this->installEntitySchema('configurable_language');
     $this->installEntitySchema('node');
     $this->installEntitySchema('user');
+    $this->installEntitySchema('path_alias');
     $this->installSchema('entity_mesh', ['entity_mesh']);
     $this->installConfig(['filter', 'node', 'system', 'language', 'entity_mesh']);
     $this->installSchema('node', ['node_access']);
-- 
GitLab


From fe9fe2a1bf58a27065e3cfb428190d55bc010ad2 Mon Sep 17 00:00:00 2001
From: lpeidro <luis.ruiz@metadrop.net>
Date: Wed, 12 Mar 2025 20:45:10 +0100
Subject: [PATCH 4/7] Issue #3512462: Fix codding standard

---
 tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
index 5202bf5..a817183 100644
--- a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
+++ b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
@@ -31,7 +31,6 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
     // Install the necessary schemas.
     $this->installConfig(['content_translation']);
 
-
     // Enable the French language.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('it')->save();
-- 
GitLab


From 31a6925505d15d20827e5665242c0fdc9b3fcefc Mon Sep 17 00:00:00 2001
From: lpeidro <luis.ruiz@metadrop.net>
Date: Thu, 13 Mar 2025 16:30:12 +0100
Subject: [PATCH 5/7] Issue #3512462: Fix phpunit tests

---
 tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
index a817183..2724ae1 100644
--- a/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
+++ b/tests/src/Kernel/EntityMeshEntityRenderMultilingualTest.php
@@ -48,9 +48,8 @@ class EntityMeshEntityRenderMultilingualTest extends EntityMeshTestBase {
 
     $this->container->get('kernel')->rebuildContainer();
     $this->container->get('router.builder')->rebuild();
-    $this->createExampleNodes();
     $this->createExampleAlias();
-
+    $this->createExampleNodes();
   }
 
   /**
-- 
GitLab


From 5c9b10639ce118dd3ed2dca1ffbe1c62d5e2a817 Mon Sep 17 00:00:00 2001
From: lpeidro <luis.ruiz@metadrop.net>
Date: Thu, 13 Mar 2025 16:46:06 +0100
Subject: [PATCH 6/7] Issue #3512462: Fix false positive broken-links

---
 src/Repository.php | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/Repository.php b/src/Repository.php
index e0a6ce9..331a911 100644
--- a/src/Repository.php
+++ b/src/Repository.php
@@ -472,10 +472,15 @@ class Repository implements RepositoryInterface {
     if (empty($prefix)) {
       return $path;
     }
+
+    // We ensure 2 structures: /langcode/path or /langcode
     $processed_path = ltrim($path, '/');
-    if (str_starts_with($processed_path, $prefix)) {
+    if (str_starts_with($processed_path, $prefix . '/')) {
       $path = substr($processed_path, strlen($prefix));
+    } elseif ($processed_path === $prefix) {
+      $path = '/';
     }
+
     return $path;
   }
 
-- 
GitLab


From 5087938fd373855bd8b37072d5eba1d2083e062f Mon Sep 17 00:00:00 2001
From: lpeidro <luis.ruiz@metadrop.net>
Date: Thu, 13 Mar 2025 20:08:00 +0100
Subject: [PATCH 7/7] Issue #3512462: Fix codding standard

---
 src/Repository.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/Repository.php b/src/Repository.php
index 331a911..b74c6b0 100644
--- a/src/Repository.php
+++ b/src/Repository.php
@@ -473,11 +473,12 @@ class Repository implements RepositoryInterface {
       return $path;
     }
 
-    // We ensure 2 structures: /langcode/path or /langcode
+    // We ensure 2 structures: /langcode/path or /langcode.
     $processed_path = ltrim($path, '/');
     if (str_starts_with($processed_path, $prefix . '/')) {
       $path = substr($processed_path, strlen($prefix));
-    } elseif ($processed_path === $prefix) {
+    }
+    elseif ($processed_path === $prefix) {
       $path = '/';
     }
 
-- 
GitLab