|
| 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 | +} |
0 commit comments