Index: tests/phpunit/tests/general-template.php
===================================================================
--- tests/phpunit/tests/general-template.php	(revision 0)
+++ tests/phpunit/tests/general-template.php	(revision 0)
@@ -0,0 +1,79 @@
+<?php
+
+class Tests_Get_Archives extends WP_UnitTestCase {
+
+	/*
+	$defaults = array(
+		'type' => 'monthly', 'limit' => '',
+		'format' => 'html', 'before' => '',
+		'after' => '', 'show_post_count' => false,
+		'echo' => 1, 'order' => 'DESC',
+	);
+	*/
+
+	function setUp() {
+		parent::setUp();	
+		$this->factory->post->create_many( 8, array( 'post_type' => 'post', 'post_author' => '1' ) );
+	}
+
+	function test_wp_get_archives_default() {
+		$expected['default'] = "<li><a href='http://example.org/?m=" . date( 'Ym' ) . "'>" . date( 'F Y' ) . "</a></li>";
+		$this->AssertEquals( $expected['default'], trim( wp_get_archives( array( 'echo' => false ) ) ) );
+	}
+
+	function test_wp_get_archives_type() {
+		$expected['type'] = "<li><a href='http://example.org/?m=" . date( 'Y' ) . "'>" . date( 'Y' ) . "</a></li>";
+		$this->AssertEquals( $expected['type'], trim( wp_get_archives( array( 'echo' => false, 'type' => 'yearly' ) ) ) );
+	}
+
+	function test_wp_get_archives_limit() {
+		$expected['limit'] = <<<EOF
+<li><a href='http://example.org/?p=26'>Post title 8</a></li>
+	<li><a href='http://example.org/?p=25'>Post title 7</a></li>
+	<li><a href='http://example.org/?p=24'>Post title 6</a></li>
+	<li><a href='http://example.org/?p=23'>Post title 5</a></li>
+	<li><a href='http://example.org/?p=22'>Post title 4</a></li>
+EOF;
+		$this->AssertEquals( $expected['limit'], trim( wp_get_archives( array( 'echo' => false, 'type' => 'postbypost', 'limit' => 5 ) ) ) );
+	}
+
+	function test_wp_get_archives_format() {
+		$expected['format'] = "<option value='http://example.org/?m=" . date( 'Ym' ) . "'> " . date( 'F Y' ) . " </option>";
+		$this->AssertEquals( $expected['format'], trim( wp_get_archives( array( 'echo' => false, 'format' => 'option' ) ) ) );
+	}
+	
+	function test_wp_get_archives_before_and_after() {
+		$expected['before_and_after'] = "<div><a href='http://example.org/?m=" . date( 'Ym' ) . "'>" . date( 'F Y' ) . "</a></div>";
+		$this->AssertEquals( $expected['before_and_after'], trim( wp_get_archives( array( 'echo' => false, 'format' => 'custom', 'before' => '<div>', 'after' => '</div>' ) ) ) );
+	}
+	
+	function test_wp_get_archives_show_post_count() {
+		$expected['show_post_count'] = "<li><a href='http://example.org/?m=" . date( 'Ym' ) . "'>" . date( 'F Y' ) . "</a>&nbsp;(8)</li>";
+		$this->AssertEquals( $expected['show_post_count'], trim( wp_get_archives( array( 'echo' => false, 'show_post_count' => 1 ) ) ) );	
+	}
+
+	function test_wp_get_archives_echo() {
+		$expected['echo'] = "<li><a href='http://example.org/?m=" . date( 'Ym' ) . "'>" . date( 'F Y' ) . "</a></li>";
+		ob_start();
+		wp_get_archives( array( 'echo' => true ) );
+		$actual = ob_get_clean();
+		$this->AssertEquals( $expected['echo'], trim( $actual ) );
+	}
+	
+	function test_wp_get_archives_order() {
+		$this->factory->post->create( array( 'post_type' => 'post', 'post_author' => '1', 'post_date' => '2012-10-23 19:34:42' ) );
+		$date_n = date( "Ym" );
+		$date_full = date( 'F Y' );
+		$expected['order_asc'] = <<<EOF
+<li><a href='http://example.org/?m=201210'>October 2012</a></li>
+	<li><a href='http://example.org/?m=$date_n'>$date_full</a></li>
+EOF;
+		$this->AssertEquals( $expected['order_asc'], trim( wp_get_archives( array( 'echo' => false, 'order' => 'ASC' ) ) ) );
+
+		$expected['order_desc'] = <<<EOF
+<li><a href='http://example.org/?m=$date_n'>$date_full</a></li>
+	<li><a href='http://example.org/?m=201210'>October 2012</a></li>
+EOF;
+		$this->AssertEquals( $expected['order_desc'], trim( wp_get_archives( array( 'echo' => false, 'order' => 'DESC' ) ) ) );
+	}
+}
\ No newline at end of file
Index: src/wp-includes/general-template.php
===================================================================
--- src/wp-includes/general-template.php	(revision 26915)
+++ src/wp-includes/general-template.php	(working copy)
@@ -934,7 +934,7 @@
  * @param string|array $args Optional. Override defaults.
  * @return string|null String when retrieving, null when displaying.
  */
