-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] CD-167092 Implement service to make footnotes accessible fr…
…om outside
- Loading branch information
Showing
12 changed files
with
179 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
/*************************************************************** | ||
* Copyright notice | ||
* | ||
* (c) 2014 AOE GmbH <[email protected]> | ||
* (c) 2020 AOE GmbH <[email protected]> | ||
* | ||
* All rights reserved | ||
* | ||
|
@@ -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; | ||
|
||
/** | ||
|
@@ -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); | ||
|
@@ -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 | ||
); | ||
|
@@ -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) | ||
{ | ||
|
@@ -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']); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
/*************************************************************** | ||
* Copyright notice | ||
* | ||
* (c) 2014 AOE GmbH <[email protected]> | ||
* (c) 2020 AOE GmbH <[email protected]> | ||
* | ||
* All rights reserved | ||
* | ||
|
@@ -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; | ||
|
||
/** | ||
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.