Skip to content
This repository

Joomla CMS [#27415] Missing platform change for update notification #657

Merged
merged 19 commits into from over 2 years ago

9 participants

Mark Dexter Jools Nikolai Plath Rouven Weßling Louis Landry elinw Christophe Demko Nicholas K. Dionysopoulos Andrew Eddie
Mark Dexter

I missed a platform change when this feature was added to the CMS. This is the change. It is already in the CMS version of this file. Thanks.

Jools
Collaborator

Unit testing complete. There were 0 failures and 0 errors from 1962 tests and 11128 assertions.
Checkstyle analysis reported 199 warnings and 12 errors.

libraries/joomla/updater/updater.php
@@ -63,12 +63,13 @@ public static function &getInstance()
63 63
 	 * Finds an update for an extension
64 64
 	 *
65 65
 	 * @param   integer  $eid  Extension Identifier; if zero use all sites
1
Rouven Weßling Collaborator

This needs to align with the param below it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
libraries/joomla/updater/updater.php
((5 lines not shown))
66 67
 	 *
67 68
 	 * @return  boolean True if there are updates
68 69
 	 *
69 70
 	 * @since   11.1
70 71
 	 */
71  
-	public function findUpdates($eid = 0)
  72
+	public function findUpdates($eid=0, $cache_timeout = 0)
2
Rouven Weßling Collaborator

The equal sign needs to be surrounded by spaces.

I'd also like to see the $cache_timeout changed to $cacheTimeout. We should be using camelcase for everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
libraries/joomla/updater/updater.php
@@ -103,6 +105,14 @@ public function findUpdates($eid = 0)
103 105
 				// Ignore update sites requiring adapters we don't have installed
104 106
 				continue;
105 107
 			}
  108
+			if($cache_timeout > 0) {
1
Rouven Weßling Collaborator

Missing space behind the if, opening parenthesis must be on a new line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
libraries/joomla/updater/updater.php
@@ -103,6 +105,14 @@ public function findUpdates($eid = 0)
103 105
 				// Ignore update sites requiring adapters we don't have installed
104 106
 				continue;
105 107
 			}
  108
+			if($cache_timeout > 0) {
  109
+				if ($now - $result['last_check_timestamp'] <= $cache_timeout) {
1
Rouven Weßling Collaborator

Opening parenthesis must be on a new line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
libraries/joomla/updater/updater.php
@@ -172,6 +182,14 @@ public function findUpdates($eid = 0)
172 182
 			{
173 183
 				$update_result = true;
174 184
 			}
  185
+			
  186
+			// Finally, update the last update check timestamp
  187
+			$query = $dbo->getQuery(true);
  188
+			$query->update($dbo->quoteName('#__update_sites'));
  189
+			$query->set($dbo->quoteName('last_check_timestamp').' = '.$dbo->quote($now));
1
Rouven Weßling Collaborator

When concating string the . operator must be surrounded by spaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
libraries/joomla/updater/updater.php
@@ -172,6 +182,14 @@ public function findUpdates($eid = 0)
172 182
 			{
173 183
 				$update_result = true;
174 184
 			}
  185
+			
  186
+			// Finally, update the last update check timestamp
  187
+			$query = $dbo->getQuery(true);
  188
+			$query->update($dbo->quoteName('#__update_sites'));
  189
+			$query->set($dbo->quoteName('last_check_timestamp').' = '.$dbo->quote($now));
  190
+			$query->where($dbo->quoteName('update_site_id').' = '.$dbo->quote($result['update_site_id']));
1
Rouven Weßling Collaborator

Same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
added some commits
Louis Landry Merge pull request #658 from eddieajau/database
Add ability for JDatabase::quoteName to auto split and quote dotted strings
2150e6d
Louis Landry Merge pull request #659 from realityking/phpmd
Fix some PHPMD warnings.
63743d1
Louis Landry Merge pull request #656 from chdemko/26632
Joomla CMS [#26632] Inconsistent operation of user field type
77d899d
Louis Landry Merge pull request #623 from elinw/urlfilter
Add url filtering, improve url field, update  tests to reflect changes.
e638330
Nikolai Plath

Almost ;) three new ones.. Tip: Eclipse save actions (PHP): remove trailing white space ;)
http://elkuku.github.com/pulltester/pulls/657

Mark Dexter
Jools
Collaborator

Build triggered by changes to the head.

Unit testing complete. There were 0 failures and 0 errors from 1971 tests and 11142 assertions.
Checkstyle analysis reported 199 warnings and 0 errors.

Louis Landry LouisLandry merged commit 262a0c1 into from
Louis Landry LouisLandry closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 19 unique commits by 6 authors.

Dec 09, 2011
elinw Add url filtering, improve url field, update tests to reflect changes. e6f1136
elinw Code style fixes. f6a3307
elinw More checkstyle issues. 58d8f0c
elinw Yet more spaces. 1e25785
Dec 18, 2011
Nicholas K. Dionysopoulos Platform updater change for update notification feature 8b2626a
elinw More work on URL field and filter, fixing code style and making the f…
…orm object simpler.
692f5a8
elinw Fix url field. 542800d
elinw Missing tabs. 5007b89
Dec 19, 2011
Christophe Demko [#26632] Inconsistent operation of user field type 8278aca
Andrew Eddie Add ability for JDatabase::quoteName to auto split and quote dotted s…
…trings.

Add tests quoteName and improve code coverage of JDatabase.
aa8e383
Andrew Eddie Fix typo. 3bd52a9
Andrew Eddie Fix @since version. b193ac5
Louis Landry Merge pull request #658 from eddieajau/database
Add ability for JDatabase::quoteName to auto split and quote dotted strings
2150e6d
Louis Landry Merge pull request #659 from realityking/phpmd
Fix some PHPMD warnings.
63743d1
Louis Landry Merge pull request #656 from chdemko/26632
Joomla CMS [#26632] Inconsistent operation of user field type
77d899d
Louis Landry Merge pull request #623 from elinw/urlfilter
Add url filtering, improve url field, update  tests to reflect changes.
e638330
Mark Dexter Merge branch 'updater-fix' of https://github.com/dextercowley/joomla-…
…platform into updater-fix
a9e98d6
Mark Dexter Clean up code style d0a6374
Mark Dexter Trailing white space 8f6ba2c
This page is out of date. Refresh to see the latest.
25  libraries/joomla/database/database.php
@@ -1225,7 +1225,7 @@ public function loadRowList($key = null)
1225 1225
 	 * Method to quote and optionally escape a string to database requirements for insertion into the database.
1226 1226
 	 *
1227 1227
 	 * @param   string   $text    The string to quote.
1228  
-	 * @param   boolean  $escape  True to escape the string, false to leave it unchanged.
  1228
+	 * @param   boolean  $escape  True (default) to escape the string, false to leave it unchanged.
1229 1229
 	 *
1230 1230
 	 * @return  string  The quoted input string.
1231 1231
 	 *
@@ -1240,7 +1240,7 @@ public function quote($text, $escape = true)
1240 1240
 	 * Wrap an SQL statement identifier name such as column, table or database names in quotes to prevent injection
1241 1241
 	 * risks and reserved word conflicts.
1242 1242
 	 *
1243  
-	 * @param   string  $name  The identifier name to wrap in quotes.
  1243
+	 * @param   mixed  $name  The identifier name to wrap in quotes, or an array of parts to quote with dot-notation.
1244 1244
 	 *
1245 1245
 	 * @return  string  The quote wrapped name.
1246 1246
 	 *
@@ -1248,24 +1248,31 @@ public function quote($text, $escape = true)
1248 1248
 	 */
1249 1249
 	public function quoteName($name)
1250 1250
 	{
1251  
-		// Don't quote names with dot-notation.
1252  
-		if (strpos($name, '.') !== false)
  1251
+		if (is_string($name))
1253 1252
 		{
1254  
-			return $name;
  1253
+			$name = explode('.', $name);
1255 1254
 		}
1256  
-		else
  1255
+		elseif (!is_array($name))
1257 1256
 		{
1258  
-			$q = $this->nameQuote;
  1257
+			settype($name, 'array');
  1258
+		}
1259 1259
 
  1260
+		$parts = array();
  1261
+		$q = $this->nameQuote;
  1262
+
  1263
+		foreach ($name as $part)
  1264
+		{
1260 1265
 			if (strlen($q) == 1)
1261 1266
 			{
1262  
-				return $q . $name . $q;
  1267
+				$parts[] = $q . $part . $q;
1263 1268
 			}
1264 1269
 			else
1265 1270
 			{
1266  
-				return $q{0} . $name . $q{1};
  1271
+				$parts[] = $q{0} . $part . $q{1};
1267 1272
 			}
1268 1273
 		}
  1274
+
  1275
+		return implode('.', $parts);
1269 1276
 	}
1270 1277
 
1271 1278
 	/**
2  libraries/joomla/database/databasequery.php
@@ -136,7 +136,7 @@ public function __clone()
136 136
 abstract class JDatabaseQuery
137 137
 {
138 138
 	/**
139  
-	 * @var    resource  The database connection resource.
  139
+	 * @var    JDatabase  The database connection resource.
140 140
 	 * @since  11.1
141 141
 	 */
142 142
 	protected $db = null;
2  libraries/joomla/form/fields/user.php
@@ -81,7 +81,7 @@ protected function getInput()
81 81
 
82 82
 		// Create a dummy text field with the user name.
83 83
 		$html[] = '<div class="fltlft">';
84  
-		$html[] = '	<input type="text" id="' . $this->id . '_name"' . ' value="' . htmlspecialchars($table->username, ENT_COMPAT, 'UTF-8') . '"'
  84
+		$html[] = '	<input type="text" id="' . $this->id . '_name"' . ' value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"'
85 85
 			. ' disabled="disabled"' . $attr . ' />';
86 86
 		$html[] = '</div>';
87 87
 
51  libraries/joomla/form/form.php
@@ -1236,6 +1236,57 @@ protected function filterField($element, $value)
1236 1236
 				}
1237 1237
 				break;
1238 1238
 
  1239
+			// Ensures a protocol is present in the saved field. Only use when
  1240
+			// the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
  1241
+
  1242
+			case 'URL':
  1243
+				if (empty($value))
  1244
+				{
  1245
+					return;
  1246
+				}
  1247
+				$value = JFilterInput::getInstance()->clean($value, 'html');
  1248
+				$value = trim($value);
  1249
+
  1250
+				// Check for a protocol
  1251
+				$protocol = parse_url($value, PHP_URL_SCHEME);
  1252
+
  1253
+				// If there is no protocol and the relative option is not specified,
  1254
+				// we assume that it is an external URL and prepend http://.
  1255
+				if (($element['type'] == 'url' && !$protocol &&  !$element['relative'])
  1256
+					|| (!$element['type'] == 'url' && !$protocol))
  1257
+				{
  1258
+					$protocol = 'http';
  1259
+					// If it looks like an internal link, then add the root.
  1260
+					if (substr($value, 0) ==  'index.php')
  1261
+					{
  1262
+						$value = JURI::root() . $value;
  1263
+					}
  1264
+
  1265
+					// Otherwise we treat it is an external link.
  1266
+					// Put the url back together.
  1267
+					$value = $protocol . '://' . ltrim($value, $protocol);
  1268
+				}
  1269
+
  1270
+				// If relative URLS are allowed we assume that URLs without protocols are internal.
  1271
+				elseif (!$protocol && $element['relative'])
  1272
+				{
  1273
+					$host = JURI::getInstance('SERVER')->gethost();
  1274
+
  1275
+					// If it starts with the host string, just prepend the protocol.
  1276
+					if (substr($value, 0) == $host)
  1277
+					{
  1278
+						$value = 'http://' . $value;
  1279
+					}
  1280
+					// Otherwise prepend the root.
  1281
+					else
  1282
+					{
  1283
+						$value = JURI::root() . $value;
  1284
+					}
  1285
+				}
  1286
+
  1287
+				$return = $value;
  1288
+				break;
  1289
+
1239 1290
 			case 'TEL':
1240 1291
 				$value = trim($value);
1241 1292
 				// Does it match the NANP pattern?
30  libraries/joomla/updater/updater.php
@@ -62,13 +62,14 @@ public static function &getInstance()
62 62
 	/**
63 63
 	 * Finds an update for an extension
64 64
 	 *
65  
-	 * @param   integer  $eid  Extension Identifier; if zero use all sites
  65
+	 * @param   integer  $eid           Extension Identifier; if zero use all sites
  66
+	 * @param   integer  $cacheTimeout  How many seconds to cache update information; if zero, force reload the update information
66 67
 	 *
67 68
 	 * @return  boolean True if there are updates
68 69
 	 *
69 70
 	 * @since   11.1
70 71
 	 */
71  
-	public function findUpdates($eid = 0)
  72
+	public function findUpdates($eid = 0, $cacheTimeout = 0)
72 73
 	{
73 74
 		// Check if fopen is allowed
74 75
 		$result = ini_get('allow_url_fopen');
@@ -83,17 +84,18 @@ public function findUpdates($eid = 0)
83 84
 		// Push it into an array
84 85
 		if (!is_array($eid))
85 86
 		{
86  
-			$query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites WHERE enabled = 1';
  87
+			$query = 'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites WHERE enabled = 1';
87 88
 		}
88 89
 		else
89 90
 		{
90  
-			$query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites' .
  91
+			$query = 'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites' .
91 92
 				' WHERE update_site_id IN' .
92 93
 				'  (SELECT update_site_id FROM #__update_sites_extensions WHERE extension_id IN (' . implode(',', $eid) . '))';
93 94
 		}
94 95
 		$dbo->setQuery($query);
95 96
 		$results = $dbo->loadAssocList();
96 97
 		$result_count = count($results);
  98
+		$now = time();
97 99
 		for ($i = 0; $i < $result_count; $i++)
98 100
 		{
99 101
 			$result = &$results[$i];
@@ -103,6 +105,16 @@ public function findUpdates($eid = 0)
103 105
 				// Ignore update sites requiring adapters we don't have installed
104 106
 				continue;
105 107
 			}
  108
+			if ($cacheTimeout > 0)
  109
+			{
  110
+				if ($now - $result['last_check_timestamp'] <= $cacheTimeout)
  111
+				{
  112
+					// Ignore update sites whose information we have fetched within
  113
+					// the cache time limit
  114
+					$retval = true;
  115
+					continue;
  116
+				}
  117
+			}
106 118
 			$update_result = $this->_adapters[$result['type']]->findUpdate($result);
107 119
 			if (is_array($update_result))
108 120
 			{
@@ -172,6 +184,14 @@ public function findUpdates($eid = 0)
172 184
 			{
173 185
 				$update_result = true;
174 186
 			}
  187
+
  188
+			// Finally, update the last update check timestamp
  189
+			$query = $dbo->getQuery(true);
  190
+			$query->update($dbo->quoteName('#__update_sites'));
  191
+			$query->set($dbo->quoteName('last_check_timestamp') . ' = ' . $dbo->quote($now));
  192
+			$query->where($dbo->quoteName('update_site_id') . ' = ' . $dbo->quote($result['update_site_id']));
  193
+			$dbo->setQuery($query);
  194
+			$dbo->query();
175 195
 		}
176 196
 		return $retval;
177 197
 	}
@@ -192,7 +212,7 @@ public function findUpdates($eid = 0)
192 212
 	 */
193 213
 	public function arrayUnique($myArray)
194 214
 	{
195  
-		JLog::add('JUpdater::arrayUnique() is deprecated. See JArrayHelper::arrayUnique().', JLog::WARNING, 'deprecated');
  215
+		JLog::add('JUpdater::arrayUnique() is deprecated. See JArrayHelper::arrayUnique() . ', JLog::WARNING, 'deprecated');
196 216
 		return JArrayHelper::arrayUnique($myArray);
197 217
 	}
198 218
 
191  tests/suite/joomla/database/JDatabaseTest.php
@@ -5,7 +5,8 @@
5 5
  * @license		GNU General Public License version 2 or later; see LICENSE.txt
6 6
  */
7 7
 
8  
-require_once JPATH_PLATFORM.'/joomla/database/database.php';
  8
+require_once JPATH_PLATFORM . '/joomla/database/database.php';
  9
+require_once __DIR__ . '/stubs/nosqldriver.php';
9 10
 
10 11
 /**
11 12
  * Test class for JDatabase.
@@ -14,9 +15,10 @@
14 15
 class JDatabaseTest extends PHPUnit_Framework_TestCase
15 16
 {
16 17
 	/**
17  
-	 * @var	JDatabase
  18
+	 * @var	   JDatabase
  19
+	 * @since  11.4
18 20
 	 */
19  
-	protected $object;
  21
+	protected $db;
20 22
 
21 23
 	/**
22 24
 	 * Sets up the fixture, for example, opens a network connection.
@@ -24,10 +26,13 @@ class JDatabaseTest extends PHPUnit_Framework_TestCase
24 26
 	 */
25 27
 	protected function setUp()
26 28
 	{
27  
-		/**
28  
-		 * JDatabase is an abstract class
29  
-		 * $this->object = new JDatabase;
30  
-		 */
  29
+		$this->db = JDatabase::getInstance(
  30
+			array(
  31
+				'driver' => 'nosql',
  32
+				'database' => 'europa',
  33
+				'prefix' => '&',
  34
+			)
  35
+		);
31 36
 	}
32 37
 
33 38
 	/**
@@ -57,20 +62,85 @@ public function test__destruct()
57 62
 	}
58 63
 
59 64
 	/**
  65
+	 * Tests the JDatabase::getConnection method.
  66
+	 *
  67
+	 * @return  void
  68
+	 *
  69
+	 * @since   11.4
  70
+	 */
  71
+	public function testGetConnection()
  72
+	{
  73
+		ReflectionHelper::setValue($this->db, 'connection', 'foo');
  74
+
  75
+		$this->assertThat(
  76
+			$this->db->getConnection(),
  77
+			$this->equalTo('foo')
  78
+		);
  79
+	}
  80
+
  81
+	/**
60 82
 	 * @todo Implement testGetConnectors().
61 83
 	 */
62  
-	public function testGetConnectors() {
  84
+	public function testGetConnectors()
  85
+	{
63 86
 		// Remove the following lines when you implement this test.
64 87
 		$this->markTestIncomplete('This test has not been implemented yet.');
65 88
 	}
66 89
 
67 90
 	/**
  91
+	 * Tests the JDatabase::getCount method.
  92
+	 *
  93
+	 * @return  void
  94
+	 *
  95
+	 * @since   11.4
  96
+	 */
  97
+	public function testGetCount()
  98
+	{
  99
+		ReflectionHelper::setValue($this->db, 'count', 42);
  100
+
  101
+		$this->assertThat(
  102
+			$this->db->getCount(),
  103
+			$this->equalTo(42)
  104
+		);
  105
+	}
  106
+
  107
+	/**
  108
+	 * Tests the JDatabase::getDatabase method.
  109
+	 *
  110
+	 * @return  void
  111
+	 *
  112
+	 * @since   11.4
  113
+	 */
  114
+	public function testGetDatabase()
  115
+	{
  116
+		$this->assertThat(
  117
+			ReflectionHelper::invoke($this->db, 'getDatabase'),
  118
+			$this->equalTo('europa')
  119
+		);
  120
+	}
  121
+
  122
+	/**
  123
+	 * Tests the JDatabase::getDateFormat method.
  124
+	 *
  125
+	 * @return  void
  126
+	 *
  127
+	 * @since   11.4
  128
+	 */
  129
+	public function testGetDateFormat()
  130
+	{
  131
+		$this->assertThat(
  132
+			$this->db->getDateFormat(),
  133
+			$this->equalTo('Y-m-d H:i:s')
  134
+		);
  135
+	}
  136
+
  137
+	/**
68 138
 	 * @todo Implement testAddQuoted().
69 139
 	 */
70 140
 	public function testAddQuoted()
71 141
 	{
72 142
 		// Remove the following lines when you implement this test.
73  
-		$this->markTestIncomplete('This test has not been implemented yet.');
  143
+		$this->markTestSkipped('Deprecated method');
74 144
 	}
75 145
 
76 146
 	/**
@@ -88,7 +158,7 @@ public function testSplitSql()
88 158
 	public function testIsQuoted()
89 159
 	{
90 160
 		// Remove the following lines when you implement this test.
91  
-		$this->markTestIncomplete('This test has not been implemented yet.');
  161
+		$this->markTestSkipped('Deprecated method');
92 162
 	}
93 163
 
94 164
 	/**
@@ -128,12 +198,20 @@ public function testGetErrorMsg()
128 198
 	}
129 199
 
130 200
 	/**
131  
-	 * @todo Implement testGetLog().
  201
+	 * Tests the JDatabase::getLog method.
  202
+	 *
  203
+	 * @return  void
  204
+	 *
  205
+	 * @since   11.4
132 206
 	 */
133 207
 	public function testGetLog()
134 208
 	{
135  
-		// Remove the following lines when you implement this test.
136  
-		$this->markTestIncomplete('This test has not been implemented yet.');
  209
+		ReflectionHelper::setValue($this->db, 'log', 'foo');
  210
+
  211
+		$this->assertThat(
  212
+			$this->db->getLog(),
  213
+			$this->equalTo('foo')
  214
+		);
137 215
 	}
138 216
 
139 217
 	/**
@@ -155,21 +233,33 @@ public function testNameQuote()
155 233
 	}
156 234
 
157 235
 	/**
158  
-	 * @todo Implement testGetPrefix().
  236
+	 * Tests the JDatabase::getDateFormat method.
  237
+	 *
  238
+	 * @return  void
  239
+	 *
  240
+	 * @since   11.4
159 241
 	 */
160 242
 	public function testGetPrefix()
161 243
 	{
162  
-		// Remove the following lines when you implement this test.
163  
-		$this->markTestIncomplete('This test has not been implemented yet.');
  244
+		$this->assertThat(
  245
+			$this->db->getPrefix(),
  246
+			$this->equalTo('&')
  247
+		);
164 248
 	}
165 249
 
166 250
 	/**
167  
-	 * @todo Implement testGetNullDate().
  251
+	 * Tests the JDatabase::getDateFormat method.
  252
+	 *
  253
+	 * @return  void
  254
+	 *
  255
+	 * @since   11.4
168 256
 	 */
169 257
 	public function testGetNullDate()
170 258
 	{
171  
-		// Remove the following lines when you implement this test.
172  
-		$this->markTestIncomplete('This test has not been implemented yet.');
  259
+		$this->assertThat(
  260
+			$this->db->getNullDate(),
  261
+			$this->equalTo('1BC')
  262
+		);
173 263
 	}
174 264
 
175 265
 	/**
@@ -205,7 +295,7 @@ public function testGetQuery()
205 295
 	public function testStderr()
206 296
 	{
207 297
 		// Remove the following lines when you implement this test.
208  
-		$this->markTestIncomplete('This test has not been implemented yet.');
  298
+		$this->markTestSkipped('Deprecated method');
209 299
 	}
210 300
 
211 301
 	/**
@@ -218,12 +308,67 @@ public function testGetVersion()
218 308
 	}
219 309
 
220 310
 	/**
221  
-	 * @todo Implement testQuote().
  311
+	 * Tests the JDatabase::quote method.
  312
+	 *
  313
+	 * @return  void
  314
+	 *
  315
+	 * @since   11.4
222 316
 	 */
223 317
 	public function testQuote()
224 318
 	{
225  
-		// Remove the following lines when you implement this test.
226  
-		$this->markTestIncomplete('This test has not been implemented yet.');
  319
+		$this->assertThat(
  320
+			$this->db->quote('test', false),
  321
+			$this->equalTo("'test'"),
  322
+			'Tests the without escaping.'
  323
+		);
  324
+
  325
+		$this->assertThat(
  326
+			$this->db->quote('test'),
  327
+			$this->equalTo("'-test-'"),
  328
+			'Tests the with escaping (default).'
  329
+		);
  330
+	}
  331
+
  332
+	/**
  333
+	 * Tests the JDatabase::quoteName method.
  334
+	 *
  335
+	 * @return  void
  336
+	 *
  337
+	 * @since   11.4
  338
+	 */
  339
+	public function testQuoteName()
  340
+	{
  341
+		$this->assertThat(
  342
+			$this->db->quoteName('test'),
  343
+			$this->equalTo('[test]'),
  344
+			'Tests the left-right quotes on a string.'
  345
+		);
  346
+
  347
+		$this->assertThat(
  348
+			$this->db->quoteName('a.test'),
  349
+			$this->equalTo('[a].[test]'),
  350
+			'Tests the left-right quotes on a dotted string.'
  351
+		);
  352
+
  353
+		$this->assertThat(
  354
+			$this->db->quoteName(array('a', 'test')),
  355
+			$this->equalTo('[a].[test]'),
  356
+			'Tests the left-right quotes on an array.'
  357
+		);
  358
+
  359
+		$this->assertThat(
  360
+			$this->db->quoteName((object) array('a', 'test')),
  361
+			$this->equalTo('[a].[test]'),
  362
+			'Tests the left-right quotes on an object.'
  363
+		);
  364
+
  365
+		ReflectionHelper::setValue($this->db, 'nameQuote', '/');
  366
+
  367
+		$this->assertThat(
  368
+			$this->db->quoteName('test'),
  369
+			$this->equalTo('/test/'),
  370
+			'Tests the uni-quotes on a string.'
  371
+		);
227 372
 	}
228 373
 
229 374
 	/**
459  tests/suite/joomla/database/stubs/nosqldriver.php
... ...
@@ -0,0 +1,459 @@
  1
+<?php
  2
+/**
  3
+ * @package     Joomla.UnitTest
  4
+ * @subpackage  Database
  5
+ *
  6
+ * @copyright	Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved.
  7
+ * @license		GNU General Public License version 2 or later; see LICENSE.txt
  8
+ */
  9
+
  10
+/**
  11
+ * Test class JDatabase.
  12
+ *
  13
+ * @package     Joomla.UnitTest
  14
+ * @subpackage  Database
  15
+ * @since       11.4
  16
+ */
  17
+class JDatabaseNosql extends JDatabase
  18
+{
  19
+	/**
  20
+	 * The name of the database driver.
  21
+	 *
  22
+	 * @var    string
  23
+	 * @since  11.4
  24
+	 */
  25
+	public $name = 'nosql';
  26
+
  27
+	/**
  28
+	 * The character(s) used to quote SQL statement names such as table names or field names,
  29
+	 * etc. The child classes should define this as necessary.  If a single character string the
  30
+	 * same character is used for both sides of the quoted name, else the first character will be
  31
+	 * used for the opening quote and the second for the closing quote.
  32
+	 *
  33
+	 * @var    string
  34
+	 * @since  11.4
  35
+	 */
  36
+	protected $nameQuote = '[]';
  37
+
  38
+	/**
  39
+	 * The null or zero representation of a timestamp for the database driver.  This should be
  40
+	 * defined in child classes to hold the appropriate value for the engine.
  41
+	 *
  42
+	 * @var    string
  43
+	 * @since  11.4
  44
+	 */
  45
+	protected $nullDate = '1BC';
  46
+
  47
+	/**
  48
+	 * Determines if the connection to the server is active.
  49
+	 *
  50
+	 * @return  boolean  True if connected to the database engine.
  51
+	 *
  52
+	 * @since   11.4
  53
+	 */
  54
+	public function connected()
  55
+	{
  56
+		return true;
  57
+	}
  58
+
  59
+	/**
  60
+	 * Drops a table from the database.
  61
+	 *
  62
+	 * @param   string   $table     The name of the database table to drop.
  63
+	 * @param   boolean  $ifExists  Optionally specify that the table must exist before it is dropped.
  64
+	 *
  65
+	 * @return  JDatabase  Returns this object to support chaining.
  66
+	 *
  67
+	 * @since   11.4
  68
+	 * @throws  JDatabaseException
  69
+	 */
  70
+	public function dropTable($table, $ifExists = true)
  71
+	{
  72
+		return $this;
  73
+	}
  74
+
  75
+	/**
  76
+	 * Method to escape a string for usage in an SQL statement.
  77
+	 *
  78
+	 * @param   string   $text   The string to be escaped.
  79
+	 * @param   boolean  $extra  Optional parameter to provide extra escaping.
  80
+	 *
  81
+	 * @return  string   The escaped string.
  82
+	 *
  83
+	 * @since   11.4
  84
+	 */
  85
+	public function escape($text, $extra = false)
  86
+	{
  87
+		return $extra ? "/$text//" : "-$text-";
  88
+	}
  89
+
  90
+	/**
  91
+	 * Diagnostic method to return explain information for a query.
  92
+	 *
  93
+	 * @return  string  The explain output.
  94
+	 *
  95
+	 * @deprecated  12.1
  96
+	 * @since   11.4
  97
+	 */
  98
+	public function explain()
  99
+	{
  100
+		return 'Not possible.';
  101
+	}
  102
+
  103
+	/**
  104
+	 * Method to fetch a row from the result set cursor as an array.
  105
+	 *
  106
+	 * @param   mixed  $cursor  The optional result set cursor from which to fetch the row.
  107
+	 *
  108
+	 * @return  mixed  Either the next row from the result set or false if there are no more rows.
  109
+	 *
  110
+	 * @since   11.4
  111
+	 */
  112
+	protected function fetchArray($cursor = null)
  113
+	{
  114
+		return array();
  115
+	}
  116
+
  117
+	/**
  118
+	 * Method to fetch a row from the result set cursor as an associative array.
  119
+	 *
  120
+	 * @param   mixed  $cursor  The optional result set cursor from which to fetch the row.
  121
+	 *
  122
+	 * @return  mixed  Either the next row from the result set or false if there are no more rows.
  123
+	 *
  124
+	 * @since   11.4
  125
+	 */
  126
+	protected function fetchAssoc($cursor = null)
  127
+	{
  128
+		return array();
  129
+	}
  130
+
  131
+	/**
  132
+	 * Method to fetch a row from the result set cursor as an object.
  133
+	 *
  134
+	 * @param   mixed   $cursor  The optional result set cursor from which to fetch the row.
  135
+	 * @param   string  $class   The class name to use for the returned row object.
  136
+	 *
  137
+	 * @return  mixed   Either the next row from the result set or false if there are no more rows.
  138
+	 *
  139
+	 * @since   11.4
  140
+	 */
  141
+	protected function fetchObject($cursor = null, $class = 'stdClass')
  142
+	{
  143
+		return new $class;
  144
+	}
  145
+
  146
+	/**
  147
+	 * Method to free up the memory used for the result set.
  148
+	 *
  149
+	 * @param   mixed  $cursor  The optional result set cursor from which to fetch the row.
  150
+	 *
  151
+	 * @return  void
  152
+	 *
  153
+	 * @since   11.4
  154
+	 */
  155
+	protected function freeResult($cursor = null)
  156
+	{
  157
+		return null;
  158
+	}
  159
+
  160
+	/**
  161
+	 * Get the number of affected rows for the previous executed SQL statement.
  162
+	 *
  163
+	 * @return  integer  The number of affected rows.
  164
+	 *
  165
+	 * @since   11.4
  166
+	 */
  167
+	public function getAffectedRows()
  168
+	{
  169
+		return 0;
  170
+	}
  171
+
  172
+	/**
  173
+	 * Method to get the database collation in use by sampling a text field of a table in the database.
  174
+	 *
  175
+	 * @return  mixed  The collation in use by the database or boolean false if not supported.
  176
+	 *
  177
+	 * @since   11.4
  178
+	 */
  179
+	public function getCollation()
  180
+	{
  181
+		return false;
  182
+	}
  183
+
  184
+	/**
  185
+	 * Get the number of returned rows for the previous executed SQL statement.
  186
+	 *
  187
+	 * @param   resource  $cursor  An optional database cursor resource to extract the row count from.
  188
+	 *
  189
+	 * @return  integer   The number of returned rows.
  190
+	 *
  191
+	 * @since   11.4
  192
+	 */
  193
+	public function getNumRows($cursor = null)
  194
+	{
  195
+		return 0;
  196
+	}
  197
+
  198
+	/**
  199
+	 * Get the current query object or a new JDatabaseQuery object.
  200
+	 *
  201
+	 * @param   boolean  $new  False to return the current query object, True to return a new JDatabaseQuery object.
  202
+	 *
  203
+	 * @return  JDatabaseQuery  The current query object or a new object extending the JDatabaseQuery class.
  204
+	 *
  205
+	 * @since   11.4
  206
+	 * @throws  JDatabaseException
  207
+	 */
  208
+	public function getQuery($new = false)
  209
+	{
  210
+		return null;
  211
+	}
  212
+
  213
+	/**
  214
+	 * Retrieves field information about the given tables.
  215
+	 *
  216
+	 * @param   string   $table     The name of the database table.
  217
+	 * @param   boolean  $typeOnly  True (default) to only return field types.
  218
+	 *
  219
+	 * @return  array  An array of fields by table.
  220
+	 *
  221
+	 * @since   11.4
  222
+	 * @throws  JDatabaseException
  223
+	 */
  224
+	public function getTableColumns($table, $typeOnly = true)
  225
+	{
  226
+		return array();
  227
+	}
  228
+
  229
+	/**
  230
+	 * Shows the table CREATE statement that creates the given tables.
  231
+	 *
  232
+	 * @param   mixed  $tables  A table name or a list of table names.
  233
+	 *
  234
+	 * @return  array  A list of the create SQL for the tables.
  235
+	 *
  236
+	 * @since   11.4
  237
+	 * @throws  JDatabaseException
  238
+	 */
  239
+	public function getTableCreate($tables)
  240
+	{
  241
+		return '';
  242
+	}
  243
+
  244
+	/**
  245
+	 * Retrieves field information about the given tables.
  246
+	 *
  247
+	 * @param   mixed  $tables  A table name or a list of table names.
  248
+	 *
  249
+	 * @return  array  An array of keys for the table(s).
  250
+	 *
  251
+	 * @since   11.4
  252
+	 * @throws  JDatabaseException
  253
+	 */
  254
+	public function getTableKeys($tables)
  255
+	{
  256
+		return array();
  257
+	}
  258
+
  259
+	/**
  260
+	 * Method to get an array of all tables in the database.
  261
+	 *
  262
+	 * @return  array  An array of all the tables in the database.
  263
+	 *
  264
+	 * @since   11.4
  265
+	 * @throws  JDatabaseException
  266
+	 */
  267
+	public function getTableList()
  268
+	{
  269
+		return array();
  270
+	}
  271
+
  272
+	/**
  273
+	 * Get the version of the database connector
  274
+	 *
  275
+	 * @return  string  The database connector version.
  276
+	 *
  277
+	 * @since   11.4
  278
+	 */
  279
+	public function getVersion()
  280
+	{
  281
+		return null;
  282
+	}
  283
+
  284
+	/**
  285
+	 * Determines if the database engine supports UTF-8 character encoding.
  286
+	 *
  287
+	 * @return  boolean  True if supported.
  288
+	 *
  289
+	 * @since   11.4
  290
+	 *
  291
+	 * @deprecated  12.1
  292
+	 */
  293
+	public function hasUTF()
  294
+	{
  295
+		return false;
  296
+	}
  297
+
  298
+	/**
  299
+	 * Method to get the auto-incremented value from the last INSERT statement.
  300
+	 *
  301
+	 * @return  integer  The value of the auto-increment field from the last inserted row.
  302
+	 *
  303
+	 * @since   11.4
  304
+	 */
  305
+	public function insertid()
  306
+	{
  307
+		return 0;
  308
+	}
  309
+
  310
+	/**
  311
+	 * Locks a table in the database.
  312
+	 *
  313
+	 * @param   string  $tableName  The name of the table to unlock.
  314
+	 *
  315
+	 * @return  JDatabase  Returns this object to support chaining.
  316
+	 *
  317
+	 * @since   11.4
  318
+	 * @throws  JDatabaseException
  319
+	 */
  320
+	public function lockTable($tableName)
  321
+	{
  322
+		return $this;
  323
+	}
  324
+
  325
+	/**
  326
+	 * Execute the SQL statement.
  327
+	 *
  328
+	 * @return  mixed  A database cursor resource on success, boolean false on failure.
  329
+	 *
  330
+	 * @since   11.4
  331
+	 * @throws  JDatabaseException
  332
+	 */
  333
+	public function query()
  334
+	{
  335
+		return false;
  336
+	}
  337
+
  338
+	/**
  339
+	 * Execute a query batch.
  340
+	 *
  341
+	 * @param   boolean  $abortOnError     Abort on error.
  342
+	 * @param   boolean  $transactionSafe  Transaction safe queries.
  343
+	 *
  344
+	 * @return  mixed  A database resource if successful, false if not.
  345
+	 *
  346
+	 * @deprecated  12.1
  347
+	 * @since   11.4
  348
+	 */
  349
+	public function queryBatch($abortOnError = true, $transactionSafe = false)
  350
+	{
  351
+		return false;
  352
+	}
  353
+
  354
+	/**
  355
+	 * Renames a table in the database.
  356
+	 *
  357
+	 * @param   string  $oldTable  The name of the table to be renamed
  358
+	 * @param   string  $newTable  The new name for the table.
  359
+	 * @param   string  $backup    Table prefix
  360
+	 * @param   string  $prefix    For the table - used to rename constraints in non-mysql databases
  361
+	 *
  362
+	 * @return  JDatabase  Returns this object to support chaining.
  363
+	 *
  364
+	 * @since   11.4
  365
+	 * @throws  JDatabaseException
  366
+	 */
  367
+	public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
  368
+	{
  369
+		return $this;
  370
+	}
  371
+
  372
+	/**
  373
+	 * Select a database for use.
  374
+	 *
  375
+	 * @param   string  $database  The name of the database to select for use.
  376
+	 *
  377
+	 * @return  boolean  True if the database was successfully selected.
  378
+	 *
  379
+	 * @since   11.4
  380
+	 * @throws  JDatabaseException
  381
+	 */
  382
+	public function select($database)
  383
+	{
  384
+		return false;
  385
+	}
  386
+
  387
+	/**
  388
+	* Set the connection to use UTF-8 character encoding.
  389
+	*
  390
+	* @return  boolean  True on success.
  391
+	*
  392
+	* @since   11.4
  393
+	*/
  394
+	public function setUTF()
  395
+	{
  396
+		return false;
  397
+	}
  398
+
  399
+	/**
  400
+	 * Test to see if the connector is available.
  401
+	 *
  402
+	 * @return  boolean  True on success, false otherwise.
  403
+	 *
  404
+	 * @since   11.2
  405
+	 */
  406
+	public static function test()
  407
+	{
  408
+		return true;
  409
+	}
  410
+
  411
+	/**
  412
+	 * Method to commit a transaction.
  413
+	 *
  414
+	 * @return  void
  415
+	 *
  416
+	 * @since   11.4
  417
+	 * @throws  JDatabaseException
  418
+	 */
  419
+	public function transactionCommit()