@@ -1351,6 +1351,116 @@ public function it_doesnt_localize_when_select_across_sites_setting_is_enabled()
13511351 $ this ->assertEquals ('<a href="http://localhost/fr/blog/one-fr">The One</a> ' , $ augmented );
13521352 }
13531353
1354+ #[Test]
1355+ public function it_preserves_query_params_on_entry_links ()
1356+ {
1357+ tap (Facades \Collection::make ('blog ' )->routes ('blog/{slug} ' ))->save ();
1358+ EntryFactory::collection ('blog ' )->id ('123 ' )->slug ('my-post ' )->data (['title ' => 'My Post ' ])->create ();
1359+
1360+ $ field = (new Bard )->setField (new Field ('test ' , ['type ' => 'bard ' ]));
1361+
1362+ $ augmented = $ field ->augment ([
1363+ ['type ' => 'text ' , 'marks ' => [['type ' => 'link ' , 'attrs ' => ['href ' => 'statamic://entry::123?foo=bar ' ]]], 'text ' => 'Link ' ],
1364+ ]);
1365+
1366+ $ this ->assertEquals ('<a href="/blog/my-post?foo=bar">Link</a> ' , $ augmented );
1367+ }
1368+
1369+ #[Test]
1370+ public function it_preserves_anchors_on_entry_links ()
1371+ {
1372+ tap (Facades \Collection::make ('blog ' )->routes ('blog/{slug} ' ))->save ();
1373+ EntryFactory::collection ('blog ' )->id ('123 ' )->slug ('my-post ' )->data (['title ' => 'My Post ' ])->create ();
1374+
1375+ $ field = (new Bard )->setField (new Field ('test ' , ['type ' => 'bard ' ]));
1376+
1377+ $ augmented = $ field ->augment ([
1378+ ['type ' => 'text ' , 'marks ' => [['type ' => 'link ' , 'attrs ' => ['href ' => 'statamic://entry::123#section ' ]]], 'text ' => 'Link ' ],
1379+ ]);
1380+
1381+ $ this ->assertEquals ('<a href="/blog/my-post#section">Link</a> ' , $ augmented );
1382+ }
1383+
1384+ #[Test]
1385+ public function it_preserves_query_params_and_anchors_on_entry_links ()
1386+ {
1387+ tap (Facades \Collection::make ('blog ' )->routes ('blog/{slug} ' ))->save ();
1388+ EntryFactory::collection ('blog ' )->id ('123 ' )->slug ('my-post ' )->data (['title ' => 'My Post ' ])->create ();
1389+
1390+ $ field = (new Bard )->setField (new Field ('test ' , ['type ' => 'bard ' ]));
1391+
1392+ $ augmented = $ field ->augment ([
1393+ ['type ' => 'text ' , 'marks ' => [['type ' => 'link ' , 'attrs ' => ['href ' => 'statamic://entry::123?foo=bar#section ' ]]], 'text ' => 'Link ' ],
1394+ ]);
1395+
1396+ $ this ->assertEquals ('<a href="/blog/my-post?foo=bar#section">Link</a> ' , $ augmented );
1397+ }
1398+
1399+ #[Test]
1400+ public function it_preserves_appends_on_localized_entry_links ()
1401+ {
1402+ $ this ->setSites ([
1403+ 'en ' => ['url ' => 'http://localhost/ ' , 'locale ' => 'en ' ],
1404+ 'fr ' => ['url ' => 'http://localhost/fr/ ' , 'locale ' => 'fr ' ],
1405+ ]);
1406+
1407+ Facades \Site::setCurrent ('fr ' );
1408+
1409+ tap (Facades \Collection::make ('blog ' )->routes ('blog/{slug} ' ))->sites (['en ' , 'fr ' ])->save ();
1410+
1411+ EntryFactory::id ('parent ' )->collection ('blog ' )->slug ('theparent ' )->id (123 )->locale ('en ' )->create ();
1412+ EntryFactory::id ('123-fr ' )->origin ('123 ' )->locale ('fr ' )->collection ('blog ' )->slug ('one-fr ' )->data (['title ' => 'Le One ' ])->create ();
1413+
1414+ $ field = (new Bard )->setField (new Field ('test ' , array_merge (['type ' => 'bard ' ], ['select_across_sites ' => false ])));
1415+
1416+ $ augmented = $ field ->augment ([
1417+ ['type ' => 'text ' , 'marks ' => [['type ' => 'link ' , 'attrs ' => ['href ' => 'statamic://entry::123-fr?foo=bar#section ' ]]], 'text ' => 'The One ' ],
1418+ ]);
1419+
1420+ $ this ->assertEquals ('<a href="/fr/blog/one-fr?foo=bar#section">The One</a> ' , $ augmented );
1421+ }
1422+
1423+ #[Test]
1424+ public function it_preserves_appends_on_entry_links_with_select_across_sites ()
1425+ {
1426+ $ this ->setSites ([
1427+ 'en ' => ['url ' => 'http://localhost/ ' , 'locale ' => 'en ' ],
1428+ 'fr ' => ['url ' => 'http://localhost/fr/ ' , 'locale ' => 'fr ' ],
1429+ ]);
1430+
1431+ Facades \Site::setCurrent ('en ' );
1432+
1433+ tap (Facades \Collection::make ('blog ' )->routes ('blog/{slug} ' ))->sites (['en ' , 'fr ' ])->save ();
1434+
1435+ EntryFactory::id ('parent ' )->collection ('blog ' )->slug ('theparent ' )->id (123 )->locale ('en ' )->create ();
1436+ EntryFactory::id ('123-fr ' )->origin ('123 ' )->locale ('fr ' )->collection ('blog ' )->slug ('one-fr ' )->data (['title ' => 'Le One ' ])->create ();
1437+
1438+ $ field = (new Bard )->setField (new Field ('test ' , array_merge (['type ' => 'bard ' ], ['select_across_sites ' => true ])));
1439+
1440+ $ augmented = $ field ->augment ([
1441+ ['type ' => 'text ' , 'marks ' => [['type ' => 'link ' , 'attrs ' => ['href ' => 'statamic://entry::123-fr?foo=bar#section ' ]]], 'text ' => 'The One ' ],
1442+ ]);
1443+
1444+ $ this ->assertEquals ('<a href="http://localhost/fr/blog/one-fr?foo=bar#section">The One</a> ' , $ augmented );
1445+ }
1446+
1447+ #[Test]
1448+ public function it_gets_link_data_with_appends ()
1449+ {
1450+ tap (Facades \Collection::make ('pages ' )->routes ('/{slug} ' ))->save ();
1451+ EntryFactory::collection ('pages ' )->id ('1 ' )->slug ('about ' )->data (['title ' => 'About ' ])->create ();
1452+
1453+ $ bard = $ this ->bard (['save_html ' => true , 'sets ' => null ]);
1454+
1455+ $ html = '<p><a href="statamic://entry::1?foo=bar#section">Link with appends</a></p> ' ;
1456+
1457+ $ prosemirror = (new Augmentor ($ this ))->renderHtmlToProsemirror ($ html )['content ' ];
1458+
1459+ $ this ->assertEquals ([
1460+ 'entry::1 ' => ['title ' => 'About ' , 'permalink ' => 'http://localhost/about ' ],
1461+ ], $ bard ->getLinkData ($ prosemirror ));
1462+ }
1463+
13541464 private function bard ($ config = [])
13551465 {
13561466 return (new Bard )->setField (new Field ('test ' , array_merge (['type ' => 'bard ' , 'sets ' => ['one ' => []]], $ config )));
0 commit comments