├── .gitignore ├── .travis.yml ├── Gruntfile.js ├── LICENSE ├── README.md ├── bin └── install-wp-tests.sh ├── bower.json ├── composer.json ├── ingot-premium.php ├── ingot.php ├── ingot_bootstrap.php ├── languages └── ingot.pot ├── package.json ├── phpunit.xml ├── readme.txt ├── releases ├── ingot-0.1.0.zip ├── ingot-0.1.1.zip ├── ingot-0.1.2.zip ├── ingot-0.2.0.1.zip ├── ingot-0.2.0.zip ├── ingot-0.2.1.zip ├── ingot-0.2.2.zip ├── ingot-0.3.0.zip ├── ingot-0.4.0.zip ├── ingot-1.0.0.zip ├── ingot-1.0.1.zip ├── ingot-1.0.2.zip ├── ingot-1.1.0-b-1.zip ├── ingot-1.1.0-b-2.zip ├── ingot-1.1.0-b-3.zip ├── ingot-1.1.0.zip ├── ingot-1.1.1-b-1.zip ├── ingot-1.1.1-b-2.zip ├── ingot-1.2.0.zip ├── ingot-1.3.0.zip ├── ingot-1.3.1.1.zip ├── ingot-1.3.1.zip ├── ingot-1.3.2-b-1.zip ├── ingot-1.3.2-b-2.zip ├── ingot-1.3.2-b-3.zip ├── ingot-1.3.2-b-4.zip └── ingot-1.3.2.zip ├── tests ├── README.md ├── api │ ├── rest-test-case.php │ ├── tests-group_api.php │ ├── tests-products.php │ └── tests-settings.php ├── bootstrap.php ├── crud │ ├── tests-defaults.php │ ├── tests-group_crud.php │ ├── tests-session_crud.php │ ├── tests-settings_crud.php │ ├── tests-tracking.php │ └── tests-variants.php ├── functions_for_tests.php ├── objects │ ├── tests-group-object.php │ ├── tests-posts-by-group.php │ └── tests-price-test.php ├── price │ ├── tests-active-check.php │ ├── tests-price-cookie.php │ ├── tests-price-edd.php │ ├── tests-price-queries.php │ └── tests-price_util.php ├── tests-array-filters.php ├── tests-color_helpers.php ├── tests-cookie-setup.php ├── tests-db.php ├── tests-destination-cookies.php ├── tests-destination-tracking.php ├── tests-destination-utility.php ├── tests-functions.php ├── tests-tests.php └── tests-ui.php └── vendor └── autoload.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | vendor/* 3 | vendor/composer 4 | node_modules 5 | build/* 6 | wp-api 7 | .idea/ 8 | bower_components 9 | assets/vendor 10 | index 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | 5 | - 5.5 6 | - 5.6 7 | - 7.0 8 | - hhvm 9 | - nightly 10 | 11 | env: 12 | - WP_VERSION=latest WP_MULTISITE=0 13 | - WP_VERSION=latest WP_MULTISITE=1 14 | - WP_VERSION=4.4 WP_MULTISITE=0 15 | - WP_VERSION=4.4 WP_MULTISITE=1 16 | 17 | matrix: 18 | exclude: 19 | - php: hhvm 20 | env: WP_VERSION=3.9.2 WP_MULTISITE=0 21 | - php: hhvm 22 | env: WP_VERSION=4.0 WP_MULTISITE=0 23 | 24 | before_script: 25 | - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION 26 | - composer self-update 27 | - npm install -g npm 28 | - bower update 29 | - bower-installer 30 | 31 | script: 32 | - if [[ $TRAVIS_PHP_VERSION = '5.5' && $WP_VERSION = 'latest' && $WP_MULTISITE = '0' 33 | ]]; then phpunit --coverage-clover=coverage.clover; else phpunit; fi 34 | 35 | 36 | after_script: 37 | - if [[ $TRAVIS_PHP_VERSION = '5.5' && $WP_VERSION = 'latest' && $WP_MULTISITE = '0' 38 | ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi 39 | - if [[ $TRAVIS_PHP_VERSION = '5.5' && $WP_VERSION = 'latest' && $WP_MULTISITE = '0' 40 | ]]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; 41 | fi 42 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | 3 | 4 | // Project configuration. 5 | grunt.initConfig({ 6 | pkg : grunt.file.readJSON( 'package.json' ), 7 | shell: { 8 | composer: { 9 | command: 'composer update --no-dev --optimize-autoloader --prefer-dist' 10 | }, 11 | bower: { 12 | command: 'bower update' 13 | }, 14 | activate : { 15 | command: 'composer update --no-dev; bower update; bower-installer' 16 | } 17 | }, 18 | clean: { 19 | post_build: [ 20 | 'build/' 21 | ], 22 | pre_compress: [ 23 | 'build/ingot/vendor/ingot/mabandit/test', 24 | 'build/ingot/vendor/ingot/mabandit/vendor/phpunit', 25 | 'build/ingot/vendor/ingot/mabandit/vendor/symfony', 26 | 'build/ingot/vendor/jaybizzle/crawler-detect/tests', 27 | 'build/ingot/vendor/blainesch/prettyarray/examples', 28 | 'build/ingot/vendor/bin', 29 | 'build/releases', 30 | 'build/ingot/build' 31 | ] 32 | }, 33 | run: { 34 | tool: { 35 | cmd: './composer' 36 | } 37 | }, 38 | copy: { 39 | build: { 40 | options : { 41 | mode :true 42 | }, 43 | src: [ 44 | '**', 45 | '!node_modules/**', 46 | '!releases', 47 | '!releases/**', 48 | '!.git/**', 49 | '!Gruntfile.js', 50 | '!package.json', 51 | '!.gitignore', 52 | '!.gitmodules', 53 | '!.gitattributes', 54 | '!composer.lock', 55 | '!naming-conventions.txt', 56 | '!how-to-grunt.md', 57 | '!.travis.yml', 58 | '!.scrutinizer.yml', 59 | '!phpunit.xml', 60 | '!tests/**', 61 | '!bower_components/**', 62 | '!bin/**', 63 | '!vendor/blainesch/prettyarray/tests/**', 64 | '!vendor/blainesch/prettyarray/examples/**', 65 | '!vendor/jaybizzle/crawler-detect/tests/**', 66 | '!vendor/oefenweb/statistics/tests/**', 67 | '!vendor/oefenweb/statistics/.travis/**', 68 | '!vendor/composer/installers/**', 69 | '!vendor/ingot/mabandit/vendor/bin/**', 70 | '!vendor/ingot/mabandit/test/**', 71 | '!vendor/ingot/mabandit/vendor/phpunit/**', 72 | '!vendor/ingot/mabandit/vendor/psy/**', 73 | '!vendor/ingot/mabandit/vendor/doctrine/**', 74 | '!vendor/ingot/mabandit/vendor/symfony/**', 75 | '!vendor/ingot/mabandit/vendor/sebastian/**', 76 | '!vendor/ingot/mabandit/vendor/nikic/**', 77 | '!vendor/ingot/mabandit/vendor/m6web/**' 78 | ], 79 | dest: 'build/<%= pkg.name %>/' 80 | } 81 | }, 82 | compress: { 83 | main: { 84 | options: { 85 | mode: 'zip', 86 | archive: 'releases/<%= pkg.name %>-<%= pkg.version %>.zip' 87 | }, 88 | expand: true, 89 | cwd: 'build/', 90 | src: [ 91 | '**/*', 92 | '!build/*' 93 | ] 94 | } 95 | }, 96 | gitadd: { 97 | add_zip: { 98 | options: { 99 | force: true 100 | }, 101 | files: { 102 | src: [ 'releases/<%= pkg.name %>-<%= pkg.version %>.zip' ] 103 | } 104 | } 105 | }, 106 | gittag: { 107 | addtag: { 108 | options: { 109 | tag: '<%= pkg.version %>', 110 | message: 'Version <%= pkg.version %>' 111 | } 112 | } 113 | }, 114 | gitcommit: { 115 | commit: { 116 | options: { 117 | message: 'Version <%= pkg.version %>', 118 | noVerify: true, 119 | noStatus: false, 120 | allowEmpty: true 121 | }, 122 | files: { 123 | src: [ 'package.json', 'ingot.php', 'releases/<%= pkg.name %>-<%= pkg.version %>.zip' ] 124 | } 125 | } 126 | }, 127 | gitpush: { 128 | push: { 129 | options: { 130 | tags: true, 131 | remote: 'origin', 132 | branch: 'master' 133 | } 134 | } 135 | }, 136 | replace: { 137 | core_file: { 138 | src: [ 'ingot.php' ], 139 | overwrite: true, 140 | replacements: [{ 141 | from: /Version:\s*(.*)/, 142 | to: "Version: <%= pkg.version %>" 143 | }, { 144 | from: /define\(\s*'INGOT_VER',\s*'(.*)'\s*\);/, 145 | to: "define( 'INGOT_VER', '<%= pkg.version %>' );" 146 | }] 147 | } 148 | }, 149 | uglify: { 150 | frontend: { 151 | files: { 152 | 'vendor/ingot/ingot-core/assets/front-end/js/ingot-click-test.min.js': [ 'vendor/ingot/ingot-core/assets/front-end/js/ingot-click-test.js' ], 153 | 'vendor/ingot/ingot-core/assets/admin/js/ingot-post-editor.min.js' : ['vendor/ingot/ingot-core/assets/admin/js/ingot-post-editor.js' ] 154 | } 155 | }, 156 | admin:{ 157 | files: { 158 | 'vendor/ingot/ingot-core/assets/admin/js/admin-app.min.js': [ 'vendor/ingot/ingot-core/assets/admin/js/admin-app.js' ] 159 | } 160 | } 161 | }, 162 | watch: { 163 | files: [ 164 | 'vendor/ingot/ingot-core/assets/admin/js/admin-app.js', 165 | 'vendor/ingot/ingot-core/assets/front-end/js/ingot-click-test.js' 166 | ], 167 | tasks: ['default'] 168 | }, 169 | addtextdomain: { 170 | options: { 171 | textdomain: 'ignot', 172 | }, 173 | target: { 174 | files: { 175 | src: [ '*.php', '**/*.php', '!node_modules/**', '!tests/**', '!bin/**' ] 176 | } 177 | } 178 | }, 179 | makepot: { 180 | target: { 181 | options: { 182 | domainPath: '/languages', 183 | mainFile: 'ingot.php', 184 | potFilename: 'ingot.pot', 185 | potHeaders: { 186 | poedit: true, 187 | 'x-poedit-keywordslist': true 188 | }, 189 | type: 'wp-plugin', 190 | updateTimestamp: true 191 | } 192 | } 193 | }, 194 | 195 | }); 196 | 197 | //load modules 198 | grunt.loadNpmTasks( 'grunt-contrib-compress' ); 199 | grunt.loadNpmTasks( 'grunt-contrib-clean' ); 200 | grunt.loadNpmTasks( 'grunt-contrib-copy' ); 201 | grunt.loadNpmTasks( 'grunt-git' ); 202 | grunt.loadNpmTasks( 'grunt-text-replace' ); 203 | grunt.loadNpmTasks( 'grunt-shell'); 204 | grunt.loadNpmTasks( 'grunt-contrib-uglify'); 205 | grunt.loadNpmTasks( 'grunt-contrib-watch'); 206 | grunt.loadNpmTasks( 'grunt-wp-i18n' ); 207 | grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] ); 208 | 209 | 210 | 211 | //register default task 212 | grunt.registerTask( 'default', [ 'uglify' ]); 213 | 214 | //release tasks 215 | grunt.registerTask( 'version_number', [ 'replace:core_file' ] ); 216 | grunt.registerTask( 'pre_vcs', [ 'shell:activate', 'version_number', 'copy', 'clean:pre_compress', 'compress' ] ); 217 | grunt.registerTask( 'do_git', [ 'gitadd', 'gitcommit', 'gittag', 'gitpush' ] ); 218 | grunt.registerTask( 'just_build', [ 'shell:composer', 'copy', 'clean:pre_compress', 'compress' ] ); 219 | grunt.registerTask( 'install', [ 'shell:activate' ] ); 220 | 221 | grunt.registerTask( 'release', [ 'pre_vcs', 'do_git', 'clean:post_build' ] ); 222 | 223 | 224 | }; 225 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ingot - Automated A/B Test Tool 2 | All of the benefits of A/B Testing, none of the hassle. 3 | 4 | Ingot is a commercial plugin available from [IngotHQ.com](http://ingothq.com). The plugin is hosted here on a public Github repository in order to better faciliate community contributions from developers and users alike. If you have a suggestion, a bug report, or a patch for an issue, feel free to submit it here. We do ask, however, that if you are using the plugin on a live site that you please purchase a valid license from the website. We cannot provide support or troubleshooting to anyone that does not hold a valid license key. 5 | 6 | ### DEVELOPERS: READ BEFORE CLONING THIS REPO OR DOWNLOADING 7 | If you clone this repo, you will need to get the dependencies via Composer and Bower. Reading the grunt file should make that clear. If you don't know how to do that, but have a reason to need to clone this repo, and make it work, buy a license and contact our support. 8 | 9 | ### Copyright/ License 10 | Copyright 2015 Josh Pollock & Ingot LLC. Licensed under the terms of the GNU GPL v2 or later. 11 | -------------------------------------------------------------------------------- /bin/install-wp-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ $# -lt 3 ]; then 4 | echo "usage: $0 [db-host] [wp-version]" 5 | exit 1 6 | fi 7 | 8 | DB_NAME=$1 9 | DB_USER=$2 10 | DB_PASS=$3 11 | DB_HOST=${4-localhost} 12 | WP_VERSION=${5-latest} 13 | 14 | WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} 15 | WP_CORE_DIR=/tmp/wordpress/ 16 | 17 | set -ex 18 | 19 | install_wp() { 20 | mkdir -p $WP_CORE_DIR 21 | 22 | if [ $WP_VERSION == 'latest' ]; then 23 | local ARCHIVE_NAME='latest' 24 | else 25 | local ARCHIVE_NAME="wordpress-$WP_VERSION" 26 | fi 27 | 28 | wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/${ARCHIVE_NAME}.tar.gz 29 | tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR 30 | 31 | wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php 32 | 33 | if [ ! -d "$WP_CORE_DIR/wp-content/plugins/easy-digital-downloads" ]; then 34 | git clone https://github.com/easydigitaldownloads/Easy-Digital-Downloads $WP_CORE_DIR/wp-content/plugins/easy-digital-downloads 35 | fi 36 | 37 | if [ -d "$WP_CORE_DIR/wp-content/wp-content/plugins/easy-digital-downloads" ]; then 38 | cd $WP_CORE_DIR/wp-content/plugins/easy-digital-downloads 39 | git pull origin master 40 | fi 41 | 42 | if [ ! -d "$WP_CORE_DIR/wp-content/plugins/woocommerce" ]; then 43 | git clone https://github.com/woothemes/woocommerce $WP_CORE_DIR/wp-content/wp-content/plugins/woocommerce 44 | fi 45 | 46 | if [ -d "$WP_CORE_DIR/wp-content/wp-content/plugins/woocommerces" ]; then 47 | cd $WP_CORE_DIR/wp-content/wp-content/plugins/woocommerce 48 | git pull origin master 49 | fi 50 | 51 | 52 | #https://github.com/woothemes/woocommerce 53 | } 54 | 55 | install_test_suite() { 56 | # portable in-place argument for both GNU sed and Mac OSX sed 57 | if [[ $(uname -s) == 'Darwin' ]]; then 58 | local ioption='-i .bak' 59 | else 60 | local ioption='-i' 61 | fi 62 | 63 | # set up testing suite 64 | mkdir -p $WP_TESTS_DIR 65 | cd $WP_TESTS_DIR 66 | svn co --quiet https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ 67 | 68 | wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php 69 | sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php 70 | sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php 71 | sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php 72 | sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php 73 | sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php 74 | } 75 | 76 | install_db() { 77 | # parse DB_HOST for port or socket references 78 | local PARTS=(${DB_HOST//\:/ }) 79 | local DB_HOSTNAME=${PARTS[0]}; 80 | local DB_SOCK_OR_PORT=${PARTS[1]}; 81 | local EXTRA="" 82 | 83 | if ! [ -z $DB_HOSTNAME ] ; then 84 | if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then 85 | EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" 86 | elif ! [ -z $DB_SOCK_OR_PORT ] ; then 87 | EXTRA=" --socket=$DB_SOCK_OR_PORT" 88 | elif ! [ -z $DB_HOSTNAME ] ; then 89 | EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" 90 | fi 91 | fi 92 | 93 | # create database 94 | mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA 95 | } 96 | 97 | install_wp 98 | install_test_suite 99 | if [ -d /var/lib/mysql/databasename ] ; then 100 | install_db 101 | fi 102 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ingot", 3 | "description": "Conversion optimization made easy for WordPress", 4 | "main": "/assets/admin/js", 5 | "authors": [ 6 | "Josh Pollock" 7 | ], 8 | "license": "GPLv2+", 9 | "keywords": [ 10 | "wordpress-plugin" 11 | ], 12 | "homepage": "http://IngotHQ.com", 13 | "moduleType": [], 14 | "private": true, 15 | "ignore": [ 16 | "**/.*", 17 | "node_modules", 18 | "bower_components", 19 | "test", 20 | "tests" 21 | ], 22 | "dependencies": { 23 | "angular": "1.3.0", 24 | "angular-ui-router": "~0.2.15", 25 | "angular-aria": "~1.4.8", 26 | "angular-resource": "~1.4.8", 27 | "angular-bootstrap-colorpicker": "~3.0.22", 28 | "angular-sanitize": "~1.3.15", 29 | "angular-translate-storage-local": "~2.7.2", 30 | "bootstrap": "~3.3.6", 31 | "Chart.js": "~1.0.2", 32 | "sweetalert": "~1.1.0", 33 | "bootstrap-bower": "https://github.com/angular-ui/bootstrap-bower/", 34 | "ngclipboard": "~1.1.0", 35 | "select2": "~4.0.1", 36 | "angular-bootstrap": "~1.3.2", 37 | "remodal": "~1.1.0" 38 | }, 39 | "resolutions": { 40 | "angular": "1.3.0", 41 | "messageformat": "~0.2.2" 42 | }, 43 | "install": { 44 | "path": { 45 | "css": "assets/vendor/css", 46 | "js": "assets/vendor/js", 47 | "/[sc|le]ss$/": "assets/vendor/css" 48 | }, 49 | "ignore": [ 50 | "jquery" 51 | ] 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ingot/ingot", 3 | "description": "Conversion optimization for WordPress made easy", 4 | "type": "wordpress-plugin", 5 | "keywords": [ 6 | "wordpress" 7 | ], 8 | "minimum-stability" : "dev", 9 | "license": "GPL-2.0+", 10 | "authors": [ 11 | { 12 | "name": "Josh Pollock", 13 | "homepage": "http://JoshPress.net", 14 | "role": "Developer" 15 | }, 16 | { 17 | "name": "Roy Sivan", 18 | "homepage": "http://roysivan.com", 19 | "role": "Developer" 20 | } 21 | ], 22 | "repositories": [ 23 | { 24 | "type":"git", 25 | "url":"https://github.com/ingothq/multiarmedbandit" 26 | }, 27 | { 28 | "type": "git", 29 | "url": "https://github.com/ingothq/wordpress-sdk" 30 | }, 31 | { 32 | "type":"git", 33 | "url":"https://github.com/ingothq/ingot-core" 34 | }, 35 | { 36 | "type": "git", 37 | "url": "https://github.com/Ingothq/ingot-woo-lib" 38 | }, 39 | { 40 | "type": "git", 41 | "url": "https://github.com/Ingothq/ingot-give-lib" 42 | }, 43 | { 44 | "type": "git", 45 | "url": "https://github.com/Ingothq/ingot-pmpro-lib" 46 | }, 47 | { 48 | "type": "git", 49 | "url": "https://github.com/Ingothq/ingot-edd-lib" 50 | } 51 | ], 52 | "require": { 53 | "calderawp/dismissible-notice": "dev-master", 54 | "ingot/ingot-core" : "*", 55 | "ingot/ingot-edd-lib" : "1.0.0", 56 | "ingot/ingot-woo-lib" : "1.0.0", 57 | "ingot/ingot-give-lib" : "1.0.0", 58 | "ingot/ingot-pmpro-lib" : "1.0.0" 59 | }, 60 | "require-dev": { 61 | "satooshi/php-coveralls": "dev-master", 62 | "phpunit/phpunit": "3.7.31", 63 | "phpunit/php-invoker": "1.1.3", 64 | "10up/wp_mock": "dev-master" 65 | }, 66 | "autoload": { 67 | "files": [ 68 | "ingot-premium.php" 69 | ] 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ingot-premium.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | 12 | /** 13 | * Function to load up premium codes 14 | * 15 | * @since 1.1.0 16 | */ 17 | function ingot_premium() { 18 | 19 | /** 20 | * Make sure we have destination tests 21 | * 22 | * @since 1.3.2 23 | */ 24 | add_filter( 'ingot_allowed_click_types', function( $types ){ 25 | return array_merge( $types, \ingot\testing\types::destination_definition() ); 26 | }, 0 ); 27 | 28 | if( ! defined( 'INGOT_EDD_VER' ) && ingot_is_edd_active() ) { 29 | define( 'INGOT_EDD_VER', '1.0.0' ); 30 | new ingot\addon\edd\add_destinations(); 31 | new ingot\addon\edd\tracking(); 32 | } 33 | 34 | if( ! defined( 'INGOT_WOO_VER' ) && ingot_is_woo_active() ) { 35 | define( 'INGOT_WOO_VER', '1.0.0' ); 36 | new ingot\addon\woo\add_destinations(); 37 | new ingot\addon\woo\tracking(); 38 | 39 | } 40 | 41 | if( ! defined( 'INGOT_GIVE_VER' ) && ingot_is_give_active() ) { 42 | define( 'INGOT_GIVE_VER', '1.0.0' ); 43 | new ingot\addon\woo\add_destinations(); 44 | new ingot\addon\woo\tracking(); 45 | 46 | } 47 | 48 | 49 | if( ! defined( 'INGOT_PMRPO_VER' ) ){ 50 | define( 'INGOT_PMRPO_VER', '1.0.0' ); 51 | if ( defined( 'PMPRO_VERSION' ) ) { 52 | new ingot\addon\pmpro\add_destinations(); 53 | new ingot\addon\pmpro\tracking(); 54 | } 55 | } 56 | 57 | 58 | } 59 | 60 | /** 61 | * Maybe load premium code 62 | * 63 | * @since 1.2.0 64 | * 65 | * @uses "ingot_plan_init" action 66 | * 67 | * @param $type 68 | * @param $object 69 | */ 70 | function ingot_maybe_load_premium( $type ){ 71 | switch( $type ){ 72 | case 'freemius' : 73 | if ( ingot_fs()->is_plan( 'premium' ) ){ 74 | ingot_premium(); 75 | } 76 | break; 77 | case 'edd' : 78 | //@todo 79 | break; 80 | } 81 | } 82 | 83 | /** 84 | * Set Ingot Plan 85 | * 86 | * @since 2.1.0 87 | */ 88 | function ingot_init_plan(){ 89 | if( is_object( ingot_fs() ) ) { 90 | $type = 'freemius'; 91 | $object = \ingot\licensing\freemius::get_instance(); 92 | }else{ 93 | $type = 'edd'; 94 | $object = \ingot\licensing\license::get_instance(); 95 | } 96 | 97 | /** 98 | * Runs after licence plan is set 99 | * 100 | * @since 1.2.0 101 | * 102 | * @param string $type 103 | * @param object $object 104 | */ 105 | do_action( 'ingot_plan_init', $type ); 106 | } 107 | -------------------------------------------------------------------------------- /ingot.php: -------------------------------------------------------------------------------- 1 | =' ) ) { 46 | $fail = true; 47 | if ( is_admin() ) { 48 | include_once( dirname( __FILE__ ) . '/vendor/calderawp/dismissible-notice/src/functions.php' ); 49 | $message = esc_html__( sprintf( 'Ingot requires PHP version 5.5.0 or later. Current version is %s.', PHP_VERSION ), 'ingot' ); 50 | echo caldera_warnings_dismissible_notice( $message, true, 'activate_plugins' ); 51 | } 52 | 53 | } 54 | global $wp_version; 55 | if ( ! version_compare( $wp_version, '4.4', '>=' ) ) { 56 | $fail = true; 57 | if ( is_admin() ) { 58 | include_once( dirname( __FILE__ ) . '/vendor/calderawp/dismissible-notice/src/functions.php' ); 59 | $message = esc_html__( sprintf( 'Ingot requires WordPress version 4.4 or later. Current version is %s.', $wp_version ), 'ingot' ); 60 | echo caldera_warnings_dismissible_notice( $message, true, 'activate_plugins' ); 61 | } 62 | 63 | } 64 | if( false == $fail ){ 65 | 66 | /** 67 | * Runs before Ingot is loaded 68 | * 69 | * NOTE: Only runs if version checks pass 70 | * 71 | * @since 1.2.0 72 | */ 73 | do_action( 'ingot_before' ); 74 | 75 | include_once dirname( __FILE__ ) . '/vendor/ingot/ingot-core/includes/functions.php'; 76 | include_once dirname( __FILE__ ) . '/vendor/ingot/ingot-core/includes/licensing.php'; 77 | include_once dirname( __FILE__ ) . '/vendor/ingot/ingot-core/includes/active_check.php'; 78 | include_once( dirname(__FILE__ ) . '/ingot_bootstrap.php' ); 79 | add_action( 'plugins_loaded', array( 'ingot_bootstrap', 'maybe_load' ) ); 80 | add_action( 'ingot_loaded', 'ingot_fs' ); 81 | 82 | } 83 | 84 | } 85 | /** 86 | * EDD Licensing 87 | * 88 | * @since 0.3.0 89 | */ 90 | function ingot_edd_sl_init(){ 91 | define( 'INGOT_SL_STORE_URL', 'http://ingothq.com' ); 92 | define( 'INGOT_SL_ITEM_NAME', 'Ingot Plugin: The Automatic A/B Tester' ); 93 | add_action( 'admin_init', 'ingot_sl_plugin_updater', 0 ); 94 | add_action( 'admin_init', 'ingot_sl_register_option' ); 95 | if ( is_admin() && ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { 96 | include( dirname( __FILE__ ) . '/includes/EDD_SL_Plugin_Updater.php' ); 97 | } 98 | } 99 | 100 | /** 101 | * Load Freemius 102 | * 103 | * @return \Freemius 104 | */ 105 | function ingot_fs() { 106 | global $ingot_fs; 107 | 108 | if ( ! isset( $ingot_fs ) ) { 109 | 110 | require_once dirname(__FILE__) . '/vendor/freemius/wordpress-sdk/start.php'; 111 | 112 | $ingot_fs = fs_dynamic_init( array( 113 | 'id' => '210', 114 | 'slug' => 'nugget-by-ingot', 115 | 'public_key' => 'pk_e6a19a3508bdb9bdc91a7182c8e0c', 116 | 'is_live' => true, 117 | 'is_premium' => true, 118 | 'has_addons' => true, 119 | 'has_paid_plans' => true, 120 | 'is_org_compliant' => true, 121 | 'menu' => array( 122 | 'slug' => 'ingot-admin-app', 123 | 'support' => false, 124 | 'first-path' => 'admin.php?page=ingot-admin-app#', 125 | ), 126 | 127 | ) ); 128 | 129 | } 130 | 131 | return $ingot_fs; 132 | 133 | } 134 | 135 | /** 136 | * Load translations 137 | * 138 | * @since 1.1.0 139 | */ 140 | add_action( 'plugins_loaded', 'ingot_load_textdomain' ); 141 | 142 | /** 143 | * Load plugin textdomain. 144 | * 145 | * @since 1.1.0 146 | */ 147 | function ingot_load_textdomain() { 148 | load_plugin_textdomain( 'ingot', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); 149 | } 150 | 151 | 152 | } 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /ingot_bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class ingot_bootstrap { 12 | 13 | /** 14 | * Loads ingot if not already loaded. 15 | * 16 | * @since 0.0.5 17 | */ 18 | public static function maybe_load() { 19 | if ( did_action( 'ingot_loaded' ) ) { 20 | return; 21 | } 22 | 23 | if ( ! defined( 'INGOT_DEV_MODE' ) ){ 24 | /** 25 | * Puts Ingot into dev mode 26 | * 27 | * Don't use on a live site -- makes API totally open 28 | * 29 | * @since 0.0.5 30 | */ 31 | define( 'INGOT_DEV_MODE', false ); 32 | } 33 | 34 | $load = true; 35 | if ( ! version_compare( PHP_VERSION, '5.5.0', '>=' ) ) { 36 | $load = false; 37 | } 38 | 39 | $autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; 40 | if ( ! file_exists( $autoloader ) ) { 41 | $load = false; 42 | } 43 | 44 | if ( $load ) { 45 | 46 | include_once( $autoloader ); 47 | $tables_existed = self::maybe_add_tables(); 48 | self::maybe_upgrade(); 49 | self::maybe_load_trial(); 50 | ingot_init_plan(); 51 | 52 | if( $tables_existed || \ingot\testing\db\delta::check_if_tables_exist() ) { 53 | ingot\testing\ingot::instance(); 54 | 55 | //make admin go in admin 56 | if ( is_admin() ) { 57 | new ingot\ui\make(); 58 | } 59 | 60 | 61 | if ( ingot_is_front_end() || ingot_is_admin_ajax() ) { 62 | //setup destination tests 63 | $destination_tests = \ingot\testing\tests\click\destination\init::set_tracking(); 64 | //run cookies 65 | add_action( 'ingot_loaded', function () { 66 | /** 67 | * Disable running cookies 68 | * 69 | * @since 1.1.0 70 | * 71 | * @param bool $run 72 | */ 73 | if ( true == (bool) apply_filters( 'ingot_run_cookies', true ) && ! did_action( 'ingot_cookies_set' ) ) { 74 | if ( ! empty( $destination_tests ) ) { 75 | \ingot\testing\tests\click\destination\init::setup_cookies( $destination_tests ); 76 | } 77 | 78 | \ingot\testing\cookies\set::run(); 79 | } 80 | 81 | }); 82 | } 83 | 84 | /** 85 | * Runs when Ingot has loaded. 86 | * 87 | * @since 0.0.5 88 | */ 89 | do_action( 'ingot_loaded' ); 90 | 91 | }else{ 92 | if ( is_admin() ) { 93 | printf( '

