2014-04-20 23:46:31 +02:00
< ? php
/**
2014-04-25 17:00:24 +02:00
*
2014-05-27 20:18:06 +02:00
* This file is part of the phpBB Forum Software package .
*
* @ copyright ( c ) phpBB Limited < https :// www . phpbb . com >
* @ license GNU General Public License , version 2 ( GPL - 2.0 )
*
* For full copyright and license information , please see
* the docs / CREDITS . txt file .
2014-04-25 17:00:24 +02:00
*
*/
2014-04-20 23:46:31 +02:00
2015-02-22 23:36:27 +01:00
require_once dirname ( __FILE__ ) . '/../../phpBB/includes/functions.php' ;
2014-04-20 23:46:31 +02:00
/**
2014-04-25 17:00:24 +02:00
* @ group functional
*/
2014-04-20 23:46:31 +02:00
class phpbb_functional_feed_test extends phpbb_functional_test_case
{
protected $data = array ();
2014-04-21 13:15:15 +02:00
static public $init_values = array ();
2016-01-07 10:31:21 +01:00
public function setUp ()
{
parent :: setUp ();
$this -> purge_cache ();
}
2014-04-29 23:48:08 +02:00
public function __construct ( $name = null , array $data = array (), $dataName = '' )
2014-04-21 13:15:15 +02:00
{
parent :: __construct ( $name , $data , $dataName );
2015-02-22 23:36:27 +01:00
$this -> backupStaticAttributesBlacklist [ 'phpbb_functional_feed_test' ] = array ( 'init_values' );
$this -> purge_cache ();
2014-04-21 13:15:15 +02:00
}
2014-04-21 01:39:12 +02:00
public function test_setup_config_before_state ()
2014-04-20 23:46:31 +02:00
{
2014-04-21 01:39:12 +02:00
$this -> login ();
$this -> admin_login ();
$crawler = self :: request ( 'GET' , " adm/index.php?sid= { $this -> sid } &i=acp_board&mode=feed " );
$form = $crawler -> selectButton ( 'Submit' ) -> form ();
$values = $form -> getValues ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'post_base_items' ] = ( int ) $values [ 'config[feed_limit_post]' ];
self :: $init_values [ 'topic_base_items' ] = ( int ) $values [ 'config[feed_limit_topic]' ];
2014-04-21 01:39:12 +02:00
// Enable all feeds
2014-04-29 23:48:08 +02:00
$values [ 'config[feed_enable]' ] = true ;
$values [ 'config[feed_forum]' ] = true ;
$values [ 'config[feed_item_statistics]' ] = true ;
$values [ 'config[feed_overall]' ] = true ;
$values [ 'config[feed_overall_forums]' ] = true ;
$values [ 'config[feed_topic]' ] = true ;
$values [ 'config[feed_topics_active]' ] = true ;
$values [ 'config[feed_topics_new]' ] = true ;
2014-04-21 01:39:12 +02:00
$form -> setValues ( $values );
$crawler = self :: submit ( $form );
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( 'CONFIG_UPDATED' , $crawler -> filter ( '.successbox' ) -> text ());
2014-04-21 01:39:12 +02:00
// Special config (Guest can't see attachments)
$this -> add_lang ( 'acp/permissions' );
$crawler = self :: request ( 'GET' , " adm/index.php?i=acp_permissions&sid= { $this -> sid } &icat=16&mode=setting_group_global&group_id[0]=1 " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( $this -> lang ( 'ACL_SET' ), $crawler -> filter ( 'h1' ) -> eq ( 1 ) -> text ());
2014-04-21 01:39:12 +02:00
$form = $crawler -> selectButton ( $this -> lang ( 'APPLY_PERMISSIONS' )) -> form ();
2014-04-29 23:48:08 +02:00
$form [ 'setting[1][0][u_download]' ] -> select ( - 1 );
2014-04-21 01:39:12 +02:00
$crawler = self :: submit ( $form );
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( 'AUTH_UPDATED' , $crawler -> filter ( '.successbox' ) -> text ());
2014-04-21 01:39:12 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_dump_board_state ()
2014-04-21 01:39:12 +02:00
{
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/forums' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-30 00:50:11 +02:00
self :: $init_values [ 'disapprove_user' ][ 'forums_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/overall' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'disapprove_user' ][ 'overall_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/topics' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'disapprove_user' ][ 'topics_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/topics_new' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'disapprove_user' ][ 'topics_new_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/topics_active' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'disapprove_user' ][ 'topics_active_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
$this -> login ();
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/forums' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-30 00:50:11 +02:00
self :: $init_values [ 'admin' ][ 'forums_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/overall' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'admin' ][ 'overall_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/topics' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'admin' ][ 'topics_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/topics_new' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'admin' ][ 'topics_new_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed/topics_active' , array (), false );
2014-04-21 01:39:12 +02:00
self :: assert_response_xml ();
2014-04-29 23:48:08 +02:00
self :: $init_values [ 'admin' ][ 'topics_active_value' ] = $crawler -> filterXPath ( '//entry' ) -> count ();
2014-04-21 01:39:12 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_setup_forums ()
2014-04-21 01:39:12 +02:00
{
2014-04-20 23:46:31 +02:00
$this -> login ();
$this -> admin_login ();
2014-04-29 23:48:08 +02:00
$this -> create_user ( 'disapprove_user' );
2014-04-20 23:46:31 +02:00
$this -> add_user_group ( 'NEWLY_REGISTERED' , array ( 'disapprove_user' ));
$crawler = self :: request ( 'GET' , " adm/index.php?i=acp_forums&mode=manage&sid= { $this -> sid } " );
$form = $crawler -> selectButton ( 'addforum' ) -> form ( array (
'forum_name' => 'Feeds #1' ,
));
$crawler = self :: submit ( $form );
$form = $crawler -> selectButton ( 'update' ) -> form ( array (
'forum_perm_from' => 2 ,
));
2015-02-22 23:36:27 +01:00
self :: submit ( $form );
2014-04-20 23:46:31 +02:00
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
));
// 'Feeds #1.1' is a sub-forum of 'Feeds #1'
$crawler = self :: request ( 'GET' , " adm/index.php?i=acp_forums&sid= { $this -> sid } &icat=6&mode=manage&parent_id= { $this -> data [ 'forums' ][ 'Feeds #1' ] } " );
$form = $crawler -> selectButton ( 'addforum' ) -> form ( array (
'forum_name' => 'Feeds #1.1' ,
));
$crawler = self :: submit ( $form );
$form = $crawler -> selectButton ( 'update' ) -> form ( array (
'forum_perm_from' => 2 ,
));
2015-02-22 23:36:27 +01:00
self :: submit ( $form );
2014-04-20 23:46:31 +02:00
// 'Feeds #news' will be used for feed.php?mode=news
$crawler = self :: request ( 'GET' , " adm/index.php?i=acp_forums&mode=manage&sid= { $this -> sid } " );
$form = $crawler -> selectButton ( 'addforum' ) -> form ( array (
'forum_name' => 'Feeds #news' ,
));
$crawler = self :: submit ( $form );
$form = $crawler -> selectButton ( 'update' ) -> form ( array (
'forum_perm_from' => 2 ,
));
2015-02-22 23:36:27 +01:00
self :: submit ( $form );
2014-04-20 23:46:31 +02:00
2015-02-22 23:36:27 +01:00
// 'Feeds #exclude' will not be displayed on app.php/feed/forums
2014-04-20 23:46:31 +02:00
$crawler = self :: request ( 'GET' , " adm/index.php?i=acp_forums&mode=manage&sid= { $this -> sid } " );
$form = $crawler -> selectButton ( 'addforum' ) -> form ( array (
'forum_name' => 'Feeds #exclude' ,
));
$crawler = self :: submit ( $form );
$form = $crawler -> selectButton ( 'update' ) -> form ( array (
'forum_perm_from' => 2 ,
));
2015-02-22 23:36:27 +01:00
self :: submit ( $form );
2014-04-20 23:46:31 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_setup_config_after_forums ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> admin_login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #news' ,
'Feeds #exclude' ,
),
));
$crawler = self :: request ( 'GET' , " adm/index.php?sid= { $this -> sid } &i=acp_board&mode=feed " );
$form = $crawler -> selectButton ( 'Submit' ) -> form ();
// News/Exclude's forums config
$form [ 'feed_news_id' ] -> select ( array ( $this -> data [ 'forums' ][ 'Feeds #news' ]));
$form [ 'feed_exclude_id' ] -> select ( array ( $this -> data [ 'forums' ][ 'Feeds #exclude' ]));
$crawler = self :: submit ( $form );
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( 'CONFIG_UPDATED' , $crawler -> filter ( '.successbox' ) -> text ());
2014-04-20 23:46:31 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_feeds_empty ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
'Feeds #1.1' ,
),
));
// Excluded forums (and topics under them) shouldn't be displayed in feeds
$this -> assert_feeds ( array (
'f' => array (
array (
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
'nb_entries' => 0 ,
),
array (
'id' => $this -> data [ 'forums' ][ 'Feeds #1.1' ],
'nb_entries' => 0 ,
),
),
'forums' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 3 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/category[@label="Feeds #exclude"]' => 0 ,
),
),
),
'news' => array (
array (
'nb_entries' => 0 ,
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_create_exclude_topic ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #exclude' ,
),
));
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #exclude' ], 'Feeds #exclude - Topic #1' , 'This is a test topic posted by the testing framework.' );
$this -> data [ 'topics' ][ 'Feeds #exclude - Topic #1' ] = ( int ) $post [ 'topic_id' ];
}
2014-04-21 13:15:15 +02:00
public function test_feeds_exclude ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #exclude' ,
),
'topics' => array (
'Feeds #exclude - Topic #1' ,
),
));
// Assert that feeds aren't available for excluded forums
$this -> assert_feeds ( array (
'f' => array (
array (
'id' => $this -> data [ 'forums' ][ 'Feeds #exclude' ],
'contents_lang' => array ( 'NO_FEED' ),
'invalid' => true ,
2015-02-22 23:36:27 +01:00
'response_code' => 404 ,
2014-04-20 23:46:31 +02:00
),
),
't' => array (
array (
'id' => $this -> data [ 'topics' ][ 'Feeds #exclude - Topic #1' ],
'contents_lang' => array ( 'NO_FEED' ),
'invalid' => true ,
2015-02-22 23:36:27 +01:00
'response_code' => 404 ,
2014-04-20 23:46:31 +02:00
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 0 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#exclude")]' => 0 ,
),
),
),
'topics' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 0 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#exclude")]' => 0 ,
),
),
),
'topics_new' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 0 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#exclude")]' => 0 ,
),
),
),
'topics_active' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 0 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#exclude")]' => 0 ,
),
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_create_news_topics ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #news' ,
),
));
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #news' ], 'Feeds #news - Topic #1' , 'This is a test topic posted by the testing framework.' );
$this -> data [ 'topics' ][ 'Feeds #news - Topic #1' ] = ( int ) $post [ 'topic_id' ];
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #news' ], 'Feeds #news - Topic #2' , 'This is a test topic posted by the testing framework.' );
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $post [ 'topic_id' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( 'Feeds #news - Topic #2' , $crawler -> filter ( 'html' ) -> text ());
2014-04-20 23:46:31 +02:00
$this -> data [ 'topics' ][ 'Feeds #news - Topic #2' ] = ( int ) $post [ 'topic_id' ];
$this -> data [ 'posts' ][ 'Feeds #news - Topic #2' ] = ( int ) $this -> get_parameter_from_link ( $crawler -> filter ( '.post' ) -> selectLink ( $this -> lang ( 'POST' , '' , '' )) -> link () -> getUri (), 'p' );
// Test creating a reply
$post2 = $this -> create_post ( $this -> data [ 'forums' ][ 'Feeds #news' ], $post [ 'topic_id' ], 'Re: Feeds #news - Topic #2' , 'This is a test post posted by the testing framework.' );
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $post2 [ 'topic_id' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( 'Re: Feeds #news - Topic #2' , $crawler -> filter ( 'html' ) -> text ());
2014-04-20 23:46:31 +02:00
$this -> data [ 'posts' ][ 'Re: Feeds #news - Topic #2' ] = ( int ) $post2 [ 'post_id' ];
}
2014-04-21 13:15:15 +02:00
public function test_feeds_news_admin ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #news' ,
),
'topics' => array (
'Feeds #news - Topic #1' ,
'Feeds #news - Topic #2' ,
),
'posts' => array (
'Feeds #news - Topic #2' ,
),
));
// Assert that the first post of the two topics are displayed in news feed
$this -> assert_feeds ( array (
'news' => array (
array (
'nb_entries' => 2 ,
'contents' => array (
1 => 'This is a test topic posted by the testing framework.' ,
2 => 'This is a test topic posted by the testing framework.' ,
),
),
),
// News should also be displayed in other feeds
'f' => array (
array (
'nb_entries' => 3 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #news' ],
),
),
't' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #news - Topic #1' ],
),
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #news - Topic #2' ],
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 3 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#news")]' => 3 ,
),
),
),
'topics' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 2 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#news")]' => 2 ,
),
),
),
'topics_new' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 2 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#news")]' => 2 ,
),
),
),
'topics_active' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 2 ,
2014-04-20 23:46:31 +02:00
'xpath' => array (
'//entry/title[contains(., "#news")]' => 2 ,
),
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_feeds_news_guest ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'posts' => array (
'Feeds #news - Topic #2' ,
),
));
// Assert that first post of the the two topics are displayed in news feed
$this -> assert_feeds ( array (
'news' => array (
array (
'nb_entries' => 2 ,
'contents' => array (
1 => 'This is a test topic posted by the testing framework.' ,
2 => 'This is a test topic posted by the testing framework.' ,
),
),
),
));
}
2014-04-21 13:15:15 +02:00
public function test_create_sub_forum_topic ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
'Feeds #1.1' ,
),
));
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #1' ], 'Feeds #1 - Topic #1' , 'This is a test topic posted by the testing framework.' );
$this -> data [ 'topics' ][ 'Feeds #1 - Topic #1' ] = ( int ) $post [ 'topic_id' ];
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #1.1' ], 'Feeds #1.1 - Topic #1' , 'This is a test topic posted by the testing framework.' );
$this -> data [ 'topics' ][ 'Feeds #1.1 - Topic #1' ] = ( int ) $post [ 'topic_id' ];
}
2014-04-21 13:15:15 +02:00
public function test_feeds_sub_forum ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
));
// The topics of the sub-forum shouldn't be displayed
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_create_softdelete_post ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
));
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #1' ], 'Feeds #1 - Topic #2' , 'This is a test topic posted by the testing framework.' );
$this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ] = ( int ) $post [ 'topic_id' ];
// Test creating a reply
$post2 = $this -> create_post ( $this -> data [ 'forums' ][ 'Feeds #1' ], $post [ 'topic_id' ], 'Re: Feeds #1 - Topic #2' , 'This is a test post posted by the testing framework.' );
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $post2 [ 'topic_id' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( 'Re: Feeds #1 - Topic #2' , $crawler -> filter ( 'html' ) -> text ());
2014-04-20 23:46:31 +02:00
$this -> data [ 'posts' ][ 'Re: Feeds #1 - Topic #2' ] = ( int ) $post2 [ 'post_id' ];
}
2014-04-21 13:15:15 +02:00
public function test_softdelete_post ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #2' ,
),
'posts' => array (
'Re: Feeds #1 - Topic #2' ,
),
));
$this -> add_lang ( 'posting' );
$crawler = self :: request ( 'GET' , " posting.php?mode=delete&f= { $this -> data [ 'forums' ][ 'Feeds #1' ] } &p= { $this -> data [ 'posts' ][ 'Re: Feeds #1 - Topic #2' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( 'DELETE_PERMANENTLY' , $crawler -> text ());
2014-04-20 23:46:31 +02:00
$form = $crawler -> selectButton ( 'Yes' ) -> form ();
$crawler = self :: submit ( $form );
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( 'POST_DELETED' , $crawler -> text ());
2014-04-20 23:46:31 +02:00
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( $this -> lang ( 'POST_DISPLAY' , '' , '' ), $crawler -> text ());
2014-04-20 23:46:31 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_feeds_softdeleted_post_admin ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #2' ,
),
));
// Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 3 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
'contents_lang' => array (
1 => 'POST_DELETED' ,
),
),
),
't' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ],
'contents_lang' => array (
1 => 'POST_DELETED' ,
),
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 7 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'POST_DELETED' ,
),
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_feeds_softdeleted_post_guest ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #2' ,
),
));
// Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
),
),
't' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ],
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 6 ,
2014-04-20 23:46:31 +02:00
),
),
));
}
2014-04-21 13:15:15 +02:00
public function test_softdelete_topic ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #2' ,
),
));
$this -> add_lang ( 'posting' );
2014-06-14 15:36:36 -07:00
$crawler = $this -> get_quickmod_page ( $this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ], 'DELETE_TOPIC' );
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( 'DELETE_PERMANENTLY' , $crawler -> text ());
2014-04-20 23:46:31 +02:00
$this -> add_lang ( 'mcp' );
$form = $crawler -> selectButton ( 'Yes' ) -> form ();
$crawler = self :: submit ( $form );
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( 'TOPIC_DELETED_SUCCESS' , $crawler -> text ());
2014-04-20 23:46:31 +02:00
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( 'Feeds #1 - Topic #2' , $crawler -> filter ( 'h2' ) -> text ());
2014-04-20 23:46:31 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_feeds_softdeleted_topic_admin ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #2' ,
),
));
// Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 3 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
'contents_lang' => array (
1 => 'POST_DELETED' ,
2 => 'POST_DELETED' ,
),
),
),
't' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ],
'contents_lang' => array (
1 => 'POST_DELETED' ,
2 => 'POST_DELETED' ,
),
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 7 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'POST_DELETED' ,
2 => 'POST_DELETED' ,
),
),
),
'topics' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 5 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'TOPIC_DELETED' ,
),
),
),
'topics_new' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 5 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'TOPIC_DELETED' ,
),
),
),
'topics_active' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 5 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'TOPIC_DELETED' ,
),
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_feeds_softdeleted_topic_guest ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #2' ,
),
));
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
),
),
't' => array (
array (
'id' => $this -> data [ 'topics' ][ 'Feeds #1 - Topic #2' ],
2015-02-22 23:36:27 +01:00
'contents_lang' => array ( 'SORRY_AUTH_READ_TOPIC' ),
2014-04-20 23:46:31 +02:00
'invalid' => true ,
2015-02-22 23:36:27 +01:00
'response_code' => 403 ,
2014-04-20 23:46:31 +02:00
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 5 ,
2014-04-20 23:46:31 +02:00
),
),
'topics' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 4 ,
2014-04-20 23:46:31 +02:00
),
),
'topics_new' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 4 ,
2014-04-20 23:46:31 +02:00
),
),
'topics_active' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 4 ,
2014-04-20 23:46:31 +02:00
),
),
));
}
2014-04-21 13:15:15 +02:00
public function test_create_unapproved_post ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1.1' ,
),
));
$this -> login ( 'admin' );
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #1.1' ], 'Feeds #1.1 - Topic #2' , 'This is a test topic posted by the testing framework.' );
$this -> data [ 'topics' ][ 'Feeds #1.1 - Topic #2' ] = ( int ) $post [ 'topic_id' ];
$this -> logout ();
// Test creating a reply
2014-04-29 23:48:08 +02:00
$this -> login ( 'disapprove_user' );
2015-02-22 23:36:27 +01:00
$this -> create_post ( $this -> data [ 'forums' ][ 'Feeds #1.1' ], $post [ 'topic_id' ], 'Re: Feeds #1.1 - Topic #2' , 'This is a test post posted by the testing framework.' , array (), 'POST_STORED_MOD' );
2014-04-20 23:46:31 +02:00
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $this -> data [ 'topics' ][ 'Feeds #1.1 - Topic #2' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertNotContains ( 'Re: Feeds #1.1 - Topic #2' , $crawler -> filter ( 'html' ) -> text ());
2014-04-20 23:46:31 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_feeds_unapproved_post_admin ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1.1' ,
),
'topics' => array (
'Feeds #1.1 - Topic #2' ,
),
));
// Assert that the unapproved post is marked as unapproved for users that have the right to see it.
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 3 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1.1' ],
'contents_lang' => array (
1 => 'POST_UNAPPROVED' ,
),
),
),
't' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1.1 - Topic #2' ],
'contents_lang' => array (
1 => 'POST_UNAPPROVED' ,
),
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 9 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'POST_UNAPPROVED' ,
),
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_feeds_unapproved_post_disapprove_user ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1.1' ,
),
'topics' => array (
'Feeds #1.1 - Topic #2' ,
),
));
// Assert that the unapproved isn't displayed for regular users
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1.1' ],
),
),
't' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1.1 - Topic #2' ],
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 6 ,
2014-04-20 23:46:31 +02:00
),
),
), 'disapprove_user' );
}
2014-04-21 13:15:15 +02:00
public function test_create_unapproved_topic ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1.1' ,
),
));
2014-10-29 13:24:59 +01:00
$this -> set_flood_interval ( 0 );
2014-04-20 23:46:31 +02:00
2014-04-29 23:48:08 +02:00
$this -> login ( 'disapprove_user' );
2014-04-20 23:46:31 +02:00
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #1.1' ], 'Feeds #1.1 - Topic #3' , 'This is a test topic posted by the testing framework.' , array (), 'POST_STORED_MOD' );
$this -> data [ 'topics' ][ 'Feeds #1 - Topic #3' ] = ( int ) $post [ 'topic_id' ];
$crawler = self :: request ( 'GET' , " viewforum.php?f= { $this -> data [ 'forums' ][ 'Feeds #1.1' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertNotContains ( 'Feeds #1.1 - Topic #3' , $crawler -> filter ( 'html' ) -> text ());
2014-10-29 13:24:59 +01:00
$this -> logout ();
$this -> set_flood_interval ( 15 );
}
protected function set_flood_interval ( $flood_interval )
{
$this -> login ();
$this -> admin_login ();
$crawler = self :: request ( 'GET' , 'adm/index.php?sid=' . $this -> sid . '&i=acp_board&mode=post' );
$form = $crawler -> selectButton ( 'Submit' ) -> form ();
$values = $form -> getValues ();
2015-02-22 23:36:27 +01:00
$values [ 'config[flood_interval]' ] = $flood_interval ;
2014-10-29 13:24:59 +01:00
$form -> setValues ( $values );
$crawler = self :: submit ( $form );
2015-02-22 23:36:27 +01:00
self :: assertGreaterThan ( 0 , $crawler -> filter ( '.successbox' ) -> count ());
2014-10-29 13:24:59 +01:00
$this -> logout ();
2014-04-20 23:46:31 +02:00
}
2014-04-21 13:15:15 +02:00
public function test_feeds_unapproved_topic_admin ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1.1' ,
),
'topics' => array (
'Feeds #1.1 - Topic #3' ,
),
));
// Assert that the unapproved topic is marked as unapproved for users that have the right to see it.
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 4 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1.1' ],
'contents_lang' => array (
1 => 'POST_UNAPPROVED' ,
),
),
),
't' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1.1 - Topic #3' ],
'contents_lang' => array (
1 => 'POST_UNAPPROVED' ,
),
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 10 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'POST_UNAPPROVED' ,
),
),
),
'topics' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 7 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'TOPIC_UNAPPROVED' ,
),
),
),
'topics_new' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 7 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'TOPIC_UNAPPROVED' ,
),
),
),
'topics_active' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 7 ,
2014-04-20 23:46:31 +02:00
'contents_lang' => array (
1 => 'TOPIC_UNAPPROVED' ,
),
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_feeds_unapproved_topic_disapprove_user ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1.1' ,
),
'topics' => array (
'Feeds #1.1 - Topic #3' ,
),
));
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1.1' ],
),
),
't' => array (
array (
'id' => $this -> data [ 'topics' ][ 'Feeds #1.1 - Topic #3' ],
2015-02-22 23:36:27 +01:00
'contents_lang' => array ( 'SORRY_AUTH_READ_TOPIC' ),
2014-04-20 23:46:31 +02:00
'invalid' => true ,
2015-02-22 23:36:27 +01:00
'response_code' => 403 ,
2014-04-20 23:46:31 +02:00
),
),
'overall' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 6 ,
2014-04-20 23:46:31 +02:00
),
),
'topics' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 5 ,
2014-04-20 23:46:31 +02:00
),
),
'topics_new' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 5 ,
2014-04-20 23:46:31 +02:00
),
),
'topics_active' => array (
array (
2014-04-21 01:39:12 +02:00
'nb_entries' => 5 ,
2014-04-20 23:46:31 +02:00
),
),
), 'disapprove_user' );
}
2014-04-21 13:15:15 +02:00
public function test_create_attachment_topic ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
));
// Test creating a topic with 1 attachment
$post = $this -> create_topic ( $this -> data [ 'forums' ][ 'Feeds #1' ], 'Feeds #1 - Topic #3' , 'This is a test topic posted by the testing framework. [attachment=0]Attachment #0[/attachment]' , array ( 'upload_files' => 1 ));
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $post [ 'topic_id' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( 'Feeds #1 - Topic #3' , $crawler -> filter ( 'html' ) -> text ());
2014-04-20 23:46:31 +02:00
$this -> data [ 'topics' ][ 'Feeds #1 - Topic #3' ] = ( int ) $post [ 'topic_id' ];
}
2014-04-21 13:15:15 +02:00
public function test_feeds_attachment_admin ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #3' ,
),
'posts' => array (
'Feeds #1 - Topic #3' ,
),
'attachments' => true ,
));
$this -> assert_feeds ( array (
'f' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 4 ,
2014-04-20 23:46:31 +02:00
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => true ,
),
),
),
),
),
't' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1 - Topic #3' ],
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => true ,
),
),
),
),
),
'overall' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 11 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => true ,
),
),
),
),
),
'topics' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 8 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => true ,
),
),
),
),
),
'topics_new' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 8 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => true ,
),
),
),
),
),
'topics_active' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 8 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => true ,
),
),
),
),
),
), 'admin' );
}
2014-04-21 13:15:15 +02:00
public function test_feeds_attachment_guest ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #3' ,
),
'posts' => array (
'Feeds #1 - Topic #3' ,
),
'attachments' => true ,
));
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => false ,
),
),
),
),
),
't' => array (
array (
'nb_entries' => 1 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1 - Topic #3' ],
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => false ,
),
),
),
),
),
'overall' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 7 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => false ,
),
),
),
),
),
'topics' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 6 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => false ,
),
),
),
),
),
'topics_new' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 6 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => false ,
),
),
),
),
),
'topics_active' => array (
array (
2014-04-30 00:47:37 +02:00
'nb_entries' => 6 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
'displayed' => false ,
),
),
),
),
),
));
}
2014-04-29 23:27:43 +02:00
public function test_create_missing_attachment_post ()
2014-04-20 23:46:31 +02:00
{
$this -> login ();
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #3' ,
),
));
// Test creating a reply with 1 missing attachment
$post2 = $this -> create_post ( $this -> data [ 'forums' ][ 'Feeds #1' ], $this -> data [ 'topics' ][ 'Feeds #1 - Topic #3' ], 'Re: Feeds #1 - Topic #3-1' , 'This is a test post posted by the testing framework. [attachment=0]Attachment #0[/attachment]' );
$crawler = self :: request ( 'GET' , " viewtopic.php?t= { $post2 [ 'topic_id' ] } &sid= { $this -> sid } " );
2015-02-22 23:36:27 +01:00
self :: assertContains ( 'Re: Feeds #1 - Topic #3-1' , $crawler -> filter ( 'html' ) -> text ());
2014-04-20 23:46:31 +02:00
$this -> data [ 'posts' ][ 'Re: Feeds #1 - Topic #3-1' ] = ( int ) $post2 [ 'post_id' ];
}
2014-04-21 13:15:15 +02:00
public function test_feeds_missing_attachment_admin ()
2014-04-20 23:46:31 +02:00
{
$this -> load_ids ( array (
'forums' => array (
'Feeds #1' ,
),
'topics' => array (
'Feeds #1 - Topic #3' ,
),
'posts' => array (
'Feeds #1 - Topic #3' ,
),
));
$this -> add_lang ( 'viewtopic' );
$this -> assert_feeds ( array (
'f' => array (
array (
'nb_entries' => 5 ,
'id' => $this -> data [ 'forums' ][ 'Feeds #1' ],
'contents' => array (
1 => 'Attachment #0' ,
),
),
),
't' => array (
array (
'nb_entries' => 2 ,
'id' => $this -> data [ 'topics' ][ 'Feeds #1 - Topic #3' ],
'contents' => array (
1 => 'Attachment #0' ,
),
),
),
'overall' => array (
array (
2014-05-06 14:54:22 +02:00
'nb_entries' => 12 ,
2014-04-20 23:46:31 +02:00
'contents' => array (
1 => 'Attachment #0' ,
),
),
),
'topics' => array (
array (
2014-05-06 14:54:22 +02:00
'nb_entries' => 8 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
2014-05-06 14:54:22 +02:00
'displayed' => true ,
2014-04-20 23:46:31 +02:00
),
),
),
),
),
'topics_new' => array (
array (
2014-05-06 14:54:22 +02:00
'nb_entries' => 8 ,
2014-04-20 23:46:31 +02:00
'attachments' => array (
1 => array ( // First entry
array ( // First attachment to fetch
'id' => $this -> data [ 'attachments' ][ $this -> data [ 'posts' ][ 'Feeds #1 - Topic #3' ]][ 0 ],
2014-05-06 14:54:22 +02:00
'displayed' => true ,
2014-04-20 23:46:31 +02:00
),
),
),
),
),
'topics_active' => array (
array (
2014-05-06 14:54:22 +02:00
'nb_entries' => 8 ,
2014-04-20 23:46:31 +02:00
'contents' => array (
1 => 'Attachment #0' ,
),
),
),
), 'admin' );
2014-04-29 23:27:43 +02:00
}
2014-04-20 23:46:31 +02:00
protected function assert_feeds ( $data , $username = false )
{
if ( $username )
{
$this -> login ( $username );
2014-04-21 13:15:15 +02:00
$init_values = self :: $init_values [ $username ];
2014-04-21 01:39:12 +02:00
}
else
{
2014-04-21 13:15:15 +02:00
$init_values = self :: $init_values [ 'disapprove_user' ];
2014-04-20 23:46:31 +02:00
}
foreach ( $data as $mode => $feeds )
{
foreach ( $feeds as $feed_data )
{
2015-02-22 23:36:27 +01:00
if ( $mode === 'f' )
{
$params = " /forum/ { $feed_data [ 'id' ] } " ;
$this -> assert_feed ( $params , $feed_data );
}
else if ( $mode === 't' )
2014-04-20 23:46:31 +02:00
{
2015-02-22 23:36:27 +01:00
$params = " /topic/ { $feed_data [ 'id' ] } " ;
2014-04-20 23:46:31 +02:00
$this -> assert_feed ( $params , $feed_data );
}
else
{
2014-04-21 01:39:12 +02:00
switch ( $mode ) {
case 'forums' :
$feed_data [ 'nb_entries' ] = (( int ) $feed_data [ 'nb_entries' ] + $init_values [ 'forums_value' ]);
break ;
case 'overall' :
2014-04-21 13:15:15 +02:00
$feed_data [ 'nb_entries' ] = min ( $feed_data [ 'nb_entries' ] + $init_values [ 'overall_value' ], self :: $init_values [ 'post_base_items' ]);
2014-04-21 01:39:12 +02:00
break ;
case 'topics' :
2014-04-21 13:15:15 +02:00
$feed_data [ 'nb_entries' ] = min ( $feed_data [ 'nb_entries' ] + $init_values [ 'topics_value' ], self :: $init_values [ 'topic_base_items' ]);
2014-04-21 01:39:12 +02:00
break ;
case 'topics_new' :
2014-04-21 13:15:15 +02:00
$feed_data [ 'nb_entries' ] = min ( $feed_data [ 'nb_entries' ] + $init_values [ 'topics_new_value' ], self :: $init_values [ 'topic_base_items' ]);
2014-04-21 01:39:12 +02:00
break ;
case 'topics_active' :
2014-04-21 13:15:15 +02:00
$feed_data [ 'nb_entries' ] = min ( $feed_data [ 'nb_entries' ] + $init_values [ 'topics_active_value' ], self :: $init_values [ 'topic_base_items' ]);
2014-04-21 01:39:12 +02:00
break ;
case 'news' :
break ;
default :
2015-02-22 23:36:27 +01:00
self :: fail ( 'Unsupported feed mode: ' . $mode );
2014-04-21 01:39:12 +02:00
}
2015-02-22 23:36:27 +01:00
$params = " / { $mode } " ;
2014-04-20 23:46:31 +02:00
$this -> assert_feed ( $params , $feed_data );
}
}
}
}
protected function assert_feed ( $params , $data )
{
2015-02-22 23:36:27 +01:00
$crawler = self :: request ( 'GET' , 'app.php/feed' . $params , array (), false );
2014-04-20 23:46:31 +02:00
2014-04-29 23:27:43 +02:00
if ( empty ( $data [ 'invalid' ]))
2014-04-20 23:46:31 +02:00
{
self :: assert_response_xml ();
2015-02-22 23:36:27 +01:00
self :: assertEquals ( $data [ 'nb_entries' ], $crawler -> filter ( 'entry' ) -> count (), " Tested feed : 'app.php/feed { $params } ' " );
2014-04-20 23:46:31 +02:00
2014-04-29 23:27:43 +02:00
if ( ! empty ( $data [ 'xpath' ]))
{
2014-04-20 23:46:31 +02:00
foreach ( $data [ 'xpath' ] as $xpath => $count_expected )
{
2015-02-22 23:36:27 +01:00
self :: assertCount ( $count_expected , $crawler -> filterXPath ( $xpath ), " Tested feed : 'app.php/feed { $params } ', Search for { $xpath } " );
2014-04-20 23:46:31 +02:00
}
}
2014-04-29 23:27:43 +02:00
if ( ! empty ( $data [ 'contents' ]))
{
2014-04-20 23:46:31 +02:00
foreach ( $data [ 'contents' ] as $entry_id => $string )
{
$content = $crawler -> filterXPath ( " //entry[ { $entry_id } ]/content " ) -> text ();
2015-02-22 23:36:27 +01:00
self :: assertContains ( $string , $content , " Tested feed : 'app.php/feed { $params } ' " );
2014-04-20 23:46:31 +02:00
}
}
2014-04-29 23:27:43 +02:00
if ( ! empty ( $data [ 'contents_lang' ]))
{
2014-04-20 23:46:31 +02:00
foreach ( $data [ 'contents_lang' ] as $entry_id => $string )
{
$content = $crawler -> filterXPath ( " //entry[ { $entry_id } ]/content " ) -> text ();
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( $string , $content , " Tested feed : 'app.php/feed { $params } ' " );
2014-04-20 23:46:31 +02:00
}
}
2014-04-29 23:27:43 +02:00
if ( ! empty ( $data [ 'attachments' ]))
{
2014-04-20 23:46:31 +02:00
foreach ( $data [ 'attachments' ] as $entry_id => $attachments )
{
2015-02-22 23:36:27 +01:00
$content = $crawler -> filterXPath ( " //entry[ { $entry_id } ]/content " ) -> text ();
2014-04-20 23:46:31 +02:00
foreach ( $attachments as $i => $attachment )
{
2015-07-15 21:55:12 +02:00
$url = self :: $root_url . " download/file.php?id= { $attachment [ 'id' ] } " ;
2014-04-20 23:46:31 +02:00
$string = " Attachment # { $i } " ;
if ( $attachment [ 'displayed' ])
{
2015-02-22 23:36:27 +01:00
self :: assertContains ( $url , $content , " Tested feed : 'app.php/feed { $params } ' " );
self :: assertNotContains ( $string , $content , " Tested feed : 'app.php/feed { $params } ' " );
2014-04-20 23:46:31 +02:00
}
else
{
2015-02-22 23:36:27 +01:00
self :: assertContains ( $string , $content , " Tested feed : 'app.php/feed { $params } ' " );
self :: assertNotContains ( $url , $content , " Tested feed : 'app.php/feed { $params } ' " );
2014-04-20 23:46:31 +02:00
}
}
}
}
}
else
{
2015-02-22 23:36:27 +01:00
self :: assert_response_html ( $data [ 'response_code' ] ? : 202 );
2014-04-20 23:46:31 +02:00
2014-04-29 23:27:43 +02:00
if ( ! empty ( $data [ 'contents_lang' ]))
{
2015-02-22 23:36:27 +01:00
$content = $crawler -> filter ( 'html' ) -> text ();
2014-04-20 23:46:31 +02:00
foreach ( $data [ 'contents_lang' ] as $string )
{
2015-02-22 23:36:27 +01:00
self :: assertContainsLang ( $string , $content , " Tested feed : 'app.php/feed { $params } ' " );
2014-04-20 23:46:31 +02:00
}
}
}
}
protected function load_ids ( $data )
{
$this -> db = $this -> get_db ();
if ( ! empty ( $data [ 'forums' ]))
{
$sql = ' SELECT *
FROM phpbb_forums
WHERE ' . $this->db->sql_in_set(' forum_name ', $data[' forums ' ]);
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
2015-02-22 23:36:27 +01:00
if ( in_array ( $row [ 'forum_name' ], $data [ 'forums' ], false ))
2014-04-20 23:46:31 +02:00
{
$this -> data [ 'forums' ][ $row [ 'forum_name' ]] = ( int ) $row [ 'forum_id' ];
}
}
$this -> db -> sql_freeresult ( $result );
}
if ( ! empty ( $data [ 'topics' ]))
{
$sql = ' SELECT *
FROM phpbb_topics
WHERE ' . $this->db->sql_in_set(' topic_title ', $data[' topics ' ]);
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
2015-02-22 23:36:27 +01:00
if ( in_array ( $row [ 'topic_title' ], $data [ 'topics' ], false ))
2014-04-20 23:46:31 +02:00
{
$this -> data [ 'topics' ][ $row [ 'topic_title' ]] = ( int ) $row [ 'topic_id' ];
}
}
$this -> db -> sql_freeresult ( $result );
}
$post_ids = array ();
if ( ! empty ( $data [ 'posts' ]))
{
$sql = ' SELECT *
FROM phpbb_posts
WHERE ' . $this->db->sql_in_set(' post_subject ', $data[' posts ' ]);
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
2015-02-22 23:36:27 +01:00
if ( in_array ( $row [ 'post_subject' ], $data [ 'posts' ], false ))
2014-04-20 23:46:31 +02:00
{
$this -> data [ 'posts' ][ $row [ 'post_subject' ]] = ( int ) $row [ 'post_id' ];
$post_ids [] = ( int ) $row [ 'post_id' ];
}
}
$this -> db -> sql_freeresult ( $result );
if ( isset ( $data [ 'attachments' ]))
{
$sql = ' SELECT *
FROM phpbb_attachments
WHERE in_message = 0 AND ' . $this->db->sql_in_set(' post_msg_id ' , $post_ids );
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
$this -> data [ 'attachments' ][( int ) $row [ 'post_msg_id' ]][] = ( int ) $row [ 'attach_id' ];
}
$this -> db -> sql_freeresult ( $result );
}
}
}
}