EXTMVC:
authorJochen Rau <j.rau@web.de>
Tue, 24 Mar 2009 22:05:36 +0000 (22:05 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 24 Mar 2009 22:05:36 +0000 (22:05 +0000)
* Implemented LIMIT for findOneByProperty() (Christopher Hlubek)

typo3/sysext/extbase/Classes/Persistence/Repository.php
typo3/sysext/extbase/Classes/View/Helper/ConvertHelper.php
typo3/sysext/extbase/Classes/View/Helper/LinkHelper.php
typo3/sysext/extbase/Tests/Repository_testcase.php

index 7ba599d..b9d25b2 100644 (file)
@@ -114,14 +114,14 @@ abstract class TX_EXTMVC_Persistence_Repository implements TX_EXTMVC_Persistence
        public function __call($methodName, $arguments) {
                if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) {
                        $propertyName = TX_EXTMVC_Utility_Strings::lowercaseFirst(substr($methodName,6));
-                       return $this->findByProperty($propertyName, $arguments[0]);
+                       return $this->find(array($propertyName => $arguments[0]));
                } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) {
                        $propertyName = TX_EXTMVC_Utility_Strings::lowercaseFirst(substr($methodName,9));
-                       $result = $this->findByProperty($propertyName, $arguments[0]);
-                       if (empty($result)) {
-                               return FALSE;
+                       $result = $this->find(array($propertyName => $arguments[0]), '', '', 1);
+                       if (count($result) > 0) {
+                               return $result[0];
                        } else {
-                               return $result[0]; // TODO Implement LIMIT
+                               return NULL;
                        }
                }
                throw new TX_EXTMVC_Persistence_Exception_UnsupportedMethod('The method "' . $methodName . '" is not supported by the repository.', 1233180480);
@@ -163,16 +163,5 @@ abstract class TX_EXTMVC_Persistence_Repository implements TX_EXTMVC_Persistence
        public function findAll() {
                return $this->find();
        }
-
-       /**
-        * Finds objects matching 'property=xyz'
-        *
-        * @param string $propertyName The name of the property (will be checked by a white list)
-        * @param string $arguments The arguments of the magic findBy method
-        * @return array The result
-        */
-       protected function findByProperty($propertyName, $value) {
-               return $this->find(array($propertyName => $value));
-       }
 }
 ?>
\ No newline at end of file
index 1f08b50..ef681c0 100644 (file)
@@ -34,10 +34,9 @@ class TX_EXTMVC_View_Helper_ConvertHelper extends TX_EXTMVC_View_Helper_Abstract
        public function render($view, $arguments, $templateSource, $variables) {
                $value = $content;
                $format = $arguments['format'];
-               if (!is_string($format)) ; // TODO Throw exception?
                if ($value instanceof DateTime) {
                        if ($format === NULL) {
-                               $value = $value->format('Y-m-d G:i'); // TODO Date time format from extension settings
+                               $value = $value->format('Y-m-d G:i');
                        } else {
                                $value = $value->format($format);
                        }
index e8262c7..46bb4f5 100644 (file)
@@ -60,7 +60,6 @@ class TX_EXTMVC_View_Helper_LinkHelper extends TX_EXTMVC_View_Helper_AbstractHel
         * @return string A content wrapped in a link
         */
        public function render($view, $arguments, $templateSource, $variables) {
-               // TODO Check for security issues
                $parameters = t3lib_div::_GET();
                $prefixedExtensionKey = 'tx_' . strtolower($this->request->getControllerExtensionKey());
                if (!empty($arguments['to'])) {
index 3abfaad..0d5189d 100644 (file)
 require_once('Base_testcase.php');
 
 class TX_EXTMVC_Persistence_Repository_testcase extends TX_EXTMVC_Base_testcase {
+       public function __construct() {
+               require_once(t3lib_extMgm::extPath('blogexample', 'Classes/Domain/BlogRepository.php'));
+       }
+
+       public function test_FindDelegatesToDataMapperFind() {
+               $repository = new TX_Blogexample_Domain_BlogRepository();
+               $repository->dataMapper = $this->getMock('TX_EXTMVC_Persistence_Mapper_DataMap', array('find'), array(), '', FALSE);
+               $repository->dataMapper->expects($this->once())
+                       ->method('find')
+                       ->with($this->equalTo('TX_Blogexample_Domain_Blog'), $this->equalTo('foo'))
+                       ->will($this->returnValue(array()));
+               
+               $result = $repository->find('foo');
+               $this->assertEquals(array(), $result);
+       }
+
        public function test_MagicFindByPropertyUsesGenericFind() {
                $repository = $this->getMock('TX_Blogexample_Domain_BlogRepository', array('find'), array('TX_Blogexample_Domain_Blog'));
                $repository->expects($this->once())