Modify unit tests following previous changes

This commit is contained in:
fred
2017-06-07 16:06:26 +02:00
parent d373d10f6c
commit 3a4b364bcd
2 changed files with 10 additions and 6 deletions

View File

@ -156,7 +156,6 @@ class MP2Migrator {
} }
$this->importSegments(); $this->importSegments();
$this->segments_mapping = $this->getImportedMapping('segments');
$this->importCustomFields(); $this->importCustomFields();
$this->importSubscribers(); $this->importSubscribers();
@ -287,6 +286,7 @@ class MP2Migrator {
private function importSegments() { private function importSegments() {
$imported_segments_count = 0; $imported_segments_count = 0;
if($this->importStopped()) { if($this->importStopped()) {
$this->segments_mapping = $this->getImportedMapping('segments');
return; return;
} }
$this->log(__("Importing segments...", 'mailpoet')); $this->log(__("Importing segments...", 'mailpoet'));
@ -308,6 +308,8 @@ class MP2Migrator {
$this->progressbar->incrementCurrentCount($lists_count); $this->progressbar->incrementCurrentCount($lists_count);
} while(($lists != null) && ($lists_count > 0)); } while(($lists != null) && ($lists_count > 0));
$this->segments_mapping = $this->getImportedMapping('segments');
$this->log(sprintf(_n("%d segment imported", "%d segments imported", $imported_segments_count, 'mailpoet'), $imported_segments_count)); $this->log(sprintf(_n("%d segment imported", "%d segments imported", $imported_segments_count, 'mailpoet'), $imported_segments_count));
} }

View File

@ -133,9 +133,9 @@ class MP2MigratorTest extends MailPoetTest {
'created_at' => $timestamp, 'created_at' => $timestamp,
)); ));
$this->invokeMethod($this->MP2Migrator, 'importSegments'); $this->invokeMethod($this->MP2Migrator, 'importSegments');
$importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments');
$table = MP_SEGMENTS_TABLE; $table = MP_SEGMENTS_TABLE;
$segment = $wpdb->get_row("SELECT * FROM $table WHERE id=$id"); $segment = $wpdb->get_row("SELECT * FROM $table WHERE id=" . $importedSegmentsMapping[$id]);
expect($segment->id)->equals($id);
expect($segment->name)->equals($name); expect($segment->name)->equals($name);
expect($segment->description)->equals($description); expect($segment->description)->equals($description);
} }
@ -195,7 +195,7 @@ class MP2MigratorTest extends MailPoetTest {
$this->initImport(); $this->initImport();
$this->loadMP2Fixtures(); $this->loadMP2Fixtures();
$this->invokeMethod($this->MP2Migrator, 'importSubscribers'); $this->invokeMethod($this->MP2Migrator, 'importSubscribers');
expect(Subscriber::count())->equals(4); expect(Subscriber::count())->equals(5); // 4 MP2 users + the current user
// Check a subscriber data // Check a subscriber data
$this->initImport(); $this->initImport();
@ -240,7 +240,7 @@ class MP2MigratorTest extends MailPoetTest {
$this->loadMP2Fixtures(); $this->loadMP2Fixtures();
$this->invokeMethod($this->MP2Migrator, 'importSegments'); $this->invokeMethod($this->MP2Migrator, 'importSegments');
$this->invokeMethod($this->MP2Migrator, 'importSubscribers'); $this->invokeMethod($this->MP2Migrator, 'importSubscribers');
expect(SubscriberSegment::count())->equals(7); expect(SubscriberSegment::count())->equals(8); // 7 + the current user belongs to WordPress users segment
// Check a subscriber segment data // Check a subscriber segment data
@ -278,10 +278,12 @@ class MP2MigratorTest extends MailPoetTest {
$this->invokeMethod($this->MP2Migrator, 'importSegments'); $this->invokeMethod($this->MP2Migrator, 'importSegments');
$this->invokeMethod($this->MP2Migrator, 'importSubscribers'); $this->invokeMethod($this->MP2Migrator, 'importSubscribers');
$importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments');
$importedSubscribersMapping = $this->MP2Migrator->getImportedMapping('subscribers'); $importedSubscribersMapping = $this->MP2Migrator->getImportedMapping('subscribers');
$table = MP_SUBSCRIBER_SEGMENT_TABLE; $table = MP_SUBSCRIBER_SEGMENT_TABLE;
$segment_id = $importedSegmentsMapping[$list_id];
$subscriber_id = $importedSubscribersMapping[$user_id]; $subscriber_id = $importedSubscribersMapping[$user_id];
$subscriber_segment = $wpdb->get_row("SELECT * FROM $table WHERE subscriber_id='$subscriber_id' AND segment_id='$list_id'"); $subscriber_segment = $wpdb->get_row("SELECT * FROM $table WHERE subscriber_id='$subscriber_id' AND segment_id='$segment_id'");
expect($subscriber_segment)->notNull(); expect($subscriber_segment)->notNull();
} }