From de6cb22225153c9391094d09b363ce392d487d6d Mon Sep 17 00:00:00 2001
From: Cameron <e107inc@gmail.com>
Date: Sat, 16 Feb 2019 12:52:07 -0800
Subject: [PATCH] Extra tests for copyRow on tables with unique fields.

---
 tests/unit/e_dateTest.php   |  2 +-
 tests/unit/e_db_pdoTest.php | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/tests/unit/e_dateTest.php b/tests/unit/e_dateTest.php
index 34576ed88..11ce3f1ff 100644
--- a/tests/unit/e_dateTest.php
+++ b/tests/unit/e_dateTest.php
@@ -255,7 +255,7 @@
 				$data = $this->dateObj->terms($input);
 				$this->assertEquals($expected, $data[2]);
 			}
-			
+
 		}
 
 
diff --git a/tests/unit/e_db_pdoTest.php b/tests/unit/e_db_pdoTest.php
index 03292365c..10b66aa2f 100644
--- a/tests/unit/e_db_pdoTest.php
+++ b/tests/unit/e_db_pdoTest.php
@@ -226,6 +226,11 @@
 			$result = $res->fetch();
 			$this->assertEquals('email@address.com', $result['user_email']);
 
+			// duplicate unique field 'media_cat_category', should return false/error.
+			$result = $this->db->db_Query("INSERT INTO ".MPREFIX."core_media_cat(media_cat_owner,media_cat_title,media_cat_category,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order) SELECT media_cat_owner,media_cat_title,media_cat_category,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order FROM ".MPREFIX."core_media_cat WHERE media_cat_id = 1");
+			$err = $this->db->getLastErrorText();
+			$this->assertFalse($result, $err);
+
 		}
 
 
@@ -335,6 +340,21 @@
 			);
 			$this->assertEquals(1,$result);
 
+
+			$qry = "INSERT INTO #core_media_cat(media_cat_owner,media_cat_title,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order) SELECT media_cat_owner,media_cat_title,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order FROM #core_media_cat WHERE media_cat_id = 1";
+			$result = $this->db->db_Select_gen($qry);
+
+
+			$qry = "INSERT INTO #core_media_cat(media_cat_owner,media_cat_title,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order) SELECT media_cat_owner,media_cat_title,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order FROM #core_media_cat WHERE media_cat_id = 1";
+			$result = $this->db->db_Select_gen($qry);
+			$this->assertFalse($result);
+		//	$error = $this->db->getLastErrorText();
+
+			$result = $this->db->db_Query("INSERT INTO ".MPREFIX."core_media_cat(media_cat_owner,media_cat_title,media_cat_category,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order) SELECT media_cat_owner,media_cat_title,media_cat_category,media_cat_sef,media_cat_diz,media_cat_class,media_cat_image,media_cat_order FROM ".MPREFIX."core_media_cat WHERE media_cat_id = 1");
+			$err = $this->db->getLastErrorText();
+			$this->assertFalse($result);
+
+
 		}
 
 		public function testInsert()
@@ -887,6 +907,16 @@
 			$result = $this->db->db_CopyRow('news', null);
 			$this->assertFalse($result);
 
+			// test with table that has unique keys.
+			$result = $this->db->db_CopyRow('core_media_cat', '*', "media_cat_id = 1");
+			$qry = $this->db->getLastErrorText();
+			$this->assertGreaterThan(1,$result, $qry);
+
+			// test with table that has unique keys. (same row again) - make sure copyRow duplicates it regardless.
+			$result = $this->db->db_CopyRow('core_media_cat', '*', "media_cat_id = 1");
+			$qry = $this->db->getLastErrorText();
+			$this->assertGreaterThan(1,$result, $qry);
+
 		}
 
 		public function testDb_CopyTable()