Aug 9, 2014

Renamed methods in class WebTestBase and other mismatches

For the most part, the methods of class WebTestBase in Drupal 8 are identical in name and functionality to the methods of class DrupalWebTestCase in D7.

However, there are some exceptions.

(1)  Both classes have a method named drupalPost(), but they do not have the same signature. It turns out that the counterpart of DrupalWebTestCase::drupalPost() is WebTestBase::drupalPostForm().

(2)  Similarly, the counterpart of DrupalWebTestCase::drupalPostAJAX() is WebTestBase::drupalPostAjaxForm().

From a Drupal coding standard: "If an acronym is used in a class or method name, make it CamelCase".

(3)  The return value of WebTestBase::drupalCreateNode() is of type NodeInterface. That's very different from what is returned by DrupalWebTestCase::drupalCreateNode(), which is an object converted from an array via a (object) typecast.

For example, to access the node id of the created node in D7, you use

    $node1 = $this->drupalCreateNode($settings);
    $id = $node1->nid;

But in D8,

    $node1 = $this->drupalCreateNode($settings);
    $id = $node1->id();

Update: see


abstract class WebTestBase!modules!simpletest!src!WebTestBase.php/class/WebTestBase/8

interface NodeInterface!modules!node!src!NodeInterface.php/interface/NodeInterface/8

drupalPost() and drupalPostAJAX() have been renamed 

Object-oriented code

No comments:

Post a Comment