Ejemplo n.º 1
0
 public function test01()
 {
     $this->runAudit();
     // TABLE1 MUST and TABLE2 MUST not exist.
     $tables = $this->getAuditTables();
     $this->assertNotNull(StaticDataLayer::searchInRowSet('table_name', 'TABLE1', $tables));
     $this->assertNull(StaticDataLayer::searchInRowSet('table_name', 'TABLE2', $tables));
     // TABLE1 MUST have triggers.
     $triggers = $this->getTableTriggers('TABLE1');
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_insert', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_update', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_delete', $triggers));
     // Create new table TABLE2.
     StaticDataLayer::multiQuery(file_get_contents(__DIR__ . '/config/create_new_table.sql'));
     $this->runAudit();
     // TABLE1 and TABLE2 MUST exist.
     $tables = $this->getAuditTables();
     $this->assertNotNull(StaticDataLayer::searchInRowSet('table_name', 'TABLE1', $tables));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('table_name', 'TABLE2', $tables));
     // TABLE1 and TABLE2 MUST have triggers.
     $triggers = $this->getTableTriggers('TABLE1');
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_insert', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_update', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_delete', $triggers));
     $triggers = $this->getTableTriggers('TABLE2');
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t2_insert', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t2_update', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t2_delete', $triggers));
 }
Ejemplo n.º 2
0
 public function test01()
 {
     // Run audit.
     $this->runAudit();
     // TABLE1 MUST exist.
     $tables = $this->getAuditTables();
     $this->assertNotNull(StaticDataLayer::searchInRowSet('table_name', 'TABLE1', $tables));
     // TABLE1 MUST have triggers.
     $triggers = $this->getTableTriggers('TABLE1');
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_insert', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_update', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_delete', $triggers));
     $actual = $this->getTableColumns(self::$auditSchema, 'TABLE1');
     $expected = [];
     $expected[] = ['column_name' => 'c1', 'column_type' => 'tinyint(4)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $expected[] = ['column_name' => 'c2', 'column_type' => 'smallint(6)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $expected[] = ['column_name' => 'c3', 'column_type' => 'mediumint(9)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $expected[] = ['column_name' => 'c4', 'column_type' => 'int(11)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $this->assertSame($expected, $actual);
     // Test triggers.
     StaticDataLayer::query('insert into `TABLE1`(c1, c2, c3, c4) values(1, 2, 3, 4)');
     StaticDataLayer::query('update `TABLE1` set c1=10, c2=20, c3=30, c4=40');
     StaticDataLayer::query('delete from `TABLE1`');
     $rows = StaticDataLayer::executeRows(sprintf('select * from `%s`.`TABLE1` where c3 is not null', self::$auditSchema));
     $this->assertSame(4, count($rows));
     // Drop column c3.
     StaticDataLayer::multiQuery(file_get_contents(__DIR__ . '/config/drop_column.sql'));
     $this->runAudit();
     // TABLE1 MUST exist.
     $tables = $this->getAuditTables();
     $this->assertNotNull(StaticDataLayer::searchInRowSet('table_name', 'TABLE1', $tables));
     // TABLE1 MUST have triggers.
     $triggers = $this->getTableTriggers('TABLE1');
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_insert', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_update', $triggers));
     $this->assertNotNull(StaticDataLayer::searchInRowSet('trigger_name', 'trg_t1_delete', $triggers));
     // TABLE1 must have column c3.
     $actual = $this->getTableColumns(self::$auditSchema, 'TABLE1');
     $expected = [];
     $expected[] = ['column_name' => 'c1', 'column_type' => 'tinyint(4)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $expected[] = ['column_name' => 'c2', 'column_type' => 'smallint(6)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $expected[] = ['column_name' => 'c3', 'column_type' => 'mediumint(9)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $expected[] = ['column_name' => 'c4', 'column_type' => 'int(11)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null];
     $this->assertSame($expected, $actual);
     // Test triggers.
     StaticDataLayer::query('insert into `TABLE1`(c1, c2, c4) values(1, 2, 4)');
     StaticDataLayer::query('update `TABLE1` set c1=10, c2=20, c4=40');
     StaticDataLayer::query('delete from `TABLE1`');
     // Assert we 4 rows with c3 is null.
     $rows = StaticDataLayer::executeRows(sprintf('select * from `%s`.`TABLE1` where c3 is null', self::$auditSchema));
     $this->assertSame(4, count($rows));
     // Assert we 8 rows in total.
     $rows = StaticDataLayer::executeRows(sprintf('select * from `%s`.`TABLE1`', self::$auditSchema));
     $this->assertSame(8, count($rows));
 }
Ejemplo n.º 3
0
 public function test01()
 {
     // Run audit.
     $this->runAudit();
     // Insert a row into TABLE1.
     StaticDataLayer::query('insert into `TABLE1`(c1, c2, c3, c4) values(1, 2, 3, 4)');
     // Rename column c3 and d3.
     StaticDataLayer::multiQuery(file_get_contents(__DIR__ . '/config/rename_column.sql'));
     $status = $this->runAudit();
     $this->assertSame(1, $status);
 }
Ejemplo n.º 4
0
 /**
  * Connects to the MySQL server.
  */
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     StaticDataLayer::multiQuery(file_get_contents(__DIR__ . '/config/setup.sql'));
 }