%s

', __( 'Ingot Not Loaded', 'ingot' ) ); 94 | 95 | } 96 | 97 | /** 98 | * Runs if Ingot failed to load 99 | * 100 | * @since 0.3.0 101 | * 102 | */ 103 | do_action( 'ingot_loaded_failed' ); 104 | 105 | return; 106 | 107 | } 108 | 109 | } 110 | 111 | } 112 | 113 | /** 114 | * Add tables to DB if needed 115 | * 116 | * @since 1.1.0 117 | * 118 | * @access protected 119 | * 120 | * @return bool 121 | */ 122 | protected static function maybe_add_tables(){ 123 | if( false == \ingot\testing\db\delta::check_if_tables_exist() ){ 124 | \ingot\testing\db\delta::add_tables(); 125 | return false; 126 | } 127 | 128 | return true; 129 | 130 | } 131 | 132 | /** 133 | * Maybe run DB updater 134 | * 135 | * @access protected 136 | * 137 | * @since 1.0.1 138 | */ 139 | protected static function maybe_upgrade(){ 140 | if( INGOT_VER != get_option( 'ingot_version', 0 ) ) { 141 | $updater = new \ingot\testing\db\upgrade( INGOT_VER ); 142 | $updater->run(); 143 | update_option( 'ingot_version', INGOT_VER, false ); 144 | } 145 | 146 | 147 | } 148 | 149 | 150 | 151 | /** 152 | * If trial mode is a thing, load the trial system 153 | * 154 | * @since 1.1.0 155 | * 156 | * @return bool 157 | */ 158 | public static function maybe_load_trial(){ 159 | return false; 160 | 161 | } 162 | 163 | 164 | } 165 | 166 | -------------------------------------------------------------------------------- /languages/ingot.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 2 | # This file is distributed under the same license as the Ingot package. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: Ingot 1.1.0-b-1\n" 6 | "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ingot\n" 7 | "POT-Creation-Date: 2015-12-29 03:03:20+00:00\n" 8 | "MIME-Version: 1.0\n" 9 | "Content-Type: text/plain; charset=utf-8\n" 10 | "Content-Transfer-Encoding: 8bit\n" 11 | "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n" 12 | "Last-Translator: FULL NAME \n" 13 | "Language-Team: LANGUAGE \n" 14 | "X-Generator: grunt-wp-i18n 0.5.3\n" 15 | "X-Poedit-KeywordsList: " 16 | "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_" 17 | "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n" 18 | "Language: en\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | "X-Poedit-Country: United States\n" 21 | "X-Poedit-SourceCharset: UTF-8\n" 22 | "X-Poedit-Basepath: ../\n" 23 | "X-Poedit-SearchPath-0: .\n" 24 | "X-Poedit-Bookmarks: \n" 25 | "X-Textdomain-Support: yes\n" 26 | 27 | #: classes/testing/api/rest/groups.php:173 28 | #: classes/testing/api/rest/groups.php:203 29 | #: classes/testing/api/rest/groups.php:236 30 | #: classes/testing/api/rest/groups.php:268 31 | #: classes/testing/api/rest/groups.php:513 32 | #: classes/testing/api/rest/groups.php:535 33 | msgid "No group found" 34 | msgstr "" 35 | 36 | #: classes/testing/api/rest/groups.php:243 37 | msgid "Group Deleted" 38 | msgstr "" 39 | 40 | #: classes/testing/api/rest/groups.php:300 41 | msgid "ID of group" 42 | msgstr "" 43 | 44 | #: classes/testing/api/rest/groups.php:306 45 | msgid "Name of Test Group" 46 | msgstr "" 47 | 48 | #: classes/testing/api/rest/groups.php:313 49 | msgid "Type of Test Group" 50 | msgstr "" 51 | 52 | #: classes/testing/api/rest/groups.php:321 53 | msgid "Link for content tests" 54 | msgstr "" 55 | 56 | #: classes/testing/api/rest/groups.php:328 57 | msgid "Page of results." 58 | msgstr "" 59 | 60 | #: classes/testing/api/rest/groups.php:334 61 | msgid "Tests to add to group" 62 | msgstr "" 63 | 64 | #: classes/testing/api/rest/groups.php:339 65 | msgid "Meta data for group" 66 | msgstr "" 67 | 68 | #: classes/testing/api/rest/route.php:239 69 | msgid "Route Not Yet Implemented :(" 70 | msgstr "" 71 | 72 | #: classes/testing/api/rest/variant.php:58 73 | msgid "ID of variant" 74 | msgstr "" 75 | 76 | #: classes/testing/api/rest/variant.php:140 77 | msgid "ID of Test" 78 | msgstr "" 79 | 80 | #: classes/testing/crud/group.php:148 classes/testing/crud/variant.php:41 81 | msgid "Invalid group type" 82 | msgstr "" 83 | 84 | #: classes/testing/crud/group.php:152 85 | msgid "Invalid click group type" 86 | msgstr "" 87 | 88 | #: classes/testing/crud/group.php:158 89 | msgid "Invalid price group type" 90 | msgstr "" 91 | 92 | #: classes/testing/crud/group.php:208 93 | msgid "Click groups must have a valid link." 94 | msgstr "" 95 | 96 | #: classes/testing/crud/variant.php:33 97 | msgid "Variant's group_ID type field numeric" 98 | msgstr "" 99 | 100 | #: classes/testing/crud/variant.php:37 101 | msgid "Variant's content field for price tests must be ID of a product" 102 | msgstr "" 103 | 104 | #: classes/testing/object/group.php:213 105 | msgid "Invalid group passed to Ingot group object." 106 | msgstr "" 107 | 108 | #: classes/testing/object/group.php:218 109 | msgid "Invalid group config passed to Ingot group object." 110 | msgstr "" 111 | 112 | #: classes/testing/tests/price/price.php:231 113 | #: classes/testing/tests/price/price.php:242 114 | #: classes/testing/tests/price/price.php:253 115 | msgid "Must override in subclass" 116 | msgstr "" 117 | 118 | #: classes/testing/types.php:52 classes/ui/admin/app/translations.php:66 119 | msgid "Link" 120 | msgstr "" 121 | 122 | #: classes/testing/types.php:53 classes/ui/admin/app/translations.php:71 123 | msgid "Text" 124 | msgstr "" 125 | 126 | #: classes/testing/types.php:54 127 | msgid "Button" 128 | msgstr "" 129 | 130 | #: classes/testing/types.php:55 131 | msgid "Button Color" 132 | msgstr "" 133 | 134 | #. Plugin Name of the plugin/theme 135 | msgid "Ingot" 136 | msgstr "" 137 | 138 | #: classes/ui/admin/app/load.php:134 139 | msgid "Toogle Navigation" 140 | msgstr "" 141 | 142 | #: classes/ui/admin/app/load.php:151 143 | msgid "Content Tests" 144 | msgstr "" 145 | 146 | #: classes/ui/admin/app/load.php:156 classes/ui/admin/app/translations.php:115 147 | msgid "Price Tests" 148 | msgstr "" 149 | 150 | #: classes/ui/admin/app/load.php:163 classes/ui/admin/app/translations.php:93 151 | msgid "Settings" 152 | msgstr "" 153 | 154 | #: classes/ui/admin/app/load.php:168 classes/ui/admin/app/translations.php:119 155 | msgid "Support" 156 | msgstr "" 157 | 158 | #: classes/ui/admin/app/translations.php:26 159 | msgid "Group Saved" 160 | msgstr "" 161 | 162 | #: classes/ui/admin/app/translations.php:27 163 | msgid "Could Not Save" 164 | msgstr "" 165 | 166 | #: classes/ui/admin/app/translations.php:28 167 | msgid "Please try again and/or contact support" 168 | msgstr "" 169 | 170 | #: classes/ui/admin/app/translations.php:29 171 | msgid "Close" 172 | msgstr "" 173 | 174 | #: classes/ui/admin/app/translations.php:30 175 | msgid "Saved Group: " 176 | msgstr "" 177 | 178 | #: classes/ui/admin/app/translations.php:31 179 | msgid "At this time, you can not remove a test from a group." 180 | msgstr "" 181 | 182 | #: classes/ui/admin/app/translations.php:32 183 | msgid "Beta Limitation Encountered" 184 | msgstr "" 185 | 186 | #: classes/ui/admin/app/translations.php:33 187 | msgid "" 188 | "Sorry about that but Ingot is still in beta. We will be adding this feature " 189 | "soon." 190 | msgstr "" 191 | 192 | #: classes/ui/admin/app/translations.php:34 193 | msgid "We do not have a functional stats viewer yet." 194 | msgstr "" 195 | 196 | #: classes/ui/admin/app/translations.php:35 197 | msgid "Test Group Deleted" 198 | msgstr "" 199 | 200 | #: classes/ui/admin/app/translations.php:36 201 | msgid "Are You Sure About That?" 202 | msgstr "" 203 | 204 | #: classes/ui/admin/app/translations.php:37 205 | msgid "Deleting all groups is not reversible or undoable." 206 | msgstr "" 207 | 208 | #: classes/ui/admin/app/translations.php:38 209 | #: classes/ui/admin/app/translations.php:78 210 | msgid "Delete" 211 | msgstr "" 212 | 213 | #: classes/ui/admin/app/translations.php:39 214 | msgid "Cancel" 215 | msgstr "" 216 | 217 | #: classes/ui/admin/app/translations.php:40 218 | msgid "Canceled" 219 | msgstr "" 220 | 221 | #: classes/ui/admin/app/translations.php:41 222 | msgid "Loading Spinner" 223 | msgstr "" 224 | 225 | #: classes/ui/admin/app/translations.php:42 226 | msgid "This group has no tests" 227 | msgstr "" 228 | 229 | #: classes/ui/admin/app/translations.php:43 230 | msgid "Please enter a number between -.99 and .99" 231 | msgstr "" 232 | 233 | #: classes/ui/admin/app/translations.php:44 234 | msgid "Settings Saved" 235 | msgstr "" 236 | 237 | #: classes/ui/admin/app/translations.php:46 238 | msgid "Stats For Group" 239 | msgstr "" 240 | 241 | #: classes/ui/admin/app/translations.php:47 242 | msgid "No Stats for this group yet" 243 | msgstr "" 244 | 245 | #: classes/ui/admin/app/translations.php:48 246 | msgid "Conversion Rate" 247 | msgstr "" 248 | 249 | #: classes/ui/admin/app/translations.php:49 250 | msgid "Varaint" 251 | msgstr "" 252 | 253 | #: classes/ui/admin/app/translations.php:52 254 | msgid "Content Test Groups" 255 | msgstr "" 256 | 257 | #: classes/ui/admin/app/translations.php:53 258 | msgid "Price Test Groups" 259 | msgstr "" 260 | 261 | #: classes/ui/admin/app/translations.php:54 262 | msgid "Show All" 263 | msgstr "" 264 | 265 | #: classes/ui/admin/app/translations.php:55 266 | msgid "Create New" 267 | msgstr "" 268 | 269 | #: classes/ui/admin/app/translations.php:56 270 | msgid "Edit Group" 271 | msgstr "" 272 | 273 | #: classes/ui/admin/app/translations.php:57 274 | msgid "Group Stats" 275 | msgstr "" 276 | 277 | #: classes/ui/admin/app/translations.php:58 278 | msgid "Delete Group" 279 | msgstr "" 280 | 281 | #: classes/ui/admin/app/translations.php:59 282 | msgid "There are no groups, create one." 283 | msgstr "" 284 | 285 | #: classes/ui/admin/app/translations.php:62 286 | msgid "Save Group" 287 | msgstr "" 288 | 289 | #: classes/ui/admin/app/translations.php:63 290 | msgid "Type" 291 | msgstr "" 292 | 293 | #: classes/ui/admin/app/translations.php:64 294 | msgid "Name" 295 | msgstr "" 296 | 297 | #: classes/ui/admin/app/translations.php:65 298 | msgid "Group Settings" 299 | msgstr "" 300 | 301 | #: classes/ui/admin/app/translations.php:67 302 | msgid "Text (Used For All Buttons)" 303 | msgstr "" 304 | 305 | #: classes/ui/admin/app/translations.php:68 306 | msgid "Color (Used For All Buttons)" 307 | msgstr "" 308 | 309 | #: classes/ui/admin/app/translations.php:69 310 | msgid "Background (Used For All Buttons)" 311 | msgstr "" 312 | 313 | #: classes/ui/admin/app/translations.php:70 314 | msgid "Tests" 315 | msgstr "" 316 | 317 | #: classes/ui/admin/app/translations.php:72 318 | msgid "Button Text Color" 319 | msgstr "" 320 | 321 | #: classes/ui/admin/app/translations.php:73 322 | msgid "Button Background Color" 323 | msgstr "" 324 | 325 | #: classes/ui/admin/app/translations.php:74 326 | msgid "Add Test" 327 | msgstr "" 328 | 329 | #: classes/ui/admin/app/translations.php:75 330 | msgid "eCommerce Plugin" 331 | msgstr "" 332 | 333 | #: classes/ui/admin/app/translations.php:76 334 | msgid "Product" 335 | msgstr "" 336 | 337 | #: classes/ui/admin/app/translations.php:77 338 | msgid "Price Variation (percentage)" 339 | msgstr "" 340 | 341 | #: classes/ui/admin/app/translations.php:79 342 | msgid "Content Test" 343 | msgstr "" 344 | 345 | #: classes/ui/admin/app/translations.php:80 346 | msgid "Data and Tests" 347 | msgstr "" 348 | 349 | #: classes/ui/admin/app/translations.php:81 350 | msgid "Group Name" 351 | msgstr "" 352 | 353 | #: classes/ui/admin/app/translations.php:82 354 | msgid "Group Type" 355 | msgstr "" 356 | 357 | #: classes/ui/admin/app/translations.php:83 358 | msgid "Group Data and Tests" 359 | msgstr "" 360 | 361 | #: classes/ui/admin/app/translations.php:84 362 | msgid "Name of your new test, be specific for easy reference later." 363 | msgstr "" 364 | 365 | #: classes/ui/admin/app/translations.php:85 366 | msgid "Test Name" 367 | msgstr "" 368 | 369 | #: classes/ui/admin/app/translations.php:86 370 | msgid "Edit Group Type" 371 | msgstr "" 372 | 373 | #: classes/ui/admin/app/translations.php:87 374 | msgid "Type of test you want to perform" 375 | msgstr "" 376 | 377 | #: classes/ui/admin/app/translations.php:88 378 | msgid "Sample Button" 379 | msgstr "" 380 | 381 | #: classes/ui/admin/app/translations.php:89 382 | msgid "New Content Test" 383 | msgstr "" 384 | 385 | #: classes/ui/admin/app/translations.php:94 386 | msgid "Work around caching" 387 | msgstr "" 388 | 389 | #: classes/ui/admin/app/translations.php:95 390 | msgid "" 391 | "If you are using a static HTML cache testing will not work properly, since " 392 | "the same version of your site is shown to all visitors. Use this mode to " 393 | "work around this issue." 394 | msgstr "" 395 | 396 | #: classes/ui/admin/app/translations.php:96 397 | msgid "Advanced Click Tracking" 398 | msgstr "" 399 | 400 | #: classes/ui/admin/app/translations.php:97 401 | msgid "" 402 | "Ingot always tracks clicks, in advanced mode, more details are tracked. " 403 | "This takes up more space in the database, but enables Ingot to be more " 404 | "powerful." 405 | msgstr "" 406 | 407 | #: classes/ui/admin/app/translations.php:98 408 | msgid "Share Your Data Anonymously" 409 | msgstr "" 410 | 411 | #: classes/ui/admin/app/translations.php:99 412 | msgid "" 413 | "When enabled, your test data is shared with Ingot to help us improve the " 414 | "service." 415 | msgstr "" 416 | 417 | #: classes/ui/admin/app/translations.php:100 418 | msgid "License Code" 419 | msgstr "" 420 | 421 | #: classes/ui/admin/app/translations.php:101 422 | msgid "Enter your license code to enable support and updates." 423 | msgstr "" 424 | 425 | #: classes/ui/admin/app/translations.php:102 426 | msgid "Save Settings" 427 | msgstr "" 428 | 429 | #: classes/ui/admin/app/translations.php:103 430 | msgid "Edit Group Name" 431 | msgstr "" 432 | 433 | #: classes/ui/admin/app/translations.php:104 434 | msgid "Edit Group Tests" 435 | msgstr "" 436 | 437 | #: classes/ui/admin/app/translations.php:105 438 | msgid "License not active or not valid" 439 | msgstr "" 440 | 441 | #: classes/ui/admin/app/translations.php:111 442 | msgid "Ingot Banner Logo" 443 | msgstr "" 444 | 445 | #: classes/ui/admin/app/translations.php:112 446 | msgid "Ingot: Do Less, Convert More" 447 | msgstr "" 448 | 449 | #: classes/ui/admin/app/translations.php:113 450 | msgid "Helpful Links" 451 | msgstr "" 452 | 453 | #: classes/ui/admin/app/translations.php:114 454 | msgid "Watch This Short Video To Learn How To Use Ingot" 455 | msgstr "" 456 | 457 | #: classes/ui/admin/app/translations.php:116 458 | msgid "Click Tests" 459 | msgstr "" 460 | 461 | #: classes/ui/admin/app/translations.php:117 462 | msgid "Learn more about Ingot" 463 | msgstr "" 464 | 465 | #: classes/ui/admin/app/translations.php:118 466 | msgid "Documentation" 467 | msgstr "" 468 | 469 | #: classes/ui/admin/app/translations.php:122 470 | msgid "For support please use:" 471 | msgstr "" 472 | 473 | #: classes/ui/render/click_tests/text.php:50 474 | msgid "Extra data for tracking Ingot click tests " 475 | msgstr "" 476 | 477 | #: classes/ui/util.php:67 478 | msgid "Choose" 479 | msgstr "" 480 | 481 | #: classes/ui/util.php:68 includes/functions.php:420 482 | msgid "Easy Digital Downloads" 483 | msgstr "" 484 | 485 | #: classes/ui/util.php:69 includes/functions.php:421 486 | msgid "WooCommerce" 487 | msgstr "" 488 | 489 | #: includes/EDD_SL_Plugin_Updater.php:181 490 | msgid "" 491 | "There is a new version of %1$s available. View version %3$s details." 493 | msgstr "" 494 | 495 | #: includes/EDD_SL_Plugin_Updater.php:188 496 | msgid "" 497 | "There is a new version of %1$s available. View version %3$s details or update now." 500 | msgstr "" 501 | 502 | #: includes/EDD_SL_Plugin_Updater.php:326 503 | msgid "You do not have permission to install plugin updates" 504 | msgstr "" 505 | 506 | #: includes/EDD_SL_Plugin_Updater.php:326 507 | msgid "Error" 508 | msgstr "" 509 | 510 | #: ingot_bootstrap.php:75 511 | msgid "Ingot Not Loaded" 512 | msgstr "" 513 | 514 | #: vendor/calderawp/dismissible-notice/src/Caldera_Warnings_Dismissible_Notice.php:129 515 | msgid "Dismiss this notice." 516 | msgstr "" -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ingot", 3 | "version": "1.3.2", 4 | "description": "Ingot", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/ingothq/ingot" 8 | }, 9 | "author": "Josh Pollock", 10 | "license": "GPLv2+", 11 | "bugs": { 12 | "url": "https://github.com/ingothq/ingot" 13 | }, 14 | "devDependencies": { 15 | "bower": "*", 16 | "bower-installer": "^1.2.0", 17 | "grunt": "~0.4.2", 18 | "grunt-cli": "~0.1.11", 19 | "grunt-contrib-clean": "^0.6.0", 20 | "grunt-contrib-compress": "^0.13.0", 21 | "grunt-contrib-copy": "^0.7.0", 22 | "grunt-contrib-uglify": "^0.11.0", 23 | "grunt-contrib-watch": "^0.6.1", 24 | "grunt-git": "^0.3.3", 25 | "grunt-shell": "^1.1.1", 26 | "grunt-text-replace": "^0.4.0", 27 | "grunt-wp-i18n": "^0.5.3", 28 | "i18n": "^0.5.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ./tests/ 12 | ./tests/crud 13 | ./tests/api 14 | ./tests/utilities 15 | ./tests/objects 16 | ./tests/price 17 | ./tests/destination 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Ingot === 2 | Contributors: Shelob9 3 | Tags: a/b testing, multi-varitant testing, ab testing, ab test, a/b testing, cro, content rate optimization, split tests, split testing, easy digital downloads, woocommerce, woo, edd, give, givewp 4 | Donate link: https://ingothq.com 5 | Requires at least: 4.4.0 6 | Tested up to: 4.5 7 | Stable tag: 1.3.0 8 | License: GPL v2+ 9 | 10 | A/B testing made easy for WordPress - Do less, convert more. 11 | 12 | == Description == 13 | [Ingot](https://ingothq.com/) is the simplest way to make your WordPress site perform better for your business — sell more, get more sign ups, get more out of your online marketing. Easy to use, affordable, and requires no 3rd party services. 14 | 15 | A/B testing is a proven technique to increase conversions on your site, but traditionally it has required a lot of traffic, a connection to a costly 3rd-party service and an expert to read the results. Busy WordPress site managers don't have time for that? Who does? Ingot changes all of that. Ingot takes a few minutes to setup, and then it just works, constantly evolving your site to find the results that convert best. 16 | 17 | Don't worry that you made the wrong choice when you chose your call to action text, site headline, or pricing, let Ingot find the best performing option. Don't worry about missing out on sales because you didn't have time to test, use Ingot -- the easy, yet surprisingly affordable A/B Testing solution for WordPress. 18 | 19 | > Stop trying to be perfect, use Ingot today and make your website smarter. 20 | > * [Get support for Ingot](https://ingothq.com/customersupport/) 21 | > * [Learn how to use Ingot by reading our documentation](https://ingothq.com/documentation/) 22 | 23 | = Features = 24 | * Works with any amount of traffic, our A/B testing algorithm is optimized to work with small sites, and large sites a like. 25 | * Test call to action button text -- A/B, split tests and multi-variant. 26 | * Test call to action button color -- A/B, split tests and multi-variant. 27 | * Find the best headline to drive sales, using A/B testing with WooCommerce or Easy Digital Downloads. 28 | * Find the best pricing structure by split testing pricing with WooCommerce or Easy Digital Downloads (coming soon). 29 | * Increase donations, by A/B testing your non-profit's messaging -- works with Give. 30 | * Requires no third-party API. 31 | * One price -- don't pay per test 32 | * Developers can create any type of A/B Test using our simple REST API, and/ or using a destination test that registers conversions using a hook. 33 | 34 | == Installation == 35 | 36 | = Minimum Requirements = 37 | 38 | * WordPress 4.4 or greater 39 | * PHP version 5.5 or greater 40 | 41 | = Automatic installation = 42 | 43 | Automatic installation is the easiest option as WordPress handles the file transfers itself and you don't need to leave your web browser. To do an automatic install of Ingot, log in to your WordPress dashboard, navigate to the Plugins menu and click "Add New". 44 | 45 | In the search field type "Ingot" and click Search Plugins. Once you have found the plugin you can view details about it such as the the point release, rating and description. Most importantly of course, you can install it by simply clicking "Install Now". 46 | 47 | = Manual installation = 48 | 49 | The manual installation method involves downloading our donation plugin and uploading it to your server via your favorite FTP application. The WordPress codex contains [instructions on how to do this here](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation). 50 | 51 | = Updating = 52 | 53 | Automatic updates should work like a charm; as always though, ensure you backup your site just in case. 54 | 55 | == Frequently Asked Questions == 56 | For more FAQs go to [https://ingothq.com/documentation/ingot-faq/](https://ingothq.com/documentation/ingot-faq/) 57 | 58 | = How Hard Is It To Implement A Test? = 59 | Not hard at all. Can you fill out a form? Can you insert a shortcode into a page? Then you can use Ingot. 60 | 61 | = Is Ingot Free? = 62 | Ingot is free to try for two weeks. Once your trial has expired, you can choose one of our plans. 63 | 64 | = Will Ingot break my site if my trial or subscription expires? = 65 | No, not at all, that would be terrible. If you do not have an active subscription, Ingot will output the first variation from a test group and will not register any stats. This way your site still has valid HTML and looks right. BTW, this is the same way we always treat bots, which need valid HTML -- since a bot may be Google -- but we don't want to track them. 66 | 67 | = Does Ingot work with a caching system ? = 68 | Yes. Many sites use a static HTML cache, which could be an issue if we didn't work around them. Ingot works around this by using a small JavaScript file to check that any tests on the page are unused, and if needed updating the HTML on the page via AJAX. This doesn't cause a full page refresh or anything, Ingot only updates the part of the page that needs updated. 69 | 70 | == Screenshots == 71 | 72 | 1. Creating a new A/B test group: choose a name 73 | 74 | 2. Creating a new A/B test group: choose a type 75 | 76 | 3. Creating a new A/B test group: call to action button test settings 77 | 78 | 4. Creating a new A/B test group: Destination test settings 79 | 80 | == Changelog == 81 | 82 | = 1.3.1.1 = 83 | * Fix destination test loading in premium mode. 84 | = 1.3.1 = 85 | * Minor bug fixes 86 | * Support for testing forms. 87 | 88 | = 1.3.0 = 89 | ADDED: Support For Paid Memberships Pro 90 | FIXED: Activation bugs 91 | 92 | = 1.2.0 = 93 | ADDED: A/B testing for Give 94 | FIXED: Bug preventing proper session tracking for destination A/B tests 95 | FIXED: Ensure that bots do not trigger an iteration of an A/B test always. 96 | FIXED: Ensure that when in random A/B testing mode, that we record iterations properly. 97 | ADDED: Show group stats for average of all A/B tests in stats view. 98 | 99 | = 1.1.0 = 100 | * ADDED: Shortcode insert button for adding A/B tests from to post editor 101 | * ADDED: Destination Tests type A/B tests with support for WooCommerce, Easy Digital Downloads and Give 102 | * IMPROVED: User interface test creation flow 103 | * FIXED: Output of button color test 104 | 105 | 106 | = 1.0.2 = 107 | * ADDED: Copy to clipboard for shortcode 108 | * FIXED: Display conversion rates properly for A/B tests 109 | * Minor bug fixes 110 | 111 | = 1.0.1 = 112 | * Dump old tables if upgrading from beta 113 | * Don't assume path for dependencies 114 | 115 | # 1.0.0 116 | * Bower for dependencies instead of using CDNs 117 | * UI Improvements 118 | * Bug fixes 119 | 120 | = 0.4.0 = 121 | * Improve A/B Test UI 122 | * Refactor testing algorithm/crud/API 123 | 124 | = 0.3.0 = 125 | * Improve UI 126 | 127 | = 0.2.2 = 128 | * Improved compatibility with WordPress 4.4 129 | * Plugin header meta data 130 | * Show version number in admin header 131 | 132 | = 0.2.1 = 133 | * Price testing for Easy Digital Downloads -- still experimental 134 | * Major UI improvements 135 | 136 | = 0.2.0.1 = 137 | * Simpler verification of click tracking A/B tests. 138 | * Better handling of failed click tracking A/B tests. 139 | 140 | = 0.2.0 = 141 | Major refactor and overhaul of UI 142 | 143 | = 0.1.0 = 144 | Initial release of our A/B testing plugin 145 | -------------------------------------------------------------------------------- /releases/ingot-0.1.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.1.0.zip -------------------------------------------------------------------------------- /releases/ingot-0.1.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.1.1.zip -------------------------------------------------------------------------------- /releases/ingot-0.1.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.1.2.zip -------------------------------------------------------------------------------- /releases/ingot-0.2.0.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.2.0.1.zip -------------------------------------------------------------------------------- /releases/ingot-0.2.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.2.0.zip -------------------------------------------------------------------------------- /releases/ingot-0.2.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.2.1.zip -------------------------------------------------------------------------------- /releases/ingot-0.2.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.2.2.zip -------------------------------------------------------------------------------- /releases/ingot-0.3.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.3.0.zip -------------------------------------------------------------------------------- /releases/ingot-0.4.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-0.4.0.zip -------------------------------------------------------------------------------- /releases/ingot-1.0.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.0.0.zip -------------------------------------------------------------------------------- /releases/ingot-1.0.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.0.1.zip -------------------------------------------------------------------------------- /releases/ingot-1.0.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.0.2.zip -------------------------------------------------------------------------------- /releases/ingot-1.1.0-b-1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.1.0-b-1.zip -------------------------------------------------------------------------------- /releases/ingot-1.1.0-b-2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.1.0-b-2.zip -------------------------------------------------------------------------------- /releases/ingot-1.1.0-b-3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.1.0-b-3.zip -------------------------------------------------------------------------------- /releases/ingot-1.1.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.1.0.zip -------------------------------------------------------------------------------- /releases/ingot-1.1.1-b-1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.1.1-b-1.zip -------------------------------------------------------------------------------- /releases/ingot-1.1.1-b-2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.1.1-b-2.zip -------------------------------------------------------------------------------- /releases/ingot-1.2.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.2.0.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.0.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.1.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.1.1.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.1.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.2-b-1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.2-b-1.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.2-b-2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.2-b-2.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.2-b-3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.2-b-3.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.2-b-4.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.2-b-4.zip -------------------------------------------------------------------------------- /releases/ingot-1.3.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ingothq/ingot/ce10e18d425c86c77f5b4035883d398f42b459b1/releases/ingot-1.3.2.zip -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | cd /srv/www/ingot-dev/wp-content/plugins/ingot 2 | 3 | ./install-wp-tests.sh wordpress_unit_tests wp wp localhost 4 | -------------------------------------------------------------------------------- /tests/api/rest-test-case.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | 12 | 13 | abstract class ingot_rest_test_case extends \WP_UnitTestCase { 14 | 15 | /** 16 | * In subclass, add route here 17 | * 18 | * @var string 19 | */ 20 | protected $route_name = ''; 21 | 22 | /** 23 | * Test REST Server 24 | * 25 | * @var WP_REST_Server 26 | */ 27 | protected $server; 28 | 29 | /** 30 | * Namespaced route name 31 | * 32 | * DONT CHANGE THIS IN SUBCLASS LET $this->setNamespace() handle it 33 | * 34 | * @var string 35 | */ 36 | protected $namespaced_route = ''; 37 | 38 | 39 | public function setUp() { 40 | parent::setUp(); 41 | 42 | /** @var WP_REST_Server $wp_rest_server */ 43 | global $wp_rest_server; 44 | $this->server = $wp_rest_server = new \WP_REST_Server; 45 | do_action( 'rest_api_init' ); 46 | 47 | 48 | $ingot = ingot\testing\ingot::instance(); 49 | $ingot->boot_rest_api(); 50 | $this->setNamespacedRoute(); 51 | 52 | 53 | 54 | 55 | } 56 | 57 | public function tearDown() { 58 | parent::tearDown(); 59 | 60 | } 61 | 62 | private function setNamespacedRoute() { 63 | $this->namespaced_route = '/' . untrailingslashit( \ingot\testing\api\rest\util::get_route( $this->route_name ) ); 64 | } 65 | 66 | /** 67 | * Tests designed to detect improperly setup subclass 68 | */ 69 | public function testSetUp() { 70 | $this->assertNotSame( $this->route_name, '', get_class( $this ) ); 71 | $this->assertNotSame( $this->namespaced_route, __return_null(), get_class( $this ) ); 72 | } 73 | 74 | 75 | /** 76 | * Test that this route is registered properly 77 | * 78 | * @since 0.2.0 79 | * 80 | * @group rest 81 | * @group settings_rest 82 | * @group group_rest 83 | * @group tracking_rest 84 | * @group session_rest 85 | * @group variant_rest 86 | */ 87 | public function test_register_route() { 88 | 89 | $routes = $this->server->get_routes(); 90 | 91 | $this->assertArrayHasKey( '/' . \ingot\testing\api\rest\util::get_namespace() . '/' . $this->route_name, $routes, get_class( $this ) ); 92 | $this->assertArrayHasKey( $this->namespaced_route, $routes, get_class( $this ) ); 93 | 94 | } 95 | 96 | /** 97 | * Test endpoint registration 98 | * 99 | * @since 0.2.0 100 | * 101 | * @group rest 102 | * @group settings_rest 103 | * @group group_rest 104 | * @group tracking_rest 105 | * @group session_rest 106 | * @group variant_rest 107 | */ 108 | public function test_endpoints() { 109 | $the_route = $this->namespaced_route; 110 | $routes = $this->server->get_routes(); 111 | foreach( $routes as $route => $route_config ) { 112 | if( 0 === strpos( $the_route, $route ) ) { 113 | $this->assertTrue( is_array( $route_config ) ); 114 | foreach( $route_config as $i => $endpoint ) { 115 | $this->assertArrayHasKey( 'callback', $endpoint, get_class( $this ) ); 116 | $this->assertArrayHasKey( 0, $endpoint[ 'callback' ], get_class( $this ) ); 117 | $this->assertArrayHasKey( 1, $endpoint[ 'callback' ], get_class( $this ) ); 118 | $this->assertTrue( is_callable( array( $endpoint[ 'callback' ][0], $endpoint[ 'callback' ][1] ) ), get_class( $this ) ); 119 | 120 | } 121 | 122 | } 123 | } 124 | 125 | } 126 | 127 | 128 | 129 | } 130 | -------------------------------------------------------------------------------- /tests/api/tests-group_api.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_group_api extends ingot_rest_test_case { 12 | 13 | public function setUp(){ 14 | parent::setUp(); 15 | 16 | } 17 | 18 | public function tearDown() { 19 | parent::tearDown(); 20 | 21 | } 22 | 23 | /** 24 | * Route name 25 | * 26 | * @since 0.4.0 27 | * 28 | * @var string 29 | */ 30 | protected $route_name = 'groups'; 31 | 32 | 33 | /** 34 | * Test getting a collection of items 35 | * 36 | * @since 0.4.0 37 | * 38 | * @group rest 39 | * @group group_rest 40 | * @group group 41 | * 42 | * @covers ingot\testing\api\rest\groups::get_items() 43 | */ 44 | public function testGetItems(){ 45 | wp_set_current_user( 1 ); 46 | $groups = ingot_tests_make_groups( true, 4, 3 ); 47 | $request = new \WP_REST_Request( 'GET', $this->namespaced_route ); 48 | $response = $this->server->dispatch( $request ); 49 | $response = rest_ensure_response( $response ); 50 | $this->assertEquals( 200, $response->get_status() ); 51 | $data = (array) $response->get_data(); 52 | $this->assertEquals( count( $groups[ 'ids' ] ), count( $data ) ); 53 | $fields = $this->get_fields_to_check_for(); 54 | foreach( $data as $group ){ 55 | $this->assertTrue( in_array( $group[ 'ID' ], $groups[ 'ids' ] ) ); 56 | $this->assertEquals( count( $group ), count( $fields ) ); 57 | $this->assertEquals( 'click', $group[ 'type' ] ); 58 | $group_direct = \ingot\testing\crud\group::read( $group[ 'ID' ] ); 59 | foreach( $fields as $field ){ 60 | $this->assertArrayHasKey( $field, $group ); 61 | $this->assertEquals( $group_direct[ $field ], $group[ $field ] ); 62 | } 63 | 64 | 65 | } 66 | } 67 | 68 | /** 69 | * Test getting price tests via API 70 | * 71 | * @since 1.0.0 72 | * 73 | * @group price 74 | * @group rest 75 | * @group group_rest 76 | * @group group 77 | * 78 | * @covers ingot\testing\api\rest\groups::get_items() 79 | */ 80 | public function testGetPrice(){ 81 | wp_set_current_user( 1 ); 82 | ingot_test_data_price::edd_tests(); 83 | ingot_test_data_price::edd_tests(); 84 | ingot_tests_make_groups( true, 4, 3 ); 85 | 86 | $groups = ingot_tests_make_groups( true, 4, 3 ); 87 | $request = new \WP_REST_Request( 'GET', $this->namespaced_route ); 88 | $request->set_query_params( array( 89 | 'type' => 'price' 90 | ) ); 91 | $response = $this->server->dispatch( $request ); 92 | $response = rest_ensure_response( $response ); 93 | $this->assertEquals( 200, $response->get_status() ); 94 | $data = (array) $response->get_data(); 95 | foreach( $data as $group ){ 96 | $this->assertEquals( 'price', $group[ 'type' ] ); 97 | } 98 | } 99 | 100 | 101 | /** 102 | * Test getting a one item 103 | * 104 | * @since 0.4.0 105 | * 106 | * @group rest 107 | * @group group_rest 108 | * @group group 109 | * 110 | * @covers ingot\testing\api\rest\groups::get_item() 111 | */ 112 | public function testGetItem(){ 113 | wp_set_current_user( 1 ); 114 | $groups = ingot_tests_make_groups( true, 2, 3 ); 115 | $id = $groups[ 'ids' ][1]; 116 | $request = new \WP_REST_Request( 'GET', $this->namespaced_route . '/' . $id ); 117 | $response = $this->server->dispatch( $request ); 118 | $response = rest_ensure_response( $response ); 119 | $this->assertEquals( 201, $response->get_status() ); 120 | $data = (array) $response->get_data(); 121 | 122 | $group = \ingot\testing\crud\group::read( $id ); 123 | 124 | 125 | 126 | $fields = $this->get_fields_to_check_for(); 127 | foreach( $fields as $field ){ 128 | $this->assertArrayHasKey( $field, $data ); 129 | $this->assertEquals( $group[ $field ], $data[ $field ] ); 130 | } 131 | } 132 | 133 | /** 134 | * Test updating one item 135 | * 136 | * @since 0.4.0 137 | * 138 | * @group rest 139 | * @group group_rest 140 | * @group group 141 | * 142 | * @covers ingot\testing\api\rest\groups::update_item() 143 | */ 144 | public function testUpdateItem(){ 145 | wp_set_current_user( 1 ); 146 | $groups = ingot_tests_make_groups( true, 2, 3 ); 147 | $id = $groups[ 'ids' ][1]; 148 | $request = new \WP_REST_Request( 'POST', $this->namespaced_route . '/' . $id ); 149 | $request->set_query_params( array( 150 | 'ID' => $id, 151 | 'type' => 'click', 152 | 'sub_type' => 'button_color', 153 | 'name' => 'josh' 154 | ) ); 155 | 156 | $response = $this->server->dispatch( $request ); 157 | $response = rest_ensure_response( $response ); 158 | $this->assertEquals( 201, $response->get_status() ); 159 | $data = (array) $response->get_data(); 160 | $group = \ingot\testing\crud\group::read( $id ); 161 | $fields = $this->get_fields_to_check_for(); 162 | $this->assertTrue( is_array( $data ) ); 163 | $this->assertEquals( count( $fields ), count( $data ), var_export( $data, true ) ); 164 | foreach( $fields as $field ) { 165 | $this->assertArrayHasKey( $field, $data ); 166 | $this->assertSame( $group[ $field ], $data[ $field ] ); 167 | } 168 | 169 | 170 | } 171 | 172 | /** 173 | * Test creating one item 174 | * 175 | * @since 0.4.0 176 | * 177 | * @group rest 178 | * @group group_rest 179 | * @group group 180 | * 181 | * @covers ingot\testing\api\rest\groups::delete_item() 182 | */ 183 | public function testDeleteItem(){ 184 | wp_set_current_user( 1 ); 185 | wp_set_current_user( 1 ); 186 | $groups = ingot_tests_make_groups( true, 2, 3 ); 187 | $id = $groups[ 'ids' ][1]; 188 | $request = new \WP_REST_Request( 'DELETE', $this->namespaced_route . '/' . $id ); 189 | 190 | $response = $this->server->dispatch( $request ); 191 | $response = rest_ensure_response( $response ); 192 | $this->assertEquals( 204, $response->get_status() ); 193 | 194 | $deleted = \ingot\testing\crud\group::read( $id ); 195 | $this->assertFalse( is_array($deleted )); 196 | $not_deleted = \ingot\testing\crud\group::read( $groups[ 'ids' ][0] ); 197 | $this->assertTrue( is_array( $not_deleted ) ); 198 | 199 | 200 | } 201 | 202 | /** 203 | * Test deleting one item 204 | * 205 | * @since 0.4.0 206 | * 207 | * @group rest 208 | * @group group_rest 209 | * @group group 210 | * 211 | * @covers ingot\testing\api\rest\groups::create_item() 212 | */ 213 | public function testCreateItem(){ 214 | wp_set_current_user( 1 ); 215 | 216 | $request = new \WP_REST_Request( 'POST', $this->namespaced_route ); 217 | $request->set_query_params( array( 218 | 'type' => 'click', 219 | 'sub_type' => 'button_color', 220 | 'name' => 'x2' 221 | ) ); 222 | 223 | $response = $this->server->dispatch( $request ); 224 | $response = rest_ensure_response( $response ); 225 | $this->assertEquals( 201, $response->get_status() ); 226 | $data = (array) $response->get_data(); 227 | 228 | $this->assertArrayHasKey( 'ID', $data ); 229 | $group = \ingot\testing\crud\group::read( $data[ 'ID'] ); 230 | $fields = $this->get_fields_to_check_for(); 231 | $this->assertTrue( is_array( $data ) ); 232 | $this->assertEquals( count( $fields ), count( $data ), var_export( $data, true ) ); 233 | foreach( $fields as $field ) { 234 | $this->assertArrayHasKey( $field, $data ); 235 | $this->assertSame( $group[ $field ], $data[ $field ] ); 236 | } 237 | 238 | 239 | } 240 | 241 | /** 242 | * Get all fields that a group in a response should have 243 | * 244 | * @since 0.4.0 245 | * 246 | * @return array 247 | */ 248 | private function get_fields_to_check_for() { 249 | $fields = \ingot\testing\crud\group::get_all_fields(); 250 | $fields[] = 'ID'; 251 | 252 | $flipped = array_flip( $fields ); 253 | $l = $flipped[ 'levers' ]; 254 | unset( $fields[ $l ] ); 255 | return $fields; 256 | } 257 | 258 | } 259 | -------------------------------------------------------------------------------- /tests/api/tests-products.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class products_api extends ingot_rest_test_case { 12 | 13 | /** 14 | * In subclass, add route here 15 | * 16 | * @var string 17 | */ 18 | protected $route_name = 'products'; 19 | 20 | /** 21 | * Test GET /products for EDD 22 | * 23 | * @since 1.1.0 24 | * 25 | * @group products_api 26 | * @group edd 27 | * @group price 28 | * 29 | * @covers ingot\testing\api\rest/products::get_items() 30 | */ 31 | public function testGetEDDItems() { 32 | wp_set_current_user( 1 ); 33 | $product_1 = ingot_test_data_price::edd_create_simple_download( 10 ); 34 | $product_2 = ingot_test_data_price::edd_create_simple_download( 10 ); 35 | $not_edd = get_post( wp_insert_post( [ 36 | 'post_type' => 'page', 37 | 'post_title' => 'hats' 38 | ] ) ); 39 | 40 | $request = new \WP_REST_Request( 'GET', $this->namespaced_route ); 41 | $request->set_query_params( array( 42 | 'plugin' => 'edd' 43 | ) ); 44 | $response = $this->server->dispatch( $request ); 45 | $response = rest_ensure_response( $response ); 46 | $this->assertEquals( 200, $response->get_status() ); 47 | $data = (array) $response->get_data(); 48 | $this->assertSame( 2, count( $data ) ); 49 | 50 | $ids = [ $product_1->ID, $product_2->ID ]; 51 | $titles = [ $product_1->post_title, $product_2->post_title ]; 52 | foreach ( $data as $product ) { 53 | $this->assertArrayHasKey( 'value', $product ); 54 | $this->assertArrayHasKey( 'label', $product ); 55 | $this->assertTrue( in_array( $product[ 'value' ], $ids ) ); 56 | $this->assertTrue( in_array( $product[ 'label' ], $titles ) ); 57 | } 58 | 59 | } 60 | 61 | /** 62 | * Test GET /products/plugins 63 | * 64 | * @since 1.1.0 65 | * 66 | * @group products_api 67 | * @group edd 68 | * @group woo 69 | * @group price 70 | * 71 | * @covers ingot\testing\api\rest/products::get_plugins() 72 | */ 73 | public function testGetPlugins() { 74 | wp_set_current_user( 1 ); 75 | 76 | $request = new \WP_REST_Request( 'GET', $this->namespaced_route . '/plugins' ); 77 | $request->set_query_params( array( 78 | 'plugin' => 'edd' 79 | ) ); 80 | $response = $this->server->dispatch( $request ); 81 | $response = rest_ensure_response( $response ); 82 | $this->assertEquals( 200, $response->get_status() ); 83 | $data = (array) $response->get_data(); 84 | $this->assertSame( 1, count( $data ) ); 85 | foreach ( $data as $plugin ) { 86 | $this->assertArrayHasKey( 'value', $plugin ); 87 | $this->assertArrayHasKey( 'label', $plugin ); 88 | } 89 | 90 | } 91 | 92 | /** 93 | * Test GET /products for EDD 94 | * 95 | * @since 1.1.0 96 | * 97 | * @group products_api 98 | * @group edd 99 | * @group price 100 | * 101 | * @covers ingot\testing\api\rest/products::get_price() 102 | */ 103 | public function testGetEDDPrice() { 104 | wp_set_current_user( 1 ); 105 | ingot_test_data_price::edd_create_simple_download( 72 ); 106 | $product = ingot_test_data_price::edd_create_simple_download( 7 ); 107 | 108 | $request = new \WP_REST_Request( 'GET', $this->namespaced_route . '/price/' . $product->ID ); 109 | $request->set_query_params( array( 110 | 'plugin' => 'edd' 111 | ) ); 112 | 113 | $response = $this->server->dispatch( $request ); 114 | $response = rest_ensure_response( $response ); 115 | $this->assertEquals( 200, $response->get_status() ); 116 | $data = (array) $response->get_data(); 117 | $this->assertArrayHasKey( 'price', $data ); 118 | $this->assertSame( ingot_sanitize_amount( 7 ), $data[ 'price' ] ); 119 | 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /tests/api/tests-settings.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_settings extends ingot_rest_test_case { 13 | 14 | /** 15 | * Route name 16 | * 17 | * @since 0.2.0 18 | * 19 | * @var string 20 | */ 21 | protected $route_name = 'settings'; 22 | 23 | public function tearDown() { 24 | parent::tearDown(); 25 | foreach( array( 26 | 'click_tracking', 27 | 'anon_tracking', 28 | 'license_code' 29 | ) as $setting ) { 30 | $saved = \ingot\testing\crud\settings::write( $setting, 0 ); 31 | } 32 | } 33 | 34 | /** 35 | * 36 | * @group rest 37 | * @group settings_rest 38 | */ 39 | public function testReadSettings() { 40 | wp_set_current_user( 1 ); 41 | $expected = array( 42 | 'click_tracking' => 1, 43 | 'anon_tracking' => 1, 44 | 'license_code' => 'batman' 45 | ); 46 | 47 | foreach( $expected as $setting => $value ){ 48 | if( 'license_code' == $expected ) { 49 | continue; 50 | } 51 | 52 | \ingot\testing\crud\settings::write( $setting, $value ); 53 | } 54 | 55 | $request = new \WP_REST_Request( 'GET', $this->namespaced_route ); 56 | 57 | 58 | $response = $this->server->dispatch( $request ); 59 | $response = rest_ensure_response( $response ); 60 | $this->assertEquals( 200, $response->get_status() ); 61 | $data = (array) $response->get_data(); 62 | foreach( $expected as $setting => $value ){ 63 | $this->assertArrayHasKey( $setting, $data ); 64 | if ( 'license_code' !== $setting ) { 65 | $this->assertEquals( $value, $data[ $setting ] ); 66 | } 67 | } 68 | 69 | 70 | } 71 | 72 | public function testUpdate() { 73 | wp_set_current_user( 1 ); 74 | $expected = array( 75 | 'click_tracking' => 0, 76 | 'anon_tracking' => 0, 77 | 'license_code' => 'batman' 78 | ); 79 | 80 | foreach( $expected as $setting => $value ){ 81 | \ingot\testing\crud\settings::write( $setting, $value ); 82 | } 83 | 84 | $request = new \WP_REST_Request( 'POST', $this->namespaced_route ); 85 | $request->set_query_params( array( 86 | 'click_tracking' => 'true', 87 | 'anon_tracking' => 'true', 88 | 'license_code' => 'allthespidermen' 89 | ) ); 90 | 91 | $response = $this->server->dispatch( $request ); 92 | $response = rest_ensure_response( $response ); 93 | $this->assertEquals( 200, $response->get_status() ); 94 | $data = (array) $response->get_data(); 95 | foreach( $expected as $setting => $value ){ 96 | $this->assertArrayHasKey( $setting, $data ); 97 | if( 'license_code' != $setting ) { 98 | $data[ $setting ] = intval( $data[ $setting ] ); 99 | $this->assertEquals( $value, $data[ $setting ], $setting ); 100 | } 101 | 102 | } 103 | 104 | 105 | } 106 | 107 | 108 | } 109 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | set_role('administrator'); 37 | global $wp_rest_server; 38 | if( ! is_object( $wp_rest_server )) { 39 | $wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' ); 40 | $wp_rest_server = new $wp_rest_server_class; 41 | } 42 | 43 | if( ! defined( 'INGOT_DEV_MODE' ) ) { 44 | define( 'INGOT_DEV_MODE', true ); 45 | } 46 | add_filter( 'ingot_run_cookies', '__return_true' ); 47 | remove_action( 'ingot_loaded', 'ingot_start_cookies' ); 48 | 49 | 50 | // Include helpers 51 | include_once( dirname( __FILE__ ) .'/api/rest-test-case.php' ); 52 | -------------------------------------------------------------------------------- /tests/crud/tests-defaults.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_defaults extends \WP_UnitTestCase{ 13 | 14 | /** 15 | * Test default threshold 16 | * 17 | * @since 0.1.1 18 | * 19 | * @covers \ingot\testing\utility\defaults::threshold() 20 | */ 21 | public function testThreshold() { 22 | $this->assertEquals( 500, \ingot\testing\utility\defaults::threshold() ); 23 | } 24 | 25 | /** 26 | * Test default initial 27 | * 28 | * @since 0.1.1 29 | * 30 | * @covers \ingot\testing\utility\defaults::initial() 31 | */ 32 | public function testInitial() { 33 | $this->assertEquals( 1000, \ingot\testing\utility\defaults::initial() ); 34 | } 35 | 36 | /** 37 | * Test default button color 38 | * 39 | * @since 0.1.1 40 | * 41 | * @covers \ingot\testing\utility\defaults::button_color() 42 | */ 43 | public function testButtonColor() { 44 | $this->assertEquals( '#2e3842', \ingot\testing\utility\defaults::button_color() ); 45 | } 46 | 47 | 48 | /** 49 | * Test default button filter 50 | * 51 | * @since 0.1.1 52 | * 53 | * @covers \ingot\testing\utility\defaults::button_color() 54 | * @covers ingot_default_button_color 55 | */ 56 | public function testButtonColorFilter() { 57 | add_filter( 'ingot_default_button_color', function() { 58 | return 'fff'; 59 | }); 60 | $this->assertEquals( '#fff', \ingot\testing\utility\defaults::button_color() ); 61 | } 62 | 63 | /** 64 | * Test default button filter returns trimmed 65 | * 66 | * @since 0.1.1 67 | * 68 | * @covers \ingot\testing\utility\defaults::button_color() 69 | * @covers ingot_default_button_color 70 | */ 71 | public function testButtonColorFilterTrim() { 72 | add_filter( 'ingot_default_button_color', function() { 73 | return '#fff'; 74 | }); 75 | //$this->assertEquals( 'fff', \ingot\testing\utility\defaults::button_color() ); 76 | } 77 | 78 | 79 | 80 | /** 81 | * Test default threshold filter 82 | * 83 | * @since 0.1.1 84 | * 85 | * @covers \ingot\testing\utility\defaults::threshold() 86 | * @covers ingot_default_threshold 87 | */ 88 | public function testThresholdFilter() { 89 | add_filter( 'ingot_default_threshold', function() { 90 | return 42; 91 | }); 92 | $this->assertEquals( 42, \ingot\testing\utility\defaults::threshold() ); 93 | } 94 | 95 | /** 96 | * Test default initial filter 97 | * 98 | * @since 0.1.1 99 | * 100 | * @covers \ingot\testing\utility\defaults::initial() 101 | * @covers ingot_default_initial 102 | */ 103 | public function testInitialFilter() { 104 | add_filter( 'ingot_default_initial', function() { 105 | return 9; 106 | }); 107 | $this->assertEquals( 9, \ingot\testing\utility\defaults::initial() ); 108 | } 109 | 110 | 111 | 112 | 113 | } 114 | -------------------------------------------------------------------------------- /tests/crud/tests-session_crud.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_session_crud extends \WP_UnitTestCase { 13 | 14 | public function setUp() { 15 | parent::setUp(); 16 | 17 | } 18 | public function tearDown() { 19 | parent::tearDown(); 20 | 21 | } 22 | 23 | 24 | /** 25 | * Test creating a session 26 | * 27 | * @since 0.3.0 28 | * 29 | * @group crud 30 | * @group session_crud 31 | * 32 | * @covers \ingot\testing\crud\session::create() 33 | * @covers \ingot\testing\crud\session::read() 34 | */ 35 | public function testCreate() { 36 | $id = \ingot\testing\crud\session::create( array() ); 37 | $this->assertTrue( is_numeric( $id ) ); 38 | $session = \ingot\testing\crud\session::read( $id ); 39 | $this->assertTrue( is_array( $session ) ); 40 | $fields = [ 41 | 'ID', 42 | 'created', 43 | 'ingot_ID', 44 | 'IP', 45 | 'uID', 46 | 'slug', 47 | 'used', 48 | 'click_url', 49 | 'click_test_ID' 50 | ]; 51 | 52 | foreach( $fields as $field ) { 53 | $this->assertArrayHasKey( $field, $session ); 54 | } 55 | 56 | $this->assertFalse( (bool) $session[ 'used' ] ); 57 | } 58 | 59 | /** 60 | * Test creating a session 61 | * 62 | * @since 0.3.0 63 | * 64 | * @group session 65 | * @group crud 66 | * 67 | * @covers \ingot\testing\crud\session::get_slug() 68 | */ 69 | public function testPageSlug() { 70 | $_SERVER[ 'REQUEST_URI' ] = '/pants'; 71 | $id = \ingot\testing\crud\session::create( array() ); 72 | 73 | $session = \ingot\testing\crud\session::read( $id ); 74 | $this->assertSame( '/pants', $session[ 'slug' ] ); 75 | } 76 | 77 | /** 78 | * Test the is_used function 79 | * 80 | * @since 0.3.0 81 | * 82 | * @group session 83 | * @group crud 84 | * 85 | * @covers \ingot\testing\crud\session::is_used() 86 | */ 87 | public function testNotUsedYet() { 88 | 89 | $id = \ingot\testing\crud\session::create( array() ); 90 | $this->assertTrue( is_numeric( $id ) ); 91 | 92 | $this->assertFalse( \ingot\testing\crud\session::is_used( $id ) ); 93 | 94 | 95 | } 96 | 97 | /** 98 | * Test that we can mark a session as used 99 | * 100 | * @since 0.3.0 101 | * 102 | * @group session 103 | * @group crud 104 | * 105 | * @covers \ingot\testing\crud\session::mark_used() 106 | */ 107 | public function testMarkUsed() { 108 | 109 | $id = \ingot\testing\crud\session::create( array() ); 110 | 111 | $this->assertTrue( is_numeric( $id ) ); 112 | \ingot\testing\crud\session::mark_used( $id ); 113 | $session = \ingot\testing\crud\session::read( $id ); 114 | $this->assertSame( '1', $session[ 'used' ] ); 115 | 116 | } 117 | 118 | /** 119 | * Test item exists method 120 | * 121 | * @since 1.1.0 122 | * 123 | * @group session 124 | * @group session_crud 125 | * @group crud 126 | * 127 | * @covers \ingot\testing\crud\group::session() 128 | */ 129 | public function testExists(){ 130 | $id = \ingot\testing\crud\session::create( [], true ); 131 | 132 | $this->assertTrue( is_numeric( $id ) ); 133 | $this->assertTrue( \ingot\testing\crud\session::exists( $id ) ); 134 | 135 | $this->assertFalse( \ingot\testing\crud\session::exists( 99999 ) ); 136 | 137 | \ingot\testing\crud\session::delete( $id ); 138 | $this->assertFalse( \ingot\testing\crud\session::exists( $id ) ); 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /tests/crud/tests-settings_crud.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_settings_crud extends \WP_UnitTestCase { 13 | 14 | public function tearDown() { 15 | parent::tearDown(); 16 | foreach( array( 17 | 'click_tracking', 18 | 'anon_tracking', 19 | 'license_code' 20 | ) as $setting ) { 21 | $saved = \ingot\testing\crud\settings::write( $setting, 0 ); 22 | } 23 | } 24 | 25 | /** 26 | * Test save click tracking 27 | * 28 | * @since 0.2.0 29 | * 30 | * @group crud 31 | * @group settings_crud 32 | * 33 | * @covers \ingot\testing\crud\settings::write() 34 | */ 35 | public function testSaveClickTracking() { 36 | $saved = \ingot\testing\crud\settings::write( 'click_tracking', true ); 37 | $this->assertTrue( $saved ); 38 | } 39 | 40 | /** 41 | * Test save anon tracking 42 | * 43 | * @since 0.2.0 44 | * 45 | * @group crud 46 | * @group settings_crud 47 | * 48 | * @covers \ingot\testing\crud\settings::write() 49 | */ 50 | public function testSaveAnonTracking() { 51 | $saved = \ingot\testing\crud\settings::write( 'anon_tracking', true ); 52 | $this->assertTrue( $saved ); 53 | } 54 | 55 | 56 | /** 57 | * Test save license 58 | * 59 | * @since 0.2.0 60 | * 61 | * @group crud 62 | * @group settings_crud 63 | * 64 | * @covers \ingot\testing\crud\settings::write() 65 | */ 66 | public function testSaveLicense() { 67 | //not sure how to test license validation 68 | return; 69 | $saved = \ingot\testing\crud\settings::write( 'license_code', rand() ); 70 | $this->assertTrue( $saved ); 71 | } 72 | 73 | /** 74 | * Test reading click tracking 75 | * 76 | * @since 0.2.0 77 | * 78 | * @group crud 79 | * @group settings_crud 80 | * 81 | * @covers \ingot\testing\crud\settings::read() 82 | */ 83 | public function testReadClickTracking() { 84 | $saved = \ingot\testing\crud\settings::write( 'click_tracking', true ); 85 | $this->assertSame( 1, \ingot\testing\crud\settings::read( 'click_tracking' ) ); 86 | $saved = \ingot\testing\crud\settings::write( 'click_tracking', false ); 87 | $this->assertSame( 0, \ingot\testing\crud\settings::read( 'click_tracking' ) ); 88 | } 89 | 90 | /** 91 | * Test reading anon tracking 92 | * 93 | * @since 0.2.0 94 | * 95 | * @group crud 96 | * @group settings_crud 97 | * 98 | * @covers \ingot\testing\crud\settings::read() 99 | */ 100 | public function testReadAnonTracking() { 101 | $saved = \ingot\testing\crud\settings::write( 'anon_tracking', true ); 102 | $this->assertSame( 1, \ingot\testing\crud\settings::read( 'anon_tracking' ) ); 103 | $saved = \ingot\testing\crud\settings::write( 'anon_tracking', false ); 104 | $this->assertSame( 0, \ingot\testing\crud\settings::read( 'anon_tracking' ) ); 105 | } 106 | 107 | /** 108 | * Test reading licensing 109 | * 110 | * @since 0.2.0 111 | * 112 | * @group crud 113 | * @group settings_crud 114 | * 115 | * @covers \ingot\testing\crud\settings::read() 116 | */ 117 | public function testReadLicense() { 118 | //not sure how to test license validation 119 | return; 120 | $code = (string) rand(); 121 | $saved = \ingot\testing\crud\settings::write( 'license_code', $code ); 122 | $this->assertSame( $code, \ingot\testing\crud\settings::read( 'license_code' ) ); 123 | $code = (string) rand(); 124 | $saved = \ingot\testing\crud\settings::write( 'license_code', $code ); 125 | $this->assertSame( $code, \ingot\testing\crud\settings::read( 'license_code' ) ); 126 | 127 | } 128 | 129 | 130 | /** 131 | * Test that saving invalid setting click tracking does not work 132 | * 133 | * @since 0.2.0 134 | * 135 | * @group crud 136 | * @group settings_crud 137 | * 138 | * @covers \ingot\testing\crud\settings::write() 139 | */ 140 | public function testSaveClickTrackingInvalid() { 141 | $saved = \ingot\testing\crud\settings::write( 'click_tracking', rand( 7, 900 ) ); 142 | $this->assertSame( 0, \ingot\testing\crud\settings::read( 'click_tracking' ) ); 143 | } 144 | 145 | /** 146 | * Test that saving invalid setting anon tracking does not work 147 | * 148 | * @since 0.2.0 149 | * 150 | * @group crud 151 | * @group settings_crud 152 | * 153 | * @covers \ingot\testing\crud\settings::write() 154 | */ 155 | public function testSaveAnonTrackingInvalid() { 156 | $saved = \ingot\testing\crud\settings::write( 'anon_tracking', rand( 7, 900 ) ); 157 | $this->assertSame( 0, \ingot\testing\crud\settings::read( 'anon_tracking' ) ); 158 | } 159 | 160 | /** 161 | * Test that saving invalid license code does not work 162 | * 163 | * @since 0.2.0 164 | * 165 | * @group crud 166 | * @group settings_crud 167 | * 168 | * @covers \ingot\testing\crud\settings::write() 169 | */ 170 | public function testSaveLicenseCodeInvalid() { 171 | $saved = \ingot\testing\crud\settings::write( 'license_code', array() ); 172 | $this->assertSame( '', \ingot\testing\crud\settings::read( 'license_code' ) ); 173 | 174 | $saved = \ingot\testing\crud\settings::write( 'license_code', serialize( array( 'bat', 'man' ) ) ); 175 | $this->assertSame( '', \ingot\testing\crud\settings::read( 'license_code' ) ); 176 | 177 | $saved = \ingot\testing\crud\settings::write( 'license_code', wp_json_encode( array( 'bat', 'man' ) ) ); 178 | $this->assertSame( '', \ingot\testing\crud\settings::read( 'license_code' ) ); 179 | 180 | } 181 | 182 | /** 183 | * Test that we can not save an invalid setting 184 | * 185 | * @since 0.2.0 186 | * 187 | * @group crud 188 | * @group settings_crud 189 | * 190 | * @covers \ingot\testing\crud\settings::write() 191 | */ 192 | public function testSaveInvalidSetting() { 193 | $saved = \ingot\testing\crud\settings::write( 'batman', 'batcave' ); 194 | $this->assertFalse( $saved ); 195 | $this->assertFalse( get_option( 'ingot_settings_batman', false ) ); 196 | } 197 | 198 | /** 199 | * Test that we can not get an invalid setting, even if its prefixed with ingot_settings 200 | * 201 | * @since 0.2.0 202 | * 203 | * @group crud 204 | * @group settings_crud 205 | * 206 | * @covers \ingot\testing\crud\settings::write() 207 | */ 208 | public function testReadInvalidSetting() { 209 | update_option( 'ingot_settings_cat', 'dog' ); 210 | $read = \ingot\testing\crud\settings::read( 'cat' ); 211 | $this->assertFalse( $read ); 212 | 213 | } 214 | 215 | 216 | } 217 | -------------------------------------------------------------------------------- /tests/crud/tests-tracking.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_tracking extends \WP_UnitTestCase { 13 | 14 | public function setUp() { 15 | parent::setUp(); 16 | $_SERVER[ 'HTTP_USER_AGENT' ] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'; 17 | 18 | } 19 | 20 | public function tearDown() { 21 | parent::tearDown(); 22 | \ingot\testing\crud\tracking::delete( 'all' ); 23 | } 24 | 25 | /** 26 | * Test that table name is right 27 | * 28 | * @since 0.0.7 29 | * 30 | * @group crud 31 | * @group tracking_crud 32 | * 33 | * @covers \ingot\testing\crud\tracking::get_table_name() 34 | */ 35 | public function testTableName() { 36 | $tablename = \ingot\testing\crud\tracking::get_table_name(); 37 | global $wpdb; 38 | $this->assertEquals( $wpdb->prefix . 'ingot_tracking', $tablename ); 39 | } 40 | 41 | /** 42 | * Test that ceating with only the required field works 43 | * 44 | * @since 0.0.7 45 | * 46 | * @group crud 47 | * @group tracking_crud 48 | * 49 | * @covers \ingot\testing\crud\tracking::create() 50 | * @covers \ingot\testing\crud\tracking::fill_in() 51 | */ 52 | public function testCreateMinimal() { 53 | $t_id = rand(); 54 | $params = array( 55 | 'test_ID' => $t_id 56 | ); 57 | $id = \ingot\testing\crud\tracking::create( $params ); 58 | $this->assertTrue( is_numeric( $id ) ); 59 | 60 | } 61 | 62 | /** 63 | * Test read of a minimially created item. 64 | * 65 | * @since 0.0.7 66 | * 67 | * @group crud 68 | * @group tracking_crud 69 | * 70 | * @covers \ingot\testing\crud\tracking::create() 71 | * @covers \ingot\testing\crud\tracking::read() 72 | */ 73 | public function testRead() { 74 | 75 | $t_id = rand(1, 1029 ); 76 | $params = array( 77 | 'test_ID' => $t_id 78 | ); 79 | $id = \ingot\testing\crud\tracking::create( $params ); 80 | $this->assertTrue( is_numeric( $id ) ); 81 | 82 | $tracking = \ingot\testing\crud\tracking::read( $id ); 83 | 84 | $this->assertTrue( is_array( $tracking ) ); 85 | $this->assertEquals( $t_id, $tracking[ 'test_ID' ] ); 86 | 87 | } 88 | 89 | /** 90 | * Test that optional fields are filled in. 91 | * 92 | * @since 0.0.7 93 | * 94 | * @group crud 95 | * @group tracking_crud 96 | * 97 | * @covers \ingot\testing\crud\tracking::create() 98 | * @covers \ingot\testing\crud\crud::fill_in() 99 | * @covers \ingot\testing\crud\crud::validate_config() 100 | */ 101 | public function testCreateFillIn() { 102 | 103 | $params = array( 104 | 'test_ID' => 42 105 | ); 106 | 107 | $created = \ingot\testing\crud\tracking::create( $params ); 108 | $this->assertTrue( is_numeric( $created ) ); 109 | $tracking = \ingot\testing\crud\tracking::read( $created ); 110 | 111 | foreach( \ingot\testing\crud\tracking::get_required_fields() as $field ) { 112 | $this->assertArrayHasKey( $field, $tracking ); 113 | } 114 | 115 | foreach( \ingot\testing\crud\tracking::get_needed_fields() as $field ) { 116 | $this->assertArrayHasKey( $field, $tracking ); 117 | } 118 | 119 | $this->assertEquals( '127.0.0.1', ingot_get_ip() ); 120 | 121 | } 122 | 123 | /** 124 | * Test create with all data filled in. 125 | * 126 | * @since 0.0.7 127 | * 128 | * @group crud 129 | * @group tracking_crud 130 | * 131 | * @covers \ingot\testing\crud\tracking::create() 132 | * @covers \ingot\testing\crud\tracking::read() 133 | */ 134 | public function testCreateWithData() { 135 | 136 | $params = array( 137 | 'test_ID' => 2, 138 | 'group_ID' => 3, 139 | 'IP' => '2.3.5.8.13', 140 | 'UTM' => array( 'a' => 'batman', 'c' => 'robin' ), 141 | 'browser' => 'firefox', 142 | 'user_agent' => 'windows and stuff', 143 | 'time' => current_time( 'mysql'), 144 | 'meta' => array( 'bees' => 'knees') 145 | ); 146 | 147 | $created = \ingot\testing\crud\tracking::create( $params ); 148 | $tracking = \ingot\testing\crud\tracking::read( $created ); 149 | $params[ 'ID' ] = $created; 150 | foreach( $params as $key => $value ) { 151 | $this->assertEquals( $value, $tracking[ $key ] ); 152 | } 153 | 154 | } 155 | 156 | /** 157 | * Test item exists method 158 | * 159 | * @since 1.1.0 160 | * 161 | * @group tracking 162 | * @group tracking_crud 163 | * @group crud 164 | * 165 | * @covers \ingot\testing\crud\group::tracking() 166 | */ 167 | public function testExists(){ 168 | $params = array( 169 | 'test_ID' => rand() 170 | ); 171 | $id = \ingot\testing\crud\tracking::create( $params, true ); 172 | 173 | $this->assertTrue( is_numeric( $id ) ); 174 | $this->assertTrue( \ingot\testing\crud\tracking::exists( $id ) ); 175 | 176 | $this->assertFalse( \ingot\testing\crud\tracking::exists( 99999 ) ); 177 | 178 | $deleted = \ingot\testing\crud\tracking::delete( $id ); 179 | 180 | $this->assertTrue( $deleted ); 181 | $this->assertFalse( \ingot\testing\crud\tracking::exists( $id ) ); 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /tests/crud/tests-variants.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_variants extends \WP_UnitTestCase { 12 | 13 | 14 | public function setUp() { 15 | parent::setUp(); 16 | } 17 | 18 | public function tearDown() { 19 | parent::tearDown(); 20 | \ingot\testing\crud\variant::delete( 'all' ); 21 | } 22 | 23 | /** 24 | * Test that table name is right 25 | * 26 | * @since 0.4.0 27 | * 28 | * @group crud 29 | * @group variant_crud 30 | * 31 | * @covers \ingot\testing\crud\variant::get_table_name() 32 | */ 33 | public function testTableName() { 34 | $tablename = \ingot\testing\crud\variant::get_table_name(); 35 | global $wpdb; 36 | $this->assertEquals( $wpdb->prefix . 'ingot_variant', $tablename ); 37 | } 38 | 39 | /** 40 | * Test create 41 | * 42 | * @since 0.4.0 43 | * 44 | * @group crud 45 | * @group variant_crud 46 | * 47 | * @covers \ingot\testing\crud\variant::create() 48 | */ 49 | public function testCreateMinimal() { 50 | $params = [ 51 | 'type' => 'click', 52 | 'group_ID' => rand(), 53 | 'content' => rand() 54 | ]; 55 | 56 | $created = \ingot\testing\crud\variant::create( $params ); 57 | $this->assertTrue( is_int( $created ) ); 58 | $this->assertFalse( is_wp_error( $created ) ); 59 | $this->assertTrue( is_numeric( $created ) ); 60 | 61 | } 62 | 63 | /** 64 | * Test invalid type -- must make WP_Error 65 | * 66 | * @since 0.4.0 67 | * 68 | * @group crud 69 | * @group variant_crud 70 | * 71 | * @covers \ingot\testing\crud\variant::create() 72 | * @covers \ingot\testing\crud\variant::validate_config() 73 | */ 74 | public function testInvalidType() { 75 | $params = [ 76 | 'type' => 'josh', 77 | 'group_ID' => rand(), 78 | 'content' => rand() 79 | ]; 80 | 81 | $created = \ingot\testing\crud\variant::create( $params ); 82 | $this->assertWPError( $created ); 83 | 84 | } 85 | 86 | /** 87 | * Test invalid group -- must make WP_Error 88 | * 89 | * @since 0.4.0 90 | * 91 | * @group crud 92 | * @group variant_crud 93 | * 94 | * @covers \ingot\testing\crud\variant::create() 95 | * @covers \ingot\testing\crud\variant::validate_config() 96 | */ 97 | public function testInvalidGroup() { 98 | $params = [ 99 | 'type' => 'click', 100 | 'group_ID' => 'l', 101 | 'content' => rand() 102 | ]; 103 | 104 | $created = \ingot\testing\crud\variant::create( $params ); 105 | $this->assertWPError( $created ); 106 | 107 | } 108 | 109 | /** 110 | * Test invalid content for a price test -- must make WP_Error 111 | * 112 | * @since 0.4.0 113 | * 114 | * @group crud 115 | * @group variant_crud 116 | * 117 | * @covers \ingot\testing\crud\variant::create() 118 | * @covers \ingot\testing\crud\variant::validate_config() 119 | */ 120 | public function testInvalidContent() { 121 | $params = [ 122 | 'type' => 'price', 123 | 'group_ID' => '42', 124 | 'content' => 'lorem ipsum sandwich' 125 | ]; 126 | 127 | $created = \ingot\testing\crud\variant::create( $params ); 128 | $this->assertWPError( $created ); 129 | 130 | } 131 | 132 | /** 133 | * Test reading 134 | * 135 | * @since 0.4.0 136 | * 137 | * @group crud 138 | * @group variant_crud 139 | * 140 | * @covers \ingot\testing\crud\variant::read() 141 | */ 142 | public function testRead(){ 143 | 144 | $time = current_time( 'mysql' ); 145 | $params = [ 146 | 'type' => 'click', 147 | 'group_ID' => '42', 148 | 'content' => '12345', 149 | 'levers' => [rand(),rand()], 150 | 'created' => $time, 151 | 'modified' => $time, 152 | 'meta' => [rand(),rand()] 153 | ]; 154 | 155 | $created = \ingot\testing\crud\variant::create( $params ); 156 | $this->assertTrue( is_int( $created ) ); 157 | $variant = \ingot\testing\crud\variant::read( $created ); 158 | $this->assertEquals( $created, $variant[ 'ID' ] ); 159 | foreach( \ingot\testing\crud\variant::get_all_fields() as $field ){ 160 | $this->assertArrayHasKey( $field, $variant ); 161 | if ( 'levers' != $field ) { 162 | $this->assertEquals( $variant[ $field ], $params[ $field ], $field ); 163 | } 164 | } 165 | 166 | } 167 | 168 | /** 169 | * Test that data is filled in properly 170 | * 171 | * 172 | * @since 0.4.0 173 | * 174 | * @group crud 175 | * @group variant_crud 176 | * 177 | * @covers \ingot\testing\crud\variant::fill_in() 178 | */ 179 | public function testFillIn(){ 180 | $params = [ 181 | 'type' => 'click', 182 | 'group_ID' => rand(), 183 | 'content' => rand() 184 | ]; 185 | 186 | $created = \ingot\testing\crud\variant::create( $params ); 187 | $this->assertTrue( is_int( $created ) ); 188 | $variant = \ingot\testing\crud\variant::read( $created ); 189 | $this->assertEquals( $created, $variant[ 'ID' ] ); 190 | 191 | foreach( \ingot\testing\crud\variant::get_all_fields() as $field ){ 192 | $this->assertArrayHasKey( $field, $variant ); 193 | } 194 | } 195 | 196 | /** 197 | * Test that data is filled in properly 198 | * 199 | * 200 | * @since 0.4.0 201 | * 202 | * @group crud 203 | * @group variant_crud 204 | * 205 | * @covers \ingot\testing\crud\update::fill_in() 206 | */ 207 | public function testUpdate() { 208 | $params = [ 209 | 'type' => 'click', 210 | 'group_ID' => rand(), 211 | 'content' => rand() 212 | ]; 213 | $created = \ingot\testing\crud\variant::create( $params ); 214 | $variant = \ingot\testing\crud\variant::read( $created ); 215 | $variant[ 'content' ] = 'I AM THE BATMAN'; 216 | \ingot\testing\crud\variant::update( $variant, $created ); 217 | $variant = \ingot\testing\crud\variant::read( $created ); 218 | $this->assertFalse( is_wp_error( $variant ) ); 219 | $this->assertSame('I AM THE BATMAN', $variant[ 'content' ] ); 220 | 221 | } 222 | 223 | /** 224 | * Test that we can delete a group 225 | * 226 | * @since 0.4.0 227 | * 228 | * @group crud 229 | * @group variant_crud 230 | * 231 | * @covers \ingot\testing\crud\variant::delete() 232 | */ 233 | public function testDelete() { 234 | $params = [ 235 | 'type' => 'click', 236 | 'group_ID' => rand(), 237 | 'content' => rand() 238 | ]; 239 | $created = \ingot\testing\crud\variant::create( $params ); 240 | 241 | \ingot\testing\crud\variant::delete( $created ); 242 | $variant = \ingot\testing\crud\variant::read( $created ); 243 | $this->assertFalse( is_array( $variant ) ); 244 | 245 | } 246 | 247 | /** 248 | * Test that we can delete all variants 249 | * 250 | * @since 0.4.0 251 | * 252 | * @group crud 253 | * @group variant_crud 254 | * 255 | * @covers \ingot\testing\crud\variant::delete() 256 | */ 257 | public function testDeleteAll() { 258 | for ( $i=0; $i <= 7; $i++ ) { 259 | $params = [ 260 | 'type' => 'click', 261 | 'group_ID' => $i + rand(), 262 | 'content' => $i 263 | ]; 264 | $created[ $i ] = \ingot\testing\crud\variant::create( $params ); 265 | } 266 | 267 | 268 | \ingot\testing\crud\variant::delete( 'all' ); 269 | 270 | $items = \ingot\testing\crud\variant::get_items( array() ); 271 | $this->assertEquals( count( $items ), 0 ); 272 | 273 | } 274 | 275 | /** 276 | * Test item exists method 277 | * 278 | * @since 1.1.0 279 | * 280 | * @group variant 281 | * @group variant_crud 282 | * @group crud 283 | * 284 | * @covers \ingot\testing\crud\group::variant() 285 | */ 286 | public function testExists(){ 287 | $params = [ 288 | 'type' => 'click', 289 | 'group_ID' => rand(), 290 | 'content' => rand() 291 | ]; 292 | $id = \ingot\testing\crud\variant::create( $params ); 293 | 294 | $this->assertTrue( is_numeric( $id ) ); 295 | $this->assertTrue( \ingot\testing\crud\variant::exists( $id ) ); 296 | 297 | $this->assertFalse( \ingot\testing\crud\variant::exists( 99999 ) ); 298 | 299 | \ingot\testing\crud\variant::delete( $id ); 300 | $this->assertFalse( \ingot\testing\crud\variant::exists( $id ) ); 301 | } 302 | 303 | } 304 | -------------------------------------------------------------------------------- /tests/functions_for_tests.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | 12 | 13 | function ingot_tests_make_groups( $add_variants = true, $total_groups = 5, $variants_per_group = 3, $args = array() ){ 14 | return ingot_tests_data::make_groups( $add_variants, $total_groups, $variants_per_group, $args ); 15 | 16 | } 17 | 18 | 19 | class ingot_tests_data { 20 | 21 | /** 22 | * Create groups with variants, optionally added to them. 23 | * 24 | * @param bool $add_variants Optional. If true, the default, variants are added to groups via groups object. If false, they are created, IDs are returned but they will nto be associated with a group properly. 25 | * @param int $total_groups Optional. Default is 5. 26 | * @param int $variants_per_group Optional. Default is 3. 27 | * @param array $args Optional 28 | * 29 | * @return array 30 | */ 31 | public static function make_groups( $add_variants = true, $total_groups = 5, $variants_per_group = 3, $args = array() ){ 32 | $defaults = [ 33 | 'group_args' => [ 34 | 'name' => rand(), 35 | 'type' => 'click', 36 | 'sub_type' => 'button', 37 | 'meta' => [ 'link' => 'https://bats.com' ], 38 | ], 39 | 'variant_args' => [ 40 | 'type' => 'click', 41 | 'group_ID' => 1, 42 | 'content' => rand() 43 | ] 44 | ]; 45 | 46 | $keys = array_keys( $defaults ); 47 | foreach ( $keys as $i => $key ) { 48 | if ( ! empty( $args[ $key ] ) ) { 49 | $args[ $key ] = wp_parse_args( 50 | $args[ $key ], 51 | $defaults[ $key ] 52 | ); 53 | 54 | }else{ 55 | $args[ $key ] = $defaults[ $key ]; 56 | } 57 | 58 | } 59 | 60 | $groups = [ 'ids' => [], 'variants' => [] ]; 61 | $group_args = $args[ 'group_args' ]; 62 | $variant_args = $args[ 'variant_args' ]; 63 | for ( $g = 0; $g <= $total_groups; $g++ ) { 64 | $variants = []; 65 | $group_args[ 'name' ] = (string) $g . rand(); 66 | 67 | $group_id = \ingot\testing\crud\group::create( $group_args, true ); 68 | 69 | $groups[ 'ids' ][] = $group_id; 70 | 71 | $variant_args[ 'group_ID' ] = $group_id; 72 | 73 | for( $v = 0; $v <= $variants_per_group; $v++ ) { 74 | $variant_id = \ingot\testing\crud\variant::create( $variant_args, true ); 75 | $variants[] = $variant_id; 76 | 77 | } 78 | 79 | $groups[ 'variants' ][ $group_id ] = $variants; 80 | 81 | if ( $add_variants ) { 82 | if ( is_user_logged_in() ) { 83 | $obj = new \ingot\testing\object\group( $group_id ); 84 | $obj->update_group( [ 'variants' => $variants ] ); 85 | }else{ 86 | $_group = \ingot\testing\crud\group::read( $group_id ); 87 | $_group[ 'variants' ] = $variants; 88 | $saved = \ingot\testing\crud\group::update( $_group, $group_id, true ); 89 | } 90 | } 91 | 92 | } 93 | 94 | return $groups; 95 | } 96 | 97 | public static function click_link_group($add_variants = true, $total_groups = 5, $variants_per_group = 3 ){ 98 | return self::make_groups( $add_variants, $total_groups, $variants_per_group ); 99 | } 100 | 101 | public static function click_button_group( $add_variants = true, $total_groups = 5, $variants_per_group = 3 ) { 102 | $args = [ 103 | 'group_args' => [ 104 | 'sub_type' => 'button', 105 | 'meta' => [ 106 | 'link' => 'https://bats.com', 107 | 'color' => '#fff', 108 | 'background_color' => '#000' 109 | ], 110 | ] 111 | ]; 112 | return self::make_groups( $add_variants, $total_groups, $variants_per_group, $args ); 113 | 114 | } 115 | 116 | public static function click_button_color_group( $add_variants = true, $total_groups = 5, $variants_per_group = 3 ) { 117 | $args = [ 118 | 'group_args' => [ 119 | 'sub_type' => 'button_color', 120 | 'meta' => [ 121 | 'link' => 'https://bats.com', 122 | 'color_test_text' => 'Default Text for group', 123 | ], 124 | 'variant_args' => [ 125 | 'color' => '#fff', 126 | 'background_color' => '#000' 127 | ] 128 | ] 129 | ]; 130 | return self::make_groups( $add_variants, $total_groups, $variants_per_group, $args ); 131 | 132 | } 133 | 134 | 135 | } 136 | 137 | /** 138 | * Create sample data for price tests 139 | * 140 | * Class ingot_price_data_edd 141 | */ 142 | class ingot_test_data_price { 143 | 144 | public static function edd_tests( $base_price = 10, $variable_price = false ){ 145 | if ( $variable_price ){ 146 | $product = self::edd_create_variable_download($base_price); 147 | }else{ 148 | $product = self::edd_create_simple_download($base_price); 149 | } 150 | $args = self::edd_args( $product->ID ); 151 | 152 | return self::make_groups( $args ); 153 | } 154 | 155 | public static function make_groups( $args ){ 156 | 157 | $group_args = $args[ 'group_args' ]; 158 | $data[ 'product_ID' ] = $group_args[ 'wp_ID' ]; 159 | $variant_args = $args[ 'variant_args' ]; 160 | 161 | $variants = []; 162 | $group_args[ 'name' ] = rand(); 163 | 164 | $group_id = \ingot\testing\crud\group::create( $group_args, true ); 165 | if( is_wp_error( $group_id ) ){ 166 | return $group_id; 167 | } 168 | $data[ 'group_ID' ] = $group_id; 169 | 170 | $variant_args[ 'group_ID' ] = $group_id; 171 | $price_variations = []; 172 | 173 | for( $v = 0; $v <= 5; $v++ ) { 174 | $variation = rand_float(); 175 | $variant_args[ 'meta' ][ 'price' ] = $variation; 176 | $variant_id = \ingot\testing\crud\variant::create( $variant_args, true ); 177 | 178 | if ( is_numeric( $variant_id) ) { 179 | $variants[] = $variant_id; 180 | $price_variations[ $variant_id ] = $variation; 181 | 182 | }else{ 183 | return $variant_id; 184 | } 185 | 186 | } 187 | 188 | $data[ 'variants' ] = $variants; 189 | $data[ 'price_variations' ] = $price_variations; 190 | 191 | $_group = \ingot\testing\crud\group::read( $group_id ); 192 | $_group[ 'variants' ] = $variants; 193 | $saved = \ingot\testing\crud\group::update( $_group, $group_id, true ); 194 | if( is_wp_error( $saved ) ){ 195 | 196 | echo $saved->get_error_messages(); 197 | die(); 198 | } 199 | 200 | $data[ 'group' ] = \ingot\testing\crud\group::read( $group_id ); 201 | 202 | return $data; 203 | } 204 | 205 | /** 206 | * @param $product_id 207 | * 208 | * @return array 209 | */ 210 | public static function edd_args( $product_id ) { 211 | return [ 212 | 'group_args' => [ 213 | 'type' => 'price', 214 | 'sub_type' => 'edd', 215 | 'meta' => [ 'product_ID' => $product_id ], 216 | 'wp_ID' => $product_id 217 | ], 218 | 'variant_args' => [ 219 | 'type' => 'price', 220 | 'meta' => [ 221 | 'price' => [ ] 222 | ], 223 | 'content' => $product_id 224 | ] 225 | ]; 226 | 227 | } 228 | 229 | 230 | /** 231 | * 232 | * 233 | * Copied from https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/tests/helpers/class-helper-download.php 234 | * @return \WP_Post 235 | */ 236 | public static function edd_create_simple_download($base_price) { 237 | $post_id = wp_insert_post( array( 238 | 'post_title' => 'Test Download Product', 239 | 'post_name' => 'test-download-product', 240 | 'post_type' => 'download', 241 | 'post_status' => 'publish' 242 | ) ); 243 | $_download_files = array( 244 | array( 245 | 'name' => 'Simple File 1', 246 | 'file' => 'http://localhost/simple-file1.jpg', 247 | 'condition' => 0 248 | ), 249 | ); 250 | $meta = array( 251 | 'edd_price' => $base_price, 252 | '_variable_pricing' => 0, 253 | 'edd_variable_prices' => false, 254 | 'edd_download_files' => array_values( $_download_files ), 255 | '_edd_download_limit' => 20, 256 | '_edd_hide_purchase_link' => 1, 257 | 'edd_product_notes' => 'Purchase Notes', 258 | '_edd_product_type' => 'default', 259 | '_edd_download_earnings' => 40, 260 | '_edd_download_sales' => 2, 261 | '_edd_download_limit_override_1' => 1, 262 | 'edd_sku' => 'sku_0012' 263 | ); 264 | foreach( $meta as $key => $value ) { 265 | update_post_meta( $post_id, $key, $value ); 266 | } 267 | return get_post( $post_id ); 268 | } 269 | 270 | /** 271 | * 272 | * Copied from https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/tests/helpers/class-helper-download.php 273 | * 274 | * @return \WP_Post 275 | */ 276 | public static function edd_create_variable_download($base_price) { 277 | $post_id = wp_insert_post( array( 278 | 'post_title' => 'Variable Test Download Product', 279 | 'post_name' => 'variable-test-download-product', 280 | 'post_type' => 'download', 281 | 'post_status' => 'publish' 282 | ) ); 283 | $_variable_pricing = array( 284 | array( 285 | 'name' => 'Simple', 286 | 'amount' => $base_price 287 | ), 288 | array( 289 | 'name' => 'Advanced', 290 | 'amount' => $base_price * 10 291 | ) 292 | ); 293 | $_download_files = array( 294 | array( 295 | 'name' => 'File 1', 296 | 'file' => 'http://localhost/file1.jpg', 297 | 'condition' => 0, 298 | ), 299 | array( 300 | 'name' => 'File 2', 301 | 'file' => 'http://localhost/file2.jpg', 302 | 'condition' => 'all', 303 | ), 304 | ); 305 | $meta = array( 306 | 'edd_price' => $base_price, 307 | '_variable_pricing' => 1, 308 | '_edd_price_options_mode' => 'on', 309 | 'edd_variable_prices' => array_values( $_variable_pricing ), 310 | 'edd_download_files' => array_values( $_download_files ), 311 | '_edd_download_limit' => 20, 312 | '_edd_hide_purchase_link' => 1, 313 | 'edd_product_notes' => 'Purchase Notes', 314 | '_edd_product_type' => 'default', 315 | '_edd_download_earnings' => 120, 316 | '_edd_download_sales' => 6, 317 | '_edd_download_limit_override_1' => 1, 318 | 'edd_sku' => 'sku_0012', 319 | ); 320 | foreach ( $meta as $key => $value ) { 321 | update_post_meta( $post_id, $key, $value ); 322 | } 323 | return get_post( $post_id ); 324 | } 325 | 326 | /** 327 | * 328 | * Based on: https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/tests/helpers/class-helper-payment.php 329 | * 330 | * @param \WP_Post $download 331 | * 332 | * @return int Payment ID 333 | */ 334 | public static function edd_create_simple_payment( $download ) { 335 | global $edd_options; 336 | // Enable a few options 337 | $edd_options['enable_sequential'] = '1'; 338 | $edd_options['sequential_prefix'] = 'EDD-'; 339 | update_option( 'edd_settings', $edd_options ); 340 | $simple_download = $download; 341 | 342 | /** Generate some sales */ 343 | $user = get_userdata(1); 344 | $user_info = array( 345 | 'id' => $user->ID, 346 | 'email' => $user->user_email, 347 | 'first_name' => $user->first_name, 348 | 'last_name' => $user->last_name, 349 | 'discount' => 'none' 350 | ); 351 | $download_details = array( 352 | array( 353 | 'id' => $simple_download->ID, 354 | 'options' => array( 355 | 'price_id' => 0 356 | ) 357 | ), 358 | 359 | ); 360 | $total = 0; 361 | $simple_price = get_post_meta( $simple_download->ID, 'edd_price', true ); 362 | 363 | $total = $simple_price; 364 | $cart_details = array( 365 | array( 366 | 'name' => 'Test Download', 367 | 'id' => $simple_download->ID, 368 | 'item_number' => array( 369 | 'id' => $simple_download->ID, 370 | 'options' => array( 371 | 'price_id' => 1 372 | ) 373 | ), 374 | 'price' => $simple_price, 375 | 'item_price' => $simple_price, 376 | 'tax' => 0, 377 | 'quantity' => 1 378 | ), 379 | ); 380 | $purchase_data = array( 381 | 'price' => number_format( (float) $total, 2 ), 382 | 'date' => date( 'Y-m-d H:i:s', strtotime( '-1 day' ) ), 383 | 'purchase_key' => strtolower( md5( uniqid() ) ), 384 | 'user_email' => $user_info['email'], 385 | 'user_info' => $user_info, 386 | 'currency' => 'USD', 387 | 'downloads' => $download_details, 388 | 'cart_details' => $cart_details, 389 | 'status' => 'pending' 390 | ); 391 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; 392 | $_SERVER['SERVER_NAME'] = 'edd_virtual'; 393 | $payment_id = edd_insert_payment( $purchase_data ); 394 | $key = $purchase_data['purchase_key']; 395 | $transaction_id = 'FIR3SID3'; 396 | edd_set_payment_transaction_id( $payment_id, $transaction_id ); 397 | edd_insert_payment_note( $payment_id, sprintf( __( 'PayPal Transaction ID: %s', 'easy-digital-downloads' ), $transaction_id ) ); 398 | return $payment_id; 399 | } 400 | 401 | } 402 | 403 | function rand_float(){ 404 | 405 | $value = lcg_value(); 406 | 407 | if( (bool) rand(0,1) ) { 408 | $value = -1 * abs( $value ); 409 | } 410 | return round( $value, 3 ); 411 | } 412 | 413 | 414 | class ingot_test_desitnation { 415 | public static function create( $type, $is_tagline = false ){ 416 | $page_id = 0; 417 | if( 'page' == $type ){ 418 | $data[ 'page' ] = $page_id = rand( 1, 5 ); 419 | } 420 | 421 | $args = self::group_args( $type, $page_id, $is_tagline ); 422 | 423 | $data[ 'group_ID' ] = \ingot\testing\crud\group::create( $args, true ); 424 | for( $i =0; $i <= rand( 3,5 ); $i++ ){ 425 | $data[ 'variants' ][] = \ingot\testing\crud\variant::create( self::variant_args( $data[ 'group_ID' ] ), true ); 426 | } 427 | 428 | $group = \ingot\testing\crud\group::read( $data[ 'group_ID' ] ); 429 | if( is_wp_error( $group ) ){ 430 | 431 | wp_die(__LINE__. __FUNCTION__ . $type ); 432 | } 433 | $group[ 'variants' ] = $data[ 'variants' ]; 434 | \ingot\testing\crud\group::update( $group, $data[ 'group_ID' ], true ); 435 | $group = \ingot\testing\crud\group::read( $data[ 'group_ID' ] ); 436 | if( is_wp_error( $group ) || empty( $group[ 'variants' ] ) ){ 437 | wp_die( __LINE__. __FUNCTION__ ); 438 | } 439 | 440 | return $data; 441 | } 442 | 443 | public static function group_args( $type, $page_id = 0, $is_tagline = false ){ 444 | $args = [ 445 | 'name' => rand(), 446 | 'type' => 'click', 447 | 'sub_type' => 'destination', 448 | 'meta' => [ 449 | 'destination' => $type, 450 | 'page' => $page_id, 451 | 'is_tagline' => $is_tagline 452 | ], 453 | ]; 454 | 455 | return $args; 456 | 457 | } 458 | 459 | public static function variant_args( $group_id ) { 460 | $args = [ 461 | 'type' => 'click', 462 | 'group_ID' => $group_id, 463 | 'content' => rand() 464 | ]; 465 | 466 | return $args; 467 | 468 | } 469 | } 470 | -------------------------------------------------------------------------------- /tests/objects/tests-group-object.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_groups_variants extends \WP_UnitTestCase { 12 | /** 13 | * Test that when we can create object using group ID 14 | * 15 | * @since 0.4.0 16 | * 17 | * @group group 18 | * @group group_object 19 | * 20 | * @covers \ingot\testing\object\group::__construct() 21 | * @covers \ingot\testing\object\group::get_group_config() 22 | * @covers \ingot\testing\object\group::get_ID() 23 | * @covers \ingot\testing\object\group::set_group() 24 | * @covers \ingot\testing\object\group::validate_group() 25 | */ 26 | public function testInitObjectByID() { 27 | $groups = ingot_tests_make_groups( false, 1, 1 ); 28 | $id = $groups[ 'ids'][0]; 29 | $group = \ingot\testing\crud\group::read( $id ); 30 | $obj = new \ingot\testing\object\group( $id ); 31 | $this->assertInstanceOf( '\ingot\testing\object\group', $obj ); 32 | $this->assertEquals( $group, $obj->get_group_config() ); 33 | $this->assertEquals( $id, $obj->get_ID() ); 34 | } 35 | 36 | /** 37 | * Test create with extra params to make sure they don't return/get saved 38 | * 39 | * @since 0.4.0 40 | * 41 | * @group crud 42 | * @group group 43 | * @group group_crud 44 | * 45 | * @covers \ingot\testing\crud\crud::prepare_data() 46 | * @covers \ingot\testing\object\group::get_group_config() 47 | * @covers \ingot\testing\object\group::set_group() 48 | * @covers \ingot\testing\object\group::validate_group() 49 | */ 50 | public function testExtraParams() { 51 | $params = array( 52 | 'type' => 'click', 53 | 'sub_type' => 'button', 54 | 'meta' => [ 'link' => 'https://bats.com' ], 55 | 'hats' => 'bats' 56 | ); 57 | 58 | $id = \ingot\testing\crud\group::create( $params ); 59 | 60 | $obj = new \ingot\testing\object\group( $id ); 61 | 62 | $this->assertArrayNotHasKey( 'hats', $obj->get_group_config() ); 63 | 64 | $obj->update_group( ['cats' => 'dogs' ] ); 65 | 66 | $this->assertArrayNotHasKey( 'cats', $obj->get_group_config() ); 67 | $group = \ingot\testing\crud\group::read( $id ); 68 | $this->assertArrayNotHasKey( 'cats', $group ); 69 | $this->assertArrayNotHasKey( 'hats', $group ); 70 | } 71 | 72 | /** 73 | * Test that when we can create object using group config array 74 | * 75 | * @since 0.4.0 76 | 77 | * @group group 78 | * @group group_object 79 | * 80 | * @covers \ingot\testing\object\group::__construct() 81 | * @covers \ingot\testing\object\group::get_group_config() 82 | * @covers \ingot\testing\object\group::get_ID() 83 | * @covers \ingot\testing\object\group::set_group() 84 | * @covers \ingot\testing\object\group::validate_group() 85 | */ 86 | public function testInitObjectByArray() { 87 | $groups = ingot_tests_make_groups( false, 1, 1 ); 88 | $id = $groups[ 'ids'][0]; 89 | $group = \ingot\testing\crud\group::read( $id ); 90 | $obj = new \ingot\testing\object\group( $group ); 91 | $this->assertInstanceOf( '\ingot\testing\object\group', $obj ); 92 | $this->assertEquals( $group, $obj->get_group_config() ); 93 | $this->assertEquals( $id, $obj->get_ID() ); 94 | } 95 | 96 | /** 97 | * Test that when we can update variants through group object 98 | * 99 | * @since 0.4.0 100 | 101 | * @group group 102 | * @group group_object 103 | * 104 | * @covers \ingot\testing\object\group::get_group_config() 105 | * @covers \ingot\testing\object\group::update_group() 106 | */ 107 | public function testVariantUpdateThroughObject() { 108 | $groups = ingot_tests_make_groups( false, 1, 3 ); 109 | $id = $groups[ 'ids'][0]; 110 | $this->assertTrue( is_numeric( $id ) ); 111 | $group = \ingot\testing\crud\group::read( $id ); 112 | $variants = $groups[ 'variants' ][ $id ]; 113 | 114 | $obj = new \ingot\testing\object\group( $id ); 115 | $obj->update_group( [ 'variants' => $variants ] ); 116 | $this->assertEquals( $variants, $obj->get_group_config()[ 'variants' ] ); 117 | $group = \ingot\testing\crud\group::read( $id ); 118 | $this->assertEquals( $variants, $group[ 'variants' ] ); 119 | 120 | } 121 | 122 | /** 123 | * Test that when we can update other stuff through group object 124 | * 125 | * @since 0.4.0 126 | * 127 | * @group group 128 | * @group group_object 129 | * 130 | * @covers \ingot\testing\object\group::get_group_config() 131 | * @covers \ingot\testing\object\group::update_group() 132 | */ 133 | public function testUpdateThroughObject() { 134 | $groups = ingot_tests_make_groups( true, 1, 3 ); 135 | $id = $groups[ 'ids'][0]; 136 | $this->assertTrue( is_numeric( $id ) ); 137 | $variants = $groups[ 'variants' ][ $id ]; 138 | 139 | $obj = new \ingot\testing\object\group( $id ); 140 | $this->assertEquals( $variants, $obj->get_group_config()[ 'variants' ] ); 141 | 142 | $new_data = [ 'name' => 'BATMAN']; 143 | $obj->update_group( $new_data ); 144 | $group = \ingot\testing\crud\group::read( $id ); 145 | $this->assertEquals( 'BATMAN', $group[ 'name' ] ); 146 | 147 | $new_data = [ 148 | 'name' => 'Hi Roy', 149 | 'sub_type' => 'button_color' 150 | ]; 151 | 152 | 153 | $obj->update_group( $new_data ); 154 | $group = \ingot\testing\crud\group::read( $id ); 155 | $this->assertEquals( 'Hi Roy', $group[ 'name' ] ); 156 | $this->assertEquals( 'button_color', $group[ 'sub_type' ] ); 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /tests/objects/tests-posts-by-group.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_posts_by_group extends \WP_UnitTestCase { 12 | /** 13 | * @var \WP_Post 14 | */ 15 | protected $the_post; 16 | 17 | /** 18 | * @var \WP_Post 19 | */ 20 | protected $not_the_post; 21 | public function setUp(){ 22 | parent::setUp(); 23 | $id = $this->factory->post->create( array( 'post_title' => 'good' ) ); 24 | $this->the_post = get_post( $id ); 25 | $id = $this->factory->post->create( array( 'post_title' => 'not_good' ) ); 26 | $this->not_the_post = get_post( $id ); 27 | 28 | } 29 | 30 | public function tearDown(){ 31 | parent::tearDown(); 32 | wp_delete_post( $this->the_post->ID ); 33 | wp_delete_post( $this->not_the_post->ID ); 34 | } 35 | 36 | /** 37 | * Test that we can add one group to the association 38 | * 39 | * @since 1.1.0 40 | * 41 | * @group group 42 | * @group objects 43 | * @group posts_object 44 | * 45 | * @covers \ingot\testing\object\posts::add() 46 | */ 47 | public function testAddOneGroup(){ 48 | 49 | $obj = new \ingot\testing\object\posts( $this->the_post ); 50 | $obj->add( 7 ); 51 | 52 | $this->assertEquals( $obj->get_groups(), get_post_meta( $this->the_post->ID, \ingot\testing\utility\posts::meta_key(), false ) ); 53 | $this->assertNotEquals( $obj->get_groups(), get_post_meta( $this->not_the_post->ID, \ingot\testing\utility\posts::meta_key(), false ) ); 54 | 55 | } 56 | 57 | /** 58 | * Test that we can add an array of group to the association 59 | * 60 | * @since 1.1.0 61 | * 62 | * @group group 63 | * @group objects 64 | * @group posts_object 65 | * 66 | * @covers \ingot\testing\object\posts::add() 67 | */ 68 | public function testAddGroups(){ 69 | $groups = [1,3,7]; 70 | $obj = new \ingot\testing\object\posts( $this->the_post ); 71 | $obj->add( $groups ); 72 | $this->assertEquals( $groups, $obj->get_groups() ); 73 | $this->assertEquals( $obj->get_groups(), get_post_meta( $this->the_post->ID, \ingot\testing\utility\posts::meta_key(), false ) ); 74 | $this->assertNotEquals( $obj->get_groups(), get_post_meta( $this->not_the_post->ID, \ingot\testing\utility\posts::meta_key(), false ) ); 75 | 76 | 77 | } 78 | 79 | /** 80 | * Test that we can add remove a group from the association 81 | * 82 | * @since 1.1.0 83 | * 84 | * @group group 85 | * @group objects 86 | * @group posts_object 87 | * 88 | * @covers \ingot\testing\object\posts::remove() 89 | */ 90 | public function testRemove(){ 91 | 92 | $groups = [5,3,7]; 93 | $obj = new \ingot\testing\object\posts( $this->the_post ); 94 | $obj->add( $groups ); 95 | $obj->remove( 5 ); 96 | $expected = [3,7]; 97 | $this->assertEquals( array_values( $expected ), array_values( $obj->get_groups() ) ); 98 | $this->assertEquals( array_values( $obj->get_groups() ), array_values( get_post_meta( $this->the_post->ID, \ingot\testing\utility\posts::meta_key(), false ) ) ); 99 | 100 | $obj = new \ingot\testing\object\posts( $this->the_post ); 101 | $this->assertEquals( array_values( $expected ), array_values( $obj->get_groups() ) ); 102 | } 103 | 104 | /** 105 | * Test that we can overwrite assoiation 106 | * 107 | * @since 1.1.0 108 | * 109 | * @group group 110 | * @group objects 111 | * @group posts_object 112 | * 113 | * @covers \ingot\testing\object\posts::add() 114 | */ 115 | public function testOverwrite(){ 116 | $groups = [5,3,7]; 117 | $groups_2 = [9,4,7,12]; 118 | $obj = new \ingot\testing\object\posts( $this->the_post ); 119 | $obj->add( $groups ); 120 | $obj->add( $groups_2, true ); 121 | $this->assertEquals( array_values( $groups_2 ), array_values( $obj->get_groups() ) ); 122 | 123 | $this->assertEquals( array_values( $groups_2 ), array_values( get_post_meta( $this->the_post->ID, \ingot\testing\utility\posts::meta_key(), false ) ) ); 124 | } 125 | 126 | /** 127 | * Test that we can find the IDs from the shortcodes in post content 128 | * 129 | * @since 1.1.0 130 | * 131 | * @group group 132 | * @group objects 133 | * @group posts_object 134 | * 135 | * @covers ingot\testing\utility\posts::find_ids() 136 | */ 137 | public function testFindShortcodes() { 138 | $str = 'fdsjklsdfajkl [ingot id="7"] asdfghj sdfghjj xfsd [ingot id="3"] sdf '; 139 | 140 | $found = \ingot\testing\utility\posts::find_ids( $str ); 141 | 142 | $this->assertSame( [7,3], $found ); 143 | } 144 | 145 | /** 146 | * Test that we can find the IDs from the shortcodes in post content 147 | * 148 | * @since 1.1.0 149 | * 150 | * @group group 151 | * @group objects 152 | * @group posts_object 153 | * 154 | * @covers ingot\testing\utility\posts::update_groups_in_post() 155 | */ 156 | public function testUpdatePost(){ 157 | $id = $this->factory->post->create( [ 158 | 'post_title' => 'good', 159 | 'post_content' => 'sfdjlakjsdf [ingot id="9"] sfdj fsdkdfs SDF657R542 ingot id="7" fsd [ingot id="42"][ingot id="11"]' 160 | ]); 161 | $post = get_post( $id ); 162 | \ingot\testing\utility\posts::update_groups_in_post( $post ); 163 | $obj = new \ingot\testing\object\posts( get_post( $id ) ); 164 | $expected = [9,42,11]; 165 | $this->assertSame( $expected, $obj->get_groups() ); 166 | $post->post_content = 'sfdjlakjsdf [ingot id="9"]'; 167 | \ingot\testing\utility\posts::update_groups_in_post( $post ); 168 | $obj = new \ingot\testing\object\posts( get_post( $id ) ); 169 | $this->assertSame( [9], $obj->get_groups() ); 170 | 171 | } 172 | 173 | /** 174 | * Test that we can find query by associated post/group 175 | * 176 | * @since 1.1.0 177 | * 178 | * @group group 179 | * @group objects 180 | * @group posts_object 181 | * 182 | * @covers ingot\testing\utility\posts::posts_by_group() 183 | */ 184 | public function testQueryByGroup(){ 185 | $this->factory->post->create( [ 186 | 'post_title' => rand(), 187 | 'post_content' => 'x' 188 | ]); 189 | for ( $i = 5; $i <=10; $i++ ) { 190 | for ( $x = 0; $x <=2; $x++ ) { 191 | $title = 'gr_' . $i; 192 | $id = get_post( $this->factory->post->create( 193 | [ 194 | 'post_title' => $title, 195 | 'post_content' => '!' 196 | ] 197 | ) ); 198 | $obj = new \ingot\testing\object\posts( get_post( $id ) ); 199 | $obj->add( $i ); 200 | } 201 | 202 | 203 | $query = \ingot\testing\utility\posts::posts_by_group( [ $i ] ); 204 | $this->assertTrue( is_a( $query, 'WP_Query' ) ); 205 | 206 | $this->assertTrue( $query->have_posts(), var_export( $i ) ); 207 | $this->assertSame( 3, $query->post_count ); 208 | if( $query->have_posts() ){ 209 | while( $query->have_posts() ){ 210 | $query->the_post(); 211 | $this->assertSame( $title, $query->post->post_title ); 212 | 213 | } 214 | } 215 | 216 | if( 7 == $i ) { 217 | $obj->add( 88 ); 218 | $query = \ingot\testing\utility\posts::posts_by_group( [ 7,88 ] ); 219 | $this->assertTrue( is_a( $query, 'WP_Query' ) ); 220 | 221 | $this->assertTrue( $query->have_posts(), var_export( $i ) ); 222 | $this->assertSame( 3, $query->post_count ); 223 | } 224 | } 225 | 226 | $query = \ingot\testing\utility\posts::posts_by_group( [5,6,7,8,9 ] ); 227 | $this->assertTrue( $query->have_posts() ); 228 | if( $query->have_posts() ){ 229 | while( $query->have_posts() ){ 230 | $query->the_post(); 231 | $this->assertSame( '!', $query->post->post_content ); 232 | 233 | } 234 | } 235 | 236 | $query = \ingot\testing\utility\posts::posts_by_group( [5,6,9 ] ); 237 | $this->assertTrue( $query->have_posts() ); 238 | if( $query->have_posts() ){ 239 | while( $query->have_posts() ){ 240 | $query->the_post(); 241 | $this->assertSame( '!', $query->post->post_content ); 242 | 243 | } 244 | } 245 | 246 | } 247 | 248 | } 249 | -------------------------------------------------------------------------------- /tests/objects/tests-price-test.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class tests_price_test extends \WP_UnitTestCase { 12 | 13 | /** 14 | * Test creating of object 15 | * 16 | * @since 1.1.0 17 | * 18 | * @group price_object 19 | * @group price 20 | * @group edd_price 21 | */ 22 | public function testWithMinimal(){ 23 | $data = ingot_test_data_price::edd_tests( 10 ); 24 | $bandit = new \ingot\testing\bandit\price( $data[ 'group_ID' ] ); 25 | $variant_id = $bandit->choose(); 26 | $obj = new \ingot\testing\object\price\test( 27 | [ 28 | 'ID' => $variant_id, 29 | 'expires' => time() * 167234 30 | ] 31 | ); 32 | 33 | $product_ID = \ingot\testing\utility\price::get_product_ID( $data[ 'group' ] ); 34 | 35 | 36 | $variant = \ingot\testing\crud\variant::read( $variant_id ); 37 | $this->assertEquals( $variant_id, $obj->ID ); 38 | $this->assertEquals( $variant, $obj->variant ); 39 | $this->assertEquals( get_post( $product_ID ), $obj->product ); 40 | $this->assertEquals( 'edd_get_download_price', $obj->price_callback ); 41 | } 42 | 43 | /** 44 | * Test inflating/defalting object 45 | * 46 | * @since 1.1.0 47 | * 48 | * @group price_object 49 | * @group price 50 | * @group edd_price 51 | */ 52 | function testInflationDefaltion(){ 53 | $data = ingot_test_data_price::edd_tests( 10 ); 54 | $bandit = new \ingot\testing\bandit\price( $data[ 'group_ID' ] ); 55 | $variant_id = $bandit->choose(); 56 | $args = [ 57 | 'ID' => $variant_id, 58 | 'expires' => 167234 59 | ]; 60 | $obj = new \ingot\testing\object\price\test($args); 61 | 62 | $as_json = wp_json_encode( $obj ); 63 | $this->assertEquals( wp_json_encode($args), $as_json ); 64 | $inflated = \ingot\testing\utility\price::inflate_price_test( $as_json ); 65 | $this->assertSame( $obj->ID, $inflated->ID ); 66 | $this->assertSame( $obj->variant, $inflated->variant ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/price/tests-active-check.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class test_active_check extends \WP_UnitTestCase { 12 | 13 | /** 14 | * Test EDD is active 15 | * 16 | * @since 1.1.0 17 | * 18 | * @group price 19 | * @group edd 20 | * @group functions 21 | * 22 | * @covers ingot_is_edd_active() 23 | * @covers ingot_check_ecommerce_active() 24 | */ 25 | public function testEDDActive(){ 26 | if ( class_exists( 'Easy_Digital_Downloads' ) ) { 27 | $this->assertTrue( ingot_is_edd_active() ); 28 | $this->assertTrue( ingot_check_ecommerce_active( 'edd' ) ); 29 | }else{ 30 | $this->assertFalse( ingot_is_edd_active() ); 31 | $this->assertFalse( ingot_check_ecommerce_active( 'edd' ) ); 32 | } 33 | 34 | } 35 | 36 | /** 37 | * Test WOO is active 38 | * 39 | * @since 1.1.0 40 | * 41 | * @group price 42 | * @group woo 43 | * @group functions 44 | * 45 | * @covers ingot_is_woo_active() 46 | * @covers ingot_check_ecommerce_active() 47 | */ 48 | public function testWOOActive(){ 49 | if ( class_exists( 'WooCommerce' ) ) { 50 | $this->assertTrue( ingot_is_woo_active() ); 51 | $this->assertTrue( ingot_check_ecommerce_active( 'woo' ) ); 52 | }else{ 53 | $this->assertFalse(ingot_is_woo_active() ); 54 | $this->assertFalse( ingot_check_ecommerce_active( 'woo' ) ); 55 | } 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /tests/price/tests-price-cookie.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_price_cookie extends \WP_UnitTestCase { 12 | 13 | public function setUp(){ 14 | parent::setUp(); 15 | \ingot\testing\crud\group::delete( 'all' ); 16 | \ingot\testing\crud\variant::delete( 'all' ); 17 | 18 | } 19 | 20 | /** 21 | * Test contents of price cookie 22 | * 23 | * @since 1.1.0 24 | * 25 | * @group cookie 26 | * @group price_cookie 27 | * @group price 28 | * 29 | * @covers \ingot\testing\cookies\price() 30 | */ 31 | public function testCookieSetup(){ 32 | return; 33 | $group_1 = ingot_test_data_price::edd_tests( 10 ); 34 | 35 | $group_2 = ingot_test_data_price::edd_tests( 15 ); 36 | $cookie_class = new \ingot\testing\cookies\price( [] ); 37 | $price_cookie = $cookie_class->get_cookie(); 38 | 39 | $this->assertArrayHasKey( 'edd', $price_cookie ); 40 | 41 | $this->assertFalse( empty( $price_cookie[ 'edd' ] ) ); 42 | $this->assertInternalType( 'array', $price_cookie[ 'edd' ] ); 43 | $product_1 = \ingot\testing\utility\price::get_product_ID( $group_1[ 'group_ID' ] ); 44 | $product_2 = \ingot\testing\utility\price::get_product_ID( $group_2[ 'group_ID' ] ); 45 | $this->assertArrayHasKey( $product_1, $price_cookie[ 'edd' ] ); 46 | $this->assertArrayHasKey( $product_2, $price_cookie[ 'edd' ] ); 47 | 48 | $this->assertSame( 2, count( $price_cookie[ 'edd' ] ) ); 49 | 50 | foreach ( $price_cookie[ 'edd' ] as $content ) { 51 | $content = \ingot\testing\utility\price::inflate_price_test( $content ); 52 | $this->assertInternalType( 'object', $content ); 53 | foreach ( 54 | [ 55 | 'plugin', 56 | 'ID', 57 | 'variant', 58 | 'expires', 59 | 'price', 60 | 'product' 61 | ] as $key 62 | ) { 63 | $this->assertObjectHasAttribute( $key, $content ); 64 | 65 | } 66 | 67 | $this->assertInternalType( 'object', $content->product ); 68 | 69 | } 70 | 71 | } 72 | 73 | /** 74 | * Test that price tests in cookie makes 1 time ran only. 75 | * 76 | * @since 1.1.0 77 | * 78 | * @group cookie 79 | * @group price_cookie 80 | * @group price 81 | * 82 | * 83 | * @covers 84 | */ 85 | public function testEnsureRate(){ 86 | $data = ingot_test_data_price::edd_tests( 10 ); 87 | for( $i= 0; $i <= 10; $i++ ) { 88 | wp_remote_get( home_url() ); 89 | } 90 | $obj = new \ingot\testing\object\group( $data[ 'group_ID' ] ); 91 | $stats_obj = new \ingot\testing\object\group_stats( $obj->get_levers() ); 92 | 93 | $stats = $stats_obj->get_stats(); 94 | $this->assertArrayHasKey( 'group', $stats ); 95 | $this->assertInternalType( 'object', $stats[ 'group' ] ); 96 | 97 | /** @var \ingot\testing\object\stats $group_stats */ 98 | $group_stats = $stats[ 'group' ]; 99 | $this->assertSame( 1, $group_stats->total ); 100 | $this->assertSame( 0, $group_stats->conversions ); 101 | 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /tests/price/tests-price-edd.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_edd_price_tests extends \WP_UnitTestCase { 12 | 13 | public function setUp(){ 14 | parent::setUp(); 15 | \ingot\testing\crud\group::delete( 'all' ); 16 | \ingot\testing\crud\variant::delete( 'all' ); 17 | } 18 | 19 | /** 20 | * Test that EDD sample data generation is valid 21 | * 22 | * @since 1.1.0 23 | * 24 | * @group price 25 | * @group edd_price 26 | */ 27 | public function testDataGeneration(){ 28 | $group_data = ingot_test_data_price::edd_tests( 10 ); 29 | $group = \ingot\testing\crud\group::read( $group_data[ 'group_ID' ] ); 30 | $this->assertTrue( \ingot\testing\crud\group::valid( $group ) ); 31 | foreach( $group_data[ 'variants' ] as $variant_id ){ 32 | $this->assertTrue( is_numeric( $variant_id ) ); 33 | $variant = \ingot\testing\crud\variant::read( $variant_id ); 34 | $this->assertTrue( \ingot\testing\crud\variant::valid( $variant ) ); 35 | $this->assertEquals( $variant[ 'content' ], $group[ 'meta'][ 'product_ID' ] ); 36 | } 37 | 38 | } 39 | 40 | /** 41 | * Test that EDD sale of non-variable product is properly priced/recorded 42 | * 43 | * @since 1.1.0 44 | * 45 | * @group pricez 46 | * @group edd_price 47 | * 48 | * @covers \ingot\testing\tests\price\plugins\edd 49 | */ 50 | public function testPriceTrackingNonVariableProduct(){ 51 | return; 52 | $price_is = 10; 53 | $product = ingot_test_data_price::edd_create_simple_download( $price_is ); 54 | $group_id = \ingot\testing\crud\group::create([ 55 | 'type' => 'price', 56 | 'sub_type' => 'edd', 57 | 'meta' => [ 'product_ID' => $product->ID ], 58 | 'wp_ID' => $product->ID 59 | ], 60 | true 61 | ); 62 | $variant_one = \ingot\testing\crud\variant::create( [ 63 | 'group_ID' => $group_id, 64 | 'type' => 'price', 65 | 'meta' => [ 66 | 'price' => [ 0.5 ] 67 | ], 68 | 'content' => $product->ID, 69 | ], 70 | true 71 | ); 72 | 73 | $variant_two = \ingot\testing\crud\variant::create( [ 74 | 'group_ID' => $group_id, 75 | 'type' => 'price', 76 | 'meta' => [ 77 | 'price' => [ 0.5 ] 78 | ], 79 | 'content' => $product->ID, 80 | ], 81 | true 82 | ); 83 | 84 | $group = \ingot\testing\crud\group::read( $group_id ); 85 | $group[ 'variants' ] = [ $variant_one, $variant_two ]; 86 | \ingot\testing\crud\group::update( $group, $group_id, true ); 87 | 88 | $cookie_class = new \ingot\testing\cookies\price( [] ); 89 | $price_cookie = $cookie_class->get_cookie(); 90 | 91 | 92 | $this->assertArrayHasKey( 'edd', $price_cookie ); 93 | $this->assertFalse( empty( $price_cookie[ 'edd' ] ) ); 94 | $this->assertInternalType( 'array', $price_cookie[ 'edd' ] ); 95 | 96 | $product_id = \ingot\testing\utility\price::get_product_ID( $group ); 97 | $this->assertEquals( $product_id, $product->ID ); 98 | $this->assertArrayHasKey( $product_id, $price_cookie[ 'edd' ] ); 99 | 100 | new \ingot\testing\tests\price\plugins\edd( $price_cookie[ 'edd' ] ); 101 | 102 | $test = \ingot\testing\utility\price::get_price_test_from_cookie( 'edd', $product->ID, $price_cookie ); 103 | 104 | $this->assertInternalType( 'object', $test ); 105 | $price_should_be = $test->get_price(); 106 | //NOTE: USING edd_get_download_price here is to ensure we don't have recursion 107 | $this->assertEquals( edd_get_download_price( $product->ID ), $price_should_be ); 108 | 109 | $group_obj = new \ingot\testing\object\group( $group_id ); 110 | $lever = $group_obj->get_lever( $test->ID ); 111 | $this->assertInternalType( 'object', $lever ); 112 | $before_wins = $lever->getNumerator(); 113 | 114 | $payment_id = ingot_test_data_price::edd_create_simple_payment( $product); 115 | edd_complete_purchase( $payment_id, 'publish', 'pending' ); 116 | 117 | $group_obj = new \ingot\testing\object\group( $group_id ); 118 | $lever = $group_obj->get_lever( $test->ID ); 119 | $this->assertInternalType( 'object', $lever ); 120 | $after_wins = $lever->getNumerator(); 121 | 122 | $this->assertEquals( $before_wins + 1, $after_wins ); 123 | 124 | 125 | } 126 | 127 | public function _testVariablePrice() { 128 | $download = ingot_test_data_price::edd_create_variable_download( 10 ); 129 | $prices = edd_get_variable_prices( $download->ID ); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /tests/price/tests-price-queries.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_price_queries extends \WP_UnitTestCase { 12 | 13 | public function tearDown(){ 14 | parent::tearDown(); 15 | ingot_destroy(); 16 | } 17 | 18 | /** 19 | * Test that we can query by product ID 20 | * 21 | * @since 1.1.0 22 | * 23 | * @group price_query 24 | * @group price 25 | * 26 | * @covers \ingot\testing\crud\price_query::find_by_product() 27 | */ 28 | public function testFindByProduct(){ 29 | 30 | $args = [ 31 | 'type' => 'price', 32 | 'sub_type' => 'edd', 33 | 'wp_ID' => 5 34 | ]; 35 | 36 | $variant_args = [ 37 | 'type' => 'price', 38 | 'meta' => [ 39 | 'price' => [ ] 40 | ], 41 | ]; 42 | $args['meta'] [ 'product_ID' ] = 99; 43 | $group_id = \ingot\testing\crud\group::create( $args, true ); 44 | for ( $i=0; $i <= 4; $i++ ) { 45 | 46 | 47 | if( 0 == $i || 1 == $i ){ 48 | $args['meta'] [ 'product_ID' ] = 5; 49 | $variant_args[ 'content' ] = 5; 50 | }else{ 51 | $args['meta'] [ 'product_ID' ] = 9; 52 | $variant_args[ 'content' ] = 9; 53 | } 54 | 55 | $args[ 'wp_ID' ] = $args[ 'wp_ID' ] + 1; 56 | $group_id = \ingot\testing\crud\group::create( $args, true ); 57 | $this->assertTrue( is_numeric( $group_id ) ); 58 | 59 | if( 0 == $i || 1 == $i ){ 60 | $expected_ids[] = $group_id; 61 | 62 | } 63 | 64 | $variant_args[ 'group_ID' ] = $group_id; 65 | $variant_id = \ingot\testing\crud\variant::create( $variant_args, true ); 66 | $this->assertTrue( is_numeric( $variant_id ) ); 67 | $variants[ $group_id ] = $variant_id; 68 | } 69 | 70 | 71 | 72 | $groups = \ingot\testing\crud\price_query::find_by_product( 5 ); 73 | 74 | $this->assertInternalType( 'array', $groups ); 75 | $this->assertFalse( empty( $groups ) ); 76 | $this->assertSame( 2, count( $groups ) ); 77 | $expected_ids = wp_list_pluck( $groups, 'ID' ); 78 | $ids = wp_list_pluck( $groups, 'ID' ); 79 | $this->assertSame( $expected_ids, $ids ); 80 | } 81 | 82 | /** 83 | * Test that we can query by plugin type 84 | * 85 | * @since 1.1.0 86 | * 87 | * @group price_query 88 | * @group price 89 | * 90 | * @covers \ingot\testing\crud\price_query::find_by_plugin() 91 | */ 92 | public function testQueryByPlugin(){ 93 | $args = [ 94 | 'type' => 'price', 95 | 'sub_type' => 'edd', 96 | 'meta' => [ 'product_ID' => 5 ], 97 | 'wp_ID' => 5 98 | ]; 99 | $group_edd = \ingot\testing\crud\group::create( $args, true ); 100 | $this->assertTrue( is_numeric( $group_edd ) ); 101 | for( $i = 0; $i <= 5; $i++ ) { 102 | $args[ 'wp_ID' ] = $args[ 'wp_ID' ] + 1; 103 | \ingot\testing\crud\group::create( $args ); 104 | } 105 | $args[ 'sub_type' ] = 'woo'; 106 | $args[ 'wp_ID' ] = $args[ 'wp_ID' ] + 1; 107 | $group_woo = \ingot\testing\crud\group::create( $args, true ); 108 | $this->assertTrue( is_numeric( $group_woo ) ); 109 | for( $i = 0; $i <= 5; $i++ ) { 110 | $args[ 'wp_ID' ] = $args[ 'wp_ID' ] + 1; 111 | \ingot\testing\crud\group::create( $args, true ); 112 | } 113 | 114 | $woos = \ingot\testing\crud\price_query::find_by_plugin( 'woo' ); 115 | $this->assertInternalType( 'array', $woos ); 116 | $ids = wp_list_pluck( $woos, 'ID' ); 117 | $this->assertTrue( in_array( $group_woo, $ids ) ); 118 | foreach( $woos as $group ) { 119 | $this->assertSame( 'woo', $group[ 'sub_type' ] ); 120 | } 121 | 122 | 123 | } 124 | 125 | /** 126 | * Test that we can query by plugin and exclude those without variants 127 | * 128 | * @since 1.1.0 129 | * 130 | * @group xs 131 | * @group price_query 132 | * @group price 133 | * 134 | * @covers \ingot\testing\crud\price_query::find_by_plugin() 135 | */ 136 | public function testQueryByPluginNoVariant(){ 137 | $args = [ 138 | 'type' => 'price', 139 | 'sub_type' => 'edd', 140 | 'meta' => [ 'product_ID' => 5 ], 141 | 'wp_ID' => 5 142 | ]; 143 | $variant_args = [ 144 | 'type' => 'price', 145 | 'meta' => [ 146 | 'price' => [ ] 147 | ], 148 | 'content' => 5 149 | ]; 150 | 151 | 152 | 153 | 154 | for( $i = 0; $i <= 5; $i++ ) { 155 | $group_id = \ingot\testing\crud\group::create( $args ); 156 | $args[ 'wp_ID' ] = $args[ 'wp_ID' ] + 1; 157 | if( 3 == $i ){ 158 | $expected_id = $group_id; 159 | $variant_args[ 'group_ID' ] = $group_id; 160 | $variant_args[ 'meta' ] [ 'price' ] = rand_float(); 161 | $variant_id = \ingot\testing\crud\variant::create( $variant_args, true ); 162 | $this->assertTrue( is_numeric( $variant_id ) ); 163 | $group = \ingot\testing\crud\group::read( $group_id ); 164 | $group[ 'variants' ] = [ $variant_id ]; 165 | \ingot\testing\crud\group::update( $group, $group_id, true ); 166 | 167 | } 168 | 169 | } 170 | 171 | $groups = \ingot\testing\crud\price_query::find_by_plugin( 'edd', true ); 172 | $this->assertInternalType( 'array', $groups ); 173 | $this->assertFalse( empty( $groups ) ); 174 | $ids = wp_list_pluck( $groups, 'ID' ); 175 | $this->assertTrue( in_array( $expected_id, $ids ) ); 176 | $this->assertSame( 1, count( $groups ) ); 177 | 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /tests/price/tests-price_util.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_price_util extends \WP_UnitTestCase { 13 | 14 | /** 15 | * Ensure valid floats are allowed 16 | * 17 | * @since 0.2.0 18 | * 19 | * @group price 20 | * @group helpers 21 | * 22 | * @covers ingot\testing\utility\price::valid_percentage 23 | */ 24 | function testFloatTestValid(){ 25 | $numbers = array( 26 | .5, 27 | '0.5', 28 | '0.005', 29 | 0.05, 30 | -.1, 31 | '-.001', 32 | '-.02', 33 | -.9, 34 | 0, 35 | '0' 36 | ); 37 | foreach( $numbers as $number ){ 38 | $this->assertTrue( ingot\testing\utility\price::valid_percentage( $number ) ); 39 | } 40 | } 41 | 42 | /** 43 | * Ensure invalid floats are not allowed 44 | * 45 | * @since 0.2.0 46 | * 47 | * @group price 48 | * @group helpers 49 | * 50 | * @covers ingot\testing\utility\price::valid_percentage 51 | */ 52 | function testFloatTestinValid(){ 53 | $numbers = array( 54 | 1.5, 55 | '1.5', 56 | '4.005', 57 | 1.05, 58 | -2, 59 | '-6.001', 60 | '-1', 61 | -999, 62 | 'hats', 63 | array(), 64 | new stdClass(), 65 | (object) array( -0.1, .9 ), 66 | json_encode( array( -0.1, .9 ) ), 67 | serialize( array( -.05, .9 ) ) 68 | ); 69 | foreach( $numbers as $number ){ 70 | $this->assertFalse( ingot\testing\utility\price::valid_percentage( $number ) ); 71 | } 72 | } 73 | 74 | /** 75 | * Test checking validity of price sub_type 76 | * 77 | * @since 1.1.0 78 | * 79 | * @group price 80 | * @group helpers 81 | * 82 | * @covers ingot_acceptable_plugin_for_price_test() 83 | * @covers ingot_accepted_plugins_for_price_tests() 84 | * @covers \ingot\testing\types::allowed_price_types() 85 | */ 86 | public function testAllowedSubTypes(){ 87 | foreach( ['woo', 'edd' ] as $plugin ){ 88 | $this->assertTrue( in_array( $plugin, \ingot\testing\types::allowed_price_types() ) ); 89 | $this->assertTrue( ingot_acceptable_plugin_for_price_test( $plugin ) ); 90 | $this->assertTrue( in_array( $plugin, ingot_accepted_plugins_for_price_tests() ) ); 91 | } 92 | 93 | $plugin = 'batman'; 94 | $this->assertFalse( in_array( $plugin, \ingot\testing\types::allowed_price_types() ) ); 95 | $this->assertFalse( ingot_acceptable_plugin_for_price_test( $plugin ) ); 96 | $this->assertFalse( in_array( $plugin, ingot_accepted_plugins_for_price_tests() ) ); 97 | 98 | 99 | } 100 | 101 | 102 | /** 103 | * Test checking validity of price sub_type with filter 104 | * 105 | * @since 1.1.0 106 | * 107 | * @group price 108 | * @group helpers 109 | * 110 | * @covers ingot_acceptable_plugin_for_price_test() 111 | * @covers ingot_accepted_plugins_for_price_tests() 112 | * @covers \ingot\testing\types::allowed_price_types() 113 | */ 114 | public function testAllowedSubTypesFilter(){ 115 | add_filter( 'ingot_accepted_plugins_for_price_tests', function( $plugins ){ 116 | $plugins[ 'roy2020' ] = 'Roy!'; 117 | return $plugins; 118 | }); 119 | 120 | $this->assertTrue( in_array( 'roy2020', \ingot\testing\types::allowed_price_types() ) ); 121 | $this->assertTrue( ingot_acceptable_plugin_for_price_test( 'roy2020' ) ); 122 | $this->assertTrue( in_array( 'roy2020', ingot_accepted_plugins_for_price_tests() ) ); 123 | foreach( ['woo', 'edd' ] as $plugin ){ 124 | $this->assertTrue( in_array( $plugin, \ingot\testing\types::allowed_price_types() ) ); 125 | $this->assertTrue( ingot_acceptable_plugin_for_price_test( $plugin ) ); 126 | $this->assertTrue( in_array( $plugin, ingot_accepted_plugins_for_price_tests() ) ); 127 | } 128 | } 129 | 130 | /** 131 | * Test get price of EDD product 132 | * 133 | * @since 1.1.0 134 | * 135 | * @group price 136 | * @group helper 137 | * @group edd 138 | * 139 | * @covers \ingot\testing\utility\price::get_price() 140 | */ 141 | public function testGetPriceEDD(){ 142 | $product_1 = ingot_test_data_price::edd_create_simple_download( 10.51 ); 143 | $product_2 = ingot_test_data_price::edd_create_simple_download( 5.21 ); 144 | $this->assertSame( ingot_sanitize_amount( 10.51 ), \ingot\testing\utility\price::get_price( 'edd', $product_1->ID ) ); 145 | $this->assertSame( ingot_sanitize_amount( 5.21 ), \ingot\testing\utility\price::get_price( 'edd', $product_2->ID ) ); 146 | 147 | } 148 | 149 | /** 150 | * Test applying utility method for price variation with negative variation 151 | * 152 | * @since 1.1.0 153 | * 154 | * @group price 155 | * @group helper 156 | * 157 | * @covers \ingot\testing\utility\price::apply_variation() 158 | */ 159 | public function testPriceVariationNegative(){ 160 | $base_price = 10; 161 | 162 | $this->assertSame( ingot_sanitize_amount( 5 ), ingot_sanitize_amount( \ingot\testing\utility\price::apply_variation( -0.5, $base_price ) ) ); 163 | 164 | $this->assertSame( ingot_sanitize_amount( 8 ), ingot_sanitize_amount( \ingot\testing\utility\price::apply_variation( -0.2, $base_price ) ) ); 165 | 166 | $this->assertSame( ingot_sanitize_amount( 7.50 ), ingot_sanitize_amount( \ingot\testing\utility\price::apply_variation( -0.25, $base_price ) ) ); 167 | 168 | $this->assertSame( ingot_sanitize_amount( 2.50 ), ingot_sanitize_amount( \ingot\testing\utility\price::apply_variation( -0.75, $base_price ) ) ); 169 | 170 | } 171 | 172 | /** 173 | * 174 | * Test applying utility method for price variation with positive variation 175 | * 176 | * @since 1.1.0 177 | * 178 | * @group price 179 | * @group helper 180 | * 181 | * @covers \ingot\testing\utility\price::apply_variation() 182 | */ 183 | public function testPriceVarPositive(){ 184 | $base_price = 10; 185 | $this->assertSame( ingot_sanitize_amount( 15 ), ingot_sanitize_amount( \ingot\testing\utility\price::apply_variation( 0.5, $base_price ) ) ); 186 | 187 | $this->assertSame( ingot_sanitize_amount( 12 ), ingot_sanitize_amount( \ingot\testing\utility\price::apply_variation( 0.2, $base_price ) ) ); 188 | 189 | $this->assertSame( ingot_sanitize_amount( 18.50 ), ingot_sanitize_amount( \ingot\testing\utility\price::apply_variation( 0.85, $base_price ) ) ); 190 | 191 | } 192 | 193 | /** 194 | * Test that we can't create a group for a product that is already being tested 195 | * 196 | * @since 1.1.0 197 | * 198 | * @group price 199 | * @group helper 200 | * @covers \ingot\testing\utility\price::product_test_exists() 201 | */ 202 | public function testPriceTestExists(){ 203 | 204 | $group = \ingot\testing\crud\group::create( [ 205 | 'name' => 'd', 206 | 'type' => 'price', 207 | 'sub_type' => 'edd', 208 | 'meta' => [ 209 | 'product_ID' => 169, 210 | ], 211 | 'wp_ID' => 169 212 | ], true ); 213 | 214 | $this->assertTrue( is_numeric( $group ) ); 215 | 216 | $existing = \ingot\testing\utility\price::product_test_exists( 169 ); 217 | 218 | $this->assertEquals( $existing, $group ); 219 | 220 | } 221 | 222 | } 223 | -------------------------------------------------------------------------------- /tests/tests-array-filters.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class tests_array_filters extends \WP_UnitTestCase{ 12 | /** 13 | * Test flattener 14 | * 15 | * @since 1.1.0 16 | * 17 | * @group utility 18 | * @group array_filter 19 | * 20 | * @covers \ingot\testing\utility\array_filters::flatten() 21 | */ 22 | public function testFlatten(){ 23 | $array = [ 24 | 'ingot_destination' => 88, 25 | 'hats_8765' => [ 'batman', 'robin'] 26 | ]; 27 | $this->assertEquals( ['ingot_destination' => 88], \ingot\testing\utility\array_filters::flatten( $array ) ); 28 | 29 | $array = [ 30 | 'ingot_destination' => 88, 31 | 'ingot_destination_12', 32 | 'hats_8765' => [ 'batman', 'robin'] 33 | ]; 34 | $this->assertEquals( ['ingot_destination' => 88, 'ingot_destination_12'], \ingot\testing\utility\array_filters::flatten( $array ) ); 35 | 36 | $array = [ 37 | new \stdClass(), 38 | 'hats_8765' => [ 'batman', 'robin'] 39 | ]; 40 | $this->assertEquals( [], \ingot\testing\utility\array_filters::flatten( $array ) ); 41 | } 42 | 43 | /** 44 | * Test the basic filter 45 | * 46 | * @since 1.1.0 47 | * 48 | * @group utility 49 | * @group array_filter 50 | * 51 | * @covers \ingot\testing\utility\array_filters::filter() 52 | * @covers \ingot\testing\utility\array_filters::match() 53 | * @covers \ingot\testing\utility\array_filters::prepare() 54 | */ 55 | public function testFilter(){ 56 | $data = [ 'ingot_destination_9', 'ingot_destination_42', 'hi chris', 'ingot_', 'ingot_destination' ]; 57 | $results = \ingot\testing\utility\array_filters::filter( $data, 'ingot_destination_' ); 58 | $this->assertEquals( [ 59 | 'ingot_destination_9', 60 | 'ingot_destination_42' 61 | ], $results ); 62 | } 63 | 64 | /** 65 | * Test filter by array keys 66 | * 67 | * @since 1.1.0 68 | * 69 | * @group utility 70 | * @group array_filter 71 | * 72 | * @covers \ingot\testing\utility\array_filters::filter_keys() 73 | * @covers \ingot\testing\utility\array_filters::match() 74 | * @covers \ingot\testing\utility\array_filters::prepare() 75 | */ 76 | public function testKeyFilter(){ 77 | $data = [ 78 | 'ingot_destination_9' => 12, 79 | 'ingot_destination_42' => 7, 80 | 'hi chris', 81 | 'ingot_' => 94, 82 | 'ingot_destination' => 88, 83 | ]; 84 | $results = \ingot\testing\utility\array_filters::filter_keys( $data, 'ingot_destination_' ); 85 | $this->assertEquals( [ 86 | 'ingot_destination_9', 87 | 'ingot_destination_42' 88 | ], $results ); 89 | } 90 | 91 | /** 92 | * Test getting results from key substr in matching keys 93 | * 94 | * 95 | * @since 1.1.0 96 | * 97 | * @group utility 98 | * @group array_filter 99 | * 100 | * @covers \ingot\testing\utility\array_filters::filter_results() 101 | * @covers \ingot\testing\utility\array_filters::match() 102 | * @covers \ingot\testing\utility\array_filters::prepare() 103 | */ 104 | public function testResultsFilter(){ 105 | $data = [ 106 | 'ingot_destination_9' => 12, 107 | 'ingot_destination_42' => 7, 108 | 'hi chris', 109 | 'ingot_97' => 94, 110 | 'ingot_destination' => 88, 111 | 'hats_8765' => [ 'batman', 'robin'] 112 | ]; 113 | $results = \ingot\testing\utility\array_filters::filter_results( $data, 'ingot_destination_' ); 114 | $this->assertEquals( [ 115 | '9', 116 | '42' 117 | ], $results ); 118 | } 119 | 120 | /** 121 | * Test getting results from matching values 122 | 123 | * @since 1.1.0 124 | * 125 | * @group utility 126 | * @group array_filter 127 | * 128 | * @covers \ingot\testing\utility\array_filters::filter_values() 129 | * @covers \ingot\testing\utility\array_filters::match() 130 | * @covers \ingot\testing\utility\array_filters::prepare() 131 | */ 132 | public function testResultsValues(){ 133 | $data = [ 134 | 'ingot_destination_19' => 12, 135 | 'ingot_destination_12142' => 17, 136 | 'ingot_destination_4899898', 137 | 'hi chris', 138 | 'ingot_97' => 94, 139 | 'ingot_destination' => 88, 140 | 'hats_8765' => [ 'batman', 'robin'] 141 | ]; 142 | $results = \ingot\testing\utility\array_filters::filter_values( $data, 'ingot_destination_' ); 143 | $this->assertEquals( [ 144 | 12, 145 | 17 146 | ], $results ); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /tests/tests-color_helpers.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_color_helpers extends \WP_UnitTestCase { 13 | 14 | /** 15 | * Test that a valid 3 digit hex passes 16 | * 17 | * @since 0.1.1 18 | * 19 | * @covers \ingot\testing\utility\helpers::prepare_color() 20 | * @covers \ingot\testing\utility\sanitize_hex_color::prepare_color() 21 | * @covers \ingot\testing\utility\maybe_hash_hex_color::prepare_color() 22 | */ 23 | public function testValidWithHash3Digits() { 24 | $color = '#fff'; 25 | $processed = \ingot\testing\utility\helpers::prepare_color( $color, true ); 26 | $this->assertSame( $color, $processed ); 27 | } 28 | 29 | /** 30 | * Test that a valid 6 digit hex passes 31 | * 32 | * @since 0.1.1 33 | * 34 | * @covers \ingot\testing\utility\helpers::prepare_color() 35 | * @covers \ingot\testing\utility\sanitize_hex_color::prepare_color() 36 | * @covers \ingot\testing\utility\maybe_hash_hex_color::prepare_color() 37 | */ 38 | public function testValidWithHash6Digits() { 39 | $color = '#fdfdfd'; 40 | $processed = \ingot\testing\utility\helpers::prepare_color( $color, true ); 41 | $this->assertSame( $color, $processed ); 42 | } 43 | 44 | /** 45 | * Test that a valid 3 digit hex passes and removes hash when asked to. 46 | * 47 | * @since 0.1.1 48 | * 49 | * @covers \ingot\testing\utility\helpers::prepare_color() 50 | * @covers \ingot\testing\utility\sanitize_hex_color::prepare_color() 51 | * @covers \ingot\testing\utility\maybe_hash_hex_color::prepare_color() 52 | */ 53 | public function testValidRemoveHash3Digits() { 54 | 55 | $processed = \ingot\testing\utility\helpers::prepare_color( '#fff', false ); 56 | $this->assertSame( 'fff', $processed ); 57 | 58 | } 59 | 60 | 61 | /** 62 | * Test that a valid 6 digit hex passes and removes hash when asked to. 63 | * 64 | * @since 0.1.1 65 | * 66 | * @covers \ingot\testing\utility\helpers::prepare_color() 67 | * @covers \ingot\testing\utility\sanitize_hex_color::prepare_color() 68 | * @covers \ingot\testing\utility\sanitize_hex_color_no_hash::prepare_color() 69 | */ 70 | public function testValidRemoveHash6Digits() { 71 | 72 | $processed = \ingot\testing\utility\helpers::prepare_color( '#f00fff', false ); 73 | $this->assertSame( 'f00fff', $processed ); 74 | 75 | } 76 | 77 | /** 78 | * Test that an INVALID hex returns default and still gives us a hash when asked for. 79 | * 80 | * @since 0.1.1 81 | * 82 | * @covers \ingot\testing\utility\helpers::prepare_color() 83 | * @covers \ingot\testing\utility\sanitize_hex_color::prepare_color() 84 | * @covers \ingot\testing\utility\maybe_hash_hex_color::prepare_color() 85 | */ 86 | public function testInvalidAddHash() { 87 | $default = \ingot\testing\utility\defaults::color(); 88 | $default = '#' . $default; 89 | $processed = \ingot\testing\utility\helpers::prepare_color( '#fdogscatsfflllll', true ); 90 | $this->assertSame( $default, $processed ); 91 | 92 | } 93 | 94 | /** 95 | * Test that an INVALID hex returns default and still gives removes a hash when asked for. 96 | * 97 | * @since 0.1.1 98 | * 99 | * @covers \ingot\testing\utility\helpers::prepare_color() 100 | * @covers \ingot\testing\utility\sanitize_hex_color::prepare_color() 101 | * @covers \ingot\testing\utility\sanitize_hex_color_no_hash::prepare_color() 102 | */ 103 | public function testInvalidRemoveHash() { 104 | $default = \ingot\testing\utility\defaults::color(); 105 | $processed = \ingot\testing\utility\helpers::prepare_color( '#fdogscatsfflllll', false ); 106 | $this->assertSame( $default, $processed ); 107 | 108 | } 109 | 110 | /** 111 | * Ensure our get color meta works with good data 112 | * 113 | * @since 0.1.1 114 | * 115 | * @covers \ingot\testing\utility\helpers::get_color_from_meta() 116 | */ 117 | public function testColorMeta() { 118 | $color = '#FF0000'; 119 | $a[ 'meta'][ 'color' ] = $color; 120 | $this->assertSame( $color, \ingot\testing\utility\helpers::get_color_from_meta( $a ) ); 121 | } 122 | 123 | /** 124 | * Ensure our get color meta falls back to default with bad color. 125 | * 126 | * @since 0.1.1 127 | * 128 | * @covers \ingot\testing\utility\helpers::get_color_from_meta() 129 | */ 130 | public function testColorMetaFallback() { 131 | $color = 'dogscats'; 132 | $a[ 'meta'][ 'color' ] = $color; 133 | $this->assertSame( \ingot\testing\utility\defaults::color(), \ingot\testing\utility\helpers::get_color_from_meta( $a, false ) ); 134 | } 135 | 136 | 137 | 138 | /** 139 | * Ensure our get color meta falls back to default with bad input. 140 | * 141 | * @since 0.1.1 142 | * 143 | * @covers \ingot\testing\utility\helpers::get_color_from_meta() 144 | * @covers \ingot\testing\utility\defaults::text_color() 145 | */ 146 | public function testColorUnset() { 147 | $color = '#fff'; 148 | $a[ 'meta'][ rand() ] = $color; 149 | $this->assertSame( \ingot\testing\utility\defaults::text_color(), \ingot\testing\utility\helpers::get_color_from_meta( $a, false ) ); 150 | } 151 | 152 | /** 153 | * Ensure our get color meta falls back to default with really bad input. 154 | * 155 | * @since 0.1.1 156 | * 157 | * @covers \ingot\testing\utility\helpers::get_color_from_meta() 158 | * @covers \ingot\testing\utility\defaults::text_color() 159 | */ 160 | public function testColorMetaUnset() { 161 | $color = '#fff'; 162 | $a[ rand() ][ rand() ] = $color; 163 | $this->assertSame( \ingot\testing\utility\defaults::text_color(), \ingot\testing\utility\helpers::get_color_from_meta( $a, false ) ); 164 | } 165 | 166 | /** 167 | * Test converting Word to Hex 168 | * 169 | * @since 0.1.1 170 | * 171 | * @covers \ingot\testing\utility\helpers::color_word_to_hex() 172 | */ 173 | public function testWordToHex() { 174 | $color = 'yellow'; 175 | $this->assertSame( 'FFFF00', \ingot\testing\utility\helpers::prepare_color( $color, false ) ); 176 | $color = 'olivedrab'; 177 | $this->assertSame( '#6B8E23', \ingot\testing\utility\helpers::prepare_color( $color, true ) ); 178 | } 179 | 180 | /** 181 | * Test that invalid word gives us default color 182 | * 183 | * @since 0.1.1 184 | * 185 | * @covers \ingot\testing\utility\helpers::is_color_word() 186 | */ 187 | public function testInvalidWordToHex() { 188 | $color = 'lemongrab'; 189 | $this->assertSame( \ingot\testing\utility\defaults::color(), \ingot\testing\utility\helpers::prepare_color( $color, false ) ); 190 | 191 | } 192 | 193 | 194 | } 195 | -------------------------------------------------------------------------------- /tests/tests-cookie-setup.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class tests_cookie_setup extends \WP_UnitTestCase{ 12 | 13 | public function setUp(){ 14 | parent::setUp(); 15 | 16 | } 17 | 18 | /** 19 | * Test that we can set the cookie 20 | * 21 | * @since 1.1.0 22 | * 23 | * @group cookie 24 | * @group price 25 | * 26 | * @covers \ingot\testing\cookies\set::setup_cookies() 27 | */ 28 | public function _testSetCookie(){ 29 | 30 | } 31 | 32 | /** 33 | * Test price testing setup 34 | * 35 | * @since 1.1.0 36 | * 37 | * @group cookie 38 | * @group price_cookie 39 | * @group price 40 | * 41 | * 42 | * @covers \ingot\testing\cookies\set::price_testing() 43 | */ 44 | public function testRunPriceTests(){ 45 | return; 46 | 47 | $this->assertFalse( (bool) did_action( 'ingot_loaded' ) ); 48 | $group_1 = ingot_test_data_price::edd_tests( 10 ); 49 | $group_2 = ingot_test_data_price::edd_tests( 15 ); 50 | $product_1 = $group_1[ 'product_ID' ]; 51 | $product_2 = $group_2[ 'product_ID' ]; 52 | $cookies = \ingot\testing\cookies\init::create( [] ); 53 | $this->assertFalse( is_wp_error( $cookies ) ); 54 | 55 | $ingot_cookies = $cookies->get_ingot_cookie( false ); 56 | 57 | $this->assertInternalType( 'array', $ingot_cookies ); 58 | $this->assertArrayHasKey( 'edd', $ingot_cookies ); 59 | 60 | $objects = \ingot\testing\cookies\set::price_testing( $ingot_cookies ); 61 | 62 | $this->assertArrayHasKey( 'edd', $objects ); 63 | $this->assertInternalType( 'object', $objects[ 'edd' ] ); 64 | 65 | /** @var ingot\testing\tests\price\plugins\edd $edd */ 66 | $edd = $objects[ 'edd' ]; 67 | $products = $edd->get_products(); 68 | $this->assertEquals( 2, count( $products ) ); 69 | $this->assertArrayHasKey( $product_1, $products ); 70 | $this->assertArrayHasKey( $product_2, $products ); 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/tests-db.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class tests_database extends \WP_UnitTestCase { 12 | 13 | /** 14 | * Test ingot version compare 15 | * 16 | * @since 1.1.0 17 | * 18 | * @group db 19 | * 20 | * @covers \ingot\testing\db\upgrade() 21 | */ 22 | public function testVersionCompare(){ 23 | $updater = new \ingot\testing\db\upgrade( '1.1.0' ); 24 | $this->assertTrue( $updater->before( '0.9' ) ); 25 | $this->assertTrue( $updater->before( '1.0.0' ) ); 26 | $this->assertTrue( $updater->before( '1.1.0-b-1' ) ); 27 | $this->assertFalse( $updater->before( '1.1.1-b-1' ) ); 28 | $this->assertFalse( $updater->before( '1.1.1' ) ); 29 | $this->assertFalse( $updater->before( '2.0' ) ); 30 | } 31 | 32 | /** 33 | * Test that the wp_ID column gets added to groups via the 1.1.0 updater 34 | * 35 | * @since 1.1.0 36 | * 37 | * @group db 38 | * 39 | * @covers \ingot\testing\db\add_wp_id_column() 40 | * @covers \ingot\testing\db\run() 41 | */ 42 | public function test1dot1Update(){ 43 | global $wpdb; 44 | $table_name = \ingot\testing\crud\group::get_table_name(); 45 | //test method in isolation 46 | 47 | $wpdb->query( sprintf( 'ALTER TABLE %s DROP COLUMN wp_ID', $table_name ) ); 48 | $updater = new \ingot\testing\db\upgrade( '1.1.0' ); 49 | $updater->add_wp_id_column(); 50 | 51 | $data = ingot_test_data_price::edd_tests( 10 ); 52 | $this->assertTrue( is_array( $data ) ); 53 | $this->assertTrue( is_numeric( $data[ 'group_ID' ] ) ); 54 | $product_ID = $data[ 'product_ID' ]; 55 | $results = $wpdb->query( sprintf( 'SELECT * FROM `%s` WHERE `wp_ID` = %d', $table_name, $product_ID ) ); 56 | $this->assertTrue( ! empty( $results ) ); 57 | 58 | //test using run method 59 | $wpdb->query( sprintf( 'ALTER TABLE %s DROP COLUMN wp_ID', $table_name ) ); 60 | $updater->run(); 61 | 62 | $data = ingot_test_data_price::edd_tests( 10 ); 63 | $this->assertTrue( is_array( $data ) ); 64 | $this->assertTrue( is_numeric( $data[ 'group_ID' ] ) ); 65 | $product_ID = $data[ 'product_ID' ]; 66 | $results = $wpdb->query( sprintf( 'SELECT * FROM `%s` WHERE `wp_ID` = %d', $table_name, $product_ID ) ); 67 | $this->assertTrue( ! empty( $results ) ); 68 | 69 | //test that running it anyway doesn't break stuff 70 | $results = $wpdb->query( sprintf( 'SELECT * FROM `%s` WHERE `wp_ID` = %d', $table_name, $product_ID ) ); 71 | $this->assertTrue( ! empty( $results ) ); 72 | 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /tests/tests-destination-cookies.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2016 Josh Pollock 11 | */ 12 | class test_cookies extends \WP_UnitTestCase { 13 | 14 | public function setUp(){ 15 | parent::setUp(); 16 | \ingot\testing\crud\group::delete( 'all' ); 17 | } 18 | 19 | /** 20 | * Test that we can query for these tests properly 21 | * 22 | * @since 1.1.0 23 | * 24 | * @group group 25 | * @group destination 26 | * @group cookie 27 | * @group destination_cookie 28 | * 29 | * @covers \ingot\testing\tests\click\destination\init::get_destination_tests() 30 | */ 31 | public function testQuery() { 32 | ingot_test_data_price::edd_tests(); 33 | ingot_tests_data::make_groups(); 34 | $x = 0; 35 | foreach ( \ingot\testing\tests\click\destination\types::destination_types() as $type ) { 36 | if( 'hook' == $type ) { 37 | continue; 38 | } 39 | 40 | $data = ingot_test_desitnation::create( $type ); 41 | 42 | $this->assertTrue( is_numeric( $data[ 'group_ID' ] ) ); 43 | $the_groups[] = $data[ 'group_ID' ]; 44 | $x++; 45 | 46 | } 47 | 48 | 49 | $groups = \ingot\testing\tests\click\destination\init::get_destination_tests(); 50 | $this->assertSame( $x, count( $groups ) ); 51 | 52 | $this->assertEquals( $the_groups , $groups ); 53 | 54 | } 55 | 56 | /** 57 | * 58 | * 59 | * @since 1.1.0 60 | * 61 | * @group group 62 | * @group destination 63 | * @group cookie 64 | * @group destination_cookie 65 | * 66 | * @covers \ingot\testing\tests\click\destination\init::setup_cookies() 67 | */ 68 | public function testCookieInitial(){ 69 | 70 | $data = ingot_test_desitnation::create( 'page' ); 71 | $group_1 = $data[ 'group_ID' ]; 72 | $variants_1 = $data[ 'variants' ]; 73 | $data = ingot_test_desitnation::create( 'page' ); 74 | $group_2 = $data[ 'group_ID' ]; 75 | $variants_2 = $data[ 'variants' ]; 76 | $variants = \ingot\testing\tests\click\destination\init::setup_cookies(); 77 | 78 | $this->assertEquals( 2, count( $variants ) ); 79 | 80 | $this->assertArrayHasKey( $group_1, $variants ); 81 | $this->assertTrue( in_array( $variants[ $group_1 ], $variants_1 ) ); 82 | 83 | $this->assertArrayHasKey( $group_2, $variants ); 84 | $this->assertTrue( in_array( $variants[ $group_2 ], $variants_2 ) ); 85 | 86 | } 87 | 88 | /** 89 | * 90 | * 91 | * @since 1.1.0 92 | * 93 | * @group group 94 | * @group destination 95 | * @group cookie 96 | * @group destination_cookie 97 | * 98 | * @covers \ingot\testing\tests\click\destination\init::get_test() 99 | * @covers \ingot\testing\tests\click\destination\init::set_tracking() 100 | * @covers \ingot\testing\tests\click\destination\cookie::get_cookie() 101 | */ 102 | public function testCookieTracking(){ 103 | 104 | $data = ingot_test_desitnation::create( 'page' ); 105 | $group_id = $data[ 'group_ID' ]; 106 | $this->assertTrue( is_numeric( $group_id ) ); 107 | $group = \ingot\testing\crud\group::read( $group_id ); 108 | $this->assertInternalType( 'array', $group ); 109 | $bandit = new \ingot\testing\bandit\content( $group_id ); 110 | $variant_id = $bandit->choose(); 111 | $this->assertTrue( is_numeric( $variant_id ) ); 112 | \ingot\testing\tests\click\destination\init::set_tracking(); 113 | \ingot\testing\tests\click\destination\init::get_test( $group_id ); 114 | $obj = new \ingot\testing\object\group( $group_id ); 115 | $levers = $obj->get_levers(); 116 | $this->assertInternalType( 'array', $levers ); 117 | 118 | $cookie_name = \ingot\testing\tests\click\destination\cookie::cookie_key( $group_id ); 119 | $variant_id = \ingot\testing\tests\click\destination\init::get_test( $group_id ); 120 | $this->assertTrue( is_numeric( $variant_id ) ); 121 | $_COOKIE[ $cookie_name ] = $variant_id; 122 | $this->assertEquals( $variant_id, \ingot\testing\tests\click\destination\cookie::get_cookie( $group_id ) ); 123 | $obj = new \ingot\testing\object\group( $group_id ); 124 | $_levers = $obj->get_levers(); 125 | for ( $i = 0; $i <= 10; $i++ ) { 126 | \ingot\testing\tests\click\destination\init::set_tracking(); 127 | } 128 | 129 | $obj = new \ingot\testing\object\group( $group_id ); 130 | $levers = $obj->get_levers(); 131 | $this->assertEquals( $levers, $_levers ); 132 | $this->assertInternalType( 'array', $levers ); 133 | $this->assertArrayHasKey( $group_id, $levers ); 134 | $this->assertArrayHasKey( $variant_id, $levers[ $group_id ] ); 135 | $lever = $levers[ $variant_id ]; 136 | $this->assertInternalType( 'object', $lever ); 137 | $this->assertEquals( 0, $lever->getNumerator() ); 138 | $this->assertEquals( 1, $lever->getDenominator() ); 139 | 140 | } 141 | 142 | /** 143 | * Test getting group IDs for destination cookies 144 | 145 | * @since 1.1.0 146 | * 147 | * @group destination 148 | * @group cookie 149 | * @group destination_cookie 150 | * @group array_filter 151 | * 152 | * @covers \ingot\testing\utility\array_filters::filter_results() 153 | * @covers \ingot\testing\utility\array_filters::match() 154 | * @covers \ingot\testing\utility\array_filters::prepare() 155 | */ 156 | public function testGetCookies(){ 157 | $_COOKIE = [ 158 | 'ingot_destination_9' => 12, 159 | 'ingot_destination_42' => 7, 160 | 'hi chris', 161 | 'ingot_97' => 94, 162 | 'ingot_destination' => 88, 163 | 'hats_8765' => [ 'batman', 'robin'] 164 | ]; 165 | $results = \ingot\testing\tests\click\destination\cookie::get_all_cookies(); 166 | $this->assertEquals( [ 167 | '9', 168 | '42' 169 | ], $results ); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /tests/tests-destination-tracking.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class tests_destination_tracking extends \WP_UnitTestCase{ 12 | 13 | /** 14 | * Test setting up tagline tests 15 | * 16 | * @since 1.1.0 17 | * 18 | * @group group 19 | * @group destination 20 | * 21 | * @covers \ingot\testing\tests\click\destination\init::set_tracking() 22 | */ 23 | public function testTagline(){ 24 | ingot_test_desitnation::create('page', false ); 25 | $args = [ 26 | 'name' => rand(), 27 | 'type' => 'click', 28 | 'sub_type' => 'destination', 29 | 'meta' => [ 30 | 'destination' => 'page', 31 | 'link' => 'https://bats.com', 32 | 'page' => 11, 33 | 'is_tagline' => true 34 | ], 35 | ]; 36 | 37 | $group_id = \ingot\testing\crud\group::create( $args, true ); 38 | $group = \ingot\testing\crud\group::read( $group_id ); 39 | $this->assertTrue( \ingot\testing\crud\group::valid( $group ) ); 40 | 41 | $content_1 = 'hats'; 42 | $args = [ 43 | 'type' => 'click', 44 | 'group_ID' => $group_id, 45 | 'content' => $content_1 46 | ]; 47 | $variant_1 = \ingot\testing\crud\variant::create( $args, true ); 48 | 49 | $content_2 = 'bats'; 50 | $args = [ 51 | 'type' => 'click', 52 | 'group_ID' => $group_id, 53 | 'content' => $content_2 54 | ]; 55 | 56 | $variant_2 = \ingot\testing\crud\variant::create( $args, true ); 57 | 58 | $group[ 'variants' ] = [ $variant_1, $variant_2 ]; 59 | \ingot\testing\crud\group::update( $group, $group_id, true ); 60 | \ingot\testing\tests\click\destination\init::set_tracking(); 61 | $this->assertTrue( in_array( \ingot\testing\tests\click\destination\init::get_test( $group_id ), [ $variant_1, $variant_2 ] ) ); 62 | $variant_id = \ingot\testing\tests\click\destination\init::get_test( $group_id ); 63 | $variant = \ingot\testing\crud\variant::read( $variant_id ); 64 | $tagline = $variant[ 'content' ]; 65 | $this->assertSame( $tagline, get_bloginfo( 'description', 'display' ) ); 66 | 67 | } 68 | 69 | /** 70 | * 71 | * 72 | * @since 1.1.0 73 | * 74 | * @group one 75 | * @group group 76 | * @group destination 77 | * 78 | * @covers \ingot\testing\tests\click\destination\hooks::track_by_id() 79 | */ 80 | public function testPageTracking(){ 81 | $post = get_post( wp_insert_post( [ 'post_title' => 'Hi Chris' ] ) ); 82 | 83 | $args = [ 84 | 'name' => rand(), 85 | 'type' => 'click', 86 | 'sub_type' => 'destination', 87 | 'meta' => [ 88 | 'destination' => 'page', 89 | 'link' => 'https://bats.com', 90 | 'page' => 11, 91 | 'is_tagline' => true 92 | ], 93 | ]; 94 | 95 | $group_id = \ingot\testing\crud\group::create( $args, true ); 96 | $group = \ingot\testing\crud\group::read( $group_id ); 97 | 98 | $content_1 = 'hats'; 99 | $args = [ 100 | 'type' => 'click', 101 | 'group_ID' => $group_id, 102 | 'content' => $content_1 103 | ]; 104 | $variant_1 = \ingot\testing\crud\variant::create( $args, true ); 105 | 106 | $content_2 = 'bats'; 107 | $args = [ 108 | 'type' => 'click', 109 | 'group_ID' => $group_id, 110 | 'content' => $content_2 111 | ]; 112 | 113 | $variant_2 = \ingot\testing\crud\variant::create( $args, true ); 114 | 115 | $group[ 'variants' ] = [ $variant_1, $variant_2 ]; 116 | $update = \ingot\testing\crud\group::update( $group, $group_id ); 117 | $this->assertEquals( $group_id, $update ); 118 | $group = \ingot\testing\crud\group::read( $group_id ); 119 | $this->assertTrue( is_array( $group ) ); 120 | $this->assertFalse( empty ($group[ 'variants' ] ) ); 121 | new \ingot\testing\bandit\content( $group_id ); 122 | 123 | $group = \ingot\testing\crud\group::read( $group_id ); 124 | $this->assertFalse( empty( $group[ 'levers' ] ) ); 125 | 126 | $groups = \ingot\testing\tests\click\destination\init::set_tracking(); 127 | new \ingot\testing\tests\click\destination\hooks( $groups ); 128 | 129 | $variant_id = \ingot\testing\tests\click\destination\init::get_test( $group_id ); 130 | 131 | $tracking = new \ingot\testing\tests\click\destination\hooks( [ $group_id ] ); 132 | $tracking->track_by_id( 11 ); 133 | 134 | $totals = \ingot\testing\utility\group::get_total( $group, true ); 135 | 136 | $this->assertEquals( 1, $totals[ 'total' ] ); 137 | $this->assertEquals( 1, $totals[ 'conversions' ] ); 138 | } 139 | 140 | /** 141 | * Track EDD at to cart conversions 142 | * 143 | * @since 1.1.0 144 | * 145 | * @group group 146 | * @group destination 147 | * @group edd 148 | * 149 | * @covers \ingot\testing\tests\click\destination\hooks::edd_post_add_to_cart() 150 | * @covers \ingot\testing\tests\click\destination\hooks::add_hooks() 151 | */ 152 | public function testEDDConversionsCart(){ 153 | if( ingot_is_edd_active() ){ 154 | $this->assertTrue( \ingot\testing\tests\click\destination\types::allowed_destination_type( 'cart_edd' ) ); 155 | $product = ingot_test_data_price::edd_create_simple_download( 10 ); 156 | $data = ingot_test_desitnation::create( 'cart_edd' ); 157 | $group_id = $data[ 'group_ID' ]; 158 | $variants = $data[ 'variants' ]; 159 | $this->assertInternalType( 'array', $variants ); 160 | $this->assertFalse( empty( $variants ) ); 161 | new \ingot\testing\bandit\content( $group_id ); 162 | $hooks = new \ingot\testing\tests\click\destination\hooks( [ $group_id ] ); 163 | 164 | $hooks->edd_post_add_to_cart(); 165 | $group = \ingot\testing\crud\group::read( $group_id ); 166 | $totals = \ingot\testing\utility\group::get_total( $group, true ); 167 | $this->assertEquals( 1, $totals[ 'total' ] ); 168 | $this->assertEquals( 1, $totals[ 'conversions' ] ); 169 | 170 | edd_add_to_cart( $product->ID ); 171 | $group = \ingot\testing\crud\group::read( $group_id ); 172 | $totals = \ingot\testing\utility\group::get_total( $group, true ); 173 | $this->assertEquals( 3, $totals[ 'total' ] ); 174 | $this->assertEquals( 2, $totals[ 'conversions' ] ); 175 | 176 | } 177 | 178 | } 179 | 180 | /** 181 | * Track EDD sale conversions 182 | * 183 | * @since 1.1.0 184 | * 185 | * @group group 186 | * @group destination 187 | * @group edd 188 | * 189 | * @covers \ingot\testing\tests\click\destination\hooks::edd_complete_purchase() 190 | * @covers \ingot\testing\tests\click\destination\hooks::add_hooks() 191 | */ 192 | public function testEDDConversionsSale(){ 193 | if( ingot_is_edd_active() ){ 194 | $this->assertTrue( \ingot\testing\tests\click\destination\types::allowed_destination_type( 'sale_edd' ) ); 195 | $product = ingot_test_data_price::edd_create_simple_download( 10 ); 196 | $data = ingot_test_desitnation::create( 'sale_edd' ); 197 | $group_id = $data[ 'group_ID' ]; 198 | 199 | 200 | $this->assertTrue( is_numeric( $group_id ) ); 201 | $variants = $data[ 'variants' ]; 202 | new \ingot\testing\bandit\content( $group_id ); 203 | 204 | $variant_id = \ingot\testing\tests\click\destination\init::get_test( $group_id ); 205 | $this->assertTrue( is_numeric( $variant_id ) ); 206 | 207 | \ingot\testing\tests\click\destination\init::set_tracking(); 208 | 209 | 210 | $this->assertTrue( in_array( \ingot\testing\tests\click\destination\init::get_test( $group_id ), $variants ) ); 211 | $variant_id = \ingot\testing\tests\click\destination\init::get_test( $group_id ); 212 | 213 | $hooks = new \ingot\testing\tests\click\destination\hooks( [ $group_id ]); 214 | 215 | 216 | $payment_id = ingot_test_data_price::edd_create_simple_payment( $product); 217 | edd_complete_purchase( $payment_id, 'publish', 'pending' ); 218 | 219 | $group = \ingot\testing\crud\group::read( $group_id ); 220 | $totals = \ingot\testing\utility\group::get_total( $group ); 221 | $this->assertEquals( 3, $totals[ 'total' ] ); 222 | $this->assertEquals( 2, $totals[ 'conversions' ] ); 223 | 224 | } 225 | 226 | } 227 | 228 | 229 | } 230 | 231 | -------------------------------------------------------------------------------- /tests/tests-destination-utility.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2016 Josh Pollock 10 | */ 11 | class test_utilities extends \WP_UnitTestCase { 12 | 13 | /** 14 | * 15 | * 16 | * @since 1.1.0 17 | * 18 | * @group group 19 | * @group group_crud 20 | * @group destination 21 | * 22 | * @covers \ingot\testing\tests\click\destination\types::allowed_destination_type() 23 | * @covers \ingot\testing\utility\destination::prepare_meta() 24 | */ 25 | public function testPrepareMeta(){ 26 | foreach( \ingot\testing\tests\click\destination\types::destination_types() as $type ){ 27 | if( 'hook' == $type ) { 28 | continue; 29 | } 30 | if ( \ingot\testing\tests\click\destination\types::allowed_destination_type( $type ) ) { 31 | $args = ingot_test_desitnation::group_args( $type ); 32 | $id = \ingot\testing\crud\group::create( $args ); 33 | $this->assertTrue( is_numeric( $id ) ); 34 | $group = \ingot\testing\crud\group::read( $id ); 35 | $this->assertInternalType( 'array', $group ); 36 | 37 | $this->assertTrue( $this->verify_meta( $group[ 'meta' ] ), var_export( $group, true ) ); 38 | } 39 | 40 | } 41 | 42 | 43 | } 44 | 45 | /** 46 | * Check meta data is good 47 | * 48 | * @since 1.1.0 49 | */ 50 | protected function verify_meta( $meta ){ 51 | foreach( [ 'page', 'is_tagline', 'destination'] as $key ){ 52 | if( ! isset( $meta[ $key ] ) ){ 53 | return false; 54 | } 55 | 56 | } 57 | 58 | if( ! is_bool( $meta[ 'is_tagline' ] ) ){ 59 | return false; 60 | } 61 | 62 | if( ! is_numeric( $meta[ 'page' ] ) ){ 63 | return false; 64 | } 65 | 66 | return \ingot\testing\tests\click\destination\types::allowed_destination_type( $meta[ 'destination' ] ); 67 | } 68 | 69 | 70 | /** 71 | * Check for tagline 72 | * 73 | * @since 1.1.0 74 | * 75 | * @group group 76 | * @group destination 77 | * 78 | * @covers \ingot\testing\utility\destination::is_tagline(); 79 | */ 80 | public function testIsTagline(){ 81 | $data = ingot_test_desitnation::create( 'page', true ); 82 | $group = \ingot\testing\crud\group::read( $data[ 'group_ID' ] ); 83 | $this->assertTrue( \ingot\testing\utility\destination::is_tagline( $group ) ); 84 | 85 | $data = ingot_test_desitnation::create( 'page', false ); 86 | $group = \ingot\testing\crud\group::read( $data[ 'group_ID' ] ); 87 | $this->assertFalse( \ingot\testing\utility\destination::is_tagline( $group ) ); 88 | 89 | } 90 | 91 | /** 92 | * Cehck getting destination from meta 93 | * 94 | * @since 1.1.0 95 | * 96 | * @group group 97 | * @group destination 98 | * 99 | * @covers \ingot\testing\utility\destination::get_destination() 100 | */ 101 | public function testGetDestination(){ 102 | foreach( \ingot\testing\tests\click\destination\types::destination_types() as $type ){ 103 | if( 'hook' == $type ) { 104 | continue; 105 | } 106 | 107 | $args = ingot_test_desitnation::group_args( $type ); 108 | $data = ingot_test_desitnation::create( $type ); 109 | $group = \ingot\testing\crud\group::read( $data[ 'group_ID' ] ); 110 | $this->assertEquals( $type, \ingot\testing\utility\destination::get_destination( $group ) ); 111 | 112 | } 113 | } 114 | 115 | /** 116 | * Check getting page ID 117 | * 118 | * @since 1.1.0 119 | * 120 | * @group group 121 | * @group destination 122 | * 123 | * \ingot\testing\utility\destination::get_page_id() 124 | */ 125 | public function testGetPageID(){ 126 | $data = ingot_test_desitnation::create( 'page', true ); 127 | $group = \ingot\testing\crud\group::read( $data[ 'group_ID' ] ); 128 | $this->assertSame( $data[ 'page' ], \ingot\testing\utility\destination::get_page_id( $group ) ); 129 | } 130 | 131 | 132 | } 133 | -------------------------------------------------------------------------------- /tests/tests-functions.php: -------------------------------------------------------------------------------- 1 | 8 | * @license GPL-2.0+ 9 | * @link 10 | * @copyright 2015 Josh Pollock 11 | */ 12 | class tests_functions extends \WP_UnitTestCase { 13 | 14 | public function setUp() { 15 | parent::setUp(); 16 | $_SERVER[ 'HTTP_USER_AGENT' ] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'; 17 | 18 | } 19 | 20 | public function tearDown() { 21 | parent::tearDown(); 22 | } 23 | 24 | /** 25 | * Test our browser detection 26 | * 27 | * 28 | * @covers ingot_get_browser() 29 | */ 30 | public function testGetBrowser() { 31 | $this->assertEquals( 'chrome', ingot_get_browser() ); 32 | 33 | } 34 | 35 | /** 36 | * Test UTM array preperation 37 | * 38 | * @since 0.0.7 39 | * 40 | * @covers ingot_get_utm(); 41 | */ 42 | public function testUTM(){ 43 | $_GET[ 'utm_referrer' ] = 'twitter'; 44 | $_GET[ 'utm_campaign' ] = 'a112357'; 45 | $_GET[ 'utm_medium' ] = 'social'; 46 | 47 | $utm = ingot_get_utm(); 48 | $this->assertArrayHasKey( 'referrer', $utm ); 49 | $this->assertArrayHasKey( 'campaign', $utm ); 50 | $this->assertArrayHasKey( 'medium', $utm ); 51 | 52 | $this->assertEquals( 'twitter', $utm[ 'referrer' ] ); 53 | $this->assertEquals( 'a112357', $utm[ 'campaign' ] ); 54 | $this->assertEquals( 'social', $utm[ 'medium' ] ); 55 | 56 | } 57 | 58 | /** 59 | * Test that a valid Refferer in UTM tracks right 60 | * 61 | * @since 0.0.7 62 | * 63 | * @covers ingot_get_refferer() 64 | */ 65 | public function testReferalTrackingByUTMValid() { 66 | $_GET[ 'utm_referrer' ] = 'twitter'; 67 | $this->assertEquals( 'twitter', ingot_get_refferer() ); 68 | 69 | } 70 | 71 | /** 72 | * Test that a valid Refferer in $_SERVER['HTTP_REFERER'] tracks right 73 | * 74 | * @since 0.0.7 75 | * 76 | * @group functions 77 | * 78 | * @covers ingot_get_refferer() 79 | */ 80 | public function testReferalTrackingByServerVarValid() { 81 | $_SERVER['HTTP_REFERER'] = 'http://twitter.com/xyz?x=hats&b=food'; 82 | $this->assertEquals( 'twitter', ingot_get_refferer() ); 83 | 84 | } 85 | 86 | /** 87 | * Test that an invalid Refferer in UTM doesn't track. 88 | * 89 | * @since 0.0.7 90 | * 91 | * @group functions 92 | * 93 | * @covers ingot_get_refferer() 94 | */ 95 | public function testReferalTrackingByUTMInvalid() { 96 | $_SERVER['HTTP_REFERER'] = 'http://airplanes.com'; 97 | $_GET[ 'utm_referrer' ] = 'myspace'; 98 | $this->assertFalse( ingot_get_refferer() ); 99 | 100 | } 101 | 102 | /** 103 | * Test that an invalid Refferer in $_SERVER['HTTP_REFERER'] tracks right 104 | * 105 | * @since 0.0.7 106 | * 107 | * @group functions 108 | * 109 | * @covers ingot_get_refferer() 110 | */ 111 | public function testReferalTrackingByServerVarInvalid() { 112 | $_SERVER['HTTP_REFERER'] = 'http://airplanes.com'; 113 | $this->assertFalse( ingot_get_refferer() ); 114 | 115 | } 116 | 117 | /** 118 | * Test that when UTM and server var reffers are valid, UTM is used. 119 | * 120 | * @since 0.0.7 121 | * 122 | * @group functions 123 | * 124 | * @covers ingot_get_refferer() 125 | */ 126 | public function testReferrerWithBoth(){ 127 | $_SERVER['HTTP_REFERER'] = 'http://facebook.com/xyz?x=hats&b=food'; 128 | $_GET[ 'utm_referrer' ] = 'twitter'; 129 | $this->assertEquals( 'twitter', ingot_get_refferer() ); 130 | 131 | } 132 | 133 | } 134 | 135 | 136 | -------------------------------------------------------------------------------- /tests/tests-tests.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | 12 | class tests extends \WP_UnitTestCase { 13 | 14 | public function setUp() { 15 | 16 | } 17 | 18 | public function tearDown() { 19 | 20 | } 21 | 22 | public function testTests() { 23 | $this->assertEquals( 1, 1 ); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/tests-ui.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link 9 | * @copyright 2015 Josh Pollock 10 | */ 11 | class tests_ui extends \WP_UnitTestCase { 12 | 13 | /** 14 | * Test that click button tests render properly 15 | * 16 | * @since 0.4.0 17 | * 18 | * @group group 19 | * @group front_ui 20 | * 21 | */ 22 | public function testClickButton(){ 23 | $groups = ingot_tests_data::click_button_group( true, 1, 3 ); 24 | $this->check_render( $groups, __METHOD__ ); 25 | } 26 | 27 | /** 28 | * Test that click button_color tests render properly 29 | * 30 | * @since 0.4.0 31 | * 32 | * @group group 33 | * @group front_ui 34 | * 35 | */ 36 | public function testClickButtonColor(){ 37 | $groups = ingot_tests_data::click_button_color_group( true, 1, 3 ); 38 | $this->check_render( $groups, __METHOD__ ); 39 | } 40 | 41 | /** 42 | * Test that click link tests render properly 43 | * 44 | * @since 0.4.0 45 | * 46 | * @group group 47 | * @group front_ui 48 | * 49 | */ 50 | public function testClickLink(){ 51 | $groups = ingot_tests_data::click_link_group( true, 1, 3 ); 52 | $this->check_render( $groups, __METHOD__ ); 53 | } 54 | 55 | /** 56 | * Loop through a few renders to make sure nothing gets wonky -- IE new levers being created or something 57 | * 58 | * @since 0.4.0 59 | * 60 | * @group bandit 61 | * @group group 62 | * @group front_ui 63 | * 64 | */ 65 | public function testMultiple(){ 66 | $groups = ingot_tests_data::click_link_group( true, 1, 3 ); 67 | $group_id = $groups[ 'ids' ][ 0 ]; 68 | $variants = $groups[ 'variants' ][ $groups[ 'ids' ][ 0 ] ]; 69 | 70 | for ( $i = 0; $i <= 5; $i++ ) { 71 | $this->check_render( $groups, __METHOD__ ); 72 | $group = \ingot\testing\crud\group::read( $group_id ); 73 | $levers = $group[ 'levers' ]; 74 | $this->assertInternalType( 'array', $levers ); 75 | $this->assertFalse( empty( $levers ) ); 76 | $this->assertArrayHasKey( $group_id, $levers ); 77 | foreach( $variants as $variant_id ){ 78 | $this->assertArrayHasKey( $variant_id, $levers[ $group_id ], 'iteration: ' . $i ); 79 | } 80 | 81 | } 82 | 83 | } 84 | 85 | /** 86 | * Test conversion 87 | * 88 | * @todo move this test to a better place 89 | * 90 | * @since 0.4.0 91 | * 92 | * @group bandit 93 | * @group group 94 | * @group front_ui 95 | * 96 | * @covers ingot_register_conversion() 97 | */ 98 | public function testConversion(){ 99 | $groups = ingot_tests_data::click_link_group( true, 1, 3 ); 100 | $chosen = $this->check_render( $groups, __METHOD__ ); 101 | $group_id = $groups[ 'ids' ][ 0 ]; 102 | 103 | ingot_register_conversion($chosen); 104 | $levers = \ingot\testing\crud\group::get_levers( $group_id ); 105 | /** @var \MaBandit\Lever $chosen_lever */ 106 | $chosen_lever = $levers[ $group_id ][ $chosen ]; 107 | 108 | $this->assertSame( 1, $chosen_lever->getNumerator() ); 109 | $this->assertSame( 1, $chosen_lever->getDenominator() ); 110 | /** @var \MaBandit\Lever $lever */ 111 | foreach( $levers[ $group_id ] as $id => $lever ){ 112 | if ( $chosen != $id ) { 113 | $this->assertSame( 0, $lever->getNumerator() ); 114 | $this->assertSame( 0, $lever->getDenominator() ); 115 | } 116 | } 117 | 118 | 119 | } 120 | 121 | /** 122 | * Test multiple conversions 123 | * 124 | * @todo move this test to a better place 125 | * 126 | * @since 0.4.0 127 | * 128 | * @group bandit 129 | * @group group 130 | * @group front_ui 131 | * 132 | * @covers ingot_register_conversion() 133 | */ 134 | public function testMultipleConversions(){ 135 | $groups = ingot_tests_data::click_link_group( true, 1, 3 ); 136 | $group_id = $groups[ 'ids' ][ 0 ]; 137 | $variants = $groups[ 'variants' ][ $groups[ 'ids' ][ 0 ] ]; 138 | $expected = []; 139 | foreach( $variants as $variant ){ 140 | $expected[ $variant ] = [ 'n' => 0 , 'd' => 0 ]; 141 | } 142 | 143 | for ( $i = 0; $i <= 25; $i++ ) { 144 | $chosen = $this->check_render( $groups, __METHOD__ ); 145 | if ( in_array( $i, [ 2,3,5,8,13,21 ]) ) { 146 | ingot_register_conversion( $chosen ); 147 | $expected[ $chosen ][ 'n' ] = $expected[ $chosen ][ 'n' ] + 1; 148 | } 149 | $expected[ $chosen ][ 'd' ] = $expected[ $chosen ][ 'd' ] + 1; 150 | $levers = \ingot\testing\crud\group::get_levers( $group_id ); 151 | /** @var \MaBandit\Lever $lever */ 152 | foreach ( $levers[ $group_id ] as $id => $lever ) { 153 | if ( $chosen != $id ) { 154 | $this->assertSame( $expected[ $id ][ 'n' ], $lever->getNumerator(), $id . '-' . $lever->getNumerator() ); 155 | $this->assertSame( $expected[ $id ][ 'd' ], $lever->getDenominator(), $id ); 156 | } 157 | } 158 | } 159 | 160 | 161 | } 162 | 163 | /** 164 | * Check the rendering of a test 165 | * 166 | * @since 0.4.0 167 | * 168 | * @param $groups 169 | * 170 | * @return int ID of chosen variant 171 | */ 172 | protected function check_render( $groups, $test_name ) { 173 | $render = new \ingot\ui\render\click_tests\button( $groups[ 'ids' ][ 0 ] ); 174 | $chosen = $render->get_chosen_variant_id(); 175 | $this->assertTrue( is_numeric( $chosen ), $test_name ); 176 | if( ! in_array( $chosen, $groups[ 'variants' ][ $groups[ 'ids' ][ 0 ] ] ) ){ 177 | var_dump( $chosen,$groups[ 'variants' ][ $groups[ 'ids' ][ 0 ] ] );die(); 178 | } 179 | $this->assertTrue( in_array( $chosen, $groups[ 'variants' ][ $groups[ 'ids' ][ 0 ] ], $test_name) ); 180 | $html = $render->get_html(); 181 | $this->assertInternalType( 'string', $html, $test_name ); 182 | $this->assertNotEquals( 0, strlen( $html ), $test_name ); 183 | 184 | return $chosen; 185 | 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /vendor/autoload.php: -------------------------------------------------------------------------------- 1 |