-function wp_get_archives($args = '') {
+function wp_get_archives( $args = '' ) {
 	global $wpdb, $wp_locale;
 
 	$defaults = array(
@@ -945,17 +945,16 @@
 	);
 
 	$r = wp_parse_args( $args, $defaults );
-	extract( $r, EXTR_SKIP );
 
-	if ( '' == $type )
-		$type = 'monthly';
+	if ( '' == $r['type'] )
+		$r['type'] = 'monthly';
 
-	if ( '' != $limit ) {
-		$limit = absint($limit);
-		$limit = ' LIMIT '.$limit;
+	if ( '' != $r['limit'] ) {
+		$r['limit'] = absint( $r['limit'] );
+		$r['limit'] = ' LIMIT ' . $r['limit'];
 	}
 
-	$order = strtoupper( $order );
+	$order = strtoupper( $r['order'] );
 	if ( $order !== 'ASC' )
 		$order = 'DESC';
 
@@ -973,9 +972,9 @@
 	$archive_week_end_date_format	= 'Y/m/d';
 
 	if ( !$archive_date_format_over_ride ) {
-		$archive_day_date_format = get_option('date_format');
-		$archive_week_start_date_format = get_option('date_format');
-		$archive_week_end_date_format = get_option('date_format');
+		$archive_day_date_format = get_option( 'date_format' );
+		$archive_week_start_date_format = get_option( 'date_format' );
+		$archive_week_end_date_format = get_option( 'date_format' );
 	}
 
 	$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
@@ -989,7 +988,9 @@
 		wp_cache_set( 'last_changed', $last_changed, 'posts' );
 	}
 
-	if ( 'monthly' == $type ) {
+	$limit = $r['limit'];
+
+	if ( 'monthly' == $r['type'] ) {
 		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
 		$key = md5( $query );
 		$key = "wp_get_archives:$key:$last_changed";
@@ -998,17 +999,17 @@
 			wp_cache_set( $key, $results, 'posts' );
 		}
 		if ( $results ) {
-			$afterafter = $after;
+			$afterafter = $r['after'];
 			foreach ( (array) $results as $result ) {
 				$url = get_month_link( $result->year, $result->month );
 				/* translators: 1: month name, 2: 4-digit year */
-				$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
-				if ( $show_post_count )
-					$after = '&nbsp;('.$result->posts.')' . $afterafter;
-				$output .= get_archives_link($url, $text, $format, $before, $after);
+				$text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
+				if ( $r['show_post_count'] )
+					$r['after'] = '&nbsp;('.$result->posts.')' . $afterafter;
+				$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
 			}
 		}
-	} elseif ('yearly' == $type) {
+	} elseif ( 'yearly' == $r['type'] ) {
 		$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
 		$key = md5( $query );
 		$key = "wp_get_archives:$key:$last_changed";
@@ -1017,16 +1018,16 @@
 			wp_cache_set( $key, $results, 'posts' );
 		}
 		if ( $results ) {
-			$afterafter = $after;
+			$afterafter = $r['after'];
 			foreach ( (array) $results as $result) {
-				$url = get_year_link($result->year);
-				$text = sprintf('%d', $result->year);
-				if ($show_post_count)
-					$after = '&nbsp;('.$result->posts.')' . $afterafter;
-				$output .= get_archives_link($url, $text, $format, $before, $after);
+				$url = get_year_link( $result->year );
+				$text = sprintf( '%d', $result->year );
+				if ( $r['show_post_count'] )
+					$r['after'] = '&nbsp;('.$result->posts.')' . $afterafter;
+				$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
 			}
 		}
-	} elseif ( 'daily' == $type ) {
+	} elseif ( 'daily' == $r['type'] ) {
 		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
 		$key = md5( $query );
 		$key = "wp_get_archives:$key:$last_changed";
@@ -1036,17 +1037,17 @@
 			wp_cache_set( $key, $results, 'posts' );
 		}
 		if ( $results ) {
-			$afterafter = $after;
+			$afterafter = $r['after'];
 			foreach ( (array) $results as $result ) {
-				$url	= get_day_link($result->year, $result->month, $result->dayofmonth);
-				$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
-				$text = mysql2date($archive_day_date_format, $date);
-				if ($show_post_count)
-					$after = '&nbsp;('.$result->posts.')'.$afterafter;
-				$output .= get_archives_link($url, $text, $format, $before, $after);
+				$url	= get_day_link( $result->year, $result->month, $result->dayofmonth );
+				$date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
+				$text = mysql2date( $archive_day_date_format, $date );
+				if ( $r['show_post_count'] )
+					$after = '&nbsp;(' . $result->posts . ')' . $afterafter;
+				$output .= get_archives_link( $url, $text, $format, $before, $after );
 			}
 		}
-	} elseif ( 'weekly' == $type ) {
+	} elseif ( 'weekly' == $r['type'] ) {
 		$week = _wp_mysql_week( '`post_date`' );
 		$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
 		$key = md5( $query );
@@ -1056,25 +1057,25 @@
 			wp_cache_set( $key, $results, 'posts' );
 		}
 		$arc_w_last = '';
