Skip to content

Instantly share code, notes, and snippets.

@michaeltwofish
Created June 6, 2010 03:12
Show Gist options
  • Save michaeltwofish/427259 to your computer and use it in GitHub Desktop.
Save michaeltwofish/427259 to your computer and use it in GitHub Desktop.
public function test_get_posts_by_tag()
{
// Create some tagged posts
$user = User::get_by_name( 'posts_test' );
$time = time() - 160;
$tagged_posts = array();
$tag_sets = array(
array('one'),
array('two'),
array('one', 'two'),
);
foreach ( $tag_sets as $tags ) {
$tagged_posts[] = $this->make_post( $user, $time = $time - rand(3600, 3600*36), $tags );
}
// Get posts via a single tag
$got = Posts::get(array('tag' => 'one'));
$this->assertType('Posts', $got, 'Result should be of type Posts');
$this->assertEquals(count($got), 2, 'The correct number of posts with the requested tag should be returned');
foreach ( $got as $g ) {
$this->assertType('Post', $g, 'Items should be of type Post');
$this->assertTrue(in_array('one', $g->tags), 'The post should have the requested tag' );
}
foreach ( $tagged_posts as $post ) {
$post->delete();
}
unset($tagged_posts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment