diff --git a/composer.json b/composer.json index 5828f68..2ffd82d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ ], "require": { "php": ">=5.6", - "composer/installers": "~1.0" + "composer/installers": "~1.0", + "ext-zip": "*" }, "require-dev": { "phing/phing": "~2.4" diff --git a/helper/packager.php b/helper/packager.php index dd6df41..aa29339 100644 --- a/helper/packager.php +++ b/helper/packager.php @@ -16,6 +16,7 @@ use phpbb\config\config; use phpbb\di\service_collection; use phpbb\filesystem\filesystem; +use phpbb\path_helper; use phpbb\skeleton\ext; use phpbb\skeleton\template\twig\extension\skeleton_version_compare; use phpbb\template\context; @@ -115,8 +116,6 @@ public function create_extension($data) $filesystem->remove($this->root_path . 'store/tmp-ext'); $filesystem->mkdir($ext_path); - $phpbb31 = (bool) preg_match('/^[\D]*3\.1.*$/', $data['requirements']['phpbb_version_min']); - $template = $this->get_template_engine(); $template->set_custom_style('skeletonextension', $this->root_path . 'ext/phpbb/skeleton/skeleton'); $template->assign_vars([ @@ -124,8 +123,7 @@ public function create_extension($data) 'EXTENSION' => $data['extension'], 'REQUIREMENTS' => $data['requirements'], 'AUTHORS' => $data['authors'], - 'LANGUAGE' => $this->get_language_version_data($phpbb31), - 'S_PHPBB_31' => $phpbb31, + 'LANGUAGE' => $this->get_language_version_data($data), ]); $component_data = $this->get_component_dialog_values(); @@ -201,10 +199,13 @@ protected function get_template_engine() 'assets_version' => null, ]); + /** @var path_helper $path_helper */ $path_helper = $this->phpbb_container->get('path_helper'); + /** @var filesystem $filesystem */ + $filesystem = $this->phpbb_container->get('filesystem'); $environment = new environment( $config, - $this->phpbb_container->get('filesystem'), + $filesystem, $path_helper, $this->phpbb_container->getParameter('core.cache_dir'), $this->phpbb_container->get('ext.manager'), @@ -236,19 +237,25 @@ protected function get_template_engine() * Get an array of language class and methods depending on 3.1 or 3.2 * compatibility, for use in the skeleton twig templates. * - * @param bool $phpbb31 Is phpBB 3.1 support requested? + * @param array $data Extension data * * @return array An array of language data */ - protected function get_language_version_data($phpbb31) + protected function get_language_version_data($data) { + $phpbb_31 = false; + if (isset($data['requirements']['phpbb_version_min'])) + { + $phpbb_31 = (bool) preg_match('/^\D*3\.1.*$/', $data['requirements']['phpbb_version_min']); + } + return [ - 'class' => $phpbb31 ? '\phpbb\user' : '\phpbb\language\language', - 'object' => $phpbb31 ? 'user' : 'language', - 'function' => $phpbb31 ? 'add_lang_ext' : 'add_lang', + 'class' => $phpbb_31 ? '\phpbb\user' : '\phpbb\language\language', + 'object' => $phpbb_31 ? 'user' : 'language', + 'function' => $phpbb_31 ? 'add_lang_ext' : 'add_lang', 'indent' => [ - 'class' => $phpbb31 ? "\t\t\t" : '', - 'object' => $phpbb31 ? "\t" : '', + 'class' => $phpbb_31 ? "\t\t\t" : '', + 'object' => $phpbb_31 ? "\t" : '', ], ]; } diff --git a/language/en/common.php b/language/en/common.php index 5d914a3..0f085d8 100644 --- a/language/en/common.php +++ b/language/en/common.php @@ -130,7 +130,7 @@ 'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_EXPLAIN' => 'Creates a GitHub Actions workflow that uses a reusable, phpBB-maintained framework to run PHPUnit tests on your repository. The workflow file is saved in .github/workflows and runs automatically on each commit and pull request.', 'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CUSTOM' => 'Create a standalone GitHub Actions workflow [Deprecated: not recommended unless you plan to modify jobs or steps]', 'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CUSTOM_UI' => 'GitHub Actions Workflow (Standalone – Deprecated)', - 'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CUSTOM_EXPLAIN' => 'Deprecated: Creates a fully standalone workflow to run PHPUnit tests without using the shared phpBB framework. This overrides the reusable workflow and is no longer recommended. The file is saved in .github/workflows and runs on each commit and pull request.', + 'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CUSTOM_EXPLAIN' => 'Deprecated: Creates a standalone workflow for PHPUnit tests without the shared phpBB framework. Will be overridden if the reusable workflow is also selected. Saved in .github/workflows and runs on each commit and pull request.', 'SKELETON_QUESTION_COMPONENT_BUILD' => 'Create a sample build script for phing', 'SKELETON_QUESTION_COMPONENT_BUILD_UI' => 'Build script (phing)', 'SKELETON_QUESTION_COMPONENT_BUILD_EXPLAIN' => 'A phing build script is generated for your extension which can be used to generate build packages to help simplify the release or deployment processes.', diff --git a/skeleton/.github/workflows/tests.yml.twig b/skeleton/.github/workflows/tests.yml.twig index e984322..552fb5a 100644 --- a/skeleton/.github/workflows/tests.yml.twig +++ b/skeleton/.github/workflows/tests.yml.twig @@ -1,6 +1,41 @@ name: Tests -{% if COMPONENT.githubactions_custom %} +{% if COMPONENT.githubactions %} +# For most extensions, this workflow should not need changing; +# simply commit it to your repository. +# +# See the README for full details and configuration instructions: +# - https://github.com/phpbb-extensions/test-framework +# +on: + push: + # Run tests when commits are pushed to these branches in your repo, + # or remove this branches section to run tests on all your branches + branches: + - main # Main production branch + - master # Legacy or alternative main branch + - dev/* # Any feature branches under "dev/", e.g., dev/new-feature + - release-* # Any release branches under "release-", e.g., release-1.0.0 + + pull_request: + # Run tests when pull requests are made on these branches in your repo, + # or remove this branches section to run tests on all your branches + branches: + - main + - master + - dev/* + +jobs: + call-tests: + name: Extension tests + # Set the phpBB branch to test your extension with after the @ symbol + # - 3.3.x: Targets the phpBB 3.3.x release line + # - master: Targets the latest development version of phpBB (master branch) + uses: phpbb-extensions/test-framework/.github/workflows/tests.yml@{{ skeleton_version_compare(REQUIREMENTS.phpbb_version_min, "4.0", "<") ? '3.3.x' : 'master' }} + with: + # Your extension vendor/package name + EXTNAME: {{ EXTENSION.vendor_name }}/{{ EXTENSION.extension_name }} +{% elseif COMPONENT.githubactions_custom %} env: EXTNAME: {{ EXTENSION.vendor_name }}/{{ EXTENSION.extension_name }} # Your extension vendor/package name SNIFF: 1 # Run code sniffer on your code? 1 or 0 @@ -425,39 +460,4 @@ jobs: run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php working-directory: ./phpBB3 # END Other Tests Job -{% else %} -# For most extensions, this workflow should not need changing; -# simply commit it to your repository. -# -# See the README for full details and configuration instructions: -# - https://github.com/phpbb-extensions/test-framework -# -on: - push: - # Run tests when commits are pushed to these branches in your repo, - # or remove this branches section to run tests on all your branches - branches: - - main # Main production branch - - master # Legacy or alternative main branch - - dev/* # Any feature branches under "dev/", e.g., dev/new-feature - - release-* # Any release branches under "release-", e.g., release-1.0.0 - - pull_request: - # Run tests when pull requests are made on these branches in your repo, - # or remove this branches section to run tests on all your branches - branches: - - main - - master - - dev/* - -jobs: - call-tests: - name: Extension tests - # Set the phpBB branch to test your extension with after the @ symbol - # - 3.3.x: Targets the phpBB 3.3.x release line - # - master: Targets the latest development version of phpBB (master branch) - uses: phpbb-extensions/test-framework/.github/workflows/tests.yml@{{ skeleton_version_compare(REQUIREMENTS.phpbb_version_min, "4.0", "<") ? '3.3.x' : 'master' }} - with: - # Your extension vendor/package name - EXTNAME: {{ EXTENSION.vendor_name }}/{{ EXTENSION.extension_name }} {% endif %} diff --git a/skeleton/README.md.twig b/skeleton/README.md.twig index e14d56c..1f72722 100644 --- a/skeleton/README.md.twig +++ b/skeleton/README.md.twig @@ -1,29 +1,18 @@ # {{ EXTENSION.extension_display_name }} -## Installation - -Copy the extension to phpBB/ext/{{ EXTENSION.vendor_name }}/{{ EXTENSION.extension_name }} - -Go to "ACP" > "Customise" > "Extensions" and enable the "{{ EXTENSION.extension_display_name }}" extension. - -{% if COMPONENT.tests %} -## Tests and Continuous Integration +This is a basic skeleton to help you start building a phpBB extension. Customise it as needed. -{% if COMPONENT.githubactions %}We use GitHub Actions as a continuous integration server and phpunit for our unit testing..{% endif %} -To run the tests locally, you need to install phpBB from its Git repository. Afterward run the following command from the phpBB Git repository's root: - -Windows: - - phpBB\vendor\bin\phpunit.bat -c phpBB\ext\{{ EXTENSION.vendor_name }}\{{ EXTENSION.extension_name }}\phpunit.xml.dist - -others: +## Installation - phpBB/vendor/bin/phpunit -c phpBB/ext/{{ EXTENSION.vendor_name }}/{{ EXTENSION.extension_name }}/phpunit.xml.dist +1. Copy the extension to: `phpBB/ext/{{ EXTENSION.vendor_name }}/{{ EXTENSION.extension_name }}` +2. In the ACP, go to: **Customise → Manage extensions** +3. Enable the **{{ EXTENSION.extension_display_name }}** extension +## Extension Development Guide -See more information on the [phpBB Developer Docs](https://area51.phpbb.com/docs/dev/master/testing/index.html) +New to phpBB extension development? +Start here: [phpBB Extension Development Guide](https://area51.phpbb.com/docs/dev/3.3.x/extensions/index.html) -{% endif %} ## License -[GNU General Public License v2](license.txt) +Licensed under the [GNU General Public License v2](license.txt) diff --git a/skeleton/adm/style/acp_demo_body.html.twig b/skeleton/adm/style/acp_demo_body.html.twig index d3c853b..65af8bc 100644 --- a/skeleton/adm/style/acp_demo_body.html.twig +++ b/skeleton/adm/style/acp_demo_body.html.twig @@ -15,14 +15,16 @@ {{ '{{' }} lang('SETTINGS') }}
-
-
+
+ + +
-   - +   + {{ '{{' }} S_FORM_TOKEN }}
diff --git a/skeleton/controller/acp_controller.php.twig b/skeleton/controller/acp_controller.php.twig index 2705fc0..a66d66b 100644 --- a/skeleton/controller/acp_controller.php.twig +++ b/skeleton/controller/acp_controller.php.twig @@ -111,7 +111,7 @@ class acp_controller // Set output variables for display in the template $this->template->assign_vars([ 'S_ERROR' => $s_errors, - 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', + 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', 'U_ACTION' => $this->u_action, diff --git a/skeleton/controller/mcp_controller.php.twig b/skeleton/controller/mcp_controller.php.twig index e5279b4..a7e51c4 100644 --- a/skeleton/controller/mcp_controller.php.twig +++ b/skeleton/controller/mcp_controller.php.twig @@ -75,7 +75,7 @@ class mcp_controller // Set output variables for display in the template $this->template->assign_vars([ 'S_ERROR' => $s_errors, - 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', + 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', 'U_MCP_ACTION' => $this->u_action, ]); diff --git a/skeleton/controller/ucp_controller.php.twig b/skeleton/controller/ucp_controller.php.twig index 5109e53..cac520b 100644 --- a/skeleton/controller/ucp_controller.php.twig +++ b/skeleton/controller/ucp_controller.php.twig @@ -96,7 +96,7 @@ class ucp_controller // Option settings have been updated // Confirm this to the user and provide (automated) link back to previous page meta_refresh(3, $this->u_action); - $message = $this->{{ LANGUAGE.object }}->lang('UCP_{{ EXTENSION.extension_name|upper }}_SAVED') . '

' . $this->{{ LANGUAGE.object }}->lang('RETURN_UCP', '', ''); + $message = $this->{{ LANGUAGE.object }}->lang('UCP_{{ EXTENSION.extension_name|upper }}_SAVED') . '

' . $this->{{ LANGUAGE.object }}->lang('RETURN_UCP', '', ''); trigger_error($message); } } @@ -106,7 +106,7 @@ class ucp_controller // Set output variables for display in the template $this->template->assign_vars([ 'S_ERROR' => $s_errors, - 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', + 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', 'U_UCP_ACTION' => $this->u_action, diff --git a/skeleton/event/main_listener.php.twig b/skeleton/event/main_listener.php.twig index 3982fcc..8acb090 100644 --- a/skeleton/event/main_listener.php.twig +++ b/skeleton/event/main_listener.php.twig @@ -20,6 +20,11 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; */ class main_listener implements EventSubscriberInterface { + /** + * Map phpBB core events to the listener methods that should handle those events + * + * @return array + */ public static function getSubscribedEvents() { return [ @@ -34,7 +39,7 @@ class main_listener implements EventSubscriberInterface 'core.display_forums_modify_template_vars' => 'display_forums_modify_template_vars', {% endif %} {% if COMPONENT.permissions %} - 'core.permissions' => 'add_permissions', + 'core.permissions' => 'add_permissions', {% endif %} ]; } diff --git a/skeleton/migrations/install_sample_data.php.twig b/skeleton/migrations/install_sample_data.php.twig index 2de1f1a..50b9e2b 100644 --- a/skeleton/migrations/install_sample_data.php.twig +++ b/skeleton/migrations/install_sample_data.php.twig @@ -27,7 +27,7 @@ class install_sample_data extends \phpbb\db\migration\migration /** * Add, update or delete data stored in the database during extension installation. * - * https://area51.phpbb.com/docs/dev/3.2.x/migrations/data_changes.html + * https://area51.phpbb.com/docs/dev/3.3.x/migrations/data_changes.html {% if COMPONENT.migration %} * config.add: Add config data. * config.update: Update config data. @@ -99,7 +99,7 @@ class install_sample_data extends \phpbb\db\migration\migration * and only needs to be used to perform custom un-installation changes, such as to revert * changes made by custom functions called in update_data. * - * https://area51.phpbb.com/docs/dev/3.2.x/migrations/data_changes.html + * https://area51.phpbb.com/docs/dev/3.3.x/migrations/data_changes.html * config.add: Add config data. * config.update: Update config data. * config.remove: Remove config. diff --git a/skeleton/migrations/install_sample_schema.php.twig b/skeleton/migrations/install_sample_schema.php.twig index 96f3c35..73158f8 100644 --- a/skeleton/migrations/install_sample_schema.php.twig +++ b/skeleton/migrations/install_sample_schema.php.twig @@ -25,7 +25,7 @@ class install_sample_schema extends \phpbb\db\migration\migration /** * Update database schema. * - * https://area51.phpbb.com/docs/dev/3.2.x/migrations/schema_changes.html + * https://area51.phpbb.com/docs/dev/3.3.x/migrations/schema_changes.html * add_tables: Add tables * drop_tables: Drop tables * add_columns: Add columns to a table @@ -69,7 +69,7 @@ class install_sample_schema extends \phpbb\db\migration\migration * Revert database schema changes. This method is almost always required * to revert the changes made above by update_schema. * - * https://area51.phpbb.com/docs/dev/3.2.x/migrations/schema_changes.html + * https://area51.phpbb.com/docs/dev/3.3.x/migrations/schema_changes.html * add_tables: Add tables * drop_tables: Drop tables * add_columns: Add columns to a table diff --git a/skeleton/styles/prosilver/template/mcp_demo_body.html.twig b/skeleton/styles/prosilver/template/mcp_demo_body.html.twig index 3606168..41d74ea 100644 --- a/skeleton/styles/prosilver/template/mcp_demo_body.html.twig +++ b/skeleton/styles/prosilver/template/mcp_demo_body.html.twig @@ -13,15 +13,15 @@
-
+
-   - +   + {{ '{{' }} S_FORM_TOKEN }}
diff --git a/skeleton/styles/prosilver/template/ucp_demo_body.html.twig b/skeleton/styles/prosilver/template/ucp_demo_body.html.twig index 0abebdd..1e62cbc 100644 --- a/skeleton/styles/prosilver/template/ucp_demo_body.html.twig +++ b/skeleton/styles/prosilver/template/ucp_demo_body.html.twig @@ -12,9 +12,11 @@ {{ '{' }}% endif %}
-

{{ '{{' }} lang('UCP_{{ EXTENSION.extension_name|upper }}_USER_EXPLAIN') }}
-
-
+

{{ '{{' }} lang('UCP_{{ EXTENSION.extension_name|upper }}_USER_EXPLAIN') }}
+
+ + +
@@ -22,8 +24,10 @@
 
-
  -
+
+   + +
{{ '{{' }} S_HIDDEN_FIELDS }} {{ '{{' }} S_FORM_TOKEN }} diff --git a/skeleton/tests/controller/main_test.php.twig b/skeleton/tests/controller/main_test.php.twig index 68f7e3a..c397eb7 100644 --- a/skeleton/tests/controller/main_test.php.twig +++ b/skeleton/tests/controller/main_test.php.twig @@ -55,7 +55,7 @@ class main_test extends \phpbb_test_case ->getMock(); // Set the expected output of the controller_helper->render() method - $controller_helper->expects(self::once()) + $controller_helper->expects($this->once()) ->method('render') ->willReturnCallback(function ($template_file, $page_title = '', $status_code = 200, $display_online_list = false) { return new \Symfony\Component\HttpFoundation\Response($template_file, $status_code); @@ -70,8 +70,8 @@ class main_test extends \phpbb_test_case ); $response = $controller->handle('test'); - self::assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); - self::assertEquals($status_code, $response->getStatusCode()); - self::assertEquals($page_content, $response->getContent()); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); + $this->assertEquals($status_code, $response->getStatusCode()); + $this->assertEquals($page_content, $response->getContent()); } } diff --git a/skeleton/tests/dbal/simple_test.php.twig b/skeleton/tests/dbal/simple_test.php.twig index f6406a5..d34287e 100644 --- a/skeleton/tests/dbal/simple_test.php.twig +++ b/skeleton/tests/dbal/simple_test.php.twig @@ -55,7 +55,7 @@ class simple_test extends \phpbb_database_test_case $db_tools = $factory->get($this->db); } - self::assertTrue($db_tools->sql_column_exists(USERS_TABLE, 'user_{{ EXTENSION.extension_name|lower }}'), 'Asserting that column "user_{{ EXTENSION.extension_name|lower }}" exists'); - self::assertFalse($db_tools->sql_column_exists(USERS_TABLE, 'user_{{ EXTENSION.extension_name|lower }}_void'), 'Asserting that column "user_{{ EXTENSION.extension_name|lower }}_void" does not exist'); + $this->assertTrue($db_tools->sql_column_exists(USERS_TABLE, 'user_{{ EXTENSION.extension_name|lower }}'), 'Asserting that column "user_{{ EXTENSION.extension_name|lower }}" exists'); + $this->assertFalse($db_tools->sql_column_exists(USERS_TABLE, 'user_{{ EXTENSION.extension_name|lower }}_void'), 'Asserting that column "user_{{ EXTENSION.extension_name|lower }}_void" does not exist'); } } diff --git a/skeleton/tests/functional/view_test.php.twig b/skeleton/tests/functional/view_test.php.twig index e39629c..fe4ef38 100644 --- a/skeleton/tests/functional/view_test.php.twig +++ b/skeleton/tests/functional/view_test.php.twig @@ -30,11 +30,11 @@ class view_test extends \phpbb_functional_test_case public function test_view_foo() { $crawler = self::request('GET', 'app.php/demo/foo'); - self::assertStringContainsString('foo', $crawler->filter('h2')->text()); + $this->assertStringContainsString('foo', $crawler->filter('h2')->text()); $this->add_lang_ext('{{ EXTENSION.vendor_name }}/{{ EXTENSION.extension_name }}', 'common'); - self::assertStringContainsString($this->lang('{{ EXTENSION.extension_name|upper }}_HELLO', 'foo'), $crawler->filter('h2')->text()); - self::assertStringNotContainsString($this->lang('{{ EXTENSION.extension_name|upper }}_GOODBYE', 'foo'), $crawler->filter('h2')->text()); + $this->assertStringContainsString($this->lang('{{ EXTENSION.extension_name|upper }}_HELLO', 'foo'), $crawler->filter('h2')->text()); + $this->assertStringNotContainsString($this->lang('{{ EXTENSION.extension_name|upper }}_GOODBYE', 'foo'), $crawler->filter('h2')->text()); $this->assertNotContainsLang('ACP_{{ EXTENSION.extension_name|upper }}_GOODBYE', $crawler->filter('h2')->text()); } @@ -46,7 +46,7 @@ class view_test extends \phpbb_functional_test_case public function test_view_bar() { $crawler = self::request('GET', 'app.php/demo/bar'); - self::assertStringNotContainsString('foo', $crawler->filter('h2')->text()); - self::assertStringContainsString('bar', $crawler->filter('h2')->text()); + $this->assertStringNotContainsString('foo', $crawler->filter('h2')->text()); + $this->assertStringContainsString('bar', $crawler->filter('h2')->text()); } } diff --git a/styles/prosilver/template/skeleton_body.html b/styles/prosilver/template/skeleton_body.html index cb85f62..ee42081 100644 --- a/styles/prosilver/template/skeleton_body.html +++ b/styles/prosilver/template/skeleton_body.html @@ -30,8 +30,8 @@

