Skip to content

Commit cf654ca

Browse files
committed
Test Folders Refactoring
1 parent e047a6c commit cf654ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+207
-261
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ package-lock.json
44
phpunit.xml.bak
55
.idea/
66
.phpunit.result.cache
7-
coverage/
7+
tests/coverage/
8+
tests/playwright-results/
9+
tests/playwright-report/
810
node_modules/
911
vendor/
10-
/test-results/
11-
/playwright-report/
1212
/blob-report/
1313
/playwright/.cache/

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
},
2828
"autoload-dev": {
2929
"psr-4": {
30-
"lloc\\MslsTests\\": "tests/"
30+
"lloc\\MslsTests\\": "tests/phpunit/"
3131
}
3232
},
3333
"scripts": {
3434
"test": "vendor/bin/phpunit",
35-
"coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html coverage",
35+
"coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",
3636
"analyze": "vendor/bin/phpstan analyze",
3737
"php74": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4",
3838
"php81": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.1",

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
<const name="WP_DEBUG" value="true"/>
1212
</php>
1313
<testsuite name="Internal tests">
14-
<directory prefix="Test" suffix=".php">./tests/</directory>
14+
<directory prefix="Test" suffix=".php">./tests/phpunit</directory>
1515
</testsuite>
1616
</phpunit>

playwright.config.ts

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,23 @@
11
import { defineConfig, devices } from '@playwright/test';
22

3-
/**
4-
* Read environment variables from file.
5-
* https://github.com/motdotla/dotenv
6-
*/
7-
// require('dotenv').config();
8-
9-
/**
10-
* See https://playwright.dev/docs/test-configuration.
11-
*/
123
export default defineConfig({
13-
testDir: './tests/e2e/',
14-
/* Run tests in files in parallel */
4+
testDir: './tests/playwright/',
5+
outputDir: './tests/playwright-results/',
156
fullyParallel: true,
16-
/* Fail the build on CI if you accidentally left test.only in the source code. */
177
forbidOnly: !!process.env.CI,
18-
/* Retry on CI only */
198
retries: process.env.CI ? 2 : 0,
20-
/* Opt out of parallel tests on CI. */
219
workers: process.env.CI ? 1 : undefined,
22-
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23-
reporter: 'html',
24-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
10+
reporter: [
11+
['list'],
12+
['json', { outputFile: './tests/playwright-report/test-results.json' }]
13+
],
2514
use: {
26-
/* Base URL to use in actions like `await page.goto('/')`. */
27-
// baseURL: 'http://127.0.0.1:3000',
28-
29-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3015
trace: 'on-first-retry',
3116
},
32-
33-
/* Configure projects for major browsers */
3417
projects: [
3518
{
3619
name: 'chromium',
3720
use: { ...devices['Desktop Chrome'] },
3821
},
39-
40-
{
41-
name: 'firefox',
42-
use: { ...devices['Desktop Firefox'] },
43-
},
44-
45-
/* Test against mobile viewports. */
46-
// {
47-
// name: 'Mobile Chrome',
48-
// use: { ...devices['Pixel 5'] },
49-
// },
50-
// {
51-
// name: 'Mobile Safari',
52-
// use: { ...devices['iPhone 12'] },
53-
// },
54-
55-
/* Test against branded browsers. */
56-
// {
57-
// name: 'Microsoft Edge',
58-
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
59-
// },
60-
// {
61-
// name: 'Google Chrome',
62-
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
63-
// },
6422
],
65-
66-
/* Run your local dev server before starting the tests */
67-
// webServer: {
68-
// command: 'npm run start',
69-
// url: 'http://127.0.0.1:3000',
70-
// reuseExistingServer: !process.env.CI,
71-
// },
7223
});

tests/Component/Icon/TestIconPng.php renamed to tests/phpunit/Component/Icon/TestIconPng.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace lloc\MslsTests\Component\Icon;
44

55
use Brain\Monkey\Functions;
6-
use lloc\MslsTests\MslsUnitTestCase;
76
use lloc\Msls\Component\Icon\IconPng;
7+
use lloc\MslsTests\MslsUnitTestCase;
88

99
class TestIconPng extends MslsUnitTestCase {
1010

1111
public function test_get(): void {
12-
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 3 ) . '/' );
12+
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 4 ) . '/' );
1313

