| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Test WPDB methods
|
|---|
| 5 | */
|
|---|
| 6 | class TestWPDB extends _WPEmptyBlog {
|
|---|
| 7 |
|
|---|
| 8 | /**
|
|---|
| 9 | * Query log
|
|---|
| 10 | * @var array
|
|---|
| 11 | */
|
|---|
| 12 | protected $_queries = array();
|
|---|
| 13 |
|
|---|
| 14 | /**
|
|---|
| 15 | * Set up the test fixture
|
|---|
| 16 | */
|
|---|
| 17 | public function setUp() {
|
|---|
| 18 | parent::setUp();
|
|---|
| 19 | $this->_queries = array();
|
|---|
| 20 | add_filter( 'query', array( $this, 'query_filter' ) );
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * Tear down the test fixture
|
|---|
| 25 | */
|
|---|
| 26 | public function tearDown() {
|
|---|
| 27 | parent::tearDown();
|
|---|
| 28 | remove_filter( 'query', array( $this, 'query_filter' ) );
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * Log each query
|
|---|
| 33 | * @param string $sql
|
|---|
| 34 | * @return string
|
|---|
| 35 | */
|
|---|
| 36 | public function query_filter( $sql ) {
|
|---|
| 37 | $this->_queries[] = $sql;
|
|---|
| 38 | return $sql;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * Test that floats formatted as "0,700" get sanitized properly by wpdb
|
|---|
| 43 | * @global mixed $wpdb
|
|---|
| 44 | */
|
|---|
| 45 | public function test_locale_floats() {
|
|---|
| 46 | global $wpdb;
|
|---|
| 47 |
|
|---|
| 48 | $this->knownWPBug( 19861 );
|
|---|
| 49 |
|
|---|
| 50 | // Save the current locale
|
|---|
| 51 | $current_locale = setlocale( LC_ALL, NULL );
|
|---|
| 52 |
|
|---|
| 53 | // Switch to Russian
|
|---|
| 54 | setlocale( LC_ALL, 'ru_RU.utf8', 'rus' );
|
|---|
| 55 |
|
|---|
| 56 | // Try an update query
|
|---|
| 57 | $wpdb->update(
|
|---|
| 58 | 'test_table',
|
|---|
| 59 | array( 'float_column' => 0.7 ),
|
|---|
| 60 | array( 'meta_id' => 5 ),
|
|---|
| 61 | array( '%f' ),
|
|---|
| 62 | array( '%d' )
|
|---|
| 63 | );
|
|---|
| 64 |
|
|---|
| 65 | // Ensure the float isn't 0,700
|
|---|
| 66 | $this->assertContains( '0.700', array_pop( $this->_queries ) );
|
|---|
| 67 |
|
|---|
| 68 | // Try a prepare
|
|---|
| 69 | $sql = $wpdb->prepare( "UPDATE test_table SET float_column = %f AND meta_id = %d", 0.7, 5 );
|
|---|
| 70 | $this->assertContains( '0.700', $sql );
|
|---|
| 71 |
|
|---|
| 72 | // Restore locale
|
|---|
| 73 | setlocale( LC_ALL, $current_locale );
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|