-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from VSEphpbb/updates/testing
Add PHPUnit Tests
- Loading branch information
Showing
9 changed files
with
661 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests/ export-ignore | ||
travis/ export-ignore | ||
.travis.yml export-ignore | ||
.gitignore export-ignore | ||
.gitattributes export-ignore | ||
phpunit.xml.dist export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
language: php | ||
|
||
matrix: | ||
include: | ||
- php: 5.3.3 | ||
env: DB=mysqli | ||
- php: 5.3 | ||
env: DB=mysqli # MyISAM | ||
- php: 5.4 | ||
env: DB=mysqli | ||
- php: 5.4 | ||
env: DB=mysql | ||
- php: 5.4 | ||
env: DB=mariadb | ||
- php: 5.4 | ||
env: DB=postgres | ||
- php: 5.4 | ||
env: DB=sqlite3 | ||
- php: 5.5 | ||
env: DB=mysqli | ||
- php: 5.6 | ||
env: DB=mysqli | ||
- php: hhvm | ||
env: DB=mysqli | ||
allow_failures: | ||
- php: hhvm | ||
fast_finish: true | ||
|
||
env: | ||
global: | ||
- EXTNAME="phpbb/boardannouncements" # CHANGE name of the extension HERE | ||
- SNIFF="1" # Should we run code sniffer on your code? | ||
- IMAGE_ICC="1" # Should we run icc profile sniffer on your images? | ||
- PHPBB_BRANCH="develop-ascraeus" | ||
|
||
branches: | ||
only: | ||
- master | ||
- develop | ||
- /^develop-.*$/ | ||
|
||
install: | ||
- travis/prepare-phpbb.sh $EXTNAME $PHPBB_BRANCH | ||
- cd ../../phpBB3 | ||
- travis/prepare-extension.sh $EXTNAME $PHPBB_BRANCH | ||
- travis/setup-phpbb.sh $DB $TRAVIS_PHP_VERSION | ||
|
||
before_script: | ||
- travis/setup-database.sh $DB $TRAVIS_PHP_VERSION | ||
|
||
script: | ||
- sh -c "if [ '$SNIFF' != '0' ]; then travis/phing-sniff.sh $DB $TRAVIS_PHP_VERSION; fi" | ||
- sh -c "if [ '$IMAGE_ICC' != '0' ]; then travis/check-image-icc-profiles.sh $DB $TRAVIS_PHP_VERSION; fi" | ||
- phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/travis/phpunit-$DB-travis.xml --bootstrap ./tests/bootstrap.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="true" | ||
backupStaticAttributes="true" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
verbose="true" | ||
bootstrap="../../../../tests/bootstrap.php" | ||
> | ||
<testsuites> | ||
<testsuite name="Extension Test Suite"> | ||
<directory suffix="_test.php">./tests</directory> | ||
<exclude>./tests/functional</exclude> | ||
</testsuite> | ||
<testsuite name="Extension Functional Tests"> | ||
<directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">./tests/functional/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<blacklist> | ||
<directory>./tests/</directory> | ||
</blacklist> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./</directory> | ||
<exclude> | ||
<directory suffix=".php">./language/</directory> | ||
<directory suffix=".php">./migrations/</directory> | ||
<directory suffix=".php">./tests/</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<dataset> | ||
<table name="phpbb_config_text"> | ||
<column>config_name</column> | ||
<column>config_value</column> | ||
<row> | ||
<value>announcement_text</value> | ||
<value>Hello world!</value> | ||
</row> | ||
<row> | ||
<value>announcement_uid</value> | ||
<value></value> | ||
</row> | ||
<row> | ||
<value>announcement_bitfield</value> | ||
<value></value> | ||
</row> | ||
<row> | ||
<value>announcement_options</value> | ||
<value>7</value> | ||
</row> | ||
<row> | ||
<value>announcement_bgcolor</value> | ||
<value>FF0000</value> | ||
</row> | ||
<row> | ||
<value>announcement_timestamp</value> | ||
<value>1402680180</value> | ||
</row> | ||
</table> | ||
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
<?php | ||
/** | ||
* | ||
* Board Announcements extension for the phpBB Forum Software package. | ||
* (Thanks/credit to nickvergessen for desigining these tests) | ||
* | ||
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
*/ | ||
|
||
namespace phpbb\boardannouncements\tests\event; | ||
|
||
require_once dirname(__FILE__) . '/../../../../../includes/functions.php'; | ||
require_once dirname(__FILE__) . '/../../../../../includes/functions_content.php'; | ||
require_once dirname(__FILE__) . '/../../../../../includes/utf/utf_tools.php'; | ||
|
||
class event_listener_test extends \phpbb_database_test_case | ||
{ | ||
/** | ||
* Define the extensions to be tested | ||
* | ||
* @return array vendor/name of extension(s) to test | ||
* @access static | ||
*/ | ||
static protected function setup_extensions() | ||
{ | ||
return array('phpbb/boardannouncements'); | ||
} | ||
|
||
/** @var \phpbb\boardannouncements\event\listener */ | ||
protected $listener; | ||
|
||
/** | ||
* Get data set fixtures | ||
* | ||
* @return PHPUnit_Extensions_Database_DataSet_XmlDataSet | ||
* @access public | ||
*/ | ||
public function getDataSet() | ||
{ | ||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config_text.xml'); | ||
} | ||
|
||
/** | ||
* Setup test environment | ||
* | ||
* @access public | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
global $cache, $user, $phpbb_dispatcher, $phpbb_root_path; | ||
|
||
// Load the database class | ||
$this->db = $this->new_dbal(); | ||
|
||
// Mock some global classes that may be called during code execution | ||
$cache = new \phpbb_mock_cache; | ||
$user = new \phpbb_mock_user; | ||
$user->optionset('viewcensors', false); | ||
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher(); | ||
|
||
// Load/Mock classes required by the event listener class | ||
$this->config = new \phpbb\config\config(array('board_announcements_enable' => 1)); | ||
$this->config_text = new \phpbb\config\db_text($this->db, 'phpbb_config_text'); | ||
$this->request = $this->getMock('\phpbb\request\request'); | ||
$this->template = new \phpbb\boardannouncements\tests\mock\template(); | ||
$this->user = $this->getMock('\phpbb\user'); | ||
$this->user->data['board_announcements_status'] = 1; | ||
$this->controller_helper = new \phpbb_mock_controller_helper( | ||
$this->template, | ||
$this->user, | ||
$this->config, | ||
new \phpbb\controller\provider(), | ||
new \phpbb_mock_extension_manager($phpbb_root_path), | ||
'', | ||
'php', | ||
dirname(__FILE__) . '/../../' | ||
); | ||
} | ||
|
||
/** | ||
* Create our event listener | ||
* | ||
* @access protected | ||
*/ | ||
protected function set_listener() | ||
{ | ||
$this->listener = new \phpbb\boardannouncements\event\listener( | ||
$this->config, | ||
$this->config_text, | ||
$this->controller_helper, | ||
$this->request, | ||
$this->template, | ||
$this->user | ||
); | ||
} | ||
|
||
/** | ||
* Test the event listener is constructed correctly | ||
* | ||
* @access public | ||
*/ | ||
public function test_construct() | ||
{ | ||
$this->set_listener(); | ||
$this->assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); | ||
} | ||
|
||
/** | ||
* Test the event listener is subscribing events | ||
* | ||
* @access public | ||
*/ | ||
public function test_getSubscribedEvents() | ||
{ | ||
$this->assertEquals(array( | ||
'core.user_setup', | ||
'core.page_header_after', | ||
), array_keys(\phpbb\boardannouncements\event\listener::getSubscribedEvents())); | ||
} | ||
|
||
/** | ||
* Data set for test_load_language_on_setup | ||
* | ||
* @return array Array of test data | ||
* @access public | ||
*/ | ||
public function load_language_on_setup_data() | ||
{ | ||
return array( | ||
array( | ||
array(), | ||
array( | ||
array( | ||
'ext_name' => 'phpbb/boardannouncements', | ||
'lang_set' => 'boardannouncements_common', | ||
), | ||
), | ||
), | ||
array( | ||
array( | ||
array( | ||
'ext_name' => 'foo/bar', | ||
'lang_set' => 'foobar', | ||
), | ||
), | ||
array( | ||
array( | ||
'ext_name' => 'foo/bar', | ||
'lang_set' => 'foobar', | ||
), | ||
array( | ||
'ext_name' => 'phpbb/boardannouncements', | ||
'lang_set' => 'boardannouncements_common', | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Test the load_language_on_setup event | ||
* | ||
* @dataProvider load_language_on_setup_data | ||
* @access public | ||
*/ | ||
public function test_load_language_on_setup($lang_set_ext, $expected_contains) | ||
{ | ||
$this->set_listener(); | ||
|
||
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); | ||
$dispatcher->addListener('core.user_setup', array($this->listener, 'load_language_on_setup')); | ||
|
||
$event_data = array('lang_set_ext'); | ||
$event = new \phpbb\event\data(compact($event_data)); | ||
$dispatcher->dispatch('core.user_setup', $event); | ||
|
||
$lang_set_ext = $event->get_data_filtered($event_data); | ||
$lang_set_ext = $lang_set_ext['lang_set_ext']; | ||
|
||
foreach ($expected_contains as $expected) | ||
{ | ||
$this->assertContains($expected, $lang_set_ext); | ||
} | ||
} | ||
|
||
/** | ||
* Test the display_board_announcements event | ||
* | ||
* @access public | ||
*/ | ||
public function test_display_board_announcements() | ||
{ | ||
$this->set_listener(); | ||
|
||
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); | ||
$dispatcher->addListener('core.page_header_after', array($this->listener, 'display_board_announcements')); | ||
$dispatcher->dispatch('core.page_header_after'); | ||
|
||
$this->assertEquals(array( | ||
'S_BOARD_ANNOUNCEMENT' => true, | ||
'BOARD_ANNOUNCEMENT' => 'Hello world!', | ||
'BOARD_ANNOUNCEMENT_BGCOLOR' => 'FF0000', | ||
'U_BOARD_ANNOUNCEMENT_CLOSE' => 'app.php/boardannouncements/close?hash=' . generate_link_hash('close_boardannouncement'), | ||
), $this->template->get_template_vars()); | ||
} | ||
} |
Oops, something went wrong.