Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #959 from mariansollmann/issue-959
Browse files Browse the repository at this point in the history
Replace CMTest_TH_Html with CM_Dom_NodeList
  • Loading branch information
Marian Sollmann committed Aug 26, 2014
2 parents 65d1f40 + 145f83c commit 137b0b0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 48 deletions.
25 changes: 12 additions & 13 deletions tests/helpers/CMTest/library/CMTest/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,13 @@ protected function _createPage($pageClass, array $params = null) {
* @param CM_Component_Abstract $component
* @param CM_Model_User|null $viewer
* @param CM_Site_Abstract|null $site
* @return CMTest_TH_Html
* @return CM_Dom_NodeList
*/
protected function _renderComponent(CM_Component_Abstract $component, CM_Model_User $viewer = null, CM_Site_Abstract $site = null) {
$render = new CM_Frontend_Render($site, $viewer);
$renderAdapter = new CM_RenderAdapter_Component($render, $component);
$componentHtml = $renderAdapter->fetch();
$html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $componentHtml . '</body></html>';
return new CMTest_TH_Html($html);
return new CM_Dom_NodeList($componentHtml, true);
}

/**
Expand All @@ -270,14 +269,14 @@ protected function _renderFormField(CM_FormField_Abstract $formField, $renderPar
}
$renderAdapter = new CM_RenderAdapter_FormField($render, $formField);
$html = $renderAdapter->fetch(CM_Params::factory($renderParams));
return new CM_Dom_NodeList($html);
return new CM_Dom_NodeList($html, true);
}

/**
* @param CM_Page_Abstract $page
* @param CM_Model_User|null $viewer
* @param CM_Site_Abstract|null $site
* @return CMTest_TH_Html
* @return CM_Dom_NodeList
*/
protected function _renderPage(CM_Page_Abstract $page, CM_Model_User $viewer = null, CM_Site_Abstract $site = null) {
if (null === $site) {
Expand All @@ -290,7 +289,7 @@ protected function _renderPage(CM_Page_Abstract $page, CM_Model_User $viewer = n
$page->prepareResponse($render->getEnvironment(), $response);
$renderAdapter = new CM_RenderAdapter_Page($render, $page);
$html = $renderAdapter->fetch();
return new CMTest_TH_Html($html);
return new CM_Dom_NodeList($html, true);
}

/**
Expand Down Expand Up @@ -528,11 +527,11 @@ public static function assertFormResponseError(CM_Response_View_Form $response,
}

/**
* @param CMTest_TH_Html $html
* @param string $css
* @param CM_Dom_NodeList $html
* @param string $css
*/
public static function assertHtmlExists(CMTest_TH_Html $html, $css) {
self::assertTrue($html->exists($css), 'HTML does not contain `' . $css . '`.');
public static function assertHtmlExists(CM_Dom_NodeList $html, $css) {
self::assertTrue($html->has($css), 'HTML does not contain `' . $css . '`.');
}

/**
Expand Down Expand Up @@ -594,10 +593,10 @@ public static function assertSameTime($expected, $actual, $delta = null) {
}

/**
* @param CMTest_TH_Html $page
* @param bool $warnings
* @param CM_Dom_NodeList $page
* @param bool $warnings
*/
public static function assertTidy(CMTest_TH_Html $page, $warnings = true) {
public static function assertTidy(CM_Dom_NodeList $page, $warnings = true) {
if (!extension_loaded('tidy')) {
self::markTestSkipped('The tidy extension is not available.');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/library/CM/Page/Error/NotAllowedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public function testGuest() {
$page = $this->_createPage('CM_Page_Error_NotAllowed');
$html = $this->_renderPage($page);

$this->assertTrue($html->exists('.CM_Component_NotAllowed'));
$this->assertTrue($html->has('.CM_Component_NotAllowed'));
}
}
2 changes: 1 addition & 1 deletion tests/library/CM/Page/Error/NotFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public function testGuest() {
$page = $this->_createPage('CM_Page_Error_NotFound');
$html = $this->_renderPage($page);

$this->assertTrue($html->exists('.CM_Component_Notfound'));
$this->assertTrue($html->has('.CM_Component_Notfound'));
}
}
66 changes: 33 additions & 33 deletions tests/library/CM/SmartyPlugins/function.selectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public function testNothingSelected() {
),
));

$this->assertSame(2, $htmlObject->getCount('option'));
$this->assertSame(1, $htmlObject->getCount('option[selected]'));
$this->assertSame(1, $htmlObject->getCount('select'));
$this->assertSame('foo', $htmlObject->getText('option[selected]'));
$this->assertSame('foo', $htmlObject->getText('.label'));
$this->assertSame(2, $htmlObject->find('option')->count());
$this->assertSame(1, $htmlObject->find('option[selected]')->count());
$this->assertSame(1, $htmlObject->find('select')->count());
$this->assertSame('foo', $htmlObject->find('option[selected]')->getText());
$this->assertSame('foo', $htmlObject->find('.label')->getText());
}

public function testSelectedValue() {
Expand All @@ -30,11 +30,11 @@ public function testSelectedValue() {
'selectedValue' => 1,
));

$this->assertSame(2, $htmlObject->getCount('option'));
$this->assertSame(1, $htmlObject->getCount('option[selected]'));
$this->assertSame(1, $htmlObject->getCount('select'));
$this->assertSame('bar', $htmlObject->getText('option[selected]'));
$this->assertSame('bar', $htmlObject->getText('.label'));
$this->assertSame(2, $htmlObject->find('option')->count());
$this->assertSame(1, $htmlObject->find('option[selected]')->count());
$this->assertSame(1, $htmlObject->find('select')->count());
$this->assertSame('bar', $htmlObject->find('option[selected]')->getText());
$this->assertSame('bar', $htmlObject->find('.label')->getText());
}

public function testPlaceholder() {
Expand All @@ -47,11 +47,11 @@ public function testPlaceholder() {
'placeholder' => 'please choose',
));

$this->assertSame(3, $htmlObject->getCount('option'));
$this->assertSame(1, $htmlObject->getCount('option[selected]'));
$this->assertSame(1, $htmlObject->getCount('select'));
$this->assertSame('please choose', $htmlObject->getText('option[selected]'));
$this->assertSame('please choose', $htmlObject->getText('.label'));
$this->assertSame(3, $htmlObject->find('option')->count());
$this->assertSame(1, $htmlObject->find('option[selected]')->count());
$this->assertSame(1, $htmlObject->find('select')->count());
$this->assertSame('please choose', $htmlObject->find('option[selected]')->getText());
$this->assertSame('please choose', $htmlObject->find('.label')->getText());
}

public function testPlaceholder_true() {
Expand All @@ -64,11 +64,11 @@ public function testPlaceholder_true() {
'placeholder' => true,
));

$this->assertSame(3, $htmlObject->getCount('option'));
$this->assertSame(1, $htmlObject->getCount('option[selected]'));
$this->assertSame(1, $htmlObject->getCount('select'));
$this->assertSame(' -Select- ', $htmlObject->getText('option[selected]'));
$this->assertSame(' -Select- ', $htmlObject->getText('.label'));
$this->assertSame(3, $htmlObject->find('option')->count());
$this->assertSame(1, $htmlObject->find('option[selected]')->count());
$this->assertSame(1, $htmlObject->find('select')->count());
$this->assertSame(' -Select- ', $htmlObject->find('option[selected]')->getText());
$this->assertSame(' -Select- ', $htmlObject->find('.label')->getText());
}

public function testPlaceholder_false() {
Expand All @@ -81,11 +81,11 @@ public function testPlaceholder_false() {
'placeholder' => false,
));

$this->assertSame(2, $htmlObject->getCount('option'));
$this->assertSame(1, $htmlObject->getCount('option[selected]'));
$this->assertSame(1, $htmlObject->getCount('select'));
$this->assertSame('foo', $htmlObject->getText('option[selected]'));
$this->assertSame('foo', $htmlObject->getText('.label'));
$this->assertSame(2, $htmlObject->find('option')->count());
$this->assertSame(1, $htmlObject->find('option[selected]')->count());
$this->assertSame(1, $htmlObject->find('select')->count());
$this->assertSame('foo', $htmlObject->find('option[selected]')->getText());
$this->assertSame('foo', $htmlObject->find('.label')->getText());
}

public function testPlaceholder_empty() {
Expand All @@ -98,11 +98,11 @@ public function testPlaceholder_empty() {
'placeholder' => '',
));

$this->assertSame(3, $htmlObject->getCount('option'));
$this->assertSame(1, $htmlObject->getCount('option[selected]'));
$this->assertSame(1, $htmlObject->getCount('select'));
$this->assertSame('', $htmlObject->getText('option[selected]'));
$this->assertSame('', $htmlObject->getText('.label'));
$this->assertSame(3, $htmlObject->find('option')->count());
$this->assertSame(1, $htmlObject->find('option[selected]')->count());
$this->assertSame(1, $htmlObject->find('select')->count());
$this->assertSame('', $htmlObject->find('option[selected]')->getText());
$this->assertSame('', $htmlObject->find('.label')->getText());
}

public function testLabelPrefix() {
Expand All @@ -115,19 +115,19 @@ public function testLabelPrefix() {
'labelPrefix' => 'foobar',
));

$this->assertEquals('foobar', $htmlObject->getText('.labelPrefix'));
$this->assertEquals('foobar', $htmlObject->find('.labelPrefix')->getText());
}

/**
* @param array $params
* @return CMTest_TH_Html
* @return CM_Dom_NodeList
*/
private function _createSelect(array $params) {
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$template = $smarty->createTemplate('string:');
$template->assignGlobal('render', $render);
$html = smarty_function_select($params, $template);
return new CMTest_TH_Html($html);
return new CM_Dom_NodeList($html);
}
}

0 comments on commit 137b0b0

Please sign in to comment.