OOP basics
Here is the OOP crash course video: And here is the Introduction to programming and Computer Science video Reference OOP programming basics Introduction to programming and computer science ...
Here is the OOP crash course video: And here is the Introduction to programming and Computer Science video Reference OOP programming basics Introduction to programming and computer science ...
Problem Add Delete button in AdminFile/update under New Attribute Create actionDeleteAttr Pass Behat tests How Add Delete button in /protected/adminFile/_form.php <tbody> <?php foreach($model->fileAttributes as $fa) { ?> <tr class="row-edit-<?= $fa->id ?>"> <td> <?= $fa->attribute->attribute_name ?> </td> <td> <?= $fa->value ?> </td> <td> <?= $fa->unit ? $fa->unit->name : '' ?> </td> <td><a role="button" class="btn btn-edit js-edit" data="<?= $fa->id ?>">Edit</a></td> <td><a role="button" class="btn js-delete" name="delete_attr" data="<?= $fa->id ?>">Delete</a></td> </tr> <?php } ?> </tbody> <script> $('.js-delete').click(function (e) { e.preventDefault(); id = $(this).attr('data'); console.log(id); row = $('.row-edit-' + id); console.log(row); if (id) { $.post('/adminFile/deleteAttr', { 'id': id }, function(result) { if (result) { // console.log(result); } }, 'json'); } window.location.reload(); }) </script> Create actionDeleteAttr in /controller/AdminFileController.php public function actionDeleteAttr() { if (!Yii::app()->request->isPostRequest) throw new CHttpException(404, "The requested page does not exist."); if (isset($_POST['id'])) { $attribute = FileAttributes::model()->findByPk($_POST['id']); if ($attribute) { $attribute->delete(); Yii::app()->end(); } } } Create admin-file.feature @admin-file @issue-457 Feature: An admin user can edit and delete attribute in admin file page As an admin user I can edit/delete attribute So that I can associate various attributes to files Background: Given Gigadb web site is loaded with production-like data @ok @issue-457 @javascript Scenario: Guest user cannot visit admin file update page Given I am not logged in to Gigadb web site When I go to "/adminFile/update/" Then I should see "Login" @ok @issue-457 @javascript Scenario: Sign in as admin and visit admin file update page and see New Attribute, Edit, Delete buttons Given I sign in as an admin When I am on "/adminFile/update/id/13973" Then I should see a button "New Attribute" And I should see a button input "Edit" And I should see a button input "Delete" @ok @issue-457 @javascript Scenario: Sign in as admin to delete attribute Given I sign in as an admin And I am on "/adminFile/update/id/13973" And I should see a button input "Delete" When I press "Delete" And I wait "3" seconds Then I should not see a button "Delete" Run behat test with Database set up 4.1 only accptance test #!/usr/bin/env bash set -e -u ./tests/acceptance #./tests/unit_functional #./tests/coverage 4.2 change tag to @wip ...
A metaphor of API Think of an API like a menu in a restaurant. The menu provides a list of dishes you can order, along with a description of each dish. When you specify what menu items you want, the restaurant’s kitchen does the work and provides you with some finished dishes. You don’t know exactly how the restaurant prepares that food, and you don’t really need to. An API is very much the same thing as a UI, except that it is geared for consumption by software instead of humans. ...
Problem To add a go to page feature in navigating file table. Details refer to this issue View files from large db #437 How Create a Go to page button match the button style with the whole webpage create btn_click class for this onclick button create input box for number, and assign id=pageTarget <style> .btn_click { border: solid 1px #0eb23c; color: #0fad59; padding: 4px 6px 3px 6px; text-decoration: none; background-color: Transparent; outline:none; } input { width: 3%; } input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } .text_box { color: #0fad59; background: #fff; border: solid 1px #0eb23c; outline:none; } </style> <button class="btn_click" onclick="goToPage()"><strong>Go to page</strong></button> <input type="number" id="pageTarget" class="text_box"> <a class="color-background"><strong> of <?= $files->getDataProvider()->getPagination()->getPageCount()?></strong></a> Create a goToPage() function in JavaScript document.getElementById('pageTarget').value gets the value of the input box <?php echo $model->identifier?> gets the paper ID number <?php echo $files->getDataProvider()->getPagination()->getPageCount()?> gets the max page count some requirements: disable input box arrows when userInput > max, return to max when userInput < min, return to min window.location.pathname will get current page url, will crash when go to page 2 and then press 1 so to create an array with default values: let targetUrlArray = ["", "dataset", "view", "id", pageID]; function goToPage() { var targetPageNumber = document.getElementById('pageTarget').value; var pageID = <?php echo $model->identifier?>; //To validate page number var userInput = parseInt(targetPageNumber); var max = <?php echo $files->getDataProvider()->getPagination()->getPageCount() ?>; //To output total pages // console.log(max); var min = 1; if (userInput >= min && userInput <= max) { console.log("Valid page number!"); }else if (userInput > max) { targetPageNumber = max; console.log("Error, return to " + max); } else if (userInput < min) { targetPageNumber = min; console.log("Error, return to " + min); } // var targetUrlArray = Array.apply(null, Array(5)).map(function(_,i) { return window.location.pathname.split("/")[i]});] // Create array with default values let targetUrlArray = ["", "dataset", "view", "id", pageID]; targetUrlArray.push('Files_page', targetPageNumber); window.location = window.location.origin + targetUrlArray.join("/"); // Uncomment will show the target url in console. // console.log(window.location.origin + targetUrlArray.join("/")) } Behat test PhantomJS has been discontinued, so it cannot simulate pressing action on Go to page button. In order to do so, behat.yml and docker-compose.yml need to be updated. ...
To start a local gigaDB server docker-compose run --rm webapp Link to test if the web page is up If there are some build errors Rebuild and up the webapp containers again. docker-compose run --rm webapp If not work, restart the docker container app and rebuild the containers. If not work, check if psql, gigadb, database is presented in ~/.containers/-data and remove it. rm -rf ~/.containers-data/gigadb Run docker-compose run --rm webapp again to rebuild the containers. How to remove images List all images docker images -a Remove all images docker rmi $(docker images -a -q) How to remove container List all containers docker ps -a Stop the containers docker stop $(docker ps -a -q) Remove stopped containers docker rm $(docker ps -a -q) source digital ocean How to run a functional test in a docker environment for testing? Write unit test script and place in protected/tests/functional-test folder. Change the unit_functional script ./bin/phpunit protected/tests/functional-test --verbose --configuration protected/tests/phpunit.xml --no-coverage Run specific unit test: docker-compose run --rm test ./tests/unit_functional Output will be like this: PHPUnit 5.7.27 by Sebastian Bergmann and contributors. Runtime: PHP 7.1.30 with Xdebug 2.9.6 Configuration: /var/www/protected/tests/phpunit.xml ... 3 / 3 (100%) Time: 7.15 seconds, Memory: 14.00MB OK (3 tests, 7 assertions) How to run a functional test on a single file in docker environment? docker oneliner docker-compose run --rm test ./bin/phpunit --testsuite functional --bootstrap protected/tests/bootstrap.php --verbose --configuration protected/tests/phpunit.xml --no-coverage protected/tests/functional/AdminSiteAccessTest.php Or go into docker bash and run phpunit docker-compose run --rm test bash root@45a46a8441d3:/var/www# ./bin/phpunit --testsuite functional --bootstrap protected/tests/bootstrap.php --verbose --configuration protected/tests/phpunit.xml --no-coverage protected/tests/functional/AdminSiteAccessTest.php root@45a46a8441d3:/var/www# ./bin/phpunit --testsuite functional --bootstrap protected/tests/bootstrap.php --verbose --configuration protected/tests/phpunit.xml --no-coverage protected/tests/functional/AdminSiteAccessTest.php PHPUnit 5.7.27 by Sebastian Bergmann and contributors. Runtime: PHP 7.1.30 with Xdebug 2.9.6 Configuration: /var/www/protected/tests/phpunit.xml ... 3 / 3 (100%) Time: 4.18 seconds, Memory: 14.00MB OK (3 tests, 7 assertions) How to run a Behat test in a docker environment for testing Update the scenario syntax specific *.feature file, like: @ok @files Scenario: Files - Call to Actions Given I am not logged in to Gigadb web site When I go to "/dataset/101001" And I follow "Files" Then I should see a link "(FTP site)" to "ftp://climb.genomics.cn/pub/10.5524/101001_102000/101001/" with title "FTP site" Then I should see a button "Table Settings" Check if related functions in features/bootstrap/*.php needed to be updated, eg: public function iShouldSeeTabWithTable($arg1, TableNode $table) { if ("Funding" == $arg1) { $this->minkContext->getSession()->getPage()->clickLink($arg1); //| Funding body | Awardee | Award ID | Comments | foreach($table as $row) { PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Funding body']) ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Awardee']) ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Award ID']) ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Comments']) ); } } elseif("Files" == $arg1) { //| File name | Sample ID | Data Type | File Format | Size | Release date | link | foreach($table as $row) { $link = $row['link']; PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['File name']), "File name match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Sample ID']), "Sample ID match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Data Type']), "Data Type match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['File Format']), "File Format match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Size']), "Size match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Release date']), "Release date match" ); if ($link) { $this->minkContext->assertSession()->elementExists('css',"a.download-btn[href='$link']"); } } } elseif("Sample" == $arg1) { //| Sample ID | Common Name | Scientific Name | Sample Attributes | Taxonomic ID | Genbank Name | foreach($table as $row) { PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Sample ID']), "Sample ID match" ); if($row['Common Name']) { PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Common Name']), "Common Name match" ); } PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Scientific Name']), "Scientific Name match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Sample Attributes']), "Sample Attributes match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Taxonomic ID']), "Taxonomic ID match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Genbank Name']), "Genbank Name match" ); } } else { PHPUnit_Framework_Assert::fail("Unknown type of tab"); } } Assign @wip tag to the working scenario in .feature file, this can smooth the running of behat test. @wip @files Scenario: Files - Call to Actions Given I am not logged in to Gigadb web site When I go to "/dataset/101001" Run the Behat test command on specific scenario. docker-compose run --rm test bin/behat -vv --stop-on-failure --tags @wip ...