コード例 #1
0
        public void EntityPropertyAccess_ForPersonAttributeValues_ReturnsCorrectValues()
        {
            var rockContext = new RockContext();

            var testPerson = new PersonService(rockContext).Queryable().First(x => x.NickName == "Ted" && x.LastName == "Decker");

            testPerson.LoadAttributes();

            var values = new LavaDataDictionary {
                { "Person", testPerson }
            };

            var input          = @"
{% for av in Person.AttributeValues %}
    {% if av.ValueFormatted != null and av.ValueFormatted != '' %}
        {{ av.AttributeName }}: {{ av.ValueFormatted }}<br>
    {% endif %}
{% endfor %}
";
            var expectedOutput = @"
 Employer: Rock Solid Church<br>
";

            var options = new LavaTestRenderOptions()
            {
                MergeFields = values, OutputMatchType = LavaTestOutputMatchTypeSpecifier.Contains
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #2
0
ファイル: ScopeTests.cs プロジェクト: SparkDevNetwork/Rock
        public void Scope_LocalVariableWithSameNameAsContainerVariable_ContainerVariableIsReturned()
        {
            var input          = @"
{% execute type:'class' %}
    using Rock;
    using Rock.Data;
    using Rock.Model;
    
    public class MyScript 
    {
        public string Execute() {
            using(RockContext rockContext = new RockContext()){
                var person = new PersonService(rockContext).Get({{ CurrentPerson | Property: 'Id' }});
                
                return person.FullName;
            }
        }
    }
{% endexecute %}
";
            var expectedOutput = @"Admin Admin"; // NOT 'Ted Decker'

            var values = new LavaDataDictionary {
                { "CurrentPerson", TestHelper.GetTestPersonTedDecker() }
            };

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "execute", MergeFields = values
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #3
0
        public void Base64EncodeFilter_WithBinaryFileObjectParameter_ReturnsExpectedEncoding()
        {
            var rockContext = new RockContext();

            var contentChannelItem = new ContentChannelItemService(rockContext)
                                     .Queryable()
                                     .FirstOrDefault(x => x.ContentChannel.Name == "External Website Ads" && x.Title == "SAMPLE: Easter");

            Assert.That.IsNotNull(contentChannelItem, "Required test data not found.");

            var values = new LavaDataDictionary {
                { "Item", contentChannelItem }
            };

            var input = @"
{% assign image = Item | Attribute:'Image','Object' %}
Base64Format: {{ image | Base64Encode }}<br/>
";

            var expectedOutput = @"Base64Format: /9j/4AAQSkZJRgABAQEAAAAAAAD/{moreBase64Data}<br/>";

            var options = new LavaTestRenderOptions()
            {
                MergeFields = values, Wildcards = new List <string> {
                    "{moreBase64Data}"
                }
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #4
0
        public void FilterFollowed_ForEntityCollectionWithFollowedAndUnfollowed_ReturnsOnlyFollowed()
        {
            var values = AddPersonTedDeckerToMergeDictionary();

            var options = new LavaTestRenderOptions {
                EnabledCommands = "rockentity", MergeFields = values
            };

            var template = @"
{%- person where:'Guid == ""<benJonesGuid>"" || Guid == ""<billMarbleGuid>"" || Guid == ""<alishaMarbleGuid>""' iterator:'People' -%}
  {%- assign followedItems = People | AppendFollowing | FilterFollowed | Sort:'FullName' -%}
<ul>
  {%- for item in followedItems -%}
    <li>{{ item.FullName }} - {{ item.IsFollowing }}</li>
  {%- endfor -%}
</ul>
{%- endperson -%}
";

            template = template.Replace("<benJonesGuid>", TestGuids.TestPeople.BenJones)
                       .Replace("<billMarbleGuid>", TestGuids.TestPeople.BillMarble)
                       .Replace("<alishaMarbleGuid>", TestGuids.TestPeople.AlishaMarble);

            // Alisha Marble should be excluded because she is not followed by Ted.
            var expectedOutputs = new List <string>()
            {
                "<li>Ben Jones - true</li>",
                "<li>Bill Marble - true</li>"
            };

            TestHelper.AssertTemplateOutput(expectedOutputs,
                                            template,
                                            options);
        }
コード例 #5
0
        public void ExecuteBlock_ClassType_ReturnsExpectedOutput()
        {
            var input = @"
{% execute type:'class' %}
    using Rock;
    using Rock.Data;
    using Rock.Model;
    
    public class MyScript 
    {
        public string Execute() {
            using(RockContext rockContext = new RockContext()) {
                var person = new PersonService(rockContext).Get(""<PersonGuid>"".AsGuid());
                
                return person.FullName;
            }
        }
    }
{% endexecute %}
";

            input = input.Replace("<PersonGuid>", TestHelper.GetTestPersonTedDecker().Guid);

            var expectedOutput = @"Ted Decker";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "execute"
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #6
0
        public void DotLiquid_FilterRegisteredToDotLiquidFramework_ProducesCorrectResultInLavaLibrary()
        {
            DotLiquid.Template.RegisterFilter(typeof(TestDotLiquidFilter));

            var rockContext = new RockContext();

            var contentChannelItem = new ContentChannelItemService(rockContext)
                                     .Queryable()
                                     .FirstOrDefault(x => x.ContentChannel.Name == "External Website Ads" && x.Title == "SAMPLE: Easter");

            Assert.That.IsNotNull(contentChannelItem, "Required test data not found.");

            var values = new LavaDataDictionary {
                { "Item", contentChannelItem }
            };

            var inputTemplate = @"
{% assign image = Item | Attribute:'Image','Object' %}
{{ image | GetVariableType }}
";

            var expectedOutput = @"BinaryFile";

            var options = new LavaTestRenderOptions {
                MergeFields = values
            };

            TestHelper.AssertTemplateOutput(typeof(RockLiquidEngine), expectedOutput, inputTemplate, options);
        }
コード例 #7
0
        public void VimeoShortcodeTag_DefaultOptions_EmitsCorrectHtml()
        {
            var input = @"
{[ vimeo id:'180467014' ]}
";

            var expectedOutput = @"
<style>
.embed-container { 
    position: relative; 
    padding-bottom: 56.25%; 
    height: 0; 
    overflow: hidden; 
    max-width: 100%; } 
.embed-container iframe, 
.embed-container object, 
.embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
</style>

<div id='id-<<guid>>' style='width:100%;'>
    <div class='embed-container'><iframe src='https://player.vimeo.com/video/180467014?autoplay=0&autoplay=0&loop=0&title=0&byline=0&portrait=0' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>
</div>
";

            var options = new LavaTestRenderOptions()
            {
                Wildcards = new List <string> {
                    "<<guid>>"
                }
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #8
0
        public void AppendFollowing_WhereCurrentUserHasFollowings_ShowsCorrectFollowingStatus()
        {
            var values = AddPersonTedDeckerToMergeDictionary();

            var options = new LavaTestRenderOptions {
                EnabledCommands = "rockentity", MergeFields = values
            };

            var template = @"
{%- person where:'Guid == ""<benJonesGuid>"" || Guid == ""<billMarbleGuid>"" || Guid == ""<alishaMarbleGuid>""' iterator:'People' -%}
  {%- assign followedItems = People | AppendFollowing | Sort:'FullName' -%}
<ul>
  {%- for item in followedItems -%}
    <li>{{ item.FullName }} - {{ item.IsFollowing }}</li>
  {%- endfor -%}
</ul>
{%- endperson -%}
";

            template = template.Replace("<benJonesGuid>", TestGuids.TestPeople.BenJones)
                       .Replace("<billMarbleGuid>", TestGuids.TestPeople.BillMarble)
                       .Replace("<alishaMarbleGuid>", TestGuids.TestPeople.AlishaMarble);

            var expectedOutputs = new List <string>()
            {
                "<li>Alisha Marble - false</li>",
                "<li>Ben Jones - true</li>",
                "<li>Bill Marble - true</li>"
            };

            TestHelper.AssertTemplateOutput(expectedOutputs,
                                            template,
                                            options);
        }
コード例 #9
0
        public void ParallaxShortcode_DefaultOptions_EmitsCorrectHtml()
        {
            var input = @"
{[ parallax image:'http://cdn.wonderfulengineering.com/wp-content/uploads/2014/09/star-wars-wallpaper-4.jpg' contentpadding:'20px' speed:'75' ]}
    <h1>Hello World</h1>
{[ endparallax ]}
";

            var expectedOutput = @"
<div id=``id-<<guid>>`` data-jarallax class=``jarallax`` data-type=``scroll`` data-speed=``1.75`` data-img-position=```` data-object-position=```` data-background-position=```` data-zindex=``2`` data-no-android=```` data-no-ios=``false``>
        <img class=``jarallax-img`` src=``http://cdn.wonderfulengineering.com/wp-content/uploads/2014/09/star-wars-wallpaper-4.jpg`` alt=````>

                    <div class=``parallax-content``>
                <h1>Hello World</h1>
            </div>
            </div>


<style>
#id-<<guid>> {
    /* eventually going to change the height using media queries with mixins using sass, and then include only the classes I want for certain parallaxes */
    min-height: 200px;
    background: transparent;
    position: relative;
    z-index: 0;
}

#id-<<guid>> .jarallax-img {
    position: absolute;
    object-fit: cover;
    /* support for plugin https://github.com/bfred-it/object-fit-images */
    font-family: 'object-fit: cover;';
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

#id-<<guid>> .parallax-content{
    display: inline-block;
    margin: 20px;
    color: #fff;
    text-align: center;
	width: 100%;
}
</style>
";

            expectedOutput = expectedOutput.Replace("``", @"""");

            var options = new LavaTestRenderOptions()
            {
                Wildcards = new List <string> {
                    "<<guid>>"
                }
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #10
0
        public void AppendFollowing_ForPersistedDataset_ShowsCorrectFollowingStatus()
        {
            var template = @"
{% assign followedItems = 'persons' | PersistedDataset | AppendFollowing | Sort:'FullName' %}
<ul>
  {%- for item in followedItems -%}
    <li>{{ item.FullName }} - {{ item.IsFollowing }}</li>
  {%- endfor -%}
</ul>

";

            var outputExpected = @"
<ul><li>Alisha Marble - false</li><li>Ben Jones - true</li><li>Bill Marble - true</li></ul>
";
            var values         = AddPersonTedDeckerToMergeDictionary();

            var options = new LavaTestRenderOptions {
                EnabledCommands = "rockentity", MergeFields = values
            };

            TestHelper.AssertTemplateOutput(outputExpected,
                                            template,
                                            options);
        }
コード例 #11
0
        public void AppendFollowing_DocumentationExample_ProducesExpectedResult()
        {
            var options = new LavaTestRenderOptions {
                EnabledCommands = "rockentity"
            };

            var template       = @"
<p>Entity Command Example</p>
{%- person where:'Id != 1' limit:'3' iterator:'People' -%}
  {%- assign followedItems = People | AppendFollowing -%}
<ul>
  {%- for item in followedItems -%}
    <li>{{ item.FullName }} - {{ item.IsFollowing }}</li>
  {%- endfor -%}
</ul>
{%- endperson -%}
";
            var outputExpected = @"
<p>Entity Command Example</p>
<ul>
<li>Giver Anonymous - false</li>
<li>Ted Decker - false</li>
<li>Cindy Decker - false</li>
</ul>
";

            TestHelper.AssertTemplateOutput(outputExpected,
                                            template,
                                            options);
        }
コード例 #12
0
        public void ExecuteBlock_WithContextValues_ResolvesContextValuesCorrectly()
        {
            var input = @"
{% execute type:'class' %}
    using Rock;
    using Rock.Data;
    using Rock.Model;
    
    public class MyScript 
    {
        public string Execute() {
            using(RockContext rockContext = new RockContext()) {
                var person = new PersonService(rockContext).Get(""{{ Person | Property: 'Guid' }}"".AsGuid());
                
                return person.FullName;
            }
        }
    }
{% endexecute %}
";

            var expectedOutput = @"Ted Decker";

            var context = new LavaDataDictionary();

            context.Add("Person", TestHelper.GetTestPersonTedDecker());

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "execute", MergeFields = context
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #13
0
        public void PersonNotes_WithCurrentPersonHavingNotes_ReturnsNotes()
        {
            var values = AddTestPersonToMergeDictionary(TestGuids.TestPeople.TedDecker.AsGuid());

            var person = values["CurrentPerson"] as Person;

            var options = new LavaTestRenderOptions {
                MergeFields = values
            };

            var template = @"
{% assign notes = CurrentPerson | Notes:'4,5','asc',2 %}
{% for note in notes %}
    <p>{{ note.Text }}</p>
{% endfor %}
";

            var outputExpected = @"
<p>Called Ted and heard that his mother is in the hospital and could use prayer.</p>
<p>Talked to Ted today about starting a new Young Adults ministry</p>
";

            TestHelper.AssertTemplateOutput(outputExpected,
                                            template,
                                            options);
        }
コード例 #14
0
        public void EntityBlock_WithNestedEntityBlock_ProducesExpectedOutput()
        {
            var input = @"
{% note expression:'NoteType.Name == ""Personal Note""' sort:'Id' limit:'3' %}
    {% for note in noteItems %}
        {% case note.NoteType.EntityType.FriendlyName %}
            {% when 'Person' %}
                {% person id:'{{ note.EntityId }}' %}
                    [{{person.FullName}}]: {{note.Text}}<br>
                {% endperson %}
        {% endcase %}
    {% endfor %}
{% endnote %}
";

            var expectedOutput = @"
[Ted Decker]: Talked to Ted today about starting a new Young Adults ministry<br>
[Ted Decker]: Called Ted and heard that his mother is in the hospital and could use prayer.<br>
[Daniel Peak]: Called Daniel to see if he would be interested in joining our team as the Communications Director.<br>
";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "RockEntity"
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #15
0
        public void CacheBlock_InsideNewScope_HasAccessToOuterVariable()
        {
            var input = @"
{% if 1 == 1 %}
    {% assign color = 'blue' %}
    Color 1: {{ color }}

    {% cache key:'fav-color' duration:'0' %}
        Color 2: {{ color }}
        {% assign color = 'red' %}
        Color 3: {{color }}
    {% endcache %}

    Color 4: {{ color }}
{% endif %}
";

            var expectedOutput = @"
Color 1: blue
Color 2: blue
Color 3: red
Color 4: blue
";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "Cache"
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #16
0
        public void CacheBlock_InnerScopeAssign_DoesNotModifyOuterVariable()
        {
            var input = @"
{% assign color = 'blue' %}
Color 1: {{ color }}

{% cache key:'fav-color' duration:'1200' %}
    Color 2: {{ color }}
    {% assign color = 'red' %}
    Color 3: {{color }}
{% endcache %}

Color 4: {{ color }}
";

            var expectedOutput = @"
Color 1: blue
Color 2: blue
Color 3: red
Color 4: blue
";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "Cache"
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #17
0
        public void Shortcode_WithEnabledCommand_DoesNotEnableCommandForOuterScope()
        {
            var shortcodeTemplate = @"
{% execute %}
    return ""Shortcode!"";
{% endexecute %}
";

            // Create a new test shortcode with the "execute" command permission.
            var shortcodeDefinition = new DynamicShortcodeDefinition();

            shortcodeDefinition.ElementType         = LavaShortcodeTypeSpecifier.Inline;
            shortcodeDefinition.TemplateMarkup      = shortcodeTemplate;
            shortcodeDefinition.Name                = "shortcode_execute";
            shortcodeDefinition.EnabledLavaCommands = new List <string> {
                "execute"
            };

            var input = @"
Shortcode Output:
{[ shortcode_execute ]}
<br>
Main Output:
{% execute %}
    return ""Main!"";
{% endexecute %}
<br>
";

            var expectedOutput = @"
Shortcode Output: Shortcode!<br>
Main Output: The Lava command 'execute' is not configured for this template.<br>
";

            // Render the template with no enabled commands.
            // The shortcode should render correctly using the enabled commands defined by its definition,
            // but the main template should show a permission error.
            var options = new LavaTestRenderOptions {
                EnabledCommands = ""
            };

            TestHelper.ExecuteForActiveEngines((engine) =>
            {
                // RockLiquid uses a different mechanism for registering shortcodes that cannot be tested here.
                if (engine.GetType() == typeof(RockLiquidEngine))
                {
                    return;
                }

                engine.RegisterShortcode(shortcodeDefinition.Name, (shortcodeName) => { return(shortcodeDefinition); });

                TestHelper.AssertTemplateOutput(engine, expectedOutput, input, options);
            });
        }
コード例 #18
0
        public void FluidEngineValueConverterPerformance_DictionaryKeyResolution_OutputsPerformanceMeasures()
        {
            var totalSets             = 10;
            var totalIterationsPerSet = 1000000;

            // Create a Fluid engine with template caching disabled.
            var engineOptions = new LavaEngineConfigurationOptions {
                CacheService = new MockTemplateCacheService()
            };

            var engine = LavaService.NewEngineInstance(typeof(FluidEngine), engineOptions);

            var standardLavaDictionary = new Dictionary <string, object>();

            var formatString = new string( '0', totalIterationsPerSet.ToString().Length );

            for (int i = 0; i < totalIterationsPerSet; i++)
            {
                standardLavaDictionary.Add(i.ToString(formatString), i);
            }

            var mergeFields = new LavaDataDictionary {
                { "Dictionary", standardLavaDictionary }
            };

            var totalTime = TestHelper.ExecuteAndGetElapsedTime(() =>
            {
                engine.ClearTemplateCache();

                for (int repeatCount = 1; repeatCount <= totalSets; repeatCount++)
                {
                    var elapsedTime = TestHelper.ExecuteAndGetElapsedTime(() =>
                    {
                        for (int i = 0; i < totalIterationsPerSet; i++)
                        {
                            var template = "{{ Dictionary['" + i.ToString(formatString) + "']}}";

                            var options = new LavaTestRenderOptions {
                                MergeFields = mergeFields
                            };

                            var output = TestHelper.GetTemplateOutput(engine, template, mergeFields);

                            // Verify that the correct entry was retrieved.
                            Assert.AreEqual(i.ToString(), output);
                        }
                    });

                    Debug.Print($"Pass {repeatCount} Elapsed Time: {elapsedTime.TotalMilliseconds} ");
                }
            });

            Debug.Print($"Average Time: {totalTime.TotalMilliseconds / totalSets} ");
        }
コード例 #19
0
        public void Shortcode_WithUnspecifiedEnabledCommands_InheritsEnabledCommandsFromOuterScope()
        {
            var shortcodeTemplate = @"
{% execute %}
    return ""Shortcode!"";
{% endexecute %}
";

            // Create a new test shortcode with no enabled commands.
            var shortcodeDefinition = new DynamicShortcodeDefinition();

            shortcodeDefinition.ElementType         = LavaShortcodeTypeSpecifier.Inline;
            shortcodeDefinition.TemplateMarkup      = shortcodeTemplate;
            shortcodeDefinition.Name                = "shortcode_execute";
            shortcodeDefinition.EnabledLavaCommands = new List <string> {
                ""
            };

            var input = @"
Shortcode Output:
{[ shortcode_execute ]}
<br>
Main Output:
{% execute %}
    return ""Main!"";
{% endexecute %}
<br>
";

            var expectedOutput = @"
Shortcode Output: Shortcode!<br>
Main Output: Main!<br>
";

            // Render the template with the "execute" command enabled.
            // This permission setting should be inherited by the shortcode, allowing it to render the "execute" command.
            var options = new LavaTestRenderOptions {
                EnabledCommands = "execute"
            };

            TestHelper.ExecuteForActiveEngines((engine) =>
            {
                // RockLiquid uses a different mechanism for registering shortcodes that cannot be tested here.
                if (engine.GetType() == typeof(RockLiquidEngine))
                {
                    return;
                }

                engine.RegisterShortcode(shortcodeDefinition.Name, (shortcodeName) => { return(shortcodeDefinition); });

                TestHelper.AssertTemplateOutput(engine, expectedOutput, input, options);
            });
        }
コード例 #20
0
        public void Shortcode_WithMergeFieldAsParameter_CorrectlyResolvesParameters()
        {
            var shortcodeTemplate = @"
Font Name: {{ fontname }}
Font Size: {{ fontsize }}
Font Bold: {{ fontbold }}
";

            // Create a new test shortcode.
            var shortcodeDefinition = new DynamicShortcodeDefinition();

            shortcodeDefinition.ElementType    = LavaShortcodeTypeSpecifier.Block;
            shortcodeDefinition.TemplateMarkup = shortcodeTemplate;
            shortcodeDefinition.Name           = "shortcodetest";

            var input = @"
{[ shortcodetest fontname:'Arial' fontsize:'{{ fontsize }}' fontbold:'true' ]}
{[ endshortcodetest ]}
";

            var expectedOutput = @"
Font Name: Arial
Font Size: 99
Font Bold: true
";

            expectedOutput = expectedOutput.Replace("``", @"""");

            var context = new LavaDataDictionary()
            {
                { "fontsize", 99 }
            };

            var options = new LavaTestRenderOptions {
                MergeFields = context
            };

            TestHelper.ExecuteForActiveEngines((engine) =>
            {
                // RockLiquid uses a different mechanism for registering shortcodes that cannot be tested here.
                if (engine.GetType() == typeof(RockLiquidEngine))
                {
                    return;
                }

                engine.RegisterShortcode(shortcodeDefinition.Name, (shortcodeName) => { return(shortcodeDefinition); });

                TestHelper.AssertTemplateOutput(engine, expectedOutput, input, options);
            });
        }
コード例 #21
0
        public void PersonAddress_WithFormatTemplateFieldCityState_ReturnsExpectedOutput()
        {
            var values = AddTestPersonToMergeDictionary(TestGuids.TestPeople.TedDecker.AsGuid());

            var options = new LavaTestRenderOptions {
                MergeFields = values
            };

            var template       = "{{ CurrentPerson | Address:'Home','[[City]], [[State]]' }}";
            var outputExpected = @"Phoenix, AZ";

            TestHelper.AssertTemplateOutput(outputExpected,
                                            template,
                                            options);
        }
コード例 #22
0
        public void PersonAddress_WithAddressTypeParameterOnly_ReturnsFullAddress()
        {
            var values = AddTestPersonToMergeDictionary(TestGuids.TestPeople.TedDecker.AsGuid());

            var options = new LavaTestRenderOptions {
                MergeFields = values
            };

            var template       = "Home Address: {{ CurrentPerson | Address:'Home' }}";
            var outputExpected = @"Home Address: 11624 N 31st Dr Phoenix, AZ 85029-3202";

            TestHelper.AssertTemplateOutput(outputExpected,
                                            template,
                                            options);
        }
コード例 #23
0
        public void WebRequestBlock_GetRockRepoCommits_ReturnsValidResponse()
        {
            var input = @"
{% webrequest url:'https://api.github.com/repos/SparkDevNetwork/Rock/git/commits/88b33817b02b798679d75f237970649f25332fe1' return:'commit' %}
    {{ commit.message }}
{% endwebrequest %}  
";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "WebRequest"
            };

            TestHelper.AssertTemplateOutput("readme", input, options);
        }
コード例 #24
0
        public void SparklineShortcodeTag_DefaultOptions_EmitsHtmlWithDefaultSettings()
        {
            var input = @"
{[ sparkline type:'line' data:'5,6,7,9,9,5,3,2,2,4,6,7' ]}
";

            var expectedOutput = @"
<script src='~/Scripts/sparkline/jquery-sparkline.min.js' type='text/javascript'></script>

<span class=``sparkline sparkline-id-<<guid>>``>Loading...</span>

  <script>
    $(``.sparkline-id-<<guid>>``).sparkline([5,6,7,9,9,5,3,2,2,4,6,7], {
      type: 'line'
      , width: 'auto'
      , height: 'auto'
      , lineColor: '#ee7625'
      , fillColor: '#f7c09b'
      , lineWidth: 1
      , spotColor: '#f80'
      , minSpotColor: '#f80'
      , maxSpotColor: '#f80'
      , highlightSpotColor: ''
      , highlightLineColor: ''
      , spotRadius: 1.5
      , chartRangeMin: undefined
      , chartRangeMax: undefined
      , chartRangeMinX: undefined
      , chartRangeMaxX: undefined
      , normalRangeMin: undefined
      , normalRangeMax: undefined
      , normalRangeColor: '#ccc'
    });
  
  </script>
";

            expectedOutput = expectedOutput.Replace("``", @"""");

            var options = new LavaTestRenderOptions()
            {
                Wildcards = new List <string> {
                    "<<guid>>"
                }
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #25
0
        public void InteractionContentChannelItemWriteTag_ForEntityCommandResult_IsCached()
        {
            var input = @"
{% interactioncontentchannelitemwrite contentchannelitemid:'1' operation:'View' summary:'Viewed content channel item #1' personaliasid:'10' %}
";

            var expectedOutput = @"
";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "InteractionContentChannelItemWrite"
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #26
0
        public void Shortcode_ReferencingItemFromParentScope_CorrectlyResolvesItem()
        {
            var shortcodeTemplate = @"
ValueInShortcodeScope = {{ Value }}
";

            // Create a new test shortcode.
            var shortcodeDefinition = new DynamicShortcodeDefinition();

            shortcodeDefinition.ElementType    = LavaShortcodeTypeSpecifier.Inline;
            shortcodeDefinition.TemplateMarkup = shortcodeTemplate;
            shortcodeDefinition.Name           = "debug";

            var input = @"
ValueInOuterScope = {{ Value }}
{[ debug ]}
";

            var expectedOutput = @"
ValueInOuterScope = 99
ValueInShortcodeScope = 99
";

            expectedOutput = expectedOutput.Replace("``", @"""");

            var context = new LavaDataDictionary()
            {
                { "Value", 99 }
            };

            var options = new LavaTestRenderOptions {
                MergeFields = context
            };

            TestHelper.ExecuteForActiveEngines((engine) =>
            {
                // RockLiquid uses a different mechanism for registering shortcodes that cannot be tested here.
                if (engine.GetType() == typeof(RockLiquidEngine))
                {
                    return;
                }

                engine.RegisterShortcode(shortcodeDefinition.Name, (shortcodeName) => { return(shortcodeDefinition); });

                TestHelper.AssertTemplateOutput(engine, expectedOutput, input, options);
            });
        }
コード例 #27
0
        public void ShortcodeBlock_WithParameterVariableContainingQuotes_CanResolveParameters()
        {
            var shortcodeTemplate = @"
Parameter 1: {{ parameterstring }}
";

            // Create a new test shortcode.
            var shortcodeDefinition = new DynamicShortcodeDefinition();

            shortcodeDefinition.ElementType    = LavaShortcodeTypeSpecifier.Block;
            shortcodeDefinition.TemplateMarkup = shortcodeTemplate;
            shortcodeDefinition.Name           = "shortcodeparametertest";
            shortcodeDefinition.Parameters     = new Dictionary <string, string> {
                { "parameterstring", "(default)" }
            };

            var input = @"
{[ shortcodeparametertest parameterstring:parameterStringValue ]}
{[ endshortcodeparametertest ]}
";

            var expectedOutput = @"
Parameter 1: Testing 'single' quotes...
";

            var mergeFields = new Dictionary <string, object> {
                { "parameterStringValue", "Testing 'single' quotes..." }
            };

            TestHelper.ExecuteForActiveEngines((engine) =>
            {
                if (engine.GetType() == typeof(RockLiquidEngine))
                {
                    // Unfortunately, there is no way of testing dynamically-defined shortcodes with RockLiquid.
                    TestHelper.DebugWriteRenderResult(engine, "(Not Implemented)", "(Not Implemented)");
                    return;
                }

                engine.RegisterShortcode(shortcodeDefinition.Name, (shortcodeName) => { return(shortcodeDefinition); });

                var options = new LavaTestRenderOptions {
                    MergeFields = mergeFields
                };

                TestHelper.AssertTemplateOutput(engine, expectedOutput, input, options);
            });
        }
コード例 #28
0
        public void ExecuteBlock_HelloWorld_ReturnsExpectedOutput()
        {
            var input = @"
{% execute %}
    return ""Hello World!"";
{% endexecute %}
            ";

            var expectedOutput = @"Hello World!";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "execute"
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #29
0
        public void WorkflowActivateBlock_ActivateSupportWorkflow_CreatesNewWorkflow()
        {
            // Activate Workflow: IT Support
            var input = @"
{% workflowactivate workflowtype:'51FE9641-FB8F-41BF-B09E-235900C3E53E' %}
  Activated new workflow with the name '{{ Workflow.Name }}'.
{% endworkflowactivate %}
";

            var expectedOutput = @"Activated new workflow with the name 'IT Support'.";

            var options = new LavaTestRenderOptions()
            {
                EnabledCommands = "WorkflowActivate"
            };

            TestHelper.AssertTemplateOutput(expectedOutput, input, options);
        }
コード例 #30
0
        public void PersonAddress_WithFormatTemplateFieldGuid_ReturnsLocationGuid()
        {
            var values = AddTestPersonToMergeDictionary(TestGuids.TestPeople.TedDecker.AsGuid());

            var person = values["CurrentPerson"] as Person;

            var options = new LavaTestRenderOptions {
                MergeFields = values
            };

            var template = @"{{ CurrentPerson | Address:'Home','[[Guid]]' }}";

            var outputExpected = person.GetHomeLocation()?.Guid.ToString("D");

            TestHelper.AssertTemplateOutput(outputExpected,
                                            template,
                                            options);
        }