mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Removing duplicated tests, and tests for methods that are not implemented in the subclasses.
This commit is contained in:
parent
7b4ffa2ee9
commit
1531a7226e
4 changed files with 2 additions and 250 deletions
|
@ -118,25 +118,4 @@ class TaskCollectionTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
|
@ -119,162 +119,6 @@ class ComponentCollectionTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
|
@ -189,11 +189,11 @@ class ObjectCollectionTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
|
|
@ -116,75 +116,4 @@ class HelperCollectionTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue