Created
October 4, 2010 00:21
-
-
Save exviva/609080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Admin_ContentTranslationsControllerTest extends Our_Test_ControllerTestCase | |
{ | |
function testEditFindTranslationByIdTheOldWay() | |
{ | |
$this->table->insert(array('key' => 'foo')); | |
$this->get('edit', array('id' => '1')); | |
$this->assertEquals(1, $this->assigns->translation->id); | |
} | |
function testEditFindTranslationByIdTheNewWay() | |
{ | |
$id = $this->table->insert(array('key' => 'foo')); | |
$this->get('edit', array('id' => $id)); | |
$this->assertEquals($id, $this->assigns->translation->id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Admin_ContentTranslationsControllerTest extends Our_Test_ControllerTestCase | |
{ | |
function testIndexAssignTranslationsNewFirst() | |
{ | |
$this->useTable($table = new Our_Model_Translation_Table); | |
$table->insert(array('locale' => 'el', 'key' => 'foo')); | |
$table->insert(array('locale' => 'el', 'key' => 'bar', 'translation' => 'baz')); | |
$this->get('index'); | |
$this->assertNull($this->assigns->translations[0]->translation); | |
$this->assertEquals('baz', $this->assigns->translations[1]->translation); | |
} | |
} | |
abstract class Our_Test_ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase | |
{ | |
public $bootstrap = array('Application', 'bootstrap'); | |
protected $_usedTables = array(); | |
function tearDown() | |
{ | |
foreach ($this->_usedTables as $table) { | |
$table->truncate(); | |
} | |
} | |
function useTable(Our_Db_Table_Abstract $table) | |
{ | |
$this->_usedTables[get_class($table)] = $table; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Our_Test_ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase | |
{ | |
function setUp() | |
{ | |
Zend_Registry::get('database')->rollBack(); | |
parent::setUp(); | |
Zend_Registry::get('database')->beginTransaction(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Our_Test_Listener_DatabaseTransaction implements PHPUnit_Framework_TestListener | |
{ | |
public function startTest(PHPUnit_Framework_Test $test) | |
{ | |
Zend_Registry::get('database')->beginTransaction(); | |
} | |
public function endTest(PHPUnit_Framework_Test $test, $time) | |
{ | |
Zend_Registry::get('database')->rollBack(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Our_Model_Admin_Employee_TableTest extends PHPUnit_Framework_TestCase | |
{ | |
function setUp() | |
{ | |
$this->table = new Our_Model_Admin_Employee_Table; | |
} | |
function tearDown() | |
{ | |
$this->table->truncate(); | |
} | |
function testFindActiveFirstFetchDeletedAsLast() | |
{ | |
$this->table->insert(array('email' => '[email protected]')); | |
$this->table->insert(array('email' => '[email protected]', 'dateDeleted' => new Zend_Db_Expr('NOW()'))); | |
$this->table->insert(array('email' => '[email protected]')); | |
$actual = $this->table->findActiveFirst(); | |
$this->assertEquals(3, $actual->count()); | |
$this->assertNotNull($actual[2]->dateDeleted); | |
} | |
} | |
class Our_Model_QuestionTest extends PHPUnit_Framework_TestCase | |
{ | |
function testUpdateAttributesSaveOnValid() | |
{ | |
$question = Our_Model_Question::create(); | |
$question->updateAttributes(array('question' => 'q', 'answer' => 'a')); | |
$this->assertEquals(1, $question->getTable()->count()); | |
$question->getTable()->truncate(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<listeners> | |
<listener class="Our_Test_Listener_DatabaseTransaction" file="library/Our/Test/Listener/DatabaseTransaction.php"> | |
</listener> | |
</listeners> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment