@@ -601,4 +601,67 @@ public function testFavoriteShareIsRenamedCorrectly() {
601601 $ this ->assertContains ($ newCategoryName , $ shareNames );
602602 $ this ->assertNotContains ($ categoryName , $ shareNames );
603603 }
604+
605+ public function testAddMultipleSharedCategoriesToMap () {
606+ // Create a custom map folder for testing
607+ $ this ->mapFolder = $ this ->createMapFolder ();
608+ $ targetMapId = $ this ->mapFolder ->getId ();
609+
610+ // Create two different categories with favorites
611+ $ categoryName1 = 'testcat1_ ' . uniqid ();
612+ $ categoryName2 = 'testcat2_ ' . uniqid ();
613+
614+ // Add favorites to both categories
615+ $ id1 = $ this ->favoritesController
616+ ->addFavorite ('Test Favorite 1 ' , 10.1 , 20.1 , $ categoryName1 , 'Comment 1 ' , null )
617+ ->getData ()['id ' ];
618+
619+ $ id2 = $ this ->favoritesController
620+ ->addFavorite ('Test Favorite 2 ' , 10.2 , 20.2 , $ categoryName2 , 'Comment 2 ' , null )
621+ ->getData ()['id ' ];
622+
623+ // Share both categories
624+ $ shareResponse1 = $ this ->favoritesController ->shareCategory ($ categoryName1 );
625+ $ shareResponse2 = $ this ->favoritesController ->shareCategory ($ categoryName2 );
626+
627+ $ this ->assertEquals (200 , $ shareResponse1 ->getStatus ());
628+ $ this ->assertEquals (200 , $ shareResponse2 ->getStatus ());
629+
630+ // Try to add both shared categories to the same custom map
631+ // This should work now that we fixed the bug
632+ $ addResponse1 = $ this ->favoritesController ->addShareCategoryToMap ($ categoryName1 , $ targetMapId );
633+ $ this ->assertEquals (200 , $ addResponse1 ->getStatus ());
634+ $ this ->assertEquals ('Done ' , $ addResponse1 ->getData ());
635+
636+ // The second addition should NOT fail (this was the bug)
637+ $ addResponse2 = $ this ->favoritesController ->addShareCategoryToMap ($ categoryName2 , $ targetMapId );
638+ $ this ->assertEquals (200 , $ addResponse2 ->getStatus ());
639+ $ this ->assertEquals ('Done ' , $ addResponse2 ->getData ());
640+
641+ // Verify that the .favorite_shares.json file contains both categories
642+ $ sharesFile = $ this ->mapFolder ->get ('.favorite_shares.json ' );
643+ $ sharesData = json_decode ($ sharesFile ->getContent (), true );
644+ $ this ->assertEquals (2 , count ($ sharesData ));
645+
646+ // Verify the tokens are different and correct categories are present
647+ $ categoryTokens = [];
648+ foreach ($ sharesData as $ share ) {
649+ $ categoryTokens [$ share ['category ' ]] = $ share ['token ' ];
650+ }
651+
652+ $ this ->assertArrayHasKey ($ categoryName1 , $ categoryTokens );
653+ $ this ->assertArrayHasKey ($ categoryName2 , $ categoryTokens );
654+ $ this ->assertNotEquals ($ categoryTokens [$ categoryName1 ], $ categoryTokens [$ categoryName2 ]);
655+
656+ // Test adding the same category again should return "Share was already on map"
657+ $ addResponse3 = $ this ->favoritesController ->addShareCategoryToMap ($ categoryName1 , $ targetMapId );
658+ $ this ->assertEquals (200 , $ addResponse3 ->getStatus ());
659+ $ this ->assertEquals ('Share was already on map ' , $ addResponse3 ->getData ());
660+
661+ // Clean up
662+ $ this ->favoritesController ->deleteFavorite ($ id1 );
663+ $ this ->favoritesController ->deleteFavorite ($ id2 );
664+ $ this ->favoritesController ->unShareCategory ($ categoryName1 );
665+ $ this ->favoritesController ->unShareCategory ($ categoryName2 );
666+ }
604667}
0 commit comments