llorien / crm

WordPress plugin installed on brithon.com to support managing customer relationship
0 stars 0 forks source link

Auto testing #48

Closed xueruini closed 9 years ago

xueruini commented 9 years ago

Let's move to the field of auto testing to increase our confidence upon committing. Two types of auto testing will be conducted in the future:

  1. php unit test towards all model apis
  2. user-defined utilities towards all ajax apis

@helloqiu we'd like you to get your feet wet with this issue. The team, especially, @excelle08 will work with you. Will talk to you when you are back.

helloqiu commented 9 years ago

I'm back.Reading the docs and learning now^_^.

xueruini commented 9 years ago

https://phpunit.de/manual/current/en/phpunit-book.html

There are also phpunit for wordpress. And, you can also check the unit test of framework.

helloqiu commented 9 years ago

I have read it and I'm going to test something now.^_^ Thanks for help.I'll keep on asking questions.@lukehl

xueruini commented 9 years ago

Yuyang, Wei and I talked about the unit test this morning. And, Yuyang will begin from a simple plugin, then move to brithon-crm.

helloqiu commented 9 years ago

I followed this article https://pippinsplugins.com/unit-tests-wordpress-plugins-setting-up-testing-suite/ to create a test but I found that the user of mysql wp didn't have the permission to create a new database.So we have to use the user root to run the command like this:

bash bin/install-wp-tests.sh wordpress_test root password localhost latest

And then grant the wp the permission like this:

mysql> grant all on wordpress_test.* to wp@'%' identified by 'wp'
helloqiu commented 9 years ago

I create a new branch called unit-test.I'll copy the files in the tests folder in vagrant here after testing something. @xueruini @lukehl Maybe I can write an article about how to use php-unit to test functions built with the framework. :) If I find any mistakes I'll call you. @excelle08 :D

xueruini commented 9 years ago

Maybe I can write an article about how to use php-unit to test functions built with the framework. :)

Great.

xueruini commented 9 years ago

@helloqiu you'd better port the current unit-test for local GAE environment. Then, everyone will benefit from this great work.

helloqiu commented 9 years ago

Get.I'm working on it.

helloqiu commented 9 years ago

I got errors while tried using wp-cli in the GAE environment. Here are errors:

Fatal error: Class 'Memcache' not found in /Users/helloqiu/birchpress/brithon.com/app/wordpress/wp-content/object-cache.php on line 385

I google it but there're no answers.And I find there is object-cache.php in the wordpress/wp-cpntent/ which means that memcache has been installed. How to fix it?

xueruini commented 9 years ago

I got errors while tried using wp-cli in the GAE environment.

@helloqiu does this error appear when you run the application in local GAE without wp-cli?

helloqiu commented 9 years ago

Nope. I installed wordpress and brithon-crm and they both work fine.

xueruini commented 9 years ago

