public void Save_WritesItem_WhenItemIsRoot_AndTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); Assert.True(File.Exists(Path.Combine(testTree.PhysicalRootPath, "sitecore.yml"))); } }
public void Save_WritesItem_WhenItemIsNested_AndTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates")) { testTree.CreateTestTree("/sitecore/templates/hello"); Assert.True(File.Exists(Path.Combine(testTree.PhysicalRootPath, "templates", "hello.yml"))); } }
public void GetRootItem_ReturnsExpectedItem_WhenTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates/User Defined")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "User Defined"); } }
public void GetRootItem_ReturnsExpectedItem_WhenNameHasInvalidChars() { using (var testTree = new TestSfsTree("/<h\\tml>")) { testTree.CreateTestTree("/<h\\tml>"); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "<h\\tml>"); } }
public void GetRootItem_ReturnsExpectedItem_WhenTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "sitecore"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenRootPathIsRequested_AndTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); var root = testTree.GetItemsByPath("/sitecore").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "sitecore"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetItemsByPath("/sitecore/templates/User Defined").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "User Defined"); } }
public void GetItemById_ResolvesItem_WhenItemIsRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); var root = testTree.GetRootItem(); var byId = testTree.GetItemById(root.Id); Assert.NotNull(byId); Assert.Equal(root.Id, byId.Id); } }
public void Remove_DeletesItem_WhenItemHasChildren() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/content/foo/bar/baz/boing"); var item = testTree.GetItemsByPath("/sitecore/content").First(); testTree.Remove(item); Assert.Empty(Directory.GetFileSystemEntries(Path.GetDirectoryName(item.SerializedItemId))); Assert.Empty(testTree.GetItemsByPath("/sitecore/content")); } }
public void GetItemById_ResolvesItem_WhenItemIsChild() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/content/foo"); var item = testTree.GetItemsByPath("/sitecore/content/foo").First(); var byId = testTree.GetItemById(item.Id); Assert.NotNull(byId); Assert.Equal(item.Id, byId.Id); } }
public void Remove_DeletesItem_WhenItemIsRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); testTree.Remove(testTree.GetRootItem()); Assert.Empty(Directory.GetFileSystemEntries(testTree.PhysicalRootPath)); var root = testTree.GetRootItem(); Assert.Null(root); } }
public void GetChildren_ReturnsExpectedItem_WhenRootPathIsParent_AndTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/templates"); var root = testTree.GetRootItem(); var children = testTree.GetChildren(root).ToArray(); Assert.NotNull(children); Assert.Equal(1, children.Length); Assert.Equal(children[0].Name, "templates"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndTreeIsAtRoot_CaseInsensitive() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/templates/User Defined"); testTree.ClearAllCaches(); var root = testTree.GetItemsByPath("/sitecore/templates/uSer dEfiNed").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "User Defined"); } }
public void Save_WritesItem_WhenPathRequiresLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 10 chars after the root path testTree.MaxPathLengthForTests = 10; testTree.CreateTestTree("/sitecore/content"); var rootItem = testTree.GetRootItem(); var loopedItem = testTree.GetChildren(rootItem).First(); Assert.Equal("/sitecore/content", loopedItem.Path); // loopback path will have root item ID in it Assert.True(loopedItem.SerializedItemId.Contains(rootItem.Id.ToString())); } }
public void GetChildren_ReturnsExpectedItem_WhenRootPathIsParent_AndTreeIsNested_AndCacheIsCleared() { using (var testTree = new TestSfsTree("/sitecore/templates")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetItemsByPath("/sitecore/templates").First(); testTree.ClearAllCaches(); var children = testTree.GetChildren(root).ToArray(); Assert.NotNull(children); Assert.Equal(1, children.Length); Assert.Equal(children[0].Name, "User Defined"); } }
public void Save_WritesItem_WhenPathRequiresChildOfLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = 50; // this tree is long enough to loopback, but the 'hello' is short enough to be a child of the first loopback at 'e' testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/e/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/e/hello").First(); Assert.Equal("/sitecore/content lorem/ipsum dolor/sit amet/e/hello", helloItem.Path); // hello item will have looped id in it Assert.True(helloItem.SerializedItemId.Contains(loopParent.Id.ToString())); } }
public void Save_WritesExpectedItems_WhenItemsWithSameNamePrefixExist() { using (var testTree = new TestSfsTree()) { // longer name first testTree.CreateTestTree("/sitecore/Html Editor Drop Down Button"); // shorter name second - name is unique, but has same prefix as longer testTree.Save("/sitecore/Html Editor Drop Down".AsTestItem(testTree.GetRootItem().Id)); var children = testTree.GetChildren(testTree.GetRootItem()).OrderBy(i => i.SerializedItemId).ToArray(); Assert.Equal(2, children.Length); Assert.Equal("/sitecore/Html Editor Drop Down Button", children[0].Path); Assert.EndsWith("Html Editor Drop Down Button.yml", children[0].SerializedItemId); Assert.Equal(children[1].Path, "/sitecore/Html Editor Drop Down"); Assert.EndsWith("Html Editor Drop Down.yml", children[1].SerializedItemId); } }
public void Save_WritesExpectedItems_WhenItemNameIsTooLong_AndItemsWithSameShortenedNameExist() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; testTree.CreateTestTree("/sitecore/hello hello"); testTree.Save("/sitecore/hello hello hello".AsTestItem(testTree.GetRootItem().Id)); var overlengthItems = testTree.GetChildren(testTree.GetRootItem()).OrderBy(i => i.SerializedItemId).ToArray(); Assert.Equal(2, overlengthItems.Length); Assert.Equal("/sitecore/hello hello", overlengthItems[0].Path); Assert.EndsWith("hello hell.yml", overlengthItems[0].SerializedItemId); Assert.Equal("/sitecore/hello hello hello", overlengthItems[1].Path); Assert.EndsWith("hello hell_" + overlengthItems[1].Id + ".yml", overlengthItems[1].SerializedItemId); } }
public void Remove_DeletesItem_WhenItemHasChildrenInLoopbackDirectory() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = testTree.PhysicalRootPath.Length + 50; // this tree is long enough to loopback, but the 'hello' is short enough to be a child of the first loopback at 'e' testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/e/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/e/hello").First(); testTree.Remove(loopParent); Assert.False(File.Exists(loopParent.SerializedItemId)); Assert.False(Directory.Exists(Path.Combine(testTree.PhysicalRootPath, loopParent.Id.ToString()))); Assert.False(File.Exists(helloItem.SerializedItemId)); } }
public void GetChildren_ReturnsExpectedItems_WhenMultipleSameNamedMatchesExist() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath); // add a second templates item testTree.Save(treePath.AsTestItem(testItem.First().ParentId)); // get the children of the root, which should include the two same named items var results = testTree.GetChildren(testTree.GetRootItem()).ToArray(); Assert.Equal(2, results.Length); Assert.NotEqual(results[0].Id, results[1].Id); Assert.NotEqual(results[0].SerializedItemId, results[1].SerializedItemId); } }
public void Remove_DeletesItem_WhenItemHasChildrenInDoubleLoopbackDirectory() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = testTree.PhysicalRootPath.Length + 50; // this tree is long enough that it will loopback at 'elitr foo bar baz', and that '{id}+/elitr foo bar baz' will make it loopback again on 'h', leaving the final 'hello' a child of the second loopback testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz").First(); var loop2Parent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello").First(); testTree.Remove(loopParent); Assert.False(File.Exists(loop2Parent.SerializedItemId)); Assert.False(Directory.Exists(Path.Combine(testTree.PhysicalRootPath, loop2Parent.Id.ToString()))); Assert.False(File.Exists(helloItem.SerializedItemId)); } }
public void GetChildren_ReturnsExpectedItems_WhenMultipleMatchesExist() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath); // add a second child item testTree.Save("/sitecore/system".AsTestItem(testItem.First().ParentId)); // get the children of the root, which should include the two items var results = testTree.GetChildren(testTree.GetRootItem()).ToArray(); Assert.Equal(2, results.Length); Assert.NotEqual(results[0].Id, results[1].Id); Assert.NotEqual(results[0].SerializedItemId, results[1].SerializedItemId); Assert.True(results.Any(result => result.Name == "templates")); Assert.True(results.Any(result => result.Name == "system")); } }
public void GetItemByPath_GetsExpectedItem_WhenItemNameIsTooLong_AndItemsWithSameShortenedNameExist() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; testTree.CreateTestTree("/sitecore/hello hello"); testTree.Save("/sitecore/hello hello hello".AsTestItem(testTree.GetRootItem().Id)); var overlengthItem = testTree.GetItemsByPath("/sitecore/hello hello").ToArray(); Assert.Equal(1, overlengthItem.Length); Assert.Equal("/sitecore/hello hello", overlengthItem.First().Path); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndNamesContainInvalidPathChars() { using (var testTree = new TestSfsTree("/?hello*")) { testTree.CreateTestTree("/?hello*/%there%"); var root = testTree.GetItemsByPath("/?hello*/%there%").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "%there%"); } }
public void GetChildren_ReturnsExpectedItem_WhenNamesContainInvalidPathChars() { using (var testTree = new TestSfsTree("/<html>")) { testTree.CreateTestTree("/<html>/$head"); var root = testTree.GetRootItem(); var children = testTree.GetChildren(root).ToArray(); Assert.NotNull(children); Assert.Equal(1, children.Length); Assert.Equal(children[0].Name, "$head"); } }
public void GetChildren_ReturnsEmptyEnumerable_WhenNoChildrenExist() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); // get the children of the root, which be empty var results = testTree.GetChildren(testTree.GetRootItem()); Assert.NotNull(results); Assert.Empty(results); } }
public void GetChildren_ReturnsExpectedItems_WhenMultipleMatchesExist_ThroughSeparateParents() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates/User Defined"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath("/sitecore/templates"); var templates1 = testItem.First(); // add a second Templates item var templates2 = "/sitecore/templates".AsTestItem(templates1.ParentId); testTree.Save(templates2); // add a child under the second templates item, giving us '/sitecore/templates/User Defined' under templates1, and '/sitecore/templates/Evil' under templates2 // P.S. don't actually do this in real life. Please? But I'm testing it, because I'm an effing pedant :) testTree.Save("/sitecore/templates/Evil".AsTestItem(templates2.Id)); // get the children of templates1, which should NOT include templates2's child var results = testTree.GetChildren(templates1).ToArray(); Assert.Equal(1, results.Length); Assert.Equal("User Defined", results[0].Name); } }
public void Save_WritesItem_WhenPathRequiresDoubleLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 10 chars after the root path // this also means that double loopback occurs each time because the loopback ID is 35 chars testTree.MaxPathLengthForTests = 10; testTree.CreateTestTree("/sitecore/content/hello"); var rootItem = testTree.GetRootItem(); var loopedItem = testTree.GetChildren(rootItem).First(); var secondLoopedItem = testTree.GetChildren(loopedItem).First(); Assert.Equal("/sitecore/content", loopedItem.Path); // loopback path will have root item ID in it Assert.True(loopedItem.SerializedItemId.Contains(rootItem.Id.ToString())); Assert.Equal("/sitecore/content/hello", secondLoopedItem.Path); // loopback path will have root item ID in it Assert.True(secondLoopedItem.SerializedItemId.Contains(loopedItem.Id.ToString())); } }
public void Save_WritesItem_WhenPathRequiresChildOfDoubleLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = 50; // this tree is long enough that it will loopback at 'elitr foo bar baz', and that '{id}+/elitr foo bar baz' will make it loopback again on 'h', leaving the final 'hello' a child of the second loopback testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello").First(); Assert.Equal("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello", helloItem.Path); // hello item will have looped id in it Assert.True(helloItem.SerializedItemId.Contains(loopParent.Id.ToString())); } }
public void GetChildren_ReturnsExpectedItems_WhenNameTruncationCausesSimilarNames() { using (var testTree = new TestSfsTree()) { testTree.MaxFileNameLengthForTests = 10; const string treePath = "/sitecore/templates"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath).First(); var multilist = "/sitecore/templates/Multilist".AsTestItem(testItem.Id); var multilistWithSearch = "/sitecore/templates/Multilist with Search".AsTestItem(testItem.Id); var multilistChild = "/sitecore/templates/Multilist/Menu".AsTestItem(multilist.Id); var multilistWithSearchChild = "/sitecore/templates/Multilist with Search/Menu".AsTestItem(multilistWithSearch.Id); testTree.Save(multilist); testTree.Save(multilistWithSearch); testTree.Save(multilistChild); testTree.Save(multilistWithSearchChild); // now we'll have "Multilist.yml" and "Multilist .yml" - make sure we get the right children from each // get the children of the root, which should include the two same named items var multilistChildren = testTree.GetChildren(multilist).ToArray(); var multilistWithSearchChildren = testTree.GetChildren(multilistWithSearch).ToArray(); Assert.Equal(1, multilistChildren.Length); Assert.Equal(multilistChild.Id, multilistChildren.First().Id); Assert.Equal(1, multilistWithSearchChildren.Length); Assert.Equal(multilistWithSearchChild.Id, multilistWithSearchChildren.First().Id); } }
public void Save_WritesItem_WhenItemNameIsFullOfInvalidChars() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/%<html>?*"); var rootItem = testTree.GetRootItem(); var charsItem = testTree.GetChildren(rootItem).First(); Assert.Equal("/sitecore/%<html>?*", charsItem.Path); } }
public void Save_WritesItem_WhenItemNameIsTooLong() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; testTree.CreateTestTree("/sitecore/hello hello"); var rootItem = testTree.GetRootItem(); var overlengthItem = testTree.GetChildren(rootItem).First(); Assert.Equal("/sitecore/hello hello", overlengthItem.Path); // name should be truncated Assert.True(overlengthItem.SerializedItemId.EndsWith("hello hell.yml")); } }