1414
$obj = new IconPng();
1515

@@ -18,5 +18,4 @@ public function test_get(): void {
1818
$this->assertEquals( 'catalonia.png', $obj->get( 'ca' ) );
1919
$this->assertEquals( 'ko.png', $obj->get( 'pinko' ) );
2020
}
21-
2221
}

tests/Component/Icon/TestIconSvg.php renamed to tests/phpunit/Component/Icon/TestIconSvg.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace lloc\MslsTests\Component\Icon;
44

55
use Brain\Monkey\Functions;
6-
use lloc\MslsTests\MslsUnitTestCase;
76
use lloc\Msls\Component\Icon\IconSvg;
7+
use lloc\MslsTests\MslsUnitTestCase;
88

99
class TestIconSvg extends MslsUnitTestCase {
1010

1111
public function test_get(): void {
12-
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 3 ) . '/' );
12+
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 4 ) . '/' );
1313

1414
$obj = new IconSvg();
1515

@@ -18,5 +18,4 @@ public function test_get(): void {
1818
$this->assertEquals( 'flag-icon-es-ca', $obj->get( 'ca' ) );
1919
$this->assertEquals( 'flag-icon-ko', $obj->get( 'pinko' ) );
2020
}
21-
2221
}

tests/Map/TestHrefLang.php renamed to tests/phpunit/Map/TestHrefLang.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,36 @@
22

33
namespace lloc\MslsTests\Map;
44

5-
use Brain\Monkey\Functions;
65
use Brain\Monkey\Filters;
7-
8-
use lloc\MslsTests\MslsUnitTestCase;
6+
use Brain\Monkey\Functions;
97
use lloc\Msls\Map\HrefLang;
108
use lloc\Msls\MslsBlog;
119
use lloc\Msls\MslsBlogCollection;
10+
use lloc\MslsTests\MslsUnitTestCase;
1211

1312
class TestHrefLang extends MslsUnitTestCase {
1413

1514
protected function setUp(): void {
1615
parent::setUp();
1716

18-
$map = [
17+
$map = array(
1918
'de_DE' => 'de',
2019
'de_DE_formal' => 'de',
2120
'fr_FR' => 'fr',
2221
'es_ES' => 'es',
2322
'cat' => 'cat',
2423
'en_US' => 'en',
2524
'en_GB' => 'en',
26-
];
25+
);
2726

2827
foreach ( $map as $locale => $alpha2 ) {
2928
$blog = \Mockery::mock( MslsBlog::class );
30-
$blog->shouldReceive( [
31-
'get_alpha2' => $alpha2,
32-
'get_language' => $locale,
33-
] );
29+
$blog->shouldReceive(
30+
array(
31+
'get_alpha2' => $alpha2,
32+
'get_language' => $locale,
33+
)
34+
);
3435

3536
$blogs[] = $blog;
3637
}
@@ -57,5 +58,4 @@ public function test_get_has_filter(): void {
5758

5859
$this->assertEquals( 'en-US', $this->test->get( 'en_US' ) );
5960
}
60-
6161
}

tests/MslsUnitTestCase.php renamed to tests/phpunit/MslsUnitTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace lloc\MslsTests;
44

5-
use PHPUnit\Framework\TestCase;
65
use Brain\Monkey;
76
use Brain\Monkey\Functions;
7+
use PHPUnit\Framework\TestCase;
88

99
class MslsUnitTestCase extends TestCase {
1010

tests/Query/TestTranslatedPostsQuery.php renamed to tests/phpunit/Query/TestTranslatedPostsQuery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace lloc\MslsTests\Query;
44

5-
use lloc\MslsTests\MslsUnitTestCase;
6-
use lloc\Msls\Query\TranslatedPostIdQuery;
75
use lloc\Msls\MslsSqlCacher;
6+
use lloc\Msls\Query\TranslatedPostIdQuery;
7+
use lloc\MslsTests\MslsUnitTestCase;
88

99
class TestTranslatedPostsQuery extends MslsUnitTestCase {
1010

tests/TestMslsAdmin.php renamed to tests/phpunit/TestMslsAdmin.php

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
namespace lloc\MslsTests;
44

55
use Brain\Monkey\Functions;
6-
76
use lloc\Msls\MslsAdmin;
87
use lloc\Msls\MslsBlog;
9-
use lloc\Msls\MslsOptions;
108
use lloc\Msls\MslsBlogCollection;
9+
use lloc\Msls\MslsOptions;
1110

1211
class TestMslsAdmin extends MslsUnitTestCase {
1312

14-
public function get_sut( array $users = [] ): MslsAdmin {
15-
Functions\when( 'get_option' )->justReturn( [] );
13+
public function get_sut( array $users = array() ): MslsAdmin {
14+
Functions\when( 'get_option' )->justReturn( array() );
1615
Functions\when( 'update_option' )->justReturn( true );
1716
Functions\when( 'get_current_blog_id' )->justReturn( 1 );
1817
Functions\when( 'checked' )->justReturn( '' );
@@ -22,7 +21,7 @@ public function get_sut( array $users = [] ): MslsAdmin {
2221

2322
$options = \Mockery::mock( MslsOptions::class );
2423
$options->shouldReceive( 'is_empty' )->andReturns( false );
25-
$options->shouldReceive( 'get_available_languages' )->andReturns( [ 'de_DE', 'it_IT' ] );
24+
$options->shouldReceive( 'get_available_languages' )->andReturns( array( 'de_DE', 'it_IT' ) );
2625
$options->shouldReceive( 'get_icon_type' )->andReturns( 'flag' );
2726

2827
$blog = \Mockery::mock( MslsBlog::class );
@@ -41,12 +40,12 @@ public function get_sut( array $users = [] ): MslsAdmin {
4140

4241
$blogs[] = $blog;
4342
if ( empty( $users ) ) {
44-
$users = [
45-
(object) [
43+
$users = array(
44+
(object) array(
4645
'ID' => 1,
47-
'user_nicename' => 'realloc'
48-
]
49-
];
46+
'user_nicename' => 'realloc',
47+
),
48+
);
5049
}
5150

5251
$collection = \Mockery::mock( MslsBlogCollection::class );
@@ -59,7 +58,7 @@ public function get_sut( array $users = [] ): MslsAdmin {
5958

6059
public function test_has_problems_no_problem(): void {
6160
$options = \Mockery::mock( MslsOptions::class );
62-
$options->shouldReceive( 'get_available_languages' )->andReturns( [ 'de_DE', 'it_IT' ] );
61+
$options->shouldReceive( 'get_available_languages' )->andReturns( array( 'de_DE', 'it_IT' ) );
6362

6463
$collection = \Mockery::mock( MslsBlogCollection::class );
6564
$options->shouldReceive( 'is_empty' )->andReturns( false );
@@ -71,7 +70,7 @@ public function test_has_problems_no_problem(): void {
7170

7271
public function test_has_problems_one_language(): void {
7372
$options = \Mockery::mock( MslsOptions::class );
74-
$options->shouldReceive( 'get_available_languages' )->andReturns( [ 'de_DE', ] );
73+
$options->shouldReceive( 'get_available_languages' )->andReturns( array( 'de_DE' ) );
7574

7675
$collection = \Mockery::mock( MslsBlogCollection::class );
7776
$options->shouldReceive( 'is_empty' )->andReturns( false );
@@ -84,7 +83,7 @@ public function test_has_problems_one_language(): void {
8483
}
8584

8685
public function test_has_problems_is_empty(): void {
87-
Functions\when( 'get_option' )->justReturn( [] );
86+
Functions\when( 'get_option' )->justReturn( array() );
8887
Functions\when( 'get_current_blog_id' )->justReturn( 1 );
8988
Functions\when( 'admin_url' )->justReturn( '' );
9089

@@ -135,10 +134,13 @@ public function test_admin_display(): void {
135134
}
136135

137136
public function test_reference_user(): void {
138-
$users = [];
137+
$users = array();
139138
$too_much = MslsAdmin::MAX_REFERENCE_USERS + 1;
140-
for ( $i = 1; $i <= $too_much; $i ++ ) {
141-
$users[] = (object) [ 'ID' => $i, 'user_nicename' => 'realloc' ];
139+
for ( $i = 1; $i <= $too_much; $i++ ) {
140+
$users[] = (object) array(
141+
'ID' => $i,
142+
'user_nicename' => 'realloc',
143+
);
142144
}
143145

144146
$obj = $this->get_sut( $users );
@@ -289,7 +291,7 @@ function test_rewrite_pallino(): void {
289291
$obj = $this->get_sut();
290292

291293
$post_type = \Mockery::mock( \WP_Post_Type::class );
292-
$post_type->rewrite = [ 'slug' => 'pallino_slug' ];
294+
$post_type->rewrite = array( 'slug' => 'pallino_slug' );
293295

294296
Functions\when( 'get_post_type_object' )->justReturn( $post_type );
295297

@@ -318,17 +320,29 @@ function test_content_priority(): void {
318320
function test_validate(): void {
319321
$obj = $this->get_sut();
320322

321-
$arr = [];
322-
$this->assertEquals( [ 'display' => 0 ], $obj->validate( $arr ) );
323-
$arr = [ 'image_url' => '/test/', 'display' => '1' ];
324-
$this->assertEquals( [ 'image_url' => '/test', 'display' => 1 ], $obj->validate( $arr ) );
323+
$arr = array();
324+
$this->assertEquals( array( 'display' => 0 ), $obj->validate( $arr ) );
325+
$arr = array(
326+
'image_url' => '/test/',
327+
'display' => '1',
328+
);
329+
$this->assertEquals(
330+
array(
331+
'image_url' => '/test',
332+
'display' => 1,
333+
),
334+
$obj->validate( $arr )
335+
);
325336
}
326337

327338
function test_set_blog_language(): void {
328339
$obj = $this->get_sut();
329340

330-
$arr = [ 'abc' => true, 'blog_language' => 'it_IT' ];
331-
$this->assertEquals( [ 'abc' => true ], $obj->set_blog_language( $arr ) );
341+
$arr = array(
342+
'abc' => true,
343+
'blog_language' => 'it_IT',
344+
);
345+
$this->assertEquals( array( 'abc' => true ), $obj->set_blog_language( $arr ) );
332346
}
333347

334348
function test_render(): void {
@@ -370,7 +384,10 @@ function test_advanced_section(): void {
370384
function test_rewrites_section(): void {
371385
$obj = $this->get_sut();
372386

373-
foreach ( [ 'post' => 'Post', 'page' => 'Page' ] as $name => $label ) {
387+
foreach ( array(
388+
'post' => 'Post',
389+
'page' => 'Page',
390+
) as $name => $label ) {
374391
$post_type = \Mockery::mock( \WP_Post_Type::class );
375392
$post_type->name = $name;
376393
$post_type->label = $label;
@@ -383,5 +400,4 @@ function test_rewrites_section(): void {
383400

384401
$this->assertEquals( 2, $obj->rewrites_section() );
385402
}
386-
387403
}

0 commit comments

Comments
 (0)