public function testUploadProgressAdapter() { if (!Adapter\Http::isApcAvailable() && !Adapter\Http::isUploadProgressAvailable()) { $this->markTestSkipped('Whether APC nor UploadExtension available'); } $_GET['progress_key'] = 'mykey'; $adapter = new AdapterProgressBar\Console(); $status = array('progress' => $adapter, 'session' => 'upload'); $status = HttpTestMockAdapter::getProgress($status); $this->assertTrue(array_key_exists('total', $status)); $this->assertTrue(array_key_exists('current', $status)); $this->assertTrue(array_key_exists('rate', $status)); $this->assertTrue(array_key_exists('id', $status)); $this->assertTrue(array_key_exists('message', $status)); $this->assertTrue(array_key_exists('progress', $status)); $this->assertTrue($status['progress'] instanceof ProgressBar\ProgressBar); $this->adapter->switchApcToUP(); $status = HttpTestMockAdapter::getProgress($status); $this->assertTrue(array_key_exists('total', $status)); $this->assertTrue(array_key_exists('current', $status)); $this->assertTrue(array_key_exists('rate', $status)); $this->assertTrue(array_key_exists('id', $status)); $this->assertTrue(array_key_exists('message', $status)); $this->assertTrue(array_key_exists('progress', $status)); $this->assertTrue($status['progress'] instanceof ProgressBar\ProgressBar); }
/** * Render a form file * * @param string $content * @return string */ public function render($content) { $element = $this->getElement(); if (!$element instanceof Element) { return $content; } $view = $element->getView(); if (!$view instanceof View) { return $content; } $name = $element->getName(); $attribs = $this->getAttribs(); if (!array_key_exists('id', $attribs)) { $attribs['id'] = $name; } $separator = $this->getSeparator(); $placement = $this->getPlacement(); $markup = array(); $size = $element->getMaxFileSize(); if ($size > 0) { $element->setMaxFileSize(0); $markup[] = $view->formHidden('MAX_FILE_SIZE', $size); } if (Adapter\Http::isApcAvailable()) { $markup[] = $view->formHidden(ini_get('apc.rfc1867_name'), uniqid(), array('id' => 'progress_key')); } else if (Adapter\Http::isUploadProgressAvailable()) { $markup[] = $view->formHidden('UPLOAD_IDENTIFIER', uniqid(), array('id' => 'progress_key')); } if ($element->isArray()) { $name .= "[]"; $count = $element->getMultiFile(); for ($i = 0; $i < $count; ++$i) { $htmlAttribs = $attribs; $htmlAttribs['id'] .= '-' . $i; $markup[] = $view->formFile($name, $htmlAttribs); } } else { $markup[] = $view->formFile($name, $attribs); } $markup = implode($separator, $markup); switch ($placement) { case self::PREPEND: return $markup . $separator . $content; case self::APPEND: default: return $content . $separator . $markup; } }
/** * Render a form file * * @param string $content * @return string */ public function render($content) { $element = $this->getElement(); if (!$element instanceof Element) { return $content; } $view = $element->getView(); if (!$view instanceof Renderer || !method_exists($view, 'broker')) { throw new Exception\UnexpectedValueException('File decorator cannot render without a registered view object containing a broker() method'); } $name = $element->getName(); $attribs = $this->getAttribs(); if (!array_key_exists('id', $attribs)) { $attribs['id'] = $name; } $separator = $this->getSeparator(); $placement = $this->getPlacement(); $markup = array(); $size = $element->getMaxFileSize(); if ($size > 0) { $element->setMaxFileSize(0); $markup[] = $view->broker('formHidden')->direct('MAX_FILE_SIZE', $size); } if (Adapter\Http::isApcAvailable()) { $markup[] = $view->broker('formHidden')->direct(ini_get('apc.rfc1867_name'), uniqid(), array('id' => 'progress_key')); } else { if (Adapter\Http::isUploadProgressAvailable()) { $markup[] = $view->broker('formHidden')->direct('UPLOAD_IDENTIFIER', uniqid(), array('id' => 'progress_key')); } } if ($element->isArray()) { $name .= "[]"; $count = $element->getMultiFile(); for ($i = 0; $i < $count; ++$i) { $htmlAttribs = $attribs; $htmlAttribs['id'] .= '-' . $i; $markup[] = $view->broker('formFile')->direct($name, null, $htmlAttribs); } } else { $markup[] = $view->broker('formFile')->direct($name, null, $attribs); } $markup = implode($separator, $markup); switch ($placement) { case self::PREPEND: return $markup . $separator . $content; case self::APPEND: default: return $content . $separator . $markup; } }