| 1 |
<?php |
| 2 |
|
| 3 |
use PHPUnit\Framework\TestCase; |
| 4 |
use ResponsiveMenu\Database\WpDatabase; |
| 5 |
|
| 6 |
class WpDatabaseTest extends TestCase { |
| 7 |
|
| 8 |
public function setUp() { |
| 9 |
$this->wpdb = $this->getMockBuilder('wpdb') |
| 10 |
->setMethods(['update', 'delete', 'get_results', 'insert', 'select']) |
| 11 |
->getMock(); |
| 12 |
$this->wpdb->prefix = 'prefix'; |
| 13 |
$this->db = new WpDatabase($this->wpdb); |
| 14 |
|
| 15 |
if(!function_exists('current_time')): |
| 16 |
function current_time($type) { |
| 17 |
return '0000'; |
| 18 |
} |
| 19 |
endif; |
| 20 |
|
| 21 |
if(!function_exists('update_option')): |
| 22 |
function update_option($a, $b) { |
| 23 |
return $a . ' ' . $b; |
| 24 |
} |
| 25 |
endif; |
| 26 |
} |
| 27 |
|
| 28 |
public function testUpdate() { |
| 29 |
$this->wpdb->method('update')->will($this->returnArgument(0)); |
| 30 |
$this->assertEquals('prefixupdate_arg', $this->db->update('update_arg', [], [])); |
| 31 |
} |
| 32 |
|
| 33 |
public function testDelete() { |
| 34 |
$this->wpdb->method('delete')->will($this->returnArgument(0)); |
| 35 |
$this->assertEquals('prefixdelete_arg', $this->db->delete('delete_arg', 'b')); |
| 36 |
} |
| 37 |
|
| 38 |
public function testGetResults() { |
| 39 |
$this->wpdb->method('get_results')->will($this->returnArgument(0)); |
| 40 |
$this->assertEquals('SELECT * FROM prefixget_results_arg', $this->db->all('get_results_arg')); |
| 41 |
} |
| 42 |
|
| 43 |
public function testInsertResults() { |
| 44 |
$this->wpdb->method('insert')->will($this->returnArgument(0)); |
| 45 |
$this->assertEquals('prefixinsert_arg', $this->db->insert('insert_arg', [])); |
| 46 |
} |
| 47 |
|
| 48 |
public function testSelectResults() { |
| 49 |
$this->wpdb->method('get_results')->will($this->returnArgument(0)); |
| 50 |
$this->assertEquals('SELECT * FROM prefixselect_arg WHERE a = \'b\';', $this->db->select('select_arg', 'a', 'b')); |
| 51 |
} |
| 52 |
|
| 53 |
public function testMySqlTime() { |
| 54 |
$this->assertEquals('0000', $this->db->mySqlTime()); |
| 55 |
} |
| 56 |
|
| 57 |
public function testUpdateOption() { |
| 58 |
$this->assertEquals('a b', $this->db->updateOption('a', 'b')); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|