Skip to content

Commit a41b181

Browse files
committed
tests
1 parent f726c25 commit a41b181

9 files changed

Lines changed: 1309 additions & 0 deletions

.github/workflows/tests.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main, master, develop]
6+
pull_request:
7+
branches: [main, master, develop]
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
php: [8.2, 8.3, 8.4]
17+
18+
name: PHP ${{ matrix.php }}
19+
20+
steps:
21+
- name: Setup PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php }}
25+
extensions: mbstring, intl, pdo_sqlite
26+
coverage: none
27+
ini-values: memory_limit=512M
28+
29+
- name: Install October CMS
30+
run: |
31+
composer create-project october/october october --no-interaction --no-progress
32+
33+
- name: Configure environment
34+
run: |
35+
cd october
36+
mkdir -p database && touch database/database.sqlite
37+
sed -i 's/DB_CONNECTION=.*/DB_CONNECTION=sqlite/' .env
38+
sed -i 's|DB_DATABASE=.*|DB_DATABASE=database/database.sqlite|' .env
39+
40+
- name: Migrate core tables
41+
run: |
42+
cd october
43+
php artisan october:migrate --no-interaction
44+
45+
- name: Checkout plugin
46+
uses: actions/checkout@v4
47+
with:
48+
path: october/plugins/october/test
49+
50+
- name: Migrate plugin
51+
run: |
52+
cd october
53+
php artisan october:migrate --no-interaction
54+
55+
- name: Run tests
56+
run: |
57+
cd october
58+
php vendor/bin/phpunit --configuration plugins/october/test/phpunit.xml

tests/DatabaseMigrationTest.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php namespace October\Test\Tests;
2+
3+
use Schema;
4+
use PluginTestCase;
5+
6+
/**
7+
* DatabaseMigrationTest validates plugin migrations create all expected tables
8+
*/
9+
class DatabaseMigrationTest extends PluginTestCase
10+
{
11+
/**
12+
* setUp
13+
*/
14+
public function setUp(): void
15+
{
16+
parent::setUp();
17+
18+
$this->migrateDatabase();
19+
}
20+
21+
/**
22+
* @dataProvider tableProvider
23+
*/
24+
public function testTableExists(string $tableName)
25+
{
26+
$this->assertTrue(
27+
Schema::hasTable($tableName),
28+
"Table '{$tableName}' should exist after migration"
29+
);
30+
}
31+
32+
/**
33+
* tableProvider returns all expected plugin tables
34+
*/
35+
public static function tableProvider(): array
36+
{
37+
return [
38+
'people' => ['october_test_people'],
39+
'phones' => ['october_test_phones'],
40+
'posts' => ['october_test_posts'],
41+
'comments' => ['october_test_comments'],
42+
'tags' => ['october_test_tags'],
43+
'posts_tags' => ['october_test_posts_tags'],
44+
'users' => ['october_test_users'],
45+
'roles' => ['october_test_roles'],
46+
'users_roles' => ['october_test_users_roles'],
47+
'countries' => ['october_test_countries'],
48+
'cities' => ['october_test_cities'],
49+
'locations' => ['october_test_locations'],
50+
'reviews' => ['october_test_reviews'],
51+
'plugins' => ['october_test_plugins'],
52+
'themes' => ['october_test_themes'],
53+
'members' => ['october_test_members'],
54+
'categories' => ['october_test_categories'],
55+
'channels' => ['october_test_channels'],
56+
'related_channels' => ['october_test_related_channels'],
57+
'galleries' => ['october_test_galleries'],
58+
'gallery_entity' => ['october_test_gallery_entity'],
59+
'pages' => ['october_test_pages'],
60+
'layouts' => ['october_test_layouts'],
61+
'products' => ['october_test_products'],
62+
'product_categories' => ['october_test_product_categories'],
63+
'products_categories' => ['october_test_products_categories'],
64+
'products_locations' => ['october_test_products_locations'],
65+
'meta' => ['october_test_meta'],
66+
'attributes' => ['october_test_attributes'],
67+
'countries_types' => ['october_test_countries_types'],
68+
'repeater_items' => ['october_test_repeater_items'],
69+
];
70+
}
71+
72+
/**
73+
* testPeopleTableHasExpectedColumns
74+
*/
75+
public function testPeopleTableHasExpectedColumns()
76+
{
77+
$this->assertTrue(Schema::hasColumn('october_test_people', 'name'));
78+
$this->assertTrue(Schema::hasColumn('october_test_people', 'preferred_name'));
79+
$this->assertTrue(Schema::hasColumn('october_test_people', 'bio'));
80+
$this->assertTrue(Schema::hasColumn('october_test_people', 'birth'));
81+
}
82+
83+
/**
84+
* testPostsTableHasExpectedColumns
85+
*/
86+
public function testPostsTableHasExpectedColumns()
87+
{
88+
$this->assertTrue(Schema::hasColumn('october_test_posts', 'name'));
89+
$this->assertTrue(Schema::hasColumn('october_test_posts', 'slug'));
90+
$this->assertTrue(Schema::hasColumn('october_test_posts', 'content_html'));
91+
}
92+
93+
/**
94+
* testUsersTableHasExpectedColumns
95+
*/
96+
public function testUsersTableHasExpectedColumns()
97+
{
98+
$this->assertTrue(Schema::hasColumn('october_test_users', 'username'));
99+
$this->assertTrue(Schema::hasColumn('october_test_users', 'security_code'));
100+
}
101+
102+
/**
103+
* testProductsTableHasExpectedColumns
104+
*/
105+
public function testProductsTableHasExpectedColumns()
106+
{
107+
$this->assertTrue(Schema::hasColumn('october_test_products', 'title'));
108+
$this->assertTrue(Schema::hasColumn('october_test_products', 'slug'));
109+
$this->assertTrue(Schema::hasColumn('october_test_products', 'price'));
110+
$this->assertTrue(Schema::hasColumn('october_test_products', 'deleted_at'));
111+
}
112+
}

