Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix a regression with controllers for specific formats. #310

Merged
merged 2 commits into from

5 participants

@realityking
Collaborator

No description provided.

@eddieajau

Rouven, would you mind adding a list of the paths that this is supposed to be looking for. Then I'll have a think about how to craft a unit test for it. Thanks!

@realityking
Collaborator

Sorry, took me a little bit longer.

Without this patch paths like this are used:

If the task contains a dot, e.g. articles.save (only the part before the dot is used):
BASE_PATH/controllers/articles.format.php

If the task doesn't contain a dot:
BASE_PATH/controllers/controller.format.php

The BASE_PATH is JPATH_COMPONENT if not overwritten.
Format can be XML, JSON and so on, if it is HTML it is omitted.

No with the pull we change the behavior when the task doesn't contain a dot:
If BASE_PATH/controllers/controller.format.php doesn't exist but BASE_PATH/controllers/controller.php does we use the later.

Is that we you need?

@jlover

Checkstyle error details:
libraries/joomla/application/component/controller.php:272
Concat operator must be surrounded by spaces
libraries/joomla/application/component/controller.php:272
Concat operator must be surrounded by spaces
libraries/joomla/application/component/controller.php:282
Expected "if (...)\n...{...}\n...else\n"; found "if (...)\n...{...}\n...else "
libraries/joomla/application/component/controller.php:286
Usage of ELSE IF is not allowed; use ELSEIF instead

@joomla-jenkins
Collaborator

Build triggered by changes to the base.

Test log missing. Tests failed to execute.
Checkstyle analysis reported 233 warnings and 4165 errors.

@joomla-jenkins
Collaborator

Build triggered by changes to the head.

Unit testing complete. There were 0 failures and 0 errors from 1704 tests and 10633 assertions.
Checkstyle analysis reported 235 warnings and 0 errors.

@joomla-jenkins
Collaborator

Build triggered by changes to the base.

Test log missing. Tests failed to execute.
Checkstyle analysis reported 235 warnings and 0 errors.

@joomla-jenkins
Collaborator

Build triggered by changes to the head.

Unit testing complete. There were 0 failures and 0 errors from 1735 tests and 10781 assertions.
Checkstyle analysis reported 235 warnings and 0 errors.

@eddieajau eddieajau merged commit 5ec800a into joomla:staging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2011
  1. @realityking
  2. @chdemko @realityking

    Add unit tests.

    chdemko authored realityking committed
This page is out of date. Refresh to see the latest.
View
10 libraries/joomla/application/component/controller.php
@@ -270,8 +270,10 @@ public static function getInstance($prefix, $config = array())
$task = $command;
// Define the controller filename and path.
- $file = self::createFileName('controller', array('name' => 'controller', 'format' => $format));
- $path = $basePath . '/' . $file;
+ $file = self::createFileName('controller', array('name' => 'controller', 'format' => $format));
+ $path = $basePath . '/' . $file;
+ $backupfile = self::createFileName('controller', array('name' => 'controller'));
+ $backuppath = $basePath . '/' . $backupfile;
}
// Get the controller class name.
@@ -285,6 +287,10 @@ public static function getInstance($prefix, $config = array())
{
require_once $path;
}
+ elseif (isset($backuppath) && file_exists($backuppath))
+ {
+ require_once $backuppath;
+ }
else
{
throw new InvalidArgumentException(JText::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER', $type, $format));
View
44 tests/suite/joomla/application/component/JControllerTest.php
@@ -195,7 +195,49 @@ public function testExecute()
public function testGetInstance()
{
// Remove the following lines when you implement this test.
- $this->markTestIncomplete('This test has not been implemented yet.');
+ $controller = $this->getMock('JController', null, array(), '', false);
+ $className = get_class($controller);
+ $_SERVER['REQUEST_METHOD'] = 'get';
+ JRequest::setVar('format', 'json');
+ try
+ {
+ $className::getInstance('MyPrefix', array('base_path' => __DIR__ . '/_data/component1'));
+ }
+ catch (Exception $e)
+ {
+ $this->assertEquals(
+ $e->getMessage(),
+ 'JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS',
+ 'Line:'.__LINE__.' File _data/component1/controller.json.php must be found.'
+ );
+ }
+ JRequest::setVar('format', 'xml');
+ try
+ {
+ $className::getInstance('MyPrefix', array('base_path' => __DIR__ . '/_data/component1'));
+ }
+ catch (Exception $e)
+ {
+ $this->assertEquals(
+ $e->getMessage(),
+ 'JLIB_APPLICATION_ERROR_INVALID_CONTROLLER',
+ 'Line:'.__LINE__.' File _data/component1/controller.xml.php and _data/component1/controller.php must not be found.'
+ );
+ }
+ JRequest::setVar('format', 'xml');
+ try
+ {
+ $className::getInstance('MyPrefix', array('base_path' => __DIR__ . '/_data/component2'));
+ }
+ catch (Exception $e)
+ {
+ $this->assertEquals(
+ $e->getMessage(),
+ 'JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS',
+ 'Line:'.__LINE__.' File _data/component2/controller.php must be found.'
+ );
+ }
+ $this->markTestIncomplete('This test is not been complete yet.');
}
/**
View
0  tests/suite/joomla/application/component/_data/component1/controller.json.php
No changes.
View
0  tests/suite/joomla/application/component/_data/component2/controller.php
No changes.
Something went wrong with that request. Please try again.