{{ lang('SKELETON_TITLE_EXTENSION_INFO') }}

-
{% if extension.DESC_EXPLAIN %}
{{ extension.DESC_EXPLAIN }}{% endif %}
-
+
{% if extension.DESC_EXPLAIN %}
{{ extension.DESC_EXPLAIN }}{% endif %}
+
@@ -52,20 +52,20 @@

{{ lang('SKELETON_TITLE_AUTHOR_INFO') }}

-
{% if author.DESC_EXPLAIN %}
{{ author.DESC_EXPLAIN }}{% endif %}
-
+
{% if author.DESC_EXPLAIN %}
{{ author.DESC_EXPLAIN }}{% endif %}
+
{% if loop.index is divisible by(4) and not loop.last %} -
+
{% endif %} {% endfor %}
- + @@ -81,8 +81,8 @@

{{ lang('SKELETON_TITLE_REQUIREMENT_INFO') }}

-
{% if requirement.DESC_EXPLAIN %}
{{ requirement.DESC_EXPLAIN }}{% endif %}
-
+
{% if requirement.DESC_EXPLAIN %}
{{ requirement.DESC_EXPLAIN }}{% endif %}
+
@@ -106,7 +106,7 @@

{{ lang('SKELETON_COMPONENT_GROUP_' ~ group) }}<
@@ -125,7 +125,7 @@

