-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_page_without_a_file.rb
167 lines (142 loc) · 4.86 KB
/
test_page_without_a_file.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# frozen_string_literal: true
require "helper"
class TestPageWithoutAFile < JekyllUnitTest
def setup_page(*args, base: source_dir, klass: PageWithoutAFile)
dir, file = args
if file.nil?
file = dir
dir = ""
end
klass.new(@site, base, dir, file)
end
def render_and_write
@site.render
@site.cleanup
@site.write
end
context "A PageWithoutAFile" do
setup do
clear_dest
@site = Site.new(Jekyll.configuration(
"source" => source_dir,
"destination" => dest_dir,
"skip_config_files" => true
))
end
context "with default site configuration" do
setup do
@page = setup_page("properties.html")
end
should "identify itself properly" do
assert_equal "#<Jekyll::PageWithoutAFile @name=\"properties.html\">", @page.inspect
end
should "not have page-content and page-data defined within it" do
assert_equal "pages", @page.type.to_s
assert_nil @page.content
assert_empty @page.data
end
should "have basic attributes defined in it" do
regular_page = setup_page("properties.html", :klass => Page)
# assert a couple of attributes accessible in a regular Jekyll::Page instance
assert_equal "All the properties.\n", regular_page["content"]
assert_equal "properties.html", regular_page["name"]
basic_attrs = %w(dir name path url)
attrs = {
"content" => "All the properties.\n",
"dir" => "/",
"excerpt" => nil,
"foo" => "bar",
"layout" => "default",
"name" => "properties.html",
"path" => "properties.html",
"permalink" => "/properties/",
"published" => nil,
"title" => "Properties Page",
"url" => "/properties.html",
}
attrs.each do |prop, value|
# assert that all attributes (of a Jekyll::PageWithoutAFile instance) other than
# "dir", "name", "path", "url" are `nil`.
# For example, @page[dir] should be "/" but @page[content] or @page[layout], should
# simply be nil.
#
if basic_attrs.include?(prop)
assert_equal value, @page[prop], "For Jekyll::PageWithoutAFile attribute '#{prop}':"
else
assert_nil @page[prop]
end
end
end
end
context "with site-wide permalink configuration" do
setup do
@site.permalink_style = :title
end
should "generate page url accordingly" do
page = setup_page("properties.html")
assert_equal "/properties", page.url
end
end
context "with default front matter configuration" do
setup do
@site.config["defaults"] = [
{
"scope" => {
"path" => "",
"type" => "pages",
},
"values" => {
"layout" => "default",
"author" => "John Doe",
},
},
]
@page = setup_page("info.md")
end
should "respect front matter defaults" do
assert_nil @page.data["title"]
assert_equal "John Doe", @page.data["author"]
assert_equal "default", @page.data["layout"]
end
end
context "with a path outside site.source" do
should "not access its contents" do
base = "../../../"
page = setup_page("pwd", :base => base)
assert_equal "pwd", page.path
assert_nil page.content
end
end
context "while processing" do
setup do
clear_dest
@site.config["title"] = "Test Site"
@page = setup_page("physical.html", :base => test_dir("fixtures"))
end
should "receive content provided to it" do
assert_nil @page.content
@page.content = "{{ site.title }}"
assert_equal "{{ site.title }}", @page.content
end
should "not be processed and written to disk at destination" do
@page.content = "Lorem ipsum dolor sit amet"
@page.data["permalink"] = "/virtual-about/"
render_and_write
refute_exist dest_dir("physical")
refute_exist dest_dir("virtual-about")
refute File.exist?(dest_dir("virtual-about", "index.html"))
end
should "be processed and written to destination when passed as "\
"an entry in 'site.pages' array" do
@page.content = "{{ site.title }}"
@page.data["permalink"] = "/virtual-about/"
@site.pages << @page
render_and_write
refute_exist dest_dir("physical")
assert_exist dest_dir("virtual-about")
assert File.exist?(dest_dir("virtual-about", "index.html"))
assert_equal "Test Site", File.read(dest_dir("virtual-about", "index.html"))
end
end
end
end