add contents
This commit is contained in:
70
lib/plugins/nspages/_tests/README.md
Normal file
70
lib/plugins/nspages/_tests/README.md
Normal file
@@ -0,0 +1,70 @@
|
||||
Running tests
|
||||
=============
|
||||
|
||||
TL;DR: from the `_test` directory, run either `./run-fast-test.sh` or `./run-exhaustive-tests.sh`
|
||||
|
||||
More details:
|
||||
|
||||
Tests can be run in two different ways: locally, or in Docker images
|
||||
|
||||
* Running locally will run the tests only once, against your local php version.
|
||||
* Running in Docker images will run the tests once in each images, so it's slower.
|
||||
But each image has a different version of php, so it can catch more regression.
|
||||
|
||||
Running the tests locally
|
||||
-------------------------
|
||||
|
||||
### Requirements
|
||||
|
||||
* Java and maven
|
||||
* Firefox
|
||||
* A web server with PHP
|
||||
|
||||
### How it works
|
||||
|
||||
`run_fast_test.sh` will:
|
||||
|
||||
* Download Dokuwiki (and cache it locally)
|
||||
* Install it on your local web server along with some test pages
|
||||
(it will do it as root to ensure it can write)
|
||||
* Download the selenium driver
|
||||
* Use maven to run selenium tests
|
||||
|
||||
(if all tests fails it's probably because the selenium maven plugin or the
|
||||
selenium driver is outdated. Updating both to the latest version will likely
|
||||
fix the issue)
|
||||
|
||||
|
||||
Optionally, you can also generate a dashboard to get more detailled results with
|
||||
|
||||
mvn site
|
||||
firefox target/site/surefire-report.html
|
||||
|
||||
Running the tests on Docker
|
||||
---------------------------
|
||||
|
||||
### Requirements
|
||||
|
||||
* Java and maven
|
||||
* Firefox
|
||||
* [Docker](http://docs.docker.com/linux/started/)
|
||||
* [GNU parallel](http://www.gnu.org/software/parallel/)
|
||||
|
||||
### How it works
|
||||
|
||||
`run-exhaustive-tests.sh` will:
|
||||
|
||||
* Download Dokuwiki (and cache it locally)
|
||||
* Build several docker images with different versions of PHP.
|
||||
Each of those images will contain a wiki with some test pages
|
||||
* Start containers with those images, and run selenium tests against them
|
||||
|
||||
### Current limitations
|
||||
|
||||
When tests fail on a container, the script doesn't stop the container
|
||||
(hence the port remains busy, hence we can't launch the tests again)
|
||||
|
||||
To fix it, we should stop the container manually:
|
||||
|
||||
docker ps
|
||||
docker stop <container-id>
|
3
lib/plugins/nspages/_tests/dockerFiles.dat
Normal file
3
lib/plugins/nspages/_tests/dockerFiles.dat
Normal file
@@ -0,0 +1,3 @@
|
||||
8 /var/www/html 5.6 5000
|
||||
7 /var/www 5.4 5001
|
||||
6 /var/www 5.3 5002
|
23
lib/plugins/nspages/_tests/internal/Dockerfile.template
Normal file
23
lib/plugins/nspages/_tests/internal/Dockerfile.template
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM debian:$DOCKER_DEBIAN_TAG
|
||||
RUN apt-get update && apt-get install -y apache2 libapache2-mod-php5
|
||||
RUN apt-get install -y wget
|
||||
COPY nspages.tgz installTestEnvironment.sh testEnvironment dw_dl_cache source.sh /home/
|
||||
RUN cd /home \
|
||||
&& mkdir nspages \
|
||||
&& cd nspages \
|
||||
&& mv ../nspages.tgz . \
|
||||
&& tar xf nspages.tgz \
|
||||
&& rm nspages.tgz \
|
||||
&& mkdir _tests \
|
||||
&& cd _tests \
|
||||
&& mv /home/installTestEnvironment.sh .\
|
||||
&& mv /home/source.sh .\
|
||||
&& mkdir testEnvironment \
|
||||
&& mv /home/data testEnvironment \
|
||||
&& mkdir dw_dl_cache \
|
||||
&& mv /home/dokuwiki-*.tgz dw_dl_cache \
|
||||
&& chmod u+x installTestEnvironment.sh \
|
||||
&& /etc/init.d/apache2 start \
|
||||
&& SERVER_FS_ROOT=$SERVER_FS_ROOT ./installTestEnvironment.sh
|
||||
|
||||
CMD /etc/init.d/apache2 start && tail -F /var/log/apache2/access.log
|
30
lib/plugins/nspages/_tests/internal/createDockerImages.sh
Normal file
30
lib/plugins/nspages/_tests/internal/createDockerImages.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
./internal/dl_dw.sh
|
||||
|
||||
function createImage {
|
||||
set -e
|
||||
export DOCKER_DEBIAN_TAG=$(echo $1 | cut -d ' ' -f 1)
|
||||
export SERVER_FS_ROOT=$(echo $1 | cut -d ' ' -f 2)
|
||||
|
||||
cat internal/Dockerfile.template | envsubst > docker/Dockerfile
|
||||
pushd docker >/dev/null
|
||||
docker build -t nspages-test-$DOCKER_DEBIAN_TAG .
|
||||
popd >/dev/null
|
||||
}
|
||||
export -f createImage
|
||||
|
||||
pushd .. >/dev/null
|
||||
STASH_NAME=$(git stash create)
|
||||
git archive -o nspages.tgz ${STASH_NAME:-HEAD}
|
||||
mkdir _tests/docker 2>/dev/null || true
|
||||
mv nspages.tgz _tests/docker
|
||||
popd >/dev/null
|
||||
|
||||
cp -r internal/installTestEnvironment.sh testEnvironment source.sh docker
|
||||
mkdir docker/dw_dl_cache 2>/dev/null || true
|
||||
cp dw_dl_cache/dokuwiki-*.tgz docker/dw_dl_cache
|
||||
|
||||
. source.sh
|
||||
echo Going to build the docker images. Parallel arg: $PARALLEL_JOB_ARG
|
||||
parallel $PARALLEL_JOB_ARG -a dockerFiles.dat createImage;
|
17
lib/plugins/nspages/_tests/internal/dl_dw.sh
Normal file
17
lib/plugins/nspages/_tests/internal/dl_dw.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
. source.sh
|
||||
|
||||
mkdir -p $DW_DL_CACHE
|
||||
cd $DW_DL_CACHE
|
||||
|
||||
echo "Going to download $DW_VERSION"
|
||||
|
||||
#Avoid downloading the tarball again if we already have it
|
||||
if [ ! -e $DW_VERSION.tgz ]; then
|
||||
echo " Starting to download $DW_VERSION.tgz"
|
||||
wget http://download.dokuwiki.org/src/dokuwiki/$DW_VERSION.tgz
|
||||
chmod a+r $DW_VERSION.tgz
|
||||
else
|
||||
echo " $DW_VERSION.tgz found. No need to download it again."
|
||||
fi
|
21
lib/plugins/nspages/_tests/internal/dl_geckodriver.sh
Normal file
21
lib/plugins/nspages/_tests/internal/dl_geckodriver.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash -e
|
||||
if [ -L "$0" ] && [ -x $(which readlink) ]; then
|
||||
thisFile="$(readlink -mn "$0")"
|
||||
else
|
||||
thisFile="$0"
|
||||
fi
|
||||
thisDir="$(dirname "$thisFile")"
|
||||
RESOURCE_DIR=$thisDir/../src/test/resources
|
||||
if [ ! -e $RESOURCE_DIR/geckodriver ]; then
|
||||
echo Downloading geckodriver
|
||||
VERSION=v0.29.1
|
||||
ARCHIVE=geckodriver-$VERSION-linux64.tar.gz
|
||||
rm -f $ARCHIVE
|
||||
wget https://github.com/mozilla/geckodriver/releases/download/$VERSION/$ARCHIVE
|
||||
tar xf $ARCHIVE
|
||||
mkdir -p $RESOURCE_DIR
|
||||
mv geckodriver $RESOURCE_DIR
|
||||
rm $ARCHIVE
|
||||
else
|
||||
echo Geckodriver already present
|
||||
fi
|
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
#directory where Dokuwiki should be installed in order to be reachable at http://localhost
|
||||
SERVER_FS_ROOT=${SERVER_FS_ROOT:-/var/www/html}
|
||||
echo Using server fs root at: $SERVER_FS_ROOT
|
||||
|
||||
#Owner of the files (to make sure the instance of dokuwiki can edit its pages)
|
||||
serverFileSystemOwner=www-data
|
||||
#Shouldn't be changed since itests try to connect to this url
|
||||
baseUrl=http://localhost
|
||||
dirNamePrefix=dokuwikiITestsForNsPages
|
||||
|
||||
. source.sh
|
||||
relativeTestFileDir=testEnvironment
|
||||
|
||||
pushd $DW_DL_CACHE >/dev/null
|
||||
|
||||
echo "Going to install $DW_VERSION"
|
||||
|
||||
tar -xzf $DW_VERSION.tgz
|
||||
|
||||
|
||||
echo " Copying files to the server"
|
||||
dirName=${dirNamePrefix}${DW_VERSION}
|
||||
destDir=$SERVER_FS_ROOT/$dirName
|
||||
|
||||
rm -rf $destDir
|
||||
cp -r $DW_VERSION $destDir
|
||||
|
||||
echo " Configuring the wiki"
|
||||
cp -r ../$relativeTestFileDir/data/* $destDir/data
|
||||
|
||||
echo " Installing the plugin"
|
||||
pluginDir=$destDir/lib/plugins/nspages
|
||||
mkdir $pluginDir
|
||||
for item in $(find ../.. -maxdepth 1 -mindepth 1 | grep -v _test | grep -v .git); do
|
||||
cp -r $item $pluginDir
|
||||
done
|
||||
|
||||
echo " Reseting some mtimes"
|
||||
touch -t201504010020.00 $destDir/data/pages/ns1/a.txt
|
||||
touch -t201504011020.00 $destDir/data/pages/ns1/b2.txt
|
||||
touch -t201504012020.00 $destDir/data/pages/ns1/c.txt
|
||||
touch -t201504012320.00 $destDir/data/pages/ns1/b1.txt
|
||||
touch -t201504022220.00 $destDir/data/pages/simpleline/p1.txt
|
||||
touch -t201504032220.00 $destDir/data/pages/simpleline/p2.txt
|
||||
|
||||
chown -R $serverFileSystemOwner $destDir
|
||||
|
||||
echo " Running the indexer"
|
||||
cd ../testEnvironment/data/pages
|
||||
for f in $(find . -name "*txt"); do
|
||||
f=$(echo $f | cut -d '.' -f 2 | tr / :)
|
||||
wget -O /dev/null -q $baseUrl/$dirName/lib/exe/taskrunner.php?id=$f
|
||||
done
|
||||
echo " Installed $DW_VERSION"
|
||||
popd >/dev/null
|
||||
|
||||
echo Done.
|
89
lib/plugins/nspages/_tests/pom.xml
Normal file
89
lib/plugins/nspages/_tests/pom.xml
Normal file
@@ -0,0 +1,89 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>fr.turri</groupId>
|
||||
<artifactId>nspagesTest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>nspagesTest</name>
|
||||
<url>https://www.dokuwiki.org/plugin:nspages</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>3.141.59</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-report-plugin</artifactId>
|
||||
<version>2.22.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!--plugin>
|
||||
<groupId>com.soebes.maven.plugins</groupId>
|
||||
<artifactId>maven-echo-plugin</artifactId>
|
||||
<version>0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-test-classes</phase>
|
||||
<goals>
|
||||
<goal>echo</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<echos>
|
||||
<echo>*** If most tests fail, make sure you've installed the fake wiki. See README for more info ***</echo>
|
||||
</echos>
|
||||
</configuration>
|
||||
</plugin-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>skip-tests-pre-warning</id>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>actual-tests</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<webdriver.gecko.driver>${project.basedir}/src/test/resources/geckodriver</webdriver.gecko.driver>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
33
lib/plugins/nspages/_tests/run-exhaustive-tests.sh
Normal file
33
lib/plugins/nspages/_tests/run-exhaustive-tests.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
./internal/dl_geckodriver.sh
|
||||
set -e
|
||||
./internal/createDockerImages.sh
|
||||
. source.sh
|
||||
set +e
|
||||
|
||||
function runTests {
|
||||
export DOCKER_DEBIAN_TAG=$(echo $1 | cut -d ' ' -f 1)
|
||||
export PHP_VERSION=$(echo $1 | cut -d ' ' -f 3)
|
||||
export NSPAGES_DOCKER_PORT=$(echo $1 | cut -d ' ' -f 4)
|
||||
echo Testing on Debian $DOCKER_DEBIAN_TAG with PHP $PHP_VERSION
|
||||
NSPAGES_DOCKER_ID=$(docker run -d -p $NSPAGES_DOCKER_PORT:80 nspages-test-$DOCKER_DEBIAN_TAG)
|
||||
mvn test
|
||||
RET_CODE=$?
|
||||
docker stop $NSPAGES_DOCKER_ID
|
||||
return $RET_CODE
|
||||
}
|
||||
|
||||
export -f runTests
|
||||
|
||||
echo Going to run tests with parallel arg: $PARALLEL_JOB_ARG
|
||||
parallel $PARALLEL_JOB_ARG -a dockerFiles.dat runTests;
|
||||
RET_CODE=$?
|
||||
|
||||
if [ $RET_CODE -eq 0 ]; then
|
||||
echo SUCESS
|
||||
else
|
||||
echo FAILURE
|
||||
fi
|
||||
exit $RET_CODE
|
||||
|
8
lib/plugins/nspages/_tests/run-fast-test.sh
Normal file
8
lib/plugins/nspages/_tests/run-fast-test.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
./internal/dl_geckodriver.sh
|
||||
|
||||
./internal/dl_dw.sh
|
||||
sudo ./internal/installTestEnvironment.sh
|
||||
|
||||
mvn test
|
13
lib/plugins/nspages/_tests/source.sh
Normal file
13
lib/plugins/nspages/_tests/source.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
DW_DL_CACHE=dw_dl_cache
|
||||
DW_VERSION="dokuwiki-2020-07-29"
|
||||
|
||||
# Empty = on job per core
|
||||
PARALLEL_NB_JOBS=3
|
||||
|
||||
# Do not edit below
|
||||
if ! [ x$PARALLEL_NB_JOBS = x ]; then
|
||||
PARALLEL_JOB_ARG="--jobs $PARALLEL_NB_JOBS"
|
||||
else
|
||||
PARALLEL_JOB_ARG=''
|
||||
fi
|
||||
export PARALLEL_JOB_ARG
|
180
lib/plugins/nspages/_tests/src/test/java/nspages/Helper.java
Normal file
180
lib/plugins/nspages/_tests/src/test/java/nspages/Helper.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.remote.UnreachableBrowserException;
|
||||
|
||||
public class Helper {
|
||||
private final static String protocol = "http://";
|
||||
private final static String server = "localhost" + getPort();
|
||||
public final static String wikiPath = "/dokuwikiITestsForNsPagesdokuwiki-2020-07-29";
|
||||
public final static String baseUrl = protocol + server + wikiPath + "/doku.php";
|
||||
private final static WebDriver driver;
|
||||
|
||||
static {
|
||||
driver = new RetrierWebDriverDecorator(new FirefoxDriver());
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
driver.quit();
|
||||
} catch (UnreachableBrowserException e) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public WebDriver getDriver(){
|
||||
return driver;
|
||||
}
|
||||
|
||||
public static String getPort(){
|
||||
final String varEnv = "NSPAGES_DOCKER_PORT";
|
||||
Map<String, String> env = System.getenv();
|
||||
if ( env.containsKey(varEnv) ){
|
||||
return ":" + env.get(varEnv);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void generatePage(String page, String wikiMarkup){
|
||||
navigateToEditionPage(page);
|
||||
WebElement wikiTextBox = getEditTextArea();
|
||||
fillTextArea(wikiTextBox, wikiMarkup);
|
||||
savePage();
|
||||
assertNoPhpWarning();
|
||||
}
|
||||
|
||||
private void assertNoPhpWarning(){
|
||||
assertFalse(driver.getPageSource().contains("Warning"));
|
||||
}
|
||||
|
||||
private void navigateToEditionPage(String page){
|
||||
driver.get(baseUrl + "?id=" + page + "&do=edit&rev=0");
|
||||
}
|
||||
|
||||
public void navigateTo(String page){
|
||||
driver.get(baseUrl + "?id=" + page);
|
||||
}
|
||||
|
||||
private WebElement getEditTextArea(){
|
||||
return driver.findElement(By.id("wiki__text"));
|
||||
}
|
||||
|
||||
private void fillTextArea(WebElement textArea, String wikiMarkup){
|
||||
textArea.clear();
|
||||
textArea.sendKeys(wikiMarkup);
|
||||
}
|
||||
|
||||
private void savePage(){
|
||||
WebElement saveButton = driver.findElement(By.id("edbtn__save"));
|
||||
saveButton.click();
|
||||
}
|
||||
|
||||
public void assertSameLinks(List<InternalLink> expectedLinks){
|
||||
List<WebElement> actualLinks = getNspagesLinks();
|
||||
assertSameLinks(expectedLinks, actualLinks);
|
||||
}
|
||||
|
||||
public List<WebElement> getNspagesLinks(){
|
||||
List<WebElement> headers = driver.findElements(By.className("catpagecol"));
|
||||
List<WebElement> links = new ArrayList<WebElement>();
|
||||
|
||||
for(WebElement header : headers){
|
||||
links.addAll(header.findElements(By.tagName("a")));
|
||||
}
|
||||
|
||||
return links;
|
||||
}
|
||||
|
||||
public void assertSameNsAndPagesLinks(List<InternalLink> expectedNsLinks, List<InternalLink> expectedPagesLinks){
|
||||
List<WebElement> sections = driver.findElements(By.className("catpageheadline"));
|
||||
assertEquals(2, sections.size());
|
||||
|
||||
List<WebElement> actualNsLinks = getSectionLinks(sections.get(0));
|
||||
assertSameLinks(expectedNsLinks, actualNsLinks);
|
||||
|
||||
List<WebElement> actualPagesLinks = getSectionLinks(sections.get(1));
|
||||
assertSameLinks(expectedPagesLinks, actualPagesLinks);
|
||||
}
|
||||
|
||||
protected void assertSameLinks(List<InternalLink> expectedLinks, List<WebElement> actualLinks){
|
||||
assertEquals(expectedLinks.size(), actualLinks.size());
|
||||
for(int numLink = 0 ; numLink < expectedLinks.size() ; numLink++ ){
|
||||
InternalLink expected = expectedLinks.get(numLink);
|
||||
WebElement actual = actualLinks.get(numLink);
|
||||
assertSameLinks(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertSameLinks(InternalLink expectedLink, WebElement actualLink){
|
||||
assertEquals(baseUrl + "?id=" + expectedLink.dest(), actualLink.getAttribute("href"));
|
||||
assertEquals(expectedLink.text(), actualLink.getAttribute("innerHTML"));
|
||||
assertEquals(expectedLink.id(), getHtmlId(actualLink));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id which may have been generated by -includeItemsInTOC
|
||||
* Depending on the printer it may either be:
|
||||
* - on a direct child div (for the -usePictures printer)
|
||||
* - or on the parent span (for all other printers)
|
||||
* - or on the grand parent span (for the link of the current page)
|
||||
* @return the html id if one is found, or null if there is none
|
||||
*/
|
||||
protected String getHtmlId(WebElement link){
|
||||
List<WebElement> children = link.findElements(By.tagName("div"));
|
||||
if (children.size() == 1){
|
||||
// Case of the -usePictures printer
|
||||
return children.get(0).getAttribute("id");
|
||||
} else {
|
||||
WebElement parent = link.findElement(By.xpath("./.."));
|
||||
if (parent.getAttribute("class").equals("curid")) {
|
||||
// case of the link which point at the current page
|
||||
WebElement grandParent = parent.findElement(By.xpath("./.."));
|
||||
return grandParent.getAttribute("id");
|
||||
} else {
|
||||
return parent.getAttribute("id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<WebElement> getSectionLinks(WebElement nsPagesHeader){
|
||||
List<WebElement> links = new ArrayList<WebElement>();
|
||||
WebElement current = getNextSibling(nsPagesHeader);
|
||||
for(
|
||||
; current.getAttribute("class").equals("catpagecol")
|
||||
; current = getNextSibling(current) ){
|
||||
links.addAll(current.findElements(By.tagName("a")));
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
||||
public WebElement getNextSibling(WebElement current){
|
||||
return current.findElement(By.xpath("following::*"));
|
||||
}
|
||||
|
||||
public List<WebElement> getColumns(){
|
||||
return driver.findElements(By.className("catpagecol"));
|
||||
}
|
||||
|
||||
public boolean pagesContains(String contained){
|
||||
return driver.findElement(By.tagName("html")).getAttribute("innerHTML").contains(contained);
|
||||
}
|
||||
|
||||
/**
|
||||
* For tests using -usePictures
|
||||
*/
|
||||
protected List<WebElement> getPictureLinks(){
|
||||
WebElement wrapper = getDriver().findElement(By.className("nspagesPicturesModeMain"));
|
||||
return wrapper.findElements(By.tagName("a"));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package nspages;
|
||||
|
||||
public class InternalLink {
|
||||
private String dest;
|
||||
private String text;
|
||||
private String id;
|
||||
|
||||
public InternalLink(String dest, String text) {
|
||||
this(dest, text, "");
|
||||
}
|
||||
public InternalLink(String dest, String text, String id){
|
||||
this.dest = dest;
|
||||
this.text = text;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String dest(){
|
||||
return dest;
|
||||
}
|
||||
|
||||
public String text(){
|
||||
return text;
|
||||
}
|
||||
|
||||
public String id(){
|
||||
return id;
|
||||
}
|
||||
}
|
@@ -0,0 +1,123 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class RetrierWebDriverDecorator implements WebDriver {
|
||||
private static final int NB_MAX_RETRY = 20;
|
||||
private final WebDriver _driver;
|
||||
|
||||
public RetrierWebDriverDecorator(WebDriver driver) {
|
||||
_driver = driver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void get(String url) {
|
||||
_driver.get(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentUrl() {
|
||||
return _driver.getCurrentUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return _driver.getTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WebElement> findElements(By by) {
|
||||
List<WebElement> result = null;
|
||||
|
||||
for(int i=0 ; i < NB_MAX_RETRY ; i++){
|
||||
result = _driver.findElements(by);
|
||||
if ( result != null && result.size() > 0 ){
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebElement findElement(By by) {
|
||||
WebElement result = null;
|
||||
Exception lastException = null;
|
||||
for ( int i=0 ; i < NB_MAX_RETRY && result == null ; i++){
|
||||
try {
|
||||
result = _driver.findElement(by);
|
||||
} catch(Exception e){
|
||||
lastException = e;
|
||||
}
|
||||
}
|
||||
|
||||
if ( lastException != null && result == null ){
|
||||
throw new RuntimeException(lastException);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPageSource() {
|
||||
try {
|
||||
Thread.sleep(100); //To ensure we don't just get the previous page
|
||||
} catch (InterruptedException e) {}
|
||||
|
||||
Exception lastException = null;
|
||||
String result = null;
|
||||
for ( int i=0 ; i < NB_MAX_RETRY && result == null; i++){
|
||||
try {
|
||||
result = _driver.getPageSource();
|
||||
} catch(Exception e){
|
||||
lastException = e;
|
||||
}
|
||||
}
|
||||
|
||||
if ( result == null && lastException != null ){
|
||||
throw new RuntimeException(lastException);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
_driver.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quit() {
|
||||
_driver.quit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getWindowHandles() {
|
||||
return _driver.getWindowHandles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWindowHandle() {
|
||||
return _driver.getWindowHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetLocator switchTo() {
|
||||
return _driver.switchTo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Navigation navigate() {
|
||||
return _driver.navigate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Options manage() {
|
||||
return _driver.manage();
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
/*public class Test_actualTitle {
|
||||
@Test
|
||||
public void stuff(){
|
||||
System.out.println(System.getProperty("webdriver.gecko.driver"));
|
||||
//System.getProperties().list(System.out);
|
||||
}
|
||||
}*/
|
||||
public class Test_actualTitle extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("titlens:start", "<nspages -textPages=\"my title\">");
|
||||
assertHasAdHocTitle("my title");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void CanWriteH2Title(){
|
||||
generatePage("titlens:start", "<nspages -actualTitle=2 -textPages=\"my title\">");
|
||||
assertHasActualTitle("my title", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void CanWriteH4Title(){
|
||||
generatePage("titlens:start", "<nspages -actualTitle=4 -textPages=\"my title\">");
|
||||
assertHasActualTitle("my title", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void DefaultLevelIsH2Title(){
|
||||
generatePage("titlens:start", "<nspages -actualTitle -textPages=\"my title\">");
|
||||
assertHasActualTitle("my title", 2);
|
||||
}
|
||||
|
||||
private void assertHasAdHocTitle(String expectedText){
|
||||
WebElement element = getDriver().findElement(By.className("catpageheadline"));
|
||||
assertEquals(expectedText, element.getAttribute("innerHTML"));
|
||||
}
|
||||
|
||||
private void assertHasActualTitle(String expectedText, int expectedLevel){
|
||||
WebElement element = getDriver().findElement(By.tagName("h" + expectedLevel));
|
||||
assertEquals(expectedText, element.getAttribute("innerHTML"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package nspages;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class Test_cacheDisabled extends Helper {
|
||||
|
||||
private final String childPage1 = "no_cache:some_page";
|
||||
private final String childPage2 = "no_cache:other_page";
|
||||
|
||||
@Before
|
||||
public void removeChildPage(){
|
||||
generatePage(childPage1, "");
|
||||
generatePage(childPage2, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addindASubPageIsTakenIntoAccount(){
|
||||
generatePage("no_cache:start", "<nspages>");
|
||||
assertNbNspagesLinks(1); //Only contains the start page
|
||||
|
||||
createChildPage(childPage1);
|
||||
navigateTo("no_cache:start");
|
||||
assertNbNspagesLinks(2);
|
||||
|
||||
createChildPage(childPage2);
|
||||
navigateTo("no_cache:start");
|
||||
assertNbNspagesLinks(3);
|
||||
}
|
||||
|
||||
public void createChildPage(String pageId){
|
||||
generatePage(pageId, "<nspages>");
|
||||
}
|
||||
|
||||
private void assertNbNspagesLinks(int expected){
|
||||
assertEquals(expected, getNspagesLinks().size());
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package nspages;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Test_customTitle extends Helper {
|
||||
@Test
|
||||
public void withSimpleOption() {
|
||||
generatePage("customtitle:start", "======Some Title======\n\n"
|
||||
+ "<nspages -customTitle=\"Custom title for page {title}\" >");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("customtitle:start", "Custom title for page Some Title"));
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withMetaNotDefined() {
|
||||
// Here "user" is a correct metadata but since test are run with an anonymous user, this metadata isn't set.
|
||||
// This test ensure we cope correctly with this case
|
||||
generatePage("customtitle:start", "======Some Title======\n\n"
|
||||
+ "<nspages -customTitle=\"{title} by {user}\" >");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("customtitle:start", "Some Title by "));
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withForbiddenMetadata(){
|
||||
// "ip" is an actual metadata but it is not allowed by default (to prevent leaking private information).
|
||||
// This test ensures we don't replace those
|
||||
generatePage("customtitle:start", "======Some Title======\n\n"
|
||||
+ "<nspages -customTitle=\"{title} by {ip}\" >");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("customtitle:start", "Some Title by ip"));
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_dashInSubNs extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("start", "<nspages test-re>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("test-re:in_subns_with_carret", "in_subns_with_carret"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_exclude extends Helper {
|
||||
// Note that the "global_exclude" conf is implicitly tested by each of those tests
|
||||
// since each would see the page "c_template" if this feature doesn't work
|
||||
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("excludepage:start", "<nspages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("excludepage:p1", "p1"));
|
||||
expectedLinks.add(new InternalLink("excludepage:p2", "p2"));
|
||||
expectedLinks.add(new InternalLink("excludepage:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionAlone(){
|
||||
generatePage("excludepage:start", "<nspages -exclude>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("excludepage:p1", "p1"));
|
||||
expectedLinks.add(new InternalLink("excludepage:p2", "p2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionWithArg(){
|
||||
generatePage("excludepage:start", "<nspages -exclude:p1 -exclude:p2>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("excludepage:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void legacySyntax(){
|
||||
generatePage("excludepage:start", "<nspages -exclude:[start p1]>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("excludepage:p2", "p2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_hideNoPages extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("noitems:start", "<nspages -exclude>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(1, sections.size());
|
||||
WebElement sibling = sections.get(0).findElement(By.xpath("following::*"));
|
||||
assertTrue(sibling.getAttribute("innerHTML").contains("No pages in this namespace."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("noitems:start", "<nspages -exclude -hideNoPages>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(0, sections.size());
|
||||
|
||||
//Without this assert, the test would succeed even without the implementation commit
|
||||
assertFalse(pagesContains("namespace doesn't exist:"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_hideNoSubns extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("noitems:start", "<nspages -nopages -subns>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(1, sections.size());
|
||||
WebElement sibling = sections.get(0).findElement(By.xpath("following::*"));
|
||||
assertTrue(sibling.getAttribute("innerHTML").contains("No subnamespaces."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("noitems:start", "<nspages -nopages -subns -hideNoSubns>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(0, sections.size());
|
||||
|
||||
//Without this assert, the test would succeed even without the implementation commit
|
||||
assertFalse(pagesContains("namespace doesn't exist:"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_idAndTitleForNs extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("titlens:start", "<nspages -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("titlens:subns1:start", "subns1"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns2_main_page:subns2_main_page", "subns2_main_page"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns_titleless:start", "subns_titleless"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("titlens:start", "<nspages -subns -nopages -idAndTitle>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("titlens:subns1:start", "subns1 - 1st subns"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns2_main_page:subns2_main_page", "subns2_main_page - ns 'playground'-style"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns_titleless:start", "subns_titleless"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_idAndTitleForPages extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("sortid:start", "<nspages>");
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
|
||||
expectedLinks.add(new InternalLink("sortid:a", "a"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:y", "y"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("sortid:start", "<nspages -idAndtitle>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("sortid:a", "a - Z"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:y", "y - B"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,301 @@
|
||||
package nspages;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class Test_includeItemsInTOC extends Helper {
|
||||
private static final String ns = "ordre_alphabetique_ns";
|
||||
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage(ns + ":start", addTitlesInOrderToHaveAToc("<nspages -subns>"));
|
||||
|
||||
// Assert links (or their surrounding span) do not have any html id
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(new InternalLink(ns + ":a:start", "a", ""));
|
||||
expectedLinks.add(new InternalLink(ns + ":aa:start", "aa", ""));
|
||||
expectedLinks.add(new InternalLink(ns + ":b:start", "b", ""));
|
||||
expectedLinks.add(new InternalLink(ns + ":start", "start", ""));
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
// Assert the TOC only has links for the normal headers
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage(ns + ":start", addTitlesInOrderToHaveAToc("<nspages -subns -includeItemsInTOC>"));
|
||||
|
||||
// Assert links (or their surrounding span) have the expected html id
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(new InternalLink(ns + ":a:start", "a", "nspages_" + ns + "astart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":aa:start", "aa", "nspages_" + ns + "aastart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":b:start", "b", "nspages_" + ns + "bstart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":start", "start", "nspages_" + ns + "start"));
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
// Assert the TOC has the expected links
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
expectedTOCLinks.addAll(expectedNsPagesTOCLinks());
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionAndh1(){
|
||||
generatePage(ns + ":start", addTitlesInOrderToHaveAToc("<nspages -h1 -subns -includeItemsInTOC>"));
|
||||
|
||||
// Assert links (or their surrounding span) have the expected html id
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(new InternalLink(ns + ":aa:start", "aa", "nspages_" + ns + "aastart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":b:start", "Y", "nspages_" + ns + "bstart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":a:start", "Z", "nspages_" + ns + "astart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":start", "A", "nspages_" + ns + "start"));
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
// Assert the TOC has the expected links
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
expectedTOCLinks.add(new TOCLink(2, getDriver().getCurrentUrl() + "#nspages_" + ns + "aastart", "aa"));
|
||||
expectedTOCLinks.add(new TOCLink(2 ,getDriver().getCurrentUrl() + "#nspages_" + ns + "bstart", "Y"));
|
||||
expectedTOCLinks.add(new TOCLink(2, getDriver().getCurrentUrl() + "#nspages_" + ns + "astart", "Z"));
|
||||
expectedTOCLinks.add(new TOCLink(2 ,getDriver().getCurrentUrl() + "#nspages_" + ns + "start", "A"));
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withAfterAH2Title(){
|
||||
generatePage(ns + ":start", addTitlesInOrderToHaveAToc("=====D=====\n<nspages -subns -includeItemsInTOC>"));
|
||||
|
||||
// Assert links (or their surrounding span) have the expected html id
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(new InternalLink(ns + ":a:start", "a", "nspages_" + ns + "astart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":aa:start", "aa", "nspages_" + ns + "aastart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":b:start", "b", "nspages_" + ns + "bstart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":start", "start", "nspages_" + ns + "start"));
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
// Assert the TOC has the expected links
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
expectedTOCLinks.add(new TOCLink(2 ,getDriver().getCurrentUrl() + "#d", "D"));
|
||||
expectedTOCLinks.addAll(expectedNsPagesTOCLinks(2));
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withTwoNspagesTagsIdsAreStillUnique(){
|
||||
generatePage(ns + ":start", addTitlesInOrderToHaveAToc("<nspages -subns -includeItemsInTOC><nspages -subns -includeItemsInTOC>"));
|
||||
|
||||
// Assert links (or their surrounding span) have the expected html id
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
// Links for the 1st tag
|
||||
expectedLinks.add(new InternalLink(ns + ":a:start", "a", "nspages_" + ns + "astart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":aa:start", "aa", "nspages_" + ns + "aastart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":b:start", "b", "nspages_" + ns + "bstart"));
|
||||
expectedLinks.add(new InternalLink(ns + ":start", "start", "nspages_" + ns + "start"));
|
||||
// Links for the 2nd tag: same links but with unique ids
|
||||
expectedLinks.add(new InternalLink(ns + ":a:start", "a", "nspages_" + ns + "astart1"));
|
||||
expectedLinks.add(new InternalLink(ns + ":aa:start", "aa", "nspages_" + ns + "aastart1"));
|
||||
expectedLinks.add(new InternalLink(ns + ":b:start", "b", "nspages_" + ns + "bstart1"));
|
||||
expectedLinks.add(new InternalLink(ns + ":start", "start", "nspages_" + ns + "start1"));
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
// Assert the TOC has links for both nspages tags and with correct id
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
expectedTOCLinks.addAll(expectedNsPagesTOCLinks());
|
||||
expectedTOCLinks.addAll(expectedNsPagesTOCLinks("1"));
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
}
|
||||
|
||||
/**
|
||||
* the -tree printer is a bit more subtle as the others because the indentation of the links in the
|
||||
* TOC should reflect the level of the entry in the tree
|
||||
*/
|
||||
@Test
|
||||
public void withTreeButNotTheOption(){
|
||||
String treeRoot = "trees:standard_tree";
|
||||
generatePage(treeRoot + ":page_at_root_level", addTitlesInOrderToHaveAToc("<nspages -r=3 -tree -subns -nopages -pagesInNs>"));
|
||||
|
||||
// Assert links (or their surrounding span) don't have a html id
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:start", "section1", ""));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:subsection1:start", "subsection1", ""));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:subsection2:start", "subsection2", ""));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:subsection3:start", "subsection3", ""));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section2:start", "section2", ""));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section3:start", "section3", ""));
|
||||
WebElement nspagesRoot = getDriver().findElement(By.className("plugin_nspages"));
|
||||
assertSameLinks(expectedLinks, nspagesRoot.findElements(By.tagName("a")));
|
||||
|
||||
// Assert the TOC doesn't have links to nspages items
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
}
|
||||
@Test
|
||||
public void withTreeAndTheOption(){
|
||||
String treeRoot = "trees:standard_tree";
|
||||
generatePage(treeRoot + ":page_at_root_level", addTitlesInOrderToHaveAToc("<nspages -r=3 -tree -subns -nopages -pagesInNs -includeItemsInTOC>"));
|
||||
|
||||
// Assert links (or their surrounding span) have the expected html id
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:start", "section1", "nspages_treesstandard_treesection1"));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:subsection1:start", "subsection1", "nspages_treesstandard_treesection1subsection1start"));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:subsection2:start", "subsection2", "nspages_treesstandard_treesection1subsection2start"));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section1:subsection3:start", "subsection3", "nspages_treesstandard_treesection1subsection3"));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section2:start", "section2", "nspages_treesstandard_treesection2start"));
|
||||
expectedLinks.add(new InternalLink(treeRoot + ":section3:start", "section3", "nspages_treesstandard_treesection3start"));
|
||||
WebElement nspagesRoot = getDriver().findElement(By.className("plugin_nspages"));
|
||||
assertSameLinks(expectedLinks, nspagesRoot.findElements(By.tagName("a")));
|
||||
|
||||
// Assert the TOC has the links with the correct indentation level
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
expectedTOCLinks.add(new TOCLink(2, getDriver().getCurrentUrl() + "#nspages_treesstandard_treesection1", "section1"));
|
||||
expectedTOCLinks.add(new TOCLink(3, getDriver().getCurrentUrl() + "#nspages_treesstandard_treesection1subsection1start", "subsection1"));
|
||||
expectedTOCLinks.add(new TOCLink(3, getDriver().getCurrentUrl() + "#nspages_treesstandard_treesection1subsection2start", "subsection2"));
|
||||
expectedTOCLinks.add(new TOCLink(3, getDriver().getCurrentUrl() + "#nspages_treesstandard_treesection1subsection3", "subsection3"));
|
||||
expectedTOCLinks.add(new TOCLink(2, getDriver().getCurrentUrl() + "#nspages_treesstandard_treesection2start", "section2"));
|
||||
expectedTOCLinks.add(new TOCLink(2, getDriver().getCurrentUrl() + "#nspages_treesstandard_treesection3start", "section3"));
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
}
|
||||
|
||||
/**
|
||||
* the -usePictures printer doesn't use the same code as the other in order to implement this feature
|
||||
* hence those ad hoc tests
|
||||
*/
|
||||
@Test
|
||||
public void withPicturesButNotTheOption(){
|
||||
generatePage(ns + ":start", addTitlesInOrderToHaveAToc("<nspages -subns -nopages -usePictures>"));
|
||||
|
||||
// Assert links don't have any html id
|
||||
List<String> expectedIds = new ArrayList<>();
|
||||
expectedIds.add("");
|
||||
expectedIds.add("");
|
||||
expectedIds.add("");
|
||||
List<WebElement> actualPictures = getPictureLinks();
|
||||
assertEquals(expectedIds.size(), actualPictures.size());
|
||||
for(int idx=0 ; idx < expectedIds.size() ; idx++){
|
||||
assertEquals(expectedIds.get(idx), getHtmlId(actualPictures.get(idx)));
|
||||
}
|
||||
|
||||
// Assert the TOC doesn't have nspages
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withPicturesAndOption(){
|
||||
generatePage(ns + ":start", addTitlesInOrderToHaveAToc("<nspages -subns -nopages -includeItemsInTOC -usePictures>"));
|
||||
|
||||
// Assert links have the expected html id
|
||||
List<String> expectedIds = new ArrayList<>();
|
||||
expectedIds.add("nspages_" + ns + "astart");
|
||||
expectedIds.add("nspages_" + ns + "aastart");
|
||||
expectedIds.add("nspages_" + ns + "bstart");
|
||||
List<WebElement> actualPictures = getPictureLinks();
|
||||
assertEquals(expectedIds.size(), actualPictures.size());
|
||||
for(int idx=0 ; idx < expectedIds.size() ; idx++){
|
||||
assertEquals(expectedIds.get(idx), getHtmlId(actualPictures.get(idx)));
|
||||
}
|
||||
|
||||
// Assert the TOC has the expected links
|
||||
List<TOCLink> expectedTOCLinks = expectedFirstTOCLinks();
|
||||
expectedTOCLinks.addAll(expectedNsPagesTOCLinksForNsOnly());
|
||||
assertSameTOC(expectedTOCLinks);
|
||||
}
|
||||
|
||||
private void assertSameTOC(List<TOCLink> expectedLinks){
|
||||
List<TOCLink> actualLinks = getActualTocLinks();
|
||||
|
||||
assertEquals(expectedLinks.size(), actualLinks.size());
|
||||
for(int numLink = 0 ; numLink < expectedLinks.size() ; numLink++ ){
|
||||
assertEquals(expectedLinks.get(numLink), actualLinks.get(numLink));
|
||||
}
|
||||
}
|
||||
|
||||
private List<TOCLink> getActualTocLinks(){
|
||||
WebElement tocRoot = getDriver().findElement(By.id("dw__toc"));
|
||||
return getTocLevelLinks(tocRoot, 1);
|
||||
}
|
||||
|
||||
private List<TOCLink> getTocLevelLinks(WebElement currentRoot, int nextLevel){
|
||||
List<TOCLink> tocLevelLinks = new ArrayList<>();
|
||||
for(WebElement nextLevelItem : currentRoot.findElements(By.className("level" + nextLevel))){
|
||||
WebElement link = nextLevelItem.findElement(By.xpath("./div/a"));
|
||||
tocLevelLinks.add(new TOCLink(nextLevel, link.getAttribute("href"), link.getAttribute("innerHTML")));
|
||||
tocLevelLinks.addAll(getTocLevelLinks(nextLevelItem, nextLevel+1));
|
||||
}
|
||||
return tocLevelLinks;
|
||||
}
|
||||
|
||||
static class TOCLink {
|
||||
private final int level;
|
||||
private final String target;
|
||||
private final String text;
|
||||
|
||||
public TOCLink(int level, String target, String text){
|
||||
this.level = level;
|
||||
this.target = target;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {return false;}
|
||||
if (obj.getClass() != this.getClass()) {return false;}
|
||||
final TOCLink other = (TOCLink) obj;
|
||||
return other.level == level && other.target.equals(target) && other.text.equals(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){return "TOCLink[" + level + ", " + target + ", " + text + "]";}
|
||||
}
|
||||
|
||||
private static String addTitlesInOrderToHaveAToc(String pageContent){
|
||||
return "======A======\n"
|
||||
+ "======B======\n"
|
||||
+ "======C======\n"
|
||||
+ pageContent;
|
||||
}
|
||||
|
||||
private List<TOCLink> expectedFirstTOCLinks(){
|
||||
List<TOCLink> expectedFirstTOCLinks = new ArrayList<>();
|
||||
expectedFirstTOCLinks.add(new TOCLink(1, getDriver().getCurrentUrl() + "#a", "A"));
|
||||
expectedFirstTOCLinks.add(new TOCLink(1, getDriver().getCurrentUrl() + "#b", "B"));
|
||||
expectedFirstTOCLinks.add(new TOCLink(1 ,getDriver().getCurrentUrl() + "#c", "C"));
|
||||
return expectedFirstTOCLinks;
|
||||
}
|
||||
|
||||
private List<TOCLink> expectedNsPagesTOCLinks(){
|
||||
return expectedNsPagesTOCLinks("", 1, true);
|
||||
}
|
||||
|
||||
private List<TOCLink> expectedNsPagesTOCLinks(int lastTitleLevel){
|
||||
return expectedNsPagesTOCLinks("", lastTitleLevel, true);
|
||||
}
|
||||
|
||||
private List<TOCLink> expectedNsPagesTOCLinks(String dedupIdPrefix){
|
||||
return expectedNsPagesTOCLinks(dedupIdPrefix, 1, true);
|
||||
}
|
||||
|
||||
private List<TOCLink> expectedNsPagesTOCLinksForNsOnly(){
|
||||
return expectedNsPagesTOCLinks("", 1, false);
|
||||
}
|
||||
|
||||
private List<TOCLink> expectedNsPagesTOCLinks(String dedupIdPrefix, int lastTitleLevel, boolean withPages){
|
||||
List<TOCLink> expectedTOCLinks = new ArrayList<>();
|
||||
expectedTOCLinks.add(new TOCLink(1 + lastTitleLevel, getDriver().getCurrentUrl() + "#nspages_" + ns + "astart" + dedupIdPrefix, "a"));
|
||||
expectedTOCLinks.add(new TOCLink(1 + lastTitleLevel, getDriver().getCurrentUrl() + "#nspages_" + ns + "aastart" + dedupIdPrefix, "aa"));
|
||||
expectedTOCLinks.add(new TOCLink(1 + lastTitleLevel,getDriver().getCurrentUrl() + "#nspages_" + ns + "bstart" + dedupIdPrefix, "b"));
|
||||
if (withPages) {
|
||||
expectedTOCLinks.add(new TOCLink(1 + lastTitleLevel, getDriver().getCurrentUrl() + "#nspages_" + ns + "start" + dedupIdPrefix, "start"));
|
||||
}
|
||||
return expectedTOCLinks;
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
public class Test_nbCols extends Helper {
|
||||
@Test
|
||||
public void implicitDefaultNbCols(){
|
||||
generatePage("nbcols:start", "<nspages>");
|
||||
assertNbCols(3, getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void implicitSmallNbOfCols(){
|
||||
generatePage("autrens:start", "<nspages>");
|
||||
assertNbCols(2, getDriver());
|
||||
|
||||
generatePage("subns:start", "<nspages>");
|
||||
assertNbCols(1, getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitNbOfCols(){
|
||||
generatePage("nbcols:start", "<nspages -nbCol 4>");
|
||||
assertNbCols(4, getDriver());
|
||||
|
||||
generatePage("nbcols:start", "<nspages -nbCol \"5\">");
|
||||
assertNbCols(5, getDriver());
|
||||
|
||||
generatePage("nbcols:start", "<nspages -nbCol=6>");
|
||||
assertNbCols(6, getDriver());
|
||||
|
||||
generatePage("nbcols:start", "<nspages -nbCol = \"7\">");
|
||||
assertNbCols(7, getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitTooBigNbOfCols(){
|
||||
generatePage("nbcols:start", "<nspages -nbCol 666>");
|
||||
assertNbCols(18, getDriver());
|
||||
}
|
||||
|
||||
private void assertNbCols(int expectedNbCols, WebDriver driver){
|
||||
assertEquals(expectedNbCols, getColumns().size());
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_nbItemsMax extends Helper {
|
||||
@Test
|
||||
public void withoutTheOptionPrintsEachElements(){
|
||||
generatePage("nbcols:start", "<nspages>");
|
||||
assertNbItems(18, getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withTheOptionLimitTheNumberOfItems(){
|
||||
generatePage("nbcols:start", "<nspages -nbItemsMax=5>");
|
||||
assertNbItems(5, getDriver());
|
||||
}
|
||||
|
||||
private void assertNbItems(int expectedNbItems, WebDriver driver){
|
||||
int actualNbItems = 0;
|
||||
|
||||
for(WebElement column : getColumns()){
|
||||
actualNbItems += column.findElements(By.className("level1")).size();
|
||||
}
|
||||
|
||||
assertEquals(expectedNbItems, actualNbItems);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_nopages extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("nopages:start", "<nspages>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(1, sections.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("nopages:start", "<nspages -nopages>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(0, sections.size());
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.matchers.JUnitMatchers;
|
||||
|
||||
public class Test_nsPath extends Helper {
|
||||
@Test
|
||||
public void defaultPath(){
|
||||
generatePage("autrens:start", "<nspages>");
|
||||
assertSameLinks(currentNsLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitDefaultPath(){
|
||||
generatePage("autrens:start", "<nspages .>");
|
||||
assertSameLinks(currentNsLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsafePath(){
|
||||
generatePage("autrens:start", "<nspages ..:..>");
|
||||
assertThat(getDriver().getPageSource(), JUnitMatchers.containsString("this namespace doesn't exist:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relativePath(){
|
||||
generatePage("autrens:start", "<nspages ..:pregpages>");
|
||||
assertSameLinks(pregPagesNsLinks());
|
||||
|
||||
generatePage("autrens:start", "<nspages .:..:pregpages>");
|
||||
assertSameLinks(pregPagesNsLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void absolutePath(){
|
||||
generatePage("autrens:start", "<nspages :pregpages>");
|
||||
assertSameLinks(pregPagesNsLinks());
|
||||
}
|
||||
|
||||
private List<InternalLink> currentNsLinks(){
|
||||
List<InternalLink> links = new ArrayList<InternalLink>();
|
||||
links.add(new InternalLink("autrens:start", "start"));
|
||||
links.add(new InternalLink("autrens:subpage", "subpage"));
|
||||
return links;
|
||||
}
|
||||
|
||||
private List<InternalLink> pregPagesNsLinks(){
|
||||
List<InternalLink> links = new ArrayList<InternalLink>();
|
||||
links.add(new InternalLink("pregpages:1p", "1p"));
|
||||
links.add(new InternalLink("pregpages:1p1", "1p1"));
|
||||
links.add(new InternalLink("pregpages:p1", "p1"));
|
||||
links.add(new InternalLink("pregpages:start", "start"));
|
||||
return links;
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_pagesInNs extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("pagesinns:start", "<nspages -subns>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(2, sections.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("pagesinns:start", "<nspages -subns -pagesInNs>");
|
||||
|
||||
List<WebElement> sections = getDriver().findElements(By.className("catpageheadline"));
|
||||
assertEquals(1, sections.size());
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pagesinns:start", "start"));
|
||||
expectedLinks.add(new InternalLink("pagesinns:subns:start", "subns"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_pregNs extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("pregns:start", "<nspages -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregns:p1:start", "p1"));
|
||||
expectedLinks.add(new InternalLink("pregns:p2:start", "p2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOn(){
|
||||
generatePage("pregns:start", "<nspages -pregNSOn=\"/1$/\" -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregns:p1:start", "p1"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOff(){
|
||||
generatePage("pregns:start", "<nspages -pregNSOff=\"/1$/\" -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregns:p2:start", "p2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_pregNsTitle extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("pregns:start", "<nspages -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregns:p1:start", "p1"));
|
||||
expectedLinks.add(new InternalLink("pregns:p2:start", "p2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOn(){
|
||||
generatePage("pregns:start", "<nspages -pregNSTitleOn=\"/A$/\" -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregns:p1:start", "p1"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOff(){
|
||||
generatePage("pregns:start", "<nspages -pregNSTitleOff=\"/A$/\" -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregns:p2:start", "p2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_pregPages extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("pregpages:start", "<nspages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:1p", "1p"));
|
||||
expectedLinks.add(new InternalLink("pregpages:1p1", "1p1"));
|
||||
expectedLinks.add(new InternalLink("pregpages:p1", "p1"));
|
||||
expectedLinks.add(new InternalLink("pregpages:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOn(){
|
||||
generatePage("pregpages:start", "<nspages -pregPagesOn=\"/1$/\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:1p1", "1p1"));
|
||||
expectedLinks.add(new InternalLink("pregpages:p1", "p1"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOff(){
|
||||
generatePage("pregpages:start", "<nspages -pregPagesOff=\"/1$/\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:1p", "1p"));
|
||||
expectedLinks.add(new InternalLink("pregpages:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSeveralPreg(){
|
||||
generatePage("pregpages:start", "<nspages -pregPagesOff=\"/1$/\" -pregPagesOff=\"/p$/\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_pregPagesTitle extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("pregpages:start", "<nspages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:1p", "1p"));
|
||||
expectedLinks.add(new InternalLink("pregpages:1p1", "1p1"));
|
||||
expectedLinks.add(new InternalLink("pregpages:p1", "p1"));
|
||||
expectedLinks.add(new InternalLink("pregpages:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOn(){
|
||||
generatePage("pregpages:start", "<nspages -pregPagesTitleOn=\"/Title/\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:1p", "1p"));
|
||||
expectedLinks.add(new InternalLink("pregpages:1p1", "1p1"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionOff(){
|
||||
generatePage("pregpages:start", "<nspages -pregPageTitleOff=\"/Title/\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:p1", "p1"));
|
||||
expectedLinks.add(new InternalLink("pregpages:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSeveralPreg(){
|
||||
generatePage("pregpages:start", "<nspages -pregPagesTitleOff=\"/^A/\" -pregPagesTitleOff=\"/^C/\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("pregpages:1p", "1p"));
|
||||
expectedLinks.add(new InternalLink("pregpages:start", "start"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_recurseAndExcludeSubNs extends Helper {
|
||||
@Test
|
||||
public void withoutExclusion(){
|
||||
generatePage("recurse_and_exclude_ns:start", "<nspages -r -h1 -exclude>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("recurse_and_exclude_ns:subns1:subns1", "Subns1"));
|
||||
expectedLinks.add(new InternalLink("recurse_and_exclude_ns:subns2:subns2", "Subns2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withExclusion(){
|
||||
generatePage("recurse_and_exclude_ns:start", "<nspages -r -h1 -exclude -exclude:subns1:>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("recurse_and_exclude_ns:subns2:subns2", "Subns2"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludeInnerNs(){
|
||||
generatePage("recurse_and_exclude_inner_ns:start", "<nspages -h1 -r -exclude -exclude:ns_to_exclude:>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("recurse_and_exclude_inner_ns:ns0:ns1:ns_to_keep:page", "To Keep"));
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_recursion extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("recursion:start", "<nspages -subns>");
|
||||
assertSameNsAndPagesLinks(level1NsLinks(), level1PagesLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levelOfRecursionOf1IsSameAsDefault(){
|
||||
generatePage("recursion:start", "<nspages -subns -r 1>");
|
||||
assertSameNsAndPagesLinks(level1NsLinks(), level1PagesLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levelOfRecursionLimited(){
|
||||
generatePage("recursion:start", "<nspages -subns -r 2>");
|
||||
assertSameNsAndPagesLinks(level2NsLinks(), level2PagesLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unlimitedRecursion(){
|
||||
generatePage("recursion:start", "<nspages -subns -r 0>");
|
||||
assertSameNsAndPagesLinks(allNsLinks(), allPagesLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alternativeSyntaxes(){
|
||||
generatePage("recursion:start", "<nspages -subns -r=2>");
|
||||
assertSameNsAndPagesLinks(level2NsLinks(), level2PagesLinks());
|
||||
|
||||
generatePage("recursion:start", "<nspages -subns -r \"2\">");
|
||||
assertSameNsAndPagesLinks(level2NsLinks(), level2PagesLinks());
|
||||
|
||||
generatePage("recursion:start", "<nspages -subns -r = \"2\">");
|
||||
assertSameNsAndPagesLinks(level2NsLinks(), level2PagesLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
//Because we had conflict in option parsing. See #30
|
||||
public void alongWithExcludeOption(){
|
||||
generatePage("recursion:start", "<nspages -subns -r -exclude:start>");
|
||||
assertSameNsAndPagesLinks(allNsLinks(), allPagesLinks(true));
|
||||
}
|
||||
|
||||
private List<InternalLink> allNsLinks(){
|
||||
return level2NsLinks();
|
||||
}
|
||||
|
||||
private List<InternalLink> allPagesLinks(){
|
||||
return allPagesLinks(false);
|
||||
}
|
||||
|
||||
private List<InternalLink> allPagesLinks(boolean excludeStart){
|
||||
List<InternalLink> links = level2PagesLinks(excludeStart);
|
||||
links.add(2, new InternalLink("recursion:lvl2:lvl3:pagelvl3", "pagelvl3"));
|
||||
return links;
|
||||
}
|
||||
|
||||
private List<InternalLink> level2NsLinks(){
|
||||
List<InternalLink> links = level1NsLinks();
|
||||
links.add(new InternalLink("recursion:lvl2:lvl3:start", "lvl3"));
|
||||
return links;
|
||||
}
|
||||
|
||||
private List<InternalLink> level2PagesLinks(){
|
||||
return level2PagesLinks(false);
|
||||
}
|
||||
|
||||
private List<InternalLink> level2PagesLinks(boolean excludeStart){
|
||||
List<InternalLink> links = level1PagesLinks(excludeStart);
|
||||
links.add(1, new InternalLink("recursion:lvl2:pagelvl2", "pagelvl2"));
|
||||
return links;
|
||||
}
|
||||
|
||||
private List<InternalLink> level1NsLinks(){
|
||||
List<InternalLink> links = new ArrayList<InternalLink>();
|
||||
links.add(new InternalLink("recursion:lvl2:start", "lvl2"));
|
||||
return links;
|
||||
}
|
||||
|
||||
private List<InternalLink> level1PagesLinks(){
|
||||
return level1PagesLinks(false);
|
||||
}
|
||||
|
||||
private List<InternalLink> level1PagesLinks(boolean excludeStart){
|
||||
List<InternalLink> links = new ArrayList<InternalLink>();
|
||||
links.add(new InternalLink("recursion:pagelvl1", "pagelvl1"));
|
||||
if ( ! excludeStart ){
|
||||
links.add(new InternalLink("recursion:start", "start"));
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//<nspages -subns>
|
||||
//<nspages -subns -R 1>
|
||||
//<nspages -subns -r 2>
|
||||
//<nspages -subns -r>
|
||||
//<nspages -subns -r = "2">
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class Test_reverse extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("reverse:start", "<nspages .>");
|
||||
assertSameLinks(currentLinks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("reverse:start", "<nspages -reverse>");
|
||||
assertSameLinks(Lists.reverse(currentLinks()));
|
||||
}
|
||||
|
||||
private List<InternalLink> currentLinks(){
|
||||
List<InternalLink> links = new ArrayList<InternalLink>();
|
||||
links.add(new InternalLink("reverse:a", "a"));
|
||||
links.add(new InternalLink("reverse:b", "b"));
|
||||
links.add(new InternalLink("reverse:c", "c"));
|
||||
links.add(new InternalLink("reverse:start", "start"));
|
||||
return links;
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package nspages;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Those tests relies on the creation date of three pages. The test wiki is configured in a way that:
|
||||
* - old_page is the page created first
|
||||
* - new_page has been created in second
|
||||
* - recent_page has been created last
|
||||
*/
|
||||
public class Test_sortByMetadata extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("sort_by_metadata:start", "<nspages -exclude>");
|
||||
|
||||
// Option isn't set => we should expect alphabetical order, as usual
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(buildInternalLink("new_page"));
|
||||
expectedLinks.add(buildInternalLink("old_page"));
|
||||
expectedLinks.add(buildInternalLink("recent_page"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("sort_by_metadata:start", "<nspages -exclude -sortByMetadata=\"date.created\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(buildInternalLink("old_page"));
|
||||
expectedLinks.add(buildInternalLink("new_page"));
|
||||
expectedLinks.add(buildInternalLink("recent_page"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOptionAndReverse(){
|
||||
generatePage("sort_by_metadata:start", "<nspages -exclude -reverse -sortByMetadata=\"date.created\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<>();
|
||||
expectedLinks.add(buildInternalLink("recent_page"));
|
||||
expectedLinks.add(buildInternalLink("new_page"));
|
||||
expectedLinks.add(buildInternalLink("old_page"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
private InternalLink buildInternalLink(String page){
|
||||
return new InternalLink("sort_by_metadata:" + page, page);
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_sortDate extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("ns1:start", "<nspages -h1 -exclude>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("ns1:a", "a"));
|
||||
expectedLinks.add(new InternalLink("ns1:b1", "b1"));
|
||||
expectedLinks.add(new InternalLink("ns1:b2", "b2"));
|
||||
expectedLinks.add(new InternalLink("ns1:c", "c"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("ns1:start", "<nspages -h1 -sortDate -exclude>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("ns1:a", "a"));
|
||||
expectedLinks.add(new InternalLink("ns1:b2", "b2"));
|
||||
expectedLinks.add(new InternalLink("ns1:c", "c"));
|
||||
expectedLinks.add(new InternalLink("ns1:b1", "b1"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNbMaxItems(){
|
||||
generatePage("ns1:start", "<nspages -h1 -sortDate -exclude -nbItemsMax=3>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("ns1:a", "a"));
|
||||
expectedLinks.add(new InternalLink("ns1:b2", "b2"));
|
||||
expectedLinks.add(new InternalLink("ns1:c", "c"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package nspages;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Test_sortDictOrder extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("start", "<nspages .:dictorder -h1>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("dictorder:apfel", "apfel"));
|
||||
expectedLinks.add(new InternalLink("dictorder:unterfuhrung", "Unterführung"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("start", "<nspages .:dictorder -h1 -dictOrder=\"sk_SK\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("dictorder:unterfuhrung", "Unterführung"));
|
||||
expectedLinks.add(new InternalLink("dictorder:apfel", "apfel"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withShortOption(){
|
||||
generatePage("start", "<nspages .:dictorder -h1 -dictionaryOrder=\"sk_SK\">");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("dictorder:unterfuhrung", "Unterführung"));
|
||||
expectedLinks.add(new InternalLink("dictorder:apfel", "apfel"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_sortNaturalOrder extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("start", "<nspages .:natural_sort>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("natural_sort:10", "10"));
|
||||
expectedLinks.add(new InternalLink("natural_sort:2a", "2a"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("start", "<nspages -naturalOrder .:natural_sort>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("natural_sort:2a", "2a"));
|
||||
expectedLinks.add(new InternalLink("natural_sort:10", "10"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withShortOption(){
|
||||
generatePage("start", "<nspages -natOrder .:natural_sort>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("natural_sort:2a", "2a"));
|
||||
expectedLinks.add(new InternalLink("natural_sort:10", "10"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_sortid extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("sortid:start", "<nspages -h1 >");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("sortid:y", "B"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:a", "Z"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("sortid:start", "<nspages -h1 -sortid>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("sortid:a", "Z"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:y", "B"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionWithNs(){
|
||||
generatePage("sortid:start", "<nspages -sortId -subns -h1 -pagesInNs>");
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("sortid:a", "Z"));
|
||||
expectedLinks.add(new InternalLink("sortid:c:start", "c"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:y", "B"));
|
||||
expectedLinks.add(new InternalLink("sortid:z:start", "Subdir"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package nspages;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
|
||||
|
||||
public class Test_subns extends Helper {
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("subns:start", "<nspages -subns>");
|
||||
|
||||
WebDriver driver = getDriver();
|
||||
List<WebElement> sections = driver.findElements(By.className("catpageheadline"));
|
||||
|
||||
assertEquals(2, sections.size());
|
||||
|
||||
assertExpectedNsSection(sections.get(0));
|
||||
assertExpectedPagesSection(sections.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("subns:start", "<nspages>");
|
||||
WebDriver driver = getDriver();
|
||||
List<WebElement> sections = driver.findElements(By.className("catpageheadline"));
|
||||
|
||||
assertEquals(1, sections.size());
|
||||
|
||||
assertExpectedPagesSection(sections.get(0));
|
||||
}
|
||||
|
||||
private void assertExpectedNsSection(WebElement nsSection){
|
||||
assertEquals("Subnamespaces:", nsSection.getAttribute("innerHTML"));
|
||||
|
||||
WebElement column = getNextSibling(nsSection);
|
||||
|
||||
WebElement colHeader = column.findElement(By.className("catpagechars"));
|
||||
assertEquals("S", colHeader.getAttribute("innerHTML"));
|
||||
|
||||
List<WebElement> links = getLinksBeneath(column);
|
||||
assertEquals(1, links.size());
|
||||
WebElement link = links.get(0);
|
||||
assertEquals("subsubns",link.getAttribute("innerHTML"));
|
||||
assertEquals(Helper.baseUrl + "?id=subns:subsubns:start", link.getAttribute("href"));
|
||||
}
|
||||
|
||||
private void assertExpectedPagesSection(WebElement pageSection){
|
||||
assertEquals("Pages in this namespace:", pageSection.getAttribute("innerHTML"));
|
||||
|
||||
WebElement column = getNextSibling(pageSection);
|
||||
|
||||
WebElement colHeader = column.findElement(By.className("catpagechars"));
|
||||
assertEquals("S", colHeader.getAttribute("innerHTML"));
|
||||
|
||||
List<WebElement> links = getLinksBeneath(column);
|
||||
assertEquals(1, links.size());
|
||||
WebElement link = links.get(0);
|
||||
assertEquals("start",link.getAttribute("innerHTML"));
|
||||
assertEquals(Helper.baseUrl + "?id=subns:start", link.getAttribute("href"));
|
||||
}
|
||||
|
||||
private List<WebElement> getLinksBeneath(WebElement element){
|
||||
return element.findElements(By.tagName("a"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_surroundingDiv extends Helper {
|
||||
@Test
|
||||
public void isSurroundedByADiv(){
|
||||
generatePage("start", "<nspages>");
|
||||
assertHasExactlyOneDivWithClassName("plugin_nspages");
|
||||
}
|
||||
|
||||
private void assertHasExactlyOneDivWithClassName(String className) {
|
||||
List<WebElement> div = getDriver().findElements(By.className(className));
|
||||
assertEquals(1, div.size());
|
||||
assertEquals("div", div.get(0).getTagName());
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_textNs extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("textns:start", "<nspages -subns -nopages>");
|
||||
assertNsText("Subnamespaces:", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("textns:start", "<nspages -subns -nopages -textNS=\"List of namespaces\">");
|
||||
assertNsText("List of namespaces", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withUnsafeText(){
|
||||
generatePage("textns:start", "<nspages -subns -nopages -textNS=\"<Danger\">");
|
||||
assertNsText("<Danger", getDriver());
|
||||
}
|
||||
|
||||
private void assertNsText(String expectedText, WebDriver driver){
|
||||
WebElement element = getDriver().findElement(By.className("catpageheadline"));
|
||||
assertEquals(expectedText, element.getAttribute("innerHTML"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package nspages;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_textPages extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("textpages:start", "<nspages>");
|
||||
assertNsText("Pages in this namespace:", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withOption(){
|
||||
generatePage("textpages:start", "<nspages -textPages=\"Custom text\">");
|
||||
assertNsText("Custom text", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withUnsafeText(){
|
||||
generatePage("textpages:start", "<nspages -textPages=\"<Danger\">");
|
||||
assertNsText("<Danger", getDriver());
|
||||
}
|
||||
|
||||
private void assertNsText(String expectedText, WebDriver driver){
|
||||
WebElement element = getDriver().findElement(By.className("catpageheadline"));
|
||||
assertEquals(expectedText, element.getAttribute("innerHTML"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_titleForNs extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("titlens:start", "<nspages -subns -nopages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("titlens:subns1:start", "subns1"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns2_main_page:subns2_main_page", "subns2_main_page"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns_titleless:start", "subns_titleless"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withTitleOption(){
|
||||
generatePage("titlens:start", "<nspages -subns -nopages -title>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("titlens:subns1:start", "1st subns"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns2_main_page:subns2_main_page", "ns 'playground'-style"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns_titleless:start", "subns_titleless"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withH1Alias(){
|
||||
generatePage("titlens:start", "<nspages -subns -nopages -h1>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("titlens:subns1:start", "1st subns"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns2_main_page:subns2_main_page", "ns 'playground'-style"));
|
||||
expectedLinks.add(new InternalLink("titlens:subns_titleless:start", "subns_titleless"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_titleForPages extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("sortid:start", "<nspages>");
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
|
||||
expectedLinks.add(new InternalLink("sortid:a", "a"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:y", "y"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withTitleOption(){
|
||||
generatePage("sortid:start", "<nspages -title>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("sortid:y", "B"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:a", "Z"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withH1Alias(){
|
||||
generatePage("sortid:start", "<nspages -h1>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("sortid:y", "B"));
|
||||
expectedLinks.add(new InternalLink("sortid:start", "start"));
|
||||
expectedLinks.add(new InternalLink("sortid:a", "Z"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package nspages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_utf8 extends Helper {
|
||||
@Test
|
||||
public void nsWithSpecialChars(){
|
||||
generatePage("utf8:start", "<nspages>");
|
||||
|
||||
List<InternalLink> expectedLinks = new ArrayList<InternalLink>();
|
||||
expectedLinks.add(new InternalLink("utf8:ea", "ea"));
|
||||
expectedLinks.add(new InternalLink("utf8:e%E0%AC%8Bae", "eଋae"));
|
||||
expectedLinks.add(new InternalLink("utf8:start", "start"));
|
||||
expectedLinks.add(new InternalLink("utf8:%E0%AC%8Beae", "ଋeae"));
|
||||
expectedLinks.add(new InternalLink("utf8:%F0%90%A4%81eae", "𐤁eae"));
|
||||
|
||||
assertSameLinks(expectedLinks);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package nspages.printers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nspages.Helper;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_ColumnHeaders extends Helper {
|
||||
@Test
|
||||
public void newChar(){
|
||||
generatePage("ns1:start", "<nspages>");
|
||||
|
||||
List<WebElement> headers = getDriver().findElements(By.className("catpagechars"));
|
||||
|
||||
assertEquals(5, headers.size());
|
||||
assertHeaderName("A", headers.get(0));
|
||||
assertHeaderName("B", headers.get(1));
|
||||
assertHeaderName("C", headers.get(3));
|
||||
assertHeaderName("S", headers.get(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void continuedChar(){
|
||||
generatePage("ns1:start", "<nspages>");
|
||||
|
||||
List<WebElement> headers = getDriver().findElements(By.className("catpagechars"));
|
||||
|
||||
assertHeaderName("B cont.", headers.get(2));
|
||||
}
|
||||
|
||||
private void assertHeaderName(String expectedName, WebElement header){
|
||||
assertEquals(expectedName, header.getAttribute("innerHTML"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
package nspages.printers;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nspages.Helper;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_anchorName extends Helper {
|
||||
@Test
|
||||
public void withoutOption(){
|
||||
generatePage("ns1:start", "<nspages -exclude >");
|
||||
List<WebElement> headers = getDriver().findElements(By.className("catpagechars"));
|
||||
|
||||
assertEquals(4, headers.size());
|
||||
assertDoesntHaveAnchor(headers.get(0));
|
||||
assertDoesntHaveAnchor(headers.get(1));
|
||||
assertDoesntHaveAnchor(headers.get(2));
|
||||
assertDoesntHaveAnchor(headers.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anchorsInHeaders(){
|
||||
generatePage("ns1:start", "<nspages -exclude -anchorName toto >");
|
||||
List<WebElement> headers = getDriver().findElements(By.className("catpagechars"));
|
||||
|
||||
assertEquals(4, headers.size());
|
||||
assertHasAnchor("A", headers.get(0));
|
||||
assertHasAnchor("B", headers.get(1));
|
||||
assertHasAnchor("C", headers.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void permissiveSyntax(){
|
||||
generatePage("ns1:start", "<nspages -exclude -anchorName = toto >");
|
||||
assertHasAnchor("A", getDriver().findElements(By.className("catpagechars")).get(0));
|
||||
|
||||
generatePage("ns1:start", "<nspages -exclude -anchorName=\"toto\" >");
|
||||
assertHasAnchor("A", getDriver().findElements(By.className("catpagechars")).get(0));
|
||||
|
||||
generatePage("ns1:start", "<nspages -exclude -anchorName \"toto\" >");
|
||||
assertHasAnchor("A", getDriver().findElements(By.className("catpagechars")).get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noAnchorInContinuedHeaders(){
|
||||
generatePage("ns1:start", "<nspages -exclude -anchorName toto >");
|
||||
List<WebElement> headers = getDriver().findElements(By.className("catpagechars"));
|
||||
assertDoesntHaveAnchor(headers.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dangerousText(){
|
||||
generatePage("ns1:start", "<nspages -anchorName <test >");
|
||||
assertNoTOC(getDriver());
|
||||
assertTrue(getDriver().getPageSource().contains("-anchorName <test"));
|
||||
|
||||
generatePage("ns1:start", "<nspages -anchorName &test >");
|
||||
assertNoTOC(getDriver());
|
||||
assertTrue(getDriver().getPageSource().contains("-anchorName &test"));
|
||||
}
|
||||
|
||||
private void assertNoTOC(WebDriver driver){
|
||||
assertEquals(0, driver.findElements(By.className("catpagechars")).size());
|
||||
}
|
||||
|
||||
private void assertHasAnchor(String letter, WebElement header){
|
||||
assertEquals("nspages_toto_" + letter, header.getAttribute("id"));
|
||||
}
|
||||
|
||||
private void assertDoesntHaveAnchor(WebElement header){
|
||||
assertEquals("", header.getAttribute("id"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package nspages.printers;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import nspages.Helper;
|
||||
|
||||
public class Test_columnSize extends Helper {
|
||||
@Test
|
||||
public void longestColumnIsTheMostOnTheLeft(){
|
||||
generatePage("ns1:start", "<nspages -exclude>");
|
||||
|
||||
assertEquals(2, columnSize(0));
|
||||
assertEquals(1, columnSize(1));
|
||||
assertEquals(1, columnSize(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallestColumnIsTheMostOnTheRight(){
|
||||
generatePage("ns1:start", "<nspages>");
|
||||
|
||||
assertEquals(2, columnSize(0));
|
||||
assertEquals(2, columnSize(1));
|
||||
assertEquals(1, columnSize(2));
|
||||
}
|
||||
|
||||
private int columnSize(int idxCol){
|
||||
WebElement column = getDriver().findElements(By.className("catpagecol")).get(idxCol);
|
||||
List<WebElement> links = column.findElements(By.tagName("a"));
|
||||
return links.size();
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
package nspages.printers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import nspages.Helper;
|
||||
|
||||
public class Test_pictures extends Helper {
|
||||
@Test
|
||||
public void useFirstImageWhenItExists(){
|
||||
generatePage("pictures:start", "<nspages -exclude -exclude:withnopicture -usePictures>");
|
||||
|
||||
WebElement link = getPictureLinks().get(0);
|
||||
assertTrue(getBackgroundStyle(link).contains("img_in_page.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useImageForNS(){
|
||||
generatePage("pictures:start", "<nspages -subns -nopages -usePictures>");
|
||||
|
||||
WebElement link = getPictureLinks().get(0);
|
||||
assertTrue(getBackgroundStyle(link).contains("img_in_page.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linkHasTheTitleOfThePage(){
|
||||
generatePage("pictures:start", "<nspages -exclude -usePictures>");
|
||||
|
||||
List<WebElement> links = getPictureLinks();
|
||||
assertEquals("withnopicture", links.get(0).getAttribute("title"));
|
||||
assertEquals("withpicture", links.get(1).getAttribute("title"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useServerSideRedimensionedImageToLimitBandwidth(){
|
||||
generatePage("pictures:start", "<nspages -exclude -exclude:withnopicture -usePictures>");
|
||||
|
||||
WebElement link = getPictureLinks().get(0);
|
||||
String backgroundStyle = getBackgroundStyle(link);
|
||||
assertTrue(backgroundStyle.contains("w="));
|
||||
assertTrue(backgroundStyle.contains("h="));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useLogoWhenNoImageInThePage(){
|
||||
generatePage("pictures:start", "<nspages -exclude -exclude:withpicture -usePictures>");
|
||||
|
||||
WebElement link = getPictureLinks().get(0);
|
||||
assertTrue(getBackgroundStyle(link).contains("lib/tpl/dokuwiki/images/logo.png"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withModificationDateOption(){
|
||||
generatePage("pictures:start", "<nspages -exclude -usePictures -displayModificationDate>");
|
||||
|
||||
List<WebElement> links = getPictureLinks();
|
||||
for(WebElement link : links){
|
||||
assertEquals(1, link.findElements(By.className("nspagesPicturesDate")).size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withoutModificationDateOption(){
|
||||
generatePage("pictures:start", "<nspages -exclude -usePictures>");
|
||||
|
||||
List<WebElement> links = getPictureLinks();
|
||||
for(WebElement link : links){
|
||||
assertEquals(0, link.findElements(By.className("nspagesPicturesDate")).size());
|
||||
}
|
||||
}
|
||||
|
||||
private String getBackgroundStyle(WebElement anchorElement){
|
||||
return anchorElement.findElement(By.tagName("div")).getCssValue("background-image");
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package nspages.printers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import nspages.Helper;
|
||||
import nspages.InternalLink;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_simpleLineBreak extends Helper {
|
||||
@Test
|
||||
public void nominalCase(){
|
||||
generatePage("simpleline:start", "<nspages -simpleLineBreak>");
|
||||
|
||||
WebElement header = getDriver().findElement(By.className("catpageheadline"));
|
||||
assertEquals("Pages in this namespace:", header.getAttribute("innerHTML"));
|
||||
|
||||
WebElement firstLink = getNextSibling(header);
|
||||
assertSameLinks(new InternalLink("simpleline:p1", "p1"), firstLink);
|
||||
|
||||
WebElement firstLineBreak = getNextSibling(firstLink);
|
||||
assertEquals("br", firstLineBreak.getTagName());
|
||||
|
||||
WebElement secondLink = getNextSibling(firstLineBreak);
|
||||
assertSameLinks(new InternalLink("simpleline:p2", "p2"), secondLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* This option applies to all display mode.
|
||||
* It is only tested with this one because the test is easier to write.
|
||||
* Since other mode use the same code we don't bother adding a similar test elsewhere.
|
||||
* One exception though: the way the "pictures" mode handle it is a bit particular
|
||||
* so this other mode has its own test.
|
||||
*/
|
||||
@Test
|
||||
public void withModificationDate(){
|
||||
generatePage("simpleline:start", "<nspages -simpleLineBreak -displayModificationDate>");
|
||||
|
||||
WebElement header = getDriver().findElement(By.className("catpageheadline"));
|
||||
|
||||
WebElement firstLink = getNextSibling(header);
|
||||
assertSameLinks(new InternalLink("simpleline:p1", "[2015-04-02] - p1"), firstLink);
|
||||
|
||||
WebElement firstLineBreak = getNextSibling(firstLink);
|
||||
assertEquals("br", firstLineBreak.getTagName());
|
||||
|
||||
WebElement secondLink = getNextSibling(firstLineBreak);
|
||||
assertSameLinks(new InternalLink("simpleline:p2", "[2015-04-03] - p2"), secondLink);
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package nspages.printers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nspages.Helper;
|
||||
import nspages.InternalLink;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_simpleList extends Helper {
|
||||
@Test
|
||||
public void simpleListCase(){
|
||||
generatePage("simpleline:start", "<nspages -simplelist>");
|
||||
assertExpectedOutput("ul");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void numberedListCase(){
|
||||
generatePage("simpleline:start", "<nspages -numberedlist>");
|
||||
assertExpectedOutput("ol");
|
||||
}
|
||||
|
||||
private void assertExpectedOutput(String openingTagName){
|
||||
WebDriver driver = getDriver();
|
||||
WebElement header = driver.findElement(By.className("catpageheadline"));
|
||||
assertEquals("Pages in this namespace:", header.getAttribute("innerHTML"));
|
||||
|
||||
WebElement list = getNextSibling(header);
|
||||
assertEquals(openingTagName, list.getTagName());
|
||||
|
||||
List<WebElement> items = list.findElements(By.xpath("*"));
|
||||
assertEquals(3, items.size());
|
||||
for(WebElement item : items){
|
||||
assertEquals("li", item.getTagName());
|
||||
assertEquals(1, item.findElements(By.tagName("a")).size());
|
||||
}
|
||||
|
||||
assertSameLinks(new InternalLink("simpleline:p1", "p1"), items.get(0).findElement(By.tagName("a")));
|
||||
assertSameLinks(new InternalLink("simpleline:p2", "p2"), items.get(1).findElement(By.tagName("a")));
|
||||
assertSameLinks(new InternalLink("simpleline:start", "start"), items.get(2).findElement(By.tagName("a")));
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package nspages.printers;
|
||||
|
||||
import nspages.Helper;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_simpleline extends Helper {
|
||||
@Test
|
||||
public void simpleLinePrinter(){
|
||||
generatePage("simpleline:start", "<nspages -simpleLine -subns>");
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void withSubnsAndEmptyTextPageEverythingIsOnASingeLine(){
|
||||
//TODO <nspages -simpleLine -subns -textPages="">
|
||||
}
|
||||
|
||||
public void withSubnsAndEmptyTextPageButWithoutWantingPagesThereIsNoEndingComma(){
|
||||
//TODO <nspages -simpleLine -subns -textPages="" -nopages>
|
||||
}
|
||||
|
||||
public void withEmptyTextPageButWithoutNsThereIsNoOpeningComma(){
|
||||
//TODO <nspages -simpleLine -textPages="">
|
||||
}
|
||||
|
||||
public void withSubnsAndEmptyTextPageButWithoutActualPagesThereIsNoEndingComma(){
|
||||
//TODO - <nspages -simpleLine -subns -exclude:p1 -exclude:p2 -exclude -textPages="">
|
||||
}
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
package nspages.printers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nspages.Helper;
|
||||
import nspages.InternalLink;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.NoSuchElementException;
|
||||
|
||||
public class Test_tree extends Helper {
|
||||
/**
|
||||
* This test should display this tree:
|
||||
* +-+ section1
|
||||
* | +-- subsection1
|
||||
* | +-- subsection2
|
||||
* | +-+ subsection3
|
||||
* | +-- subsubsection1
|
||||
* +-- section2
|
||||
* +-- section3
|
||||
*/
|
||||
@Test
|
||||
public void testStandardCase(){
|
||||
generatePage("trees:start", "<nspages -tree -r -subns -nopages .:standard_tree>");
|
||||
assertGotStandardSubnsTree();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void treeIsCorrectlyRenderedEvenFromAPageNotAtTheRootLevel(){
|
||||
generatePage("trees:standard_tree:section1:subsection1:start", "<nspages -tree -r -subns -nopages ..:..>");
|
||||
assertGotStandardSubnsTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check we're correctly displaying the subnamespaces of trees:standard.
|
||||
* This checks
|
||||
* - The html structure
|
||||
* - The links
|
||||
* - The html level classes ("level1", "level2", ...)
|
||||
*/
|
||||
private void assertGotStandardSubnsTree(){
|
||||
// Test 1st level nodes
|
||||
List<WebElement> firstLevelNodes = getFirstLevelChildren();
|
||||
assertEquals(3, firstLevelNodes.size());
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:start", "section1"), 1, firstLevelNodes.get(0));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section2:start", "section2"), 1, firstLevelNodes.get(1));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section3:start", "section3"), 1, firstLevelNodes.get(2));
|
||||
|
||||
// Test 2nd level nodes
|
||||
// Nodes below the 1st one
|
||||
List<WebElement> childrenOfFirstSection = getDirectChildren(firstLevelNodes.get(0));
|
||||
assertEquals(3, childrenOfFirstSection.size());
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:subsection1:start", "subsection1"), 2, childrenOfFirstSection.get(0));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:subsection2:start", "subsection2"), 2, childrenOfFirstSection.get(1));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:subsection3:start", "subsection3"), 2, childrenOfFirstSection.get(2));
|
||||
|
||||
// Other first level nodes should have no child
|
||||
assertEquals(0, getDirectChildren(firstLevelNodes.get(1)).size());
|
||||
assertEquals(0, getDirectChildren(firstLevelNodes.get(2)).size());
|
||||
|
||||
// Test 3rd level node
|
||||
// The first two 2nd-level nodes should have no child
|
||||
assertEquals(0, getDirectChildren(childrenOfFirstSection.get(0)).size());
|
||||
assertEquals(0, getDirectChildren(childrenOfFirstSection.get(1)).size());
|
||||
|
||||
// The third one should have one last child
|
||||
List<WebElement> thirdLevelNodes = getDirectChildren(childrenOfFirstSection.get(2));
|
||||
assertEquals(1, thirdLevelNodes.size());
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:subsection3:subsubsection1:start", "subsubsection1"), 3, thirdLevelNodes.get(0));
|
||||
|
||||
// There should be not 4th level nodes
|
||||
assertEquals(0, getDirectChildren(thirdLevelNodes.get(0)).size());
|
||||
}
|
||||
|
||||
private void assertSameLinksAndLevel(InternalLink expectedLink, int expectedLevel, WebElement actualNode) {
|
||||
assertSameLinks(expectedLink, getSelfLink(actualNode));
|
||||
assertEquals("level" + expectedLevel, actualNode.getAttribute("class"));
|
||||
}
|
||||
|
||||
/**
|
||||
* This should display this tree:
|
||||
* +-+ section1
|
||||
* +-+ section2
|
||||
* +-+ section4
|
||||
*
|
||||
* This is a corner case on which we already had bug because the first node wasn't correctly computed
|
||||
*/
|
||||
@Test
|
||||
public void rootIsCorrectlyComputedEvenInLinearTreeCase(){
|
||||
generatePage("trees:start", "<nspages -tree -r -subns -nopages .:linear_tree>");
|
||||
|
||||
List<WebElement> firstLevelChildren = getFirstLevelChildren();
|
||||
assertEquals(1, firstLevelChildren.size());
|
||||
assertSameLinks(new InternalLink("trees:linear_tree:section1:start", "section1"), getSelfLink(firstLevelChildren.get(0)));
|
||||
|
||||
// This test is only interested in testing the root has been correctly computed. No need for further assertions
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the special case which is fixed by version 2021-03-19 of nspages
|
||||
*/
|
||||
@Test
|
||||
public void pagesAtTheRootOfTheWikiAreCorrectlyHandled(){
|
||||
// We only need one page for this test. More would make the test needlessly more complicated.
|
||||
// So we put a unique title to this page and filter on it with the -pregXXX option
|
||||
generatePage(":", "======Root======\n<nspages -tree -r -h1 -pregPagesTitleOn=\"/Root/\" >");
|
||||
List<WebElement> firstLevelChildren = getFirstLevelChildren();
|
||||
assertEquals(1, firstLevelChildren.size());
|
||||
assertSameLinks(new InternalLink("start", "Root"), getSelfLink(firstLevelChildren.get(0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Building the tree will likely not preserve ordering.
|
||||
* This tests that we still correctly render a tree with every level sorted
|
||||
* (see issue #109)
|
||||
*/
|
||||
@Test
|
||||
public void treeIsCorrectlySorted(){
|
||||
generatePage("trees:start", "<nspages -tree -r -subns -pagesInNs .:tree_tricky_to_sort -exclude>");
|
||||
|
||||
List<WebElement> firstLevelNodes = getFirstLevelChildren();
|
||||
assertSameLinks(new InternalLink("trees:tree_tricky_to_sort:b:start", "b"), getSelfLink(firstLevelNodes.get(0)));
|
||||
assertSameLinks(new InternalLink("trees:tree_tricky_to_sort:d:start", "d"), getSelfLink(firstLevelNodes.get(1)));
|
||||
assertSameLinks(new InternalLink("trees:tree_tricky_to_sort:ns_with_no_main_page:start", "ns_with_no_main_page"), getSelfLink(firstLevelNodes.get(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayingPages(){
|
||||
// Exclude start pages to ensure empty subnamespaces aren't displayed
|
||||
generatePage("trees:start", "<nspages -tree -r .:standard_tree -exclude:start>");
|
||||
|
||||
// Test the first level nodes
|
||||
List<WebElement> firstLevelChildren = getFirstLevelChildren();
|
||||
assertEquals("trees:standard_tree:section1:", getNonLinkNodeInnerHTML(firstLevelChildren.get(0)));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:page_at_root_level", "page_at_root_level"), 1, firstLevelChildren.get(1));
|
||||
|
||||
// Test second level nodes
|
||||
List<WebElement> section1Children = getDirectChildren(firstLevelChildren.get(0));
|
||||
assertEquals("trees:standard_tree:section1:subsection1:", getNonLinkNodeInnerHTML(section1Children.get(0)));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:other_page_at_level2", "other_page_at_level2"), 2, section1Children.get(1));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:page_at_level2", "page_at_level2"), 2, section1Children.get(2));
|
||||
|
||||
// Test third level nodes
|
||||
List<WebElement> thirdLevelNodes = getDirectChildren(section1Children.get(0));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:subsection1:other_page_at_level3", "other_page_at_level3"), 3, thirdLevelNodes.get(0));
|
||||
assertSameLinksAndLevel(new InternalLink("trees:standard_tree:section1:subsection1:page_at_level3", "page_at_level3"), 3, thirdLevelNodes.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canBeCalledAtWikiRoot(){
|
||||
generatePage("start", "<nspages -tree -r>");
|
||||
// No need for assertions: the generatePage method already checks that there are no php warning
|
||||
// and no php error. This is all we need for this test
|
||||
}
|
||||
|
||||
private WebElement getSelfLink(WebElement node){
|
||||
try{
|
||||
return node.findElement(By.xpath("div/a"));
|
||||
}catch (NoSuchElementException e){
|
||||
// When DW renders a link to the current page it adds a <span class="curid">
|
||||
// between the <div class="li"> and the <a> so the previous xpath resolution
|
||||
// would fail in this case. Below is the correct one to use in this case.
|
||||
return node.findElement(By.xpath("div/span/a"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When nspages is called without the -subns flag, then it displays namespace node as text only (no link).
|
||||
* This method retrieve the text of such nodes
|
||||
*/
|
||||
private String getNonLinkNodeInnerHTML(WebElement node){
|
||||
return node.findElement(By.xpath("div")).getAttribute("innerHTML");
|
||||
}
|
||||
|
||||
private List<WebElement> getFirstLevelChildren(){
|
||||
WebElement root = getDriver().findElement(By.cssSelector(".plugin_nspages"));
|
||||
return getDirectChildren(root);
|
||||
}
|
||||
|
||||
private List<WebElement> getDirectChildren(WebElement node){
|
||||
return node.findElements(By.xpath("ul/li"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package nspages.printers;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nspages.Helper;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
public class Test_width extends Helper {
|
||||
@Test
|
||||
public void implicitDefaultNbCols(){
|
||||
generatePage("nbcols:start", "<nspages>");
|
||||
assertPercentWidthForEachColumns("33.33", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitDefaultNbCols(){
|
||||
generatePage("nbcols:start", "<nspages -nbCol 3>");
|
||||
assertPercentWidthForEachColumns("33.33", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void greatNbOfCols(){
|
||||
generatePage("nbcols:start", "<nspages -nbCol 4>");
|
||||
assertPercentWidthForEachColumns("25", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitSmallNbOfCols(){
|
||||
generatePage("nbcols:start", "<nspages -nbCol 2>");
|
||||
assertPercentWidthForEachColumns("50", getDriver());
|
||||
|
||||
generatePage("nbcols:start", "<nspages -nbCol 1>");
|
||||
assertPercentWidthForEachColumns("100", getDriver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void implicitSmallNbOfCols(){
|
||||
generatePage("autrens:start", "<nspages>");
|
||||
assertPercentWidthForEachColumns("50", getDriver());
|
||||
|
||||
generatePage("subns:start", "<nspages>");
|
||||
assertPercentWidthForEachColumns("100", getDriver());
|
||||
}
|
||||
|
||||
private void assertPercentWidthForEachColumns(String percentExpected, WebDriver driver){
|
||||
List<WebElement> columns = driver.findElements(By.className("catpagecol"));
|
||||
for(WebElement col : columns){
|
||||
assertPercentWidth(percentExpected, col);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertPercentWidth(String percentExpected, WebElement element){
|
||||
String style = element.getAttribute("style");
|
||||
style = style.replaceAll(" ", "");
|
||||
assertTrue(style.contains("width:" + percentExpected));
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1 @@
|
||||
a:2:{s:7:"current";a:8:{s:4:"date";a:2:{s:7:"created";i:1613513576;s:8:"modified";i:1613513576;}s:11:"last_change";a:8:{s:4:"date";i:1613513576;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"C";s:2:"id";s:25:"sort_by_metadata:new_page";s:4:"user";s:0:"";s:3:"sum";s:7:"created";s:5:"extra";s:0:"";s:10:"sizechange";i:20;}s:4:"user";s:0:"";s:7:"creator";s:0:"";s:5:"title";s:8:"new page";s:11:"description";a:2:{s:15:"tableofcontents";a:1:{i:0;a:4:{s:3:"hid";s:8:"new_page";s:5:"title";s:8:"new page";s:4:"type";s:2:"ul";s:5:"level";i:1;}}s:8:"abstract";s:8:"new page";}s:8:"internal";a:2:{s:5:"cache";b:1;s:3:"toc";b:1;}s:8:"relation";a:1:{s:10:"firstimage";s:0:"";}}s:10:"persistent";a:4:{s:4:"date";a:1:{s:7:"created";i:1613513576;}s:11:"last_change";a:8:{s:4:"date";i:1613513576;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"C";s:2:"id";s:25:"sort_by_metadata:new_page";s:4:"user";s:0:"";s:3:"sum";s:7:"created";s:5:"extra";s:0:"";s:10:"sizechange";i:20;}s:4:"user";s:0:"";s:7:"creator";s:0:"";}}
|
@@ -0,0 +1 @@
|
||||
a:2:{s:7:"current";a:8:{s:4:"date";a:2:{s:7:"created";i:1613513556;s:8:"modified";i:1613513556;}s:11:"last_change";a:8:{s:4:"date";i:1613513556;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"C";s:2:"id";s:25:"sort_by_metadata:old_page";s:4:"user";s:0:"";s:3:"sum";s:7:"created";s:5:"extra";s:0:"";s:10:"sizechange";i:20;}s:4:"user";s:0:"";s:7:"creator";s:0:"";s:5:"title";s:8:"Old page";s:11:"description";a:2:{s:15:"tableofcontents";a:1:{i:0;a:4:{s:3:"hid";s:8:"old_page";s:5:"title";s:8:"Old page";s:4:"type";s:2:"ul";s:5:"level";i:1;}}s:8:"abstract";s:8:"Old page";}s:8:"internal";a:2:{s:5:"cache";b:1;s:3:"toc";b:1;}s:8:"relation";a:1:{s:10:"firstimage";s:0:"";}}s:10:"persistent";a:4:{s:4:"date";a:1:{s:7:"created";i:1613513556;}s:11:"last_change";a:8:{s:4:"date";i:1613513556;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"C";s:2:"id";s:25:"sort_by_metadata:old_page";s:4:"user";s:0:"";s:3:"sum";s:7:"created";s:5:"extra";s:0:"";s:10:"sizechange";i:20;}s:4:"user";s:0:"";s:7:"creator";s:0:"";}}
|
@@ -0,0 +1 @@
|
||||
a:2:{s:7:"current";a:8:{s:4:"date";a:2:{s:7:"created";i:1613514357;s:8:"modified";i:1613514357;}s:11:"last_change";a:8:{s:4:"date";i:1613514357;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"C";s:2:"id";s:28:"sort_by_metadata:recent_page";s:4:"user";s:0:"";s:3:"sum";s:7:"created";s:5:"extra";s:0:"";s:10:"sizechange";i:23;}s:4:"user";s:0:"";s:7:"creator";s:0:"";s:5:"title";s:11:"Recent page";s:11:"description";a:2:{s:15:"tableofcontents";a:1:{i:0;a:4:{s:3:"hid";s:11:"recent_page";s:5:"title";s:11:"Recent page";s:4:"type";s:2:"ul";s:5:"level";i:1;}}s:8:"abstract";s:11:"Recent page";}s:8:"internal";a:2:{s:5:"cache";b:1;s:3:"toc";b:1;}s:8:"relation";a:1:{s:10:"firstimage";s:0:"";}}s:10:"persistent";a:4:{s:4:"date";a:1:{s:7:"created";i:1613514357;}s:11:"last_change";a:8:{s:4:"date";i:1613514357;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"C";s:2:"id";s:28:"sort_by_metadata:recent_page";s:4:"user";s:0:"";s:3:"sum";s:7:"created";s:5:"extra";s:0:"";s:10:"sizechange";i:23;}s:4:"user";s:0:"";s:7:"creator";s:0:"";}}
|
@@ -0,0 +1 @@
|
||||
mlkj
|
@@ -0,0 +1 @@
|
||||
======apfel======
|
@@ -0,0 +1 @@
|
||||
======Unterführung======
|
@@ -0,0 +1,3 @@
|
||||
======_template======
|
||||
|
||||
This page should be excluded because of the global exclude default conf
|
@@ -0,0 +1 @@
|
||||
======page 1======
|
@@ -0,0 +1 @@
|
||||
======page 2======
|
@@ -0,0 +1 @@
|
||||
a
|
@@ -0,0 +1 @@
|
||||
a
|
@@ -0,0 +1 @@
|
||||
1
|
@@ -0,0 +1 @@
|
||||
10
|
@@ -0,0 +1 @@
|
||||
11
|
@@ -0,0 +1 @@
|
||||
12
|
@@ -0,0 +1 @@
|
||||
13
|
@@ -0,0 +1 @@
|
||||
14
|
@@ -0,0 +1 @@
|
||||
15
|
@@ -0,0 +1 @@
|
||||
16
|
@@ -0,0 +1 @@
|
||||
17
|
@@ -0,0 +1 @@
|
||||
2
|
@@ -0,0 +1 @@
|
||||
3
|
@@ -0,0 +1 @@
|
||||
4
|
@@ -0,0 +1 @@
|
||||
5
|
@@ -0,0 +1 @@
|
||||
6
|
@@ -0,0 +1 @@
|
||||
7
|
@@ -0,0 +1 @@
|
||||
8
|
@@ -0,0 +1 @@
|
||||
9
|
@@ -0,0 +1 @@
|
||||
some page
|
@@ -0,0 +1 @@
|
||||
some page
|
@@ -0,0 +1 @@
|
||||
some page
|
@@ -0,0 +1 @@
|
||||
some page
|
@@ -0,0 +1 @@
|
||||
======Z======
|
@@ -0,0 +1 @@
|
||||
test
|
@@ -0,0 +1 @@
|
||||
======Y======
|
@@ -0,0 +1 @@
|
||||
subns
|
@@ -0,0 +1,2 @@
|
||||
======subns======
|
||||
{{:pictures:img_in_page.jpg?400|}}
|
@@ -0,0 +1 @@
|
||||
======with no picture======
|
@@ -0,0 +1,3 @@
|
||||
======With Picture======
|
||||
|
||||
{{:pictures:img_in_page.jpg?200|}}
|
@@ -0,0 +1 @@
|
||||
<nspages>
|
@@ -0,0 +1 @@
|
||||
====== PlayGround ======
|
@@ -0,0 +1,3 @@
|
||||
======A======
|
||||
|
||||
mlkj
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user