Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
add taxonomy test
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed May 1, 2015
1 parent 4384595 commit 21f639b
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 0 deletions.
8 changes: 8 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
TODO:

- refactor processing pipeline: add an additional stage.
Currently for each resource we output directly the result. Instead, it would be better to first generate
a representation of the output tree, and then apply the processors.

- test embedded webserver

- replace all syserr with java.util.logging : it's more sane if we want to use it as a lib...

- support
- iterate-over-static-directory: a special case for paginate with a page size of 1 for static dir
- page name is generated from the static file name
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/ch/digitalfondue/stampo/ContentPaginationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,20 @@ public void paginationMissingDirToPaginateTest() throws IOException {
stampo.build();
}
}

/**
* Cannot have paginate-over-taxonomy and paginate-over-directory in the same page.
*
* @throws IOException
*/
@Test(expected = IllegalArgumentException.class)
public void paginationBothConfiguration() throws IOException {
try (InputOutputDirs iod = get()) {
write(iod.inputDir.resolve("content/index.html"),
fromTestResource("pagination/index-both-pagination.html.peb"));
Stampo stampo = new Stampo(iod.inputDir, iod.outputDir);
stampo.build();
}
}

}
70 changes: 70 additions & 0 deletions src/test/java/ch/digitalfondue/stampo/TaxonomyPaginationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright (C) 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.stampo;

import static ch.digitalfondue.stampo.TestUtils.fileOutputAsString;
import static ch.digitalfondue.stampo.TestUtils.fromTestResource;
import static ch.digitalfondue.stampo.TestUtils.fromTestResourceAsString;
import static ch.digitalfondue.stampo.TestUtils.get;
import static java.nio.file.Files.write;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.junit.Assert;
import org.junit.Test;

import ch.digitalfondue.stampo.TestUtils.InputOutputDirs;

public class TaxonomyPaginationTest {


@Test
public void testTaxonomyTags() throws IOException {

try (InputOutputDirs iod = get()) {
write(iod.inputDir.resolve("content/tags.html.peb"),
fromTestResource("pagination/tags.html.peb"));

write(iod.inputDir.resolve("configuration.yaml"), "taxonomies: [tags, authors]".getBytes(StandardCharsets.UTF_8));

Files.createDirectories(iod.inputDir.resolve("content/post"));
Files.createDirectories(iod.inputDir.resolve("content/post/durpdurp"));

for (int i = 1; i <= 20; i++) {
write(iod.inputDir.resolve("content/post/post" + i + ".md"),
fromTestResource("pagination/post/post" + i + ".md"));
}

for (int i = 21; i <= 31; i++) {
write(iod.inputDir.resolve("content/post/durpdurp/post" + i + ".md"),
fromTestResource("pagination/post/durpdurp/post" + i + ".md"));
}


Stampo stampo = new Stampo(iod.inputDir, iod.outputDir);
stampo.build();

Assert.assertEquals(fromTestResourceAsString("pagination/result/taxonomy/tags-index.html"),
fileOutputAsString(iod, "tags/test/index.html"));
Assert.assertEquals(fromTestResourceAsString("pagination/result/taxonomy/tags-page2.html"),
fileOutputAsString(iod, "tags/test/page/2/index.html"));
Assert.assertEquals(fromTestResourceAsString("pagination/result/taxonomy/hack-index.html"),
fileOutputAsString(iod, "tags/hack/index.html"));
}
}
}
25 changes: 25 additions & 0 deletions src/test/resources/pagination/index-both-configuration.html.peb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
paginate-over-taxonomy: tags
paginate-over-directory: content/post
paginate-page-size: 5
---
<a href="{{relativeRootPath}}">go to root dir</a>

{{outputPath}}

<ul>
{% for post in pagination.pageContent %}
<li>
<a href="{{post.relativeUrlToContent}}"><div>{{post.renderedResource | raw}}</div></a>
{% endfor %}
</ul>

{% if not pagination.firstPage %}
<a href="{{pagination.previousPageRelativeLink}}">« Newer Posts</a>
{% endif %}

{{pagination.currentPage}} / {{pagination.pageCount}}

{% if not pagination.lastPage %}
<a href="{{pagination.nextPageRelativeLink}}">Older Posts »</a>
{% endif %}
18 changes: 18 additions & 0 deletions src/test/resources/pagination/result/taxonomy/hack-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<head>
</head>
<body>
<a href="../..">go to root dir</a>

tags/hack
<ul>
<li>
<a href="../../post/post19"><div><p>post 19</p></div></a>
<li>
<a href="../../post/post8"><div><p>post 8</p></div></a>
</ul>


1 / 1
</body>
</html>
25 changes: 25 additions & 0 deletions src/test/resources/pagination/result/taxonomy/tags-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
</head>
<body>
<a href="../..">go to root dir</a>

tags/test
<ul>
<li>
<a href="../../post/post19"><div><p>post 19</p></div></a>
<li>
<a href="../../post/post16"><div><p>post 16</p></div></a>
<li>
<a href="../../post/post11"><div><p>post 11</p></div></a>
<li>
<a href="../../post/post8"><div><p>post 8</p></div></a>
<li>
<a href="../../post/post3"><div><p>post 3</p></div></a>
</ul>


1 / 2
<a href="page/2/">Older Posts »</a>
</body>
</html>
17 changes: 17 additions & 0 deletions src/test/resources/pagination/result/taxonomy/tags-page2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head>
</head>
<body>
<a href="../../../..">go to root dir</a>

tags/test/page/2
<ul>
<li>
<a href="../../../../post/post1"><div><p>post 1</p></div></a>
</ul>

<a href="../../">« Newer Posts</a>

2 / 2
</body>
</html>
30 changes: 30 additions & 0 deletions src/test/resources/pagination/tags.html.peb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
paginate-over-taxonomy: tags
paginate-page-size: 5
---
<html>
<head>
</head>
<body>
<a href="{{relativeRootPath}}">go to root dir</a>

{{outputPath}}

<ul>
{% for post in pagination.pageContent %}
<li>
<a href="{{post.relativeUrlToContent}}"><div>{{post.renderedResource | raw}}</div></a>
{% endfor %}
</ul>

{% if not pagination.firstPage %}
<a href="{{pagination.previousPageRelativeLink}}">« Newer Posts</a>
{% endif %}

{{pagination.currentPage}} / {{pagination.pageCount}}

{% if not pagination.lastPage %}
<a href="{{pagination.nextPageRelativeLink}}">Older Posts »</a>
{% endif %}
</body>
</html>

0 comments on commit 21f639b

Please sign in to comment.