diff --git a/tests/Zend/Form/Element/CaptchaTest.php b/tests/Zend/Form/Element/CaptchaTest.php index 6ca4426..8d0ab93 100644 --- a/tests/Zend/Form/Element/CaptchaTest.php +++ b/tests/Zend/Form/Element/CaptchaTest.php @@ -388,6 +388,36 @@ class Zend_Form_Element_CaptchaTest extends PHPUnit_Framework_TestCase var_export($decorators, true) ); } + + /** + * @group ZF-12173 + */ + public function testShouldAllowAddingCaptchaPrefixPathWithBackslash() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater'); + return; + } + $this->element->addPrefixPath('My\Captcha', 'My/Captcha/', 'captcha'); + $loader = $this->element->getPluginLoader('captcha'); + $paths = $loader->getPaths('My\Captcha'); + $this->assertTrue(is_array($paths)); + } + + /** + * @group ZF-12173 + */ + public function testAddingCaptchaPrefixPathWithBackslash() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater'); + return; + } + $this->element->addPrefixPath('My\\', 'My/'); + $loader = $this->element->getPluginLoader('captcha'); + $paths = $loader->getPaths('My\Captcha'); + $this->assertTrue(is_array($paths)); + } } /** diff --git a/tests/Zend/Form/Element/FileTest.php b/tests/Zend/Form/Element/FileTest.php index 2ff3a48..b6703e0 100644 --- a/tests/Zend/Form/Element/FileTest.php +++ b/tests/Zend/Form/Element/FileTest.php @@ -491,6 +491,21 @@ class Zend_Form_Element_FileTest extends PHPUnit_Framework_TestCase { $this->assertSame($this->element, $this->element->loadDefaultDecorators()); } + + /** + * @group ZF-12173 + */ + public function testElementShouldAllowAdapterWithBackslahes() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater'); + return; + } + $this->element->addPrefixPath('Zend\Form\Element\FileTest\Adapter', dirname(__FILE__) . '/_files/TransferAdapter', 'transfer_adapter'); + $this->element->setTransferAdapter('Bar'); + $test = $this->element->getTransferAdapter(); + $this->assertTrue($test instanceof \Zend\Form\Element\FileTest\Adapter\Bar); + } } class Zend_Form_Element_FileTest_MockAdapter extends Zend_File_Transfer_Adapter_Abstract diff --git a/tests/Zend/Form/Element/_files/TransferAdapter/Bar.php b/tests/Zend/Form/Element/_files/TransferAdapter/Bar.php new file mode 100644 index 0000000..ebd46bb --- /dev/null +++ b/tests/Zend/Form/Element/_files/TransferAdapter/Bar.php @@ -0,0 +1,70 @@ +received = true; + return; + } + + public function isSent($file = null) + { + return false; + } + + public function isReceived($file = null) + { + return $this->received; + } + + public function isUploaded($files = null) + { + return true; + } + + public function isFiltered($files = null) + { + return true; + } + + public static function getProgress() + { + return; + } +} diff --git a/tests/Zend/Form/ElementTest.php b/tests/Zend/Form/ElementTest.php index f673e3a..9bc3bf2 100644 --- a/tests/Zend/Form/ElementTest.php +++ b/tests/Zend/Form/ElementTest.php @@ -2189,6 +2189,36 @@ class Zend_Form_ElementTest extends PHPUnit_Framework_TestCase $validator = $username->getValidator('regex'); $this->assertTrue($validator->zfBreakChainOnFailure); } + + /** + * @group ZF-12173 + */ + public function testCanAddPluginLoaderPrefixPathsWithBackslashes() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater'); + return; + } + $validatorLoader = new Zend_Loader_PluginLoader(); + $filterLoader = new Zend_Loader_PluginLoader(); + $decoratorLoader = new Zend_Loader_PluginLoader(); + $this->element->setPluginLoader($validatorLoader, 'validate') + ->setPluginLoader($filterLoader, 'filter') + ->setPluginLoader($decoratorLoader, 'decorator') + ->addPrefixPath('Zf\Foo', 'Zf/Foo'); + + $paths = $filterLoader->getPaths('Zf\Foo\Filter'); + $this->assertTrue(is_array($paths)); + $this->assertContains('Filter', $paths[0]); + + $paths = $validatorLoader->getPaths('Zf\Foo\Validate'); + $this->assertTrue(is_array($paths)); + $this->assertContains('Validate', $paths[0]); + + $paths = $decoratorLoader->getPaths('Zf\Foo\Decorator'); + $this->assertTrue(is_array($paths), var_export($paths, 1)); + $this->assertContains('Decorator', $paths[0]); + } } class Zend_Form_ElementTest_Decorator extends Zend_Form_Decorator_Abstract diff --git a/tests/Zend/Form/FormTest.php b/tests/Zend/Form/FormTest.php index 609ee14..c21ab37 100644 --- a/tests/Zend/Form/FormTest.php +++ b/tests/Zend/Form/FormTest.php @@ -4534,6 +4534,26 @@ class Zend_Form_FormTest extends PHPUnit_Framework_TestCase 'SubForm element received wrong validator' ); } + + /** + * @group ZF-12173 + */ + public function testAddingPrefixPathsWithBackslashWillLoadNamespacedPlugins() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater'); + return; + } + $form = new Zend_Form(); + $form->addPrefixPath('Zf\Foo', 'Zf/Foo'); + foreach (array('element', 'decorator') as $type) { + $loader = $form->getPluginLoader($type); + $paths = $loader->getPaths('Zf\Foo\\' . ucfirst($type)); + $this->assertTrue(is_array($paths), "Failed for type $type: " . var_export($paths, 1)); + $this->assertFalse(empty($paths)); + $this->assertContains('Foo', $paths[0]); + } + } } class Zend_Form_FormTest_DisplayGroup extends Zend_Form_DisplayGroup