Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
[#3085] Ensure controller is current in plugin manager
Browse files Browse the repository at this point in the history
- When fetching the plugin manager, inject the current controller
  *always*; this ensures that if a plugin is retrieved, it receives the
  controller that actually requested it.
  • Loading branch information
weierophinney committed Feb 13, 2013
1 parent 44b7108 commit bb2e97b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/Zend/Mvc/Controller/AbstractController.php
Expand Up @@ -255,6 +255,7 @@ public function getPluginManager()
$this->setPluginManager(new PluginManager());
}

$this->plugins->setController($this);
return $this->plugins;
}

Expand Down
51 changes: 51 additions & 0 deletions tests/ZendTest/Mvc/Controller/IntegrationTest.php
@@ -0,0 +1,51 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mvc
*/

namespace ZendTest\Mvc\Controller;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\EventManager\SharedEventManager;
use Zend\Mvc\Controller\ControllerManager;
use Zend\Mvc\Controller\PluginManager;
use Zend\ServiceManager\ServiceManager;

class IntegrationTest extends TestCase
{
public function setUp()
{
$this->plugins = new PluginManager();
$this->sharedEvents = new SharedEventManager();
$this->services = new ServiceManager();
$this->services->setService('ControllerPluginManager', $this->plugins);
$this->services->setService('SharedEventManager', $this->sharedEvents);
$this->services->setService('Zend\ServiceManager\ServiceLocatorInterface', $this->services);

$this->controllers = new ControllerManager();
$this->controllers->setServiceLocator($this->services);
}

public function testPluginReceivesCurrentController()
{
$this->controllers->setInvokableClass('first', 'ZendTest\Mvc\Controller\TestAsset\SampleController');
$this->controllers->setInvokableClass('second', 'ZendTest\Mvc\Controller\TestAsset\SampleController');

$first = $this->controllers->get('first');
$second = $this->controllers->get('second');
$this->assertNotSame($first, $second);

$plugin1 = $first->plugin('url');
$this->assertSame($first, $plugin1->getController());

$plugin2 = $second->plugin('url');
$this->assertSame($second, $plugin2->getController());

$this->assertSame($plugin1, $plugin2);
}
}

0 comments on commit bb2e97b

Please sign in to comment.