Skip to content

Commit

Permalink
Removing duplicated tests, and tests for methods that are not impleme…
Browse files Browse the repository at this point in the history
…nted in the subclasses.
  • Loading branch information
markstory committed Dec 15, 2010
1 parent 7b4ffa2 commit 1531a72
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 250 deletions.
21 changes: 0 additions & 21 deletions cake/tests/cases/console/libs/task_collection.test.php
Expand Up @@ -118,25 +118,4 @@ function testUnload() {
$this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong');
}

/**
* test normalizeObjectArray
*
* @return void
*/
function testnormalizeObjectArray() {
$tasks = array(
'Html',
'Foo.Bar' => array('one', 'two'),
'Something',
'Banana.Apple' => array('foo' => 'bar')
);
$result = TaskCollection::normalizeObjectArray($tasks);
$expected = array(
'Html' => array('class' => 'Html', 'settings' => array()),
'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')),
'Something' => array('class' => 'Something', 'settings' => array()),
'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')),
);
$this->assertEquals($expected, $result);
}
}
156 changes: 0 additions & 156 deletions cake/tests/cases/libs/controller/component_collection.test.php
Expand Up @@ -119,162 +119,6 @@ function testUnload() {
$this->assertEquals(array('Security'), $result, 'enabled components is wrong');
}

/**
* creates mock classes for testing
*
* @return void
*/
protected function _makeMockClasses() {
if (!class_exists('TriggerMockCookieComponent')) {
$this->getMock('CookieComponent', array(), array(), 'TriggerMockCookieComponent', false);
$this->getMock('SecurityComponent', array(), array(), 'TriggerMockSecurityComponent', false);
}
}

/**
* test triggering callbacks.
*
* @return void
*/
function testTrigger() {
$controller = null;
$this->_makeMockClasses();
$this->Components->load('TriggerMockCookie');
$this->Components->load('TriggerMockSecurity');

$this->Components->TriggerMockCookie->expects($this->once())->method('startup')
->with(null);
$this->Components->TriggerMockSecurity->expects($this->once())->method('startup')
->with(null);

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$this->assertNull($this->Components->trigger('startup', array(&$controller)));
}

/**
* test that the initalize callback is triggered on all components even those that are disabled.
*
* @return void
*/
function testTriggerWithTriggerDisabledObjects() {
$controller = 'Not a controller';

$this->_makeMockClasses();
$this->Components->load('TriggerMockCookie', array(), false);
$this->Components->load('TriggerMockSecurity');

$this->Components->TriggerMockCookie->expects($this->once())->method('initialize')
->with($controller);
$this->Components->TriggerMockSecurity->expects($this->once())->method('initialize')
->with($controller);

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$result = $this->Components->trigger('initialize', array(&$controller), array('triggerDisabled' => true));
$this->assertNull($result);
}

/**
* test trigger and disabled helpers.
*
* @return void
*/
function testTriggerWithDisabledComponents() {
$controller = null;
$this->_makeMockClasses();
$this->Components->load('TriggerMockCookie');
$this->Components->load('TriggerMockSecurity');

$this->Components->TriggerMockCookie->expects($this->once())->method('startup')
->with($controller);
$this->Components->TriggerMockSecurity->expects($this->never())->method('startup');

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$this->Components->disable('TriggerMockSecurity');

$this->assertNull($this->Components->trigger('startup', array(&$controller)));
}

/**
* test that the collectReturn option works.
*
* @return void
*/
function testTriggerWithCollectReturn() {
$controller = null;
$this->_makeMockClasses();
$this->Components->load('TriggerMockCookie');
$this->Components->load('TriggerMockSecurity');

$this->Components->TriggerMockCookie->expects($this->once())->method('startup')
->will($this->returnValue(array('one', 'two')));
$this->Components->TriggerMockSecurity->expects($this->once())->method('startup')
->will($this->returnValue(array('three', 'four')));

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$result = $this->Components->trigger('startup', array(&$controller), array('collectReturn' => true));
$expected = array(
array('one', 'two'),
array('three', 'four')
);
$this->assertEquals($expected, $result);
}

/**
* test that trigger with break & breakOn works.
*
* @return void
*/
function testTriggerWithBreak() {
$controller = null;
$this->_makeMockClasses();
$this->Components->load('TriggerMockCookie');
$this->Components->load('TriggerMockSecurity');

$this->Components->TriggerMockCookie->expects($this->once())->method('startup')
->will($this->returnValue(false));
$this->Components->TriggerMockSecurity->expects($this->never())->method('startup');

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$result = $this->Components->trigger(
'startup',
array(&$controller),
array('break' => true, 'breakOn' => false)
);
$this->assertFalse($result);
}

/**
* test normalizeObjectArray
*
* @return void
*/
function testnormalizeObjectArray() {
$components = array(
'Html',
'Foo.Bar' => array('one', 'two'),
'Something',
'Banana.Apple' => array('foo' => 'bar')
);
$result = ComponentCollection::normalizeObjectArray($components);
$expected = array(
'Html' => array('class' => 'Html', 'settings' => array()),
'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')),
'Something' => array('class' => 'Something', 'settings' => array()),
'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')),
);
$this->assertEquals($expected, $result);
}

/**
* test getting the controller out of the collection
*
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/object_collection.test.php
Expand Up @@ -189,11 +189,11 @@ function testTriggerWithTriggerDisabledObjects() {
}

/**
* test trigger and disabled helpers.
* test trigger and disabled objects
*
* @return void
*/
function testTriggerWithDisabledComponents() {
function testTriggerWithDisabledObjects() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
Expand Down
71 changes: 0 additions & 71 deletions cake/tests/cases/libs/view/helper_collection.test.php
Expand Up @@ -116,75 +116,4 @@ function testUnload() {
$this->assertEquals(array('Form'), $result, 'loaded helpers is wrong');
}

/**
* test triggering callbacks.
*
* @return void
*/
function testTrigger() {
if (!class_exists('TriggerMockHtmlHelper')) {
$this->getMock('HtmlHelper', array(), array($this->View), 'TriggerMockHtmlHelper');
$this->getMock('FormHelper', array(), array($this->View), 'TriggerMockFormHelper');
}

$this->Helpers->load('TriggerMockHtml');
$this->Helpers->load('TriggerMockForm');

$this->Helpers->TriggerMockHtml->expects($this->once())->method('beforeRender')
->with('one', 'two');
$this->Helpers->TriggerMockForm->expects($this->once())->method('beforeRender')
->with('one', 'two');

$this->mockObjects[] = $this->Helpers->TriggerMockForm;

$this->assertNull($this->Helpers->trigger('beforeRender', array('one', 'two')));
}

/**
* test trigger and disabled helpers.
*
* @return void
*/
function testTriggerWithDisabledHelpers() {
if (!class_exists('TriggerMockHtmlHelper')) {
$this->getMock('HtmlHelper', array(), array(), 'TriggerMockHtmlHelper', false);
$this->getMock('FormHelper', array(), array(), 'TriggerMockFormHelper', false);
}

$this->Helpers->load('TriggerMockHtml');
$this->Helpers->load('TriggerMockForm');

$this->Helpers->TriggerMockHtml->expects($this->once())->method('beforeRender')
->with('one', 'two');
$this->Helpers->TriggerMockForm->expects($this->never())->method('beforeRender');

$this->mockObjects[] = $this->Helpers->TriggerMockForm;
$this->mockObjects[] = $this->Helpers->TriggerMockHtml;

$this->Helpers->disable('TriggerMockForm');

$this->assertNull($this->Helpers->trigger('beforeRender', array('one', 'two')));
}

/**
* test normalizeObjectArray
*
* @return void
*/
function testnormalizeObjectArray() {
$helpers = array(
'Html',
'Foo.Bar' => array('one', 'two'),
'Something',
'Banana.Apple' => array('foo' => 'bar')
);
$result = ObjectCollection::normalizeObjectArray($helpers);
$expected = array(
'Html' => array('class' => 'Html', 'settings' => array()),
'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')),
'Something' => array('class' => 'Something', 'settings' => array()),
'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')),
);
$this->assertEquals($expected, $result);
}
}

0 comments on commit 1531a72

Please sign in to comment.