Changeset 44272 for trunk/tests/phpunit/tests/db.php
- Timestamp:
- 12/17/2018 06:38:13 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43934
- Property svn:mergeinfo changed
-
trunk/tests/phpunit/tests/db.php
r43571 r44272 569 569 $this->assertInternalType( 'object', $row ); 570 570 $this->assertEquals( 'Walter Sobchak', $row->display_name ); 571 } 572 573 /** 574 * Test the `get_col()` method. 575 * 576 * @param string|null $query The query to run. 577 * @param string|array $expected The expected resulting value. 578 * @param arrray|string|null $last_result The value to assign to `$wpdb->last_result`. 579 * @param int|string $column The column index to retrieve. 580 * 581 * @dataProvider data_test_get_col 582 * 583 * @ticket 45299 584 */ 585 function test_get_col( $query, $expected, $last_result, $column ) { 586 global $wpdb; 587 588 $wpdb->last_result = $last_result; 589 590 $result = $wpdb->get_col( $query, $column ); 591 592 if ( $query ) { 593 $this->assertSame( $query, $wpdb->last_query ); 594 } 595 596 if ( is_array( $expected ) ) { 597 $this->assertSame( $expected, $result ); 598 } else { 599 $this->assertContains( $expected, $result ); 600 } 601 } 602 603 /** 604 * Data provider for testing `get_col()`. 605 * 606 * @return array { 607 * Arguments for testing `get_col()`. 608 * 609 * @type string|null $query The query to run. 610 * @type string|array $expected The resulting expected value. 611 * @type arrray|string|null $last_result The value to assign to `$wpdb->last_result`. 612 * @type int|string $column The column index to retrieve. 613 */ 614 function data_test_get_col() { 615 global $wpdb; 616 617 return array( 618 array( 619 "SELECT display_name FROM $wpdb->users", 620 'admin', 621 array(), 622 0, 623 ), 624 array( 625 "SELECT user_login, user_email FROM $wpdb->users", 626 'admin', 627 array(), 628 0, 629 ), 630 array( 631 "SELECT user_login, user_email FROM $wpdb->users", 632 'admin@example.org', 633 array(), 634 1, 635 ), 636 array( 637 "SELECT user_login, user_email FROM $wpdb->users", 638 'admin@example.org', 639 array(), 640 '1', 641 ), 642 array( 643 "SELECT user_login, user_email FROM $wpdb->users", 644 array( null ), 645 array(), 646 3, 647 ), 648 array( 649 '', 650 array(), 651 null, 652 0, 653 ), 654 array( 655 null, 656 array(), 657 '', 658 0, 659 ), 660 ); 571 661 } 572 662
Note: See TracChangeset
for help on using the changeset viewer.