{{ lang('SKELETON_COMPONENT_GROUP_' ~ group) }}<
{{ S_HIDDEN_FIELDS }} - +

diff --git a/tests/console/create_test.php b/tests/console/create_test.php index 37bed9f..feb06c0 100644 --- a/tests/console/create_test.php +++ b/tests/console/create_test.php @@ -50,7 +50,7 @@ public function setUp(): void ->getMock(); $this->language->method('lang') - ->will($this->returnArgument(0)); + ->willReturnArgument(0); $this->user = $this->user = $this->getMockBuilder('\phpbb\user') ->disableOriginalConstructor() @@ -62,7 +62,7 @@ public function setUp(): void ->disableOriginalConstructor() ->getMock(); - $this->packager->expects(self::atMost(1)) + $this->packager->expects($this->atMost(1)) ->method('get_composer_dialog_values') ->willReturn([ 'author' => ['author_name' => null], @@ -70,7 +70,7 @@ public function setUp(): void 'requirements' => ['php_version' => '>=5.4'], ]); - $this->packager->expects(self::atMost(1)) + $this->packager->expects($this->atMost(1)) ->method('get_component_dialog_values') ->willReturn([ 'phplistener' => [ diff --git a/tests/controller/main_test.php b/tests/controller/main_test.php index e42469a..cb804f8 100644 --- a/tests/controller/main_test.php +++ b/tests/controller/main_test.php @@ -132,16 +132,16 @@ public function test_handle($status_code, $page_content) $this->user->data['is_bot'] = false; $this->language->method('lang') - ->will(self::returnArgument(0)); + ->willReturnArgument(0); $this->language->method('is_set') ->willReturn(true); - $this->request->expects(self::once()) + $this->request->expects($this->once()) ->method('is_set_post') ->willReturn(false); $this->request->method('variable') - ->with(self::anything()) + ->with($this->anything()) ->willReturnMap([ ['vendor_name', '', true, \phpbb\request\request_interface::REQUEST, 'foo'], ['author_name', [''], true, \phpbb\request\request_interface::REQUEST, ['bar']], @@ -150,13 +150,13 @@ public function test_handle($status_code, $page_content) ['component_phplistener', false, false, \phpbb\request\request_interface::REQUEST, true], ]); - $this->controller_helper->expects(self::once()) + $this->controller_helper->expects($this->once()) ->method('render') ->willReturnCallback(function ($template_file, $page_title = '', $status_code = 200) { return new \Symfony\Component\HttpFoundation\Response($template_file, $status_code); }); - $this->template->expects(self::atLeastOnce()) + $this->template->expects($this->atLeastOnce()) ->method('assign_block_vars') ->withConsecutive( ['extension', [ @@ -254,9 +254,9 @@ public function test_handle($status_code, $page_content) $response = $this->get_controller($this->packager)->handle(); - self::assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); - self::assertEquals($status_code, $response->getStatusCode()); - self::assertEquals($page_content, $response->getContent()); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); + $this->assertEquals($status_code, $response->getStatusCode()); + $this->assertEquals($page_content, $response->getContent()); } /** @@ -276,7 +276,7 @@ public function test_submit_success() { $this->user->data['is_bot'] = false; - $this->request->expects(self::once()) + $this->request->expects($this->once()) ->method('is_set_post') ->willReturn(true); @@ -289,7 +289,7 @@ public function test_submit_success() ['component_githubactions', true, false, \phpbb\request\request_interface::REQUEST, true], ]); - $this->packager_mock->expects(self::once()) + $this->packager_mock->expects($this->once()) ->method('get_composer_dialog_values') ->willReturn([ 'author' => ['author_name' => null], @@ -297,7 +297,7 @@ public function test_submit_success() 'requirements' => ['php_version' => '>=5.4'], ]); - $this->packager_mock->expects(self::once()) + $this->packager_mock->expects($this->once()) ->method('get_component_dialog_values') ->willReturn([ 'phplistener' => [ @@ -323,27 +323,27 @@ public function test_submit_success() $response = $this->get_controller($this->packager_mock)->handle(); - self::assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); } public function test_submit_exception() { $this->user->data['is_bot'] = false; - $this->request->expects(self::once()) + $this->request->expects($this->once()) ->method('is_set_post') ->with('submit') ->willReturn(true); $this->request->method('variable') - ->with(self::anything()) + ->with($this->anything()) ->willReturnMap([ ['author_name', [''], true, \phpbb\request\request_interface::REQUEST, ['']], ['vendor_name', '', true, \phpbb\request\request_interface::REQUEST, 'foo_vendor'], ['php_version', '>=5.4', true, \phpbb\request\request_interface::REQUEST, '>=5.4'], ]); - $this->packager_mock->expects(self::atLeastOnce()) + $this->packager_mock->expects($this->atLeastOnce()) ->method('get_composer_dialog_values') ->willReturn([ 'author' => ['author_name' => null], @@ -351,7 +351,7 @@ public function test_submit_exception() 'requirements' => ['php_version' => '>=5.4'], ]); - $this->packager_mock->expects(self::atLeastOnce()) + $this->packager_mock->expects($this->atLeastOnce()) ->method('get_component_dialog_values') ->willReturn([ 'phplistener' => [ @@ -362,7 +362,7 @@ public function test_submit_exception() ], ]); - $this->validator->expects(self::once()) + $this->validator->expects($this->once()) ->method('validate_vendor_name') ->with('foo_vendor') ->willThrowException(new runtime_exception('SKELETON_INVALID_VENDOR_NAME')); diff --git a/tests/event_listener_test.php b/tests/event_listener_test.php index d8c8fa9..7d6a0a5 100644 --- a/tests/event_listener_test.php +++ b/tests/event_listener_test.php @@ -41,7 +41,7 @@ public function setUp(): void public function test_construct() { - self::assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); + $this->assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); } /** @@ -49,7 +49,7 @@ public function test_construct() */ public function test_getSubscribedEvents() { - self::assertEquals(array( + $this->assertEquals(array( 'core.user_setup', 'core.page_header', ), array_keys(\phpbb\skeleton\event\main_listener::getSubscribedEvents())); @@ -65,16 +65,16 @@ public function test_load_language_on_setup() $event_data_after = $dispatcher->trigger_event('core.user_setup', compact($event_data)); extract($event_data_after, EXTR_OVERWRITE); - self::assertEquals([['ext_name' => 'phpbb/skeleton', 'lang_set' => 'common']], $lang_set_ext); + $this->assertEquals([['ext_name' => 'phpbb/skeleton', 'lang_set' => 'common']], $lang_set_ext); } public function test_add_page_header_link() { - $this->controller_helper->expects(self::once()) + $this->controller_helper->expects($this->once()) ->method('route') ->willReturnArgument(0); - $this->template->expects(self::once()) + $this->template->expects($this->once()) ->method('assign_var') ->with('U_PHPBB_SKELETON_EXT', 'phpbb_skeleton_controller'); diff --git a/tests/functional/view_test.php b/tests/functional/view_test.php index 2682070..cef574d 100644 --- a/tests/functional/view_test.php +++ b/tests/functional/view_test.php @@ -30,6 +30,6 @@ public function test_view_skeleton() { $this->add_lang_ext('phpbb/skeleton', 'common'); $crawler = self::request('GET', 'app.php/skeleton'); - self::assertStringContainsString($this->lang('PHPBB_CREATE_SKELETON_EXT'), $crawler->filter('h2')->text()); + $this->assertStringContainsString($this->lang('PHPBB_CREATE_SKELETON_EXT'), $crawler->filter('h2')->text()); } } diff --git a/tests/helper/packager_test.php b/tests/helper/packager_test.php index d9b87e5..7ffa987 100644 --- a/tests/helper/packager_test.php +++ b/tests/helper/packager_test.php @@ -132,12 +132,66 @@ public function test_create_zip_creates_zip_file() // Clean up or further assertions here } - public function test_get_language_version_data_returns_expected() + /** + * @dataProvider provide_language_version_data + */ + public function test_get_language_version_data_returns_expected($phpbb_version, $expected) { - $data_31 = $this->invokeMethod($this->packager, 'get_language_version_data', [true]); - $data_32 = $this->invokeMethod($this->packager, 'get_language_version_data', [false]); - $this->assertArrayHasKey('class', $data_31); - $this->assertArrayHasKey('class', $data_32); + $data = [ + 'requirements' => [ + 'phpbb_version_min' => $phpbb_version + ] + ]; + + $result = $this->invokeMethod($this->packager, 'get_language_version_data', [$data]); + + $this->assertSame($expected['class'], $result['class']); + $this->assertSame($expected['object'], $result['object']); + $this->assertSame($expected['function'], $result['function']); + $this->assertSame($expected['indent']['class'], $result['indent']['class']); + $this->assertSame($expected['indent']['object'], $result['indent']['object']); + } + + public function provide_language_version_data() + { + return [ + '3.1 version' => [ + '3.1.0', + [ + 'class' => '\phpbb\user', + 'object' => 'user', + 'function' => 'add_lang_ext', + 'indent' => [ + 'class' => "\t\t\t", + 'object' => "\t" + ] + ] + ], + '3.2 version' => [ + '3.2.0', + [ + 'class' => '\phpbb\language\language', + 'object' => 'language', + 'function' => 'add_lang', + 'indent' => [ + 'class' => '', + 'object' => '' + ] + ] + ], + 'null version' => [ + null, + [ + 'class' => '\phpbb\language\language', + 'object' => 'language', + 'function' => 'add_lang', + 'indent' => [ + 'class' => '', + 'object' => '' + ] + ] + ] + ]; } public function test_get_template_engine_returns_twig_instance() diff --git a/tests/helper/validator_test.php b/tests/helper/validator_test.php index 5c4e74e..b06fa1b 100644 --- a/tests/helper/validator_test.php +++ b/tests/helper/validator_test.php @@ -119,7 +119,7 @@ public function valid_data(): array */ public function test_validator_valid($validator, $value) { - self::assertEquals($value, call_user_func([$this->validator, "validate_{$validator}"], $value)); + $this->assertEquals($value, call_user_func([$this->validator, "validate_{$validator}"], $value)); } public function invalid_data(): array