-		$afterafter = $after;
+		$afterafter = $r['after'];
 		if ( $results ) {
 				foreach ( (array) $results as $result ) {
 					if ( $result->week != $arc_w_last ) {
 						$arc_year = $result->yr;
 						$arc_w_last = $result->week;
-						$arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week'));
-						$arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
-						$arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
-						$url  = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&amp;', '=', $result->week);
+						$arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
+						$arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
+						$arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
+						$url  = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&amp;', '=', $result->week );
 						$text = $arc_week_start . $archive_week_separator . $arc_week_end;
-						if ($show_post_count)
-							$after = '&nbsp;('.$result->posts.')'.$afterafter;
-						$output .= get_archives_link($url, $text, $format, $before, $after);
+						if ( $r['show_post_count'] )
+							$after = '&nbsp;(' . $result->posts . ')' . $afterafter;
+						$output .= get_archives_link( $url, $text, $format, $before, $after );
 					}
 				}
 		}
-	} elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
-		$orderby = ('alpha' == $type) ? 'post_title ASC ' : 'post_date DESC ';
+	} elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
+		$orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC ';
 		$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
 		$key = md5( $query );
 		$key = "wp_get_archives:$key:$last_changed";
@@ -1092,12 +1093,12 @@
 					} else {
 						$text = $result->ID;
 					}
-					$output .= get_archives_link($url, $text, $format, $before, $after);
+					$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
 				}
 			}
 		}
 	}
-	if ( $echo )
+	if ( $r['echo'] )
 		echo $output;
 	else
 		return $output;
