Skip to content
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

Item.Links.GetValidLinks only returns the item template. #171

Open
solrobson opened this issue Feb 21, 2017 · 1 comment
Open

Item.Links.GetValidLinks only returns the item template. #171

solrobson opened this issue Feb 21, 2017 · 1 comment

Comments

@solrobson
Copy link

In the code below, only the template of the item is returned when calling articles.Links.GetValidLinks() or source.Links.GetValidLinks(). I've tried creating a hierarchy and using the LinkDatabaseSwitcher.

public void TestHierarchy()
{
using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
{
new Sitecore.FakeDb.DbItem("Articles")
{
new Sitecore.FakeDb.DbItem("Getting Started"),
new Sitecore.FakeDb.DbItem("Troubleshooting")
}
})
{
Sitecore.Data.Items.Item articles =
db.GetItem("/sitecore/content/Articles");

	**var links = articles.Links.GetValidLinks();**
	Assert.IsTrue(links.Any());
}

}

public void HowToWorkWithLinkDatabase()
{
// arrange your database and items
Sitecore.Data.ID sourceId = Sitecore.Data.ID.NewID;
Sitecore.Data.ID aliasId = Sitecore.Data.ID.NewID;
Sitecore.Data.ID linkedItemId = Sitecore.Data.ID.NewID;

using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
{
	new Sitecore.FakeDb.DbItem("source", sourceId),
	new Sitecore.FakeDb.DbItem("clone"),
	new Sitecore.FakeDb.DbItem("alias", aliasId, Sitecore.TemplateIDs.Alias)
	{
		new Sitecore.FakeDb.DbField("Linked item", linkedItemId)
	}
})
{
	// arrange desired LinkDatabase behavior
	var behavior = Substitute.For<Sitecore.Links.LinkDatabase>();

	Sitecore.Data.Items.Item source = db.GetItem("/sitecore/content/source");
	Sitecore.Data.Items.Item alias = db.GetItem("/sitecore/content/alias");
	Sitecore.Data.Items.Item clone = db.GetItem("/sitecore/content/clone");

	string sourcePath = source.Paths.FullPath;
	behavior.GetReferrers(source).Returns(new[]
	{
		new Sitecore.Links.ItemLink(alias, linkedItemId, source, sourcePath),
		new Sitecore.Links.ItemLink(clone, Sitecore.FieldIDs.Source, source, sourcePath)
	});
	

	using (new Sitecore.FakeDb.Links.LinkDatabaseSwitcher(behavior))
	{
		**var sourceLinks = source.Links.GetValidLinks();**
	}
}

}

@sshushliapin
Copy link
Owner

What would you expect to be returned? Please provide a Minimal, Complete, and Verifiable example describing your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants