Skip to content

Commit 7cf3e5c

Browse files
committed
[TASK] Added more unit tests
1 parent f4e1da4 commit 7cf3e5c

23 files changed

Lines changed: 782 additions & 18 deletions

File tree

src/app/code/community/FireGento/AdminMonitoring/Test/Model/Config.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class FireGento_AdminMonitoring_Test_Model_Config extends EcomDev_PHPUnit_Test_Case
2626
{
2727
/**
28-
* @var FireGento_AdminMonitoring_Model_History
28+
* @var FireGento_AdminMonitoring_Model_Config
2929
*/
3030
protected $_model;
3131

@@ -48,4 +48,47 @@ public function testInstance()
4848
$this->_model
4949
);
5050
}
51+
52+
/**
53+
* @test
54+
*/
55+
public function getObjectTypeExcludes()
56+
{
57+
$objectTypeExcludes = $this->_model->getObjectTypeExcludes();
58+
$this->assertGreaterThan(0, $objectTypeExcludes);
59+
$this->assertContains('FireGento_AdminMonitoring_Model_History', $objectTypeExcludes);
60+
}
61+
62+
/**
63+
* @test
64+
*/
65+
public function getGlobalAdminRouteExcludes()
66+
{
67+
$globalAdminRouteExcludes = $this->_model->getGlobalAdminRouteExcludes();
68+
$this->assertGreaterThan(0, $globalAdminRouteExcludes);
69+
$this->assertContains('admin_sales_order_create_loadBlock', $globalAdminRouteExcludes);
70+
$this->assertNotContains('admin_promo_catalog_save', $globalAdminRouteExcludes);
71+
}
72+
73+
/**
74+
* @test
75+
*/
76+
public function getPartialAdminRouteExcludes()
77+
{
78+
$partialAdminRouteExcludes = $this->_model->getPartialAdminRouteExcludes();
79+
$this->assertGreaterThan(0, $partialAdminRouteExcludes);
80+
$this->assertArrayHasKey('admin_promo_catalog_save', $partialAdminRouteExcludes);
81+
$this->assertArrayNotHasKey('admin_sales_order_create_loadBlock', $partialAdminRouteExcludes);
82+
}
83+
84+
/**
85+
* @test
86+
*/
87+
public function getFieldExcludes()
88+
{
89+
$fieldExcludes = $this->_model->getFieldExcludes();
90+
$this->assertGreaterThan(0, $fieldExcludes);
91+
$this->assertContains('created_at', $fieldExcludes);
92+
$this->assertContains('updated_at', $fieldExcludes);
93+
}
5194
}

src/app/code/community/FireGento/AdminMonitoring/Test/Model/History.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,84 @@ public function testInstance()
4848
$this->_model
4949
);
5050
}
51+
52+
/**
53+
* @test
54+
* @loadFixture ~FireGento_AdminMonitoring/default
55+
*/
56+
public function getOriginalModel()
57+
{
58+
$model = $this->_model->load(2);
59+
$this->assertInstanceOf(
60+
'Mage_Cms_Model_Page',
61+
$model->getOriginalModel()
62+
);
63+
$this->assertEquals(1, $model->getOriginalModel()->getId());
64+
}
65+
66+
/**
67+
* @test
68+
* @loadFixture ~FireGento_AdminMonitoring/default
69+
*/
70+
public function getDecodedContentDiff()
71+
{
72+
$model = $this->_model->load(2);
73+
$this->assertEquals(
74+
array('content_heading' => 'foo baz'),
75+
$model->getDecodedContentDiff()
76+
);
77+
}
78+
79+
/**
80+
* @test
81+
* @loadFixture ~FireGento_AdminMonitoring/default
82+
*/
83+
public function getDecodedContent()
84+
{
85+
$model = $this->_model->load(2);
86+
$this->assertEquals(
87+
array('content_heading' => 'foo bar'),
88+
$model->getDecodedContent()
89+
);
90+
}
91+
92+
/**
93+
* @test
94+
* @loadFixture ~FireGento_AdminMonitoring/default
95+
*/
96+
public function isInsert()
97+
{
98+
$model = $this->_model->load(1);
99+
$this->assertTrue($model->isInsert());
100+
}
101+
102+
/**
103+
* @test
104+
* @loadFixture ~FireGento_AdminMonitoring/default
105+
*/
106+
public function isUpdate()
107+
{
108+
$model = $this->_model->load(2);
109+
$this->assertTrue($model->isUpdate());
110+
}
111+
112+
/**
113+
* @test
114+
* @loadFixture ~FireGento_AdminMonitoring/default
115+
*/
116+
public function isDelete()
117+
{
118+
$model = $this->_model->load(3);
119+
$this->assertTrue($model->isDelete());
120+
}
121+
122+
/**
123+
* @test
124+
* @loadFixture ~FireGento_AdminMonitoring/default
125+
*/
126+
public function isLogin()
127+
{
128+
$model = $this->_model->load(4);
129+
$this->assertTrue($model->isLogin());
130+
}
51131
}

src/app/code/community/FireGento/AdminMonitoring/Test/Model/History/Data.php

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ class FireGento_AdminMonitoring_Test_Model_History_Data extends EcomDev_PHPUnit_
3535
protected function setUp()
3636
{
3737
parent::setUp();
38-
39-
$modelMock = $this->getModelMock('cms/page', array());
40-
$this->replaceByMock('model', 'cms/page', $modelMock);
41-
42-
$this->_model = Mage::getModel('firegento_adminmonitoring/history_data', $modelMock);
38+
$this->_model = Mage::getModel('firegento_adminmonitoring/history_data', Mage::getModel('cms/page'));
4339
}
4440

4541
/**
@@ -52,4 +48,73 @@ public function testInstance()
5248
$this->_model
5349
);
5450
}
51+
52+
/**
53+
* @test
54+
* @loadFixture historyDataCmsPage
55+
*/
56+
public function getSerializedContent()
57+
{
58+
$model = $this->_getModel();
59+
$serializedContent = $model->getSerializedContent();
60+
$this->assertContains('"title":"Foo Baz"', $serializedContent);
61+
}
62+
63+
/**
64+
* @test
65+
* @loadFixture historyDataCmsPage
66+
*/
67+
public function getContent()
68+
{
69+
$model = $this->_getModel();
70+
$content = $model->getContent();
71+
$this->assertGreaterThan(0, count($content));
72+
$this->assertTrue(isset($content['title']));
73+
$this->assertEquals('Foo Baz', $content['title']);
74+
}
75+
76+
/**
77+
* @test
78+
* @loadFixture historyDataCmsPage
79+
*/
80+
public function getOrigContent()
81+
{
82+
$model = $this->_getModel();
83+
$origContent = $model->getOrigContent();
84+
$this->assertGreaterThan(0, count($origContent));
85+
$this->assertTrue(isset($origContent['title']));
86+
$this->assertEquals('Foo Baz', $origContent['title']);
87+
}
88+
89+
/**
90+
* @test
91+
* @loadFixture historyDataCmsPage
92+
*/
93+
public function getObjectType()
94+
{
95+
$model = $this->_getModel();
96+
$this->assertEquals('Mage_Cms_Model_Page', $model->getObjectType());
97+
}
98+
99+
/**
100+
* @test
101+
* @loadFixture historyDataCmsPage
102+
*/
103+
public function getObjectId()
104+
{
105+
$model = $this->_getModel();
106+
$this->assertEquals(99, $model->getObjectId());
107+
}
108+
109+
/**
110+
* Retrieve the changed model
111+
*
112+
* @return FireGento_AdminMonitoring_Model_History_Data
113+
*/
114+
protected function _getModel()
115+
{
116+
$page = Mage::getModel('cms/page')->load(99);
117+
118+
return Mage::getModel('firegento_adminmonitoring/history_data', $page);
119+
}
55120
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tables:
2+
cms/page:
3+
- page_id: 99
4+
title: Foo Baz
5+
identifier: foobar
6+
content_heading: Foo Bar
7+
content: Lorem ipsum dolor sit amet.
8+
is_active: 0
9+
creation_time: 2014-10-01 13:00:00
10+
update_time: 2014-10-01 13:00:00

src/app/code/community/FireGento/AdminMonitoring/Test/Model/History/Diff.php

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ protected function setUp()
3636
{
3737
parent::setUp();
3838

39-
$modelMock = $this->getModelMock('cms/page', array());
40-
$this->replaceByMock('model', 'cms/page', $modelMock);
41-
42-
$dataMock = $this->getModelMock('firegento_adminmonitoring/history_data', array(), false, array($modelMock));
43-
$this->replaceByMock('model', 'firegento_adminmonitoring/history_data', $dataMock);
44-
45-
$this->_model = Mage::getModel('firegento_adminmonitoring/history_diff', $dataMock);
39+
$dataModel = Mage::getModel('firegento_adminmonitoring/history_data', Mage::getModel('cms/page'));
40+
$this->_model = Mage::getModel('firegento_adminmonitoring/history_diff', $dataModel);
4641
}
4742

4843
/**
@@ -55,4 +50,40 @@ public function testInstance()
5550
$this->_model
5651
);
5752
}
53+
54+
/**
55+
* @test
56+
* @loadFixture historyDiffCmsPage
57+
*/
58+
public function hasChanged()
59+
{
60+
$model = $this->_getModel();
61+
$this->assertTrue($model->hasChanged());
62+
}
63+
64+
/**
65+
* @test
66+
* @loadFixture historyDiffCmsPage
67+
*/
68+
public function getSerializedDiff()
69+
{
70+
$model = $this->_getModel();
71+
$this->assertEquals('{"title":"Foo Baz","is_active":0}', $model->getSerializedDiff());
72+
}
73+
74+
/**
75+
* Retrieve the changed model
76+
*
77+
* @return FireGento_AdminMonitoring_Model_History_Diff
78+
*/
79+
protected function _getModel()
80+
{
81+
$page = Mage::getModel('cms/page')->load(99);
82+
$page->setOrigData('title', 'Foo Baz');
83+
$page->setOrigData('is_active', 0);
84+
85+
$dataModel = Mage::getModel('firegento_adminmonitoring/history_data', $page);
86+
87+
return Mage::getModel('firegento_adminmonitoring/history_diff', $dataModel);
88+
}
5889
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tables:
2+
cms/page:
3+
- page_id: 99
4+
title: Foo Bar
5+
identifier: foobar
6+
content_heading: Foo Bar
7+
content: Lorem ipsum dolor sit amet.
8+
is_active: 1
9+
creation_time: 2014-10-01 13:00:00
10+
update_time: 2014-10-01 13:00:00

src/app/code/community/FireGento/AdminMonitoring/Test/Model/Observer/Log.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* Class FireGento_AdminMonitoring_Test_Model_Observer_Log
2424
*/
25-
class FireGento_AdminMonitoring_Test_Model_Observer_Log extends EcomDev_PHPUnit_Test_Case
25+
class FireGento_AdminMonitoring_Test_Model_Observer_Log extends EcomDev_PHPUnit_Test_Case_Controller
2626
{
2727
/**
2828
* @var FireGento_AdminMonitoring_Model_Observer_Log
@@ -48,4 +48,65 @@ public function testInstance()
4848
$this->_model
4949
);
5050
}
51+
52+
/**
53+
* @test
54+
* @loadFixture ~FireGento_AdminMonitoring/default
55+
*/
56+
public function getUserId()
57+
{
58+
$this->_mockAdminSession();
59+
$this->assertEquals(1, $this->_model->getUserId());
60+
}
61+
62+
/**
63+
* @test
64+
* @loadFixture ~FireGento_AdminMonitoring/default
65+
*/
66+
public function getUserName()
67+
{
68+
$this->_mockAdminSession();
69+
$this->assertEquals('admin', $this->_model->getUserName());
70+
}
71+
72+
/**
73+
* @test
74+
* @loadFixture ~FireGento_AdminMonitoring/default
75+
*/
76+
public function getUser()
77+
{
78+
$this->_mockAdminSession();
79+
$this->assertInstanceOf(
80+
'Mage_Admin_Model_User',
81+
$this->_model->getUser()
82+
);
83+
}
84+
85+
/**
86+
* @test
87+
*/
88+
public function getRemoteAddr()
89+
{
90+
$helperMock = $this->getHelperMock('core/http', array('getRemoteAddr'));
91+
$helperMock->expects($this->any())
92+
->method('getRemoteAddr')
93+
->will($this->returnValue('8.8.8.8'));
94+
$this->replaceByMock('helper', 'core/http', $helperMock);
95+
96+
$this->assertEquals('8.8.8.8', $this->_model->getRemoteAddr());
97+
}
98+
99+
/**
100+
* Mock an admin session with returning the same admin user
101+
*/
102+
protected function _mockAdminSession()
103+
{
104+
$adminUser = Mage::getModel('admin/user')->load(1);
105+
106+
$sessionMock = $this->getModelMock('admin/session', array('getUser'));
107+
$sessionMock->expects($this->any())
108+
->method('getUser')
109+
->will($this->returnValue($adminUser));
110+
$this->replaceByMock('singleton', 'admin/session', $sessionMock);
111+
}
51112
}

0 commit comments

Comments
 (0)