Welcome Guest, Not a member yet? Register   Sign In
  Some help for Unit Testing, part II
Posted by: El Forum - 04-14-2008, 12:23 AM - Replies (8)

[eluser]t'mo[/eluser]
(continued from Part I)

Last time I shared how I made a Controller subclass that had some helpful methods for simplifying use of CI's Unit Testing class. The primary benefit was that you could point your browser to your test class and see your test results nicely formatted in the browser:

Code:
http://localhost/path/to/app/test/something

One downside, though, is that you have to remember all the "somethings" you've written tests for and point your browser at each of them. What I really wanted was a way to see *all* the results of *all* my test classes together.

Enter the command line. Following the lead from an entry in the wiki (cron scripts), I saw it would be possible, with a little modification, to create a version of "index.php" that would invoke an arbitrary path into my application. I created a copy of index.php called "cmdline.php" and added one line to set the path into my app:

Code:
...
$_SERVER['PATH_INFO'] = $argv[1]; // <-- My new addition

// next line is where CI gets its start
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
?&gt;

For example, I run my "Product" model's test class from the command line like this:

Code:
$ php cmdline.php /test/products

From here it was just a short step to producing a shell script that would execute all my tests:

Code:
#!/bin/sh

for f in `ls controllers/test`; do
  g=/test/`echo $f | sed 's/.php//'`
  php cmdline.php $g
done

While running my test suite on the command line, I don't want to see HTML output - it's too hard to parse visually. I hinted at this in part I, but didn't explain. You may recall this snippet from MY_TestController::index:

Code:
if ($_SERVER['SCRIPT_NAME'] == 'cmdline.php') { // YES! this is the line; pay attention, grasshopper
      $this->load->view('test/simpleResults', $data);
    }
    else ...

So, I just load a different view, depending on where I'm running the test from. The simplified view says either "OK" or "Failed" for each test (plus a handy 'print_r' on the failed response):

Code:
=========================================================
Unit test results for &lt;?=$modelname."\n"?&gt;
=========================================================
&lt;?php
foreach ($results as $result) {
  if ($result['Result'] == 'Passed') {
    print "OK: " . $result['Test Name'] . "\n";
  }
  else {
    print "Failed: ";
    print_r($result);
  }
}
?&gt;

Quick, easy, mostly painless, eh? Well, unless you're on Windows...then I don't know what you'll do for a "shell". ;-)

---

I originally planned on stopping the "unit testing help" series here, but questions in another thread about "how to test the front end", plus some neat stuff I saw at work the other day in Ruby, have prompted me to look at how I might do automated acceptance testing with CI...so there will be more to come.


  mogileFS
Posted by: El Forum - 04-14-2008, 12:05 AM - Replies (1)

[eluser]Ignacio[/eluser]
Anybody here are tried with this file distribution system?
Thanks.


  Expression Engine written in CI
Posted by: El Forum - 04-13-2008, 11:34 PM - Replies (23)

[eluser]taewoo[/eluser]
Does anyone know the ETA on EE 2.0 written in CI?
I can't wait! (Prairie-doggin'!)


  InkType.org is Unofficially Launched
Posted by: El Forum - 04-13-2008, 11:18 PM - Replies (27)

[eluser]Developer13[/eluser]
Hi All -

I have "unofficially" launched InkType.org, the new home for InkType (blogging platform built on CodeIgniter... and yes, InkType.org runs on InkType!).

I say this is an "unofficial" launch since InkType is still in alpha and since the documentation section has a ton of things I need to finish.

Resources:
The Unofficial Launch of the Official InkType Website
InkType User Guide
InkType Support Forums

Please take a look around, feel free to register in the InkType Support Forums and let me know your thoughts.


  Pagination please
Posted by: El Forum - 04-13-2008, 11:05 PM - Replies (10)

[eluser]RaiNnTeaRs[/eluser]
Hi..can someone help me ( again ) with paging ?
i dont get how it works...
I understand that we need controllers and view models to create something with Ci
my controller name is : dojang.php
and my view file is : news_view.php
index.php is located in www.localhost.com/ci2/index.php

