DEFINE CLASS MarkdownParserTests as FxuTestCase OF FxuTestCase.prg

*** SETUP AND CONFIGURATION *** 

************************************************************************
*  Setup
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION Setup()

	*** Make sure libraries are loaded
	DO MarkdownParser
ENDFUNC
*   Setup

************************************************************************
*  TearDown
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION TearDown()

ENDFUNC
*   TearDown


************************************************************************
*  BaseTest
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION BaseTest()


loParser = CREATEOBJECT("MarkDownParserExtended")

TEXT TO lcText NOSHOW
### @icon-info-circle Examples are great

```html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>HelloWorld</title>
    <link href="../westwind.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server" method="POST">
    <h1>HelloWorld</h1>
    
    <div class="containercontent">    
        Enter your name:
        <input type="textbox" id="txtName" name="txtName" value="<%= pcName %>" />
        <input type="submit" id="btnSayHello" name="btnSayHello" value="Say Hello" />
        <hr />
        <%= pcMessage %>
    </div>    
    
</body>
</html>
```

* some list1
* some list2
* some list3


### XSS Sanitation - the following should be stripped

#### Script tag
<script>
alert('this shouldn't be here');
</script>

####  OnXXXX events
<input type="text" onchange="alert('dont do it!');" />

ENDTEXT


? lctext
? "---"

lcHtml = loParser.Parse(lcText)
this.MessageOut(lcHtml)

ENDFUNC
*   BaseTest


************************************************************************
*  MarkdownFunctionTest
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION MarkdownFunctionTest()

lcMarkdown = "This is **bold** text. Visit the [West Wind Site](https://west-wind.com)"
lcHtml = Markdown(lcMarkdown)

this.AssertTrue(ATC("<strong>bold</strong>",lcHtml) > 0)
this.MessageOut(lcHtml)
ENDFUNC
*   MarkdownFunctionTest

************************************************************************
*  HtmlSanitizeTest
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION HtmlSanitizeTest()

TEXT TO lcMarkdown NOSHOW
### Script Block (shouldn't show)

<script>
alert('Gotcha!')
</script>

### javascript:

<a href="javascript: alert('gotcha')">Link me</a>

### OnXXX Events

<div onmouseenter="alert('gotcha again!')">Hover over me!</div>

ENDTEXT

*** markdown, mode, reload, utf8, noSanitize
lcHtml = Markdown(lcMarkdown,0,.F.,.F.,.F.)

this.AssertTrue( OCCURS("alert",lcHTML) = 1 AND ATC("unsupported:",lcHtml) > 0)

this.Messageout(lcHtml)


ENDFUNC
*   HtmlSanitizeTest

ENDDEFINE
