From 4d169dd8a00258d9187fc2ba43f82d413b1f3987 Mon Sep 17 00:00:00 2001 From: Deltik Date: Thu, 7 Feb 2019 20:44:25 -0600 Subject: [PATCH 1/5] Removed print_r()s that were probably accidentally committed --- e107 | 2 +- tests/unit/db_verifyTest.php | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/e107 b/e107 index 0f96f7cab..3976b9b4b 160000 --- a/e107 +++ b/e107 @@ -1 +1 @@ -Subproject commit 0f96f7cabddfb4690497fc6b22f25da2f4330de2 +Subproject commit 3976b9b4bd8920d9ea59ca34da35927a62d0c761 diff --git a/tests/unit/db_verifyTest.php b/tests/unit/db_verifyTest.php index b1cdcc90b..4643057e4 100644 --- a/tests/unit/db_verifyTest.php +++ b/tests/unit/db_verifyTest.php @@ -628,21 +628,12 @@ $actual = $this->dbv->getSqlFileTables($sql); - if($table == 'test_json') - { - print_r($actual); - print_r($this->dbv->results); - } - $this->assertEquals($actual['tables'], $expected[$table]['tables'], "Table ".$table." could not be parsed."); foreach($expected[$table]['data'] as $k=>$data) { $data = str_replace("\t", '', $data); $this->assertEquals($actual['data'][$k], $data, "Table ".$table."['data'][".$k."] did not match."); - - $fields = $this->dbv->getFields($actual['data'][$k]); - print_r($fields); } $this->assertEquals($actual['engine'], $expected[$table]['engine']); From 92fb16fe86189c87ff7dfa7b4cf6449f28e16dce Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Fri, 8 Feb 2019 20:53:49 +0100 Subject: [PATCH 2/5] fixed the assertions in e_db_mysqlTest --- tests/unit/e_db_mysqlTest.php | 38 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/unit/e_db_mysqlTest.php b/tests/unit/e_db_mysqlTest.php index 53620b98c..900e53f7d 100644 --- a/tests/unit/e_db_mysqlTest.php +++ b/tests/unit/e_db_mysqlTest.php @@ -245,7 +245,7 @@ */ public function testInsert() { - $actual = $this->db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'test insert')); + $actual = $this->db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Insert test')); $this->assertEquals(1, $actual, 'Unable to add record to table #tmp'); } /* @@ -286,17 +286,18 @@ $db->delete('tmp'); // Test 1 - $expected = $db->update('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'test 1', 'WHERE' => 'tmp_ip="127.0.0.1"')); + $expected = $db->update('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Update test 1', 'WHERE' => 'tmp_ip="127.0.0.1"')); $this->assertEmpty($expected, "Test 1 update() failed (not empty {$expected})"); + $actual = 1; // Test 2 - $actual = $db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'test 2')); - $expected = $db->update('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'test 2a', 'WHERE' => 'tmp_ip="127.0.0.1"')); - $this->assertEquals(1, $expected, "Test 2 update() failed ({$actual} != {$expected}"); + $db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'test 2')); + $expected = $db->update('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Update test 2a', 'WHERE' => 'tmp_ip="127.0.0.1"')); + $this->assertEquals($actual, $expected, "Test 2 update() failed ({$actual} != {$expected}"); // Test 3 - $expected = $db->update('tmp', 'tmp_ip = "127.0.0.1", tmp_time = tmp_time + 1, tmp_info = "test 3" WHERE tmp_ip="127.0.0.1"'); - $this->assertEquals(1, $expected, "Test 3 update() failed ({$actual} != {$expected}"); + $expected = $db->update('tmp', 'tmp_ip = "127.0.0.1", tmp_time = tmp_time + 1, tmp_info = "Update test 3" WHERE tmp_ip="127.0.0.1"'); + $this->assertEquals($actual, $expected, "Test 3 update() failed ({$actual} != {$expected}"); } /* @@ -357,10 +358,29 @@ */ public function testDelete() { - $expected = $this->db->count('tmp'); + // make sure the table is empty $actual = $this->db->delete('tmp'); - $this->assertEquals($expected, $actual, 'Unable to delete all records.'); + $this->assertNotEmpty($actual, 'Unable to empty the table.'); + // Insert some records + $this->db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Delete test 1')); + $this->db->insert('tmp', array('tmp_ip' => '127.0.0.2', 'tmp_time' => time(), 'tmp_info' => 'Delete test 2')); + $this->db->insert('tmp', array('tmp_ip' => '127.0.0.3', 'tmp_time' => time(), 'tmp_info' => 'Delete test 3')); + + + // Delete 1 record + $expected = 1; + $actual = $this->db->delete('tmp', 'tmp_ip="127.0.0.1"'); + $this->assertEquals($expected, $actual, 'Unable to delete 1 records.'); + + // Delete all remaining (2) records + $expected = 2; + $actual = $this->db->delete('tmp'); + $this->assertEquals($expected, $actual, 'Unable to delete the remaining records.'); + + // Delete from an table that doesn't exist + $actual = $this->db->delete('tmp_unknown_table'); + $this->assertFalse($actual, 'Trying to delete records from an invalid table should return FALSE!'); } /* public function testDb_Delete() From 77374ae03c568030373f57d57bd7f30cd7d55588 Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Fri, 8 Feb 2019 21:17:29 +0100 Subject: [PATCH 3/5] fixed typo in testUpdate() Added additional assertion in testInsert() --- tests/unit/e_db_mysqlTest.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/unit/e_db_mysqlTest.php b/tests/unit/e_db_mysqlTest.php index 900e53f7d..d3d360092 100644 --- a/tests/unit/e_db_mysqlTest.php +++ b/tests/unit/e_db_mysqlTest.php @@ -245,8 +245,16 @@ */ public function testInsert() { - $actual = $this->db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Insert test')); + $actual = $this->db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => '12345435', 'tmp_info' => 'Insert test')); $this->assertEquals(1, $actual, 'Unable to add record to table #tmp'); + + $expected = array( + 'tmp_ip' => '127.0.0.1', + 'tmp_time' => '12345435', + 'tmp_info' => 'Insert test' + ); + $actual = $this->db->retrieve('tmp', '*','tmp_ip = "127.0.0.1" AND tmp_time = 12345435'); + $this->assertEquals($expected, $actual, 'Inserted content doesn\'t match the retrieved content'); } /* public function testLastInsertId() @@ -293,11 +301,11 @@ // Test 2 $db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'test 2')); $expected = $db->update('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Update test 2a', 'WHERE' => 'tmp_ip="127.0.0.1"')); - $this->assertEquals($actual, $expected, "Test 2 update() failed ({$actual} != {$expected}"); + $this->assertEquals($expected, $actual, "Test 2 update() failed ({$actual} != {$expected}"); // Test 3 $expected = $db->update('tmp', 'tmp_ip = "127.0.0.1", tmp_time = tmp_time + 1, tmp_info = "Update test 3" WHERE tmp_ip="127.0.0.1"'); - $this->assertEquals($actual, $expected, "Test 3 update() failed ({$actual} != {$expected}"); + $this->assertEquals($expected, $actual, "Test 3 update() failed ({$actual} != {$expected}"); } /* From 964eef125ebadd04fcb78ee10932ba809bfedf73 Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Fri, 8 Feb 2019 21:27:03 +0100 Subject: [PATCH 4/5] Added additional assertion in testUpdate() Added additional assertion in testDelete() --- tests/unit/e_db_mysqlTest.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/unit/e_db_mysqlTest.php b/tests/unit/e_db_mysqlTest.php index d3d360092..ac07878bd 100644 --- a/tests/unit/e_db_mysqlTest.php +++ b/tests/unit/e_db_mysqlTest.php @@ -245,9 +245,11 @@ */ public function testInsert() { + // Test 1 $actual = $this->db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => '12345435', 'tmp_info' => 'Insert test')); $this->assertEquals(1, $actual, 'Unable to add record to table #tmp'); + // Test 2 Verify content $expected = array( 'tmp_ip' => '127.0.0.1', 'tmp_time' => '12345435', @@ -300,13 +302,22 @@ $actual = 1; // Test 2 $db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'test 2')); - $expected = $db->update('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Update test 2a', 'WHERE' => 'tmp_ip="127.0.0.1"')); + $expected = $db->update('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => '1234567', 'tmp_info' => 'Update test 2a', 'WHERE' => 'tmp_ip="127.0.0.1"')); $this->assertEquals($expected, $actual, "Test 2 update() failed ({$actual} != {$expected}"); // Test 3 $expected = $db->update('tmp', 'tmp_ip = "127.0.0.1", tmp_time = tmp_time + 1, tmp_info = "Update test 3" WHERE tmp_ip="127.0.0.1"'); $this->assertEquals($expected, $actual, "Test 3 update() failed ({$actual} != {$expected}"); + // Test 4: Verify content + $expected = array( + 'tmp_ip' => '127.0.0.1', + 'tmp_time' => '1234568', + 'tmp_info' => 'Update test 3' + ); + $actual = $this->db->retrieve('tmp', '*','tmp_ip = "127.0.0.1"'); + $this->assertEquals($expected, $actual, 'Test 4: Updated content doesn\'t match the retrieved content'); + } /* public function testDb_Update() @@ -375,6 +386,10 @@ $this->db->insert('tmp', array('tmp_ip' => '127.0.0.2', 'tmp_time' => time(), 'tmp_info' => 'Delete test 2')); $this->db->insert('tmp', array('tmp_ip' => '127.0.0.3', 'tmp_time' => time(), 'tmp_info' => 'Delete test 3')); + // Count records + $expected = 3; + $actual = $this->db->count('tmp'); + $this->assertEquals($expected, $actual, "Number of inserted records is wrong ({$expected} != {$actual}"); // Delete 1 record $expected = 1; From 77a2ae1092981fcbebbe1b840eee44949a681e2d Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Fri, 8 Feb 2019 21:45:01 +0100 Subject: [PATCH 5/5] Added additional assertion in testDelete() --- tests/unit/e_db_mysqlTest.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/unit/e_db_mysqlTest.php b/tests/unit/e_db_mysqlTest.php index ac07878bd..02aeae8fa 100644 --- a/tests/unit/e_db_mysqlTest.php +++ b/tests/unit/e_db_mysqlTest.php @@ -378,8 +378,15 @@ public function testDelete() { // make sure the table is empty + // table may contain data, so number of deleted records is unknown, + // but should always be >= 0 $actual = $this->db->delete('tmp'); - $this->assertNotEmpty($actual, 'Unable to empty the table.'); + $this->assertGreaterThanOrEqual(0, $actual, 'Unable to empty the table.'); + + // Check if the returned value is equal to the number of affected records + $expected = $actual; + $actual = $this->db->rowCount(); + $this->assertEquals($expected, $actual, "Number of deleted records is wrong ({$expected} != {$actual}"); // Insert some records $this->db->insert('tmp', array('tmp_ip' => '127.0.0.1', 'tmp_time' => time(), 'tmp_info' => 'Delete test 1')); @@ -396,11 +403,21 @@ $actual = $this->db->delete('tmp', 'tmp_ip="127.0.0.1"'); $this->assertEquals($expected, $actual, 'Unable to delete 1 records.'); + // Check if the returned value is equal to the number of affected records + $expected = $actual; + $actual = $this->db->rowCount(); + $this->assertEquals($expected, $actual, "Number of deleted records is wrong ({$expected} != {$actual}"); + // Delete all remaining (2) records $expected = 2; $actual = $this->db->delete('tmp'); $this->assertEquals($expected, $actual, 'Unable to delete the remaining records.'); + // Check if the returned value is equal to the number of affected records + $expected = $actual; + $actual = $this->db->rowCount(); + $this->assertEquals($expected, $actual, "Number of deleted records is wrong ({$expected} != {$actual}"); + // Delete from an table that doesn't exist $actual = $this->db->delete('tmp_unknown_table'); $this->assertFalse($actual, 'Trying to delete records from an invalid table should return FALSE!');