|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace n5s\PageForCustomPostType\Tests\Integration; |
| 6 | + |
| 7 | +use n5s\PageForCustomPostType\Lifecycle\Migrator; |
| 8 | +use n5s\PageForCustomPostType\Tests\Fixtures\TestCase; |
| 9 | + |
| 10 | +class MigratorTest extends TestCase |
| 11 | +{ |
| 12 | + private Migrator $migrator; |
| 13 | + |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + $this->migrator = new Migrator(); |
| 18 | + } |
| 19 | + |
| 20 | + public function testFreshInstallSetsDbVersionWithoutTouchingUseSlug(): void |
| 21 | + { |
| 22 | + delete_option('pfcpt_db_version'); |
| 23 | + delete_option('pages_for_custom_post_type'); |
| 24 | + delete_option('page_for_book_use_slug'); |
| 25 | + |
| 26 | + $this->migrator->migrate(); |
| 27 | + |
| 28 | + $this->assertNotEmpty(get_option('pfcpt_db_version')); |
| 29 | + $this->assertFalse(get_option('page_for_book_use_slug')); |
| 30 | + } |
| 31 | + |
| 32 | + public function testUpgradeFromPreUseSlugEnablesUseSlugForAssignedCPTs(): void |
| 33 | + { |
| 34 | + $this->createFixtures(); |
| 35 | + delete_option('pfcpt_db_version'); |
| 36 | + delete_option('page_for_' . self::BOOK_POST_TYPE . '_use_slug'); |
| 37 | + delete_option('page_for_' . self::BIKE_POST_TYPE . '_use_slug'); |
| 38 | + |
| 39 | + $this->migrator->migrate(); |
| 40 | + |
| 41 | + $this->assertEquals('1', get_option('page_for_' . self::BOOK_POST_TYPE . '_use_slug')); |
| 42 | + $this->assertEquals('1', get_option('page_for_' . self::BIKE_POST_TYPE . '_use_slug')); |
| 43 | + $this->assertNotEmpty(get_option('pfcpt_db_version')); |
| 44 | + } |
| 45 | + |
| 46 | + public function testMigrationDoesNotOverwriteExplicitlySetUseSlug(): void |
| 47 | + { |
| 48 | + $this->createFixtures(); |
| 49 | + delete_option('pfcpt_db_version'); |
| 50 | + update_option('page_for_' . self::BOOK_POST_TYPE . '_use_slug', '0'); |
| 51 | + |
| 52 | + $this->migrator->migrate(); |
| 53 | + |
| 54 | + $this->assertEquals('0', get_option('page_for_' . self::BOOK_POST_TYPE . '_use_slug')); |
| 55 | + } |
| 56 | + |
| 57 | + public function testMigrationIsIdempotent(): void |
| 58 | + { |
| 59 | + $this->createFixtures(); |
| 60 | + update_option('pfcpt_db_version', '0.6.0'); |
| 61 | + delete_option('page_for_' . self::BOOK_POST_TYPE . '_use_slug'); |
| 62 | + |
| 63 | + $this->migrator->migrate(); |
| 64 | + |
| 65 | + $this->assertFalse(get_option('page_for_' . self::BOOK_POST_TYPE . '_use_slug')); |
| 66 | + } |
| 67 | +} |
0 commit comments