View source
<?php
namespace Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
use Drupal\Tests\migrate\Kernel\MigrateDumpAlterInterface;
use Drupal\profile\Entity\Profile;
class ProfileBillingDeletedUserTest extends Ubercart7TestBase implements MigrateDumpAlterInterface {
use CommerceMigrateTestTrait;
protected static $modules = [
'commerce_number_pattern',
'commerce_order',
'commerce_price',
'commerce_store',
'migrate_plus',
'path',
'profile',
'state_machine',
'telephone',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_order');
$this
->installEntitySchema('profile');
$this
->installEntitySchema('commerce_store');
$this
->installSchema('commerce_number_pattern', [
'commerce_number_pattern_sequence',
]);
$this
->installConfig('commerce_order');
$this
->migrateUsers(FALSE);
$this
->executeMigration('uc7_profile_billing');
}
public static function migrateDumpAlter(KernelTestBase $test) {
$db = Database::getConnection('default', 'migrate');
$db
->update('uc_orders')
->condition('uid', '4')
->fields([
'uid' => '400',
])
->execute();
}
public function testProfileBilling() {
$profile_id = 1;
$this
->assertProfile($profile_id, 'customer', '2', 'und', TRUE, TRUE, '1536902338', NULL);
$profile = Profile::load($profile_id);
$address = $profile
->get('address')
->first()
->getValue();
$this
->assertAddressField($address, 'CA', NULL, 'Starship Voyager', NULL, '', NULL, 'Level 12', '', 'Tom', NULL, 'Paris', '');
$phone = $profile
->get('phone')
->getValue();
$this
->assertSame([], $phone);
$profile_id = 2;
$this
->assertProfile($profile_id, 'customer', '0', 'und', FALSE, FALSE, '1536902428', NULL);
$profile = Profile::load($profile_id);
$address = $profile
->get('address')
->first()
->getValue();
$this
->assertAddressField($address, 'CA', NULL, '', NULL, '', NULL, '', '', '', NULL, '', '');
$phone = $profile
->get('phone')
->getValue();
$this
->assertSame([], $phone);
$profile_revision = \Drupal::entityTypeManager()
->getStorage('profile')
->loadRevision(1);
$address = $profile_revision
->get('address')
->first()
->getValue();
$this
->assertAddressField($address, 'US', 'AL', 'San Francisco', NULL, '74656', NULL, '', '', 'Tom', NULL, 'Paris', '');
$phone = $profile_revision
->get('phone')
->getValue()[0]['value'];
$this
->assertSame('555-4747', $phone);
$profile_revision = \Drupal::entityTypeManager()
->getStorage('profile')
->loadRevision(2);
$address = $profile_revision
->get('address')
->first()
->getValue();
$this
->assertAddressField($address, 'US', 'CA', 'San Francisco', NULL, '', NULL, '33 First Street', '', 'Harry', NULL, 'Kim', '');
$phone = $profile
->get('phone')
->getValue();
$this
->assertSame([], $phone);
}
}