Ejemplo n.º 1
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     Registry::_unsetInstance();
     $this->view   = $this->getView();
     $this->helper = new DojoContainer();
     $this->helper->setView($this->view);
     Registry::set('Zend\Dojo\View\Helper\Dojo', $this->helper);
     DojoHelper::setUseProgrammatic();
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * Map constants to doctype strings, and set default doctype
  *
  * @return void
  */
 public function __construct()
 {
     if (!\Zend\Registry::isRegistered($this->_regKey)) {
         $this->_registry = new \ArrayObject(array('doctypes' => array(self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">', self::XHTML5 => '<!DOCTYPE html>', self::HTML4_STRICT => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', self::HTML4_LOOSE => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', self::HTML4_FRAMESET => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">', self::HTML5 => '<!DOCTYPE html>')));
         \Zend\Registry::set($this->_regKey, $this->_registry);
         $this->setDoctype($this->_defaultDoctype);
     } else {
         $this->_registry = \Zend\Registry::get($this->_regKey);
     }
 }
Ejemplo n.º 3
0
 /**
  * Retrieve or create registry instnace
  *
  * @return void
  */
 public static function getRegistry()
 {
     if (\Zend\Registry::isRegistered(self::REGISTRY_KEY)) {
         $registry = \Zend\Registry::get(self::REGISTRY_KEY);
     } else {
         $registry = new self();
         \Zend\Registry::set(self::REGISTRY_KEY, $registry);
     }
     return $registry;
 }
Ejemplo n.º 4
0
 /**
  * @group ZF-7352
  */
 public function testTranslationIsAddedIfRegistryKeyExistsAlready()
 {
     $options1 = array('foo' => 'bar');
     $options2 = array_merge_recursive($this->_translationOptions, array('content' => array('message4' => 'bericht4')));
     $translate = new \Zend\Translator\Translator(\Zend\Translator\Translator::AN_ARRAY, $options1);
     Registry::set('Zend_Translator', $translate);
     $resource = new TranslateResource($options2);
     $this->assertTrue($translate === $resource->getTranslate());
     $this->assertEquals('bar', $translate->translate('foo'));
     $this->assertEquals('bericht4', $translate->translate('message4'));
     $this->assertEquals('shouldNotExist', $translate->translate('shouldNotExist'));
 }
Ejemplo n.º 5
0
 function __construct()
 {
     $this->open_connection();
     $this->magic_quotes_active = get_magic_quotes_gpc();
     $this->real_escape_string_exists = function_exists("mysql_real_escape_string");
     // $this->cache = new Memcache();
     // $this->cache->connect(CACHE_SERVER, CACHE_PORT) or die ("Could not connect");
     $this->zend_cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 3600 * 24, 'automatic_serialization' => true), array('cache_dir' => SITE_ROOT . '/cache_files'));
     Zend_Registry::set('cached', $this->zend_cache);
     //<---set a registry refference
     $this->zend_cache = Zend_Registry::get('cached');
     //<---gets the a registry refference
 }
Ejemplo n.º 6
0
 public function testShouldProxyToMenuHelperByDeafult()
 {
     // setup
     $oldReg = null;
     if (\Zend\Registry::isRegistered(self::REGISTRY_KEY)) {
         $oldReg = \Zend\Registry::get(self::REGISTRY_KEY);
     }
     \Zend\Registry::set(self::REGISTRY_KEY, $this->_nav1);
     $this->_helper->setContainer(null);
     // result
     $expected = $this->_getExpected('menu/default1.html');
     $actual = $this->_helper->render();
     // teardown
     \Zend\Registry::set(self::REGISTRY_KEY, $oldReg);
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 7
0
 /**
  * Retrieve locale object
  *
  * @return \Zend\Locale\Locale
  */
 public function getLocale()
 {
     if (null === $this->_locale) {
         $options = $this->getOptions();
         if (!isset($options['default'])) {
             $this->_locale = new SystemLocale\Locale();
         } elseif (!isset($options['force']) || (bool) $options['force'] == false) {
             // Don't force any locale, just go for auto detection
             SystemLocale\Locale::setDefault($options['default']);
             $this->_locale = new SystemLocale\Locale();
         } else {
             $this->_locale = new SystemLocale\Locale($options['default']);
         }
         $key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;
         \Zend\Registry::set($key, $this->_locale);
     }
     return $this->_locale;
 }
Ejemplo n.º 8
0
 /**
  * @group ZF-11831
  */
 public function testElementsOfSubFormReceiveCorrectDefaultTranslator()
 {
     $isEmptyKey = \Zend\Validator\NotEmpty::IS_EMPTY;
     // Global default translator
     $trDefault = new Translator(array('adapter' => 'arrayAdapter', 'content' => array($isEmptyKey => 'Default'), 'locale' => 'en'));
     Registry::set('Zend_Translate', $trDefault);
     // Translator to use for elements
     $trElement = new Translator(array('adapter' => 'arrayAdapter', 'content' => array($isEmptyKey => 'Element'), 'locale' => 'en'));
     \Zend\Validator\AbstractValidator::setDefaultTranslator($trElement);
     // Change the form's translator
     $form = new Form();
     $form->addElement(new \Zend\Form\Element\Text('foo', array('required' => true, 'validators' => array('NotEmpty'))));
     // Create a subform with it's own validator
     $sf1 = new SubForm();
     $sf1->addElement(new \Zend\Form\Element\Text('foosub', array('required' => true, 'validators' => array('NotEmpty'))));
     $form->addSubForm($sf1, 'Test1');
     $form->isValid(array());
     $messages = $form->getMessages();
     $this->assertEquals('Element', @$messages['foo'][$isEmptyKey], 'Form element received wrong validator');
     $this->assertEquals('Element', @$messages['Test1']['foosub'][$isEmptyKey], 'SubForm element received wrong validator');
 }
Ejemplo n.º 9
0
 /**
  * @ZF-7703
  */
 public function testLocaleDetectsNoEnglishLocaleOnOtherSetLocale()
 {
     \Zend\Registry::set('Zend_Locale', new Locale\Locale('de'));
     $valid = new Validator\Int();
     $this->assertTrue($valid->isValid(1200));
     $this->assertFalse($valid->isValid('1,200'));
 }
Ejemplo n.º 10
0
 public function testZF3679()
 {
     $locale = new Locale\Locale('de_AT');
     \Zend\Registry::set('Zend_Locale', $locale);
     $lang = new Translator\Translator(Translator\Translator::AN_ARRAY, array('msg1' => 'message1'), 'de_AT');
     $this->assertEquals('de_AT', $lang->getLocale());
     \Zend\Registry::_unsetInstance();
 }
Ejemplo n.º 11
0
 /**
  * Stores navigation container in the registry
  *
  * @return void
  */
 protected function _storeRegistry()
 {
     $options = $this->getOptions();
     if (isset($options['storage']['registry']['key']) && !is_numeric($options['storage']['registry']['key'])) {
         $key = $options['storage']['registry']['key'];
     } else {
         $key = self::DEFAULT_REGISTRY_KEY;
     }
     \Zend\Registry::set($key, $this->getContainer());
 }
Ejemplo n.º 12
0
    public function testAutoloadContainerFromRegistry()
    {
        $oldReg = null;
        if (\Zend\Registry::isRegistered(self::REGISTRY_KEY)) {
            $oldReg = \Zend\Registry::get(self::REGISTRY_KEY);
        }
        \Zend\Registry::set(self::REGISTRY_KEY, $this->_nav1);

        $this->_helper->setContainer(null);

        $expected = $this->_getExpected('sitemap/default1.xml');
        $actual = $this->_helper->render();

        \Zend\Registry::set(self::REGISTRY_KEY, $oldReg);

        $this->assertEquals($expected, $expected);
    }
Ejemplo n.º 13
0
 /**
  * @group ZF-9275
  */
 public function testDefaultTranslatorDoesntOverrideElementTranslatorOnValdiation()
 {
     $registryTranslations = array('alphaInvalid' => 'Registry message');
     $registryTranslate = new Translator('ArrayAdapter', $registryTranslations);
     Registry::set('Zend_Translator', $registryTranslate);
     $validatorTranslations = array('alphaInvalid' => 'Validator message');
     $validatorTranslate = new Translator('ArrayAdapter', $validatorTranslations);
     AbstractValidator::setDefaultTranslator($validatorTranslate);
     $elementTranslations = array('alphaInvalid' => 'Element message');
     $elementTranslate = new Translator('ArrayAdapter', $elementTranslations);
     $this->element->addValidator('Alpha');
     $this->element->setTranslator($elementTranslate);
     $this->assertFalse($this->element->isValid(123));
     $messages = $this->element->getMessages();
     $this->assertEquals('Element message', $messages['alphaInvalid']);
 }
Ejemplo n.º 14
0
 /**
  * @group ZF-11631
  */
 public function testRegistryLocale()
 {
     $locale = new Locale('ja');
     \Zend\Registry::set('Zend_Locale', $locale);
     if (!self::$_unicodeEnabled) {
         $this->markTestSkipped('Unicode not enabled');
     }
     $valuesExpected = array('aABbc' => 'aBc', 'z Y x' => 'zx', 'W1v3U4t' => 'vt', ',sй.rλ:qν_p' => 'srqp', 'onml' => 'onml');
     $filter = new AlphaFilter();
     $this->assertEquals('ja', (string) $filter->getLocale());
     foreach ($valuesExpected as $input => $output) {
         $this->assertEquals($output, $result = $filter($input), "Expected '{$input}' to filter to '{$output}', but received '{$result}' instead");
     }
 }
Ejemplo n.º 15
0
 /**
  * testing registry Locale
  * ZF-3676
  */
 public function testRegistryLocale()
 {
     $locale = new Locale\Locale('de_AT');
     \Zend\Registry::set('Zend_Locale', $locale);
     $currency = new Currency\Currency('EUR');
     $this->assertSame('de_AT', $currency->getLocale());
 }
Ejemplo n.º 16
0
 public function testGlobalTranslatorFromRegistryUsedWhenNoLocalTranslatorSet()
 {
     set_error_handler(array($this, 'errorHandlerIgnore'));
     $translate = new Translator\Translator('ArrayAdapter', array());
     restore_error_handler();
     \Zend\Registry::set('Zend_Translate', $translate);
     $this->assertSame($translate->getAdapter(), $this->validator->getTranslator());
 }
Ejemplo n.º 17
0
 public function bootstrapCallback()
 {
     $router = new Router\Rewrite();
     $dispatcher = new Dispatcher\Standard();
     $plugin = new Plugin\ErrorHandler();
     $controller = Controller\Front::getInstance();
     $controller->setParam('foo', 'bar')->registerPlugin($plugin)->setRouter($router)->setDispatcher($dispatcher);
     $broker = $controller->getHelperBroker();
     $viewRenderer = $broker->load('ViewRenderer');
     Registry::set('router', $router);
     Registry::set('dispatcher', $dispatcher);
     Registry::set('plugin', $plugin);
     Registry::set('viewRenderer', $viewRenderer);
 }
Ejemplo n.º 18
0
 /**
  * @ZF-6374
  */
 public function testUsingApplicationLocale()
 {
     \Zend\Registry::set('Zend_Locale', new \Zend\Locale\Locale('de'));
     $valid = new Validator\Date();
     $this->assertTrue($valid->isValid('10.April.2008'));
 }
Ejemplo n.º 19
0
 /**
  * @group ZF-9540
  */
 public function testSubFormTranslatorPreferredOverDefaultTranslator()
 {
     $defaultTranslations = array('isEmpty' => 'Default message');
     $subformTranslations = array('isEmpty' => 'SubForm message');
     $defaultTranslate = new Translator('ArrayAdapter', $defaultTranslations);
     $subformTranslate = new Translator('ArrayAdapter', $subformTranslations);
     Registry::set('Zend_Translate', $defaultTranslate);
     $this->form->addSubForm(new SubForm(), 'subform');
     $this->form->subform->setTranslator($subformTranslate);
     $this->form->subform->addElement('text', 'foo', array('required' => true));
     $this->assertFalse($this->form->isValid(array('subform' => array('foo' => ''))));
     $messages = $this->form->getMessages();
     $this->assertEquals('SubForm message', $messages['subform']['foo']['isEmpty']);
     $this->assertFalse($this->form->isValidPartial(array('subform' => array('foo' => ''))));
     $messages = $this->form->getMessages();
     $this->assertEquals('SubForm message', $messages['subform']['foo']['isEmpty']);
 }
Ejemplo n.º 20
0
 /**
  * @group ZF-3736
  */
 public function testTranslateNotEmptyMessagesByUsingRegistry()
 {
     $translator = new Translator\Adapter\ArrayAdapter(array('locale' => 'en_US', 'content' => array('missingMessage' => 'Still missing')));
     \Zend\Registry::set('Zend_Translate', $translator);
     $validators = array('rule1' => array('presence' => 'required', 'fields' => array('field1', 'field2'), 'default' => array('field1default')));
     $data = array();
     $input = new InputFilter(null, $validators, $data);
     $this->assertTrue($input->hasMissing(), 'Expected hasMissing() to return true');
     $this->assertFalse($input->hasInvalid(), 'Expected hasInvalid() to return false');
     $this->assertFalse($input->hasUnknown(), 'Expected hasUnknown() to return false');
     $this->assertFalse($input->hasValid(), 'Expected hasValid() to return false');
     $missing = $input->getMissing();
     $this->assertInternalType('array', $missing);
     $this->assertEquals(array('rule1'), array_keys($missing));
     $this->assertEquals(array("Still missing"), $missing['rule1']);
 }
Ejemplo n.º 21
0
    public function testTranslationFromTranslatorInRegistry()
    {
        $oldReg = \Zend\Registry::isRegistered('Zend_Translator')
                ? \Zend\Registry::get('Zend_Translator')
                : null;

        $translator = $this->_getTranslator();
        \Zend\Registry::set('Zend_Translator', $translator);

        $expected = $this->_getExpected('bc/translated.html');
        $actual = $this->_helper->render();

        \Zend\Registry::set('Zend_Translator', $oldReg);

        $this->assertEquals($expected, $actual);
    }
Ejemplo n.º 22
0
 /**
  * @ZF-7489
  */
 public function testUsingApplicationLocale()
 {
     \Zend\Registry::set('Zend_Locale', new \Zend\Locale\Locale('de'));
     $valid = new Validator\Float();
     $this->assertTrue($valid->isValid('123,456'));
 }
Ejemplo n.º 23
0
 public function testCanTranslateTitle()
 {
     $adapter = new \Zend\Translator\Adapter\Ini(dirname(__FILE__) . '/../../Translator/Adapter/_files/translation_en.ini', 'en');
     \Zend\Registry::set('Zend_Translate', $adapter);
     $this->helper->enableTranslation();
     $this->helper->direct('Message_1');
     $this->assertEquals('<title>Message 1 (en)</title>', $this->helper->toString());
 }
Ejemplo n.º 24
0
 public function testRegistryGet()
 {
     Registry::set('foo', 'bar');
     $bar = Registry::get('foo');
     $this->assertEquals('bar', $bar);
 }
Ejemplo n.º 25
0
 /**
  * Retrieve translate object
  *
  * @return \Zend\Translator\Translator
  * @throws \Zend\Application\ResourceException if registry key was used
  *          already but is no instance of Zend_Translator
  */
 public function getTranslate()
 {
     if (null === $this->_translate) {
         $options = $this->getOptions();
         if (!isset($options['data'])) {
             throw new Exception\InitializationException('No translation source data provided.');
         }
         if (empty($options['adapter'])) {
             $options['adapter'] = Translator::AN_ARRAY;
         }
         if (!empty($options['data'])) {
             $options['content'] = $options['data'];
             unset($options['data']);
         }
         if (isset($options['options'])) {
             foreach ($options['options'] as $key => $value) {
                 $options[$key] = $value;
             }
         }
         if (!empty($options['cache']) && is_string($options['cache'])) {
             $bootstrap = $this->getBootstrap();
             if ($bootstrap instanceof \Zend\Application\ResourceBootstrapper && $bootstrap->getBroker()->hasPlugin('CacheManager')) {
                 $cacheManager = $bootstrap->bootstrap('CacheManager')->getResource('CacheManager');
                 if (null !== $cacheManager && $cacheManager->hasCache($options['cache'])) {
                     $options['cache'] = $cacheManager->getCache($options['cache']);
                 }
             }
         }
         $key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;
         unset($options['registry_key']);
         if (Registry::isRegistered($key)) {
             $translate = Registry::get($key);
             if (!$translate instanceof Translator) {
                 throw new Exception\InitializationException($key . ' already registered in registry but is ' . 'no instance of Zend_Translator');
             }
             $translate->addTranslation($options);
             $this->_translate = $translate;
         } else {
             $this->_translate = new Translator($options);
             Registry::set($key, $this->_translate);
         }
     }
     return $this->_translate;
 }
Ejemplo n.º 26
0
//   - Requires little memory (RAM)
//   - No reduction in file size
//
// o PROCESSOR_GHOSTSCRIPT
//   - Slower
//   - Requires lots of memory (RAM)
//   - Reduction in file size
//
// If you have both installed on your system, PROCESSOR_PDFTK is recommended.
$processor = PROCESSOR_PDFTK;
// Number of documents (populated with random strings) to concatenate.
$iterations = 3;
// -----------------------------------------------------------------------------
// Logger to output status messages
$logger = new Logger(new Writer('php://stdout'));
Registry::set('logger', $logger);
// -----------------------------------------------------------------------------
// Create temporary directory
$tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(rand(1, 10000) . __FILE__);
if (is_dir($tempDirectory)) {
    recursiveRemoveDirectory($tempDirectory);
}
$logger->log(sprintf('Making temporary directory %s.', $tempDirectory), Logger::INFO);
mkdir($tempDirectory);
// -----------------------------------------------------------------------------
// Generate temporary documents
$tempFilenames = array();
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$mailMerge->setLocalTemplate('template.docx');
for ($iteration = 1; $iteration <= $iterations; $iteration++) {
Ejemplo n.º 27
0
    /**
     * Caching method tests
     */
    public function testFindingTheProperLocale()
    {
        $this->assertTrue(is_string(LocaleTestHelper::findLocale()));
        $this->assertEquals('de', LocaleTestHelper::findLocale('de'));
        $this->assertEquals('de', LocaleTestHelper::findLocale('de_XX'));

        try {
            $locale = LocaleTestHelper::findLocale('xx_YY');
            $this->fail();
        } catch (InvalidArgumentException $e) {
            $this->assertContains('is no known locale', $e->getMessage());
        }

        \Zend\Registry::set('Zend_Locale', 'de');
        $this->assertEquals('de', LocaleTestHelper::findLocale());
    }
Ejemplo n.º 28
0
 public function testLocalTranslationObjectIsPreferredOverRegistry()
 {
     $transReg = new Translator\Translator('arrayAdapter', array('one' => 'eins'));
     \Zend\Registry::set('Zend_Translate', $transReg);
     $this->assertSame($transReg->getAdapter(), $this->helper->getTranslator());
     $transLoc = new Translator\Translator('arrayAdapter', array('one' => 'uno'));
     $this->helper->setTranslator($transLoc);
     $this->assertSame($transLoc->getAdapter(), $this->helper->getTranslator());
     $this->assertNotSame($transLoc->getAdapter(), $transReg->getAdapter());
 }
Ejemplo n.º 29
0
    public function testLocalCurrencyObjectIsPreferredOverRegistry()
    {
        $currReg = new Currency\Currency('de_AT');
        \Zend\Registry::set('Zend_Currency', $currReg);

        $this->helper = new Helper\Currency();
        $this->assertSame($currReg, $this->helper->getCurrency());

        $currLoc = new Currency\Currency('en_US');
        $this->helper->setCurrency($currLoc);
        $this->assertSame($currLoc, $this->helper->getCurrency());
        $this->assertNotSame($currLoc, $currReg);
    }
Ejemplo n.º 30
0
 public function testTableMetadataCacheException()
 {
     \Zend\Loader::loadClass('\\ZendTest\\Db\\Table\\TestAsset\\TableBugs');
     /**
      * options array points 'metadataCache' to integer scalar
      */
     try {
         $table = new \ZendTest\Db\Table\TestAsset\TableBugs(array('metadataCache' => 327));
         $this->fail('Expected to catch Zend_Db_Table_Exception');
     } catch (\Zend\Exception $e) {
         $this->assertType('Zend\\Db\\Table\\Exception', $e, 'Expecting object of type Zend_Db_Table_Exception, got ' . get_class($e));
         $this->assertEquals("Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored", $e->getMessage());
     }
     /**
      * options array points 'metadataCache' to Registry key containing integer scalar
      */
     \Zend\Registry::set('registered_metadata_cache', 327);
     try {
         $table = new \ZendTest\Db\Table\TestAsset\TableBugs(array('metadataCache' => 'registered_metadata_cache'));
         $this->fail('Expected to catch Zend_Db_Table_Exception');
     } catch (\Zend\Exception $e) {
         $this->assertType('Zend\\Db\\Table\\Exception', $e, 'Expecting object of type Zend_Db_Table_Exception, got ' . get_class($e));
         $this->assertEquals("Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored", $e->getMessage());
     }
 }