Skip to content

Commit

Permalink
Ability to remove trees in the backoffice
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdemooij9 authored and nul800sebastiaan committed Oct 12, 2021
1 parent d222972 commit 04f53b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Linq;
using NUnit.Framework;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.BackOffice.Trees;

namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.CollectionBuilders
{
public class TreeCollectionBuilderTests
{
[Test]
public void Adding_Tree_To_Collection_Builder()
{
var collectionBuilder = new TreeCollectionBuilder();
var treeDefinition = new Tree(0, "test", "test", "test", "test", TreeUse.Main, typeof(LanguageTreeController), false);

collectionBuilder.AddTree(treeDefinition);
var collection = collectionBuilder.CreateCollection(null);

Assert.AreEqual(1, collection.Count);
Assert.AreEqual(treeDefinition, collection.FirstOrDefault());
}

[Test]
public void Remove_Tree_From_Collection_Builder()
{
var collectionBuilder = new TreeCollectionBuilder();
var treeDefinition = new Tree(0, "test", "test", "test", "test", TreeUse.Main, typeof(LanguageTreeController), false);

collectionBuilder.AddTree(treeDefinition);
collectionBuilder.RemoveTreeController<LanguageTreeController>();
var collection = collectionBuilder.CreateCollection(null);

Assert.AreEqual(0, collection.Count);
}
}
}
12 changes: 12 additions & 0 deletions src/Umbraco.Web.BackOffice/Trees/TreeCollectionBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Trees;
Expand Down Expand Up @@ -56,5 +57,16 @@ public void AddTreeControllers(IEnumerable<Type> controllerTypes)
foreach (var controllerType in controllerTypes)
AddTreeController(controllerType);
}

public void RemoveTreeController<T>() => RemoveTreeController(typeof(T));

public void RemoveTreeController(Type type)
{
var tree = _trees.FirstOrDefault(it => it.TreeControllerType == type);
if (tree != null)
{
_trees.Remove(tree);
}
}
}
}

0 comments on commit 04f53b7

Please sign in to comment.