Skip to content

Instantly share code, notes, and snippets.

@mattleff
Created June 27, 2011 22:53
Show Gist options
  • Save mattleff/1050060 to your computer and use it in GitHub Desktop.
Save mattleff/1050060 to your computer and use it in GitHub Desktop.
<?php
class DB_unit_test_comments extends DB_unit_case_freshdb
{
function testGetNewConfig()
{
$siteinfo = new DB_siteinfo();
$siteinfo->save();
$config = DB_comments_config::get();
$this->assertSame( SF_static_global::getSiteId(), $config->getSiteId() );
}
function testGetCommentsByTree()
{
$siteinfo = new DB_siteinfo();
$siteinfo->save();
$article = new DB_article();
$article->setPageId( 1 )->setSiteId( 1 )->save();
$article = new DB_article();
$article->setPageId( 10 )->setSiteId( 1 )->save();
$user1 = new DB_user();
$user1->setFname( 'Matthew' )
->setLname( 'Leffler' )
->setEmail( 'matthew@simpleupdates.com' );
$user1->save();
$user2 = new DB_user();
$user2->setFname( 'Phil' )
->setLname( 'Schmo' )
->setEmail( 'philmore@simpleupdates.com' )
->setCommentsHandle( 'Schmo Mo' );
$user2->save();
$first_comment = new DB_comments();
$first_comment->setPageId( 1 )
->setSiteId( 1 )
->setUserId( $user1->getId() )
->setCommentText( 'First' )
->setStatus( 'active' )
->save();
$comment = new DB_comments();
$comment->setPageId( 1 )
->setSiteId( 1 )
->setUserId( $user1->getId() )
->setCommentText( 'Second' )
->setStatus( 'active' )
->save();
$subcomment = new DB_comments();
$subcomment->setPageId( 1 )
->setSiteId( 1 )
->setUserId( $user2->getId() )
->setInReplyTo( $first_comment->getRecordId() )
->setCommentText( 'Sub' )
->setStatus( 'active' )
->save();
$subcomment = new DB_comments();
$subcomment->setPageId( 1 )
->setSiteId( 1 )
->setUserId( $user2->getId() )
->setInReplyTo( $first_comment->getRecordId() )
->setCommentText( 'Sub 2' )
->setStatus( 'active' )
->save();
$subsubcomment = new DB_comments();
$subsubcomment->setPageId( 1 )
->setSiteId( 1 )
->setUserId( $user1->getId() )
->setInReplyTo( $subcomment->getRecordId() )
->setCommentText( 'Sub sub' )
->setStatus( 'active' )
->save();
$comment = new DB_comments();
$comment->setPageId( 1 )
->setSiteId( 1 )
->setUserId( $user1->getId() )
->setCommentText( 'Last with <html>' )
->setStatus( 'active' )
->save();
/* shouldn't be included */
$other_page_comment = new DB_comments();
$other_page_comment->setPageId( 10 )
->setSiteId( 1 )
->setStatus( 'active' )
->setUserId( $user1->getId() )
->save();
$unapproved_comment = new DB_comments();
$unapproved_comment->setPageId( 1 )
->setSiteId( 1 )
->setStatus( 'unapproved' )
->setUserId( $user1->getId() )
->save();
$comments_tree = array (
'' =>
array (
0 =>
array (
'RecordId' => 1,
'PageId' => 1,
'SiteId' => 1,
'Status' => 'active',
'CommentText' => 'First',
'CommentAuthor' => 'Matthew Leffler',
'CommentDate' => NULL,
'CommentIp' => NULL,
'CommentEmail' => NULL,
'InReplyTo' => NULL,
'UserId' => 1,
'CanReplyTo' => true,
'CanApprove' => false,
'CanDelete' => false,
),
1 =>
array (
'RecordId' => 2,
'PageId' => 1,
'SiteId' => 1,
'Status' => 'active',
'CommentText' => 'Second',
'CommentAuthor' => 'Matthew Leffler',
'CommentDate' => NULL,
'CommentIp' => NULL,
'CommentEmail' => NULL,
'InReplyTo' => NULL,
'UserId' => 1,
'CanReplyTo' => true,
'CanApprove' => false,
'CanDelete' => false,
),
2 =>
array (
'RecordId' => 6,
'PageId' => 1,
'SiteId' => 1,
'Status' => 'active',
'CommentText' => 'Last with &lt;html&gt;',
'CommentAuthor' => 'Matthew Leffler',
'CommentDate' => NULL,
'CommentIp' => NULL,
'CommentEmail' => NULL,
'InReplyTo' => NULL,
'UserId' => 1,
'CanReplyTo' => true,
'CanApprove' => false,
'CanDelete' => false,
),
),
1 =>
array (
0 =>
array (
'RecordId' => 3,
'PageId' => 1,
'SiteId' => 1,
'Status' => 'active',
'CommentText' => 'Sub',
'CommentAuthor' => 'Schmo Mo',
'CommentDate' => NULL,
'CommentIp' => NULL,
'CommentEmail' => NULL,
'InReplyTo' => 1,
'UserId' => 2,
'CanReplyTo' => true,
'CanApprove' => false,
'CanDelete' => false,
),
1 =>
array (
'RecordId' => 4,
'PageId' => 1,
'SiteId' => 1,
'Status' => 'active',
'CommentText' => 'Sub 2',
'CommentAuthor' => 'Schmo Mo',
'CommentDate' => NULL,
'CommentIp' => NULL,
'CommentEmail' => NULL,
'InReplyTo' => 1,
'UserId' => 2,
'CanReplyTo' => true,
'CanApprove' => false,
'CanDelete' => false,
),
),
4 =>
array (
0 =>
array (
'RecordId' => 5,
'PageId' => 1,
'SiteId' => 1,
'Status' => 'active',
'CommentText' => 'Sub sub',
'CommentAuthor' => 'Matthew Leffler',
'CommentDate' => NULL,
'CommentIp' => NULL,
'CommentEmail' => NULL,
'InReplyTo' => 4,
'UserId' => 1,
'CanReplyTo' => true,
'CanApprove' => false,
'CanDelete' => false,
),
),
);
$this->assertSame( $comments_tree, DB_comments::getCommentsByTree( 1, new DB_user() ) );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment