Example #1
0
 /**
  * Delete everything out of our testing database.
  */
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     \Definition::truncate();
     \CsvDefinition::truncate();
     \InstalledDefinition::truncate();
     \JsonDefinition::truncate();
     \ShpDefinition::truncate();
     \SparqlDefinition::truncate();
     \XlsDefinition::truncate();
     \XmlDefinition::truncate();
     \GeoProperty::truncate();
     \TabularColumns::truncate();
     \Geoprojection::truncate();
 }
Example #2
0
 public function testDeleteApi()
 {
     // Delete the published definition for each test xls file.
     foreach ($this->test_data as $entry) {
         $file = $entry['file'];
         $this->updateRequest('DELETE');
         $controller = \App::make('Tdt\\Core\\Definitions\\DefinitionController');
         $response = $controller->handle("xls/{$file}");
         $this->assertEquals(200, $response->getStatusCode());
     }
     // Check if everything is deleted properly.
     $definitions_count = \Definition::all()->count();
     $xls_count = \XlsDefinition::all()->count();
     $this->assertTrue($xls_count == 0);
     $this->assertTrue($definitions_count == 0);
 }
Example #3
0
 /**
  * Seed the XLS definitions
  */
 private function seedXls()
 {
     $xls_data = array('baseball' => array('description' => 'Individual offensive statistics from the 2008 Major League Baseball season.', 'columns' => array(array('column_name' => 'Player', 'index' => 0, 'column_name_alias' => 'Player', 'is_pk' => 0), array('column_name' => 'Id', 'index' => 1, 'column_name_alias' => 'Id', 'is_pk' => 0), array('column_name' => 'Salary', 'index' => 2, 'column_name_alias' => 'Salary', 'is_pk' => 0), array('column_name' => 'Rookie', 'index' => 3, 'column_name_alias' => 'Rookie', 'is_pk' => 0), array('column_name' => 'Position', 'index' => 4, 'column_name_alias' => 'Position', 'is_pk' => 0))));
     $added = false;
     foreach ($xls_data as $file => $definition_info) {
         // Don't create doubles
         $definition = Definition::where('collection_uri', '=', 'xls')->where('resource_name', '=', $file)->first();
         if (empty($definition)) {
             // Create a new XlsDefinition
             $xls_def = new XlsDefinition();
             $xls_def->uri = app_path() . '/storage/data/xls/' . $file . '.xlsx';
             $xls_def->description = $definition_info['description'];
             $xls_def->sheet = 'Sheet1';
             $xls_def->has_header_row = 1;
             $xls_def->start_row = 0;
             $xls_def->save();
             // Add the tabular columns
             foreach ($definition_info['columns'] as $column) {
                 $tab_column = new TabularColumns();
                 $tab_column->column_name = $column['column_name'];
                 $tab_column->index = $column['index'];
                 $tab_column->column_name_alias = $column['column_name_alias'];
                 $tab_column->is_pk = $column['is_pk'];
                 $tab_column->tabular_id = $xls_def->id;
                 $tab_column->tabular_type = 'XlsDefinition';
                 $tab_column->save();
             }
             // Add the XlsDefinition to the Definition
             $definition = new Definition();
             $definition->collection_uri = 'xls';
             $definition->resource_name = $file;
             $definition->source_id = $xls_def->id;
             $definition->source_type = 'XlsDefinition';
             $definition->draft = false;
             $definition->save();
             $this->command->info("Published an XLS file, {$file}, on uri (relative to the root) xls/{$file} .");
             $added = true;
         }
     }
     if (!$added) {
         $this->command->info("No XLS files have been published, all of the uri's that the XLS seeder wanted to use are already taken.");
     }
 }