add contents
This commit is contained in:
339
lib/plugins/nspages/LICENSE
Normal file
339
lib/plugins/nspages/LICENSE
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
lib/plugins/nspages/README.md
Normal file
12
lib/plugins/nspages/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
I'm looking for a co-maintainer!
|
||||
|
||||
If you're a user of this plugin, don't worry: I'm still taking care of it, I will make sure it keeps working with future versions of Dokuwiki. But I have much less time than before to dedicate to it, and as a consequence feature requests tend to pile up.
|
||||
|
||||
If you're interested in co-maintaining this plugin, just send me an email (adress available in the commit log).
|
||||
|
||||
---
|
||||
Plugin for Dokuwiki.
|
||||
|
||||
Generate and displays a list of the pages of a namespace.
|
||||
|
||||
See https://www.dokuwiki.org/plugin:nspages for more info about installation and usage.
|
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>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user