Exemple #1
0
 /**
  * @testdox A report's Template inherits  the report's `file_extension`, `mime_type`, and `title` attributes.
  * @test
  */
 public function fileExtension()
 {
     $reportsTable = $this->db->getTable(Reports::reportsTableName());
     $reports = new Reports($this->db);
     // 1. No file_extension attribute is set, but the others are.
     $report1 = $reportsTable->saveRecord(array('title' => 'Test Report 1', 'mime_type' => 'text/plain'));
     $template1 = $reports->get_template($report1->id());
     $this->assertNull($template1->file_extension);
     $this->assertEquals('text/plain', $template1->mime_type);
     // 2. A 'GPX' file extension is set, and the default mime_type.
     $report2 = $reportsTable->saveRecord(array('title' => 'Test Report 2', 'file_extension' => 'gpx'));
     $template2 = $reports->get_template($report2->id());
     $this->assertEquals('gpx', $template2->file_extension);
     $this->assertEquals('text/html', $template2->mime_type);
 }
 public function index($args)
 {
     $db = new Database($this->wpdb);
     $id = isset($args['id']) ? $args['id'] : Reports::DEFAULT_REPORT_ID;
     $reports = new Reports($db);
     $template = $reports->get_template($id);
     $out = $template->render();
     if ($template->file_extension) {
         $this->send_file($template->file_extension, $template->mime_type, $out, $template->title);
     } else {
         return $out;
     }
 }