in this news_view i Have 20 lines of rows and i would like to separate them into pages
1st page : 1..10
2nd page : 11..20
I've wrote this code on my controller file (dojang.php) and it didnt work, can someone help me solve this problem ? thanks a million lol.
$this->db->from('tabel_news');
$this->db->orderby("tanggal","asc");
$query = $this->db->get();
$data['query']=$query;

$config['base_url']='http://192.168.1.188/ci2/index.php/dojang/news_view';
$config['total_rows']='200';
$config['per_page']='10';
$config['uri_segment']='4';

$this->pagination->initialize($config);
echo $this->pagination->create_links();
//LOAD VIEW
$this->load->view('news_view',$data);


  Application folder; Where does it need to be?
Posted by: El Forum - 04-13-2008, 10:46 PM - Replies (6)

[eluser]Michael;[/eluser]
Quick question... Does the application folder need to be in the webroot or can it reside outside like the system folder? Then, extending on that can an index.php be placed in a subdomain location and then use the same apppath as everything else.

i.e.

system
application

->public_html

-> -> www.example.com
-> -> -> index.php

-> ->subdomain.example.com
-> -> -> index.php


  Where can I read the changelog?
Posted by: El Forum - 04-13-2008, 08:52 PM - Replies (7)

[eluser]louis w[/eluser]
Can I read the changelog somewhere online without downloading the latest build from svn?

I checked out the online repository.


  using xajax in button and textfield
Posted by: El Forum - 04-13-2008, 08:28 PM - Replies (6)

[eluser]pandjie[/eluser]
Hi,
I have a problem in using xajax and CI. I have a button and a textfield input. I want a scenario like this : when the button pressed, some text displayed in text field input. I have code like this :

Code:
&lt;?php
    class Formajax Extends Controller {
        function Formajax(){
            parent :: Controller();
            $this->load->library('xajax');
            $this->load->helper('url');
            $this->xajax->registerFunction(array ('process_form',& $this,'process_form'));
            $this->xajax->processRequest();
        }
        
        function process_form($form_data){
            $objResponse = new xajaxResponse();
            $result = "Your name is  panji";
            $name = $form_data['txt_value'];
            
            $objResponse->addAssign($name, "value", $result);
            return $objResponse;
        }
        
        function index(){
            $template['xajax_js'] = $this->xajax->getJavascript(base_url());
            $this->load->view('coba/form',$template);
        }
    }
?&gt;


and HTML code like this :
Code:
&lt;form name="ajaxform" id="ajaxform" onsubmit="return false;"&gt;
               &lt;input type="submit" value="submit" onclick="xajax_process_form(xajax.getFormValues('ajaxform'));"/&gt;
          &lt;input type="text" name="txt_value" value="" size="20"/&gt;

  &lt;/form&gt;

but, when I pressed the button no text was displayed.
what's wrong ?


  Model or Controller - Where to Validate
Posted by: El Forum - 04-13-2008, 04:21 PM - Replies (6)

[eluser]louis w[/eluser]
Previously I was skipping the Model layer when making small sites. Preparing for a larger application and would like to utilize the MVC pattern a bit more.

I am wondering in what layer do you validate the data? Do you do it before you pass your data to the Model (in the Controller) or before you do your database operation (in the Model)?

Wondering if the Model contains anything besides very bare bone database interaction.


  CI 1.6.1 manual as chm or pdf??
Posted by: El Forum - 04-13-2008, 11:48 AM - Replies (8)

[eluser]gunter[/eluser]
Hi!
Where can I find the actual CI 1.6.1 manual as pdf, or better as chm help file?
I cannot find them...


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
SQL server connection not...
by falagar2k
1 hour ago
Validation | trim
by Gary
1 hour ago
Problem with session hand...
by Julesb
2 hours ago
External script access to...
by PomaryLinea
2 hours ago
Is it possible to go back...
by Bosborne
3 hours ago
VIRUS reported after Chro...
by InsiteFX
7 hours ago
Codeigniter4 version 4.5....
by kenjis
Yesterday, 04:10 PM
Cannot access protected p...
by xsPurX
Yesterday, 02:10 PM
Update to v4.5.1, same us...
by xsPurX
Yesterday, 08:31 AM
How to use Codeigniter wi...
by kenjis
Yesterday, 05:06 AM

Forum Statistics
» Members: 85,462
» Latest member: webskittersltd
» Forum threads: 77,582
» Forum posts: 376,014

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB