Skip to content

Commit

Permalink
[FEATURE] CD-167092 Implement service to make footnotes accessible fr…
Browse files Browse the repository at this point in the history
…om outside
  • Loading branch information
srotsch committed Jun 30, 2020
1 parent 8af31b0 commit 7592106
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 11 deletions.
28 changes: 21 additions & 7 deletions Classes/Domain/Repository/FootnoteRepository.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2014 AOE GmbH <[email protected]>
* (c) 2020 AOE GmbH <[email protected]>
*
* All rights reserved
*
Expand All @@ -30,7 +30,9 @@
use PDO;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;

/**
Expand All @@ -56,7 +58,7 @@ class FootnoteRepository extends Repository
*/
public function initializeObject()
{
/** @var $defaultQuerySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
/** @var $defaultQuerySettings Typo3QuerySettings */
$defaultQuerySettings = $this->objectManager->get(Typo3QuerySettings::class);
$defaultQuerySettings->setRespectStoragePage(false);
$defaultQuerySettings->setRespectSysLanguage(false);
Expand Down Expand Up @@ -102,13 +104,13 @@ public function getLowestFreeIndexNumber()
/**
* @param Footnote $object
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws IllegalObjectTypeException
*/
public function add($object)
{
/** @var Footnote $object */
if (false === ($object instanceof Footnote)) {
throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException(
throw new IllegalObjectTypeException(
'The object given to add() was not of the type (' . $this->objectType . ') this repository manages.',
1392911702
);
Expand All @@ -117,9 +119,21 @@ public function add($object)
parent::add($object);
}

/**
* @param integer $uid
* @return Footnote|null
*/
public function getFootnoteByUid($uid)
{
$query = $this->createQuery();
$query->setQuerySettings($this->defaultQuerySettings);

return $query->matching($query->equals('uid', $uid))->execute()->getFirst();
}

/**
* @param array $uids
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
* @return array|QueryResultInterface
*/
public function getFootnotesByUids(array $uids)
{
Expand All @@ -131,13 +145,13 @@ public function getFootnotesByUids(array $uids)
}

/**
* @param array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $queryResult
* @param array|QueryResultInterface $queryResult
* @param $uids
* @return mixed
*/
public function sortFootnotesByUids($queryResult, $uids)
{
if ($queryResult instanceof \TYPO3\CMS\Extbase\Persistence\QueryResultInterface) {
if ($queryResult instanceof QueryResultInterface) {
$queryResult = $queryResult->toArray();
}
usort($queryResult, [$this, 'usortFootnotesByUids']);
Expand Down
54 changes: 54 additions & 0 deletions Classes/Service/FootnoteService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace AOE\HappyFeet\Service;

/***************************************************************
* Copyright notice
*
* (c) 2020 AOE GmbH <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project 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 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use AOE\HappyFeet\Domain\Model\Footnote;
use AOE\HappyFeet\Domain\Repository\FootnoteRepository;

class FootnoteService extends AbstractService
{
/**
* @var FootnoteRepository
*/
private $footnoteRepository;

/**
* @param FootnoteRepository $footnoteRepository
*/
public function __construct(FootnoteRepository $footnoteRepository)
{
$this->footnoteRepository = $footnoteRepository;
}

/**
* @param integer $footnoteId
* @return Footnote|null
*/
public function getFootnoteById($footnoteId)
{
return $this->footnoteRepository->getFootnoteByUid($footnoteId);
}
}
Empty file modified Classes/Service/RenderingService.php
100755 → 100644
Empty file.
Empty file modified Classes/Typo3/Hook/LinkRenderer.php
100755 → 100644
Empty file.
Empty file modified Classes/ViewHelpers/FlatifyViewHelper.php
100755 → 100644
Empty file.
25 changes: 23 additions & 2 deletions Tests/Functional/Domain/Repository/FootnoteRepositoryTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2014 AOE GmbH <[email protected]>
* (c) 2020 AOE GmbH <[email protected]>
*
* All rights reserved
*
Expand All @@ -30,7 +30,7 @@
use Nimut\TestingFramework\TestCase\FunctionalTestCase;
use stdClass;
use Throwable;
use \TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

/**
Expand Down Expand Up @@ -119,6 +119,27 @@ public function shouldGetNextIndexInRow()
$this->assertEquals(3, $lowestIndex);
}

/**
* @test
*/
public function shouldGetFootnoteByUid()
{
$this->importDataSet(__DIR__ . '/fixtures/tx_happyfeet_domain_model_footnote.xml');
$footnote = $this->repository->getFootnoteByUid(1);
$this->assertInstanceOf(Footnote::class, $footnote);
$this->assertEquals(1, $footnote->getUid());
}

/**
* @test
*/
public function shouldReturnNullIfFootnoteNotFound()
{
$this->importDataSet(__DIR__ . '/fixtures/tx_happyfeet_domain_model_footnote.xml');
$footnote = $this->repository->getFootnoteByUid(99);
$this->assertNull($footnote);
}

/**
* @test
*/
Expand Down
2 changes: 0 additions & 2 deletions Tests/Functional/Service/RenderingServiceTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public function setUp()
'groups' => ['system']
];

Bootstrap::getInstance()->initializeCachingFramework();

$footnote1 = $this->getMockBuilder(Footnote::class)->setMethods(['getHeader', 'getDescription', 'getIndexNumber'])->getMock();

$footnote1->_setProperty('uid', 4711);
Expand Down
Empty file modified Tests/Unit/Domain/Model/FootnoteTest.php
100755 → 100644
Empty file.
Empty file modified Tests/Unit/Service/FCEFootnoteServiceTest.php
100755 → 100644
Empty file.
81 changes: 81 additions & 0 deletions Tests/Unit/Service/FootnoteServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
namespace AOE\HappyFeet\Tests\Unit\Service;

/***************************************************************
* Copyright notice
*
* (c) 2020 AOE GmbH <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project 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 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use AOE\HappyFeet\Domain\Model\Footnote;
use AOE\HappyFeet\Domain\Repository\FootnoteRepository;
use AOE\HappyFeet\Service\FootnoteService;
use Nimut\TestingFramework\TestCase\UnitTestCase;

/**
* @package HappyFeet
* @subpackage Service_Test
*/
class FootnoteServiceTest extends UnitTestCase
{
/**
* @var FootnoteRepository
*/
private $footnoteRepository;

/**
* @var FootnoteService
*/
private $footnoteService;

protected function setUp()
{
$this->footnoteRepository = $this
->getMockBuilder(FootnoteRepository::class)
->setMethods(['getFootnoteByUid'])
->disableOriginalConstructor()
->getMock();
$this->footnoteService = new FootnoteService($this->footnoteRepository);
}

/**
* @test
*/
public function shouldGetFootnoteById()
{
$footnote = new Footnote();

$this->footnoteRepository
->method('getFootnoteByUid')
->with(123)
->willReturn($footnote);

$this->assertSame($footnote, $this->footnoteService->getFootnoteById(123));
}

/**
* @test
*/
public function shouldReturnNullIfFootnoteNotFound()
{
$this->assertNull($this->footnoteService->getFootnoteById(456));
}
}
Empty file modified Tests/Unit/Typo3/Hooks/TcemainTest.php
100755 → 100644
Empty file.
Empty file modified Tests/Unit/ViewHelpers/FlatifyViewHelperTest.php
100755 → 100644
Empty file.

0 comments on commit 7592106

Please sign in to comment.