예제 #1
0
<?php

PHPUnit_Akelos_autoload::addFolder(AK_PHPUNIT_TESTSUITE_FIXTURES);
class TestModelTest extends PHPUnit_Model_TestCase
{
    function testCreateTableOnTheFly()
    {
        #we take a name that we won't use anywhere else
        $this->createTable('UnusualName', 'id,title');
        $this->assertTrue(self::table_exists('unusual_names'));
        $this->assertTableHasColumns('unusual_names', array('id', 'title'));
        $this->drop('unusual_names');
    }
    function testGenerateModelOnTheFly()
    {
        $this->assertFalse(class_exists('UnusualName', false));
        $this->generateModel('UnusualName');
        $this->assertTrue(class_exists('UnusualName', false));
        #we need a table before we can instantiate an ActiveRecord
        $this->createTable('UnusualName', 'id,title');
        $this->assertType('ActiveRecord', new UnusualName());
        $this->drop('unusual_names');
    }
    function testCreateTableUsingAnInstaller()
    {
        $this->createTable('Person');
        $this->assertTrue(self::table_exists('people'));
        $this->assertTableHasColumns('people', array('id', 'first_name', 'last_name', 'updated_at', 'created_at'));
        $this->drop('people');
    }
    function testInstantiateModel()
예제 #2
0
 static function deleteExtraFolders()
 {
     return self::$extra_folders = array();
 }
예제 #3
0
 function findFixtureForModel($model_name)
 {
     $fixture_file_name = AkInflector::tableize($model_name) . '.yaml';
     $include_path = array(AK_PHPUNIT_TESTSUITE_FIXTURES, AK_APP_DIR . DS . 'data');
     return PHPUnit_Akelos_autoload::searchFilenameInPath($include_path, $fixture_file_name);
 }
예제 #4
0
<?php

PHPUnit_Akelos_autoload::addFolder(dirname(dirname(__FILE__)) . DS . 'lib');
class Test_of_AkRouter_Class extends PHPUnit_Framework_TestCase
{
    var $Router;
    var $url_prefix = '';
    function createRequest($url, $method = 'get')
    {
        $Request = $this->getMock('AkRequest', array('getRequestedUrl', 'getMethod'));
        $Request->expects($this->any())->method('getRequestedUrl')->will($this->returnValue($url));
        $Request->expects($this->any())->method('getMethod')->will($this->returnValue($method));
        return $this->Request = $Request;
    }
    function setUp()
    {
        $this->Router = new AkRouter();
        $this->url_prefix = AK_URL_REWRITE_ENABLED ? '' : '/?ak=';
        $this->Router->connect('/topic/:id', array('controller' => 'topic', 'action' => 'view', 'id' => COMPULSORY), array('id' => '[0-9]+'));
        $this->Router->connect('/topic/:id/unread', array('controller' => 'topic', 'action' => 'unread', 'id' => COMPULSORY), array('id' => '[0-9]+'));
        $this->Router->connect('/lists/:action/:id/:option', array('controller' => 'todo', 'option' => COMPULSORY));
        $this->Router->connect('/setup/*config_settings', array('controller' => 'setup'));
        $this->Router->connect('/redirect/:url', array('controller' => 'redirect'));
        $this->Router->connect('/regex/:text/:int', array('text' => '/[A-Za-z]+/', 'int' => '/[0-9]+/', 'controller' => 'regex'));
        $this->Router->connect('/customize/*options/:action', array('controller' => 'themes', 'options' => 3));
        $this->Router->connect('/blog/:action/:id', array('controller' => 'post', 'action' => 'list', 'id' => OPTIONAL, 'requirements' => array('id' => '/\\d{1,}/')));
        $this->Router->connect('/:year/:month/:day', array('controller' => 'articles', 'action' => 'view_headlines', 'year' => COMPULSORY, 'month' => 'all', 'day' => OPTIONAL), array('year' => '/20\\d{2}/', 'month' => '/1?\\d{1,2}/', 'day' => '/[1-3]?\\d{1,2}/'));
        $this->Router->connect('/:webpage', array('controller' => 'page', 'action' => 'view_page', 'webpage' => 'index'), array('webpage' => '/[\\w_]+/'));
        $this->Router->connect('/', array('controller' => 'page', 'action' => 'view_page', 'webpage' => 'index'));
        $this->Router->connect('/:controller/:action/:id');
    }
예제 #5
0
 function testAllowAddingMultipleFoldersAsArgumentsList()
 {
     PHPUnit_Akelos_autoload::deleteExtraFolders();
     PHPUnit_Akelos_autoload::addFolder(__FILE__, AK_PHPUNIT_TESTSUITE_FIXTURES);
     $this->assertEquals(array(dirname(__FILE__), AK_PHPUNIT_TESTSUITE_FIXTURES), PHPUnit_Akelos_autoload::$extra_folders);
 }
예제 #6
0
<?php

PHPUnit_Akelos_autoload::addFolder(__FILE__);
class AuthorsOfAPostTest extends PHPUnit_Model_TestCase
{
    function testPostIsWrittenByAnAuthor()
    {
        $this->useModel('Post');
        list(, $People) = $this->useModel('Person');
        $FirstPost = $this->createPost("title: First Post,written_by: {$People['sigmund']->id}");
        $Reloaded = $this->Post->find($FirstPost->id, array('include' => 'author'));
        $this->assertEquals($Reloaded->author->id, $People['sigmund']->find()->id);
        $this->assertEquals('Sigmund', $Reloaded->author->first_name);
    }
    function testDeleteCommentFromAPost()
    {
        list($Post) = $this->useModel('Post');
        list($Comment) = $this->useModel('Comment');
        $MyPost = $this->createPost('title: First Post');
        $MyComment = $this->createComment("name: My 2 cents,post_id: {$MyPost->id}");
        $Reloaded = $Post->find('first');
        $Reloaded->comment->delete($MyComment);
        $this->assertEquals(0, $Comment->count());
    }
}