From 826d1b868be3ea1a45fbdfa0e5f205649cf96fe0 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 22 Feb 2016 21:23:15 +0200 Subject: [PATCH] Enable auto renewing and updated Travis config --- .travis.yml | 24 +- app/Console/Commands/SendRenewalInvoices.php | 2 +- app/Console/Kernel.php | 1 + app/Libraries/Utils.php | 2 +- app/Listeners/SubscriptionListener.php | 20 ++ app/Ninja/Repositories/AccountRepository.php | 9 +- tests/_bootstrap.php.default | 2 +- .../_generated/AcceptanceTesterActions.php | 315 +++++++++++++----- tests/acceptance.suite.yml | 2 +- tests/functional.suite.yml | 2 +- 10 files changed, 276 insertions(+), 103 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3b0e7301e69..bcfe155094b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,26 +54,26 @@ before_script: - php artisan db:seed --no-interaction # default seed - php artisan db:seed --no-interaction --class=UserTableSeeder # development seed # Start webserver on ninja.dev:8000 - - php artisan serve --host=ninja.dev --port=8000 & # '&' allows to run in background + - php artisan serve --host=ninja.dev & # '&' allows to run in background # Start PhantomJS - phantomjs --webdriver=4444 & # '&' allows to run in background # Give it some time to start - sleep 5 # Make sure the app is up-to-date - - curl -L http://ninja.dev:8000/update + - curl -L http://ninja.dev/update script: - php ./vendor/codeception/codeception/codecept run --debug acceptance AllPagesCept.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance APICest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance CheckBalanceCest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance ClientCest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance CreditCest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance InvoiceCest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance InvoiceDesignCest.php - - php ./vendor/codeception/codeception/codecept run acceptance OnlinePaymentCest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance PaymentCest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance TaskCest.php - - php ./vendor/codeception/codeception/codecept run --debug acceptance TaxRatesCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance APICest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance CheckBalanceCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance ClientCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance CreditCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance InvoiceCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance InvoiceDesignCest.php + #- php ./vendor/codeception/codeception/codecept run acceptance OnlinePaymentCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance PaymentCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance TaskCest.php + #- php ./vendor/codeception/codeception/codecept run --debug acceptance TaxRatesCest.php #- sed -i 's/NINJA_DEV=true/NINJA_PROD=true/g' .env #- php ./vendor/codeception/codeception/codecept run acceptance GoProCest.php diff --git a/app/Console/Commands/SendRenewalInvoices.php b/app/Console/Commands/SendRenewalInvoices.php index 1e8ea1b49eb1..0faf1304a964 100644 --- a/app/Console/Commands/SendRenewalInvoices.php +++ b/app/Console/Commands/SendRenewalInvoices.php @@ -47,7 +47,7 @@ class SendRenewalInvoices extends Command } $client = $this->accountRepo->getNinjaClient($account); - $invitation = $this->accountRepo->createNinjaInvoice($client); + $invitation = $this->accountRepo->createNinjaInvoice($client, $account); // set the due date to 10 days from now $invoice = $invitation->invoice; diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index bd2720afa96f..d04eab9fad91 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel 'App\Console\Commands\ResetData', 'App\Console\Commands\CheckData', 'App\Console\Commands\SendRenewalInvoices', + 'App\Console\Commands\ChargeRenewalInvoices', 'App\Console\Commands\SendReminders', 'App\Console\Commands\TestOFX', 'App\Console\Commands\GenerateResources', diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 027f512a47df..340cfdfeba48 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -72,7 +72,7 @@ class Utils public static function requireHTTPS() { - if (Request::root() === 'http://ninja.dev:8000') { + if (Request::root() === 'http://ninja.dev') { return false; } diff --git a/app/Listeners/SubscriptionListener.php b/app/Listeners/SubscriptionListener.php index 2d12fcaeb953..0949e6de9c8c 100644 --- a/app/Listeners/SubscriptionListener.php +++ b/app/Listeners/SubscriptionListener.php @@ -24,29 +24,49 @@ class SubscriptionListener { public function createdClient(ClientWasCreated $event) { + if ( ! Auth::check()) { + return; + } + $transformer = new ClientTransformer(Auth::user()->account); $this->checkSubscriptions(ACTIVITY_TYPE_CREATE_CLIENT, $event->client, $transformer); } public function createdQuote(QuoteWasCreated $event) { + if ( ! Auth::check()) { + return; + } + $transformer = new InvoiceTransformer(Auth::user()->account); $this->checkSubscriptions(ACTIVITY_TYPE_CREATE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT); } public function createdPayment(PaymentWasCreated $event) { + if ( ! Auth::check()) { + return; + } + $transformer = new PaymentTransformer(Auth::user()->account); $this->checkSubscriptions(ACTIVITY_TYPE_CREATE_PAYMENT, $event->payment, $transformer, [ENTITY_CLIENT, ENTITY_INVOICE]); } public function createdCredit(CreditWasCreated $event) { + if ( ! Auth::check()) { + return; + } + //$this->checkSubscriptions(ACTIVITY_TYPE_CREATE_CREDIT, $event->credit); } public function createdInvoice(InvoiceWasCreated $event) { + if ( ! Auth::check()) { + return; + } + $transformer = new InvoiceTransformer(Auth::user()->account); $this->checkSubscriptions(ACTIVITY_TYPE_CREATE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT); } diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 2b469bf0fcf7..eab8ebd22794 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -124,13 +124,14 @@ class AccountRepository return false; } - $client = $this->getNinjaClient(Auth::user()->account); - $invitation = $this->createNinjaInvoice($client); + $account = Auth::user()->account; + $client = $this->getNinjaClient($account); + $invitation = $this->createNinjaInvoice($client, $account); return $invitation; } - public function createNinjaInvoice($client) + public function createNinjaInvoice($client, $account) { $account = $this->getNinjaAccount(); $lastInvoice = Invoice::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first(); @@ -142,7 +143,7 @@ class AccountRepository $invoice->public_id = $publicId; $invoice->client_id = $client->id; $invoice->invoice_number = $account->getNextInvoiceNumber($invoice); - $invoice->invoice_date = Auth::user()->account->getRenewalDate(); + $invoice->invoice_date = $account->getRenewalDate(); $invoice->amount = PRO_PLAN_PRICE; $invoice->balance = PRO_PLAN_PRICE; $invoice->save(); diff --git a/tests/_bootstrap.php.default b/tests/_bootstrap.php.default index 33ecdcb60782..2f520aacb010 100644 --- a/tests/_bootstrap.php.default +++ b/tests/_bootstrap.php.default @@ -2,7 +2,7 @@ // This is global bootstrap for autoloading use Codeception\Util\Fixtures; -Fixtures::add('url', 'http://ninja.dev:8000'); +Fixtures::add('url', 'http://ninja.dev'); Fixtures::add('username', 'user@example.com'); Fixtures::add('password', 'password'); diff --git a/tests/_support/_generated/AcceptanceTesterActions.php b/tests/_support/_generated/AcceptanceTesterActions.php index 3135d9aa0510..cebe7fff8f20 100644 --- a/tests/_support/_generated/AcceptanceTesterActions.php +++ b/tests/_support/_generated/AcceptanceTesterActions.php @@ -1,4 +1,4 @@ -getScenario()->runStep(new \Codeception\Step\Action('debugWebDriverLogs', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -166,7 +177,7 @@ trait AcceptanceTesterActions * [!] Method is generated. Documentation taken from corresponding module. * * Sets a cookie with the given name and value. - * You can set additional cookie params like `domain`, `path`, `expire`, `secure` in array passed as last argument. + * You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. * * ``` php * amOnPage('/'); * // opens /register page * $I->amOnPage('/register'); - * ?> * ``` * * @param $page @@ -263,16 +273,31 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Checks that the current page contains the given string. - * Specify a locator as the second parameter to match a specific region. + * Checks that the current page contains the given string (case insensitive). + * + * You can specify a specific HTML element (via CSS or XPath) as the second + * parameter to only search within that element. * * ``` php * see('Logout'); // I can suppose user is logged in - * $I->see('Sign Up','h1'); // I can suppose it's a signup page - * $I->see('Sign Up','//body/h1'); // with XPath - * ?> + * $I->see('Logout'); // I can suppose user is logged in + * $I->see('Sign Up', 'h1'); // I can suppose it's a signup page + * $I->see('Sign Up', '//body/h1'); // with XPath * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->see('strong')` will return true for strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will *not* be true for strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. * * @param $text * @param null $selector @@ -285,16 +310,31 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Checks that the current page contains the given string. - * Specify a locator as the second parameter to match a specific region. + * Checks that the current page contains the given string (case insensitive). + * + * You can specify a specific HTML element (via CSS or XPath) as the second + * parameter to only search within that element. * * ``` php * see('Logout'); // I can suppose user is logged in - * $I->see('Sign Up','h1'); // I can suppose it's a signup page - * $I->see('Sign Up','//body/h1'); // with XPath - * ?> + * $I->see('Logout'); // I can suppose user is logged in + * $I->see('Sign Up', 'h1'); // I can suppose it's a signup page + * $I->see('Sign Up', '//body/h1'); // with XPath * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->see('strong')` will return true for strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will *not* be true for strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. * * @param $text * @param null $selector @@ -308,16 +348,29 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Checks that the current page doesn't contain the text specified. + * Checks that the current page doesn't contain the text specified (case insensitive). * Give a locator as the second parameter to match a specific region. * * ```php * dontSee('Login'); // I can suppose user is already logged in - * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page - * $I->dontSee('Sign Up','//body/h1'); // with XPath - * ?> + * $I->dontSee('Login'); // I can suppose user is already logged in + * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page + * $I->dontSee('Sign Up','//body/h1'); // with XPath * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->dontSee('strong')` will fail on strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will ignore strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. * * @param $text * @param null $selector @@ -330,16 +383,29 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Checks that the current page doesn't contain the text specified. + * Checks that the current page doesn't contain the text specified (case insensitive). * Give a locator as the second parameter to match a specific region. * * ```php * dontSee('Login'); // I can suppose user is already logged in - * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page - * $I->dontSee('Sign Up','//body/h1'); // with XPath - * ?> + * $I->dontSee('Login'); // I can suppose user is already logged in + * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page + * $I->dontSee('Sign Up','//body/h1'); // with XPath * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->dontSee('strong')` will fail on strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will ignore strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. * * @param $text * @param null $selector @@ -350,6 +416,80 @@ trait AcceptanceTesterActions } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ``` php + * seeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeInSource() + */ + public function canSeeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInSource', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ``` php + * seeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * @see \Codeception\Module\WebDriver::seeInSource() + */ + public function seeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInSource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ```php + * dontSeeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeInSource() + */ + public function cantSeeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInSource', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ```php + * dontSeeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * @see \Codeception\Module\WebDriver::dontSeeInSource() + */ + public function dontSeeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInSource', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -790,7 +930,6 @@ trait AcceptanceTesterActions * * @param null $uri * - * @internal param $url * @return mixed * @see \Codeception\Module\WebDriver::grabFromCurrentUrl() */ @@ -1388,7 +1527,7 @@ trait AcceptanceTesterActions * * @param $cssOrXpath * @param $attribute - * @internal param $element + * * @return mixed * @see \Codeception\Module\WebDriver::grabAttributeFrom() */ @@ -1425,7 +1564,28 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * + * Grabs either the text content, or attribute values, of nodes + * matched by $cssOrXpath and returns them as an array. + * + * ```html + * First + * Second + * Third + * ``` + * + * ```php + * grabMultiple('a'); + * + * // would return ['#first', '#second', '#third'] + * $aLinks = $I->grabMultiple('a', 'href'); + * ?> + * ``` + * + * @param $cssOrXpath + * @param $attribute + * @return string[] * @see \Codeception\Module\WebDriver::grabMultiple() */ public function grabMultiple($cssOrXpath, $attribute = null) { @@ -1640,6 +1800,27 @@ trait AcceptanceTesterActions } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeNumberOfElementsInDOM() + */ + public function canSeeNumberOfElementsInDOM($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberOfElementsInDOM', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\WebDriver::seeNumberOfElementsInDOM() + */ + public function seeNumberOfElementsInDOM($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberOfElementsInDOM', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -1957,13 +2138,13 @@ trait AcceptanceTesterActions * ``` * Note that "2" will be the submitted value for the "plan" field, as it is * the selected option. - * + * * Also note that this differs from PhpBrowser, in that * ```'user' => [ 'login' => 'Davert' ]``` is not supported at the moment. * Named array keys *must* be included in the name as above. - * + * * Pair this with seeInFormFields for quick testing magic. - * + * * ``` php * submitForm('#my-form', [ * 'field[]' => 'value', * 'field[]' => 'another value', // 'field[]' is already a defined key * ]); * ``` - * + * * The solution is to pass an array value: - * + * * ```php * // this way both values are submitted * $I->submitForm('#my-form', [ @@ -2179,7 +2360,7 @@ trait AcceptanceTesterActions * If Codeception commands are not enough, this allows you to use Selenium WebDriver methods directly: * * ``` php - * $I->executeInSelenium(function(\Facebook\WebDriver\RemoteWebDriver $webdriver) { + * $I->executeInSelenium(function(\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) { * $webdriver->get('http://google.com'); * }); * ``` @@ -2222,7 +2403,7 @@ trait AcceptanceTesterActions * * ``` php * executeInSelenium(function (\Facebook\WebDriver\RemoteWebDriver $webdriver) { + * $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) { * $handles=$webdriver->getWindowHandles(); * $last_window = end($handles); * $webdriver->switchTo()->window($last_window); @@ -2463,34 +2644,7 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Saves current cookies into named snapshot in order to restore them in other tests - * This is useful to save session state between tests. - * For example, if user needs log in to site for each test this scenario can be executed once - * while other tests can just restore saved cookies. - * - * ``` php - * loadSessionSnapshot('login')) return; - * - * // logging in - * $I->amOnPage('/login'); - * $I->fillField('name', 'jon'); - * $I->fillField('password', '123345'); - * $I->click('Login'); - * - * // saving snapshot - * $I->saveSessionSnapshot('login'); - * } - * ?> - * ``` - * - * @param $name - * @return mixed + * @param string $name * @see \Codeception\Module\WebDriver::saveSessionSnapshot() */ public function saveSessionSnapshot($name) { @@ -2501,11 +2655,8 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Loads cookies from saved snapshot. - * - * @param $name - * @see saveSessionSnapshot - * @return mixed + * @param string $name + * @return bool * @see \Codeception\Module\WebDriver::loadSessionSnapshot() */ public function loadSessionSnapshot($name) { @@ -2516,7 +2667,7 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Inserts SQL record into database. This record will be erased after the test. + * Inserts an SQL record into a database. This record will be erased after the test. * * ``` php * * ``` * - * @param int $num Expected number + * @param int $expectedNumber Expected number * @param string $table Table name * @param array $criteria Search criteria [Optional] * Conditional Assertion: Test won't be stopped on fail * @see \Codeception\Module\Db::seeNumRecords() */ - public function canSeeNumRecords($num, $table, $criteria = null) { + public function canSeeNumRecords($expectedNumber, $table, $criteria = null) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumRecords', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Asserts that found number of records in database + * Asserts that the given number of records were found in the database. * * ``` php * * ``` * - * @param int $num Expected number + * @param int $expectedNumber Expected number * @param string $table Table name * @param array $criteria Search criteria [Optional] * @see \Codeception\Module\Db::seeNumRecords() */ - public function seeNumRecords($num, $table, $criteria = null) { + public function seeNumRecords($expectedNumber, $table, $criteria = null) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumRecords', func_get_args())); } @@ -2638,7 +2789,7 @@ trait AcceptanceTesterActions * * Effect is opposite to ->seeInDatabase * - * Checks if there is no record with such column values in database. + * Asserts that there is no record with the given column values in a database. * Provide table name and column values. * * Example: @@ -2668,7 +2819,7 @@ trait AcceptanceTesterActions * * Effect is opposite to ->seeInDatabase * - * Checks if there is no record with such column values in database. + * Asserts that there is no record with the given column values in a database. * Provide table name and column values. * * Example: diff --git a/tests/acceptance.suite.yml b/tests/acceptance.suite.yml index 05dcbc71eca7..293645697bef 100644 --- a/tests/acceptance.suite.yml +++ b/tests/acceptance.suite.yml @@ -8,7 +8,7 @@ class_name: AcceptanceTester modules: enabled: - WebDriver: - url: 'http://ninja.dev:8000/' + url: 'http://ninja.dev/' window_size: 1024x768 wait: 5 browser: firefox diff --git a/tests/functional.suite.yml b/tests/functional.suite.yml index b89e2023daba..7c84b1000840 100644 --- a/tests/functional.suite.yml +++ b/tests/functional.suite.yml @@ -9,7 +9,7 @@ modules: enabled: - \Helper\Functional - PhpBrowser: - url: 'http://ninja.dev:8000' + url: 'http://ninja.dev' curl: CURLOPT_RETURNTRANSFER: true - Laravel5: