diff --git a/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php index c23d002..8606f2b 100644 --- a/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php +++ b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php @@ -31,13 +31,14 @@ use Drupal\Core\Ajax\RedirectCommand; /** - * @coversDefaultClass \Drupal\Core\Ajax\AjaxCommands + * Test coverage for various classes in the \Drupal\Core\Ajax namespace. + * * @group Ajax */ class AjaxCommandsTest extends UnitTestCase { /** - * @covers ::addCssCommand + * @covers \Drupal\Core\Ajax\AddCssCommand */ public function testAddCssCommand() { $command = new AddCssCommand('p{ text-decoration:blink; }'); @@ -47,11 +48,11 @@ public function testAddCssCommand() { 'data' => 'p{ text-decoration:blink; }', ); - $this->assertEquals($command->render(), $expected, "AddCssCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::afterCommand + * @covers \Drupal\Core\Ajax\AfterCommand */ public function testAfterCommand() { $command = new AfterCommand('#page-title', '
New Text!
', array('my-setting' => 'setting')); @@ -64,11 +65,11 @@ public function testAfterCommand() { 'settings' => array('my-setting' => 'setting'), ); - $this->assertEquals($command->render(), $expected, "AfterCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::alertCommand + * @covers \Drupal\Core\Ajax\AlertCommand */ public function testAlertCommand() { $command = new AlertCommand('Set condition 1 throughout the ship!'); @@ -77,11 +78,11 @@ public function testAlertCommand() { 'text' => 'Set condition 1 throughout the ship!', ); - $this->assertEquals($command->render(), $expected, "AlertCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::appendCommand + * @covers \Drupal\Core\Ajax\AppendCommand */ public function testAppendCommand() { $command = new AppendCommand('#page-title', 'New Text!
', array('my-setting' => 'setting')); @@ -94,11 +95,11 @@ public function testAppendCommand() { 'settings' => array('my-setting' => 'setting'), ); - $this->assertEquals($command->render(), $expected, "AppendCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::beforeCommand + * @covers \Drupal\Core\Ajax\BeforeCommand */ public function testBeforeCommand() { $command = new BeforeCommand('#page-title', 'New Text!
', array('my-setting' => 'setting')); @@ -111,11 +112,11 @@ public function testBeforeCommand() { 'settings' => array('my-setting' => 'setting'), ); - $this->assertEquals($command->render(), $expected, "BeforeCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::changedCommand + * @covers \Drupal\Core\Ajax\ChangedCommand */ public function testChangedCommand() { $command = new ChangedCommand('#page-title', '#page-title-changed'); @@ -126,11 +127,11 @@ public function testChangedCommand() { 'asterisk' => '#page-title-changed', ); - $this->assertEquals($command->render(), $expected, "ChangedCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::cssCommand + * @covers \Drupal\Core\Ajax\CssCommand */ public function testCssCommand() { $command = new CssCommand('#page-title', array('text-decoration' => 'blink')); @@ -146,11 +147,11 @@ public function testCssCommand() { ), ); - $this->assertEquals($command->render(), $expected, "CssCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::dataCommand + * @covers \Drupal\Core\Ajax\DataCommand */ public function testDataCommand() { $command = new DataCommand('#page-title', 'my-data', array('key' => 'value')); @@ -162,11 +163,11 @@ public function testDataCommand() { 'value' => array('key' => 'value'), ); - $this->assertEquals($command->render(), $expected, "DataCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::htmlCommand + * @covers \Drupal\Core\Ajax\HtmlCommand */ public function testHtmlCommand() { $command = new HtmlCommand('#page-title', 'New Text!
', array('my-setting' => 'setting')); @@ -179,11 +180,11 @@ public function testHtmlCommand() { 'settings' => array('my-setting' => 'setting'), ); - $this->assertEquals($command->render(), $expected, "HtmlCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::insertCommand + * @covers \Drupal\Core\Ajax\InsertCommand */ public function testInsertCommand() { $command = new InsertCommand('#page-title', 'New Text!
', array('my-setting' => 'setting')); @@ -196,11 +197,11 @@ public function testInsertCommand() { 'settings' => array('my-setting' => 'setting'), ); - $this->assertEquals($command->render(), $expected, "InsertCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::invokeCommand + * @covers \Drupal\Core\Ajax\InvokeCommand */ public function testInvokeCommand() { $command = new InvokeCommand('#page-title', 'myMethod', array('var1', 'var2')); @@ -212,11 +213,11 @@ public function testInvokeCommand() { 'args' => array('var1', 'var2'), ); - $this->assertEquals($command->render(), $expected, "InvokeCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::prependCommand + * @covers \Drupal\Core\Ajax\PrependCommand */ public function testPrependCommand() { $command = new PrependCommand('#page-title', 'New Text!
', array('my-setting' => 'setting')); @@ -229,11 +230,11 @@ public function testPrependCommand() { 'settings' => array('my-setting' => 'setting'), ); - $this->assertEquals($command->render(), $expected, "PrependCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::removeCommand + * @covers \Drupal\Core\Ajax\RemoveCommand */ public function testRemoveCommand() { $command = new RemoveCommand('#page-title'); @@ -243,11 +244,11 @@ public function testRemoveCommand() { 'selector' => '#page-title', ); - $this->assertEquals($command->render(), $expected, "RemoveCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::replaceCommand + * @covers \Drupal\Core\Ajax\ReplaceCommand */ public function testReplaceCommand() { $command = new ReplaceCommand('#page-title', 'New Text!
', array('my-setting' => 'setting')); @@ -260,11 +261,11 @@ public function testReplaceCommand() { 'settings' => array('my-setting' => 'setting'), ); - $this->assertEquals($command->render(), $expected, "ReplaceCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::restripeCommand + * @covers \Drupal\Core\Ajax\RestripeCommand */ public function testRestripeCommand() { $command = new RestripeCommand('#page-title'); @@ -274,11 +275,11 @@ public function testRestripeCommand() { 'selector' => '#page-title', ); - $this->assertEquals($command->render(), $expected, "RestripeCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::settingsCommand + * @covers \Drupal\Core\Ajax\SettingsCommand */ public function testSettingsCommand() { $command = new SettingsCommand(array('key' => 'value'), TRUE); @@ -289,11 +290,11 @@ public function testSettingsCommand() { 'merge' => TRUE, ); - $this->assertEquals($command->render(), $expected, "SettingsCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::openDialogCommand + * @covers \Drupal\Core\Ajax\OpenDialogCommand */ public function testOpenDialogCommand() { $command = $this->getMockBuilder('Drupal\Core\Ajax\OpenDialogCommand') @@ -301,18 +302,22 @@ public function testOpenDialogCommand() { '#some-dialog', 'Title', 'Text!
', array( 'url' => FALSE, 'width' => 500, - ) + ), )) - // This method calls drupal_render which isn't available. We want it to do - // nothing so we mock it to return null. - ->setMethods(array('drupalAttachLibrary')) + ->setMethods(array('getRenderedContent')) ->getMock(); + // This method calls the render service, which isn't available. We want it + // to do nothing so we mock it to return a known value. + $command->expects($this->once()) + ->method('getRenderedContent') + ->willReturn('rendered content'); + $expected = array( 'command' => 'openDialog', 'selector' => '#some-dialog', 'settings' => NULL, - 'data' => 'Text!
', + 'data' => 'rendered content', 'dialogOptions' => array( 'url' => FALSE, 'width' => 500, @@ -320,11 +325,11 @@ public function testOpenDialogCommand() { 'modal' => FALSE, ), ); - $this->assertEquals($command->render(), $expected, "OpenDialogCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::openModalDialogCommand + * @covers \Drupal\Core\Ajax\OpenModalDialogCommand */ public function testOpenModalDialogCommand() { $command = $this->getMockBuilder('Drupal\Core\Ajax\OpenModalDialogCommand') @@ -332,18 +337,22 @@ public function testOpenModalDialogCommand() { 'Title', 'Text!
', array( 'url' => 'example', 'width' => 500, - ) + ), )) - // This method calls drupal_render which isn't available. We want it to do - // nothing so we mock it to return null. - ->setMethods(array('drupalAttachLibrary')) + ->setMethods(array('getRenderedContent')) ->getMock(); + // This method calls the render service, which isn't available. We want it + // to do nothing so we mock it to return a known value. + $command->expects($this->once()) + ->method('getRenderedContent') + ->willReturn('rendered content'); + $expected = array( 'command' => 'openDialog', 'selector' => '#drupal-modal', 'settings' => NULL, - 'data' => 'Text!
', + 'data' => 'rendered content', 'dialogOptions' => array( 'url' => 'example', 'width' => 500, @@ -351,11 +360,11 @@ public function testOpenModalDialogCommand() { 'modal' => TRUE, ), ); - $this->assertEquals($command->render(), $expected, "OpenModalDialogCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::closeModalDialogCommand + * @covers \Drupal\Core\Ajax\CloseModalDialogCommand */ public function testCloseModalDialogCommand() { $command = new CloseModalDialogCommand(); @@ -365,11 +374,11 @@ public function testCloseModalDialogCommand() { 'persist' => FALSE, ); - $this->assertEquals($command->render(), $expected, "CloseModalDialogCommand::render() didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::closeDialogCommand + * @covers \Drupal\Core\Ajax\CloseDialogCommand */ public function testCloseDialogCommand() { $command = new CloseDialogCommand('#some-dialog', TRUE); @@ -379,11 +388,11 @@ public function testCloseDialogCommand() { 'persist' => TRUE, ); - $this->assertEquals($command->render(), $expected, "CloseDialogCommand::render() with a selector and persistence enabled didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::setDialogOptionCommand + * @covers \Drupal\Core\Ajax\SetDialogOptionCommand */ public function testSetDialogOptionCommand() { $command = new SetDialogOptionCommand('#some-dialog', 'width', '500'); @@ -394,11 +403,11 @@ public function testSetDialogOptionCommand() { 'optionValue' => '500', ); - $this->assertEquals($command->render(), $expected, "SetDialogOptionCommand::render() with a selector didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::setDialogTitleCommand + * @covers \Drupal\Core\Ajax\SetDialogTitleCommand */ public function testSetDialogTitleCommand() { $command = new SetDialogTitleCommand('#some-dialog', 'Example'); @@ -409,11 +418,11 @@ public function testSetDialogTitleCommand() { 'optionValue' => 'Example', ); - $this->assertEquals($command->render(), $expected, "SetDialogTitleCommand::render() with a selector didn't return the expected array."); + $this->assertEquals($expected, $command->render()); } /** - * @covers ::redirectCommand + * @covers \Drupal\Core\Ajax\RedirectCommand */ public function testRedirectCommand() { $command = new RedirectCommand('http://example.com'); @@ -422,7 +431,7 @@ public function testRedirectCommand() { 'url' => 'http://example.com', ); - $this->assertEquals($command->render(), $expected, "RedirectCommand::render() didn't return the expected command array."); + $this->assertEquals($expected, $command->render()); } }