public function SimplenewsSynchronizeFieldsFormTest::testSubscriberFormFieldSync in Simplenews 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplenewsSynchronizeFieldsFormTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSynchronizeFieldsFormTest::testSubscriberFormFieldSync()
Tests that fields are synchronized using the Subscriber form.
File
- tests/
src/ Functional/ SimplenewsSynchronizeFieldsFormTest.php, line 52
Class
- SimplenewsSynchronizeFieldsFormTest
- Tests that shared fields are synchronized when using forms.
Namespace
Drupal\Tests\simplenews\FunctionalCode
public function testSubscriberFormFieldSync() {
// Create a subscriber for the user.
$subscriber = Subscriber::create([
'mail' => 'user@example.com',
]);
$subscriber
->save();
$this
->assertEquals($this->user
->id(), $subscriber
->getUserId());
// Edit subscriber field and assert user field is changed accordingly.
$this
->drupalLogin($this->user);
$this
->drupalGet('admin/people/simplenews/edit/' . $subscriber
->id());
$this
->assertField('field_shared[0][value]');
$this
->assertRaw($this->user->field_shared->value);
$new_value = $this
->randomMachineName();
$this
->submitForm([
'field_shared[0][value]' => $new_value,
], 'Save');
$this
->drupalGet('admin/people/simplenews/edit/' . $subscriber
->id());
$this
->assertRaw($new_value);
$this->user = User::load($this->user
->id());
$this
->assertEqual($this->user->field_shared->value, $new_value);
// Unset the sync setting and assert field is not synced.
$this
->drupalGet('admin/config/people/simplenews/settings/subscriber');
$this
->submitForm([
'simplenews_sync_fields' => FALSE,
], 'Save configuration');
$unsynced_value = $this
->randomMachineName();
$this
->drupalGet('admin/people/simplenews/edit/' . $subscriber
->id());
$this
->submitForm([
'field_shared[0][value]' => $unsynced_value,
], 'Save');
$this
->drupalGet('admin/people/simplenews/edit/' . $subscriber
->id());
$this
->assertRaw($unsynced_value);
$this->user = User::load($this->user
->id());
$this
->assertEqual($this->user->field_shared->value, $new_value);
$this
->assertNotEqual($this->user->field_shared->value, $unsynced_value);
}