From ee93fac2b7fe8b9802c9f5121a3813d25985b7a3 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 5 Nov 2013 12:41:20 +0100 Subject: [PATCH] [FEATURE] Add missing files for indexAction. --- Classes/Controller/TestimonialController.php | 77 ++++++++++++++++ Configuration/TypoScript/constants.txt | 18 ++++ Configuration/TypoScript/setup.txt | 13 +++ Resources/Private/Layouts/Default.html | 3 + .../Private/Templates/Testimonial/Index.html | 16 ++++ .../Controller/TestimonialControllerTest.php | 91 +++++++++++++++++++ ext_localconf.php | 18 ++++ 7 files changed, 236 insertions(+) create mode 100644 Classes/Controller/TestimonialController.php create mode 100644 Configuration/TypoScript/constants.txt create mode 100644 Configuration/TypoScript/setup.txt create mode 100644 Resources/Private/Layouts/Default.html create mode 100644 Resources/Private/Templates/Testimonial/Index.html create mode 100644 Tests/Unit/Controller/TestimonialControllerTest.php create mode 100644 ext_localconf.php diff --git a/Classes/Controller/TestimonialController.php b/Classes/Controller/TestimonialController.php new file mode 100644 index 0000000..a39dfca --- /dev/null +++ b/Classes/Controller/TestimonialController.php @@ -0,0 +1,77 @@ +, oliverklee.de + * + * 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 2 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 TYPO3\CMS\Extbase\Mvc\Controller\ActionController; +use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; + +use OliverKlee\Tea\Domain\Repository\TestimonialRepository; + +/** + * This controller takes care of displaying testimonials. + * + * @author Oliver Klee + */ +class TestimonialController extends ActionController { + /** + * @var \OliverKlee\Tea\Domain\Repository\TestimonialRepository + */ + protected $testimonialRepository = NULL; + + /** + * Injects the TestimonialRepository. + * + * @param \OliverKlee\Tea\Domain\Repository\TestimonialRepository $repository + * + * @return void + */ + public function injectTestimonialRepository(TestimonialRepository $repository) { + $this->testimonialRepository = $repository; + } + + /** + * Lists all testimonials. + * + * @return void + */ + public function indexAction() { + $this->view->assign('testimonials', $this->testimonialRepository->findAll()); + } + + /** + * Injects the view. + * + * Note: This function is intended for unit-testing purposes only. + * + * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view + * + * @return view + */ + public function setView(ViewInterface $view) { + $this->view = $view; + } +} +?> \ No newline at end of file diff --git a/Configuration/TypoScript/constants.txt b/Configuration/TypoScript/constants.txt new file mode 100644 index 0000000..9997dcb --- /dev/null +++ b/Configuration/TypoScript/constants.txt @@ -0,0 +1,18 @@ +plugin.tx_tea { + view { + # cat=plugin.tx_tea/file; type=string; label=Path to template root (FE) + templateRootPath = EXT:tea/Resources/Private/Templates/ + # cat=plugin.tx_tea/file; type=string; label=Path to template partials (FE) + partialRootPath = EXT:tea/Resources/Private/Partials/ + # cat=plugin.tx_tea/file; type=string; label=Path to template layouts (FE) + layoutRootPath = EXT:tea/Resources/Private/Layouts/ + } + persistence { + # cat=plugin.tx_tea//a; type=string; label=Default storage PID + storagePid = + # cat=plugin.tx_tea//a; type=int; label=UID of the page/folder where all new records will be created + newRecordStoragePid = + } + settings { + } +} \ No newline at end of file diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt new file mode 100644 index 0000000..6e5b131 --- /dev/null +++ b/Configuration/TypoScript/setup.txt @@ -0,0 +1,13 @@ +plugin.tx_tea { + view { + templateRootPath = {$plugin.tx_tea.view.templateRootPath} + partialRootPath = {$plugin.tx_tea.view.partialRootPath} + layoutRootPath = {$plugin.tx_tea.view.layoutRootPath} + } + persistence { + storagePid = {$plugin.tx_tea.persistence.storagePid} + } + features { + rewrittenPropertyMapper = 1 + } +} \ No newline at end of file diff --git a/Resources/Private/Layouts/Default.html b/Resources/Private/Layouts/Default.html new file mode 100644 index 0000000..2b76734 --- /dev/null +++ b/Resources/Private/Layouts/Default.html @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/Resources/Private/Templates/Testimonial/Index.html b/Resources/Private/Templates/Testimonial/Index.html new file mode 100644 index 0000000..754d6d4 --- /dev/null +++ b/Resources/Private/Templates/Testimonial/Index.html @@ -0,0 +1,16 @@ + + + +

+ +

+ + + + {testimonial.dateOfPosting} +

+ + {testimonial.text} + +
+
\ No newline at end of file diff --git a/Tests/Unit/Controller/TestimonialControllerTest.php b/Tests/Unit/Controller/TestimonialControllerTest.php new file mode 100644 index 0000000..d4da0e0 --- /dev/null +++ b/Tests/Unit/Controller/TestimonialControllerTest.php @@ -0,0 +1,91 @@ +, oliverklee.de + * + * 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 2 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 TYPO3\CMS\Extbase\Mvc\View\ViewInterface; +use TYPO3\CMS\Extbase\Persistence\ObjectStorage; + +use OliverKlee\Tea\Controller\TestimonialController; +use OliverKlee\Tea\Domain\Repository\TestimonialRepository; + +/** + * Test case. + * + * @author Oliver Klee + */ +class TestimonialControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { + /** + * @var TestimonialController + */ + protected $fixture; + + /** + * @var ViewInterface + */ + protected $view = NULL; + + /** + * @var TestimonialRepository + */ + protected $testimonialRepository = NULL; + + public function setUp() { + $this->fixture = new TestimonialController(); + + $this->view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface'); + $this->fixture->setView($this->view); + + $this->testimonialRepository = $this->getMock( + 'OliverKlee\\Tea\\Domain\\Repository\\TestimonialRepository', array(), array(), '', FALSE + ); + $this->fixture->injectTestimonialRepository($this->testimonialRepository); + } + + public function tearDown() { + unset($this->fixture, $this->view, $this->testimonialRepository); + } + + /** + * @test + */ + public function indexActionCanBeCalled() { + $this->fixture->indexAction(); + } + + /** + * @test + */ + public function indexActionPassesAllTestimonialsAsTestimonialsToView() { + $allTestimonials = new ObjectStorage(); + $this->testimonialRepository->expects($this->any())->method('findAll') + ->will($this->returnValue($allTestimonials)); + + $this->view->expects($this->once())->method('assign')->with('testimonials', $allTestimonials); + + $this->fixture->indexAction(); + } +} +?> \ No newline at end of file diff --git a/ext_localconf.php b/ext_localconf.php new file mode 100644 index 0000000..ea45893 --- /dev/null +++ b/ext_localconf.php @@ -0,0 +1,18 @@ + 'index', + ), + // non-cacheable actions + array( + 'Testimonial' => 'index', + ) +); +?> \ No newline at end of file