Commit c532b2f9 authored by catch's avatar catch
Browse files

Issue #3139442 by mondrake, munish.kumar, Hardik_Patel_12, jungle, mohrerao,...

Issue #3139442 by mondrake, munish.kumar, Hardik_Patel_12, jungle, mohrerao, alexpott: Replace usages of AssertLegacyTrait::constructFieldXpath, that is deprecated
parent 369277f6
......@@ -63,17 +63,13 @@ public function testCommentWizard() {
$this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
// Check for available options of the row plugin.
$xpath = $this->constructFieldXpath('name', 'page[style][row_plugin]');
$fields = $this->xpath($xpath);
$options = [];
foreach ($fields as $field) {
$items = $field->findAll('xpath', 'option');
foreach ($items as $item) {
$options[] = $item->getValue();
}
}
$expected_options = ['entity:comment', 'fields'];
$this->assertEqual($options, $expected_options);
$items = $this->getSession()->getPage()->findField('page[style][row_plugin]')->findAll('xpath', 'option');
$actual_options = [];
foreach ($items as $item) {
$actual_options[] = $item->getValue();
}
$this->assertEquals($expected_options, $actual_options);
$view['id'] = strtolower($this->randomMachineName(16));
$this->drupalPostForm(NULL, $view, t('Save and edit'));
......
......@@ -191,8 +191,7 @@ public function testThemeSettings() {
];
$this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
$fields = $this->xpath($this->constructFieldXpath('name', 'logo_path'));
$uploaded_filename = 'public://' . $fields[0]->getValue();
$uploaded_filename = 'public://' . $this->getSession()->getPage()->findField('logo_path')->getValue();
$this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
$this->drupalGet('');
......
......@@ -58,7 +58,7 @@ public function testUserAdminLanguageConfigurationNotAvailableWithOnlyOneLanguag
$path = 'user/' . $this->adminUser->id() . '/edit';
$this->drupalGet($path);
// Ensure administration pages language settings widget is not available.
$this->assertNoFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector not available.');
$this->assertSession()->fieldNotExists('edit-preferred-admin-langcode');
}
/**
......@@ -72,13 +72,13 @@ public function testUserAdminLanguageConfigurationAvailableWithAdminLanguageNego
// Checks with user administration pages language negotiation disabled.
$this->drupalGet($path);
// Ensure administration pages language settings widget is not available.
$this->assertNoFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector not available.');
$this->assertSession()->fieldNotExists('edit-preferred-admin-langcode');
// Checks with user administration pages language negotiation enabled.
$this->setLanguageNegotiation();
$this->drupalGet($path);
// Ensure administration pages language settings widget is available.
$this->assertFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector is available.');
$this->assertSession()->fieldExists('edit-preferred-admin-langcode');
}
/**
......@@ -100,20 +100,20 @@ public function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegoti
$path = 'user/' . $this->adminUser->id() . '/edit';
$this->drupalGet($path);
// Ensure administration pages language setting is visible for admin.
$this->assertFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector available for admins.');
$this->assertSession()->fieldExists('edit-preferred-admin-langcode');
// Ensure administration pages language setting is visible for editors.
$editor = $this->drupalCreateUser(['view the administration theme']);
$this->drupalLogin($editor);
$path = 'user/' . $editor->id() . '/edit';
$this->drupalGet($path);
$this->assertFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector available for editors.');
$this->assertSession()->fieldExists('edit-preferred-admin-langcode');
// Ensure administration pages language setting is hidden for non-admins.
$this->drupalLogin($this->regularUser);
$path = 'user/' . $this->regularUser->id() . '/edit';
$this->drupalGet($path);
$this->assertNoFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector not available for regular user.');
$this->assertSession()->fieldNotExists('edit-preferred-admin-langcode');
}
/**
......
......@@ -252,7 +252,8 @@ protected function assertResponse($code) {
*/
protected function assertFieldByName($name, $value = NULL) {
@trigger_error('AssertLegacyTrait::assertFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
$this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value);
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $name]);
$this->assertFieldByXPath($xpath, $value);
}
/**
......@@ -275,7 +276,8 @@ protected function assertFieldByName($name, $value = NULL) {
*/
protected function assertNoFieldByName($name, $value = '') {
@trigger_error('AssertLegacyTrait::assertNoFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
$this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value);
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $name]);
$this->assertNoFieldByXPath($xpath, $value);
}
/**
......@@ -300,7 +302,8 @@ protected function assertNoFieldByName($name, $value = '') {
*/
protected function assertFieldById($id, $value = '') {
@trigger_error('AssertLegacyTrait::assertFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
$this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value);
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]);
$this->assertFieldByXPath($xpath, $value);
}
/**
......@@ -317,7 +320,10 @@ protected function assertFieldById($id, $value = '') {
*/
protected function assertField($field) {
@trigger_error('AssertLegacyTrait::assertField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
$this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $field]) .
'|' .
$this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $field]);
$this->assertFieldByXPath($xpath);
}
/**
......@@ -334,7 +340,10 @@ protected function assertField($field) {
*/
protected function assertNoField($field) {
@trigger_error('AssertLegacyTrait::assertNoField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
$this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $field]) .
'|' .
$this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $field]);
$this->assertNoFieldByXPath($xpath);
}
/**
......@@ -483,7 +492,8 @@ protected function assertNoLinkByHref($href) {
*/
protected function assertNoFieldById($id, $value = '') {
@trigger_error('AssertLegacyTrait::assertNoFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
$this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value);
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]);
$this->assertNoFieldByXPath($xpath, $value);
}
/**
......
......@@ -10,6 +10,7 @@
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\WebAssert;
use PHPUnit\Framework\ExpectationFailedException;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait
......@@ -236,6 +237,18 @@ public function testPass() {
$this->pass('Passed.');
}
/**
* @covers ::constructFieldXpath
* @expectedDeprecation AssertLegacyTrait::constructFieldXpath() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->findField() instead. See https://www.drupal.org/node/3129738
*/
public function testConstructFieldXpath() {
$this->webAssert
->buildXPathQuery(Argument::any(), Argument::any())
->willReturn('qux');
$this->assertSame('qux', $this->constructFieldXpath('foo', ['bar']));
}
/**
* Returns a mocked behat session object.
*
......
......@@ -142,7 +142,6 @@ public static function getSkippedDeprecations() {
'AssertLegacyTrait::assertFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and check the values directly in the test. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertNoFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and assert that the result is empty. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertFieldsByValue() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::constructFieldXpath() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->findField() instead. See https://www.drupal.org/node/3129738',
];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment