1

I am having a problem asserting that a blocks property contains an array key.

I have added a link to the my customer account area using the following XML:

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="namespace_ordermigration">
            <name>migration</name>
            <path>migration/order/list/</path>
            <label>Migrated Orders</label>
        </action>
    </reference>
</customer_account>

That addLink method is called on the block Mage_Customer_Block_Account_Navigation which has a protected property $_links = array();

Here the closest I could get with a EcomDev_PHPUnit_Test_Case_Controller test:

public function testMyAccountButtonDefined()
{
    $this->dispatch('migration/order/list');

    $this->assertLayoutBlockPropertyEquals('customer_account_navigation', '_links', array('migration' => ''));
}

Which fails:

1) Namespace_OrderMigration_Test_Controller_OrderController::testMyAccountButtonDefined
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
-    'migration' => ''
+    'migration' => Varien_Object Object (...)
+    'account' => Varien_Object Object (...)
+    'account_edit' => Varien_Object Object (...)
+    'address_book' => Varien_Object Object (...)
...

Does anybody know how I could get access to the property it is testing so I could do a simpler PHPUnit test with the results?

Another potential option is creating a new wrapper around the assertContains method of PHPUnit_Framework_Assert in EcomDev_PHPUnit_Test_Case_Controller called something like $this->assertLayoutBlockPropertyContains. This is quite a bit of work and it would probably be better spent exposing the response.

1 Answer 1

0

This is how I ended tested a blocks property contains the array key I defined in my layout.xml, a bit more of a direct route and only possible as the property is exposed in the block, so not a valid answer just a work around

public function testMyAccountButtonDefined()
{
    $this->dispatch('migration/order/list');

    /* @var $block Mage_Customer_Block_Account_Navigation */
    $block = $this->app()->getLayout()->getBlock('customer_account_navigation');

    $this->assertContains('migration', array_keys($block->getLinks()));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.