Exemplo n.º 1
0
 public function testOutputWithoutHeaders()
 {
     $this->config->setExtraSettings(['skipHeaders' => true]);
     $buffer = $this->adapter->output();
     $sampleCsv = 'zażółć gęślą,jaźń';
     $this->assertSame($sampleCsv, $buffer);
 }
Exemplo n.º 2
0
 /**
  * Saves export output under specified filepath without downloading.
  * Proxied via __call() method
  * @param AdapterInterface $adapter
  */
 protected function save(AdapterInterface $adapter)
 {
     $output = $adapter->output();
     $filename = $this->config->getFilename() . $adapter->getExtension();
     $filepath = implode(DIRECTORY_SEPARATOR, [$this->config->getOutputDir(), $filename]);
     $file = fopen($filepath, 'wb');
     fwrite($file, $output);
     fclose($file);
 }
Exemplo n.º 3
0
 public function testMissingTemplateSettings()
 {
     $this->config->setTemplate(null);
     try {
         $this->adapter->validateOutput();
         $this->fail();
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Vegas\\Exporter\\Adapter\\Exception\\TemplateNotSetException', $e);
     }
 }
Exemplo n.º 4
0
 /**
  * Triggers the rendering process and gets result content as string.
  * Use only for custom template exports.
  * @return string
  * @throws \Vegas\Mvc\Exception
  */
 protected function getRenderedView()
 {
     try {
         /** @var \Phalcon\Mvc\View $view */
         $view = \Phalcon\DI::getDefault()->get('view');
     } catch (\Phalcon\DI\Exception $e) {
         throw new \Vegas\Mvc\Exception();
     }
     $view->start();
     $level = $view->getCurrentRenderLevel();
     $view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
     $view->render($this->config->getTemplate(), null);
     $view->setRenderLevel($level);
     $view->finish();
     return $view->getContent();
 }
Exemplo n.º 5
0
    public function testUseObjectDataForOutput()
    {
        $object = new \stdClass();
        $object->bar = 'zażółć gęślą';
        $object->foo = 'jaźń';
        $this->config->setHeaders(['foo', 'bar', 'empty']);
        $this->config->setData([$object]);
        $buffer = $this->adapter->output();
        $prettyPrintXml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <item>
    <foo>jaźń</foo>
    <bar>zażółć gęślą</bar>
    <empty></empty>
  </item>
</root>
XML;
        $this->assertSame($prettyPrintXml, rtrim($buffer, PHP_EOL));
    }
Exemplo n.º 6
0
 public function testGetSetFilenameWithDefaultValue()
 {
     $config = new ExportSettings();
     $newFilename = 'new_output_filename';
     $this->assertNotNull($config->getFilename());
     $this->assertNotSame($newFilename, $config->getFilename());
     $config->setFilename($newFilename);
     $this->assertSame($newFilename, $config->getFilename());
 }