Browse Source

Add stub helper

euromark 11 years ago
parent
commit
0a324ec9de

+ 10 - 8
tests/TestCase/View/HelperRegistryTest.php

@@ -15,6 +15,7 @@
 namespace Cake\Test\TestCase\View;
 
 use Cake\Core\App;
+use Cake\Core\Configure;
 use Cake\Core\Plugin;
 use Cake\TestSuite\TestCase;
 use Cake\View\Helper;
@@ -187,12 +188,12 @@ class HelperRegistryTest extends TestCase {
  * @return void
  */
 	public function testReset() {
-		$this->skipIf(true, 'Currently no helper with any event');
+		Configure::write('App.namespace', 'TestApp');
 
-		$instance = $this->Helpers->load('Paginator');
+		$instance = $this->Helpers->load('EventListenerTest');
 		$this->assertSame(
 			$instance,
-			$this->Helpers->Paginator,
+			$this->Helpers->EventListenerTest,
 			'Instance in registry should be the same as previously loaded'
 		);
 		$this->assertCount(1, $this->Events->listeners('View.beforeRender'));
@@ -200,7 +201,7 @@ class HelperRegistryTest extends TestCase {
 		$this->assertNull($this->Helpers->reset(), 'No return expected');
 		$this->assertCount(0, $this->Events->listeners('View.beforeRender'));
 
-		$this->assertNotSame($instance, $this->Helpers->load('Paginator'));
+		$this->assertNotSame($instance, $this->Helpers->load('EventListenerTest'));
 	}
 
 /**
@@ -209,17 +210,18 @@ class HelperRegistryTest extends TestCase {
  * @return void
  */
 	public function testUnload() {
-		$this->skipIf(true, 'Currently no helper with any event');
+		Configure::write('App.namespace', 'TestApp');
 
-		$instance = $this->Helpers->load('Paginator');
+		$instance = $this->Helpers->load('EventListenerTest');
 		$this->assertSame(
 			$instance,
-			$this->Helpers->Paginator,
+			$this->Helpers->EventListenerTest,
 			'Instance in registry should be the same as previously loaded'
 		);
 		$this->assertCount(1, $this->Events->listeners('View.beforeRender'));
 
-		$this->assertNull($this->Helpers->unload('Paginator'), 'No return expected');
+		$this->assertNull($this->Helpers->unload('EventListenerTest'), 'No return expected');
 		$this->assertCount(0, $this->Events->listeners('View.beforeRender'));
 	}
+
 }

+ 42 - 0
tests/test_app/TestApp/View/Helper/EventListenerTestHelper.php

@@ -0,0 +1,42 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.0.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace TestApp\View\Helper;
+
+use Cake\Event\Event;
+use Cake\View\Helper;
+
+class EventListenerTestHelper extends Helper {
+
+/**
+ * Before render callback. Stub.
+ *
+ * @param \Cake\Event\Event $event The event instance.
+ * @param string $viewFile The view file being rendered.
+ * @return void
+ */
+	public function beforeRender(Event $event, $viewFile) {
+		$this->config('options.foo', 'bar');
+	}
+
+/**
+ * Event listeners.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return ['View.beforeRender' => 'beforeRender'];
+	}
+
+}