tests/LangFilesTest.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php namespace October\Test\Tests;
2+
3+
use PluginTestCase;
4+
5+
/**
6+
* LangFilesTest validates language files are well-formed
7+
*/
8+
class LangFilesTest extends PluginTestCase
9+
{
10+
/**
11+
* @dataProvider langJsonProvider
12+
*/
13+
public function testJsonLangFileIsValid($filePath)
14+
{
15+
$content = file_get_contents($filePath);
16+
$decoded = json_decode($content);
17+
18+
$this->assertNotNull(
19+
$decoded,
20+
basename($filePath) . ' contains invalid JSON: ' . json_last_error_msg()
21+
);
22+
23+
$this->assertIsObject(
24+
$decoded,
25+
basename($filePath) . ' should decode to a JSON object'
26+
);
27+
}
28+
29+
/**
30+
* @dataProvider langJsonProvider
31+
*/
32+
public function testJsonLangFileValuesAreStrings($filePath)
33+
{
34+
$content = file_get_contents($filePath);
35+
$decoded = json_decode($content, true);
36+
37+
foreach ($decoded as $key => $value) {
38+
$this->assertIsString(
39+
$value,
40+
basename($filePath) . " key '{$key}' has a non-string value"
41+
);
42+
}
43+
}
44+
45+
/**
46+
* @dataProvider langPhpProvider
47+
*/
48+
public function testPhpLangFileReturnsArray($filePath)
49+
{
50+
$result = include $filePath;
51+
52+
$this->assertIsArray(
53+
$result,
54+
basename(dirname($filePath)) . '/lang.php should return an array'
55+
);
56+
}
57+
58+
/**
59+
* langJsonProvider returns all JSON lang files
60+
*/
61+
public static function langJsonProvider(): array
62+
{
63+
$langPath = __DIR__ . '/../lang';
64+
$files = glob($langPath . '/*.json');
65+
66+
$data = [];
67+
foreach ($files as $file) {
68+
$data[basename($file)] = [$file];
69+
}
70+
71+
return $data;
72+
}
73+
74+
/**
75+
* langPhpProvider returns all PHP lang files
76+
*/
77+
public static function langPhpProvider(): array
78+
{
79+
$langPath = realpath(__DIR__ . '/../lang');
80+
$iterator = new \RecursiveIteratorIterator(
81+
new \RecursiveDirectoryIterator($langPath, \RecursiveDirectoryIterator::SKIP_DOTS)
82+
);
83+
84+
$data = [];
85+
foreach ($iterator as $file) {
86+
if ($file->isFile() && $file->getExtension() === 'php') {
87+
$relativePath = str_replace($langPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
88+
$data[$relativePath] = [$file->getPathname()];
89+
}
90+
}
91+
92+
return $data;
93+
}
94+
}

0 commit comments

Comments
 (0)