Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/4.0-dev' into j4/mvcfa…
Browse files Browse the repository at this point in the history
…ctory/service

# Conflicts:
#	libraries/src/Dispatcher/DispatcherFactory.php
  • Loading branch information
laoneo committed Mar 7, 2018
2 parents ec7839b + 1851d79 commit 0860219
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 23 deletions.
6 changes: 3 additions & 3 deletions administrator/components/com_content/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
use Joomla\DI\ServiceProviderInterface;

/**
* Content component loader.
* The content service provider.
*
* @since __DEPLOY_VERSION__
*/
class ContentComponentServiceProvider implements ServiceProviderInterface
return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
Expand All @@ -46,4 +46,4 @@ public function register(Container $container)
);
$container->registerServiceProvider(new Component);
}
}
};
6 changes: 4 additions & 2 deletions libraries/src/Dispatcher/DispatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\Input\Input;
use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface;

/**
Expand Down Expand Up @@ -56,12 +57,13 @@ public function __construct(string $namespace, MVCFactoryFactoryInterface $mvcFa
* Creates a dispatcher.
*
* @param CMSApplicationInterface $application The application
* @param Input $input The input object, defaults to the one in the application
*
* @return DispatcherInterface
*
* @since __DEPLOY_VERSION__
*/
public function createDispatcher(CMSApplicationInterface $application): DispatcherInterface
public function createDispatcher(CMSApplicationInterface $application, Input $input = null): DispatcherInterface
{
$name = 'Site';

Expand All @@ -72,6 +74,6 @@ public function createDispatcher(CMSApplicationInterface $application): Dispatch

$className = '\\' . trim($this->namespace, '\\') . '\\' . $name . '\\Dispatcher\\Dispatcher';

return new $className($application, $application->input, $this->mvcFactory);
return new $className($application, $input ?: $application->input, $this->mvcFactory);
}
}
1 change: 0 additions & 1 deletion libraries/src/Extension/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Dispatcher\DispatcherFactory;
use Joomla\CMS\Dispatcher\DispatcherFactoryInterface;
use Joomla\CMS\Dispatcher\DispatcherInterface;
use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface;
Expand Down
20 changes: 8 additions & 12 deletions libraries/src/Extension/ExtensionManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,21 @@ private function loadExtension($type, $extensionName, $extensionPath)
}

// The container to get the services from
$container = new Container($this->getContainer());

// The class name to load
$className = ucfirst($extensionName) . ucfirst($type) . 'ServiceProvider';
$container = $this->getContainer()->createChild();

// The path of the loader file
$path = $extensionPath . '/services/provider.php';

if (!class_exists($className) && file_exists($path))
if (file_exists($path))
{
// Load the file
require_once $path;
}
$provider = require_once $path;

// Check if the extension supports the service provider interface
if (class_exists($className) && is_subclass_of($className, ServiceProviderInterface::class))
{
$extensionLoader = new $className;
$extensionLoader->register($container);
// Check if the extension supports the service provider interface
if ($provider instanceof ServiceProviderInterface)
{
$provider->register($container);
}
}

// Fallback to legacy
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class Factory
public static $cache = null;

/**
* Global configuraiton object
* Global configuration object
*
* @var \JConfig
* @since 11.1
Expand Down
51 changes: 48 additions & 3 deletions tests/unit/suites/libraries/cms/error/JErrorPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ protected function setUp()
*/
protected function tearDown()
{
TestReflection::setValue('JDocument', 'instances', array());
$this->restoreFactoryState();

parent::tearDown();
Expand Down Expand Up @@ -65,7 +64,30 @@ public function testEnsureTheErrorPageIsCorrectlyRendered()
->method('render')
->willReturn($documentResponse);

TestReflection::setValue('JDocument', 'instances', array($key => $mockErrorDocument));
$mockFactory = new class($mockErrorDocument) implements \Joomla\CMS\Document\FactoryInterface
{
private $mockErrorDoc;

public function __construct($mockErrorDoc)
{
$this->mockErrorDoc = $mockErrorDoc;
}

public function createDocument(string $type = 'html', array $attributes = []): \Joomla\CMS\Document\Document
{
return $this->mockErrorDoc;
}

public function createRenderer(\Joomla\CMS\Document\Document $document, string $type): \Joomla\CMS\Document\RendererInterface
{
throw new BadMethodCallException;
}
};

// Set our mock document into the container
$container = new \Joomla\DI\Container;
$container->set(\Joomla\CMS\Document\FactoryInterface::class, $mockFactory);
JFactory::$container = $container;

// Create an Exception to inject into the method
$exception = new RuntimeException('Testing JErrorPage::render() with RuntimeException', 500);
Expand Down Expand Up @@ -107,7 +129,30 @@ public function testEnsureTheErrorPageIsCorrectlyRenderedWithThrowables()
->method('render')
->willReturn($documentResponse);

TestReflection::setValue('JDocument', 'instances', array($key => $mockErrorDocument));
$mockFactory = new class($mockErrorDocument) implements \Joomla\CMS\Document\FactoryInterface
{
private $mockErrorDoc;

public function __construct($mockErrorDoc)
{
$this->mockErrorDoc = $mockErrorDoc;
}

public function createDocument(string $type = 'html', array $attributes = []): \Joomla\CMS\Document\Document
{
return $this->mockErrorDoc;
}

public function createRenderer(\Joomla\CMS\Document\Document $document, string $type): \Joomla\CMS\Document\RendererInterface
{
throw new BadMethodCallException;
}
};

// Set our mock document into the container
$container = new \Joomla\DI\Container;
$container->set(\Joomla\CMS\Document\FactoryInterface::class, $mockFactory);
JFactory::$container = $container;

// Create an Error to inject into the method
$exception = new Error('Testing JErrorPage::render() with PHP 7 Error', 500);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/suites/libraries/cms/layout/JLayoutBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testEscapingSpecialCharactersIntoHtmlEntities()

$this->assertThat(
$this->layoutBase->escape("<a href='test'>Test</a>"),
$this->equalTo("&lt;a href='test'&gt;Test&lt;/a&gt;"),
$this->equalTo("&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;"),
'Test the characters <> are not converted'
);
}
Expand Down

0 comments on commit 0860219

Please sign in to comment.