public function test_get_connection() { $name = 'test'; $factory = new O2O_Connection_Factory(); $connection = $factory->register($name, 'post', 'post'); $this->assertFalse($factory->get_connection('invalid_name')); $this->assertSame($connection, $factory->get_connection($name)); }
/** * @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); }
public function test_add_rewrite_rules_page() { global $wp_rewrite; $args = array('rewrite' => 'to'); $connection_factory = new O2O_Connection_Factory(); $connection_factory->register('page_to_flat', 'page', 'flat_post_type', $args); $o2o_rewrites = new O2O_Rewrites($connection_factory); $o2o_rewrites->add_rewrite_rules(); $rules = $wp_rewrite->rewrite_rules(); $required_rewrites = array('([^/]+?)/flat-posts/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?connection_name=page_to_flat&connected_name=$matches[1]&feed=$matches[2]&connection_dir=to', '([^/]+?)/flat-posts/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?connection_name=page_to_flat&connected_name=$matches[1]&feed=$matches[2]&connection_dir=to', '([^/]+?)/flat-posts/page/?([0-9]{1,})/?$' => 'index.php?connection_name=page_to_flat&connected_name=$matches[1]&paged=$matches[2]&connection_dir=to', '([^/]+?)/flat-posts/?$' => 'index.php?connection_name=page_to_flat&connected_name=$matches[1]&connection_dir=to'); foreach ($required_rewrites as $regex => $replace) { $this->assertArrayHasKey($regex, $rules); $this->assertEquals($rules[$regex], $replace); } }