more tests
This commit is contained in:
@@ -85,7 +85,8 @@ namespace Umbraco.Examine
|
||||
// return nothing if we're not supporting protected content and it is protected, and we're not supporting unpublished content
|
||||
if (valueSet.Category == IndexTypes.Content
|
||||
&& !SupportProtectedContent
|
||||
&& _publicAccessService.IsProtected(path))
|
||||
//if the service is null we can't look this up so we'll return false
|
||||
&& (_publicAccessService == null || _publicAccessService.IsProtected(path)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Umbraco.Examine
|
||||
/// <summary>
|
||||
/// Performing basic validation of a value set
|
||||
/// </summary>
|
||||
public abstract class ValueSetValidator : IValueSetValidator
|
||||
public class ValueSetValidator : IValueSetValidator
|
||||
{
|
||||
protected ValueSetValidator(
|
||||
public ValueSetValidator(
|
||||
IEnumerable<string> includeItemTypes,
|
||||
IEnumerable<string> excludeItemTypes,
|
||||
IEnumerable<string> includeFields,
|
||||
@@ -22,9 +22,10 @@ namespace Umbraco.Examine
|
||||
ExcludeItemTypes = excludeItemTypes;
|
||||
IncludeFields = includeFields;
|
||||
ExcludeFields = excludeFields;
|
||||
ValidIndexCategories = null;
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<string> ValidIndexCategories { get; }
|
||||
protected virtual IEnumerable<string> ValidIndexCategories { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional inclusion list of content types to index
|
||||
@@ -60,7 +61,7 @@ namespace Umbraco.Examine
|
||||
|
||||
public virtual bool Validate(ValueSet valueSet)
|
||||
{
|
||||
if (!ValidIndexCategories.InvariantContains(valueSet.Category))
|
||||
if (ValidIndexCategories != null && !ValidIndexCategories.InvariantContains(valueSet.Category))
|
||||
return false;
|
||||
|
||||
//check if this document is of a correct type of node type alias
|
||||
|
||||
@@ -61,12 +61,60 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Inclusion_List()
|
||||
public void Inclusion_Field_List()
|
||||
{
|
||||
var validator = new ValueSetValidator(null, null,
|
||||
new[] { "hello", "world" },
|
||||
null);
|
||||
|
||||
var valueSet = new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
|
||||
var result = validator.Validate(valueSet);
|
||||
Assert.IsTrue(result);
|
||||
|
||||
Assert.IsFalse(valueSet.Values.ContainsKey("path"));
|
||||
Assert.IsTrue(valueSet.Values.ContainsKey("hello"));
|
||||
Assert.IsTrue(valueSet.Values.ContainsKey("world"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Exclusion_Field_List()
|
||||
{
|
||||
var validator = new ValueSetValidator(null, null,
|
||||
null,
|
||||
new[] { "hello", "world" });
|
||||
|
||||
var valueSet = new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
|
||||
var result = validator.Validate(valueSet);
|
||||
Assert.IsTrue(result);
|
||||
|
||||
Assert.IsTrue(valueSet.Values.ContainsKey("path"));
|
||||
Assert.IsFalse(valueSet.Values.ContainsKey("hello"));
|
||||
Assert.IsFalse(valueSet.Values.ContainsKey("world"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Inclusion_Exclusion_Field_List()
|
||||
{
|
||||
var validator = new ValueSetValidator(null, null,
|
||||
new[] { "hello", "world" },
|
||||
new[] { "world" });
|
||||
|
||||
var valueSet = new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
|
||||
var result = validator.Validate(valueSet);
|
||||
Assert.IsTrue(result);
|
||||
|
||||
Assert.IsFalse(valueSet.Values.ContainsKey("path"));
|
||||
Assert.IsTrue(valueSet.Values.ContainsKey("hello"));
|
||||
Assert.IsFalse(valueSet.Values.ContainsKey("world"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Inclusion_Type_List()
|
||||
{
|
||||
var validator = new ContentValueSetValidator(true, true, Mock.Of<IPublicAccessService>(),
|
||||
includeItemTypes: new List<string> { "include-content" });
|
||||
|
||||
var result = validator.Validate(new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
|
||||
var result = validator.Validate(new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
|
||||
Assert.IsFalse(result);
|
||||
|
||||
result = validator.Validate(new ValueSet("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
|
||||
@@ -77,7 +125,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Exclusion_List()
|
||||
public void Exclusion_Type_List()
|
||||
{
|
||||
var validator = new ContentValueSetValidator(true, true, Mock.Of<IPublicAccessService>(),
|
||||
excludeItemTypes: new List<string> { "exclude-content" });
|
||||
@@ -93,12 +141,12 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Inclusion_Exclusion_List()
|
||||
public void Inclusion_Exclusion_Type_List()
|
||||
{
|
||||
var validator = new ContentValueSetValidator(true, true, Mock.Of<IPublicAccessService>(),
|
||||
includeItemTypes: new List<string> { "include-content", "exclude-content" },
|
||||
excludeItemTypes: new List<string> { "exclude-content" });
|
||||
|
||||
|
||||
var result = validator.Validate(new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
|
||||
Assert.IsFalse(result);
|
||||
|
||||
@@ -113,9 +161,9 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Recycle_Bin()
|
||||
public void Recycle_Bin_Content()
|
||||
{
|
||||
var validator = new ContentValueSetValidator(false, true, Mock.Of<IPublicAccessService>());
|
||||
var validator = new ContentValueSetValidator(false, false, Mock.Of<IPublicAccessService>());
|
||||
|
||||
var result = validator.Validate(new ValueSet("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555" }));
|
||||
Assert.IsFalse(result);
|
||||
@@ -136,6 +184,22 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Recycle_Bin_Media()
|
||||
{
|
||||
var validator = new ContentValueSetValidator(false, false, Mock.Of<IPublicAccessService>());
|
||||
|
||||
var result = validator.Validate(new ValueSet("555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555" }));
|
||||
Assert.IsFalse(result);
|
||||
|
||||
result = validator.Validate(new ValueSet("555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555,777" }));
|
||||
Assert.IsFalse(result);
|
||||
|
||||
result = validator.Validate(new ValueSet("555", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
|
||||
Assert.IsTrue(result);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Published_Only()
|
||||
{
|
||||
@@ -202,7 +266,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
["title_es-ES"] = "my title",
|
||||
[UmbracoExamineIndexer.PublishedFieldName] = 1
|
||||
});
|
||||
Assert.AreEqual(10, valueSet.Values.Count());
|
||||
Assert.AreEqual(10, valueSet.Values.Count());
|
||||
Assert.IsTrue(valueSet.Values.ContainsKey($"{UmbracoExamineIndexer.PublishedFieldName}_es-es"));
|
||||
Assert.IsTrue(valueSet.Values.ContainsKey("hello_es-ES"));
|
||||
Assert.IsTrue(valueSet.Values.ContainsKey("title_es-ES"));
|
||||
|
||||
Reference in New Issue
Block a user