[CLEANUP] Adjust usage of ContentObjectRenderer->getTreeList()

In ContentObjectRenderer->getQuery() the pid where clause is build
using getTreeList() to fetch recursive pids. But for the inclusion
of the uppermost pid, string concatenation is used.
The method getTreeList() offers the option to include the uppermost
pid into the returned result by passing it as a negative value. Method
getQuery() should use this opportunity instead of doing its own magic.

Additionally some cleanup is done for getTreeList, optimizing the
returned string, and unittests were added.

Resolves: #51067
Resolves: #51503
Releases: 6.2
Change-Id: Ie72103ca66d847cb0eb0f3ef5e33a1896d86de5b
Reviewed-on: https://review.typo3.org/23092
Reviewed-by: Kai Ole Hartwig
Tested-by: Kai Ole Hartwig
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn