Use array_map
This commit is contained in:
parent
238dd8fb68
commit
38314a0ed2
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\tdd_dublin\Kernel;
|
||||||
|
|
||||||
use Drupal\KernelTests\KernelTestBase;
|
use Drupal\KernelTests\KernelTestBase;
|
||||||
use Drupal\node\Entity\Node;
|
use Drupal\node\Entity\Node;
|
||||||
|
use Drupal\views\ResultRow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group tdd_dublin
|
* @group tdd_dublin
|
||||||
|
@ -55,10 +56,9 @@ class PageListTest extends KernelTestBase {
|
||||||
// This makes it easier to test certain scenarios, and ensures that the
|
// This makes it easier to test certain scenarios, and ensures that the
|
||||||
// test is future-proofed and won't fail at a later date due to a change in
|
// test is future-proofed and won't fail at a later date due to a change in
|
||||||
// the presentation code.
|
// the presentation code.
|
||||||
$nids = [];
|
$nids = array_map(function (ResultRow $result) {
|
||||||
foreach (views_get_view_result('pages') as $result) {
|
return $result->_entity->id();
|
||||||
$nids[] = $result->nid;
|
}, views_get_view_result('pages'));
|
||||||
}
|
|
||||||
|
|
||||||
// Only node 1 matches the criteria of being a published page, so only that
|
// Only node 1 matches the criteria of being a published page, so only that
|
||||||
// node ID should be being returned from the view. assertEquals() can be
|
// node ID should be being returned from the view. assertEquals() can be
|
||||||
|
@ -86,10 +86,9 @@ class PageListTest extends KernelTestBase {
|
||||||
Node::create($this->validParams(['title' => 'Page B']))->save();
|
Node::create($this->validParams(['title' => 'Page B']))->save();
|
||||||
|
|
||||||
// Get the result data from the view.
|
// Get the result data from the view.
|
||||||
$nids = [];
|
$nids = array_map(function (ResultRow $result) {
|
||||||
foreach (views_get_view_result('pages') as $result) {
|
return $result->_entity->id();
|
||||||
$nids[] = $result->nid;
|
}, views_get_view_result('pages'));
|
||||||
}
|
|
||||||
|
|
||||||
// Compare the expected order based on the titles defined above to the
|
// Compare the expected order based on the titles defined above to the
|
||||||
// ordered results from the view.
|
// ordered results from the view.
|
||||||
|
|
Loading…
Reference in a new issue