private static function expand_partitioned_table(&$doc, $schema, $table)
 {
     // Validate
     if (!isset($table->tablePartition['type'])) {
         throw new exception('No table partiton type selected for ' . $table['name']);
     }
     if ($table->tablePartition['type'] != 'MODULO') {
         throw new exception('Invalid partition type: ' . $table->tablePartition['type']);
     }
     // Establish the partition column and number of partitions
     self::$part_number = NULL;
     self::$part_column = NULL;
     self::$first_slony_id = NULL;
     self::$last_slony_id = NULL;
     foreach ($table->tablePartition->tablePartitionOption as $opt) {
         if ($opt['name'] == 'number') {
             self::$part_number = $opt['value'];
         }
         if ($opt['name'] == 'column') {
             self::$part_column = pgsql8::get_quoted_column_name($opt['value']);
         }
         if ($opt['name'] == 'firstSlonyId') {
             self::$first_slony_id = (int) $opt['value'];
         }
         if ($opt['name'] == 'lastSlonyId') {
             self::$last_slony_id = (int) $opt['value'];
         }
     }
     if (empty(self::$part_number)) {
         throw new exception('tablePartitionOption "number" must be specified for table ' . $table['name']);
     }
     if (empty(self::$part_column)) {
         throw new exception('tablePartitionOption "column" must be specified for table ' . $table['name']);
     }
     if (!is_null(self::$first_slony_id) && !is_null(self::$last_slony_id)) {
         $slony_ids_allocated = self::$last_slony_id - self::$first_slony_id + 1;
         if ($slony_ids_allocated != self::$part_number) {
             throw new exception('Requested ' . self::$part_number . " partitions but provided {$slony_ids_allocated} slony IDs");
         }
     }
     // Create the schema node for the partitions
     $new_schema = $doc->addChild('schema');
     self::create_partition_schema($schema, $table, $new_schema);
     // Clone the node as many times as needed to create the partition tables
     self::create_partition_tables($schema, $new_schema, $table);
     // Remove attributes from the main table that move to the partitions
     unset($table->index);
     // Add the trigger to the main table
     $trigger = $schema->addChild('trigger');
     $trigger->addAttribute('name', $table['name'] . '_part_trg');
     $trigger->addAttribute('sqlFormat', 'pgsql8');
     $trigger->addAttribute('event', 'INSERT');
     $trigger->addAttribute('when', 'BEFORE');
     $trigger->addAttribute('table', $table['name']);
     $trigger->addAttribute('forEach', 'ROW');
     $trigger->addAttribute('function', $new_schema['name'] . '.insert_trigger()');
     // Create the stored prodecure
     self::create_procedure($new_schema, $table);
 }
 /**
  * @dataProvider processProvider()
  */
 public function testProcess($in_xml, $out_xml)
 {
     $doc = new SimpleXMLElement(file_get_contents($in_xml));
     pgsql8_xml_parser::process($doc);
     // Uncomment this line to create the _out file that will be asserted against.
     // Make sure to double check the contents and then commit to version control
     //file_put_contents($out_xml, $doc->saveXML());
     $this->assertEquals(new SimpleXMLElement(file_get_contents($out_xml)), $doc);
 }