PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.0.12
Responsive Menu – Create Mobile-Friendly Menu v3.0.12
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / tests / app / Database / MigrationTest.php

MigrationTest.php in Responsive Menu – Create Mobile-Friendly Menu 3.0.12, at tests/app/Database/MigrationTest.php

115 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use PHPUnit\Framework\TestCase;
4 use ResponsiveMenu\Collections\OptionsCollection;
5 use ResponsiveMenu\Database\Migration;
6 use ResponsiveMenu\Models\Option;
7
8 class MigrationTest extends TestCase {
9
10 public function setUp() {
11 $this->database = $this->createMock('ResponsiveMenu\Database\WpDatabase');
12 $this->service = $this->createMock('ResponsiveMenu\Services\OptionService');
13 $this->defaults = ['default_one' => 1, 'default_two' => 'string', 'default_three' => 4.5, 'default_four' => 'new'];
14 $this->current_version = '3.0.8';
15 $this->old_version = '3.0.7';
16 $this->old_options = ['default_one' => 4, 'default_two' => 'old string', 'default_three' => 4.5, 'RM' => 'old RM value', 'RMDepth' => 'old RMDepth value'];
17
18 $this->base_migration = new Migration($this->database, $this->service, $this->defaults, $this->current_version, $this->old_version, $this->old_options);
19
20 $this->options_collection = new OptionsCollection;
21 $this->options_collection->add(new Option('default_one', 5));
22 $this->options_collection->add(new Option('default_two', 'string'));
23 $this->options_collection->add(new Option('default_three', 7.5));
24
25 /*
26 * Mock the repository all() function to return controlled options collection
27 */
28 $service_options = new OptionsCollection;
29 $service_options->add(new Option('default_one', 5));
30 $service_options->add(new Option('default_two', 'new option'));
31 $service_options->add(new Option('to_delete', 'delete me!'));
32 $service_options->add(new Option('to_delete_also', 'delete me too!'));
33 $this->service->method('all')->willReturn($service_options);
34
35 }
36
37 public function testVersionCompareNeedsUpdate() {
38 $this->assertTrue($this->base_migration->needsUpdate());
39 }
40
41 public function testVersionCompareDoesntNeedUpdate() {
42 $migration = new Migration($this->database, $this->service, $this->defaults, $this->current_version, '3.0.9', $this->old_options);
43 $this->assertFalse($migration->needsUpdate());
44 }
45
46 public function testVersionCompareNeedUpdateWithDoubleEndPoint() {
47 $migration = new Migration($this->database, $this->service, $this->defaults, '3.0.10', $this->old_version, $this->old_options);
48 $this->assertTrue($migration->needsUpdate());
49 }
50
51 public function testVersionCompareDoesntNeedUpdateWithDoubleEndPoint() {
52 $migration = new Migration($this->database, $this->service, $this->defaults, '3.0.10', '3.1.0', $this->old_options);
53 $this->assertFalse($migration->needsUpdate());
54 }
55
56 public function testVersionCompareDoesNeedUpdateWithTenComparedToOne() {
57 $migration = new Migration($this->database, $this->service, $this->defaults, '3.0.10', '3.0.1', $this->old_options);
58 $this->assertTrue($migration->needsUpdate());
59 }
60
61 public function testVersionCompareDoesntNeedUpdateWithOneComparedToTen() {
62 $migration = new Migration($this->database, $this->service, $this->defaults, '3.0.1', '3.0.10', $this->old_options);
63 $this->assertFalse($migration->needsUpdate());
64 }
65
66 public function testVersionCompareDoesntNeedUpdateWithDoubleEndPointWithVersionHigher() {
67 $migration = new Migration($this->database, $this->service, $this->defaults, '3.0.10', '3.2.0', $this->old_options);
68 $this->assertFalse($migration->needsUpdate());
69 }
70
71 public function testVersionCompareDoesNeedUpdateWithDoubleEndPointWithVersionHigher() {
72 $migration = new Migration($this->database, $this->service, $this->defaults, '3.2.0', '3.0.10', $this->old_options);
73 $this->assertTrue($migration->needsUpdate());
74 }
75
76 public function testNewOptionsReturnedAreCorrect() {
77 $this->assertSame(['default_four' => 'new'], $this->base_migration->getNewOptions($this->options_collection));
78 }
79
80 public function testIsVersion3CheckReturnsFalse() {
81 $migration = new Migration($this->database, $this->service, $this->defaults, $this->current_version, '2.8.0', $this->old_options);
82 $this->assertFalse($migration->isVersion3());
83 }
84
85 public function testIsVersion3CheckReturnsTrue() {
86 $this->assertTrue($this->base_migration->isVersion3());
87 }
88
89 public function testDeletableOptions() {
90 $this->assertSame(['to_delete' => 'to_delete', 'to_delete_also' => 'to_delete_also'], $this->base_migration->getOptionsToDelete());
91 }
92
93 public function testOptionsToMigrate() {
94 $this->assertSame(['menu_to_use' => 'old RM value', 'menu_depth' => 'old RMDepth value'], $this->base_migration->getMigratedOptions());
95 }
96
97 public function testSetup() {
98 $this->database->method('createTable')->willReturn(true);
99 $migration = new Migration($this->database, $this->service, $this->defaults, '3.0.10', '2.8.9', $this->old_options);
100 $this->assertEquals(null, $migration->setUp());
101 }
102
103 public function testSynchronise() {
104 $this->assertEquals(null, $this->base_migration->synchronise());
105 }
106
107 public function testAddNewOptionsEmpty() {
108 $service = $this->createMock('ResponsiveMenu\Services\OptionService');
109 $service->method('all')->willReturn(new ResponsiveMenu\Collections\OptionsCollection);
110 $migration = new Migration($this->database, $service, $this->defaults, $this->current_version, $this->old_version, $this->old_options);
111 $this->assertEquals(null, $migration->addNewOptions());
112 }
113
114 }
115