GAE bundle includes Memcached.php in `/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/php/sdk/google/appengine/runtime'.

helloqiu commented 9 years ago

I still can't run wp-cli correctly. I tried to install php plugin memcache but the property "rootless" of OS X 10.11 made me to get errors while install everything.And after turning it off I got errors that can't find zlib while installing memcache. Where is the path of zlib in OS X? I try requiring Memcached.php or Memcache.php in the object-cache.php but there appears more errors. I'm confused now.QAQ

helloqiu commented 9 years ago

I run wpsuccessfully after moving the object-cache.php and disabling the plugin appengine.

But there's another problem.I got error

Error: Error creating file: /Users/helloqiu/birchpress/brithon.com/app/wordpress/wp-content/plugins/unit-test/tests/bootstrap.php

while running wp scaffold plugin-tests unit-test.

helloqiu commented 9 years ago

I make a mistake.I should run wp scaffold plugin-tests brithon-crm. It's OK now.

xueruini commented 9 years ago

Excellent job!

Waiting for you commit!

helloqiu commented 9 years ago

Another error appears. I run phpunit after running wp scaffold plugin-tests brithon-crm but I got some strange errors.

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /private/tmp/wordpress/wp-includes/wp-db.php on line 1482

Warning: mysql_connect(): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1482
<!DOCTYPE html>
<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono
-->
<html xmlns="http://www.w3.org/1999/xhtml" dir='ltr'>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width">
    <title>WordPress &rsaquo; Error</title>
    <style type="text/css">
        html {
            background: #f1f1f1;
        }
        body {
            background: #fff;
            color: #444;
            font-family: "Open Sans", sans-serif;
            margin: 2em auto;
            padding: 1em 2em;
            max-width: 700px;
            -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.13);
            box-shadow: 0 1px 3px rgba(0,0,0,0.13);
        }
        h1 {
            border-bottom: 1px solid #dadada;
            clear: both;
            color: #666;
            font: 24px "Open Sans", sans-serif;
            margin: 30px 0 0 0;
            padding: 0;
            padding-bottom: 7px;
        }
        #error-page {
            margin-top: 50px;
        }
        #error-page p {
            font-size: 14px;
            line-height: 1.5;
            margin: 25px 0 20px;
        }
        #error-page code {
            font-family: Consolas, Monaco, monospace;
        }
        ul li {
            margin-bottom: 10px;
            font-size: 14px ;
        }
        a {
            color: #21759B;
            text-decoration: none;
        }
        a:hover {
            color: #D54E21;
        }
        .button {
            background: #f7f7f7;
            border: 1px solid #cccccc;
            color: #555;
            display: inline-block;
            text-decoration: none;
            font-size: 13px;
            line-height: 26px;
            height: 28px;
            margin: 0;
            padding: 0 10px 1px;
            cursor: pointer;
            -webkit-border-radius: 3px;
            -webkit-appearance: none;
            border-radius: 3px;
            white-space: nowrap;
            -webkit-box-sizing: border-box;
            -moz-box-sizing:    border-box;
            box-sizing:         border-box;

            -webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 0 rgba(0,0,0,.08);
            box-shadow: inset 0 1px 0 #fff, 0 1px 0 rgba(0,0,0,.08);
            vertical-align: top;
        }

        .button.button-large {
            height: 29px;
            line-height: 28px;
            padding: 0 12px;
        }

        .button:hover,
        .button:focus {
            background: #fafafa;
            border-color: #999;
            color: #222;
        }

        .button:focus  {
            -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2);
            box-shadow: 1px 1px 1px rgba(0,0,0,.2);
        }

        .button:active {
            background: #eee;
            border-color: #999;
            color: #333;
            -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
            box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
        }

            </style>
</head>
<body id="error-page">
    <p>
<h1>Error establishing a database connection</h1>
<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>localhost</code>. This could mean your host's database server is down.</p>
<ul>
    <li>Are you sure you have the correct username and password?</li>
    <li>Are you sure that you have typed the correct hostname?</li>
    <li>Are you sure that the database server is running?</li>
</ul>
<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>
</p></body>
</html>
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /private/tmp/wordpress/wp-includes/wp-db.php on line 1482

Warning: mysql_connect(): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1482

wp_die called
Message :
<h1>Error establishing a database connection</h1>
<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>localhost</code>. This could mean your host's database server is down.</p>
<ul>
    <li>Are you sure you have the correct username and password?</li>
    <li>Are you sure that you have typed the correct hostname?</li>
    <li>Are you sure that the database server is running?</li>
</ul>
<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>

Title :

wp_die called
Message :
<h1>Error establishing a database connection</h1>
<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>localhost</code>. This could mean your host's database server is down.</p>
<ul>
    <li>Are you sure you have the correct username and password?</li>
    <li>Are you sure that you have typed the correct hostname?</li>
    <li>Are you sure that the database server is running?</li>
</ul>
<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>

Title :

Warning: Cannot modify header information - headers already sent by (output started at /private/tmp/wordpress-tests-lib/includes/bootstrap.php:55) in /private/tmp/wordpress/wp-includes/pluggable.php on line 1207

It seems that the wordpress died because of the mysql.

xueruini commented 9 years ago

Does /private/tmp/wordpress/wp-includes/wp-db.php really exist in your box?

helloqiu commented 9 years ago

Yes.

helloqiu commented 9 years ago

I think maybe this issue is caused by mysql.So I'm going to reinstall mysql and see if it will help.

helloqiu commented 9 years ago

I reinstall mysql but it seems that phpunit still can't connect to the database. @starsharp06sharp Does this issue appear on your computer?

helloqiu commented 9 years ago

I find a way to solve part of the issue. I notice this warning:

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452

And it means that mysqli_real_connect() can't connect to mysql. I google it and here's my solution:

cd /var 
sudo mkdir mysql
sudo chmod 755 mysql
cd mysql
sudo ln -s /tmp/mysql.sock mysql.sock

But there still appears errors:

Fatal error: Class 'WP_REST_Server' not found in /private/tmp/wordpress-tests-lib/includes/spy-rest-server.php on line 3

Does anyone have ideas what is WP_REST_Server ? @birchpress/project-cloud

helloqiu commented 9 years ago

I finally make it. :D It's a bug of wp-cli(https://github.com/wp-cli/wp-cli/issues/2129). And they provide a new install-we-test.sh and this bug will be fixed in the new version of wp-cli which will be published next week. Now everything is OK.

xueruini commented 9 years ago

Excellent job!

On Sun, Oct 18, 2015 at 8:18 AM, Yuyang Zhang(helloqiu) < notifications@github.com> wrote:

I finally make it. :D It's a bug of wp-cli(wp-cli/wp-cli#2129 https://github.com/wp-cli/wp-cli/issues/2129). And they provide a new install-we-test.sh https://raw.githubusercontent.com/wp-cli/wp-cli/master/templates/install-wp-tests.sh and this bug will be fixed in the new version of wp-cli which will be published next week. Now everything is OK.

— Reply to this email directly or view it on GitHub https://github.com/birchpress/brithon-crm/issues/48#issuecomment-148998376 .

Ray Xue

xueruini commented 9 years ago

Let's close this issue.