/** * @testdox A report's Template inherits the report's `file_extension`, `mime_type`, and `title` attributes. * @test */ public function file_extension() { $reportsTable = $this->db->get_table(Reports::reports_table_name()); $reports = new Reports($this->db); // 1. No file_extension attribute is set, but the others are. $report1 = $reportsTable->save_record(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->save_record(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; } }