Unit Testing code that retrieves content I have a method which calls another one to retrieve a specific node ID. If it can be found, it then retrieves the node.

Is this the kind of functionality that can be tested in Drupal? Or even should it tested? If so what is the best approach for it?

private function retrieve() {
  // Call another method to get IDs of specific bundle based on its workflow status. We get just one ID back as there is only one node for this bundle.

  // If statement to validate we do have a node ID.
  // Call method to retrieve content for node based on the retrieved `nid`
  // Return node content if any has been found

  // If no content is found return FALSE.
}
By definition, when unit testing your function you should focus on the logic the unit delivers, which, in your case, is the following conditional logic:

IF (nid IS NOT FOUND) OR (a node for a found nid HAS NO CONTENT)
  =&gt; FALSE
ELSE
  =&gt; NODE.CONTENT


That being said, you could:


Mock the two internally-used methods:


methodA:


CaseA1: returns an empty result (no nid found)
CaseA2: returns X as a nid
CaseA3: returns Y as a nid

methodB:


CaseB1: Given X as a parameter returns an empty result (no content found)
CaseB2: Given Y as a parameter returns some dummy content


Assert that the retrieve() method returns for each of the following cases:


CaseA1: FALSE
CaseA2+CaseB1: FALSE
CaseA3+CaseB2: TRUE



This is not very "deep" testing, but your function does not carry much logic. It is still testable in this minimal way.

Good luck!