[ticket/11805] Do not generate the same link twice

There is no need to generate the prev/next links twice

PHPBB3-11805
[ticket/11805] Add unit tests for pagination

PHPBB3-11805