2020-12-20 08:36:11 +01:00
|
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using NUnit.Framework;
|
2021-02-12 11:49:48 +01:00
|
|
|
|
using Umbraco.Cms.Infrastructure.Macros;
|
2022-05-19 10:25:44 +01:00
|
|
|
|
using Umbraco.Cms.Tests.Common.Extensions;
|
2021-02-10 14:45:44 +01:00
|
|
|
|
using Umbraco.Cms.Tests.Common.TestHelpers;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Macros;
|
|
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
|
public class MacroParserTests
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
[TestCase(@"<p>hello world</p>")]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_No_Macros(string expected)
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = expected;
|
|
|
|
|
|
var result = MacroTagParser.FormatRichTextContentForPersistence(content);
|
|
|
|
|
|
Assert.AreEqual(expected, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Non_AlphaNumeric_Char_In_Alias()
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""My.Map.isCool eh[boy!]"" />
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""My.Map.isCool eh[boy!]"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>My.Map.isCool eh[boy!]</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" />
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_Closing_Tag()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" ></?UMBRACO_MACRO>
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Params()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" />
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Params_When_MacroAlias_Not_First()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO test1=""value1"" test2=""value2"" macroAlias=""Map"" />
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO test1=""value1"" test2=""value2"" macroAlias=""Map"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Params_When_MacroAlias_Is_First()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" />
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Params_When_Multiple_Macros()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO test1=""value1"" test2=""value2"" macroAlias=""Map"" />
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO test1=""value1"" macroAlias=""Map"" test2=""value2"" />
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" />
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO test1=""value1"" test2=""value2"" macroAlias=""Map"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO test1=""value1"" macroAlias=""Map"" test2=""value2"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Multiple_Macros()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Breadcrumb"" />
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""login"" />
|
|
|
|
|
|
<p> </p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(content, new Dictionary<string, string>());
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Breadcrumb"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Breadcrumb</strong></ins></div>
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""login"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>login</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p> </p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Persistence_Multiline_Parameters()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<html>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<body>
|
|
|
|
|
|
<h1>asdfasdf</h1>
|
|
|
|
|
|
<div class='umb-macro-holder mceNonEditable' att1='asdf' att2='asdfasdfasdf' att3=""sdfsdfd"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2
|
|
|
|
|
|
dfdsfds"" /> -->
|
|
|
|
|
|
asdfasdf
|
|
|
|
|
|
asdfas
|
|
|
|
|
|
<span>asdfasdfasdf</span>
|
|
|
|
|
|
<p>asdfasdf</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span>asdfdasf</span>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
asdfsdf
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</body>
|
|
|
|
|
|
</html>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextContentForPersistence(content);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<html>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<body>
|
|
|
|
|
|
<h1>asdfasdf</h1>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2
|
|
|
|
|
|
dfdsfds"" />
|
|
|
|
|
|
<span>asdfdasf</span>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
asdfsdf
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</body>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
</html>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Params_Closing_Tag()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" ></?UMBRACO_MACRO>
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Params_Closing_Tag_And_Content()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" ><img src='blah.jpg'/></?UMBRACO_MACRO>
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2" } });
|
2020-12-20 08:36:11 +01:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Editor_With_Multiline_Parameters()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2
|
|
|
|
|
|
test"" />
|
|
|
|
|
|
<p>asdfasdf</p>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "test2", "value2\r\ntest" } });
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2
|
|
|
|
|
|
test"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2
|
|
|
|
|
|
test"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>Map</strong></ins></div>
|
2020-12-20 08:36:11 +01:00
|
|
|
|
<p>asdfasdf</p>".NoCrLf(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.NoCrLf());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Persistence()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<html>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<body>
|
|
|
|
|
|
<h1>asdfasdf</h1>
|
|
|
|
|
|
<div class='umb-macro-holder mceNonEditable' att1='asdf' att2='asdfasdfasdf' att3=""sdfsdfd"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2"" /> -->
|
|
|
|
|
|
asdfasdf
|
|
|
|
|
|
asdfas
|
|
|
|
|
|
<span>asdfasdfasdf</span>
|
|
|
|
|
|
<p>asdfasdf</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span>asdfdasf</span>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
asdfsdf
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</body>
|
|
|
|
|
|
</html>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextContentForPersistence(content);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<html>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<body>
|
|
|
|
|
|
<h1>asdfasdf</h1>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2"" />
|
|
|
|
|
|
<span>asdfdasf</span>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
asdfsdf
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</body>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
</html>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Persistence_No_Class()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<html>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<body>
|
|
|
|
|
|
<h1>asdfasdf</h1>
|
|
|
|
|
|
<div att1='asdf' att2='asdfasdfasdf' att3=""sdfsdfd"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2"" /> -->
|
|
|
|
|
|
asdfasdf
|
|
|
|
|
|
asdfas
|
|
|
|
|
|
<span>asdfasdfasdf</span>
|
|
|
|
|
|
<p>asdfasdf</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span>asdfdasf</span>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
asdfsdf
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</body>
|
|
|
|
|
|
</html>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextContentForPersistence(content);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<html>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<body>
|
|
|
|
|
|
<h1>asdfasdf</h1>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2"" />
|
|
|
|
|
|
<span>asdfdasf</span>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
asdfsdf
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</body>
|
2022-05-19 10:25:44 +01:00
|
|
|
|
</html>".StripNewLines(),
|
2022-06-21 08:09:38 +02:00
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_Data_For_Persistence_Custom_Single_Entry()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content =
|
|
|
|
|
|
@"<div class=""umb-macro-holder mceNonEditable umb-macro-mce_1""><!-- <?UMBRACO_MACRO macroAlias=""Test"" content=""1089"" textArea=""asdfasdf"" title="""" bool=""0"" number="""" contentType="""" multiContentType="""" multiProperties="""" properties="""" tabs="""" multiTabs="""" /> --><ins>
|
2018-06-29 19:52:40 +02:00
|
|
|
|
<div class=""facts-box"">
|
|
|
|
|
|
<div class=""fatcs-box-header"">
|
|
|
|
|
|
<h3>null</h3>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class=""fatcs-box-body"">1089</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</ins></div>";
|
2022-06-21 08:09:38 +02:00
|
|
|
|
var result = MacroTagParser.FormatRichTextContentForPersistence(content);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<?UMBRACO_MACRO macroAlias=""Test"" content=""1089"" textArea=""asdfasdf"" title="""" bool=""0"" number="""" contentType="""" multiContentType="""" multiProperties="""" properties="""" tabs="""" multiTabs="""" />",
|
|
|
|
|
|
result);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|
2023-02-22 15:21:53 +01:00
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Format_RTE_WhenMacroContainsParameter_EnableInlineMacro_WithValue_1_ItShouldBeInASpan()
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = @"<p>asdfasdf</p>
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<?UMBRACO_MACRO macroAlias=""My.Map.isCool eh[boy!]"" test1=""value1"" enableInlineMacro=""1""/>
|
|
|
|
|
|
<p>asdfasdf</p>";
|
|
|
|
|
|
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(
|
|
|
|
|
|
content,
|
|
|
|
|
|
new Dictionary<string, string> { { "test1", "value1" }, { "enableInlineMacro", "1"} });
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
|
@"<p>asdfasdf</p>
|
|
|
|
|
|
<p>asdfsadf</p>
|
|
|
|
|
|
<span class=""umb-macro-holder inlined-macro mceNonEditable"" test1=""value1"" enableInlineMacro=""1"">
|
|
|
|
|
|
<!-- <?UMBRACO_MACRO macroAlias=""My.Map.isCool eh[boy!]"" test1=""value1"" enableInlineMacro=""1"" /> -->
|
|
|
|
|
|
<ins>Macro alias: <strong>My.Map.isCool eh[boy!]</strong></ins></span>
|
|
|
|
|
|
<p>asdfasdf</p>".StripNewLines(),
|
|
|
|
|
|
result.StripNewLines());
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|