コード例 #1
0
 /**
  * @covers ::add
  */
 public function test_add_sets_connection_by_name()
 {
     $name = 'test';
     $factory = new O2O_Connection_Factory();
     $connection = $factory->register($name, 'post', 'post');
     $factory->add($connection);
     $connections = PHPUnit_Framework_Assert::readAttribute($factory, 'connections');
     $this->assertInternalType('array', $connections);
     $this->assertArrayHasKey($name, $connections);
     $this->assertSame($connections[$name], $connection);
 }
コード例 #2
0
 /**
  * @covers ::_filter_posts_clauses
  */
 public function test_filter_posts_clauses()
 {
     global $wpdb;
     $args = array('from' => array('sortable' => true));
     $connection = new O2O_Mock_Connection('test', 'post', 'page', $args);
     $connection_factory = new O2O_Connection_Factory();
     $connection_factory->add($connection);
     $query_vars = array('o2o_query' => array('connection' => 'test', 'direction' => 'from', 'id' => 1), 'orderby' => 'test');
     $query = new WP_Query();
     $query->query_vars = $query_vars;
     $o2o_query = new O2O_Query($connection_factory);
     $o2o_query->_action_parse_query($query);
     //required for other filters to work properly
     $clauses = $o2o_query->_filter_posts_clauses(array(), $query);
     $this->assertInternalType('array', $clauses);
     $this->assertArrayHasKey('orderby', $clauses);
     $this->assertEquals(" find_in_set({$wpdb->posts}.ID, '1, 2') ASC", $clauses['orderby']);
 }