Skip to content

Commit

Permalink
#5127: Add unit test covering the import of legacy media browser favo…
Browse files Browse the repository at this point in the history
…urites
  • Loading branch information
codereader committed Dec 27, 2020
1 parent 6796334 commit cf98ee4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
52 changes: 51 additions & 1 deletion test/Favourites.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
#include "RadiantTest.h"

#include "ifavourites.h"
#include "iregistry.h"

namespace test
{

using FavouritesTest = RadiantTest;
class FavouritesTest :
public RadiantTest
{
protected:
void copyUserXmlFileToSettingsPath(const std::string& userXmlFile)
{
fs::path sourcePath = _context.getTestResourcePath();
sourcePath /= "settings/";
sourcePath /= userXmlFile;

fs::path targetPath = _context.getSettingsPath();
targetPath /= "user.xml";

fs::remove(targetPath);
fs::copy(sourcePath, targetPath);
}
};

class FavouritesTestWithLegacyFavourites :
public FavouritesTest
{
public:
void SetUp() override
{
copyUserXmlFileToSettingsPath("old_mediabrowser_favourites.xml");

RadiantTest::SetUp();
}
};

TEST_F(FavouritesTest, AddingAndRemovingFavourites)
{
Expand Down Expand Up @@ -75,4 +104,25 @@ TEST_F(FavouritesTest, AddingEmptyPaths)
EXPECT_FALSE(GlobalFavouritesManager().isFavourite(decl::Type::Material, ""));
}

TEST_F(FavouritesTestWithLegacyFavourites, LegacyFavouritesAreImported)
{
// The settings in the old location in the user.xml file should have been imported
EXPECT_FALSE(GlobalFavouritesManager().getFavourites(decl::Type::Material).empty());

// These were present in the legacy nodes
EXPECT_TRUE(GlobalFavouritesManager().isFavourite(decl::Type::Material, "textures/base_trim/gotrustcol1"));
EXPECT_TRUE(GlobalFavouritesManager().isFavourite(decl::Type::Material, "textures/common/caulk"));
EXPECT_TRUE(GlobalFavouritesManager().isFavourite(decl::Type::Material, "textures/common/clip"));
EXPECT_TRUE(GlobalFavouritesManager().isFavourite(decl::Type::Material, "textures/common/monster_clip"));
EXPECT_TRUE(GlobalFavouritesManager().isFavourite(decl::Type::Material, "textures/darkmod/stone/cobblestones/blocks_mixedsize01_dark"));
EXPECT_TRUE(GlobalFavouritesManager().isFavourite(decl::Type::Material, "textures/darkmod/stone/cobblestones/blocks_mixedsize03_mossy"));

// This one is already saved in the new location and should have been loaded too
EXPECT_TRUE(GlobalFavouritesManager().isFavourite(decl::Type::Material, "textures/common/ladder"));

// The old node should have been automatically removed
auto legacyNodes = GlobalRegistry().findXPath("user/ui/mediaBrowser/favourites");
EXPECT_TRUE(legacyNodes.empty());
}

}
20 changes: 20 additions & 0 deletions test/resources/settings/old_mediabrowser_favourites.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<user>
<ui>
<favourites>
<materials>
<favourite value="textures/common/ladder"/>
</materials>
</favourites>
<mediaBrowser>
<favourites>
<favourite value="textures/base_trim/gotrustcol1"/>
<favourite value="textures/common/caulk"/>
<favourite value="textures/common/clip"/>
<favourite value="textures/common/monster_clip"/>
<favourite value="textures/darkmod/stone/cobblestones/blocks_mixedsize01_dark"/>
<favourite value="textures/darkmod/stone/cobblestones/blocks_mixedsize03_mossy"/>
</favourites>
</mediaBrowser>
</ui>
</user>

0 comments on commit cf98ee4

Please sign in to comment.