Example #1
0
func setupTestEnvironment(id string) (string, input.ConfigData, []input.ContentData) {
	baseDir := filepath.Join(test.GetTestPath(), "pageTest"+id)
	outputDirectory := filepath.Join(baseDir, "output")
	test.CreateTestDirectory(baseDir)
	test.CreateTestDirectory(outputDirectory)

	configDataPath := createConfigFile(baseDir)
	contentPath := createContent(baseDir)

	configData := input.CreateConfigData(configDataPath)
	elements := input.LoadContentData(contentPath)

	return outputDirectory, configData, elements
}
Example #2
0
func TestLoadContentCorrectContentForData(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo4")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)

	files := LoadContentData(pathToFolder)

	if len(files) != 1 {
		t.Error("expected 1 files but were : " + fmt.Sprintf("%v", len(files)))
	}

	file := files[0]

	test.TestValues(t, test.ContentDataTitle, file.Title, "title not correctly loaded")

	if file.Date.Unix() != 1427236080 {
		t.Error("date not correctly loaded")
	}
	if len(file.Categories) != len(test.ContentDataCategories) {
		t.Error("category not correctly loaded")
	}
	if file.Categories[0] != test.ContentDataCategories[0] || file.Categories[1] != test.ContentDataCategories[1] {
		t.Error("category content not correctly loaded")
	}

	test.TestValues(t, test.ContentDataContent, file.Content, "content not correctly loaded")
}
Example #3
0
func createContent(baseDir string) string {
	pathToFolder := filepath.Join(baseDir, "input")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo.md"), test.ContentData)

	return pathToFolder
}
Example #4
0
func TestLoadContentMissingSeparator(t *testing.T) {
	alteredContent := strings.Replace(test.ContentData, "---", "", -1)
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo9")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredContent)

	testLoadContentDataExpectException("Content file must contain '---' to separate config data from content", pathToFolder, t)
}
Example #5
0
func TestLoadContentMissingContentException(t *testing.T) {
	alteredContent := strings.Replace(test.ContentData, test.ContentDataContent, "", -1)
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo8")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredContent)

	testLoadContentDataExpectException("Content missing in content file", pathToFolder, t)
}
Example #6
0
func TestLoadContentIncorrectDateException(t *testing.T) {
	alteredContent := strings.Replace(test.ContentData, test.ContentDataDate, "a"+test.ContentDataDate+"1", -1)
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo7")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredContent)

	testLoadContentDataExpectException("Incorrect format of date in content file", pathToFolder, t)
}
Example #7
0
func TestLoadContentCorrectContentCountWithSubfolders(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo2")
	pathToFolder2 := filepath.Join(pathToFolder, "foo2")
	pathToFolder3 := filepath.Join(pathToFolder2, "foo2")
	pathToFolder4 := filepath.Join(pathToFolder3, "foo2")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestDirectory(pathToFolder2)
	test.CreateTestDirectory(pathToFolder3)
	test.CreateTestDirectory(pathToFolder4)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder2, "foo2.md"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder4, "foo3.md"), test.ContentData)

	files := LoadContentData(pathToFolder)

	if len(files) != 3 {
		t.Error("expected 3 files but were : " + fmt.Sprintf("%v", len(files)))
	}
}
Example #8
0
func TestCreateContent(t *testing.T) {
	outputDirectory, configData, elements := setupTestEnvironment("3")
	contentPath := filepath.Join(outputDirectory, "content")
	test.CreateTestDirectory(contentPath)
	content := elements[0]

	CreateContentPage(outputDirectory, configData, content, elements, test.BaseHtmlContent)
	expected := "Old Pages ||| <p>foo</p>\n ||| <p>2015-03-24 22:28</p></br>\n<h2>Old Pages</h2>\n<p>Old unsupported pages :</p>\n ||| <a href=\"../index.html\">Index</a></br>\n</br>\n<a href=\"../categories/x1.html\">X1</a></br>\n<a href=\"../categories/x2.html\">X2</a> ||| <p>© foo</p>\n"

	filePath := filepath.Join(contentPath, slug.GenerateSlug(test.ContentDataTitle)+".html")
	result := test.GetTestFileContent(filePath)

	test.TestValues(t, expected, result, "incorrect page generated")
}
Example #9
0
func TestCreateCategory(t *testing.T) {
	outputDirectory, configData, elements := setupTestEnvironment("2")
	category := test.ContentDataCategories[0]
	categoryPath := filepath.Join(outputDirectory, "categories")
	test.CreateTestDirectory(categoryPath)

	CreateCategoryPage(outputDirectory, configData, category, elements, test.BaseHtmlContent)
	expected := "X1 ||| <p>foo</p>\n ||| <h2>X1</h2>\n<a href=\"../content/old-pages.html\">(2015-03-24) Old Pages</a></br>\n ||| <a href=\"../index.html\">Index</a></br>\n</br>\n<a href=\"../categories/x1.html\">X1</a></br>\n<a href=\"../categories/x2.html\">X2</a> ||| <p>© foo</p>\n"

	filePath := filepath.Join(categoryPath, slug.GenerateSlug(category)+".html")
	result := test.GetTestFileContent(filePath)

	test.TestValues(t, expected, result, "incorrect page generated")
}
Example #10
0
func TestLoadContentCorrectContentCountAccordingToFileEnding(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo3")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo2.markdown"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo3.m2"), test.ContentData)

	files := LoadContentData(pathToFolder)

	if len(files) != 2 {
		t.Error("expected 2 files but were : " + fmt.Sprintf("%v", len(files)))
	}
}
Example #11
0
func TestCreateContent(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo66")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)

	files := input.LoadContentData(pathToFolder)
	result := CreateContent(testConfigData, files[0])
	expected := "<p>2015-03-24 22:28</p></br>\n<h3>Old Pages</h3>\n<p>Old unsupported pages :</p>\n"

	if result != expected {
		fmt.Println("expected : '" + expected + "'")
		fmt.Println("result   : '" + result + "'")
		t.Error("incorrect created content")
	}
}
Example #12
0
func TestCreateContentChangeVariousProperties(t *testing.T) {
	alteredCorrectData := strings.Replace(test.ContentData, "2015-03-24 22:28", "2015-03-24 22:29", -1)
	alteredCorrectData = strings.Replace(alteredCorrectData, "Old Pages", "New Pages", -1)
	alteredCorrectData = strings.Replace(alteredCorrectData, "Old unsupported pages :", "New supported pages :", -1)
	alteredTestConfigData := input.ConfigData{TitleType: "h2"}

	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo67")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredCorrectData)

	files := input.LoadContentData(pathToFolder)
	result := CreateContent(alteredTestConfigData, files[0])
	expected := "<p>2015-03-24 22:29</p></br>\n<h2>New Pages</h2>\n<p>New supported pages :</p>\n"

	if result != expected {
		fmt.Println("expected : '" + expected + "'")
		fmt.Println("result   : '" + result + "'")
		t.Error("incorrect created content")
	}
}